ZyX_I avatar ZyX_I committed a5398e3

@/decorators/altervars: Added `folds' special setter

Comments (0)

Files changed (5)

                    tabpage or window-local variables).
         buffer     Saves and restores current buffer number.
         window     Saves and restores current tab page and window.
+        folds      Saves and restores folds state.
         winview    Saves and restores window view (using |winsaveview()| and 
                    |winrestview()|).
         matches    Saves and restores matches (using |getmatches()| and 
 @/os:
     0.1: Added |frawor-r-os.path.relpath|
          Made |frawor-r-os.path.normpath| also simplify its argument
+@/decorators/altervars:
+    0.1: Added folds |frawor-av-special|
 
 vim: ft=help:tw=78

plugin/frawor/decorators/altervars.vim

 "▶1 Header
 scriptencoding utf-8
-execute frawor#Setup('0.0', {'@/decorators': '0.0',
+execute frawor#Setup('0.1', {'@/decorators': '0.0',
             \                    '@/checks': '0.0',
             \      '@/decorators/altervars': '0.0'}, 1)
 "▶1 Define messages
 "▶2 winview
 call s:_f.addaltspecial('winview', function('winsaveview'),
             \                      function('winrestview'))
+"▶2 folds
+function s:F.saver.folds()
+    let r=[]
+    for line in range(1, line('$'))
+        if foldclosed(line)!=-1
+            execute line.'foldopen'
+            call insert(r, line)
+        endif
+    endfor
+    return r
+endfunction
+function s:F.setter.folds(flist)
+    if type(a:flist)==type([]) &&
+                \empty(filter(copy(a:flist), 'type(v:val)!='.type(0)))
+        try
+            normal! zR
+            for line in a:flist
+                execute line.'foldclose'
+            endfor
+        catch
+            echohl ErrorMsg
+            echomsg v:exception
+            echohl None
+        endtry
+    endif
+endfunction
+call s:_f.addaltspecial('folds', s:F.saver.folds, s:F.setter.folds)
 "▶2 buffer
 function s:F.saver.buffer()
     return bufnr('%')

test/rtp/plugin/wrapfunc-alter-special-folds.vim

+execute frawor#Setup('0.0', {'@/functions': '0.0',
+            \     '@/decorators/altervars': '0.0'}, 1)
+append
+{{{1 1
+{{{2 2
+{{{3 3
+4
+5
+6
+{{{3 7
+8
+9
+{{{2 a
+b
+c
+d
+{{{1 e
+f
+.
+setlocal foldmethod=marker foldmarker={{{,}}}
+setlocal foldtext=foldtext()
+function s:F.printfolds()
+    let r=[]
+    let lline=line('$')
+    let line=1
+    while line<=lline
+        if foldclosed(line)!=-1
+            let r+=['F'.foldtextresult(line)]
+            let line=foldclosedend(line)
+        else
+            let r+=[' '.getline(line)]
+        endif
+        let line+=1
+    endwhile
+    call WriteFile(r)
+endfunction
+function s:F.wrappedfunc(...)
+    normal! zR
+    call s:F.printfolds()
+endfunction
+call s:_f.addextfunctions({'Function': {'function': s:F.wrappedfunc,
+            \                         '@altervars': [['+folds']]}})
+normal! zMggzojjzo
+call s:F.printfolds()
+W>>>
+call Function()
+W<<<
+call s:F.printfolds()

test/wrapfunc-alter-special-folds.in

+:let &rtp.=",".escape($TESTDIR, ',\').'/rtp'
+:let g:testfile="plugin/".g:curtest.".vim"
+:source test.vim

test/wrapfunc-alter-special-folds.ok

+ {{{1 1
+F+---  8 lines: 2
+ {{{2 a
+ b
+ c
+ d
+F+--  2 lines: e
+>>>
+ {{{1 1
+ {{{2 2
+ {{{3 3
+ 4
+ 5
+ 6
+ {{{3 7
+ 8
+ 9
+ {{{2 a
+ b
+ c
+ d
+ {{{1 e
+ f
+<<<
+ {{{1 1
+F+---  8 lines: 2
+ {{{2 a
+ b
+ c
+ d
+F+--  2 lines: e
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.