Skip to content

Commit

Permalink
Version 0.33
Browse files Browse the repository at this point in the history
- tlib#agent#Exit: explicitly return empty value (as a consequence,
pressing <esc> when browsing an index-list, returns 0 and not "")
- tlib#signs
- tlib#input#List: set local statusline
- Don't reset statusline
- Don't use fnamemodify() to split filenames (for performance reasons)
- scratch: Set ft after setting up scratch options
- tlib#map#PumAccept(key)
  • Loading branch information
tomtom authored and vim-scripts committed Oct 18, 2010
1 parent f886285 commit 3654b70
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 107 deletions.
73 changes: 47 additions & 26 deletions autoload/tlib/World.vim
Expand Up @@ -3,8 +3,8 @@
" @Website: http://members.a1.net/t.link/
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-05-01.
" @Last Change: 2009-02-25.
" @Revision: 0.1.696
" @Last Change: 2009-08-23.
" @Revision: 0.1.738

" :filedoc:
" A prototype used by |tlib#input#List|.
Expand Down Expand Up @@ -103,16 +103,25 @@ endf

" :nodoc:
function! s:prototype.FormatFilename(file) dict "{{{3
let fname = fnamemodify(a:file, ":p:t")
" let fname = fnamemodify(a:file, ":t")
" if isdirectory(a:file)
" let fname .='/'
" endif
let dname = fnamemodify(a:file, ":h")
let width = eval(g:tlib_inputlist_width_filename)
let split = match(a:file, '[/\\]\zs[^/\\]\+$')
if split == -1
let fname = ''
let dname = a:file
else
let fname = strpart(a:file, split)
let dname = strpart(a:file, 0, split - 1)
endif
" let fname = fnamemodify(a:file, ":p:t")
" " let fname = fnamemodify(a:file, ":t")
" " if isdirectory(a:file)
" " let fname .='/'
" " endif
" let dname = fnamemodify(a:file, ":h")
" let dname = pathshorten(fnamemodify(a:file, ":h"))
let dnmax = &co - max([eval(g:tlib_inputlist_width_filename), len(fname)]) - 11 - self.index_width - &fdc
let dnmax = &co - max([width, len(fname)]) - 11 - self.index_width - &fdc
if len(dname) > dnmax
let dname = '...'. strpart(fnamemodify(a:file, ":h"), len(dname) - dnmax)
let dname = '...'. strpart(dname, len(dname) - dnmax)
endif
let marker = []
if g:tlib_inputlist_filename_indicators
Expand Down Expand Up @@ -525,6 +534,7 @@ function! s:prototype.CloseScratch(...) dict "{{{3
return 0
else
let rv = tlib#scratch#CloseScratch(self, reset_scratch)
" TLogVAR rv
if rv
call self.SwitchWindow('win')
endif
Expand Down Expand Up @@ -677,6 +687,7 @@ function! s:prototype.DisplayList(query, ...) dict "{{{3
elseif self.state == 'help'
call self.DisplayHelp()
else
" TLogVAR query
" let ll = len(list)
let ll = self.llen
" let x = len(ll) + 1
Expand Down Expand Up @@ -713,15 +724,16 @@ function! s:prototype.DisplayList(query, ...) dict "{{{3
call add(b:tlibDisplayListMarks, base_pref)
call self.DisplayListMark(x, base_pref, '*')
call self.SetOffset()
call self.SetStatusline(a:query)
" TLogVAR self.offset
" TLogDBG winheight('.')
" if self.prefidx > winheight(0)
" let lt = len(list) - winheight('.') + 1
" if self.offset > lt
" exec 'norm! '. lt .'zt'
" else
exec 'norm! '. self.offset .'zt'
" endif
" let lt = len(list) - winheight('.') + 1
" if self.offset > lt
" exec 'norm! '. lt .'zt'
" else
exec 'norm! '. self.offset .'zt'
" endif
" else
" norm! 1zt
" endif
Expand All @@ -734,21 +746,30 @@ function! s:prototype.DisplayList(query, ...) dict "{{{3
exec 'match '. g:tlib_inputlist_higroup .' /\c'. escape(rx0, '/') .'/'
endif
endif
let query = a:query
let options = [self.matcher.name]
if self.sticky
call add(options, '#')
endif
if !empty(options)
let query .= printf('%%=[%s] ', join(options, ', '))
endif
" TLogVAR query
let &statusline = query
endif
redraw
endf


