[ADD] conf for archlinux, <init>
[arrow.git] / archlinux_conf / home / .vim / autoload / viki_viki.vim
blob7fb9cff0df115bbaa6cd023561328039f825995c
1 " vikiDeplate.vim
2 " @Author:      Thomas Link (micathom AT gmail com?subject=[vim])
3 " @Website:     http://www.vim.org/account/profile.php?user_id=4037
4 " @License:     GPL (see http://www.gnu.org/licenses/gpl.txt)
5 " @Created:     2007-09-03.
6 " @Last Change: 2007-11-15.
7 " @Revision:    0.0.95
9 if &cp || exists("loaded_viki_viki")
10     finish
11 endif
12 let loaded_viki_viki = 1
14 let s:save_cpo = &cpo
15 set cpo&vim
18 """ viki/deplate {{{1
19 " Prepare a buffer for use with viki.vim. Setup all buffer-local 
20 " variables etc.
21 " This also sets up the rx for the different viki name types.
22 " viki_viki#SetupBuffer(state, ?dontSetup='')
23 function! viki_viki#SetupBuffer(state, ...) "{{{3
24     if !g:vikiEnabled
25         return
26     endif
27     " TLogDBG expand('%') .': '. (exists('b:vikiFamily') ? b:vikiFamily : 'default')
29     let dontSetup = a:0 > 0 ? a:1 : ""
30     let noMatch = ""
31    
32     if exists("b:vikiNoSimpleNames") && b:vikiNoSimpleNames
33         let b:vikiNameTypes = substitute(b:vikiNameTypes, '\Cs', '', 'g')
34     endif
35     if exists("b:vikiDisableType") && b:vikiDisableType != ""
36         let b:vikiNameTypes = substitute(b:vikiNameTypes, '\C'. b:vikiDisableType, '', 'g')
37     endif
39     call viki#SetBufferVar("vikiAnchorMarker")
40     call viki#SetBufferVar("vikiSpecialProtocols")
41     call viki#SetBufferVar("vikiSpecialProtocolsExceptions")
42     call viki#SetBufferVar("vikiMarkInexistent")
43     call viki#SetBufferVar("vikiTextstylesVer")
44     " call viki#SetBufferVar("vikiTextstylesVer")
45     call viki#SetBufferVar("vikiLowerCharacters")
46     call viki#SetBufferVar("vikiUpperCharacters")
47     call viki#SetBufferVar("vikiFeedbackMin")
49     if a:state == 1
50         call viki#SetBufferVar("vikiCommentStart", 
51                     \ "b:commentStart", "b:ECcommentOpen", "b:EnhCommentifyCommentOpen",
52                     \ "*matchstr(&commentstring, '^\\zs.*\\ze%s')")
53         call viki#SetBufferVar("vikiCommentEnd",
54                     \ "b:commentEnd", "b:ECcommentClose", "b:EnhCommentifyCommentClose", 
55                     \ "*matchstr(&commentstring, '%s\\zs.*\\ze$')")
56     elseif !exists('b:vikiCommentStart')
57         " This actually is an error.
58         if &debug != ''
59             echom "Viki: FTPlugin wasn't loaded. Viki requires :filetype plugin on"
60         endif
61         let b:vikiCommentStart = '%'
62         let b:vikiCommentEnd   = ''
63     endif
64     
65     let b:vikiSimpleNameQuoteChars = '^][:*/&?<>|\"'
66     
67     let b:vikiSimpleNameQuoteBeg   = '\[-'
68     let b:vikiSimpleNameQuoteEnd   = '-\]'
69     let b:vikiQuotedSelfRef        = "^". b:vikiSimpleNameQuoteBeg . b:vikiSimpleNameQuoteEnd ."$"
70     let b:vikiQuotedRef            = "^". b:vikiSimpleNameQuoteBeg .'.\+'. b:vikiSimpleNameQuoteEnd ."$"
72     let b:vikiAnchorNameRx         = '['. b:vikiLowerCharacters .']['. 
73                 \ b:vikiLowerCharacters . b:vikiUpperCharacters .'_0-9]*'
74     
75     let interviki = '\<['. b:vikiUpperCharacters .']\+::'
77     " if viki#IsSupportedType("sSc") && !(dontSetup =~? "s")
78     if viki#IsSupportedType("s") && !(dontSetup =~? "s")
79         if viki#IsSupportedType("S") && !(dontSetup =~# "S")
80             let quotedVikiName = b:vikiSimpleNameQuoteBeg 
81                         \ .'['. b:vikiSimpleNameQuoteChars .']'
82                         \ .'\{-}'. b:vikiSimpleNameQuoteEnd
83         else
84             let quotedVikiName = ""
85         endif
86         if viki#IsSupportedType("c") && !(dontSetup =~# "c")
87             let simpleWikiName = viki#GetSimpleRx4SimpleWikiName()
88             if quotedVikiName != ""
89                 let quotedVikiName = quotedVikiName .'\|'
90             endif
91         else
92             let simpleWikiName = '\(\)'
93         endif
94         let simpleHyperWords = ''
95         if v:version >= 700 && viki#IsSupportedType('w') && !(dontSetup =~# 'w')
96             let b:vikiHyperWordTable = {}
97             if viki#IsSupportedType('f') && !(dontSetup =~# 'f')
98                 call viki#CollectFileWords(b:vikiHyperWordTable, simpleWikiName)
99             endif
100             call viki#CollectHyperWords(b:vikiHyperWordTable)
101             let hyperWords = keys(b:vikiHyperWordTable)
102             if !empty(hyperWords)
103                 let simpleHyperWords = join(map(hyperWords, '"\\<".tlib#rx#Escape(v:val)."\\>"'), '\|') .'\|'
104                 let simpleHyperWords = substitute(simpleHyperWords, ' \+', '\\s\\+', 'g')
105             endif
106         endif
107         let b:vikiSimpleNameRx = '\C\(\('. interviki .'\)\?'.
108                     \ '\('. simpleHyperWords . quotedVikiName . simpleWikiName .'\)\)'.
109                     \ '\(#\('. b:vikiAnchorNameRx .'\)\>\)\?'
110         let b:vikiSimpleNameSimpleRx = '\C\(\<['.b:vikiUpperCharacters.']\+::\)\?'.
111                     \ '\('. simpleHyperWords . quotedVikiName . simpleWikiName .'\)'.
112                     \ '\(#'. b:vikiAnchorNameRx .'\>\)\?'
113         let b:vikiSimpleNameNameIdx   = 1
114         let b:vikiSimpleNameDestIdx   = 0
115         let b:vikiSimpleNameAnchorIdx = 6
116         let b:vikiSimpleNameCompound = 'let erx="'. escape(b:vikiSimpleNameRx, '\"')
117                     \ .'" | let nameIdx='. b:vikiSimpleNameNameIdx
118                     \ .' | let destIdx='. b:vikiSimpleNameDestIdx
119                     \ .' | let anchorIdx='. b:vikiSimpleNameAnchorIdx
120     else
121         let b:vikiSimpleNameRx        = noMatch
122         let b:vikiSimpleNameSimpleRx  = noMatch
123         let b:vikiSimpleNameNameIdx   = 0
124         let b:vikiSimpleNameDestIdx   = 0
125         let b:vikiSimpleNameAnchorIdx = 0
126     endif
127    
128     if viki#IsSupportedType("u") && !(dontSetup =~# "u")
129         let urlChars = 'A-Za-z0-9.,:%?=&_~@$/|+-'
130         let b:vikiUrlRx = '\<\(\('.b:vikiSpecialProtocols.'\):['. urlChars .']\+\)'.
131                     \ '\(#\([A-Za-z0-9]*\)\)\?'
132         let b:vikiUrlSimpleRx = '\<\('. b:vikiSpecialProtocols .'\):['. urlChars .']\+'.
133                     \ '\(#[A-Za-z0-9]*\)\?'
134         let b:vikiUrlNameIdx   = 0
135         let b:vikiUrlDestIdx   = 1
136         let b:vikiUrlAnchorIdx = 4
137         let b:vikiUrlCompound = 'let erx="'. escape(b:vikiUrlRx, '\"')
138                     \ .'" | let nameIdx='. b:vikiUrlNameIdx
139                     \ .' | let destIdx='. b:vikiUrlDestIdx
140                     \ .' | let anchorIdx='. b:vikiUrlAnchorIdx
141     else
142         let b:vikiUrlRx        = noMatch
143         let b:vikiUrlSimpleRx  = noMatch
144         let b:vikiUrlNameIdx   = 0
145         let b:vikiUrlDestIdx   = 0
146         let b:vikiUrlAnchorIdx = 0
147     endif
148    
149     if viki#IsSupportedType("x") && !(dontSetup =~# "x")
150         " let vikicmd = '['. b:vikiUpperCharacters .']\w*'
151         let vikicmd    = '\(IMG\|Img\|INC\%[LUDE]\)\>'
152         let vikimacros = '\(img\|ref\)\>'
153         let b:vikiCmdRx        = '\({'. vikimacros .'\|#'. vikicmd .'\)\(.\{-}\):\s*\(.\{-}\)\($\|}\)'
154         let b:vikiCmdSimpleRx  = '\({'. vikimacros .'\|#'. vikicmd .'\).\{-}\($\|}\)'
155         let b:vikiCmdNameIdx   = 1
156         let b:vikiCmdDestIdx   = 5
157         let b:vikiCmdAnchorIdx = 4
158         let b:vikiCmdCompound = 'let erx="'. escape(b:vikiCmdRx, '\"')
159                     \ .'" | let nameIdx='. b:vikiCmdNameIdx
160                     \ .' | let destIdx='. b:vikiCmdDestIdx
161                     \ .' | let anchorIdx='. b:vikiCmdAnchorIdx
162     else
163         let b:vikiCmdRx        = noMatch
164         let b:vikiCmdSimpleRx  = noMatch
165         let b:vikiCmdNameIdx   = 0
166         let b:vikiCmdDestIdx   = 0
167         let b:vikiCmdAnchorIdx = 0
168     endif
169     
170     if viki#IsSupportedType("e") && !(dontSetup =~# "e")
171         let b:vikiExtendedNameRx = 
172                     \ '\[\[\(\('.b:vikiSpecialProtocols.'\)://[^]]\+\|[^]#]\+\)\?'.
173                     \ '\(#\([^]]*\)\)\?\]\(\[\([^]]\+\)\]\)\?\([!~*$\-]*\)\]'
174                     " \ '\(#\('. b:vikiAnchorNameRx .'\)\)\?\]\(\[\([^]]\+\)\]\)\?[!~*\-]*\]'
175         let b:vikiExtendedNameSimpleRx = 
176                     \ '\[\[\('. b:vikiSpecialProtocols .'://[^]]\+\|[^]#]\+\)\?'.
177                     \ '\(#[^]]*\)\?\]\(\[[^]]\+\]\)\?[!~*$\-]*\]'
178                     " \ '\(#'. b:vikiAnchorNameRx .'\)\?\]\(\[[^]]\+\]\)\?[!~*\-]*\]'
179         let b:vikiExtendedNameNameIdx   = 6
180         let b:vikiExtendedNameModIdx    = 7
181         let b:vikiExtendedNameDestIdx   = 1
182         let b:vikiExtendedNameAnchorIdx = 4
183         let b:vikiExtendedNameCompound = 'let erx="'. escape(b:vikiExtendedNameRx, '\"')
184                     \ .'" | let nameIdx='. b:vikiExtendedNameNameIdx
185                     \ .' | let destIdx='. b:vikiExtendedNameDestIdx
186                     \ .' | let anchorIdx='. b:vikiExtendedNameAnchorIdx
187     else
188         let b:vikiExtendedNameRx        = noMatch
189         let b:vikiExtendedNameSimpleRx  = noMatch
190         let b:vikiExtendedNameNameIdx   = 0
191         let b:vikiExtendedNameDestIdx   = 0
192         let b:vikiExtendedNameAnchorIdx = 0
193     endif
195     let b:vikiInexistentHighlight = "vikiInexistentLink"
197     if a:state == 2
198         if g:vikiAutoMarks
199             call viki#SetAnchorMarks()
200         endif
201         if g:vikiNameSuffix != ''
202             exec 'setlocal suffixesadd+='. g:vikiNameSuffix
203         endif
204         if exists('b:vikiNameSuffix') && b:vikiNameSuffix != '' && b:vikiNameSuffix != g:vikiNameSuffix
205             exec 'setlocal suffixesadd+='. b:vikiNameSuffix
206         endif
207         if exists('g:loaded_hookcursormoved') && g:loaded_hookcursormoved >= 3 && exists('b:vikiMarkInexistent') && b:vikiMarkInexistent
208             let b:hookcursormoved_syntaxleave = ['vikiLink', 'vikiExtendedLink', 'vikiURL', 'vikiOkLink', 'vikiInexistentLink']
209             for cond in g:vikiHCM
210                 call hookcursormoved#Register(cond, function('viki#HookCheckPreviousPosition'))
211             endfor
212         endif
213     endif
214 endf
217 " Define viki core syntax groups for hyperlinks
218 function! viki_viki#DefineMarkup(state) "{{{3
219     if viki#IsSupportedType("sS") && b:vikiSimpleNameSimpleRx != ""
220         exe "syntax match vikiLink /" . b:vikiSimpleNameSimpleRx . "/"
221     endif
222     if viki#IsSupportedType("e") && b:vikiExtendedNameSimpleRx != ""
223         exe "syntax match vikiExtendedLink '" . b:vikiExtendedNameSimpleRx . "' skipnl"
224     endif
225     if viki#IsSupportedType("u") && b:vikiUrlSimpleRx != ""
226         exe "syntax match vikiURL /" . b:vikiUrlSimpleRx . "/"
227     endif
228 endf
231 " Define the highlighting of the core syntax groups for hyperlinks
232 function! viki_viki#DefineHighlighting(state) "{{{3
233     exec 'hi vikiInexistentLink '. g:viki_highlight_inexistent_{&background}
234     exec 'hi vikiHyperLink '. g:viki_highlight_hyperlink_{&background}
236     if viki#IsSupportedType("sS")
237         hi def link vikiLink vikiHyperLink
238         hi def link vikiOkLink vikiHyperLink
239         hi def link vikiRevLink Normal
240     endif
241     if viki#IsSupportedType("e")
242         hi def link vikiExtendedLink vikiHyperLink
243         hi def link vikiExtendedOkLink vikiHyperLink
244         hi def link vikiRevExtendedLink Normal
245     endif
246     if viki#IsSupportedType("u")
247         hi def link vikiURL vikiHyperLink
248     endif
249 endf
252 " Define viki-related key maps
253 function! viki_viki#MapKeys(state) "{{{3
254     if exists('b:vikiDidMapKeys')
255         return
256     endif
257     if a:state == 1
258         if exists('b:vikiMapFunctionalityMinor') && b:vikiMapFunctionalityMinor
259             let mf = b:vikiMapFunctionalityMinor
260         else
261             let mf = g:vikiMapFunctionalityMinor
262         endif
263     elseif exists('b:vikiMapFunctionality') && b:vikiMapFunctionality
264         let mf = b:vikiMapFunctionality
265     else
266         let mf = g:vikiMapFunctionality
267     endif
269     " if !hasmapto('viki#MaybeFollowLink')
270         if viki#MapFunctionality(mf, 'c')
271             nnoremap <buffer> <silent> <c-cr> :call viki#MaybeFollowLink(0,1)<cr>
272             inoremap <buffer> <silent> <c-cr> <c-o>:call viki#MaybeFollowLink(0,1)<cr>
273             " nnoremap <buffer> <silent> <LocalLeader><c-cr> :call viki#MaybeFollowLink(0,1,-1)<cr>
274         endif
275         if viki#MapFunctionality(mf, 'f')
276             " nnoremap <buffer> <silent> <c-cr> :call viki#MaybeFollowLink(0,1)<cr>
277             " inoremap <buffer> <silent> <c-cr> <c-o>:call viki#MaybeFollowLink(0,1)<cr>
278             " nnoremap <buffer> <silent> <LocalLeader><c-cr> :call viki#MaybeFollowLink(0,1,-1)<cr>
279             exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'f :call viki#MaybeFollowLink(0,1)<cr>'
280             exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'s :call viki#MaybeFollowLink(0,1,-1)<cr>'
281             exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'v :call viki#MaybeFollowLink(0,1,-2)<cr>'
282             exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'1 :call viki#MaybeFollowLink(0,1,1)<cr>'
283             exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'2 :call viki#MaybeFollowLink(0,1,2)<cr>'
284             exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'3 :call viki#MaybeFollowLink(0,1,3)<cr>'
285             exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'4 :call viki#MaybeFollowLink(0,1,4)<cr>'
286             exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'t :call viki#MaybeFollowLink(0,1,"tab")<cr>'
287         endif
288         if viki#MapFunctionality(mf, 'mf')
289             " && !hasmapto("viki#MaybeFollowLink")
290             nnoremap <buffer> <silent> <m-leftmouse> <leftmouse>:call viki#MaybeFollowLink(0,1)<cr>
291             inoremap <buffer> <silent> <m-leftmouse> <leftmouse><c-o>:call viki#MaybeFollowLink(0,1)<cr>
292         endif
293     " endif
295     " if !hasmapto('VikiMarkInexistent')
296         if viki#MapFunctionality(mf, 'i')
297             exec 'noremap <buffer> <silent> '. g:vikiMapLeader .'d :call viki#MarkInexistentInElement("Document")<cr>'
298             exec 'noremap <buffer> <silent> '. g:vikiMapLeader .'p :call viki#MarkInexistentInElement("Paragraph")<cr>'
299         endif
300         if viki#MapFunctionality(mf, 'I')
301             if g:vikiMapInexistent
302                 let i = 0
303                 let m = strlen(g:vikiMapKeys)
304                 while i < m
305                     let k = g:vikiMapKeys[i]
306                     call viki#MapMarkInexistent(k, "LineQuick")
307                     let i = i + 1
308                 endwh
309                 let i = 0
310                 let m = strlen(g:vikiMapQParaKeys)
311                 while i < m
312                     let k = g:vikiMapQParaKeys[i]
313                     call viki#MapMarkInexistent(k, "ParagraphVisible")
314                     let i = i + 1
315                 endwh
316             endif
317         endif
318     " endif
320     if viki#MapFunctionality(mf, 'e')
321         " && !hasmapto("viki#Edit")
322         exec 'noremap <buffer> '. g:vikiMapLeader .'e :VikiEdit '
323     endif
324     
325     if viki#MapFunctionality(mf, 'q') && exists("*VEnclose")
326         " && !hasmapto("VikiQuote")
327         exec 'vnoremap <buffer> <silent> '. g:vikiMapLeader .'q :VikiQuote<cr><esc>:call viki#MarkInexistentInElement("LineQuick")<cr>'
328         exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'q viw:VikiQuote<cr><esc>:call viki#MarkInexistentInElement("LineQuick")<cr>'
329         exec 'inoremap <buffer> <silent> '. g:vikiMapLeader .'q <esc>viw:VikiQuote<cr>:call viki#MarkInexistentInElement("LineQuick")<cr>i'
330     endif
331     
332     if viki#MapFunctionality(mf, 'p')
333         exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'<bs> :call viki#GoParent()<cr>'
334         exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'<up> :call viki#GoParent()<cr>'
335     endif
337     if viki#MapFunctionality(mf, 'b')
338         " && !hasmapto("VikiGoBack")
339         exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'b :call viki#GoBack()<cr>'
340         exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'<left> :call viki#GoBack()<cr>'
341     endif
342     if viki#MapFunctionality(mf, 'mb')
343         nnoremap <buffer> <silent> <m-rightmouse> <leftmouse>:call viki#GoBack(0)<cr>
344         inoremap <buffer> <silent> <m-rightmouse> <leftmouse><c-o>:call viki#GoBack(0)<cr>
345     endif
346     
347     if viki#MapFunctionality(mf, 'F')
348         exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'n :VikiFindNext<cr>'
349         exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'N :VikiFindPrev<cr>'
350         exec 'nmap <buffer> <silent> '. g:vikiMapLeader .'F '. g:vikiMapLeader .'n'. g:vikiMapLeader .'f'
351     endif
352     if viki#MapFunctionality(mf, 'tF')
353         nnoremap <buffer> <silent> <c-tab>   :VikiFindNext<cr>
354         nnoremap <buffer> <silent> <c-s-tab> :VikiFindPrev<cr>
355     endif
356     if viki#MapFunctionality(mf, 'Files')
357         exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'u :VikiFilesUpdate<cr>'
358         exec 'nnoremap <buffer> <silent> '. g:vikiMapLeader .'U :VikiFilesUpdateAll<cr>'
359         exec 'nnoremap <buffer> '. g:vikiMapLeader .'x :VikiFilesExec '
360         exec 'nnoremap <buffer> '. g:vikiMapLeader .'X :VikiFilesExec! '
361     endif
362     let b:vikiDidMapKeys = 1
363 endf
366 " Initialize viki as minor mode (add-on to some buffer filetype)
367 "state ... no-op:0, minor:1, major:2
368 function! viki_viki#MinorMode(state) "{{{3
369     if !g:vikiEnabled
370         return 0
371     endif
372     if a:state == 0
373         return 0
374     endif
375     let state = a:state < 0 ? -a:state : a:state
376     let vf = viki#Family(1)
377     " c ... CamelCase 
378     " s ... Simple viki name 
379     " S ... Simple quoted viki name
380     " e ... Extended viki name
381     " u ... URL
382     " i ... InterViki
383     " call viki#SetBufferVar('vikiNameTypes', 'g:vikiNameTypes', "*'csSeui'")
384     call viki#SetBufferVar('vikiNameTypes')
385     call viki#DispatchOnFamily('SetupBuffer', vf, state)
386     call viki#DispatchOnFamily('DefineMarkup', vf, state)
387     call viki#DispatchOnFamily('DefineHighlighting', vf, state)
388     call viki#DispatchOnFamily('MapKeys', vf, state)
389     if !exists('b:vikiEnabled') || b:vikiEnabled < state
390         let b:vikiEnabled = state
391     endif
392     " call viki#DispatchOnFamily('VikiDefineMarkup', vf, state)
393     " call viki#DispatchOnFamily('VikiDefineHighlighting', vf, state)
394     return 1
395 endf
398 " Find an anchor
399 function! viki_viki#FindAnchor(anchor) "{{{3
400     " TLogVAR a:anchor
401     if a:anchor == g:vikiDefNil || a:anchor == ''
402         return
403     endif
404     let mode = matchstr(a:anchor, '^\(l\(ine\)\?\|rx\|vim\)\ze=')
405     if exists('*VikiAnchor_'. mode)
406         let arg  = matchstr(a:anchor, '=\zs.\+$')
407         call VikiAnchor_{mode}(arg)
408     else
409         let co = col('.')
410         let li = line('.')
411         let anchorRx = viki#GetAnchorRx(a:anchor)
412         " TLogVAR anchorRx
413         keepjumps go
414         let found = search(anchorRx, 'Wc')
415         " TLogVAR found
416         if !found
417             call cursor(li, co)
418             if g:vikiFreeMarker
419                 call search('\c\V'. escape(a:anchor, '\'), 'w')
420             endif
421         endif
422     endif
423     exec g:vikiPostFindAnchor
424 endf
427 " Complete missing information in the definition of an extended viki name
428 function! viki_viki#CompleteExtendedNameDef(def) "{{{3
429     " TLogVAR a:def
430     exec viki#SplitDef(a:def)
431     if v_dest == g:vikiDefNil
432         if v_anchor == g:vikiDefNil
433             throw "Viki: Malformed extended viki name (no destination): ". string(a:def)
434         else
435             let v_dest = g:vikiSelfRef
436         endif
437     elseif viki#IsInterViki(v_dest)
438         let useSuffix = viki#InterVikiSuffix(v_dest)
439         let v_dest = viki#InterVikiDest(v_dest)
440         " TLogVAR v_dest
441         if v_dest != g:vikiDefNil
442             let v_dest = viki#ExpandSimpleName('', v_dest, useSuffix)
443             " TLogVAR v_dest
444         endif
445     else
446         if v_dest =~? '^[a-z]:'                      " an absolute dos path
447         elseif v_dest =~? '^\/'                          " an absolute unix path
448         elseif v_dest =~? '^'.b:vikiSpecialProtocols.':' " some protocol
449         elseif v_dest =~ '^\~'                           " user home
450             " let v_dest = $HOME . strpart(v_dest, 1)
451             let v_dest = fnamemodify(v_dest, ':p')
452             let v_dest = viki#CanonicFilename(v_dest)
453         else                                           " a relative path
454             let v_dest = expand("%:p:h") .g:vikiDirSeparator. v_dest
455             let v_dest = viki#CanonicFilename(v_dest)
456         endif
457         if v_dest != '' && v_dest != g:vikiSelfRef && !viki#IsSpecial(v_dest)
458             let mod = viki#ExtendedModifier(v_part)
459             if fnamemodify(v_dest, ':e') == '' && mod !~# '!'
460                 let v_dest = viki#WithSuffix(v_dest)
461             endif
462         endif
463     endif
464     if v_name == g:vikiDefNil
465         let v_name = fnamemodify(v_dest, ':t:r')
466     endif
467     let v_type = v_type == g:vikiDefNil ? 'e' : v_type
468     " TLogVAR v_name, v_dest, v_anchor, v_part, v_type
469     return viki#MakeDef(v_name, v_dest, v_anchor, v_part, v_type)
470 endf
473 " Complete missing information in the definition of a command viki name
474 function! viki_viki#CompleteCmdDef(def) "{{{3
475     " TLogVAR a:def
476     exec viki#SplitDef(a:def)
477     " TLogVAR v_name, v_dest, v_anchor
478     let args     = v_anchor
479     let v_anchor = g:vikiDefNil
480     if v_name ==# "#IMG" || v_name =~# "{img"
481         let v_dest = viki#FindFileWithSuffix(v_dest, viki#GetSpecialFilesSuffixes())
482         " TLogVAR v_dest
483     elseif v_name ==# "#Img"
484         let id = matchstr(args, '\sid=\zs\w\+')
485         if id != ''
486             let v_dest = viki#FindFileWithSuffix(id, viki#GetSpecialFilesSuffixes())
487         endif
488     elseif v_name =~ "^#INC"
489         " <+TBD+> Search path?
490     elseif v_name =~ '^{ref\>'
491         let v_anchor = v_dest
492         let v_name = g:vikiSelfRef
493         let v_dest = g:vikiSelfRef
494         " TLogVAR v_name, v_anchor, v_dest
495     else
496         " throw "Viki: Unknown command: ". v_name
497         let v_name = g:vikiDefNil
498         let v_dest = g:vikiDefNil
499         " let v_anchor = g:vikiDefNil
500     endif
501     let v_type = v_type == g:vikiDefNil ? 'cmd' : v_type
502     let vdef   = viki#MakeDef(v_name, v_dest, v_anchor, v_part, v_type)
503     " TLogVAR vdef
504     return vdef
505 endf
508 " Complete missing information in the definition of a simple viki name
509 function! viki_viki#CompleteSimpleNameDef(def) "{{{3
510     " TLogVAR a:def
511     exec viki#SplitDef(a:def)
512     if v_name == g:vikiDefNil
513         throw "Viki: Malformed simple viki name (no name): ". string(a:def)
514     endif
516     if !(v_dest == g:vikiDefNil)
517         throw "Viki: Malformed simple viki name (destination=".v_dest."): ". string(a:def)
518     endif
520     " TLogVAR v_name
521     if viki#IsInterViki(v_name)
522         let i_name = viki#InterVikiName(v_name)
523         let useSuffix = viki#InterVikiSuffix(v_name)
524         let v_name = viki#InterVikiPart(v_name)
525     elseif viki#IsHyperWord(v_name)
526         let hword = viki#HyperWordValue(v_name)
527         if type(hword) == 4
528             let i_name = hword.interviki
529             let useSuffix = hword.suffix
530             let v_name = hword.name
531         else
532             let i_name = ''
533             let useSuffix = ''
534             let v_name = hword
535         end
536     else
537         let i_name = ''
538         let v_dest = expand("%:p:h")
539         let useSuffix = g:vikiDefSep
540     endif
541     " TLogVAR i_name
543     if viki#IsSupportedType("S")
544         " TLogVAR v_name
545         if v_name =~ b:vikiQuotedSelfRef
546             let v_name  = g:vikiSelfRef
547         elseif v_name =~ b:vikiQuotedRef
548             let v_name = matchstr(v_name, "^". b:vikiSimpleNameQuoteBeg .'\zs.\+\ze'. b:vikiSimpleNameQuoteEnd ."$")
549         endif
550     elseif !viki#IsSupportedType("c")
551         throw "Viki: CamelCase names not allowed"
552     endif
554     if v_name != g:vikiSelfRef
555         " TLogVAR v_dest, v_name, useSuffix
556         let rdest = viki#ExpandSimpleName(v_dest, v_name, useSuffix)
557         " TLogVAR rdest
558     else
559         let rdest = g:vikiDefNil
560         " TLogVAR rdest
561     endif
563     if i_name != ''
564         let rdest = viki#InterVikiDest(rdest, i_name)
565         " TLogVAR rdest
566         " let v_name = ''
567     endif
569     let v_type   = v_type == g:vikiDefNil ? 's' : v_type
570     " TLogVAR v_type
571     return viki#MakeDef(v_name, rdest, v_anchor, v_part, v_type)
572 endf
575 " Find a viki name
576 " viki_viki#Find(flag, ?count=0, ?rx=nil)
577 function! viki_viki#Find(flag, ...) "{{{3
578     let rx = (a:0 >= 2 && a:2 != '') ? a:2 : viki#FindRx()
579     if rx != ""
580         let i = a:0 >= 1 ? a:1 : 0
581         while i >= 0
582             call search(rx, a:flag)
583             let i = i - 1
584         endwh
585     endif
586 endf
589 let &cpo = s:save_cpo
590 unlet s:save_cpo