aboutsummaryrefslogtreecommitdiff
path: root/plugin/cecutil.vim
diff options
context:
space:
mode:
Diffstat (limited to 'plugin/cecutil.vim')
-rw-r--r--plugin/cecutil.vim482
1 files changed, 0 insertions, 482 deletions
diff --git a/plugin/cecutil.vim b/plugin/cecutil.vim
deleted file mode 100644
index 506b7bf..0000000
--- a/plugin/cecutil.vim
+++ /dev/null
@@ -1,482 +0,0 @@
1" cecutil.vim : save/restore window position
2" save/restore mark position
3" save/restore selected user maps
4" Author: Charles E. Campbell, Jr.
5" Version: 17
6" Date: Sep 04, 2007
7"
8" Saving Restoring Destroying Marks: {{{1
9" call SaveMark(markname) let savemark= SaveMark(markname)
10" call RestoreMark(markname) call RestoreMark(savemark)
11" call DestroyMark(markname)
12" commands: SM RM DM
13"
14" Saving Restoring Destroying Window Position: {{{1
15" call SaveWinPosn() let winposn= SaveWinPosn()
16" call RestoreWinPosn() call RestoreWinPosn(winposn)
17" \swp : save current window/buffer's position
18" \rwp : restore current window/buffer's previous position
19" commands: SWP RWP
20"
21" Saving And Restoring User Maps: {{{1
22" call SaveUserMaps(mapmode,maplead,mapchx,suffix)
23" call RestoreUserMaps(suffix)
24"
25" GetLatestVimScripts: 1066 1 :AutoInstall: cecutil.vim
26"
27" You believe that God is one. You do well. The demons also {{{1
28" believe, and shudder. But do you want to know, vain man, that
29" faith apart from works is dead? (James 2:19,20 WEB)
30
31" Load Once: {{{1
32if &cp || exists("g:loaded_cecutil")
33 finish
34endif
35let g:loaded_cecutil = "v17"
36let s:keepcpo = &cpo
37set cpo&vim
38"DechoVarOn
39
40" -----------------------
41" Public Interface: {{{1
42" -----------------------
43
44" Map Interface: {{{2
45if !hasmapto('<Plug>SaveWinPosn')
46 map <unique> <Leader>swp <Plug>SaveWinPosn
47endif
48if !hasmapto('<Plug>RestoreWinPosn')
49 map <unique> <Leader>rwp <Plug>RestoreWinPosn
50endif
51nmap <silent> <Plug>SaveWinPosn :call SaveWinPosn()<CR>
52nmap <silent> <Plug>RestoreWinPosn :call RestoreWinPosn()<CR>
53
54" Command Interface: {{{2
55com! -bar -nargs=0 SWP call SaveWinPosn()
56com! -bar -nargs=0 RWP call RestoreWinPosn()
57com! -bar -nargs=1 SM call SaveMark(<q-args>)
58com! -bar -nargs=1 RM call RestoreMark(<q-args>)
59com! -bar -nargs=1 DM call DestroyMark(<q-args>)
60
61if v:version < 630
62 let s:modifier= "sil "
63else
64 let s:modifier= "sil keepj "
65endif
66
67" ---------------------------------------------------------------------
68" SaveWinPosn: {{{1
69" let winposn= SaveWinPosn() will save window position in winposn variable
70" call SaveWinPosn() will save window position in b:cecutil_winposn{b:cecutil_iwinposn}
71" let winposn= SaveWinPosn(0) will *only* save window position in winposn variable (no stacking done)
72fun! SaveWinPosn(...)
73" call Dfunc("SaveWinPosn() a:0=".a:0)
74 if line(".") == 1 && getline(1) == ""
75" call Dfunc("SaveWinPosn : empty buffer")
76 return ""
77 endif
78 let so_keep = &so
79 let siso_keep = &siso
80 let ss_keep = &ss
81 set so=0 siso=0 ss=0
82
83 let swline = line(".")
84 let swcol = col(".")
85 let swwline = winline() - 1
86 let swwcol = virtcol(".") - wincol()
87 let savedposn = "call GoWinbufnr(".winbufnr(0).")|silent ".swline
88 let savedposn = savedposn."|".s:modifier."norm! 0z\<cr>"
89 if swwline > 0
90 let savedposn= savedposn.":".s:modifier."norm! ".swwline."\<c-y>\<cr>"
91 endif
92 if swwcol > 0
93 let savedposn= savedposn.":".s:modifier."norm! 0".swwcol."zl\<cr>"
94 endif
95 let savedposn = savedposn.":".s:modifier."call cursor(".swline.",".swcol.")\<cr>"
96
97 " save window position in
98 " b:cecutil_winposn_{iwinposn} (stack)
99 " only when SaveWinPosn() is used
100 if a:0 == 0
101 if !exists("b:cecutil_iwinposn")
102 let b:cecutil_iwinposn= 1
103 else
104 let b:cecutil_iwinposn= b:cecutil_iwinposn + 1
105 endif
106" call Decho("saving posn to SWP stack")
107 let b:cecutil_winposn{b:cecutil_iwinposn}= savedposn
108 endif
109
110 let &so = so_keep
111 let &siso = siso_keep
112 let &ss = ss_keep
113
114" if exists("b:cecutil_iwinposn") " Decho
115" call Decho("b:cecutil_winpos{".b:cecutil_iwinposn."}[".b:cecutil_winposn{b:cecutil_iwinposn}."]")
116" else " Decho
117" call Decho("b:cecutil_iwinposn doesn't exist")
118" endif " Decho
119" call Dret("SaveWinPosn [".savedposn."]")
120 return savedposn
121endfun
122
123" ---------------------------------------------------------------------
124" RestoreWinPosn: {{{1
125fun! RestoreWinPosn(...)
126" call Dfunc("RestoreWinPosn() a:0=".a:0)
127" call Decho("getline(1)<".getline(1).">")
128" call Decho("line(.)=".line("."))
129 if line(".") == 1 && getline(1) == ""
130" call Dfunc("RestoreWinPosn : empty buffer")
131 return ""
132 endif
133 let so_keep = &so
134 let siso_keep = &siso
135 let ss_keep = &ss
136 set so=0 siso=0 ss=0
137
138 if a:0 == 0 || a:1 == ""
139 " use saved window position in b:cecutil_winposn{b:cecutil_iwinposn} if it exists
140 if exists("b:cecutil_iwinposn") && exists("b:cecutil_winposn{b:cecutil_iwinposn}")
141" call Decho("using stack b:cecutil_winposn{".b:cecutil_iwinposn."}<".b:cecutil_winposn{b:cecutil_iwinposn}.">")
142 try
143 exe "silent! ".b:cecutil_winposn{b:cecutil_iwinposn}
144 catch /^Vim\%((\a\+)\)\=:E749/
145 " ignore empty buffer error messages
146 endtry
147 " normally drop top-of-stack by one
148 " but while new top-of-stack doesn't exist
149 " drop top-of-stack index by one again
150 if b:cecutil_iwinposn >= 1
151 unlet b:cecutil_winposn{b:cecutil_iwinposn}
152 let b:cecutil_iwinposn= b:cecutil_iwinposn - 1
153 while b:cecutil_iwinposn >= 1 && !exists("b:cecutil_winposn{b:cecutil_iwinposn}")
154 let b:cecutil_iwinposn= b:cecutil_iwinposn - 1
155 endwhile
156 if b:cecutil_iwinposn < 1
157 unlet b:cecutil_iwinposn
158 endif
159 endif
160 else
161 echohl WarningMsg
162 echomsg "***warning*** need to SaveWinPosn first!"
163 echohl None
164 endif
165
166 else " handle input argument
167" call Decho("using input a:1<".a:1.">")
168 " use window position passed to this function
169 exe "silent ".a:1
170 " remove a:1 pattern from b:cecutil_winposn{b:cecutil_iwinposn} stack
171 if exists("b:cecutil_iwinposn")
172 let jwinposn= b:cecutil_iwinposn
173 while jwinposn >= 1 " search for a:1 in iwinposn..1
174 if exists("b:cecutil_winposn{jwinposn}") " if it exists
175 if a:1 == b:cecutil_winposn{jwinposn} " and the pattern matches
176 unlet b:cecutil_winposn{jwinposn} " unlet it
177 if jwinposn == b:cecutil_iwinposn " if at top-of-stack
178 let b:cecutil_iwinposn= b:cecutil_iwinposn - 1 " drop stacktop by one
179 endif
180 endif
181 endif
182 let jwinposn= jwinposn - 1
183 endwhile
184 endif
185 endif
186
187 " seems to be something odd: vertical motions after RWP
188 " cause jump to first column. Following fixes that
189 if wincol() > 1
190 silent norm! hl
191 elseif virtcol(".") < virtcol("$")
192 silent norm! lh
193 endif
194
195 let &so = so_keep
196 let &siso = siso_keep
197 let &ss = ss_keep
198
199" call Dret("RestoreWinPosn")
200endfun
201
202" ---------------------------------------------------------------------
203" GoWinbufnr: go to window holding given buffer (by number) {{{1
204" Prefers current window; if its buffer number doesn't match,
205" then will try from topleft to bottom right
206fun! GoWinbufnr(bufnum)
207" call Dfunc("GoWinbufnr(".a:bufnum.")")
208 if winbufnr(0) == a:bufnum
209" call Dret("GoWinbufnr : winbufnr(0)==a:bufnum")
210 return
211 endif
212 winc t
213 let first=1
214 while winbufnr(0) != a:bufnum && (first || winnr() != 1)
215 winc w
216 let first= 0
217 endwhile
218" call Dret("GoWinbufnr")
219endfun
220
221" ---------------------------------------------------------------------
222" SaveMark: sets up a string saving a mark position. {{{1
223" For example, SaveMark("a")
224" Also sets up a global variable, g:savemark_{markname}
225fun! SaveMark(markname)
226" call Dfunc("SaveMark(markname<".a:markname.">)")
227 let markname= a:markname
228 if strpart(markname,0,1) !~ '\a'
229 let markname= strpart(markname,1,1)
230 endif
231" call Decho("markname=".markname)
232
233 let lzkeep = &lz
234 set lz
235
236 if 1 <= line("'".markname) && line("'".markname) <= line("$")
237 let winposn = SaveWinPosn(0)
238 exe s:modifier."norm! `".markname
239 let savemark = SaveWinPosn(0)
240 let g:savemark_{markname} = savemark
241 let savemark = markname.savemark
242 call RestoreWinPosn(winposn)
243 else
244 let g:savemark_{markname} = ""
245 let savemark = ""
246 endif
247
248 let &lz= lzkeep
249
250" call Dret("SaveMark : savemark<".savemark.">")
251 return savemark
252endfun
253
254" ---------------------------------------------------------------------
255" RestoreMark: {{{1
256" call RestoreMark("a") -or- call RestoreMark(savemark)
257fun! RestoreMark(markname)
258" call Dfunc("RestoreMark(markname<".a:markname.">)")
259
260 if strlen(a:markname) <= 0
261" call Dret("RestoreMark : no such mark")
262 return
263 endif
264 let markname= strpart(a:markname,0,1)
265 if markname !~ '\a'
266 " handles 'a -> a styles
267 let markname= strpart(a:markname,1,1)
268 endif
269" call Decho("markname=".markname." strlen(a:markname)=".strlen(a:markname))
270
271 let lzkeep = &lz
272 set lz
273 let winposn = SaveWinPosn(0)
274
275 if strlen(a:markname) <= 2
276 if exists("g:savemark_{markname}") && strlen(g:savemark_{markname}) != 0
277 " use global variable g:savemark_{markname}
278" call Decho("use savemark list")
279 call RestoreWinPosn(g:savemark_{markname})
280 exe "norm! m".markname
281 endif
282 else
283 " markname is a savemark command (string)
284" call Decho("use savemark command")
285 let markcmd= strpart(a:markname,1)
286 call RestoreWinPosn(markcmd)
287 exe "norm! m".markname
288 endif
289
290 call RestoreWinPosn(winposn)
291 let &lz = lzkeep
292
293" call Dret("RestoreMark")
294endfun
295
296" ---------------------------------------------------------------------
297" DestroyMark: {{{1
298" call DestroyMark("a") -- destroys mark
299fun! DestroyMark(markname)
300" call Dfunc("DestroyMark(markname<".a:markname.">)")
301
302 " save options and set to standard values
303 let reportkeep= &report
304 let lzkeep = &lz
305 set lz report=10000
306
307 let markname= strpart(a:markname,0,1)
308 if markname !~ '\a'
309 " handles 'a -> a styles
310 let markname= strpart(a:markname,1,1)
311 endif
312" call Decho("markname=".markname)
313
314 let curmod = &mod
315 let winposn = SaveWinPosn(0)
316 1
317 let lineone = getline(".")
318 exe "k".markname
319 d
320 put! =lineone
321 let &mod = curmod
322 call RestoreWinPosn(winposn)
323
324 " restore options to user settings
325 let &report = reportkeep
326 let &lz = lzkeep
327
328" call Dret("DestroyMark")
329endfun
330
331" ---------------------------------------------------------------------
332" QArgSplitter: to avoid \ processing by <f-args>, <q-args> is needed. {{{1
333" However, <q-args> doesn't split at all, so this one returns a list
334" with splits at all whitespace (only!), plus a leading length-of-list.
335" The resulting list: qarglist[0] corresponds to a:0
336" qarglist[i] corresponds to a:{i}
337fun! QArgSplitter(qarg)
338" call Dfunc("QArgSplitter(qarg<".a:qarg.">)")
339 let qarglist = split(a:qarg)
340 let qarglistlen = len(qarglist)
341 let qarglist = insert(qarglist,qarglistlen)
342" call Dret("QArgSplitter ".string(qarglist))
343 return qarglist
344endfun
345
346" ---------------------------------------------------------------------
347" ListWinPosn:
348"fun! ListWinPosn() " Decho
349" if !exists("b:cecutil_iwinposn") || b:cecutil_iwinposn == 0 " Decho
350" call Decho("nothing on SWP stack") " Decho
351" else " Decho
352" let jwinposn= b:cecutil_iwinposn " Decho
353" while jwinposn >= 1 " Decho
354" if exists("b:cecutil_winposn{jwinposn}") " Decho
355" call Decho("winposn{".jwinposn."}<".b:cecutil_winposn{jwinposn}.">") " Decho
356" else " Decho
357" call Decho("winposn{".jwinposn."} -- doesn't exist") " Decho
358" endif " Decho
359" let jwinposn= jwinposn - 1 " Decho
360" endwhile " Decho
361" endif " Decho
362"endfun " Decho
363"com! -nargs=0 LWP call ListWinPosn() " Decho
364
365" ---------------------------------------------------------------------
366" SaveUserMaps: this function sets up a script-variable (s:restoremap) {{{1
367" which can be used to restore user maps later with
368" call RestoreUserMaps()
369"
370" mapmode - see :help maparg for its list
371" ex. "n" = Normal
372" If the first letter is u, then unmapping will be done
373" ex. "un" = Normal + unmapping
374" maplead - see mapchx
375" mapchx - "<something>" handled as a single map item.
376" ex. "<left>"
377" - "string" a string of single letters which are actually
378" multiple two-letter maps (using the maplead:
379" maplead . each_character_in_string)
380" ex. maplead="\" and mapchx="abc" saves user mappings for
381" \a, \b, and \c
382" Of course, if maplead is "", then for mapchx="abc",
383" mappings for a, b, and c are saved.
384" - :something handled as a single map item, w/o the ":"
385" ex. mapchx= ":abc" will save a mapping for "abc"
386" suffix - a string unique to your plugin
387" ex. suffix= "DrawIt"
388fun! SaveUserMaps(mapmode,maplead,mapchx,suffix)
389" call Dfunc("SaveUserMaps(mapmode<".a:mapmode."> maplead<".a:maplead."> mapchx<".a:mapchx."> suffix<".a:suffix.">)")
390
391 if !exists("s:restoremap_{a:suffix}")
392 " initialize restoremap_suffix to null string
393 let s:restoremap_{a:suffix}= ""
394 endif
395
396 " set up dounmap: if 1, then save and unmap (a:mapmode leads with a "u")
397 " if 0, save only
398 if a:mapmode =~ '^u'
399 let dounmap= 1
400 let mapmode= strpart(a:mapmode,1)
401 else
402 let dounmap= 0
403 let mapmode= a:mapmode
404 endif
405
406 " save single map :...something...
407 if strpart(a:mapchx,0,1) == ':'
408 let amap= strpart(a:mapchx,1)
409 if amap == "|" || amap == "\<c-v>"
410 let amap= "\<c-v>".amap
411 endif
412 let amap = a:maplead.amap
413 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|:silent! ".mapmode."unmap ".amap
414 if maparg(amap,mapmode) != ""
415 let maprhs = substitute(maparg(amap,mapmode),'|','<bar>','ge')
416 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|:".mapmode."map ".amap." ".maprhs
417 endif
418 if dounmap
419 exe "silent! ".mapmode."unmap ".amap
420 endif
421
422 " save single map <something>
423 elseif strpart(a:mapchx,0,1) == '<'
424 let amap = a:mapchx
425 if amap == "|" || amap == "\<c-v>"
426 let amap= "\<c-v>".amap
427 endif
428 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|silent! ".mapmode."unmap ".amap
429 if maparg(a:mapchx,mapmode) != ""
430 let maprhs = substitute(maparg(amap,mapmode),'|','<bar>','ge')
431 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|".mapmode."map ".amap." ".maprhs
432 endif
433 if dounmap
434 exe "silent! ".mapmode."unmap ".amap
435 endif
436
437 " save multiple maps
438 else
439 let i= 1
440 while i <= strlen(a:mapchx)
441 let amap= a:maplead.strpart(a:mapchx,i-1,1)
442 if amap == "|" || amap == "\<c-v>"
443 let amap= "\<c-v>".amap
444 endif
445 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|silent! ".mapmode."unmap ".amap
446 if maparg(amap,mapmode) != ""
447 let maprhs = substitute(maparg(amap,mapmode),'|','<bar>','ge')
448 let s:restoremap_{a:suffix} = s:restoremap_{a:suffix}."|".mapmode."map ".amap." ".maprhs
449 endif
450 if dounmap
451 exe "silent! ".mapmode."unmap ".amap
452 endif
453 let i= i + 1
454 endwhile
455 endif
456" call Dret("SaveUserMaps : restoremap_".a:suffix.": ".s:restoremap_{a:suffix})
457endfun
458
459" ---------------------------------------------------------------------
460" RestoreUserMaps: {{{1
461" Used to restore user maps saved by SaveUserMaps()
462fun! RestoreUserMaps(suffix)
463" call Dfunc("RestoreUserMaps(suffix<".a:suffix.">)")
464 if exists("s:restoremap_{a:suffix}")
465 let s:restoremap_{a:suffix}= substitute(s:restoremap_{a:suffix},'|\s*$','','e')
466 if s:restoremap_{a:suffix} != ""
467" call Decho("exe ".s:restoremap_{a:suffix})
468 exe "silent! ".s:restoremap_{a:suffix}
469 endif
470 unlet s:restoremap_{a:suffix}
471 endif
472" call Dret("RestoreUserMaps")
473endfun
474
475" ---------------------------------------------------------------------
476" Restore: {{{1
477let &cpo= s:keepcpo
478unlet s:keepcpo
479
480" ---------------------------------------------------------------------
481" Modelines: {{{1
482" vim: ts=4 fdm=marker
..