Permalink
Browse files

Toggle marks, jump to prev/next mark

  • Loading branch information...
1 parent 9696404 commit 41ec3b7ada469b4c57b3c0a579e8210cba8cc959 @tomtom committed Oct 23, 2010
Showing with 129 additions and 68 deletions.
  1. +104 −54 autoload/tmarks.vim
  2. +25 −14 plugin/tmarks.vim
View
@@ -3,12 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2009-03-29.
-" @Last Change: 2010-01-17.
-" @Revision: 0.0.28
-
-let s:save_cpo = &cpo
-set cpo&vim
-" call tlog#Log('Load: '. expand('<sfile>')) " vimtlib-sfile
+" @Last Change: 2010-10-23.
+" @Revision: 0.0.109
if !exists('g:tmarks_handlers') "{{{2
@@ -19,6 +15,7 @@ if !exists('g:tmarks_handlers') "{{{2
endif
+" :nodoc:
function! tmarks#AgentDeleteMark(world, selected) "{{{3
for l in a:selected
call s:DelMark(s:GetMark(l))
@@ -39,10 +36,17 @@ function! s:GetList() "{{{3
endf
-function! s:GetLocalList() "{{{3
+function! s:GetLocalMarks(key_is_mark) "{{{3
let local_marks = s:GetList()
call filter(local_marks, 'v:val =~ '' \l ''')
- return local_marks
+ let marks = {}
+ for line in local_marks
+ let ml = matchlist(line, '^\s\(\l\)\s\+\(\d\+\)')[1:2]
+ if !empty(ml)
+ let marks[ml[!a:key_is_mark]] = ml[!!a:key_is_mark]
+ endif
+ endfor
+ return marks
endf
@@ -51,6 +55,7 @@ function! s:GetMark(line) "{{{3
endf
+" :nodoc:
function! tmarks#List() "{{{3
keepjumps let m = tlib#input#List('s', 'Marks', s:GetList(), g:tmarks_handlers)
if !empty(m)
@@ -59,49 +64,94 @@ function! tmarks#List() "{{{3
endf
-" " Use wokmarks instead:
-"
-" " Delete all (lower-case) marks at the specified line.
-" " :display: tmarks#DeleteInRange(?line1=line('.'), ?line2=line('.'))
-" function! tmarks#DeleteInRange(...) "{{{3
-" TVarArg ['line1', line('.')], ['line2', line('.')]
-" let local_marks = s:GetLocalList()
-" call filter(local_marks, 'matchstr(v:val, ''\l \+\zs\d\+'') >= line1 && matchstr(v:val, ''\l \+\zs\d\+'') <= line2')
-" for mark in local_marks
-" call s:DelMark(s:GetMark(mark))
-" endfor
-" endf
-"
-"
-" " Delete all (lower-case) marks for the current buffer.
-" function! tmarks#DeleteAllMarks() "{{{3
-" let local_marks = s:GetLocalList()
-" for mark in local_marks
-" call s:DelMark(s:GetMark(mark))
-" endfor
-" endf
-"
-"
-" let s:local_marks = split('abcdefghijklmnopqrstuvwxyz', '\zs')
-"
-" function! tmarks#PlaceNextMarkAtLine(...) "{{{3
-" TVarArg ['line', line('.')]
-" let local_marks = s:GetLocalList()
-" let i = 0
-" for mark in local_marks
-" let this = s:GetMark(mark)
-" let that = s:local_marks[i]
-" if this !=# that
-" exec line .'mark '. that
-" return
-" endif
-" let i += 1
-" endfor
-" echohl Error
-" echom 'TMarks: No mark available'
-" echohl None
-" endf
-
-
-let &cpo = s:save_cpo
-unlet s:save_cpo
+" Delete all (lower-case) marks at the specified line.
+" :display: tmarks#DeleteInRange(?line1=line('.'), ?line2=line('.'))
+" :nodoc:
+function! tmarks#DeleteInRange(...) "{{{3
+ TVarArg ['line1', line('.')], ['line2', line('.')]
+ for [line, mark] in items(s:GetLocalMarks(0))
+ if line >= line1 && line <= line2
+ call s:DelMark(mark)
+ endif
+ endfor
+endf
+
+
+" Delete all (lower-case) marks for the current buffer.
+" :nodoc:
+function! tmarks#DeleteAllMarks() "{{{3
+ for mark in keys(s:GetLocalMarks(1))
+ call s:DelMark(mark)
+ endfor
+endf
+
+
+let s:local_marks = split('abcdefghijklmnopqrstuvwxyz', '\zs')
+
+
+" :display: tmarks#ToggleMarkAtLine(?line='.')
+" Toggle the mark at line.
+function! tmarks#ToggleMarkAtLine(...) "{{{3
+ TVarArg ['line', line('.')]
+ if line =~ '^\.\?$'
+ let line = line('.')
+ endif
+ let lines = s:GetLocalMarks(0)
+ " TLogVAR lines, marks
+ if has_key(lines, line)
+ let mark = lines[line]
+ call s:DelMark(mark)
+ echom 'Remove mark' mark 'at line' line
+ return
+ else
+ let marks = s:GetLocalMarks(1)
+ for mark in s:local_marks
+ if !has_key(marks, mark)
+ exec line .'mark '. mark
+ echom 'Set mark' mark 'at line' line
+ return
+ endif
+ endfor
+ endif
+ echohl Error
+ echom 'TMarks: No mark available'
+ echohl None
+endf
+
+
+function! tmarks#Next(count) "{{{3
+ let cnt = a:count
+ let cul = line('.')
+ " TLogVAR cnt, cul
+ let lines = keys(s:GetLocalMarks(0))
+ if !empty(lines)
+ call map(lines, 'printf("%99s", v:val)')
+ call sort(lines)
+ call map(lines, '0 + matchstr(v:val, ''\d\+'')')
+ " TLogVAR lines
+ if cnt > 0
+ let lines = filter(copy(lines), 'v:val > cul')
+ \ + filter(copy(lines), 'v:val <= cul')
+ while cnt > 1
+ " TLogVAR cnt, lines
+ let lines = add(lines[1 : -1], lines[0])
+ let cnt -= 1
+ endwh
+ elseif cnt < 0
+ let lines = reverse(filter(copy(lines), 'v:val < cul'))
+ \ + reverse(filter(copy(lines), 'v:val >= cul'))
+ while cnt < -1
+ " TLogVAR cnt, lines
+ let lines = add(lines[1 : -1], lines[0])
+ let cnt += 1
+ endwh
+ endif
+ " TLogVAR lines
+ let line = lines[0]
+ " TLogVAR line
+ exec line
+ endif
+endf
+
+
+
View
@@ -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-08-23.
-" @Last Change: 2010-01-17.
-" @Revision: 0.0.54
+" @Last Change: 2010-10-23.
+" @Revision: 0.0.65
" GetLatestVimScripts: <+SCRIPTID+> 1 tmarks.vim
if &cp || exists("loaded_tmarks")
@@ -26,18 +26,29 @@ set cpo&vim
command! -bar TMarks call tmarks#List()
-" " Use wokmarks instead:
-" "
-" " Place the next available a-z mark at the specified line.
-" " :display: :{range}TMarksPlace
-" command! -range -nargs=? -bar TMarksPlace call tmarks#PlaceNextMarkAtLine(<line1>)
-"
-" " Delete all a-z marks in range.
-" " :display: :{range}TMarksDelete
-" command! -range -nargs=? -bar TMarksDelete call tmarks#DeleteInRange(<line1>, <line2>)
-"
-" " Delete all a-z marks in the current buffer.
-" command! -bar TMarksDeleteAll call tmarks#DeleteAllMarks()
+" Place the next available a-z mark at the specified line.
+" :display: :{range}TMarkstoggle
+command! -range -nargs=? -bar TMarkstoggle call tmarks#ToggleMarkAtLine(<line1>)
+
+" Delete all a-z marks in range.
+" :display: :{range}TMarksdelete
+command! -range -nargs=? -bar TMarksdelete call tmarks#DeleteInRange(<line1>, <line2>)
+
+" Delete all a-z marks in the current buffer.
+" :display: :TMarksdeleteall
+command! -bar TMarksdeleteall call tmarks#DeleteAllMarks()
+
+" Jump to the nth prev/next mark.
+" :display: :TMarksnext
+command! -count=1 -bar TMarksnext call tmarks#Next(<count>)
+
+
+echom exists('g:tmarks_key')
+if exists('g:tmarks_key')
+ exec 'map <silent> <'. g:tmarks_key .'> :<c-u>call tmarks#Next(v:count1)<cr>'
+ exec 'map <silent> <s-'. g:tmarks_key .'> :<c-u>call tmarks#Next(-v:count1)<cr>'
+ exec 'map <silent> <c-'. g:tmarks_key .'> :call tmarks#ToggleMarkAtLine()<cr>'
+endif
let &cpo = s:save_cpo

0 comments on commit 41ec3b7

Please sign in to comment.