Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Version 3.10

From this version on, viki requires vim 7.2's shellescape() and fnameescape() functions.

- VikiOpenSpecialFile() uses fnameescape()
- FIX: automatically set marks (#m? type of anchors)
- Anchor regexp can be configured via g:vikiAnchorNameRx
  • Loading branch information...
commit ffdbcfea06a71f624251124e0135bb4acad09daf 1 parent b0608f2
Tom Link authored August 31, 2008 vim-scripts committed November 13, 2010
21  autoload/viki.vim
@@ -3,8 +3,8 @@
3 3
 " @Website:     http://www.vim.org/account/profile.php?user_id=4037
4 4
 " @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
5 5
 " @Created:     2007-03-25.
6  
-" @Last Change: 2008-06-22.
7  
-" @Revision:    0.460
  6
+" @Last Change: 2008-08-28.
  7
+" @Revision:    0.475
8 8
 
9 9
 if &cp || exists("loaded_viki_auto") "{{{2
10 10
     finish
@@ -983,7 +983,7 @@ function! viki#SubstituteArgs(str, ...) "{{{3
983 983
         if lab == ''
984 984
             let default = val
985 985
         else
986  
-            let rv0 = substitute(rv, '\C\(^\|[^%]\)\zs%{'. lab .'}', escape(val, '\&'), "g")
  986
+            let rv0 = substitute(rv, '\C\(^\|[^%]\)\zs%{'. lab .'}', escape(val, '\~&'), 'g')
987 987
             if rv != rv0
988 988
                 let done = 1
989 989
                 let rv = rv0
@@ -1052,9 +1052,10 @@ function! viki#SetAnchorMarks() "{{{3
1052 1052
     let pos = getpos(".")
1053 1053
     " TLogVAR pos
1054 1054
     let sr  = @/
1055  
-    let anchorRx = viki#GetAnchorRx('m\(\[a-zA-Z]\)\s\*\$')
  1055
+    let anchorRx = viki#GetAnchorRx('m\zs\[a-zA-Z]\ze\s\*\$')
  1056
+    " TLogVAR anchorRx
1056 1057
     " exec 'silent keepjumps g /'. anchorRx .'/exec "norm! m". substitute(getline("."), anchorRx, ''\2'', "")'
1057  
-    exec 'silent keepjumps g /'. anchorRx .'/exec "norm! m". matchlist(getline("."), anchorRx)[1]'
  1058
+    exec 'silent keepjumps g /'. anchorRx .'/exec "norm! m". matchstr(getline("."), anchorRx)'
1058 1059
     let @/ = sr
1059 1060
     " TLogVAR pos
1060 1061
     call setpos('.', pos)
@@ -1286,7 +1287,9 @@ function! s:OpenLink(dest, anchor, winNr)
1286 1287
     " TLogVAR a:dest, a:anchor, a:winNr
1287 1288
     try
1288 1289
         if viki#IsSpecialProtocol(a:dest)
1289  
-            call VikiOpenSpecialProtocol(viki#MakeUrl(a:dest, a:anchor))
  1290
+            let url = viki#MakeUrl(a:dest, a:anchor)
  1291
+            " TLogVAR url
  1292
+            call VikiOpenSpecialProtocol(url)
1290 1293
         elseif viki#IsSpecialFile(a:dest)
1291 1294
             call VikiOpenSpecialFile(a:dest)
1292 1295
         elseif isdirectory(a:dest)
@@ -2105,6 +2108,7 @@ fun! viki#GetIndent()
2105 2108
 endf
2106 2109
 
2107 2110
 function! viki#ExecExternal(cmd) "{{{3
  2111
+    " TLogVAR a:cmd
2108 2112
     exec a:cmd
2109 2113
     if !has("gui_running")
2110 2114
         " Scrambled window with vim
@@ -2212,6 +2216,7 @@ endf
2212 2216
 
2213 2217
 fun! viki#DirListing(lhs, lhb, indent) "{{{3
2214 2218
     let args = s:GetRegionArgs(a:lhs, a:lhb - 1)
  2219
+    " TLogVAR args
2215 2220
     let patt = get(args, 'glob', '')
2216 2221
     " TLogVAR patt
2217 2222
     if empty(patt)
@@ -2316,17 +2321,21 @@ fun! s:GetRegionArgs(ls, le) "{{{3
2316 2321
     " let p = getpos('.')
2317 2322
     try
2318 2323
         let t = s:GetBrokenLine(a:ls, a:le)
  2324
+        " TLogVAR t
2319 2325
         let t = matchstr(t, '^\s*#\([A-Z]\([a-z][A-Za-z]*\)\?\>\|!!!\)\zs.\{-}\ze<<$')
  2326
+        " TLogVAR t
2320 2327
         let args = {}
2321 2328
         let rx = '^\s*\(\(\S\{-}\)=\("\(\(\"\|.\{-}\)\{-}\)"\|\(\(\S\+\|\\ \)\+\)\)\|\(\w\)\+!\)\s*'
2322 2329
         let s  = 0
2323 2330
         let sm = len(t)
2324 2331
         while s < sm
2325 2332
             let m = matchlist(t, rx, s)
  2333
+            " TLogVAR m
2326 2334
             if empty(m)
2327 2335
                 echoerr "Viki: Can't parse argument list: ". t
2328 2336
             else
2329 2337
                 let key = m[2]
  2338
+                " TLogVAR key
2330 2339
                 if !empty(key)
2331 2340
                     let val = empty(m[4]) ? m[6] : m[4]
2332 2341
                     if val =~ '^".\{-}"'
19  autoload/viki_viki.vim
@@ -3,8 +3,8 @@
3 3
 " @Website:     http://www.vim.org/account/profile.php?user_id=4037
4 4
 " @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
5 5
 " @Created:     2007-09-03.
6  
-" @Last Change: 2007-11-15.
7  
-" @Revision:    0.0.95
  6
+" @Last Change: 2008-08-28.
  7
+" @Revision:    0.0.107
8 8
 
9 9
 if &cp || exists("loaded_viki_viki")
10 10
     finish
@@ -44,6 +44,8 @@ function! viki_viki#SetupBuffer(state, ...) "{{{3
44 44
     " call viki#SetBufferVar("vikiTextstylesVer")
45 45
     call viki#SetBufferVar("vikiLowerCharacters")
46 46
     call viki#SetBufferVar("vikiUpperCharacters")
  47
+    call viki#SetBufferVar("vikiAnchorNameRx")
  48
+    call viki#SetBufferVar("vikiUrlRestRx")
47 49
     call viki#SetBufferVar("vikiFeedbackMin")
48 50
 
49 51
     if a:state == 1
@@ -69,8 +71,11 @@ function! viki_viki#SetupBuffer(state, ...) "{{{3
69 71
     let b:vikiQuotedSelfRef        = "^". b:vikiSimpleNameQuoteBeg . b:vikiSimpleNameQuoteEnd ."$"
70 72
     let b:vikiQuotedRef            = "^". b:vikiSimpleNameQuoteBeg .'.\+'. b:vikiSimpleNameQuoteEnd ."$"
71 73
 
72  
-    let b:vikiAnchorNameRx         = '['. b:vikiLowerCharacters .']['. 
73  
-                \ b:vikiLowerCharacters . b:vikiUpperCharacters .'_0-9]*'
  74
+    if empty(b:vikiAnchorNameRx)
  75
+        let b:vikiAnchorNameRx         = '['. b:vikiLowerCharacters .']['. 
  76
+                    \ b:vikiLowerCharacters . b:vikiUpperCharacters .'_0-9]*'
  77
+    endif
  78
+    " TLogVAR b:vikiAnchorNameRx
74 79
     
75 80
     let interviki = '\<['. b:vikiUpperCharacters .']\+::'
76 81
 
@@ -128,9 +133,9 @@ function! viki_viki#SetupBuffer(state, ...) "{{{3
128 133
     if viki#IsSupportedType("u") && !(dontSetup =~# "u")
129 134
         let urlChars = 'A-Za-z0-9.,:%?=&_~@$/|+-'
130 135
         let b:vikiUrlRx = '\<\(\('.b:vikiSpecialProtocols.'\):['. urlChars .']\+\)'.
131  
-                    \ '\(#\([A-Za-z0-9]*\)\)\?'
  136
+                    \ '\(#\('. b:vikiAnchorNameRx .'\)\)\?'. b:vikiUrlRestRx
132 137
         let b:vikiUrlSimpleRx = '\<\('. b:vikiSpecialProtocols .'\):['. urlChars .']\+'.
133  
-                    \ '\(#[A-Za-z0-9]*\)\?'
  138
+                    \ '\(#'. b:vikiAnchorNameRx .'\)\?'. b:vikiUrlRestRx
134 139
         let b:vikiUrlNameIdx   = 0
135 140
         let b:vikiUrlDestIdx   = 1
136 141
         let b:vikiUrlAnchorIdx = 4
@@ -194,7 +199,9 @@ function! viki_viki#SetupBuffer(state, ...) "{{{3
194 199
 
195 200
     let b:vikiInexistentHighlight = "vikiInexistentLink"
196 201
 
  202
+    " TLogVAR a:state
197 203
     if a:state == 2
  204
+        " TLogVAR g:vikiAutoMarks
198 205
         if g:vikiAutoMarks
199 206
             call viki#SetAnchorMarks()
200 207
         endif
54  plugin/viki.vim
@@ -2,8 +2,8 @@
2 2
 " @Author:      Thomas Link (micathom AT gmail com?subject=vim)
3 3
 " @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
4 4
 " @Created:     08-Dec-2003.
5  
-" @Last Change: 2008-06-22.
6  
-" @Revision: 3.7.2563
  5
+" @Last Change: 2008-08-28.
  6
+" @Revision:    2610
7 7
 "
8 8
 " GetLatestVimScripts: 861 1 viki.vim
9 9
 "
@@ -41,7 +41,7 @@ if !exists('g:loaded_tlib') || g:loaded_tlib < 15
41 41
         finish
42 42
     endif
43 43
 endif
44  
-let loaded_viki = 308
  44
+let loaded_viki = 310
45 45
 
46 46
 " This is what we consider nil, in the absence of nil in vimscript
47 47
 let g:vikiDefNil  = ''
@@ -80,6 +80,17 @@ if !exists("g:vikiLowerCharacters") "{{{2
80 80
     let g:vikiLowerCharacters = "a-z"
81 81
 endif
82 82
 
  83
+" Characters allowed in anchors
  84
+" Defaults to:
  85
+" [b:vikiLowerCharacters][b:vikiLowerCharacters +  b:vikiUpperCharacters + '_0-9]*
  86
+if !exists('g:vikiAnchorNameRx')
  87
+    let g:vikiAnchorNameRx = '' "{{{2
  88
+endif
  89
+
  90
+if !exists('g:vikiUrlRestRx')
  91
+    let g:vikiUrlRestRx = '['. g:vikiLowerCharacters . g:vikiUpperCharacters .'0-9?%_=&+-]*'  "{{{2
  92
+endif
  93
+
83 94
 " The prefix for the menu of intervikis. Set to '' in order to remove the 
84 95
 " menu.
85 96
 if !exists("g:vikiMenuPrefix") "{{{2
@@ -349,13 +360,13 @@ endif
349 360
 
350 361
 if !exists("g:vikiOpenFileWith_ANY") "{{{2
351 362
     if exists('g:netrw_browsex_viewer')
352  
-        let g:vikiOpenFileWith_ANY = "exec 'silent !'. g:netrw_browsex_viewer .' '. escape('%{FILE}', ' &!%')"
  363
+        let g:vikiOpenFileWith_ANY = "exec 'silent !'. g:netrw_browsex_viewer .' '. shellescape('%{FILE}')"
353 364
     elseif has("win32") || has("win16") || has("win64")
354  
-        let g:vikiOpenFileWith_ANY = "exec 'silent !cmd /c start '. escape('%{FILE}', ' &!%')"
  365
+        let g:vikiOpenFileWith_ANY = "exec 'silent !cmd /c start '. shellescape('%{FILE}')"
355 366
     elseif $GNOME_DESKTOP_SESSION_ID != ""
356  
-        let g:vikiOpenFileWith_ANY = "exec 'silent !gnome-open '. escape('%{FILE}', ' &!%')"
  367
+        let g:vikiOpenFileWith_ANY = "exec 'silent !gnome-open '. shellescape('%{FILE}')"
357 368
     elseif $KDEDIR != ""
358  
-        let g:vikiOpenFileWith_ANY = "exec 'silent !kfmclient exec '. escape('%{FILE}', ' &!%')"
  369
+        let g:vikiOpenFileWith_ANY = "exec 'silent !kfmclient exec '. shellescape('%{FILE}')"
359 370
     endif
360 371
 endif
361 372
 
@@ -371,6 +382,7 @@ if !exists('*VikiOpenSpecialFile') "{{{2
371 382
             let prot = ''
372 383
         endif
373 384
         if prot != ''
  385
+            " let openFile = viki#SubstituteArgs(prot, 'FILE', fnameescape(a:file))
374 386
             let openFile = viki#SubstituteArgs(prot, 'FILE', a:file)
375 387
             " TLogVAR openFile
376 388
             call viki#ExecExternal(openFile)
@@ -401,6 +413,7 @@ if !exists("g:vikiUrlFileAs") | let g:vikiUrlFileAs = 'special' | endif "{{{2
401 413
 if !exists("g:vikiOpenUrlWith_file") "{{{2
402 414
     let g:vikiOpenUrlWith_file="call VikiOpenFileUrl('%{URL}')"
403 415
     function! VikiOpenFileUrl(url) "{{{3
  416
+        " TLogVAR url
404 417
         if viki#IsSpecialFile(a:url)
405 418
             if g:vikiUrlFileAs == 'special'
406 419
                 let as_special = 1
@@ -411,16 +424,17 @@ if !exists("g:vikiOpenUrlWith_file") "{{{2
411 424
             else
412 425
                 let as_special = 0
413 426
             endif
  427
+            " TLogVAR as_special
414 428
             if as_special
415 429
                 call VikiOpenSpecialFile(a:url)
416 430
                 return
417 431
             endif
418 432
         endif
419 433
         exec viki#DecomposeUrl(strpart(a:url, 7))
420  
-        if filereadable(filename)
  434
+        if filereadable(filename) || isdirectory(filename)
421 435
             call viki#OpenLink(filename, anchor)
422 436
         else
423  
-            throw 'Viki: Can't find file url: '.filename
  437
+            throw "Viki: Can't find file url: ". filename
424 438
         endif
425 439
     endf
426 440
 endif
@@ -428,16 +442,18 @@ endif
428 442
 if !exists("g:vikiOpenUrlWith_ANY") "{{{2
429 443
     " let g:vikiOpenUrlWith_ANY = "exec 'silent !". g:netrw_browsex_viewer ." '. escape('%{URL}', ' &!%')"
430 444
     if has("win32")
431  
-        let g:vikiOpenUrlWith_ANY = "exec 'silent !rundll32 url.dll,FileProtocolHandler '. escape('%{URL}', ' !&%')"
  445
+        let g:vikiOpenUrlWith_ANY = "exec 'silent !rundll32 url.dll,FileProtocolHandler '. shellescape('%{URL}')"
432 446
     elseif $GNOME_DESKTOP_SESSION_ID != ""
433  
-        let g:vikiOpenUrlWith_ANY = "exec 'silent !gnome-open '. escape('%{URL}', ' !&%')"
  447
+        let g:vikiOpenUrlWith_ANY = "exec 'silent !gnome-open '. shellescape('%{URL}')"
434 448
     elseif $KDEDIR != ""
435  
-        let g:vikiOpenUrlWith_ANY = "exec 'silent !kfmclient exec '. escape('%{URL}', ' !&%')"
  449
+        let g:vikiOpenUrlWith_ANY = "exec 'silent !kfmclient exec '. shellescape('%{URL}')"
436 450
     endif
437 451
 endif
438 452
 
439 453
 if !exists("*VikiOpenSpecialProtocol") "{{{2
440 454
     function! VikiOpenSpecialProtocol(url) "{{{3
  455
+        " TLogVAR a:url
  456
+        " TLogVAR a:url
441 457
         let proto = tolower(matchstr(a:url, '\c^[a-z]\{-}\ze:'))
442 458
         let prot  = 'g:vikiOpenUrlWith_'. proto
443 459
         let protp = exists(prot)
@@ -447,7 +463,10 @@ if !exists("*VikiOpenSpecialProtocol") "{{{2
447 463
         endif
448 464
         if protp
449 465
             exec 'let openURL = '. prot
450  
-            let openURL = viki#SubstituteArgs(openURL, 'URL', a:url)
  466
+            " let url = shellescape(a:url)
  467
+            let url = a:url
  468
+            " TLogVAR url, a:url
  469
+            let openURL = viki#SubstituteArgs(openURL, 'URL', url)
451 470
             " TLogVAR openURL
452 471
             call viki#ExecExternal(openURL)
453 472
         else
@@ -999,5 +1018,12 @@ rtp-directory (thanks to M Brandmeyer)
999 1018
 - Added dia to g:vikiSpecialFiles
1000 1019
 - FIX: Scrambled window when opening an url from vim (thanks A Moell)
1001 1020
 
1002  
-"
  1021
+3.9
  1022
+- VikiOpenSpecialFile() uses fnameescape()
  1023
+
  1024
+3.10
  1025
+- FIX: automatically set marks (#m? type of anchors)
  1026
+- Anchor regexp can be configured via g:vikiAnchorNameRx
  1027
+
  1028
+
1003 1029
 " vim: ff=unix
8  syntax/viki.vim
@@ -2,8 +2,8 @@
2 2
 " @Author:      Thomas Link (micathom AT gmail com?subject=vim)
3 3
 " @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
4 4
 " @Created:     30-Dez-2003.
5  
-" @Last Change: 2008-04-17.
6  
-" @Revision: 0.858
  5
+" @Last Change: 2008-08-20.
  6
+" @Revision: 0.862
7 7
 
8 8
 if !g:vikiEnabled
9 9
     finish
@@ -93,6 +93,7 @@ syn match vikiPriorityListTodoE /^[[:blank:]]\+\zs#\(T: \+.\{-}E.\{-}:\|\d*E\d*\
93 93
 syn match vikiPriorityListTodoF /^[[:blank:]]\+\zs#\(T: \+.\{-}F.\{-}:\|\d*F\d*\( \+\(_\|[0-9%-]\+\)\)\?\)\( \+\[[^[].\{-}\]\)\?\ze /
94 94
 
95 95
 syn match vikiPriorityListDoneGen /^[[:blank:]]\+\zs#\(T: \+x\([0-9%-]\+\)\?.\{-}\u.\{-}:\|\(T: \+\)\?\d*\u\d* \+x[0-9%-]*\):\? .*/
  96
+syn match vikiPriorityListDoneX /^[[:blank:]]\+\zs#X\d\?\s.*/
96 97
 syn match vikiPriorityListDoneA /^[[:blank:]]\+\zs#\(T: \+x\([0-9%-]\+\)\?.\{-}A.\{-}:\|\(T: \+\)\?\d*A\d* \+x[0-9%-]*\):\? .*/
97 98
 syn match vikiPriorityListDoneB /^[[:blank:]]\+\zs#\(T: \+x\([0-9%-]\+\)\?.\{-}B.\{-}:\|\(T: \+\)\?\d*B\d* \+x[0-9%-]*\):\? .*/
98 99
 syn match vikiPriorityListDoneC /^[[:blank:]]\+\zs#\(T: \+x\([0-9%-]\+\)\?.\{-}C.\{-}:\|\(T: \+\)\?\d*C\d* \+x[0-9%-]*\):\? .*/
@@ -164,7 +165,7 @@ syn region vikiFilesRegion matchgroup=vikiMacroDelim
164 165
 
165 166
 if g:vikiHighlightMath == 'latex'
166 167
     syn region vikiTexFormula matchgroup=Comment
167  
-                \ start=/\$/ end=/\$/
  168
+                \ start=/\z(\$\$\?\)/ end=/\z1/
168 169
                 \ contains=@texmathMath
169 170
     syn sync match vikiTexFormula grouphere NONE /^\s*$/
170 171
 endif
@@ -268,6 +269,7 @@ if version >= 508 || !exists("did_viki_syntax_inits")
268 269
   HiLink vikiPriorityListDoneE Comment
269 270
   HiLink vikiPriorityListDoneF Comment
270 271
   HiLink vikiPriorityListDoneGen Comment
  272
+  HiLink vikiPriorityListDoneX Comment
271 273
   
272 274
   exe "hi vikiTableRowSep term=bold cterm=bold gui=bold ctermbg=". s:cm2 ."Grey guibg=". s:cm2 ."Grey"
273 275
   

0 notes on commit ffdbcfe

Please sign in to comment.
Something went wrong with that request. Please try again.