Skip to content

Commit e91ed34

Browse files
committed
Option to highlight note names on word boundaries (pull request #67)
1 parent 14838be commit e91ed34

File tree

3 files changed

+41
-16
lines changed

3 files changed

+41
-16
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ When you rename a file in your notes directory but don't change the title, the p
6565

6666
If you set this option to the string `'no'` this feature will be completely disabled. If you set it to `'change_title'` it will automatically change the title to match the filename. If you set it to `'rename_file'` it will automatically rename the file on disk to match the title.
6767

68+
### The `g:notes_word_boundaries` option
69+
70+
Old versions of the notes plug-in would highlight note titles without considering word boundaries. This is still the default behavior but the plug-in can now be told to respect word boundaries by changing this option from its default:
71+
72+
:let g:notes_word_boundaries = 1
73+
6874
### The `g:notes_smart_quotes` option
6975

7076
By default the notes plug-in automatically performs several substitutions on the text you type in insert mode, for example regular quote marks are replaced with curly quotes. The full list of substitutions can be found below in the documentation on mappings. If you don't want the plug-in to perform these substitutions, you can set this option to zero like this:
@@ -323,8 +329,8 @@ If you have questions, bug reports, suggestions, etc. the author can be contacte
323329

324330
## License
325331

326-
This software is licensed under the [MIT license] [mit].
327-
© 2013 Peter Odding &lt;<peter@peterodding.com>&gt;.
332+
This software is licensed under the [MIT license] [mit].
333+
© 2014 Peter Odding &lt;<peter@peterodding.com>&gt;.
328334

329335

330336
[ctrlwf]: http://vimdoc.sourceforge.net/htmldoc/windows.html#CTRL-W_f

autoload/xolox/notes.vim

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: September 2, 2013
3+
" Last Change: June 16, 2014
44
" URL: http://peterodding.com/code/vim/notes/
55

66
" Note: This file is encoded in UTF-8 including a byte order mark so
77
" that Vim loads the script using the right encoding transparently.
88

9-
let g:xolox#notes#version = '0.23.4'
9+
let g:xolox#notes#version = '0.23.5'
1010
let g:xolox#notes#url_pattern = '\<\(mailto:\|javascript:\|\w\{3,}://\)\(\S*\w\)\+/\?'
1111
let s:scriptdir = expand('<sfile>:p:h')
1212

@@ -96,6 +96,10 @@ function! xolox#notes#init() " {{{1
9696
let g:notes_list_bullets = g:notes_ascii_bullets
9797
endif
9898
endif
99+
" Should note titles only match (be highlighted) on word boundaries?
100+
if !exists('g:notes_word_boundaries')
101+
let g:notes_word_boundaries = 0
102+
endif
99103
endfunction
100104

101105
function! s:create_notes_directories()
@@ -1067,7 +1071,11 @@ function! xolox#notes#highlight_names(force) " {{{3
10671071
if hlexists('notesName')
10681072
syntax clear notesName
10691073
endif
1070-
execute 'syntax match notesName /\c\%>1l\%(' . escape(join(titles, '\|'), '/') . '\)/'
1074+
let pattern = '\%(' . escape(join(titles, '\|'), '/') . '\)'
1075+
if g:notes_word_boundaries
1076+
let pattern = '\<' . pattern . '\>'
1077+
endif
1078+
execute 'syntax match notesName /\c\%>1l' . pattern . '/'
10711079
let b:notes_names_last_highlighted = localtime()
10721080
call xolox#misc#timer#stop("notes.vim %s: Highlighted note names in %s.", g:xolox#notes#version, starttime)
10731081
endif

doc/notes.txt

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ Contents ~
1010
1. Backwards compatibility |notes-backwards-compatibility|
1111
2. The |g:notes_suffix| option
1212
3. The |g:notes_title_sync| option
13-
4. The |g:notes_smart_quotes| option
14-
5. The |g:notes_ruler_text| option
15-
6. The |g:notes_list_bullets| option
16-
7. The |g:notes_tab_indents| option
17-
8. The |g:notes_alt_indents| option
18-
9. The |g:notes_shadowdir| option
19-
10. The |g:notes_indexfile| option
20-
11. The |g:notes_indexscript| option
21-
12. The |g:notes_tagsindex| option
22-
13. The |g:notes_markdown_program| option
13+
4. The |g:notes_word_boundaries| option
14+
5. The |g:notes_smart_quotes| option
15+
6. The |g:notes_ruler_text| option
16+
7. The |g:notes_list_bullets| option
17+
8. The |g:notes_tab_indents| option
18+
9. The |g:notes_alt_indents| option
19+
10. The |g:notes_shadowdir| option
20+
11. The |g:notes_indexfile| option
21+
12. The |g:notes_indexscript| option
22+
13. The |g:notes_tagsindex| option
23+
14. The |g:notes_markdown_program| option
2324
4. Commands |notes-commands|
2425
1. The |:Note| command
2526
2. The |:NoteFromSelectedText| command
@@ -213,6 +214,16 @@ disabled. If you set it to "'change_title'" it will automatically change the
213214
title to match the filename. If you set it to "'rename_file'" it will
214215
automatically rename the file on disk to match the title.
215216

217+
-------------------------------------------------------------------------------
218+
The *g:notes_word_boundaries* option
219+
220+
Old versions of the notes plug-in would highlight note titles without
221+
considering word boundaries. This is still the default behavior but the plug-in
222+
can now be told to respect word boundaries by changing this option from its
223+
default:
224+
>
225+
:let g:notes_word_boundaries = 1
226+
<
216227
-------------------------------------------------------------------------------
217228
The *g:notes_smart_quotes* option
218229

@@ -648,7 +659,7 @@ If you like the script please vote for it on Vim Online [17].
648659
*notes-license*
649660
License ~
650661

651-
This software is licensed under the MIT license [18]. © 2013 Peter Odding
662+
This software is licensed under the MIT license [18]. © 2014 Peter Odding
652663
<peter@peterodding.com>.
653664

654665
===============================================================================

0 commit comments

Comments
 (0)