From bbf00637100e60543c0bc409eaeef68c679aebf0 Mon Sep 17 00:00:00 2001 From: Jeet Sukumaran Date: Thu, 13 Mar 2014 18:52:39 -0400 Subject: [PATCH 1/4] Add support for highlighting locally-marked lines --- plugin/mark_tools.vim | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/plugin/mark_tools.vim b/plugin/mark_tools.vim index 393c529..991d643 100644 --- a/plugin/mark_tools.vim +++ b/plugin/mark_tools.vim @@ -69,6 +69,36 @@ if exists("loaded_toggle_local_marks") endif let loaded_toggle_local_marks = 1 +let s:marktools_highlight_group = "MarkToolsHighlight" +if !hlexists(s:marktools_highlight_group) + execute "hi " . s:marktools_highlight_group . " term=reverse cterm=reverse gui=undercurl guisp=green" +endif +function! s:clear_previously_set_matches() + let cleared_matches = [] + let mm = getmatches() + for m in mm + if m['group'] == s:marktools_highlight_group + call matchdelete(m['id']) + call add(cleared_matches, m['id']) + endif + endfor + return cleared_matches +endfunction + +" state 0 = forced off, state 1 = forced on, state 2 = toggle +function! s:highlight_marks(state) + if !exists("g:marktools_highlight_marked_lines") || g:marktools_highlight_marked_lines == 1 + let cleared_matches = s:clear_previously_set_matches() + if (a:state == 1) || (a:state == 2 && empty(cleared_matches)) + let index = char2nr('a') + while index < char2nr('z') + call matchadd(s:marktools_highlight_group, '\%'.line( "'".nr2char(index)).'l') + let index = index + 1 + endwhile + endif + endif +endfunction + unlockvar s:marks_names unlockvar s:marks_count unlockvar s:marks_nlist @@ -149,6 +179,7 @@ function! s:ToggleMarks(a2z, forceAdd) else exec 'delma ' . l:marks_here[strlen(l:marks_here)-1] endif + call s:highlight_marks(1) else " no marks, add first available mark let l:used = s:UsedMarks() @@ -157,6 +188,7 @@ function! s:ToggleMarks(a2z, forceAdd) for i in range(0, l:len-1) if l:used[i] == ' ' exec "normal m" . s:marks_names[i] + call s:highlight_marks(1) return endif endfor @@ -164,11 +196,13 @@ function! s:ToggleMarks(a2z, forceAdd) for i in range(l:len-1, 0, -1) if l:used[i] == ' ' exec "normal m" . s:marks_names[i] + call s:highlight_marks(1) return endif endfor endif endif + call s:highlight_marks(1) endfunction function! s:GetWrapSearch() @@ -305,5 +339,7 @@ nnoremap PrevMarkLexi :call PrevByAlpha() " suggested mapping: w and W nnoremap MarksLoc :call MarksLoc() nnoremap MarksQF :call MarksQF() +" suggested mapping: ! +nnoremap MarksHighlightToggle :call highlight_marks(2) let &cpo = s:save_cpo From 1d603a80635c11516848506b29108b48d5c42b7c Mon Sep 17 00:00:00 2001 From: Jeet Sukumaran Date: Thu, 13 Mar 2014 19:17:06 -0400 Subject: [PATCH 2/4] Support for entering buffer with highlights on --- plugin/mark_tools.vim | 57 ++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 14 deletions(-) diff --git a/plugin/mark_tools.vim b/plugin/mark_tools.vim index 991d643..c0eaf5c 100644 --- a/plugin/mark_tools.vim +++ b/plugin/mark_tools.vim @@ -19,6 +19,7 @@ " PrevMarkLexi- go to next mark in lexicographical order " MarksLoc - open location list window with local mark positions " MarksQF - open quickfix window with marks +" MarksHighlightToggle - toggle highlighting of matched lines " " recommended mapping: " nmap a ToggleMarkAZ @@ -31,6 +32,7 @@ " nmap L PrevMarkLexi " nmap w MarksLoc " nmap W MarksQF +" nmap ! MarksHighlightToggle " so " \a and \z toggle a mark at current line " \A and \Z force another mark @@ -42,24 +44,35 @@ " e.g. quickfixsigns (http://www.vim.org/scripts/script.php?script_id=2584) " " CUSTOMISATION: -" toggle_marks_wrap_search variable controls whether search wraps around or not -" (order of precedence: w:toggle_marks_wrap_search, b:toggle_marks_wrap_search, g:toggle_marks_wrap_search) -" Possible values: -" -1 - use 'wrapscan' option value -" 0 - do not wrap -" 1 - always wrap (default) " -" To customise marks which you want to see in location list and quickfix -" windows you can override variables below: -" let g:lmarks_names = 'abcdefghijklmnopqrstuvwxyz''.' -" let g:gmarks_names = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' +" `toggle_marks_wrap_search` variable controls whether search wraps around or not +" (order of precedence: w:toggle_marks_wrap_search, b:toggle_marks_wrap_search, g:toggle_marks_wrap_search) +" Possible values: +" -1 - use 'wrapscan' option value +" 0 - do not wrap +" 1 - always wrap (default) +" +" `g:marktools_highlight_marked_lines` controls whether or not lines are +" highlighted as they are marked +" 0 - do not highlight +" 1 - highlight (default) +" +" `marktools_highlight_default_on` controls whether lines whether marks +" already in the buffer are highlighted +" 0 - begin with highlighting off (default) +" 1 - begin with highlighting on +" +" To customise marks which you want to see in location list and quickfix +" windows you can override variables below: +" let g:lmarks_names = 'abcdefghijklmnopqrstuvwxyz''.' +" let g:gmarks_names = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' " " When using \w and \W with quickfixsigns plugin, you may want to protect mark signs from " quickfix signs with: -" let g:quickfixsigns_lists = [ -" \ {'sign': 'QFS_QFL', 'get': 'g:NonMarkQFEntries()', 'event': ['BufEnter']}, -" \ {'sign': 'QFS_LOC', 'get': 'g:NonMarkLocEntries(winnr())', 'event': ['BufEnter']}, -" \ ] +" let g:quickfixsigns_lists = [ +" \ {'sign': 'QFS_QFL', 'get': 'g:NonMarkQFEntries()', 'event': ['BufEnter']}, +" \ {'sign': 'QFS_LOC', 'get': 'g:NonMarkLocEntries(winnr())', 'event': ['BufEnter']}, +" \ ] let s:save_cpo = &cpo set cpo&vim @@ -73,6 +86,7 @@ let s:marktools_highlight_group = "MarkToolsHighlight" if !hlexists(s:marktools_highlight_group) execute "hi " . s:marktools_highlight_group . " term=reverse cterm=reverse gui=undercurl guisp=green" endif + function! s:clear_previously_set_matches() let cleared_matches = [] let mm = getmatches() @@ -99,6 +113,21 @@ function! s:highlight_marks(state) endif endfunction +function! s:set_initial_highlight() + if !exists("b:marktools_highlighted") + call highlight_marks(1) + let b:marktools_highlighted = 1 + endif +endfunction +if exists("g:marktools_highlight_default_on") && g:marktools_highlight_default_on == 1 + if has("autocmd") + augroup MarkToolsHighlightCommands + autocmd! + autocmd BufEnter * :call set_initial_highlight() + augroup end + endif +endif + unlockvar s:marks_names unlockvar s:marks_count unlockvar s:marks_nlist From f93ab03884b10ede4a0495565b0aebabcdf6f847 Mon Sep 17 00:00:00 2001 From: Jeet Sukumaran Date: Thu, 13 Mar 2014 19:21:20 -0400 Subject: [PATCH 3/4] Support for clearing all marks --- plugin/mark_tools.vim | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugin/mark_tools.vim b/plugin/mark_tools.vim index c0eaf5c..063ccb7 100644 --- a/plugin/mark_tools.vim +++ b/plugin/mark_tools.vim @@ -20,6 +20,7 @@ " MarksLoc - open location list window with local mark positions " MarksQF - open quickfix window with marks " MarksHighlightToggle - toggle highlighting of matched lines +" MarksClear - clear all local marks " " recommended mapping: " nmap a ToggleMarkAZ @@ -33,6 +34,7 @@ " nmap w MarksLoc " nmap W MarksQF " nmap ! MarksHighlightToggle +" nmap DDD MarksClear " so " \a and \z toggle a mark at current line " \A and \Z force another mark @@ -370,5 +372,7 @@ nnoremap MarksLoc :call MarksLoc() nnoremap MarksQF :call MarksQF() " suggested mapping: ! nnoremap MarksHighlightToggle :call highlight_marks(2) +" suggested mapping: DDD +nnoremap MarksClear :call highlight_marks(0)\|:delmarks a-z let &cpo = s:save_cpo From 21737354fec149f9c766c44d56118e062e35f2a4 Mon Sep 17 00:00:00 2001 From: Jeet Sukumaran Date: Thu, 13 Mar 2014 19:28:17 -0400 Subject: [PATCH 4/4] Add acknowledgements --- plugin/mark_tools.vim | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/plugin/mark_tools.vim b/plugin/mark_tools.vim index 063ccb7..bd67d2d 100644 --- a/plugin/mark_tools.vim +++ b/plugin/mark_tools.vim @@ -75,6 +75,14 @@ " \ {'sign': 'QFS_QFL', 'get': 'g:NonMarkQFEntries()', 'event': ['BufEnter']}, " \ {'sign': 'QFS_LOC', 'get': 'g:NonMarkLocEntries(winnr())', 'event': ['BufEnter']}, " \ ] +" +" Acknowledgements: +" +" - Highlighting of marked lines based on: +" +" BOOKMARKS: Mark & Highlight Full Lines : Easily Highlight Lines with Marks, and Add/Remove Marks +" Ignacio Nunez +" http://www.vim.org/scripts/script.php?script_id=3394 let s:save_cpo = &cpo set cpo&vim