On Apr 15, 10:02 pm, ZyX <[email protected]> wrote:
> Reply to message «Re: syntax coloring»,
> sent 23:29:29 15 April 2011, Friday
> by rameo:
>
> > I found a new way to integrate argdel:
>
> > augroup SaveRestoreSessions
> > autocmd!
> > autocmd VimEnter * nested source $VIM\vimfiles\sessions\Session.vim
> > autocmd VimLeave * call MakeSession()
> > autocmd VimLeave * nested mksession! $VIM\vimfiles\sessions
> > \Session.vim
> > augroup END
>
> > function! MakeSession()
> >   if argc() != 0
> >     execute 'argdel *'
> >   endif
> > endfunction
>
> You are doing a strange things again:
> 1. You should either rename `MakeSession' to `ClearArgs' (because 
> `MakeSession'
> will confuse somebody (maybe even you) who will read you code as it does not
> makes any sessions) or, better, move `mksession!' call inside a function.
> 2. Why are you again writing `execute'?
> 3. You don't need `nested' for mksession, you need it only for VimEnter.
> 4. Never write anything user-specific to application folder, it may be purged 
> by
> application update, removed by the package manager (if any) or uninstaller, or
> you may have to create more then one user on the machine.
>
> Original message:
>
>
>
>
>
>
>
> > On Apr 15, 9:14 pm, ZyX <[email protected]> wrote:
> > > Reply to message «Re: syntax coloring»,
> > > sent 23:02:40 15 April 2011, Friday
>
> > > by rameo:
> > > > Tnx.. this is what I added:
> > > > autocmd VimLeave * if argc() != 0 | 'argdel *' endif
>
> > > Reread help. This is false: you should not use strikes around `argdel *'
> > > and you should have bar before `endif' just like you have before
> > > `argdel'.
>
> > > > I noted that (even after a buffer delete :bd) certain buffers do
> > > > remain in "session.vim"
> > > > I had no troubles anymore after removing "argdel *" and troubles again
> > > > after having changed the script as above.
>
> > > I know this issue. In this case you should have `argdel' before
> > > mksession, I don't get why you have it *after*.
>
> > > Original message:
> > > > On Apr 15, 8:55 pm, ZyX <[email protected]> wrote:
> > > > > 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
>
> ...
>
> read more »
>
>  signature.asc
> < 1KViewDownload

Is this the correct one?

augroup SaveRestoreSessions
autocmd!
autocmd VimEnter * nested source D:\Session.vim
autocmd VimLeave * call ClearArgs()
autocmd VimLeave * nested mksession! D:\Session.vim
augroup END

function! ClearArgs()
  if argc() != 0
   argdel *
  endif
endfunction

-----------------

Regards,
R.

-- 
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to