Skip to content

Commit

Permalink
Version 3.19
Browse files Browse the repository at this point in the history
- Use tlib#balloon#Register() if available- viki#Edit(): Switch to homepage only if we are in a viki-enabled buffer- Run VimEnter command immediately if !has('vim_starting')- Transcode balloon text (guess the file encoding based on the value of &fenc)- Don't rely on g:vikiEnabled to be set when loading syntax/viki.vim- Removed g:vikiEnabled variable (use g:viki#quit for checking when to quit)- Act more graciously if g:vikiHomePage is emptyMD5 checksum: 64ebd14609764e98b91f1e233e121e32
  • Loading branch information
tomtom authored and vim-scripts committed Nov 14, 2010
1 parent 2dca1aa commit 5308d47
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 108 deletions.
107 changes: 75 additions & 32 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: 2010-03-09.
" @Revision: 0.621
" @Last Change: 2010-09-14.
" @Revision: 0.679

" call tlog#Log('Load: '. expand('<sfile>')) " vimtlib-sfile

Expand Down Expand Up @@ -54,8 +54,8 @@ if !exists("g:vikiSpecialProtocolsExceptions") "{{{2
let g:vikiSpecialProtocolsExceptions = ""
endif

" Files matching these suffixes are handled by viki#OpenSpecialFile()
if !exists("g:vikiSpecialFiles") "{{{2
" Files matching these suffixes are handled by viki#OpenSpecialFile()
let g:vikiSpecialFiles = [
\ 'aac',
\ 'aif',
Expand All @@ -74,6 +74,7 @@ if !exists("g:vikiSpecialFiles") "{{{2
\ 'jpeg',
\ 'jpg',
\ 'm3u',
\ 'mhtml',
\ 'mp1',
\ 'mp2',
\ 'mp3',
Expand Down Expand Up @@ -222,6 +223,8 @@ if !exists("g:vikiBalloonLines") | let g:vikiBalloonLines = '&lines / 3' | en
" window.
if !exists("g:vikiBalloon") | let g:vikiBalloon = 1 | endif "{{{2

if !exists("g:vikiBalloonEncoding") | let g:vikiBalloonEncoding = &enc | endif "{{{2


" A list of files that contain special viki names
if v:version >= 700 && !exists("g:vikiHyperWordsFiles") "{{{2
Expand Down Expand Up @@ -255,6 +258,7 @@ if !exists("g:vikiMapFunctionalityMinor") "{{{2
let g:vikiMapFunctionalityMinor = 'f b p mf mb tF c q e'
endif

let g:viki#quit = 0

let s:positions = {}
let s:InterVikiRx = '^\(['. g:vikiUpperCharacters .']\+\)::\(.*\)$'
Expand Down Expand Up @@ -285,13 +289,12 @@ command! VikiJump call viki#MaybeFollowLink(0,1)

command! VikiIndex :call viki#Index()

command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEdit :call viki#Edit(<q-args>, "<bang>")
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEditInVim :call viki#Edit(<q-args>, "<bang>", 0, 1)
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEditTab :call viki#Edit(<q-args>, "<bang>", 'tab')
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEditInWin1 :call viki#Edit(<q-args>, "<bang>", 1)
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEditInWin2 :call viki#Edit(<q-args>, "<bang>", 2)
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEditInWin3 :call viki#Edit(<q-args>, "<bang>", 3)
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEditInWin4 :call viki#Edit(<q-args>, "<bang>", 4)
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEdit :call viki#Edit(<q-args>, !empty("<bang>"))
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEditTab :call viki#Edit(<q-args>, !empty("<bang>"), 'tab')
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEditInWin1 :call viki#Edit(<q-args>, !empty("<bang>"), 1)
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEditInWin2 :call viki#Edit(<q-args>, !empty("<bang>"), 2)
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEditInWin3 :call viki#Edit(<q-args>, !empty("<bang>"), 3)
command! -nargs=1 -bang -complete=customlist,viki#EditComplete VikiEditInWin4 :call viki#Edit(<q-args>, !empty("<bang>"), 4)

command! VikiFilesUpdate call viki#FilesUpdate()
command! VikiFilesUpdateAll call viki#FilesUpdateAll()
Expand Down Expand Up @@ -348,7 +351,7 @@ if !exists("g:vikiOpenFileWith_ANY") "{{{2
let g:vikiOpenFileWith_ANY = "exec 'silent ! start \"\" '. shellescape('%{FILE}')"
elseif has("mac")
let g:vikiOpenFileWith_ANY = "exec 'silent !open '. shellescape('%{FILE}')"
elseif $GNOME_DESKTOP_SESSION_ID != ""
elseif $GNOME_DESKTOP_SESSION_ID != "" || $DESKTOP_SESSION == 'gnome'
let g:vikiOpenFileWith_ANY = "exec 'silent !gnome-open '. shellescape('%{FILE}')"
elseif $KDEDIR != ""
let g:vikiOpenFileWith_ANY = "exec 'silent !kfmclient exec '. shellescape('%{FILE}')"
Expand All @@ -357,6 +360,7 @@ endif

if !exists('*VikiOpenSpecialFile') "{{{2
function! VikiOpenSpecialFile(file) "{{{3
" TLogVAR a:file
" let proto = tolower(matchstr(a:file, '\c\.\zs[a-z]\+$'))
let proto = tolower(fnamemodify(a:file, ':e'))
if exists('g:vikiOpenFileWith_'. proto)
Expand Down Expand Up @@ -813,6 +817,9 @@ if v:version == 700 && !has('patch8')
endf

function! viki#MarkInexistentInElement(elt) "{{{3
if exists('b:vikiEnabled') && b:vikiEnabled <= 1
finish
endif
let lr = &lazyredraw
set lazyredraw
call viki#SaveCursorPosition()
Expand All @@ -825,6 +832,9 @@ if v:version == 700 && !has('patch8')
endf
else
function! viki#MarkInexistentInElement(elt) "{{{3
if exists('b:vikiEnabled') && b:vikiEnabled <= 1
finish
endif
let lr = &lazyredraw
set lazyredraw
" let pos = getpos('.')
Expand All @@ -843,6 +853,13 @@ else
endf
endif


function! viki#ExprMarkInexistentInElement(elt, key) "{{{3
call viki#MarkInexistentInElement(a:elt)
return a:key
endf


function! viki#MarkInexistentInRange(line1, line2) "{{{3
let lr = &lazyredraw
set lazyredraw
Expand Down Expand Up @@ -949,7 +966,7 @@ endf
" The function called from autocommands: re-check for inexistent names
" when re-entering a buffer.
function! viki#CheckInexistent() "{{{3
if g:vikiEnabled && exists("b:vikiCheckInexistent") && b:vikiCheckInexistent > 0
if !g:viki#quit && exists("b:vikiCheckInexistent") && b:vikiCheckInexistent > 0
call viki#MarkInexistentInRange(b:vikiCheckInexistent, b:vikiCheckInexistent)
endif
endf
Expand All @@ -972,7 +989,7 @@ function! viki#SetBufferVar(name, ...) "{{{3
let i = i + 1
endwh
throw 'VikiSetBuffer: Couldn't set '. a:name
else
elseif exists('g:'. a:name)
exe 'let b:'.a:name.' = g:'.a:name
endif
endif
Expand Down Expand Up @@ -1155,9 +1172,10 @@ function! viki#MapMarkInexistent(key, element) "{{{3
if arg == ''
let arg = key
endif
let map = '<c-r>=viki#MarkInexistentInElement("'. a:element .'")<cr>'
let map = stridx(g:vikiMapBeforeKeys, a:key) != -1 ? arg.map : map.arg
exe 'inoremap <silent> <buffer> '. key .' '. map
" let map = '<c-r>=viki#MarkInexistentInElement('. string(a:element) .')<cr>'
" let map = stridx(g:vikiMapBeforeKeys, a:key) != -1 ? arg.map : map.arg
" exe 'inoremap <silent> <buffer> '. key .' '. map
exe 'inoremap <buffer> <expr> '. key .' viki#ExprMarkInexistentInElement('. string(a:element) .','. string(key) .')'
endf


Expand Down Expand Up @@ -1890,13 +1908,20 @@ endf
" Get the interviki name of a vikiname
function! viki#InterVikiName(vikiname)
" return substitute(a:vikiname, s:InterVikiRx, '\1', '')
return matchlist(a:vikiname, s:InterVikiRx)[1]
let ml = matchlist(a:vikiname, s:InterVikiRx)
let name = get(ml, 1, '')
" echom "DBG" a:vikiname string(ml) name
return name
endf

" Get the plain vikiname of a vikiname
function! viki#InterVikiPart(vikiname)
" return substitute(a:vikiname, s:InterVikiRx, '\2', '')
return matchlist(a:vikiname, s:InterVikiRx)[2]
" return matchlist(a:vikiname, s:InterVikiRx)[2]
let ml = matchlist(a:vikiname, s:InterVikiRx)
let part = get(ml, 2, '')
" echom "DBG" a:vikiname string(ml) part
return part
endf

" Return vimscript code describing an interviki
Expand Down Expand Up @@ -1955,11 +1980,11 @@ function! viki#InterVikiDest(vikiname, ...)
let i_dest = fnamemodify(i_dest, ':p')
" TLogVAR i_dest, rx
if !empty(rx)
if i_dest !~ '[\/]$'
let i_dest .= '/'
endif
let i_dest = s:RxifyFilename(i_dest)
" TLogVAR i_dest
if i_dest !~ '\[\\/\]$'
let i_dest .= '[\/]'
endif
let v_dest = i_dest . v_dest
else
let v_dest = tlib#file#Join([i_dest, v_dest], 1)
Expand Down Expand Up @@ -2166,7 +2191,12 @@ endf
function! viki#HomePage(...) "{{{3
TVarArg ['winNr', 0]
if g:vikiHomePage != ''
call viki#OpenLink(g:vikiHomePage, '', '', '', winNr)
let bufnr = bufnr(g:vikiHomePage)
if bufnr != -1
exec 'buffer '. bufnr
else
call viki#OpenLink(g:vikiHomePage, '', '', '', winNr)
endif
return 1
else
return 0
Expand All @@ -2175,14 +2205,16 @@ endf


" Edit a vikiname
" viki#Edit(name, ?bang='', ?winNr=0, ?ìgnoreSpecial=0)
" viki#Edit(name, ?ìgnoreSpecial=0, ?winNr=0)
function! viki#Edit(name, ...) "{{{3
TVarArg ['bang', ''], ['winNr', 0], ['ignoreSpecial', 0]
TVarArg ['ignoreSpecial', 0], ['winNr', 0]
" TLogVAR a:name
if exists('b:vikiEnabled') && bang != '' &&
\ exists('b:vikiFamily') && b:vikiFamily != ''
" \ (!exists('b:vikiFamily') || b:vikiFamily != '')
if winNr != 0
exec winNr .'wincmd w'
endif
if exists('b:vikiEnabled')
if !viki#HomePage(winNr)
call tlib#notify#Echo('VIKI: Please set g:vikiHomePage', 'WarningMsg')
call s:EditWrapper('buffer', 1)
endif
endif
Expand All @@ -2191,6 +2223,9 @@ function! viki#Edit(name, ...) "{{{3
else
let name = a:name
end
if empty(name)
return
endif
let name = substitute(name, '\\', '/', 'g')
if !exists('b:vikiNameTypes')
call viki#SetBufferVar('vikiNameTypes')
Expand Down Expand Up @@ -2306,8 +2341,8 @@ function! viki#EditComplete(ArgLead, CmdLine, CursorPos) "{{{3
" TLogVAR a:ArgLead, a:CmdLine, a:CursorPos
" let arglead = a:ArgLead
let rx_pre = '^\s*\(\d*\(verb\|debug\|sil\|sp\|vert\|tab\)\w\+!\?\s\+\)*'
let arglead = matchstr(a:CmdLine, rx_pre .'\(\u\+\)\s\zs.*')
let ii = matchstr(a:CmdLine, rx_pre .'\zs\(\u\+\)\ze\s')
let arglead = matchstr(a:CmdLine, rx_pre .'\(\u\+\)!\?\s\zs.*')
let ii = matchstr(a:CmdLine, rx_pre .'\zs\(\u\+\)\ze!\?\s')
" TLogVAR ii
if !empty(ii) && arglead !~ '::'
let arglead = ii.'::'.arglead
Expand Down Expand Up @@ -2649,7 +2684,11 @@ fun! viki#DirListing(lhs, lhb, indent) "{{{3
if !empty(types)
let show_files = stridx(types, 'f') != -1
let show_dirs = stridx(types, 'd') != -1
call filter(ls, '(show_files && !isdirectory(v:val)) || (show_dirs && isdirectory(v:val))')
if show_files || show_dirs
call filter(ls, '(show_files && !isdirectory(v:val)) || (show_dirs && isdirectory(v:val))')
else
let ls = []
endif
endif
let filter = get(args, 'filter', '')
if !empty(filter)
Expand Down Expand Up @@ -2865,8 +2904,12 @@ function! viki#Balloon() "{{{3
" TLogVAR v_dest
if !viki#IsSpecial(v_dest)
try
let text = readfile(v_dest)[0 : eval(g:vikiBalloonLines)]
return join(text, "\n")
let lines = readfile(v_dest)[0 : eval(g:vikiBalloonLines)]
let text = join(lines, "\n")
if &fenc != g:vikiBalloonEncoding && has('iconv')
let text = iconv(text, &fenc, g:vikiBalloonEncoding)
endif
return text
catch
endtry
endif
Expand Down
12 changes: 3 additions & 9 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: 2010-02-28.
" @Revision: 0.0.127
" @Last Change: 2010-09-13.
" @Revision: 0.0.129

let s:save_cpo = &cpo
set cpo&vim
Expand All @@ -17,9 +17,6 @@ set cpo&vim
" This also sets up the rx for the different viki name types.
" viki_viki#SetupBuffer(state, ?dontSetup='')
function! viki_viki#SetupBuffer(state, ...) "{{{3
if !g:vikiEnabled
return
endif
" TLogDBG expand('%') .': '. (exists('b:vikiFamily') ? b:vikiFamily : 'default')

let dontSetup = a:0 > 0 ? a:1 : ""
Expand Down Expand Up @@ -99,7 +96,7 @@ function! viki_viki#SetupBuffer(state, ...) "{{{3
call viki#CollectFileWords(b:vikiHyperWordTable, simpleWikiName)
endif
call viki#CollectHyperWords(b:vikiHyperWordTable)
let hyperWords = keys(b:vikiHyperWordTable)
let hyperWords = reverse(sort(keys(b:vikiHyperWordTable)))
if !empty(hyperWords)
let simpleHyperWords = join(map(hyperWords, '"\\<".tlib#rx#Escape(v:val)."\\>"'), '\|') .'\|'
let simpleHyperWords = substitute(simpleHyperWords, ' \+', '\\s\\+', 'g')
Expand Down Expand Up @@ -373,9 +370,6 @@ endf
" Initialize viki as minor mode (add-on to some buffer filetype)
"state ... no-op:0, minor:1, major:2
function! viki_viki#MinorMode(state) "{{{3
if !g:vikiEnabled
return 0
endif
if a:state == 0
return 0
endif
Expand Down
Loading

0 comments on commit 5308d47

Please sign in to comment.