Am 16.10.2012 20:18, schrieb Christian Brabandt:
Hi Andy!

On Di, 16 Okt 2012, Andy Wokula wrote:

Am 16.10.2012 18:00, schrieb Christian Brabandt:> Bram,
when doing :setglobal noswapfile, Vim incorrectly does not delete all
swapfiles. Also, if you have disabled swapfiles, :setglobal swapfile
won't create swapfiles for all loaded buffers.

Attached patch fixes it.

Why is that a bug?
The 'swapfile' option is "local to buffer" which means the global value
is only used for *new* buffers.

This means, when globally enabling undofiles, all loaded buffers
shouldn't try to read their undofiles, because their local value is
still disabled.

This is really confusing.

You're right, I have actually faced this /confusion/ too.

I've even thrown a script at the issue (see attachment)!  You do
    :ForceSet {set-arg} ...
(e.g. :ForceSet swapfile)
to set certain options whenever a buffer is visited, and
    :NoForceSet [set-arg] ...
to turn these actions off.
So to say, it operates in a `lazy' (not `eager') manner ...

Just
    :ForceSet
prints the enabled set commands, and
    :NoForceSet
(without arguments) removes all actions.

(Detail: It's clever enough to not accumulate actions for the same
option (nu, nonu, invnu, nu!, ...) but it's not aware of long and short
option names (nu, number)).

