Skip to content

Commit

Permalink
Version 3.3
Browse files Browse the repository at this point in the history
- Use hookcursormoved >= 0.3
- Backslash-save command-line completion
- Mark unknown intervikis as inexistent
  • Loading branch information
tomtom authored and vim-scripts committed Nov 14, 2010
1 parent b336bc2 commit 8f34d38
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 41 deletions.
82 changes: 62 additions & 20 deletions autoload/viki.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-03-25.
" @Last Change: 2007-10-04.
" @Revision: 0.284
" @Last Change: 2007-10-12.
" @Revision: 0.381

if &cp || exists("loaded_viki_auto") "{{{2
finish
Expand Down Expand Up @@ -264,6 +264,7 @@ function! s:MarkInexistent(line1, line2, ...) "{{{3
endif
let ll = li
let co1 = co - 1
" TLogVAR co1
let def = viki#GetLink(1, getline('.'), co1)
" TAssert IsList(def)
" TLogDBG getline('.')[co1 : -1]
Expand All @@ -280,6 +281,9 @@ function! s:MarkInexistent(line1, line2, ...) "{{{3
elseif v:version >= 700 && viki#IsHyperWord(v_part)
" TLogDBG "viki#IsHyperWord(v_part) => 0"
let check = 0
elseif v_name == g:vikiSelfRef
" TLogDBG "simple self ref"
let check = 0
else
" TLogDBG "else1 => 1"
let check = 1
Expand Down Expand Up @@ -313,14 +317,16 @@ function! s:MarkInexistent(line1, line2, ...) "{{{3
let check = 0
endif
" TLogVAR check, v_dest
if check && v_dest != "" && v_dest != g:vikiSelfRef && !isdirectory(v_dest)
" if check && v_dest != "" && v_dest != g:vikiSelfRef && !isdirectory(v_dest)
if check && v_dest != g:vikiSelfRef && !isdirectory(v_dest)
if filereadable(v_dest)
call filter(b:vikiNamesNull, 'v:val != partx')
call insert(b:vikiNamesOk, partx)
else
call insert(b:vikiNamesNull, partx)
call filter(b:vikiNamesOk, 'v:val != partx')
endif
" TLogVAR partx, b:vikiNamesNull, b:vikiNamesOk
endif
endif
unlet! def
Expand Down Expand Up @@ -748,12 +754,12 @@ function! viki#MapMarkInexistent(key, element) "{{{3
exe 'inoremap <silent> <buffer> '. key .' '. map
endf


" In case this function gets called repeatedly for the same position, check only once.
let s:hookcursormoved_oldpos = []
function! viki#HookCheckPreviousPosition(mode) "{{{3
" if a:mode == 'n'
if s:hookcursormoved_oldpos != b:hookcursormoved_oldpos
" call setpos('.', b:hookcursormoved_oldpos)
" keepjumps keepmarks call s:MarkInexistentInLine()
keepjumps keepmarks call s:MarkInexistent(b:hookcursormoved_oldpos[1], b:hookcursormoved_oldpos[1])
let s:hookcursormoved_oldpos = b:hookcursormoved_oldpos
endif
Expand Down Expand Up @@ -1394,29 +1400,33 @@ endf

" Return a viki filename with a suffix
function! viki#WithSuffix(fname)
" TLogVAR a:fname
" TLogDBG isdirectory(a:fname)
if isdirectory(a:fname)
return a:fname
else
return a:fname.s:GetSuffix()
return a:fname . s:GetSuffix()
endif
endf

" Get the suffix to use for viki filenames
function! s:GetSuffix() "{{{3
if exists("b:vikiNameSuffix")
if exists('b:vikiNameSuffix')
return b:vikiNameSuffix
endif
if g:vikiUseParentSuffix
let sfx = expand("%:e")
if sfx != ""
return ".".sfx
" TLogVAR sfx
if !empty(sfx)
return '.'. sfx
endif
endif
return g:vikiNameSuffix
endf

