Reply to message «Re: syntax coloring», 
sent 21:39:21 15 April 2011, Friday
by rameo:

> Still have a little problem.
> I had also a VimLeave argdel command in my _vimrc.
> 
> Is this correct?:
> 
> augroup SaveRestoreSessions
> autocmd!
> autocmd VimEnter * nested source D:\session.vim
> autocmd VimLeave * nested mksession! D:\session.vim
> autocmd VimLeave *  if argc() != 0 | exe 'argdel *'
> augroup END
> 
> btw tnx. for your script.
1. Missing endif.
2. You don't need `exe' here.
3. I don't get why do you need this command at all.

Original message:
> On Apr 15, 5:43 pm, ZyX <[email protected]> wrote:
> > Reply to message «Re: syntax coloring»,
> > sent 19:13:18 15 April 2011, Friday
> > 
> > by rameo:
> > > Please let me ask you one more question...
> > > How do you close this session and reopens a custom one (happens once
> > > in a while)?
> > 
> > I don't use one continious vim session and don't load any sessions at
> > vim startup (the `just the same error' meant that I used an autocommand
> > in a similar way and got the same error, not that I used the same code).
> > Instead I create a new session file almost each time when vim exits
> > and load one of created sessions at vim startup:
> > 1. due to virtual desktops I almost never close any of my projects'
> > windows, 2. I use vim to quickly edit something from command-line,
> > loading any sessions will discard the most significant part of vim
> > invocation arguments for this use-case.
> > Saving session at vim exit is for the case when I have to reload vim
> > (mostly plugin or kernel updates).
> > Here is my code:
> > 
> >     "▶2 mksession
> >     if has('mksession')
> >         function s:InitSes()
> >             let sesdir=expand('~/.vimsessions')
> >             if !isdirectory(sesdir)
> >                 call mkdir(expand(sesdir), "", 0700)
> >             endif
> >             let sesfile=os#JoinPath(sesdir, '.sessions.lst')
> >             let sessions=[]
> >             if filereadable(sesfile)
> >                 let sessions+=readfile(sesfile, 'b')
> >                 while !empty(sessions) && empty(sessions[-1])
> >                     call remove(sessions, -1)
> >                 endwhile
> >             endif
> >             let sessplitted=map(copy(sessions),
> >                         \'split(v:val, ''\v%(\\@<!%(\\\\)*)@<=,'')')
> >             let sesdirs=map(copy(sessplitted),
> > '((empty(v:val))?(""):(v:val[0]))') let sesfiles=map(copy(sessplitted),
> > '((empty(v:val))?([]):(v:val[1:]))') execute "cd
> > ".fnameescape(resolve(fnamemodify('.', ':p'))) let
> > curdir=escape(fnamemodify('.', ':p'), ',\')
> >             return [sesdir, sesfile, sessions, sesdirs, sesfiles, curdir]
> >         endfunction
> >         let s:_functions['s:InitSes']=function('s:InitSes')
> >         function s:MakeSession()
> >             let [sesdir, sesfile, sessions, sesdirs, sesfiles,
> > curdir]=s:InitSes() let files=sort(map(filter(map(filter(range(1,
> > bufnr('$')), \                        'getbufvar(v:val,
> > "&bt")!=#"help"'), \                 'bufname(v:val)'),
> >                         \             'filereadable(v:val)'),
> >                         \    
> >  'escape(fnamemodify(resolve(fnamemodify(v:val, ":p")), ":~:."),
> > ",\\")'))
> >             if empty(files)
> >                 return
> >             endif
> >             let sesstr=join([curdir]+files, ',')
> >             let sindex=index(sessions, sesstr)
> >             if sindex==-1
> >                 let sindex=index(sessions, '')
> >             endif
> >             if sindex==-1
> >                 let sesname=os#JoinPath(sesdir, len(sesdirs).'.vim')
> >                 call add(sessions, sesstr)
> >             else
> >                 let sesname=os#JoinPath(sesdir, sindex.'.vim')
> >                 let sessions[sindex]=sesstr
> >             endif
> >             execute 'mksession! '.fnameescape(sesname)
> >             call writefile(sessions, sesfile, 'b')
> >         endfunction
> >         let s:_functions['s:MakeSession']=function('s:MakeSession')
> >         function s:LoadSession(bang, ...)
> >             let [sesdir, sesfile, sessions, sesdirs, sesfiles,
> > curdir]=s:InitSes() if a:0 && string(+a:1)==#a:1 && a:1<len(sessions) &&
> > \!empty(sessions[a:1])
> >                 let dirsessions=[[+a:1, sesdirs[a:1], sessions[a:1]]]
> >             else
> >                 let dirsessions=filter(map(copy(sesdirs),
> >                             \              '[v:key, v:val,
> > sessions[v:key]]'), \          'v:val[1]==#curdir'.
> >                             \                   ((a:0)?(' &&
> > v:val[2]=~?a:1'):(''))) endif
> >             if len(dirsessions)==1 || (!empty(dirsessions) && a:bang)
> >                 let sesid=dirsessions[0][0]
> >                 let sesname=os#JoinPath(sesdir, sesid.'.vim')
> >                 execute 'source '.fnameescape(sesname)
> >                 call delete(sesname)
> >                 if sesid==(len(sessions)-1)
> >                     call remove(sessions, -1)
> >                 else
> >                     let sessions[sesid]=""
> >                 endif
> >                 call writefile(sessions, sesfile, 'b')
> >             endif
> >         endfunction
> >         let s:_functions['s:LoadSession']=function('s:LoadSession')
> >         function s:PrintSessions()
> >             let [sesdir, sesfile, sessions, sesdirs, sesfiles,
> > curdir]=s:InitSes() call map(sessions,
> >                         \'printf("%'.len(len(sessions)-1).'u %s", v:key,
> > v:val)') echo join(sessions, "\n")
> >         endfunction
> >         let s:_functions['s:PrintSessions']=function('s:PrintSessions')
> >         autocmd VimLeavePre * call s:MakeSession()
> >         command -nargs=? -bang LoadSession   call s:LoadSession(<bang>0,
> > <q-args>) command -bar           PrintSessions call s:PrintSessions()
> > let s:_commands+=['LoadSession', 'PrintSessions']
> >     endif
> >     "▲2
> > 
> > I am going to evolve this into plugin sometime.
> > 
> > Original message:
> > > On Apr 15, 1:43 pm, ZyX <[email protected]> wrote:
> > > > Reply to message «syntax coloring»,
> > > > sent 11:06:33 15 April 2011, Friday
> > > > 
> > > > by rameo:
> > > > > When I start VIM it shows my tabs and reloads my buffers from the
> > > > > last time.
> > > > > 
> > > > > I use a session to do this.
> > > > > 
> > > > > au VimEnter * exe "so d:\\Session.vim"
> > > > > au VimLeave * exe "'mksession! d:\\Session.vim'"
> > > > 
> > > > You have made just the same mistake as me some time ago: all
> > > > filetype-related files are loaded using an autocommand, but by
> > > > default no autocommands are allowed when you are executing an
> > > > autocommand, so you should add `nested' just after the pattern. By
> > > > the way, why do you use `exe'? The following works as well:
> > > >     augroup SaveRestoreSessions
> > > >         autocmd!
> > > >         autocmd VimEnter * nested source D:\session.vim
> > > >         autocmd VimLeave * nested mksession! D:\session.vim
> > > >     augroup END
> > > > 
> > > > See `:h autocmd-nested' for more details.
> > > > 
> > > > Original message:
> > > > > When I start VIM it shows my tabs and reloads my buffers from the
> > > > > last time.
> > > > > 
> > > > > I use a session to do this.
> > > > > 
> > > > > au VimEnter * exe "so d:\\Session.vim"
> > > > > au VimLeave * exe "'mksession! d:\\Session.vim'"
> > > > > 
> > > > > My reopened files do not have syntax coloring.
> > > > > I have to do ":e" in every file where I need syntax coloring to
> > > > > view syntax coloring.
> > > > > 
> > > > > I know that I can add "localoptions" in sessionoptions but this
> > > > > slows down my vim (I noted that it uses 20-25% more CPU). Without
> > > > > "localoptions" my vim is much faster.
> > > > > 
> > > > > How do you resolve this?
> > > > > Don't you use sessions?
> > > > 
> > > >  signature.asc
> > > > < 1KViewDownload
> > > 
> > > Great! It does work.
> > > Thanks a lot!
> > > 
> > > Please let me ask you one more question...
> > > How do you close this session and reopens a custom one (happens once
> > > in a while)?
> > 
> >  signature.asc
> > < 1KViewDownload
> 
> Still have a little problem.
> I had also a VimLeave argdel command in my _vimrc.
> 
> Is this correct?:
> 
> augroup SaveRestoreSessions
> autocmd!
> autocmd VimEnter * nested source D:\session.vim
> autocmd VimLeave * nested mksession! D:\session.vim
> autocmd VimLeave *  if argc() != 0 | exe 'argdel *'
> augroup END
> 
> btw tnx. for your script.

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to