From c12ebf43d08321cf129a3b92d3e9f8024c92f9d9 Mon Sep 17 00:00:00 2001 From: gryf Date: Mon, 23 May 2011 20:43:28 +0200 Subject: [PATCH] Updated Mark plugin --- GetLatest/GetLatestVimScripts.dat | 2 +- autoload/mark.vim | 29 ++++++++++++++++++++--------- doc/mark.txt | 28 ++++++++++++++++++++++++++++ doc/tags | 2 ++ 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/GetLatest/GetLatestVimScripts.dat b/GetLatest/GetLatestVimScripts.dat index b0ef066..d5f269b 100644 --- a/GetLatest/GetLatestVimScripts.dat +++ b/GetLatest/GetLatestVimScripts.dat @@ -7,7 +7,7 @@ ScriptID SourceID Filename 311 7645 grep.vim 3304 15211 gundo.vim 2727 11120 jsbeautify.vim -2666 15603 Mark +2666 15663 Mark 2262 8944 occur.vim 910 14691 pydoc.vim #2421 9423 pysmell.vim diff --git a/autoload/mark.vim b/autoload/mark.vim index 22148f1..2f95841 100644 --- a/autoload/mark.vim +++ b/autoload/mark.vim @@ -10,8 +10,19 @@ " Dependencies: " - SearchSpecial.vim autoload script (optional, for improved search messages). " -" Version: 2.5.0 +" Version: 2.5.1 " Changes: +" +" 17-May-2011, Ingo Karkat +" - Make s:GetVisualSelection() public to allow use in suggested +" MarkSpaceIndifferent vmap. +" - FIX: == comparison in s:DoMark() leads to wrong regexp (\A vs. \a) being +" cleared when 'ignorecase' is set. Use case-sensitive comparison ==# instead. +" +" 10-May-2011, Ingo Karkat +" - Refine :MarkLoad messages: Differentiate between nonexistent and empty +" g:MARK_MARKS; add note when marks are disabled. +" " 06-May-2011, Ingo Karkat " - Also print status message on :MarkClear to be consistent with :MarkToggle. " @@ -155,7 +166,7 @@ function! mark#MarkCurrentWord() endif endfunction -function! s:GetVisualSelection() +function! mark#GetVisualSelection() let save_clipboard = &clipboard set clipboard= " Avoid clobbering the selection and clipboard registers. let save_reg = getreg('"') @@ -167,10 +178,10 @@ function! s:GetVisualSelection() return res endfunction function! mark#GetVisualSelectionAsLiteralPattern() - return s:EscapeText(s:GetVisualSelection()) + return s:EscapeText(mark#GetVisualSelection()) endfunction function! mark#GetVisualSelectionAsRegexp() - return substitute(s:GetVisualSelection(), '\n', '', 'g') + return substitute(mark#GetVisualSelection(), '\n', '', 'g') endfunction " Manually input a regular expression. @@ -348,8 +359,8 @@ function! mark#DoMark(...) " DoMark(regexp) " clear the mark if it has been marked let i = 0 while i < s:markNum - if regexp == s:pattern[i] - if s:lastSearch == s:pattern[i] + if regexp ==# s:pattern[i] + if s:lastSearch ==# s:pattern[i] let s:lastSearch = '' endif call s:SetPattern(i, '') @@ -394,7 +405,7 @@ function! mark#DoMark(...) " DoMark(regexp) " choose a mark group by cycle let i = s:Cycle() - if s:lastSearch == s:pattern[i] + if s:lastSearch ==# s:pattern[i] let s:lastSearch = '' endif call s:SetPattern(i, regexp) @@ -675,9 +686,9 @@ function! mark#LoadCommand( isShowMessages ) execute 'let l:loadedMarkNum = mark#Load(' . g:MARK_MARKS . ', ' . (exists('g:MARK_ENABLED') ? g:MARK_ENABLED : 1) . ')' if a:isShowMessages if l:loadedMarkNum == 0 - echomsg 'No persistent marks found' + echomsg 'No persistent marks defined' else - echomsg printf('Loaded %d mark%s', l:loadedMarkNum, (l:loadedMarkNum == 1 ? '' : 's')) + echomsg printf('Loaded %d mark%s', l:loadedMarkNum, (l:loadedMarkNum == 1 ? '' : 's')) . (s:enabled ? '' : '; marks currently disabled') endif endif catch /^Vim\%((\a\+)\)\=:E/ diff --git a/doc/mark.txt b/doc/mark.txt index 343489d..75df9c0 100644 --- a/doc/mark.txt +++ b/doc/mark.txt @@ -165,6 +165,9 @@ DEPENDENCIES *mark-dependencies* ============================================================================== CONFIGURATION *mark-configuration* +For a permanent configuration, put the following commands into your |vimrc|. + + *mark-highlight-colors* You may define your own colors or more than the default 6 highlightings in your vimrc file (or anywhere before this plugin is sourced), in the following form (where N = 1..): > @@ -199,6 +202,24 @@ command, but you can define some yourself: > To remove the default overriding of * and #, use: > nmap IgnoreMarkSearchNext MarkSearchNext nmap IgnoreMarkSearchPrev MarkSearchPrev +< + *mark-whitespace-indifferent* +Some people like to create a mark based on the visual selection, like +|v_m|, but have whitespace in the selection match any whitespace when +searching (searching for "hello world" will also find "helloworld" as +well as "hello" at the end of a line, with "world" at the start of the next +line). The Vim Tips Wiki describes such a setup for the built-in search at + http://vim.wikia.com/wiki/Search_for_visually_selected_text +You can achieve the same with the Mark plugin through the following scriptlet: > + function! s:GetVisualSelectionAsLiteralWhitespaceIndifferentPattern() + return substitute(escape(mark#GetVisualSelection(), '\' . '^$.*[~'), '\_s\+', '\\_s\\+', 'g') + endfunction + vnoremap MarkWhitespaceIndifferent :call mark#DoMark(GetVisualSelectionAsLiteralWhitespaceIndifferentPattern()) +Using this, you can assign a new visual mode mapping * > + vmap * MarkWhitespaceIndifferent +or override the default |v_m| mapping, in case you always want this +behavior: > + vmap m MarkWhitespaceIndifferent < ============================================================================== LIMITATIONS *mark-limitations* @@ -224,6 +245,13 @@ http://vim.wikia.com/wiki/Highlight_multiple_words: ============================================================================== HISTORY *mark-history* +2.5.1 17-May-2011 +- FIX: == comparison in s:DoMark() leads to wrong regexp (\A vs. \a) being + cleared when 'ignorecase' is set. Use case-sensitive comparison ==# instead. +- Refine :MarkLoad messages +- Add whitespace-indifferent visual mark configuration example. Thanks to Greg + Klein for the suggestion. + 2.5.0 07-May-2011 - ENH: Add explicit mark persistence via :MarkLoad and :MarkSave commands and automatic persistence via the g:mwAutoLoadMarks and g:mwAutoSaveMarks diff --git a/doc/tags b/doc/tags index 5bc907e..3f0fe04 100644 --- a/doc/tags +++ b/doc/tags @@ -442,6 +442,7 @@ loremipsum.txt loremipsum.txt /*loremipsum.txt* mark-configuration mark.txt /*mark-configuration* mark-dependencies mark.txt /*mark-dependencies* mark-description mark.txt /*mark-description* +mark-highlight-colors mark.txt /*mark-highlight-colors* mark-highlighting mark.txt /*mark-highlighting* mark-history mark.txt /*mark-history* mark-ideas mark.txt /*mark-ideas* @@ -453,6 +454,7 @@ mark-persistence mark.txt /*mark-persistence* mark-searching mark.txt /*mark-searching* mark-todo mark.txt /*mark-todo* mark-usage mark.txt /*mark-usage* +mark-whitespace-indifferent mark.txt /*mark-whitespace-indifferent* mark.txt mark.txt /*mark.txt* mark.vim mark.txt /*mark.vim* multi_snip snipMate.txt /*multi_snip*