" Return the real destination for a simple viki name
function! viki#ExpandSimpleName(dest, name, suffix) "{{{3
" TLogVAR a:dest
if a:name == ''
return a:dest
else
Expand All @@ -1425,11 +1435,15 @@ function! viki#ExpandSimpleName(dest, name, suffix) "{{{3
else
let dest = a:dest . g:vikiDirSeparator . a:name
endif
" TLogVAR dest, a:suffix
if a:suffix == g:vikiDefSep
" TLogDBG 'ExpandSimpleName 1'
return viki#WithSuffix(dest)
elseif isdirectory(dest)
" TLogDBG 'ExpandSimpleName 2'
return dest
else
" TLogDBG 'ExpandSimpleName 3'
return dest . a:suffix
endif
endif
Expand Down Expand Up @@ -1457,10 +1471,11 @@ function! s:InterVikiDef(vikiname, ...)
let ow = a:0 >= 1 ? a:1 : viki#InterVikiName(a:vikiname)
let vd = s:LetVar('i_dest', 'vikiInter'.ow)
let id = s:LetVar('i_index', 'vikiInter'.ow.'_index')
" TLogVAR a:vikiname, ow, vd, id
" TLogVAR a:vikiname, ow, id
if !empty(id)
let vd .= '|'. id
endif
" TLogVAR vd
if vd != ''
exec vd
if i_dest =~ '^\*\S\+('
Expand All @@ -1477,35 +1492,59 @@ endf

" Return an interviki's root directory
function! viki#InterVikiDest(vikiname, ...)
if a:0 >= 1 && a:1 != ''
let ow = a:1
let v_dest = a:vikiname
else
let ow = viki#InterVikiName(a:vikiname)
TVarArg 'ow', ['rx', 0]
" TLogVAR ow, rx
if empty(ow)
let ow = viki#InterVikiName(a:vikiname)
let v_dest = viki#InterVikiPart(a:vikiname)
else
let v_dest = a:vikiname
endif
let vd = s:InterVikiDef(a:vikiname, ow)
" TLogVAR vd
if vd != ''
exec vd
let f = strpart(i_dest, 1)
" TLogVAR i_type, i_dest
if !empty(rx)
let f = s:RxifyFilename(f)
endif
if i_type == 'fn'
let f = strpart(i_dest, 1)
exec 'let v_dest = '. s:sprintf1(f, v_dest)
elseif i_type == 'fmt'
let f = strpart(i_dest, 1)
let v_dest = s:sprintf1(f, v_dest)
else
if empty(v_dest) && exists('i_index')
let v_dest = i_index
endif
let v_dest = expand(i_dest) . g:vikiDirSeparator . v_dest
let i_dest = expand(i_dest)
if !empty(rx)
let sep = '[\/]'
let i_dest = s:RxifyFilename(i_dest)
else
let sep = g:vikiDirSeparator
endif
let v_dest = i_dest . sep . v_dest
endif
" TLogVAR v_dest
return v_dest
else
echoerr "Viki: InterViki is not defined: ". ow
" TLogVAR ow
echohl Error
echom "Viki: InterViki is not defined: ". ow
echohl NONE
return g:vikiDefNil
endif
endf

function! s:RxifyFilename(filename) "{{{3
let f = tlib#rx#Escape(a:filename)
if exists('+shellslash')
let f = substitute(f, '\(\\\\\|/\)', '[\\/]', 'g')
endif
return f
endf