function! s:prototype.SetStatusline(query) dict "{{{3
let query = a:query
let options = [self.matcher.name]
if self.sticky
call add(options, '#')
endif
if !empty(options)
let sopts = printf('[%s]', join(options, ', '))
" let echo = query . repeat(' ', &columns - len(sopts) - len(query) - 20) . sopts
let echo = query . ' ' . sopts
" let query .= '%%='. sopts .' '
endif
" TLogVAR &l:statusline, query
" let &l:statusline = query
echo
echo echo
endf


" :nodoc:
function! s:prototype.SetOffset() dict "{{{3
" TLogVAR self.prefidx, self.offset
Expand Down
12 changes: 7 additions & 5 deletions autoload/tlib/agent.vim
Expand Up @@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-24.
" @Last Change: 2009-02-25.
" @Revision: 0.1.168
" @Last Change: 2009-08-04.
" @Revision: 0.1.172

if &cp || exists("loaded_tlib_agent_autoload") "{{{2
finish
Expand All @@ -18,7 +18,7 @@ let loaded_tlib_agent_autoload = 1

function! tlib#agent#Exit(world, selected) "{{{3
call a:world.CloseScratch()
let a:world.state = 'exit escape'
let a:world.state = 'exit empty escape'
let a:world.list = []
" let a:world.base = []
call a:world.ResetSelected()
Expand Down Expand Up @@ -475,12 +475,14 @@ function! tlib#agent#DoAtLine(world, selected) "{{{3
let cmd = input('Command: ', '', 'command')
if !empty(cmd)
call a:world.SwitchWindow('win')
let pos = getpos('.')
" let pos = getpos('.')
let view = winsaveview()
for l in a:selected
call tlib#buffer#ViewLine(l, '')
exec cmd
endfor
call setpos('.', pos)
" call setpos('.', pos)
call winrestview(view)
endif
endif
call a:world.ResetSelected()
Expand Down
60 changes: 37 additions & 23 deletions autoload/tlib/buffer.vim
Expand Up @@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-30.
" @Last Change: 2009-02-15.
" @Revision: 0.0.268
" @Last Change: 2009-08-17.
" @Revision: 0.0.283

if &cp || exists("loaded_tlib_buffer_autoload")
finish
Expand Down Expand Up @@ -238,9 +238,11 @@ endf
" Insert text (a string) in the buffer.
function! tlib#buffer#InsertText(text, ...) "{{{3
TVarArg ['keyargs', {}]
" TLogVAR a:text, keyargs
TKeyArg keyargs, ['shift', 0], ['col', col('.')], ['lineno', line('.')], ['pos', 'e'],
\ ['indent', 0]
" TLogVAR shift, col, lineno, pos, indent
let grow = 0
let post_del_last_line = line('$') == 1
let line = getline(lineno)
if col + shift > 0
Expand All @@ -259,24 +261,29 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
call cursor(lineno, col)
if indent && col > 1
if &fo =~# '[or]'
" This doesn't work because it's not guaranteed that the
" cursor is set.
let cline = getline('.')
norm! a
"norm! o
" TAssertExec redraw | sleep 3
let idt = strpart(getline('.'), 0, col('.') + shift)
" TLogVAR idt
let idtl = len(idt)
-1,.delete
" TAssertExec redraw | sleep 3
call append(lineno - 1, cline)
call cursor(lineno, col)
" TAssertExec redraw | sleep 3
if idtl == 0 && icol != 0
let idt = matchstr(pre, '^\s\+')
let idtl = len(idt)
endif
" FIXME: Is the simple version sufficient?
" VERSION 1
" " This doesn't work because it's not guaranteed that the
" " cursor is set.
" let cline = getline('.')
" norm! a
" "norm! o
" " TAssertExec redraw | sleep 3
" let idt = strpart(getline('.'), 0, col('.') + shift)
" " TLogVAR idt
" let idtl = len(idt)
" -1,.delete
" " TAssertExec redraw | sleep 3
" call append(lineno - 1, cline)
" call cursor(lineno, col)
" " TAssertExec redraw | sleep 3
" if idtl == 0 && icol != 0
" let idt = matchstr(pre, '^\s\+')
" let idtl = len(idt)
" endif
" VERSION 2
let idt = matchstr(pre, '^\s\+')
let idtl = len(idt)
else
let [m_0, idt, iline; rest] = matchlist(pre, '^\(\s*\)\(.*\)$')
let idtl = len(idt)
Expand All @@ -285,11 +292,13 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
let idt .= repeat(' ', icol - idtl)
endif
" TLogVAR idt
let idtl1 = len(idt)
for i in range(1, len(text) - 1)
let text[i] = idt . text[i]
let grow += idtl1
endfor
" TLogVAR text
endif
" TLogVAR text
" exec 'norm! '. lineno .'Gdd'
call tlib#normal#WithRegister('"tdd', 't')
call append(lineno - 1, text)
Expand All @@ -298,17 +307,20 @@ function! tlib#buffer#InsertText(text, ...) "{{{3
endif
let tlen = len(text)
let posshift = matchstr(pos, '\d\+')
" TLogVAR pos
if pos =~ '^e'
exec lineno + tlen - 1
exec 'norm! 0'. (len(text[-1]) - len(post) + posshift - 1) .'l'
elseif pos =~ '^s'
" TLogVAR lineno, pre, posshift
exec lineno
exec 'norm! '. len(pre) .'|'
if !empty(posshift)
exec 'norm! '. posshift .'h'
endif
endif
" TLogDBG string(getline(1, '$'))
return grow
endf


