Changeset 3750 for lang/vim/narrow/trunk

Show
Ignore:
Timestamp:
12/29/07 08:25:57 (11 months ago)
Author:
kana
Message:

lang/vim/narrow:
* Fix :Narrow and :Widen not to use temporary files. Now :Widen correctly

works even if the target buffer is :Narrow'ed by two or more Vim processes.

* Modify :Narrow to zz after narrowing for visibility.
* Modify :Narrow to include all lines of closed folds in [range].

Location:
lang/vim/narrow/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/vim/narrow/trunk/autoload/narrow.vim

    r3648 r3750  
    11" narrow - Emulate Emacs' narrowing feature 
    2 " Version: 0.1 
     2" Version: 0.2 
    33" Copyright (C) 2007 kana <http://nicht.s8.xrea.com/> 
    44" License: MIT license (see <http://www.opensource.org/licenses/mit-license>) 
     
    1919  endif 
    2020 
     21  let line1 = s:normalize_line(a:line1, 'head') 
     22  let line2 = s:normalize_line(a:line2, 'tail') 
     23 
    2124  setlocal foldenable 
    2225  setlocal foldmethod=manual 
    2326  setlocal foldtext='' 
    24   call s:adjust_cursor_if_invoked_via_visual_mode(a:line1, a:line2) 
     27  call s:adjust_cursor_if_invoked_via_visual_mode(line1, line2) 
    2528  let pos = getpos('.') 
    2629    call s:clear_all_folds() 
    27     call s:fold_before(a:line1) 
    28     call s:fold_after(a:line2) 
     30    call s:fold_before(line1) 
     31    call s:fold_after(line2) 
    2932  call setpos('.', pos) 
     33  normal! zz 
    3034  return 1 
    3135endfunction 
     
    7781 
    7882 
     83function! s:normalize_line(line, mode)  "{{{2 
     84  " Return the first/last line number of a closed fold if a:line is contained 
     85  " the fold, otherwise return a:line as is. 
     86  let pline = (a:mode ==# 'head' ? foldclosed(a:line) : foldclosedend(a:line)) 
     87  return 0 < pline ? pline : a:line 
     88endfunction 
     89 
     90 
     91 
     92 
    7993function! s:fold_before(line)  "{{{2 
    8094  if 1 < a:line 
     
    106120 
    107121 
    108 " view options  "{{{2 
    109 function! s:set_view_options() 
    110   let s:original_viewdir = &viewdir 
    111   let &viewdir = s:original_viewdir . '/narrow' 
    112   let s:original_viewoptions = &viewoptions 
    113   let &viewoptions = 'folds' 
    114 endfunction 
    115  
    116 function! s:restore_view_options() 
    117   let &viewdir = s:original_viewdir 
    118   let &viewoptions = s:original_viewoptions 
    119 endfunction 
    120  
    121  
    122  
    123  
    124122function! s:save_the_state_of_buffer()  "{{{2 
    125   call s:set_view_options() 
    126     " BUGS: :mkview doesn't create intermediate directories. 
    127     if !isdirectory(&viewdir) 
    128       call mkdir(&viewdir, 'p', 0700) 
    129     endif 
    130     " BUGS: :mkview doesn't save folds info when &l:buftype isn't ''. 
    131     let original_buftype = &l:buftype 
    132     let &l:buftype = '' 
    133       mkview 
    134     let &l:buftype = original_buftype 
    135   call s:restore_view_options() 
    136  
    137123  let original_state = {} 
    138124  let original_state.foldenable = &l:foldenable 
    139125  let original_state.foldmethod = &l:foldmethod 
    140126  let original_state.foldtext = &l:foldtext 
     127 
     128  " save folds 
     129  let original_state.foldstate = [] 
     130  let original_pos = getpos('.') 
     131  let line = 1 
     132  while line <= line('$') 
     133    if 0 < foldclosed(line)  " is the first line of a fold? 
     134      call add(original_state.foldstate, line) 
     135      let line = foldclosedend(line) + 1 
     136    else 
     137      let previous_line = line 
     138      call cursor(previous_line, 0) 
     139      normal! zj 
     140      let line = line('.') 
     141      if line == previous_line 
     142        break  " no more folds. 
     143      endif 
     144    endif 
     145  endwhile 
     146  call setpos('.', original_pos) 
     147 
    141148  return original_state 
    142149endfunction 
     
    146153 
    147154function! s:load_the_state_of_buffer(original_state)  "{{{2 
    148   call s:set_view_options() 
    149   loadview 
    150   call s:restore_view_options() 
    151  
    152155  let &l:foldenable = a:original_state.foldenable 
    153156  let &l:foldmethod = a:original_state.foldmethod 
    154157  let &l:foldtext = a:original_state.foldtext 
     158 
     159  " restore folds. 
     160  %foldopen! 
     161  for line in a:original_state.foldstate 
     162    call cursor(line, 0) 
     163    foldclose 
     164  endfor 
    155165endfunction 
    156166 
  • lang/vim/narrow/trunk/doc/narrow.txt

    r3648 r3750  
    11*narrow.txt*    Emulate Emacs' narrowing feature 
    22 
    3 Version 0.1 
     3Version 0.2 
    44Copyright (C) 2007 kana <http://nicht.s8.xrea.com/> 
    55License: MIT license (see <http://www.opensource.org/licenses/mit-license>) 
     
    8181  In Emacs, these actions aren't allowed. 
    8282 
    83 - This plugin uses |:mkview| to save the current state of a buffer for 
    84   |:Widen|, and and |:mkview| writes a file.  So this plugin may be confused 
    85   when there are two or more Vim processes and they narrow/widen the same 
    86   buffers. 
    87  
    88 - Temporary files written by |:mkview| will be created in the "narrow" 
    89   subdirectory in 'viewdir'.  For example, "~/.vim/view/narrow". 
    90  
    9183 
    9284 
     
    9486============================================================================== 
    9587CHANGELOG                                       *narrow-changelog* 
     88 
     890.2     2007-12-29T07:24:53+09:00 
     90        - Fix |:Narrow| and |:Widen| not to use temporary files.  Now |:Widen| 
     91          correctly works even if the target buffer is |:Narrow|'ed by two or 
     92          more Vim processes. 
     93        - Modify |:Narrow| to |zz| after narrowing for visibility. 
     94        - Modify |:Narrow| to include all lines of closed folds in [range]. 
    9695 
    97960.1     2007-12-28T01:13:48+09:00 
  • lang/vim/narrow/trunk/plugin/narrow.vim

    r3648 r3750  
    11" narrow - Emulate Emacs' narrowing feature 
    2 " Version: 0.1 
     2" Version: 0.2 
    33" Copyright (C) 2007 kana <http://nicht.s8.xrea.com/> 
    44" License: MIT license (see <http://www.opensource.org/licenses/mit-license>)