" Return an interviki's suffix
function! viki#InterVikiSuffix(vikiname, ...)
exec tlib#arg#Let(['ow'])
Expand Down Expand Up @@ -1826,21 +1865,24 @@ function! viki#EditComplete(ArgLead, CmdLine, CursorPos) "{{{3
" TLogDBG 'A'
let f = matchstr(arglead, '::\(\[-\)\?\zs.*$')
let d = viki#InterVikiDest(f.'*', i)
let r = '\V\^'. viki#InterVikiDest('\(\.\{-}\)', i) .'\$'
let r = '^'. viki#InterVikiDest('\(.\{-}\)', i, 1) .'$'
" TLogVAR f,d,r
let d = substitute(d, '\', '/', 'g')
let rv = split(glob(d), '\n')
" TLogVAR d,rv
if sfx != ''
call filter(rv, 'isdirectory(v:val) || ".". fnamemodify(v:val, ":e") == sfx')
endif
" TLogVAR rv
call map(rv, 's:EditCompleteMapAgent1(v:val, sfx, i, r)')
" TLogVAR rv
call filter(rv, '!empty(v:val)')
" TLogVAR rv
" call map(rv, string(i). '."::". substitute(v:val, r, ''\1'', "")')
else
" TLogDBG 'B'
let rv = split(glob(arglead.'*'.sfx), '\n')
" TLogVAR rv
call map(rv, 's:EditCompleteAgent('. string(i) .', v:val, v:val)')
" TLogVAR rv
if arglead == ''
Expand Down
4 changes: 2 additions & 2 deletions autoload/viki_anyword.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
" @Author: Thomas Link (mailto:micathom AT gmail com?subject=vim-vikiAnyWord)
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 04-Apr-2005.
" @Last Change: 2007-10-05.
" @Revision: 0.31
" @Last Change: 2007-10-12.
" @Revision: 0.35

if &cp || exists('loaded_viki_anyword')
finish
Expand Down
18 changes: 13 additions & 5 deletions autoload/viki_viki.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
" @Website: http://www.vim.org/account/profile.php?user_id=4037
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 2007-09-03.
" @Last Change: 2007-10-05.
" @Revision: 0.0.70
" @Last Change: 2007-10-12.
" @Revision: 0.0.89

if &cp || exists("loaded_viki_viki")
finish
Expand Down Expand Up @@ -204,9 +204,10 @@ function! viki_viki#SetupBuffer(state, ...) "{{{3
if exists('b:vikiNameSuffix') && b:vikiNameSuffix != '' && b:vikiNameSuffix != g:vikiNameSuffix
exec 'setlocal suffixesadd+='. b:vikiNameSuffix
endif
if exists('g:loaded_hookcursormoved') && exists('b:vikiMarkInexistent') && b:vikiMarkInexistent
if exists('g:loaded_hookcursormoved') && g:loaded_hookcursormoved >= 3 && exists('b:vikiMarkInexistent') && b:vikiMarkInexistent
let b:hookcursormoved_syntaxleave = ['vikiLink', 'vikiExtendedLink', 'vikiURL', 'vikiOkLink', 'vikiInexistentLink']
for cond in g:vikiHCM
call hookcursormoved#Register('b', cond, function('viki#HookCheckPreviousPosition'))
call hookcursormoved#Register(cond, function('viki#HookCheckPreviousPosition'))
endfor
endif
endif
Expand Down Expand Up @@ -512,6 +513,7 @@ function! viki_viki#CompleteSimpleNameDef(def) "{{{3
throw "Viki: Malformed simple viki name (destination=".v_dest."): ". string(a:def)
endif

" TLogVAR v_name
if viki#IsInterViki(v_name)
let i_name = viki#InterVikiName(v_name)
let useSuffix = viki#InterVikiSuffix(v_name)
Expand All @@ -532,7 +534,8 @@ function! viki_viki#CompleteSimpleNameDef(def) "{{{3
let v_dest = expand("%:p:h")
let useSuffix = g:vikiDefSep
endif

" TLogVAR i_name

if viki#IsSupportedType("S")
" TLogVAR v_name
if v_name =~ b:vikiQuotedSelfRef
Expand All @@ -545,17 +548,22 @@ function! viki_viki#CompleteSimpleNameDef(def) "{{{3
endif

if v_name != g:vikiSelfRef
" TLogVAR v_dest, v_name, useSuffix
let rdest = viki#ExpandSimpleName(v_dest, v_name, useSuffix)
" TLogVAR rdest
else
let rdest = g:vikiDefNil
" TLogVAR rdest
endif

if i_name != ''
let rdest = viki#InterVikiDest(rdest, i_name)
" TLogVAR rdest
" let v_name = ''
endif

let v_type = v_type == g:vikiDefNil ? 's' : v_type
" TLogVAR v_type
return viki#MakeDef(v_name, rdest, v_anchor, v_part, v_type)
endf

Expand Down
13 changes: 7 additions & 6 deletions doc/viki.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ markup.
MINOR WIKI MODE:
Just type |:VikiMinorMode| and all wiki names and URLs will be highlighted.
When the cursor is over a wiki name, you can press <c-cr> to jump to (or
create) the referred page. Pressing <LocalLeader>vb brings you back to the
original document. Alternatively, you can use <m-leftmouse> and <m-rightmouse>
to jump back and forth. (NOTE: In minor mode, it's possible that viki words
and URLs are not highlighted when they are included in some syntactic
regions.)
create) the referred page (on a terminal use <LocalLeader>vf). Pressing
<LocalLeader>vb brings you back to the original document. Alternatively, you
can use <m-leftmouse> and <m-rightmouse> to jump back and forth. (NOTE: In
minor mode, it's possible that viki words and URLs are not highlighted when
they are included in some syntactic regions.)

