Skip to content

Commit

Permalink
Invoke autoload functions instead of custom commands
Browse files Browse the repository at this point in the history
Pull request #31: #31

Ingo's explanation (which I completely agree with):

  Some people using the :Session... alternatives may :delcommand the
  original commands; in that case, the invocations by the script would
  fail. Prevent this error by invoking the autoload functions directly;
  this also obsoletes the need for fnameescape().
  • Loading branch information
xolox committed Apr 21, 2013
1 parent d405393 commit b6b6d7f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -148,6 +148,8 @@ When this option is enabled the session plug-in will define the following comman

The aliases support tab completion just like the real commands; they're exactly the same except for the names.

When you enable the aliases, the default command names will still be available. If you really don't like them, feel free to delete them using [:delcommand] [delcommand].

### The `g:loaded_session` option

This variable isn't really an option but if you want to avoid loading the `session.vim` plug-in you can set this variable to any value in your [vimrc script] [vimrc]:
Expand Down Expand Up @@ -274,7 +276,9 @@ Here's an example session script generated by the `session.vim` plug-in while I
doautoall SessionLoadPost
unlet SessionLoad


[delcommand]: http://vimdoc.sourceforge.net/htmldoc/map.html#:delcommand
[mksession]: http://vimdoc.sourceforge.net/htmldoc/starting.html#:mksession
[sessionoptions]: http://vimdoc.sourceforge.net/htmldoc/options.html#%27sessionoptions%27
[source]: http://vimdoc.sourceforge.net/htmldoc/repeat.html#:source
[vimrc]: http://vimdoc.sourceforge.net/htmldoc/starting.html#vimrc
[sessionoptions]: http://vimdoc.sourceforge.net/htmldoc/options.html#%27sessionoptions%27
14 changes: 7 additions & 7 deletions autoload/xolox/session.vim
Expand Up @@ -3,7 +3,7 @@
" Last Change: April 21, 2013
" URL: http://peterodding.com/code/vim/session/

let g:xolox#session#version = '1.5.8'
let g:xolox#session#version = '1.5.9'

call xolox#misc#compat#check('session', 1)

Expand Down Expand Up @@ -255,7 +255,7 @@ function! xolox#session#auto_load() " {{{2
if v:servername !~ '^\cgvim\d*$'
for session in xolox#session#get_names()
if v:servername ==? session
execute 'OpenSession' fnameescape(session)
call xolox#session#open_cmd(session, '')
return
endif
endfor
Expand All @@ -267,7 +267,7 @@ function! xolox#session#auto_load() " {{{2
let msg = "Do you want to restore your %s editing session?"
let label = session != 'default' ? 'last used' : 'default'
if s:prompt(printf(msg, label), 'g:session_autoload')
execute 'OpenSession' fnameescape(session)
call xolox#session#open_cmd(session, '')
endif
endif
endif
Expand All @@ -279,7 +279,7 @@ function! xolox#session#auto_save() " {{{2
if name != ''
let msg = "Do you want to save your editing session before quitting Vim?"
if s:prompt(msg, 'g:session_autosave')
execute 'SaveSession' fnameescape(name)
call xolox#session#save_cmd(name, '')
endif
endif
endif
Expand Down Expand Up @@ -396,7 +396,7 @@ function! xolox#session#close_cmd(bang, silent, save_allowed) abort " {{{2
if a:save_allowed
let msg = "Do you want to save your current editing session before closing it?"
if s:prompt(msg, 'g:session_autosave')
SaveSession
call xolox#session#save_cmd(name, a:bang)
endif
else
call xolox#misc#msg#debug("session.vim %s: Session reset requested, not saving changes to session ..", g:xolox#session#version)
Expand Down Expand Up @@ -448,7 +448,7 @@ function! xolox#session#restart_cmd(bang, args) abort " {{{2
else
let name = s:get_name('', 0)
if name == '' | let name = 'restart' | endif
execute 'SaveSession' . a:bang fnameescape(name)
call xolox#session#save_cmd(name, a:bang)
let progname = xolox#misc#escape#shell(fnameescape(v:progname))
let command = progname . ' -c ' . xolox#misc#escape#shell('OpenSession\! ' . fnameescape(name))
let args = matchstr(a:args, '^\s*|\s*\zs.\+$')
Expand All @@ -466,7 +466,7 @@ function! xolox#session#restart_cmd(bang, args) abort " {{{2
call add(cmdline, printf("--cmd ':set enc=%s'", escape(&enc, '\ ')))
silent execute '!' join(cmdline, ' ') '&'
endif
execute 'CloseSession' . a:bang
call xolox#session#close_cmd(a:bang, 0, 1)
silent quitall
endif
endfunction
Expand Down
4 changes: 4 additions & 0 deletions doc/session.txt
Expand Up @@ -299,6 +299,10 @@ command aliases:
The aliases support tab completion just like the real commands; they're
exactly the same except for the names.

When you enable the aliases, the default command names will still be
available. If you really don't like them, feel free to delete them using
|:delcommand|.

-------------------------------------------------------------------------------
The *g:loaded_session* option

Expand Down

0 comments on commit b6b6d7f

Please sign in to comment.