Expand Down Expand Up @@ -338,11 +350,13 @@ endf

" Evaluate cmd while maintaining the cursor position and jump registers.
function! tlib#buffer#KeepCursorPosition(cmd) "{{{3
let pos = getpos('.')
" let pos = getpos('.')
let view = winsaveview()
try
keepjumps exec a:cmd
finally
call setpos('.', pos)
" call setpos('.', pos)
call winrestview(view)
endtry
endf

8 changes: 4 additions & 4 deletions autoload/tlib/dir.vim
Expand Up @@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-30.
" @Last Change: 2009-02-15.
" @Revision: 0.0.29
" @Last Change: 2009-08-04.
" @Revision: 0.0.32

if &cp || exists("loaded_tlib_dir_autoload")
finish
Expand All @@ -29,7 +29,7 @@ endf
" => 'foo/bar'
function! tlib#dir#PlainName(dirname) "{{{3
let dirname = a:dirname
while dirname[-1 : -1] == g:tlib_filename_sep
while index(['/', '\'], dirname[-1 : -1]) != -1
let dirname = dirname[0 : -2]
endwh
return dirname
Expand Down Expand Up @@ -59,7 +59,7 @@ function! tlib#dir#CD(dir, ...) "{{{3
let cmd = locally ? 'lcd ' : 'cd '
" let cwd = getcwd()
let cmd .= tlib#arg#Ex(a:dir)
" TLogVAR cmd
" TLogVAR a:dir, locally, cmd
exec cmd
" return cwd
return getcwd()
Expand Down
7 changes: 4 additions & 3 deletions autoload/tlib/file.vim
Expand Up @@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-06-30.
" @Last Change: 2009-02-25.
" @Revision: 0.0.65
" @Last Change: 2009-03-13.
" @Revision: 0.0.67

if &cp || exists("loaded_tlib_file_autoload")
finish
Expand Down Expand Up @@ -43,7 +43,8 @@ endf
function! tlib#file#Join(filename_parts, ...) "{{{3
TVarArg 'strip_slashes'
if strip_slashes
let rx = tlib#rx#Escape(g:tlib_filename_sep) .'$'
" let rx = tlib#rx#Escape(g:tlib_filename_sep) .'$'
let rx = '[/\\]$'
let parts = map(copy(a:filename_parts), 'substitute(v:val, rx, "", "")')
return join(parts, g:tlib_filename_sep)
else
Expand Down

0 comments on commit 3654b70

Please sign in to comment.