(Didn't check if it actually works for 'swapfile' and 'undofile')

--
Andy

--
You received this message from the "vim_dev" 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
" Vimball Archiver by Charles E. Campbell, Jr., Ph.D.
UseVimball
finish
plugin\forceset.vim     [[[1
87
" File:         C371.vim
" Created:      2009 May 21
" Last Change:  2012 Mar 11
" Rev Days:     4

" :ForceSet {set-arg} ...
"
"   set an option {set-arg} when any buffer is entered.  The purpose is to
"   set a local option back that has already been set in many buffers;
"   alternative to :bufdo
"
"   Note: uses :set, not :setlocal
"
" Comments: {{{
"
" Dependencies: (by :PutDepend)
"   UniqMapStr()
"
" 2012 Jan 11   see also  :h cpo-S
" 2012 Mar 11   * removed the redirection from  :au forceset  (more
"                 informative now)
"               * different commands for the same option no longer
"                 accumulate (thanks to UniqMapStr())
"               * renamed :ForceUnset to :NoForceSet
" }}}

com! -bar -nargs=* -complete=option             ForceSet call 
s:ForceSet(<f-args>)
com! -bar -nargs=* -complete=custom,FUs_Compl   NoForceSet call 
s:NoForceSet(<f-args>)

augroup forceset
augroup End

" list of set-arguments
if !exists("s:arglog")
    let s:arglog = []
endif

func! s:ForceSet(...) "{{{
    " a:000     new set arguments
    if a:0 == 0
        echo "Set-commands on BufEnter:"
        if !empty(s:arglog)
            echo "  set ".join(s:arglog, "\n  set ")
        else
            echon " NONE"
        endif
        return
    endif
    try
        exec "set" join(a:000)
    catch
        echomsg v:exception
        return
    endtry
    let s:arglog = UniqMapStr(s:arglog + a:000, '\%(no\|inv\)\=\zs\a\+', 1)
    exec "au! forceset BufEnter * set" join(s:arglog)
endfunc "}}}

func! s:NoForceSet(...) "{{{
    if a:0 == 0
        if empty(s:arglog)
            echo "Set-commands on BufEnter: NONE"
            return
        endif
        let s:arglog = []
        au! forceset
        return
    endif
    call filter(s:arglog, 'index(a:000, v:val) < 0')
    if empty(s:arglog)
        au! forceset
    else
        exec "au! forceset BufEnter * set" join(s:arglog)
    endif
endfunc "}}}

" completion: we have to decide: either complete items that can be removed
" from the BufEnter call; or possible arguments to :set (would be useful as
" well), then with -complete=options (or so...)
func! FUs_Compl(...) "{{{
    return join(s:arglog, "\n")
    " if a:2=~'ForceSet!'
    "     return join(s:arglog, "\n")
    " else
    "     return ""
    " endif
endfunc "}}}
plugin\uniqmap.vim      [[[1
116
" File:         w98c109.vim
" Created:      2012 Mar 11
" Last Change:  2012 Oct 11
" Rev Days:     3

" 2012 Apr 20   uploaded to  http://vpaste.net/R8cQw
"               bairu's mod  https://gist.github.com/2427305
" 2012 Jul 21
" 2012 Oct 11

" UniqMapFirst({list}, {mapexpr})

" UniqMap({list}, {mapexpr}[, {keeplast}])
"   remove duplicates from {list}, but check for duplicates after mapping
"   list items with {mapexpr} (see :h map()).  The instance with lowest
"   index is kept, or the highest index with non-zero {keeplast}.
"
" UniqMapStr({list}, {pattern}[, {keeplast}])
"   remove duplicates from a list of strings {list}, but compare the item
"   parts matched by {pattern}.

" Dejavu List Operations: {{{
" - apply changes for one list to another list also
"
" Scenario: Howto solve the following:
"   We want to remove duplicate items from a list, but the Uniq() function
"   can't yet detect these items, so first we have to apply a map()
"   operation to prepare the list.  This makes Uniq(map({list}, '...'))
"   work, but gets a list of mapped items.  To get the final result, we need
"   something like
"       reverse-map(Uniq(map({list}, ...)), ...)
"   We don't want reverse-map().  Instead, we want a version of Uniq() that
"   accepts a map()-expression.
"
" }}}
" Examples: {{{
" - :echo map(split('the brown fox jumps'), 'strlen(v:val)')
"       [3, 5, 3, 5]
"   :echo UniqMap(split('the brown fox jumps'), 'strlen(v:val)')
"       ['the', 'brown']
"   :echo UniqMap(split('the brown fox jumps'), 'strlen(v:val)', 1)
"       ['fox', 'jumps']
" - Remove duplicates from a list of :set commands:
"       :let list = ['set nu', 'set nonu', 'set et!', 'set et']
"   We have a duplicate when two commands set the same option; the prepared
"   list will be
"       :let pattern = '^set \%(no\)\=\zs\w\+'
"       :echo map(copy(list), 'matchstr(v:val, pattern)')
"       ['nu', 'nu', 'et, 'et']
"   Command:
"       :echo UniqMapStr(copy(list), pattern, 1)
"       ['set nonu', 'set et']

" }}}

" TODO {{{
" - SortMap({list}, {mapexpr}) -- probably impossible at the moment
" - "set functions": IntersectMap(), UnionMap(), SubstractMap()
" -- IndexMap() is too trivial

" }}}

" (in place)
func! UniqMapFirst(list, mapexpr) "{{{
    let mlist = map(copy(a:list), a:mapexpr)
    let idx = len(a:list) - 1
    while idx >= 1
        if index(mlist, mlist[idx]) < idx
            call remove(a:list, idx)
        endif
        let idx -= 1
    endwhile
    return a:list
endfunc "}}}

" (in place)
func! UniqMapLast(list, mapexpr) "{{{
    return reverse(UniqMapFirst(reverse(a:list), a:mapexpr))
endfunc "}}}

" (in place)
func! UniqMap(list, mapexpr, ...) "{{{
    return a:0>=1 && a:1
        \ ? UniqMapLast(a:list, a:mapexpr)
        \ : UniqMapFirst(a:list, a:mapexpr)
endfunc "}}}

""" (old)
""func! UniqMap(list, mapexpr, ...) "{{{
""    let keeplast = a:0>=1 && a:1
""    let len = len(a:list)
""    let idx = len-1
""    let mlist = map(copy(a:list), a:mapexpr)
""    if keeplast
""      call reverse(mlist)
""      call reverse(a:list)
""    endif
""    while idx >= 1
""      if index(mlist, mlist[idx]) < idx
""          " call remove(mlist, idx)
""          call remove(a:list, idx)
""      endif
""      let idx -= 1
""    endwhile
""    if keeplast
""      call reverse(a:list)
""    endif
""    return a:list
""endfunc "}}}

" (in place)
func! UniqMapStr(list, pat, ...) "{{{
    let keeplast = a:0>=1 && a:1
    return UniqMap(a:list, printf('matchstr(v:val, %s)', string(a:pat)), 
keeplast)
endfunc "}}}

Raspunde prin e-mail lui