I've been customizing my .vimrc a lot lately and love the power and convenience that :mksession gives me. I currently have the following in my .vimrc to autoload sessions:
function! LoadSession()
if argc() == 0 && ! &diff
let g:sessiondir = $HOME . "/.vim/sessions" . getcwd()
let g:sessionfile = g:sessiondir . "/session.vim"
if (filereadable(g:sessionfile))
exe 'source ' g:sessionfile
else
echo "No session loaded." + argc() + argv()
endif
else
let g:sessionfile = ""
let g:sessiondir = ""
call ResCur()
endif
endfunction
I then call this with au VimEnter * nested :call LoadSession(). This works great for most cases, except when vim is reading from stdin. In that case the session is still loaded, however I want to prevent that from happening. I would have thought the argc() == 0 conditions would be enough, but it appears that the - that vim is being called with to read from stdin causes argc() to not return 0. Poop! ;]
I've tried all sorts of things from looking at argv(0) (it's empty in this case - why?), trying to find ways of identifying that vim is reading from stdin (it shows a message that it's doing so, but I can't figure out how to tap into that), etc., but no luck so far.
I'm sure I'm missing something terribly obvious here, but the Googles and vim :help isn't getting me anywhere, so I'm hoping some kind soul here can shed some light on this for me.