|
1 | 1 | " Vim auto-load script
|
2 | 2 | " Author: Peter Odding <[email protected]>
|
3 |
| -" Last Change: August 4, 2014 |
| 3 | +" Last Change: September 14, 2014 |
4 | 4 | " URL: http://peterodding.com/code/vim/notes/
|
5 | 5 |
|
6 | 6 | " Note: This file is encoded in UTF-8 including a byte order mark so
|
7 | 7 | " that Vim loads the script using the right encoding transparently.
|
8 | 8 |
|
9 |
| -let g:xolox#notes#version = '0.26.1' |
| 9 | +let g:xolox#notes#version = '0.27' |
10 | 10 | let g:xolox#notes#url_pattern = '\<\(mailto:\|javascript:\|\w\{3,}://\)\(\S*\w\)\+/\?'
|
11 | 11 | let s:scriptdir = expand('<sfile>:p:h')
|
12 | 12 |
|
@@ -386,6 +386,14 @@ function! xolox#notes#omni_complete(findstart, base) " {{{1
|
386 | 386 | endif
|
387 | 387 | endfunction
|
388 | 388 |
|
| 389 | +function! xolox#notes#auto_complete_tags() " {{{1 |
| 390 | + " Automatic completion of tags when the user types "@". |
| 391 | + if !xolox#notes#currently_inside_snippet() |
| 392 | + return "@\<C-x>\<C-o>" |
| 393 | + endif |
| 394 | + return "@" |
| 395 | +endfunction |
| 396 | + |
389 | 397 | function! xolox#notes#save() abort " {{{1
|
390 | 398 | " When the current note's title is changed, automatically rename the file.
|
391 | 399 | if xolox#notes#filetype_is_note(&ft)
|
@@ -967,22 +975,47 @@ function! xolox#notes#insert_ruler() " {{{3
|
967 | 975 | call append(line1, ['', g:notes_ruler_text, ''])
|
968 | 976 | endfunction
|
969 | 977 |
|
970 |
| -function! xolox#notes#insert_quote(style) " {{{3 |
| 978 | +function! xolox#notes#insert_quote(chr) " {{{3 |
971 | 979 | " XXX When I pass the below string constants as arguments from the file type
|
972 | 980 | " plug-in the resulting strings contain mojibake (UTF-8 interpreted as
|
973 | 981 | " latin1?) even if both scripts contain a UTF-8 BOM! Maybe a bug in Vim?!
|
974 |
| - if xolox#notes#unicode_enabled() |
975 |
| - let [open_quote, close_quote] = a:style == 1 ? ['‘', '’'] : ['“', '”'] |
976 |
| - else |
977 |
| - let [open_quote, close_quote] = a:style == 1 ? ['`', "'"] : ['"', '"'] |
| 982 | + if g:notes_smart_quotes && !xolox#notes#currently_inside_snippet() |
| 983 | + if xolox#notes#unicode_enabled() |
| 984 | + let [open_quote, close_quote] = (a:chr == "'") ? ['‘', '’'] : ['“', '”'] |
| 985 | + else |
| 986 | + let [open_quote, close_quote] = (a:chr == "'") ? ['`', "'"] : ['"', '"'] |
| 987 | + endif |
| 988 | + return getline('.')[col('.')-2] =~ '[^\t (]$' ? close_quote : open_quote |
978 | 989 | endif
|
979 |
| - return getline('.')[col('.')-2] =~ '[^\t (]$' ? close_quote : open_quote |
| 990 | + return a:chr |
| 991 | +endfunction |
| 992 | + |
| 993 | +function! xolox#notes#insert_em_dash() " {{{3 |
| 994 | + " Change double-dash (--) to em-dash (—) as it is typed. |
| 995 | + return (g:notes_smart_quotes && xolox#notes#unicode_enabled() && !xolox#notes#currently_inside_snippet()) ? '—' : '--' |
| 996 | +endfunction |
| 997 | + |
| 998 | +function! xolox#notes#insert_left_arrow() " {{{3 |
| 999 | + " Change ASCII left arrow (<-) to Unicode arrow (←) as it is typed. |
| 1000 | + return (g:notes_smart_quotes && xolox#notes#unicode_enabled() && !xolox#notes#currently_inside_snippet()) ? '←' : "<-" |
| 1001 | +endfunction |
| 1002 | + |
| 1003 | +function! xolox#notes#insert_right_arrow() " {{{3 |
| 1004 | + " Change ASCII right arrow (->) to Unicode arrow (→) as it is typed. |
| 1005 | + return (g:notes_smart_quotes && xolox#notes#unicode_enabled() && !xolox#notes#currently_inside_snippet()) ? '→' : '->' |
| 1006 | +endfunction |
| 1007 | + |
| 1008 | +function! xolox#notes#insert_bidi_arrow() " {{{3 |
| 1009 | + " Change bidirectional ASCII arrow (->) to Unicode arrow (→) as it is typed. |
| 1010 | + return (g:notes_smart_quotes && xolox#notes#unicode_enabled() && !xolox#notes#currently_inside_snippet()) ? '↔' : "<->" |
980 | 1011 | endfunction
|
981 | 1012 |
|
982 | 1013 | function! xolox#notes#insert_bullet(chr) " {{{3
|
983 | 1014 | " Insert a UTF-8 list bullet when the user types "*".
|
984 |
| - if getline('.')[0 : max([0, col('.') - 2])] =~ '^\s*$' |
985 |
| - return xolox#notes#get_bullet(a:chr) |
| 1015 | + if !xolox#notes#currently_inside_snippet() |
| 1016 | + if getline('.')[0 : max([0, col('.') - 2])] =~ '^\s*$' |
| 1017 | + return xolox#notes#get_bullet(a:chr) |
| 1018 | + endif |
986 | 1019 | endif
|
987 | 1020 | return a:chr
|
988 | 1021 | endfunction
|
@@ -1209,23 +1242,34 @@ function! xolox#notes#foldexpr() " {{{3
|
1209 | 1242 | let retval = '>' . nextlevel
|
1210 | 1243 | endif
|
1211 | 1244 | endif
|
1212 |
| - if retval != '=' |
1213 |
| - " Check whether the change in folding introduced by 'rv' |
1214 |
| - " is invalidated because we're inside a code block. |
1215 |
| - let pos_save = getpos('.') |
1216 |
| - try |
1217 |
| - call setpos('.', [0, v:lnum, 1, 0]) |
1218 |
| - if search('{{{\|\(}}}\)', 'bnpW') == 1 |
1219 |
| - let retval = '=' |
1220 |
| - endif |
1221 |
| - finally |
1222 |
| - " Always restore the cursor position! |
1223 |
| - call setpos('.', pos_save) |
1224 |
| - endtry |
| 1245 | + " Check whether the change in folding introduced by 'rv' |
| 1246 | + " is invalidated because we're inside a code block. |
| 1247 | + if retval != '=' && xolox#notes#inside_snippet(v:lnum, 1) |
| 1248 | + let retval = '=' |
1225 | 1249 | endif
|
1226 | 1250 | return retval
|
1227 | 1251 | endfunction
|
1228 | 1252 |
|
| 1253 | +function! xolox#notes#inside_snippet(lnum, col) " {{{3 |
| 1254 | + " Check if the given line and column position is inside a snippet (a code |
| 1255 | + " block enclosed by triple curly brackets). This function temporarily |
| 1256 | + " changes the cursor position in the current buffer in order to search |
| 1257 | + " backwards efficiently. |
| 1258 | + let pos_save = getpos('.') |
| 1259 | + try |
| 1260 | + call setpos('.', [0, a:lnum, a:col, 0]) |
| 1261 | + return search('{{{\|\(}}}\)', 'bnpW') == 1 |
| 1262 | + finally |
| 1263 | + call setpos('.', pos_save) |
| 1264 | + endtry |
| 1265 | +endfunction |
| 1266 | + |
| 1267 | +function! xolox#notes#currently_inside_snippet() " {{{3 |
| 1268 | + " Check if the current cursor position is inside a snippet (a code block |
| 1269 | + " enclosed by triple curly brackets). |
| 1270 | + return xolox#notes#inside_snippet(line('.'), col('.')) |
| 1271 | +endfunction |
| 1272 | + |
1229 | 1273 | function! xolox#notes#foldtext() " {{{3
|
1230 | 1274 | " Replace atx style "#" markers with "-" fold marker.
|
1231 | 1275 | let line = getline(v:foldstart)
|
|
0 commit comments