FULL WIKI MODE:
In full mode, viki becomes a personal wiki
Expand Down Expand Up @@ -588,7 +588,8 @@ Default Key Binding~

<c-cr> ... |viki#MaybeFollowLink()|: Usually only works when the cursor is over
a wiki syntax group -- if the second argument is 1 it tries to interpret the
text under the cursor as a wiki name anyway.
text under the cursor as a wiki name anyway. (NOTE: If you're working on a
terminal, <c-cr> most likely won't work. Use <LocalLeader>vf instead.)

<LocalLeader>vf ... Open in window
<LocalLeader>vt ... Open in a new tab
Expand Down
21 changes: 13 additions & 8 deletions plugin/viki.vim
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
" @Author: Thomas Link (micathom AT gmail com?subject=vim)
" @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
" @Created: 08-Dec-2003.
" @Last Change: 2007-10-05.
" @Revision: 3.2.2502
" @Last Change: 2007-10-11.
" @Revision: 3.3.2520
"
" GetLatestVimScripts: 861 1 viki.vim
"
" Short Description:
" This plugin adds wiki-like hypertext capabilities to any document. Just
" type :VikiMinorMode and all wiki names will be highlighted. If you press
" <c-cr> when the cursor is over a wiki name, you jump to (or create) the
" referred page. When invoked as :VikiMode or via :set ft=viki additional
" highlighting is provided.
" <c-cr> (or <LocalLeader>vf) when the cursor is over a wiki name, you
" jump to (or create) the referred page. When invoked via :set ft=viki,
" additional highlighting is provided.
"
" Requirements:
" - tlib.vim (vimscript #1863)
Expand All @@ -38,7 +38,7 @@ if !exists('loaded_tlib') || loaded_tlib < 15
echoerr 'tlib >= 0.15 is required'
finish
endif
let loaded_viki = 302
let loaded_viki = 303

" This is what we consider nil, in the absence of nil in vimscript
let g:vikiDefNil = ''
Expand Down Expand Up @@ -225,8 +225,7 @@ if !exists("g:vikiMapQParaKeys") | let g:vikiMapQParaKeys = "\n" | endif
" installed)
" "linechange" could cause some slowdown.
if !exists("g:vikiHCM") "{{{2
let g:vikiHCM = ['linechange', 'syntaxchange']
" let g:vikiHCM = ['syntaxchange']
let g:vikiHCM = ['syntaxleave_oneline']
endif

" Check the viki name before inserting this character
Expand Down Expand Up @@ -358,6 +357,7 @@ if !exists('*VikiOpenSpecialFile') "{{{2
endif
if prot != ''
let openFile = viki#SubstituteArgs(prot, 'FILE', a:file)
" TLogVAR openFile
exec openFile
else
throw 'Viki: Please define g:vikiOpenFileWith_'. proto .' or g:vikiOpenFileWith_ANY!'
Expand Down Expand Up @@ -950,5 +950,10 @@ b:vikiCmdAnchorIdx.
- Moved :VikiMinorModeViki, :VikiMinorModeLaTeX, and
:VikiMinorModeAnyWord to plugin/viki.vim

3.3
- Use hookcursormoved >= 0.3
- Backslash-save command-line completion
- Mark unknown intervikis as inexistent


" vim: ff=unix

0 comments on commit 8f34d38

Please sign in to comment.