mirror of
https://github.com/gryf/.vim.git
synced 2025-12-17 11:30:29 +01:00
Moja prawie współczesna konfiguracja. Dużo rzeczy :)
This commit is contained in:
1155
autoload/fuf.vim
Normal file
1155
autoload/fuf.vim
Normal file
File diff suppressed because it is too large
Load Diff
211
autoload/fuf/bookmark.vim
Normal file
211
autoload/fuf/bookmark.vim
Normal file
@@ -0,0 +1,211 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_bookmark') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_bookmark = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#bookmark#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#bookmark#getSwitchOrder()
|
||||
return g:fuf_bookmark_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#bookmark#renewCache()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#bookmark#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#bookmark#onInit()
|
||||
call fuf#defineLaunchCommand('FufBookmark', s:MODE_NAME, '""')
|
||||
command! -bang -narg=? FufAddBookmark call s:bookmarkHere(<q-args>)
|
||||
command! -bang -narg=0 -range FufAddBookmarkAsSelectedText call s:bookmarkHere(s:getSelectedText())
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
let s:OPEN_TYPE_DELETE = -1
|
||||
|
||||
"
|
||||
function s:getSelectedText()
|
||||
let reg_ = [@", getregtype('"')]
|
||||
let regA = [@a, getregtype('a')]
|
||||
if mode() =~# "[vV\<C-v>]"
|
||||
silent normal! "aygv
|
||||
else
|
||||
let pos = getpos('.')
|
||||
silent normal! gv"ay
|
||||
call setpos('.', pos)
|
||||
endif
|
||||
let text = @a
|
||||
call setreg('"', reg_[0], reg_[1])
|
||||
call setreg('a', regA[0], regA[1])
|
||||
return text
|
||||
endfunction
|
||||
|
||||
" opens a:path and jumps to the line matching to a:pattern from a:lnum within
|
||||
" a:range. if not found, jumps to a:lnum.
|
||||
function s:jumpToBookmark(path, mode, pattern, lnum)
|
||||
call fuf#openFile(a:path, a:mode, g:fuf_reuseWindow)
|
||||
call cursor(s:getMatchingLineNumber(getline(1, '$'), a:pattern, a:lnum), 0)
|
||||
normal! zvzz
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:getMatchingLineNumber(lines, pattern, lnumBegin)
|
||||
let l = min([a:lnumBegin, len(a:lines)])
|
||||
for [l0, l1] in map(range(0, g:fuf_bookmark_searchRange),
|
||||
\ '[l + v:val, l - v:val]')
|
||||
if l0 <= len(a:lines) && a:lines[l0 - 1] =~# a:pattern
|
||||
return l0
|
||||
elseif l1 >= 0 && a:lines[l1 - 1] =~# a:pattern
|
||||
return l1
|
||||
endif
|
||||
endfor
|
||||
return l
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:getLinePattern(lnum)
|
||||
return '\C\V\^' . escape(getline(a:lnum), '\') . '\$'
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:bookmarkHere(word)
|
||||
if !empty(&buftype) || expand('%') !~ '\S'
|
||||
call fuf#echoWithHl('Can''t bookmark this buffer.', 'WarningMsg')
|
||||
return
|
||||
endif
|
||||
let item = {
|
||||
\ 'word' : (a:word =~# '\S' ? substitute(a:word, '\n', ' ', 'g')
|
||||
\ : pathshorten(expand('%:p:~')) . '|' . line('.') . '| ' . getline('.')),
|
||||
\ 'path' : expand('%:p'),
|
||||
\ 'lnum' : line('.'),
|
||||
\ 'pattern' : s:getLinePattern(line('.')),
|
||||
\ 'time' : localtime(),
|
||||
\ }
|
||||
let item.word = fuf#inputHl('Bookmark as:', item.word, 'Question')
|
||||
if item.word !~ '\S'
|
||||
call fuf#echoWithHl('Canceled', 'WarningMsg')
|
||||
return
|
||||
endif
|
||||
let info = fuf#loadInfoFile(s:MODE_NAME)
|
||||
call insert(info.data, item)
|
||||
call fuf#saveInfoFile(s:MODE_NAME, info)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:findItem(items, word)
|
||||
for item in a:items
|
||||
if item.word ==# a:word
|
||||
return item
|
||||
endif
|
||||
endfor
|
||||
return {}
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_bookmark_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
let item = s:findItem(self.info.data, a:word)
|
||||
let lines = fuf#getFileLines(item.path)
|
||||
if empty(lines)
|
||||
return []
|
||||
endif
|
||||
let index = s:getMatchingLineNumber(lines, item.pattern, item.lnum) - 1
|
||||
return fuf#makePreviewLinesAround(
|
||||
\ lines, [index], a:count, self.getPreviewHeight())
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return self.items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
if a:mode == s:OPEN_TYPE_DELETE
|
||||
call filter(self.info.data, 'v:val.word !=# a:word')
|
||||
call fuf#saveInfoFile(s:MODE_NAME, self.info)
|
||||
call fuf#launch(s:MODE_NAME, self.lastPattern, self.partialMatching)
|
||||
return
|
||||
else
|
||||
let item = s:findItem(self.info.data, a:word)
|
||||
if !empty(item)
|
||||
call s:jumpToBookmark(item.path, a:mode, item.pattern, item.lnum)
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
call fuf#defineKeyMappingInHandler(g:fuf_bookmark_keyDelete,
|
||||
\ 'onCr(' . s:OPEN_TYPE_DELETE . ', 0)')
|
||||
let self.items = copy(self.info.data)
|
||||
call map(self.items, 'fuf#makeNonPathItem(v:val.word, strftime(g:fuf_timeFormat, v:val.time))')
|
||||
call fuf#mapToSetSerialIndex(self.items, 1)
|
||||
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
176
autoload/fuf/buffer.vim
Normal file
176
autoload/fuf/buffer.vim
Normal file
@@ -0,0 +1,176 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_buffer') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_buffer = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#buffer#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#buffer#getSwitchOrder()
|
||||
return g:fuf_buffer_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#buffer#renewCache()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#buffer#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#buffer#onInit()
|
||||
call fuf#defineLaunchCommand('FufBuffer', s:MODE_NAME, '""')
|
||||
augroup fuf#buffer
|
||||
autocmd!
|
||||
autocmd BufEnter * call s:updateBufTimes()
|
||||
autocmd BufWritePost * call s:updateBufTimes()
|
||||
augroup END
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
let s:bufTimes = {}
|
||||
|
||||
"
|
||||
function s:updateBufTimes()
|
||||
let s:bufTimes[bufnr('%')] = localtime()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:makeItem(nr)
|
||||
let fname = (empty(bufname(a:nr))
|
||||
\ ? '[No Name]'
|
||||
\ : fnamemodify(bufname(a:nr), ':~:.'))
|
||||
let time = (exists('s:bufTimes[a:nr]') ? s:bufTimes[a:nr] : 0)
|
||||
let item = fuf#makePathItem(fname, strftime(g:fuf_timeFormat, time), 0)
|
||||
let item.index = a:nr
|
||||
let item.bufNr = a:nr
|
||||
let item.time = time
|
||||
let item.abbrPrefix = s:getBufIndicator(a:nr) . ' '
|
||||
return item
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:getBufIndicator(bufNr)
|
||||
if !getbufvar(a:bufNr, '&modifiable')
|
||||
return '[-]'
|
||||
elseif getbufvar(a:bufNr, '&modified')
|
||||
return '[+]'
|
||||
elseif getbufvar(a:bufNr, '&readonly')
|
||||
return '[R]'
|
||||
else
|
||||
return ' '
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:compareTimeDescending(i1, i2)
|
||||
return a:i1.time == a:i2.time ? 0 : a:i1.time > a:i2.time ? -1 : +1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:findItem(items, word)
|
||||
for item in a:items
|
||||
if item.word ==# a:word
|
||||
return item
|
||||
endif
|
||||
endfor
|
||||
return {}
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_buffer_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
let item = s:findItem(self.items, a:word)
|
||||
if empty(item)
|
||||
return []
|
||||
endif
|
||||
return fuf#makePreviewLinesForFile(item.bufNr, a:count, self.getPreviewHeight())
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return self.items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
" not use bufnr(a:word) in order to handle unnamed buffer
|
||||
let item = s:findItem(self.items, a:word)
|
||||
if !empty(item)
|
||||
call fuf#openBuffer(item.bufNr, a:mode, g:fuf_reuseWindow)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
let self.items = map(filter(range(1, bufnr('$')),
|
||||
\ 'buflisted(v:val) && v:val != self.bufNrPrev'),
|
||||
\ 's:makeItem(v:val)')
|
||||
if g:fuf_buffer_mruOrder
|
||||
call fuf#mapToSetSerialIndex(sort(self.items, 's:compareTimeDescending'), 1)
|
||||
endif
|
||||
let self.items = fuf#mapToSetAbbrWithSnippedWordAsPath(self.items)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
133
autoload/fuf/callbackfile.vim
Normal file
133
autoload/fuf/callbackfile.vim
Normal file
@@ -0,0 +1,133 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_callbackfile') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_callbackfile = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#callbackfile#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#callbackfile#getSwitchOrder()
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#callbackfile#renewCache()
|
||||
let s:cache = {}
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#callbackfile#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#callbackfile#onInit()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#callbackfile#launch(initialPattern, partialMatching, prompt, exclude, listener)
|
||||
let s:prompt = (empty(a:prompt) ? '>' : a:prompt)
|
||||
let s:exclude = a:exclude
|
||||
let s:listener = a:listener
|
||||
call fuf#launch(s:MODE_NAME, a:initialPattern, a:partialMatching)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
"
|
||||
function s:enumItems(dir)
|
||||
let key = getcwd() . s:exclude . "\n" . a:dir
|
||||
if !exists('s:cache[key]')
|
||||
let s:cache[key] = fuf#enumExpandedDirsEntries(a:dir, s:exclude)
|
||||
if isdirectory(a:dir)
|
||||
call insert(s:cache[key], fuf#makePathItem(a:dir . '.', '', 0))
|
||||
endif
|
||||
call fuf#mapToSetSerialIndex(s:cache[key], 1)
|
||||
call fuf#mapToSetAbbrWithSnippedWordAsPath(s:cache[key])
|
||||
endif
|
||||
return s:cache[key]
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(s:prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPathTail',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
let items = copy(s:enumItems(fuf#splitPath(a:patternPrimary).head))
|
||||
return filter(items, 'bufnr("^" . v:val.word . "$") != self.bufNrPrev')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call s:listener.onComplete(a:word, a:mode)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
if !a:opened
|
||||
call s:listener.onAbort()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
135
autoload/fuf/callbackitem.vim
Normal file
135
autoload/fuf/callbackitem.vim
Normal file
@@ -0,0 +1,135 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_callbackitem') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_callbackitem = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#callbackitem#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#callbackitem#getSwitchOrder()
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#callbackitem#renewCache()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#callbackitem#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#callbackitem#onInit()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#callbackitem#launch(initialPattern, partialMatching, prompt, listener, items, forPath)
|
||||
let s:prompt = (empty(a:prompt) ? '>' : a:prompt)
|
||||
let s:listener = a:listener
|
||||
let s:forPath = a:forPath
|
||||
let s:items = copy(a:items)
|
||||
if s:forPath
|
||||
call map(s:items, 'fuf#makePathItem(v:val, "", 1)')
|
||||
call fuf#mapToSetSerialIndex(s:items, 1)
|
||||
call fuf#mapToSetAbbrWithSnippedWordAsPath(s:items)
|
||||
else
|
||||
call map(s:items, 'fuf#makeNonPathItem(v:val, "")')
|
||||
call fuf#mapToSetSerialIndex(s:items, 1)
|
||||
call map(s:items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
|
||||
endif
|
||||
call fuf#launch(s:MODE_NAME, a:initialPattern, a:partialMatching)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(s:prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
if s:forPath
|
||||
return g:fuf_previewHeight
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return s:forPath
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
let parser = (s:forPath
|
||||
\ ? 's:interpretPrimaryPatternForPath'
|
||||
\ : 's:interpretPrimaryPatternForNonPath')
|
||||
return fuf#makePatternSet(a:patternBase, parser, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
if s:forPath
|
||||
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
|
||||
endif
|
||||
return []
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return s:items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call s:listener.onComplete(a:word, a:mode)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
if !a:opened
|
||||
call s:listener.onAbort()
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
168
autoload/fuf/changelist.vim
Normal file
168
autoload/fuf/changelist.vim
Normal file
@@ -0,0 +1,168 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_changelist') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_changelist = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#changelist#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#changelist#getSwitchOrder()
|
||||
return g:fuf_changelist_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#changelist#renewCache()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#changelist#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#changelist#onInit()
|
||||
call fuf#defineLaunchCommand('FufChangeList', s:MODE_NAME, '""')
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
"
|
||||
function s:getChangesLines()
|
||||
redir => result
|
||||
:silent changes
|
||||
redir END
|
||||
return split(result, "\n")
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:parseChangesLine(line)
|
||||
" return matchlist(a:line, '^\(.\)\s\+\(\d\+\)\s\(.*\)$')
|
||||
let elements = matchlist(a:line, '\v^(.)\s*(\d+)\s+(\d+)\s+(\d+)\s*(.*)$')
|
||||
if empty(elements)
|
||||
return {}
|
||||
endif
|
||||
return {
|
||||
\ 'prefix': elements[1],
|
||||
\ 'count' : elements[2],
|
||||
\ 'lnum' : elements[3],
|
||||
\ 'text' : printf('|%d:%d|%s', elements[3], elements[4], elements[5]),
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:makeItem(line)
|
||||
let parsed = s:parseChangesLine(a:line)
|
||||
if empty(parsed)
|
||||
return {}
|
||||
endif
|
||||
let item = fuf#makeNonPathItem(parsed.text, '')
|
||||
let item.abbrPrefix = parsed.prefix
|
||||
let item.lnum = parsed.lnum
|
||||
return item
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_changelist_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
let items = filter(copy(self.items), 'v:val.word ==# a:word')
|
||||
if empty(items)
|
||||
return []
|
||||
endif
|
||||
let lines = fuf#getFileLines(self.bufNrPrev)
|
||||
return fuf#makePreviewLinesAround(
|
||||
\ lines, [items[0].lnum - 1], a:count, self.getPreviewHeight())
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return self.items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call fuf#prejump(a:mode)
|
||||
let older = 0
|
||||
for line in reverse(s:getChangesLines())
|
||||
if stridx(line, '>') == 0
|
||||
let older = 1
|
||||
endif
|
||||
let parsed = s:parseChangesLine(line)
|
||||
if !empty(parsed) && parsed.text ==# a:word
|
||||
if parsed.count != 0
|
||||
execute 'normal! ' . parsed.count . (older ? 'g;' : 'g,') . 'zvzz'
|
||||
endif
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
let self.items = s:getChangesLines()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
call map(self.items, 's:makeItem(v:val)')
|
||||
call filter(self.items, '!empty(v:val)')
|
||||
call reverse(self.items)
|
||||
call fuf#mapToSetSerialIndex(self.items, 1)
|
||||
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
|
||||
128
autoload/fuf/dir.vim
Normal file
128
autoload/fuf/dir.vim
Normal file
@@ -0,0 +1,128 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_dir') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_dir = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#dir#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#dir#getSwitchOrder()
|
||||
return g:fuf_dir_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#dir#renewCache()
|
||||
let s:cache = {}
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#dir#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#dir#onInit()
|
||||
call fuf#defineLaunchCommand('FufDir' , s:MODE_NAME, '""')
|
||||
call fuf#defineLaunchCommand('FufDirWithFullCwd' , s:MODE_NAME, 'fnamemodify(getcwd(), '':p'')')
|
||||
call fuf#defineLaunchCommand('FufDirWithCurrentBufferDir', s:MODE_NAME, 'expand(''%:~:.'')[:-1-len(expand(''%:~:.:t''))]')
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
"
|
||||
function s:enumItems(dir)
|
||||
let key = getcwd() . g:fuf_dir_exclude . "\n" . a:dir
|
||||
if !exists('s:cache[key]')
|
||||
let s:cache[key] = fuf#enumExpandedDirsEntries(a:dir, g:fuf_dir_exclude)
|
||||
call filter(s:cache[key], 'v:val.word =~# ''[/\\]$''')
|
||||
if isdirectory(a:dir)
|
||||
call insert(s:cache[key], fuf#makePathItem(a:dir . '.', '', 0))
|
||||
endif
|
||||
call fuf#mapToSetSerialIndex(s:cache[key], 1)
|
||||
call fuf#mapToSetAbbrWithSnippedWordAsPath(s:cache[key])
|
||||
endif
|
||||
return s:cache[key]
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_dir_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPathTail',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
return fuf#makePreviewLinesAround(
|
||||
\ split(glob(fnamemodify(a:word, ':p') . '*'), "\n"),
|
||||
\ [], a:count, self.getPreviewHeight())
|
||||
return
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return s:enumItems(fuf#splitPath(a:patternPrimary).head)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
execute ':cd ' . fnameescape(a:word)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
137
autoload/fuf/file.vim
Normal file
137
autoload/fuf/file.vim
Normal file
@@ -0,0 +1,137 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_file') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_file = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#file#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#file#getSwitchOrder()
|
||||
return g:fuf_file_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#file#renewCache()
|
||||
let s:cache = {}
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#file#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#file#onInit()
|
||||
call fuf#defineLaunchCommand('FufFile' , s:MODE_NAME, '""')
|
||||
call fuf#defineLaunchCommand('FufFileWithFullCwd' , s:MODE_NAME, 'fnamemodify(getcwd(), '':p'')')
|
||||
call fuf#defineLaunchCommand('FufFileWithCurrentBufferDir', s:MODE_NAME, 'expand(''%:~:.'')[:-1-len(expand(''%:~:.:t''))]')
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
"
|
||||
function s:enumItems(dir)
|
||||
let key = getcwd() . g:fuf_file_exclude . "\n" . a:dir
|
||||
if !exists('s:cache[key]')
|
||||
let s:cache[key] = fuf#enumExpandedDirsEntries(a:dir, g:fuf_file_exclude)
|
||||
call fuf#mapToSetSerialIndex(s:cache[key], 1)
|
||||
call fuf#mapToSetAbbrWithSnippedWordAsPath(s:cache[key])
|
||||
endif
|
||||
return s:cache[key]
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:enumNonCurrentItems(dir, bufNr, cache)
|
||||
let key = a:dir . 'AVOIDING EMPTY KEY'
|
||||
if !exists('a:cache[key]')
|
||||
" NOTE: filtering should be done with
|
||||
" 'bufnr("^" . v:val.word . "$") != a:bufNr'.
|
||||
" But it takes a lot of time!
|
||||
let bufName = bufname(a:bufNr)
|
||||
let a:cache[key] =
|
||||
\ filter(copy(s:enumItems(a:dir)), 'v:val.word != bufName')
|
||||
endif
|
||||
return a:cache[key]
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_file_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPathTail',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return s:enumNonCurrentItems(
|
||||
\ fuf#splitPath(a:patternPrimary).head, self.bufNrPrev, self.cache)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call fuf#openFile(a:word, a:mode, g:fuf_reuseWindow)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
let self.cache = {}
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
119
autoload/fuf/givencmd.vim
Normal file
119
autoload/fuf/givencmd.vim
Normal file
@@ -0,0 +1,119 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_givencmd') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_givencmd = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#givencmd#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givencmd#getSwitchOrder()
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givencmd#renewCache()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givencmd#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givencmd#onInit()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givencmd#launch(initialPattern, partialMatching, prompt, items)
|
||||
let s:prompt = (empty(a:prompt) ? '>' : a:prompt)
|
||||
let s:items = copy(a:items)
|
||||
call map(s:items, 'fuf#makeNonPathItem(v:val, "")')
|
||||
call fuf#mapToSetSerialIndex(s:items, 1)
|
||||
call map(s:items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
|
||||
call fuf#launch(s:MODE_NAME, a:initialPattern, a:partialMatching)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(s:prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
return []
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return s:items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
if a:word[0] =~# '[:/?]'
|
||||
call histadd(a:word[0], a:word[1:])
|
||||
endif
|
||||
call feedkeys(a:word . "\<CR>", 'n')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
119
autoload/fuf/givendir.vim
Normal file
119
autoload/fuf/givendir.vim
Normal file
@@ -0,0 +1,119 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_givendir') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_givendir = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#givendir#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givendir#getSwitchOrder()
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givendir#renewCache()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givendir#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givendir#onInit()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givendir#launch(initialPattern, partialMatching, prompt, items)
|
||||
let s:prompt = (empty(a:prompt) ? '>' : a:prompt)
|
||||
let s:items = map(copy(a:items), 'substitute(v:val, ''[/\\]\?$'', "", "")')
|
||||
let s:items = map(s:items, 'fuf#makePathItem(v:val, "", 0)')
|
||||
call fuf#mapToSetSerialIndex(s:items, 1)
|
||||
call fuf#mapToSetAbbrWithSnippedWordAsPath(s:items)
|
||||
call fuf#launch(s:MODE_NAME, a:initialPattern, a:partialMatching)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(s:prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
return fuf#makePreviewLinesAround(
|
||||
\ split(glob(fnamemodify(a:word, ':p') . '*'), "\n"),
|
||||
\ [], a:count, self.getPreviewHeight())
|
||||
return
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return s:items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
execute ':cd ' . fnameescape(a:word)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
117
autoload/fuf/givenfile.vim
Normal file
117
autoload/fuf/givenfile.vim
Normal file
@@ -0,0 +1,117 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_givenfile') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_givenfile = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#givenfile#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givenfile#getSwitchOrder()
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givenfile#renewCache()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givenfile#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givenfile#onInit()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#givenfile#launch(initialPattern, partialMatching, prompt, items)
|
||||
let s:prompt = (empty(a:prompt) ? '>' : a:prompt)
|
||||
let s:items = map(copy(a:items), 'fuf#makePathItem(v:val, "", 0)')
|
||||
call fuf#mapToSetSerialIndex(s:items, 1)
|
||||
call map(s:items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
|
||||
call fuf#launch(s:MODE_NAME, a:initialPattern, a:partialMatching)
|
||||
endfunction
|
||||
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(s:prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return s:items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call fuf#openFile(a:word, a:mode, g:fuf_reuseWindow)
|
||||
endfunction
|
||||
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
202
autoload/fuf/help.vim
Normal file
202
autoload/fuf/help.vim
Normal file
@@ -0,0 +1,202 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_help') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_help = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#help#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#help#getSwitchOrder()
|
||||
return g:fuf_help_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#help#renewCache()
|
||||
let s:cache = {}
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#help#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#help#onInit()
|
||||
call fuf#defineLaunchCommand('FufHelp' , s:MODE_NAME, '""')
|
||||
call fuf#defineLaunchCommand('FufHelpWithCursorWord', s:MODE_NAME, 'expand(''<cword>'')')
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
"
|
||||
function s:getCurrentHelpTagFiles()
|
||||
let prefix = 'doc' . fuf#getPathSeparator()
|
||||
let tagFiles = split(globpath(&runtimepath, prefix . 'tags' ), "\n")
|
||||
\ + split(globpath(&runtimepath, prefix . 'tags-??'), "\n")
|
||||
return sort(map(tagFiles, 'fnamemodify(v:val, ":p")'))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:parseHelpTagEntry(line, tagFile)
|
||||
let elements = split(a:line, "\t")
|
||||
if len(elements) != 3 || elements[0][0] ==# '!'
|
||||
return {}
|
||||
endif
|
||||
let suffix = matchstr(a:tagFile, '-\zs..$')
|
||||
if empty(suffix)
|
||||
let suffix = '@en'
|
||||
else
|
||||
let suffix = '@' . suffix
|
||||
endif
|
||||
let dir = fnamemodify(a:tagFile, ':h') . fuf#getPathSeparator()
|
||||
return {
|
||||
\ 'word' : elements[0] . suffix,
|
||||
\ 'path' : dir . elements[1],
|
||||
\ 'pattern': elements[2][1:],
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:getHelpTagEntries(tagFile)
|
||||
let names = map(readfile(a:tagFile), 's:parseHelpTagEntry(v:val, a:tagFile)')
|
||||
return filter(names, '!empty(v:val)')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:parseHelpTagFiles(tagFiles)
|
||||
if !empty(g:fuf_help_cache_dir)
|
||||
if !isdirectory(expand(g:fuf_help_cache_dir))
|
||||
call mkdir(expand(g:fuf_help_cache_dir), 'p')
|
||||
endif
|
||||
" NOTE: fnamemodify('a/b', ':p') returns 'a/b/' if the directory exists.
|
||||
let cacheFile = fnamemodify(g:fuf_help_cache_dir, ':p')
|
||||
\ . fuf#hash224(join(a:tagFiles, "\n"))
|
||||
if filereadable(cacheFile) && fuf#countModifiedFiles(a:tagFiles, getftime(cacheFile)) == 0
|
||||
return map(readfile(cacheFile), 'eval(v:val)')
|
||||
endif
|
||||
endif
|
||||
let items = fuf#unique(fuf#concat(map(copy(a:tagFiles), 's:getHelpTagEntries(v:val)')))
|
||||
let items = map(items, 'extend(v:val, fuf#makeNonPathItem(v:val.word, ""))')
|
||||
call fuf#mapToSetSerialIndex(items, 1)
|
||||
let items = map(items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
|
||||
if !empty(g:fuf_help_cache_dir)
|
||||
call writefile(map(copy(items), 'string(v:val)'), cacheFile)
|
||||
endif
|
||||
return items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:enumHelpTags(tagFiles)
|
||||
if !len(a:tagFiles)
|
||||
return []
|
||||
endif
|
||||
let key = join(a:tagFiles, "\n")
|
||||
if !exists('s:cache[key]') || fuf#countModifiedFiles(a:tagFiles, s:cache[key].time)
|
||||
let s:cache[key] = {
|
||||
\ 'time' : localtime(),
|
||||
\ 'items' : s:parseHelpTagFiles(a:tagFiles)
|
||||
\ }
|
||||
endif
|
||||
return s:cache[key].items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:getMatchingIndex(lines, pattern)
|
||||
if empty(a:pattern)
|
||||
return -1
|
||||
endif
|
||||
for i in range(len(a:lines))
|
||||
if stridx(a:lines[i], a:pattern) >= 0
|
||||
return i
|
||||
endif
|
||||
endfor
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_help_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
let items = filter(copy(s:enumHelpTags(self.tagFiles)), 'v:val.word ==# a:word')
|
||||
if empty(items)
|
||||
return []
|
||||
endif
|
||||
let lines = fuf#getFileLines(items[0].path)
|
||||
let index = s:getMatchingIndex(lines, items[0].pattern)
|
||||
return [items[0].path . ':'] + fuf#makePreviewLinesAround(
|
||||
\ lines, (index < 0 ? [] : [index]), a:count, self.getPreviewHeight() - 1)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return s:enumHelpTags(self.tagFiles)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call fuf#openHelp(a:word, a:mode)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
let self.tagFiles = s:getCurrentHelpTagFiles()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
178
autoload/fuf/jumplist.vim
Normal file
178
autoload/fuf/jumplist.vim
Normal file
@@ -0,0 +1,178 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_jumplist') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_jumplist = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#jumplist#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#jumplist#getSwitchOrder()
|
||||
return g:fuf_jumplist_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#jumplist#renewCache()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#jumplist#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#jumplist#onInit()
|
||||
call fuf#defineLaunchCommand('FufJumpList', s:MODE_NAME, '""')
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
"
|
||||
function s:getJumpsLines()
|
||||
redir => result
|
||||
:silent jumps
|
||||
redir END
|
||||
return split(result, "\n")
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:parseJumpsLine(line, bufnrPrev)
|
||||
"return matchlist(a:line, '^\(.\)\s\+\(\d\+\)\s\(.*\)$')
|
||||
let elements = matchlist(a:line, '\v^(.)\s*(\d+)\s+(\d+)\s+(\d+)\s*(.*)$')
|
||||
if empty(elements)
|
||||
return {}
|
||||
endif
|
||||
let linePrevBuffer = join(getbufline(a:bufnrPrev, elements[3]))
|
||||
if stridx(linePrevBuffer, elements[5]) >= 0
|
||||
let fname = bufname(a:bufnrPrev)
|
||||
let text = elements[5]
|
||||
else
|
||||
let fname = elements[5]
|
||||
let text = join(getbufline('^' . elements[5] . '$', elements[3]))
|
||||
endif
|
||||
return {
|
||||
\ 'prefix': elements[1],
|
||||
\ 'count' : elements[2],
|
||||
\ 'lnum' : elements[3],
|
||||
\ 'fname' : fname,
|
||||
\ 'text' : printf('%s|%d:%d|%s', fname, elements[3], elements[4], text),
|
||||
\ }
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:makeItem(line, bufnrPrev)
|
||||
let parsed = s:parseJumpsLine(a:line, a:bufnrPrev)
|
||||
if empty(parsed)
|
||||
return {}
|
||||
endif
|
||||
let item = fuf#makeNonPathItem(parsed.text, '')
|
||||
let item.abbrPrefix = parsed.prefix
|
||||
let item.lnum = parsed.lnum
|
||||
let item.fname = parsed.fname
|
||||
return item
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_jumplist_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
let items = filter(copy(self.items), 'v:val.word ==# a:word')
|
||||
if empty(items)
|
||||
return []
|
||||
endif
|
||||
let lines = fuf#getFileLines(items[0].fname)
|
||||
return fuf#makePreviewLinesAround(
|
||||
\ lines, [items[0].lnum - 1], a:count, self.getPreviewHeight())
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return self.items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call fuf#prejump(a:mode)
|
||||
let older = 0
|
||||
for line in reverse(s:getJumpsLines())
|
||||
if stridx(line, '>') == 0
|
||||
let older = 1
|
||||
endif
|
||||
let parsed = s:parseJumpsLine(line, self.bufNrPrev)
|
||||
if !empty(parsed) && parsed.text ==# a:word
|
||||
if parsed.count != 0
|
||||
execute 'normal! ' . parsed.count . (older ? "\<C-o>" : "\<C-i>") . 'zvzz'
|
||||
endif
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
let self.items = s:getJumpsLines()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
call map(self.items, 's:makeItem(v:val, self.bufNrPrev)')
|
||||
call filter(self.items, '!empty(v:val)')
|
||||
call reverse(self.items)
|
||||
call fuf#mapToSetSerialIndex(self.items, 1)
|
||||
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
|
||||
131
autoload/fuf/line.vim
Normal file
131
autoload/fuf/line.vim
Normal file
@@ -0,0 +1,131 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_line') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_line = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#line#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#line#getSwitchOrder()
|
||||
return g:fuf_line_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#line#renewCache()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#line#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#line#onInit()
|
||||
call fuf#defineLaunchCommand('FufLine', s:MODE_NAME, '""')
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
let s:OPEN_TYPE_DELETE = -1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_line_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
let items = filter(copy(self.items), 'v:val.word ==# a:word')
|
||||
if empty(items)
|
||||
return []
|
||||
endif
|
||||
let lines = fuf#getFileLines(self.bufNrPrev)
|
||||
return fuf#makePreviewLinesAround(
|
||||
\ lines, [items[0].index - 1], a:count, self.getPreviewHeight())
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return self.items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call fuf#prejump(a:mode)
|
||||
call filter(self.items, 'v:val.word ==# a:word')
|
||||
if empty(self.items)
|
||||
return
|
||||
execute 'cc ' . self.items[0].index
|
||||
endif
|
||||
call cursor(self.items[0].index, 0)
|
||||
normal! zvzz
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
let tab = repeat(' ', getbufvar(self.bufNrPrev, '&tabstop'))
|
||||
let self.items = getbufline(self.bufNrPrev, 1, '$')
|
||||
let lnumFormat = '%' . len(string(len(self.items) + 1)) . 'd|'
|
||||
for i in range(len(self.items))
|
||||
let self.items[i] = printf(lnumFormat, i + 1)
|
||||
\ . substitute(self.items[i], "\t", tab, 'g')
|
||||
endfor
|
||||
call map(self.items, 'fuf#makeNonPathItem(v:val, "")')
|
||||
call fuf#mapToSetSerialIndex(self.items, 1)
|
||||
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 0)')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
130
autoload/fuf/mrucmd.vim
Normal file
130
autoload/fuf/mrucmd.vim
Normal file
@@ -0,0 +1,130 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_mrucmd') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_mrucmd = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#mrucmd#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#mrucmd#getSwitchOrder()
|
||||
return g:fuf_mrucmd_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#mrucmd#renewCache()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#mrucmd#requiresOnCommandPre()
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#mrucmd#onInit()
|
||||
call fuf#defineLaunchCommand('FufMruCmd', s:MODE_NAME, '""')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#mrucmd#onCommandPre(cmd)
|
||||
if getcmdtype() =~# '^[:/?]'
|
||||
call s:updateInfo(a:cmd)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
"
|
||||
function s:updateInfo(cmd)
|
||||
let info = fuf#loadInfoFile(s:MODE_NAME)
|
||||
let info.data = fuf#updateMruList(
|
||||
\ info.data, { 'word' : a:cmd, 'time' : localtime() },
|
||||
\ g:fuf_mrucmd_maxItem, g:fuf_mrucmd_exclude)
|
||||
call fuf#saveInfoFile(s:MODE_NAME, info)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_mrucmd_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
return []
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return self.items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call s:updateInfo(a:word)
|
||||
call histadd(a:word[0], a:word[1:])
|
||||
call feedkeys(a:word . "\<CR>", 'n')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
let self.items = copy(self.info.data)
|
||||
call map(self.items, 'fuf#makeNonPathItem(v:val.word, strftime(g:fuf_timeFormat, v:val.time))')
|
||||
call fuf#mapToSetSerialIndex(self.items, 1)
|
||||
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
156
autoload/fuf/mrufile.vim
Normal file
156
autoload/fuf/mrufile.vim
Normal file
@@ -0,0 +1,156 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_mrufile') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_mrufile = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#mrufile#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#mrufile#getSwitchOrder()
|
||||
return g:fuf_mrufile_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#mrufile#renewCache()
|
||||
let s:cache = {}
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#mrufile#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#mrufile#onInit()
|
||||
call fuf#defineLaunchCommand('FufMruFile', s:MODE_NAME, '""')
|
||||
augroup fuf#mrufile
|
||||
autocmd!
|
||||
autocmd BufEnter * call s:updateInfo()
|
||||
autocmd BufWritePost * call s:updateInfo()
|
||||
augroup END
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
"
|
||||
function s:updateInfo()
|
||||
if !empty(&buftype) || !filereadable(expand('%'))
|
||||
return
|
||||
endif
|
||||
let info = fuf#loadInfoFile(s:MODE_NAME)
|
||||
let info.data = fuf#updateMruList(
|
||||
\ info.data, { 'word' : expand('%:p'), 'time' : localtime() },
|
||||
\ g:fuf_mrufile_maxItem, g:fuf_mrufile_exclude)
|
||||
call fuf#saveInfoFile(s:MODE_NAME, info)
|
||||
call s:removeItemFromCache(expand('%:p'))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:removeItemFromCache(word)
|
||||
for items in values(s:cache)
|
||||
if exists('items[a:word]')
|
||||
unlet items[a:word]
|
||||
endif
|
||||
endfor
|
||||
endfunction
|
||||
|
||||
" returns empty value if invalid item
|
||||
function s:formatItemUsingCache(item)
|
||||
if a:item.word !~ '\S'
|
||||
return {}
|
||||
endif
|
||||
if !exists('s:cache[a:item.word]')
|
||||
if filereadable(a:item.word)
|
||||
let s:cache[a:item.word] = fuf#makePathItem(
|
||||
\ fnamemodify(a:item.word, ':~'), strftime(g:fuf_timeFormat, a:item.time), 0)
|
||||
else
|
||||
let s:cache[a:item.word] = {}
|
||||
endif
|
||||
endif
|
||||
return s:cache[a:item.word]
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_mrufile_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return self.items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call fuf#openFile(a:word, a:mode, g:fuf_reuseWindow)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
let self.items = copy(self.info.data)
|
||||
let self.items = map(self.items, 's:formatItemUsingCache(v:val)')
|
||||
let self.items = filter(self.items, '!empty(v:val) && bufnr("^" . v:val.word . "$") != self.bufNrPrev')
|
||||
let self.items = fuf#mapToSetSerialIndex(self.items, 1)
|
||||
let self.items = fuf#mapToSetAbbrWithSnippedWordAsPath(self.items)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
150
autoload/fuf/quickfix.vim
Normal file
150
autoload/fuf/quickfix.vim
Normal file
@@ -0,0 +1,150 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_quickfix') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_quickfix = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#quickfix#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#quickfix#getSwitchOrder()
|
||||
return g:fuf_quickfix_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#quickfix#renewCache()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#quickfix#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#quickfix#onInit()
|
||||
call fuf#defineLaunchCommand('FufQuickfix', s:MODE_NAME, '""')
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
"
|
||||
function s:getJumpsLines()
|
||||
redir => result
|
||||
:silent jumps
|
||||
redir END
|
||||
return split(result, "\n")
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:parseJumpsLine(line)
|
||||
return matchlist(a:line, '^\(.\)\s\+\(\d\+\)\s\(.*\)$')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:makeItem(qfItem)
|
||||
if !a:qfItem.valid
|
||||
return {}
|
||||
endif
|
||||
let item = fuf#makeNonPathItem(
|
||||
\ printf('%s|%d:%d|%s', bufname(a:qfItem.bufnr), a:qfItem.lnum,
|
||||
\ a:qfItem.col, matchstr(a:qfItem.text, '\s*\zs.*\S'))
|
||||
\ , '')
|
||||
let item.bufnr = a:qfItem.bufnr
|
||||
let item.lnum = a:qfItem.lnum
|
||||
return item
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_quickfix_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
let items = filter(copy(self.items), 'v:val.word ==# a:word')
|
||||
if empty(items)
|
||||
return []
|
||||
endif
|
||||
let lines = fuf#getFileLines(items[0].bufnr)
|
||||
return fuf#makePreviewLinesAround(
|
||||
\ lines, [items[0].lnum - 1], a:count, self.getPreviewHeight())
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return self.items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call fuf#prejump(a:mode)
|
||||
call filter(self.items, 'v:val.word ==# a:word')
|
||||
if !empty(self.items)
|
||||
execute 'cc ' . self.items[0].index
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
let self.items = getqflist()
|
||||
call map(self.items, 's:makeItem(v:val)')
|
||||
call fuf#mapToSetSerialIndex(self.items, 1)
|
||||
call filter(self.items, 'exists("v:val.word")')
|
||||
call map(self.items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
|
||||
182
autoload/fuf/tag.vim
Normal file
182
autoload/fuf/tag.vim
Normal file
@@ -0,0 +1,182 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_tag') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_tag = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#tag#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#tag#getSwitchOrder()
|
||||
return g:fuf_tag_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#tag#renewCache()
|
||||
let s:cache = {}
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#tag#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#tag#onInit()
|
||||
call fuf#defineLaunchCommand('FufTag' , s:MODE_NAME, '""')
|
||||
call fuf#defineLaunchCommand('FufTagWithCursorWord', s:MODE_NAME, 'expand(''<cword>'')')
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
"
|
||||
function s:getTagNames(tagFile)
|
||||
let names = map(readfile(a:tagFile), 'matchstr(v:val, ''^[^!\t][^\t]*'')')
|
||||
return filter(names, 'v:val =~# ''\S''')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:parseTagFiles(tagFiles)
|
||||
if !empty(g:fuf_tag_cache_dir)
|
||||
if !isdirectory(expand(g:fuf_tag_cache_dir))
|
||||
call mkdir(expand(g:fuf_tag_cache_dir), 'p')
|
||||
endif
|
||||
" NOTE: fnamemodify('a/b', ':p') returns 'a/b/' if the directory exists.
|
||||
let cacheFile = fnamemodify(g:fuf_tag_cache_dir, ':p')
|
||||
\ . fuf#hash224(join(a:tagFiles, "\n"))
|
||||
if filereadable(cacheFile) && fuf#countModifiedFiles(a:tagFiles, getftime(cacheFile)) == 0
|
||||
return map(readfile(cacheFile), 'eval(v:val)')
|
||||
endif
|
||||
endif
|
||||
let items = fuf#unique(fuf#concat(map(copy(a:tagFiles), 's:getTagNames(v:val)')))
|
||||
let items = map(items, 'fuf#makeNonPathItem(v:val, "")')
|
||||
call fuf#mapToSetSerialIndex(items, 1)
|
||||
let items = map(items, 'fuf#setAbbrWithFormattedWord(v:val, 1)')
|
||||
if !empty(g:fuf_tag_cache_dir)
|
||||
call writefile(map(copy(items), 'string(v:val)'), cacheFile)
|
||||
endif
|
||||
return items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:enumTags(tagFiles)
|
||||
if !len(a:tagFiles)
|
||||
return []
|
||||
endif
|
||||
let key = join(a:tagFiles, "\n")
|
||||
if !exists('s:cache[key]') || fuf#countModifiedFiles(a:tagFiles, s:cache[key].time)
|
||||
let s:cache[key] = {
|
||||
\ 'time' : localtime(),
|
||||
\ 'items' : s:parseTagFiles(a:tagFiles)
|
||||
\ }
|
||||
endif
|
||||
return s:cache[key].items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:getMatchingIndex(lines, cmd)
|
||||
if a:cmd !~# '\D'
|
||||
return str2nr(a:cmd)
|
||||
endif
|
||||
let pattern = matchstr(a:cmd, '^\/\^\zs.*\ze\$\/$')
|
||||
if empty(pattern)
|
||||
return -1
|
||||
endif
|
||||
for i in range(len(a:lines))
|
||||
if a:lines[i] ==# pattern
|
||||
return i
|
||||
endif
|
||||
endfor
|
||||
return -1
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_tag_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForNonPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
" 'cmd' is '/^hoge hoge$/' or line number
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
let tags = taglist('^' . a:word . '$')
|
||||
if empty(tags)
|
||||
return []
|
||||
endif
|
||||
let i = a:count % len(tags)
|
||||
let title = printf('(%d/%d) %s', i + 1, len(tags), tags[i].filename)
|
||||
let lines = fuf#getFileLines(tags[i].filename)
|
||||
let index = s:getMatchingIndex(lines, tags[i].cmd)
|
||||
return [title] + fuf#makePreviewLinesAround(
|
||||
\ lines, (index < 0 ? [] : [index]), 0, self.getPreviewHeight() - 1)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return s:enumTags(self.tagFiles)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call fuf#openTag(a:word, a:mode)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
let self.tagFiles = fuf#getCurrentTagFiles()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
let &l:tags = join(self.tagFiles, ',')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
let &l:tags = ''
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
162
autoload/fuf/taggedfile.vim
Normal file
162
autoload/fuf/taggedfile.vim
Normal file
@@ -0,0 +1,162 @@
|
||||
"=============================================================================
|
||||
" Copyright (c) 2007-2009 Takeshi NISHIDA
|
||||
"
|
||||
"=============================================================================
|
||||
" LOAD GUARD {{{1
|
||||
|
||||
if exists('g:loaded_autoload_fuf_taggedfile') || v:version < 702
|
||||
finish
|
||||
endif
|
||||
let g:loaded_autoload_fuf_taggedfile = 1
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" GLOBAL FUNCTIONS {{{1
|
||||
|
||||
"
|
||||
function fuf#taggedfile#createHandler(base)
|
||||
return a:base.concretize(copy(s:handler))
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#taggedfile#getSwitchOrder()
|
||||
return g:fuf_taggedfile_switchOrder
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#taggedfile#renewCache()
|
||||
let s:cache = {}
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#taggedfile#requiresOnCommandPre()
|
||||
return 0
|
||||
endfunction
|
||||
|
||||
"
|
||||
function fuf#taggedfile#onInit()
|
||||
call fuf#defineLaunchCommand('FufTaggedFile', s:MODE_NAME, '""')
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" LOCAL FUNCTIONS/VARIABLES {{{1
|
||||
|
||||
let s:MODE_NAME = expand('<sfile>:t:r')
|
||||
|
||||
"
|
||||
function s:getTaggedFileList(tagfile)
|
||||
execute 'cd ' . fnamemodify(a:tagfile, ':h')
|
||||
let result = map(readfile(a:tagfile), 'matchstr(v:val, ''^[^!\t][^\t]*\t\zs[^\t]\+'')')
|
||||
call map(readfile(a:tagfile), 'fnamemodify(v:val, ":p")')
|
||||
cd -
|
||||
call map(readfile(a:tagfile), 'fnamemodify(v:val, ":~:.")')
|
||||
return filter(result, 'v:val =~# ''[^/\\ ]$''')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:parseTagFiles(tagFiles)
|
||||
if !empty(g:fuf_taggedfile_cache_dir)
|
||||
if !isdirectory(expand(g:fuf_taggedfile_cache_dir))
|
||||
call mkdir(expand(g:fuf_taggedfile_cache_dir), 'p')
|
||||
endif
|
||||
" NOTE: fnamemodify('a/b', ':p') returns 'a/b/' if the directory exists.
|
||||
let cacheFile = fnamemodify(g:fuf_taggedfile_cache_dir, ':p')
|
||||
\ . fuf#hash224(join(a:tagFiles, "\n"))
|
||||
if filereadable(cacheFile) && fuf#countModifiedFiles(a:tagFiles, getftime(cacheFile)) == 0
|
||||
return map(readfile(cacheFile), 'eval(v:val)')
|
||||
endif
|
||||
endif
|
||||
let items = fuf#unique(fuf#concat(map(copy(a:tagFiles), 's:getTaggedFileList(v:val)')))
|
||||
call map(items, 'fuf#makePathItem(v:val, "", 0)')
|
||||
call fuf#mapToSetSerialIndex(items, 1)
|
||||
call fuf#mapToSetAbbrWithSnippedWordAsPath(items)
|
||||
if !empty(g:fuf_taggedfile_cache_dir)
|
||||
call writefile(map(copy(items), 'string(v:val)'), cacheFile)
|
||||
endif
|
||||
return items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:enumTaggedFiles(tagFiles)
|
||||
if !len(a:tagFiles)
|
||||
return []
|
||||
endif
|
||||
let key = join([getcwd()] + a:tagFiles, "\n")
|
||||
if !exists('s:cache[key]') || fuf#countModifiedFiles(a:tagFiles, s:cache[key].time)
|
||||
let s:cache[key] = {
|
||||
\ 'time' : localtime(),
|
||||
\ 'items' : s:parseTagFiles(a:tagFiles)
|
||||
\ }
|
||||
endif
|
||||
return s:cache[key].items
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" s:handler {{{1
|
||||
|
||||
let s:handler = {}
|
||||
|
||||
"
|
||||
function s:handler.getModeName()
|
||||
return s:MODE_NAME
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPrompt()
|
||||
return fuf#formatPrompt(g:fuf_taggedfile_prompt, self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getPreviewHeight()
|
||||
return g:fuf_previewHeight
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.targetsPath()
|
||||
return 1
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePatternSet(patternBase)
|
||||
return fuf#makePatternSet(a:patternBase, 's:interpretPrimaryPatternForPath',
|
||||
\ self.partialMatching)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.makePreviewLines(word, count)
|
||||
return fuf#makePreviewLinesForFile(a:word, a:count, self.getPreviewHeight())
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.getCompleteItems(patternPrimary)
|
||||
return self.items
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onOpen(word, mode)
|
||||
call fuf#openFile(a:word, a:mode, g:fuf_reuseWindow)
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPre()
|
||||
let self.tagFiles = fuf#getCurrentTagFiles()
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeEnterPost()
|
||||
" NOTE: Don't do this in onModeEnterPre()
|
||||
" because that should return in a short time.
|
||||
let self.items =
|
||||
\ filter(copy(s:enumTaggedFiles(self.tagFiles)),
|
||||
\ 'bufnr("^" . v:val.word . "$") != self.bufNrPrev')
|
||||
endfunction
|
||||
|
||||
"
|
||||
function s:handler.onModeLeavePost(opened)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
"=============================================================================
|
||||
" vim: set fdm=marker:
|
||||
591
autoload/getscript.vim
Normal file
591
autoload/getscript.vim
Normal file
@@ -0,0 +1,591 @@
|
||||
" ---------------------------------------------------------------------
|
||||
" getscript.vim
|
||||
" Author: Charles E. Campbell, Jr.
|
||||
" Date: Jan 08, 2008
|
||||
" Version: 29
|
||||
" Installing: :help glvs-install
|
||||
" Usage: :help glvs
|
||||
"
|
||||
" GetLatestVimScripts: 642 1 :AutoInstall: getscript.vim
|
||||
"redraw!|call inputsave()|call input("Press <cr> to continue")|call inputrestore()
|
||||
" ---------------------------------------------------------------------
|
||||
" Initialization: {{{1
|
||||
" if you're sourcing this file, surely you can't be
|
||||
" expecting vim to be in its vi-compatible mode!
|
||||
if &cp
|
||||
echoerr "GetLatestVimScripts is not vi-compatible; not loaded (you need to set nocp)"
|
||||
finish
|
||||
endif
|
||||
let s:keepcpo = &cpo
|
||||
set cpo&vim
|
||||
"DechoTabOn
|
||||
|
||||
if exists("g:loaded_getscript")
|
||||
finish
|
||||
endif
|
||||
let g:loaded_getscript= "v29"
|
||||
|
||||
" ---------------------------
|
||||
" Global Variables: {{{1
|
||||
" ---------------------------
|
||||
" Cygwin Detection ------- {{{2
|
||||
if !exists("g:getscript_cygwin")
|
||||
if has("win32") || has("win95") || has("win64") || has("win16")
|
||||
if &shell =~ '\%(\<bash\>\|\<zsh\>\)\%(\.exe\)\=$'
|
||||
let g:getscript_cygwin= 1
|
||||
else
|
||||
let g:getscript_cygwin= 0
|
||||
endif
|
||||
else
|
||||
let g:getscript_cygwin= 0
|
||||
endif
|
||||
endif
|
||||
" shell quoting character {{{2
|
||||
if exists("g:netrw_shq") && !exists("g:getscript_shq")
|
||||
let g:getscript_shq= g:netrw_shq
|
||||
elseif !exists("g:getscript_shq")
|
||||
if exists("&shq") && &shq != ""
|
||||
let g:getscript_shq= &shq
|
||||
elseif exists("&sxq") && &sxq != ""
|
||||
let g:getscript_shq= &sxq
|
||||
elseif has("win32") || has("win95") || has("win64") || has("win16")
|
||||
if g:getscript_cygwin
|
||||
let g:getscript_shq= "'"
|
||||
else
|
||||
let g:getscript_shq= '"'
|
||||
endif
|
||||
else
|
||||
let g:getscript_shq= "'"
|
||||
endif
|
||||
" call Decho("g:getscript_shq<".g:getscript_shq.">")
|
||||
endif
|
||||
|
||||
" wget vs curl {{{2
|
||||
if !exists("g:GetLatestVimScripts_wget")
|
||||
if executable("wget")
|
||||
let g:GetLatestVimScripts_wget= "wget"
|
||||
elseif executable("curl")
|
||||
let g:GetLatestVimScripts_wget= "curl"
|
||||
else
|
||||
let g:GetLatestVimScripts_wget = 'echo "GetLatestVimScripts needs wget or curl"'
|
||||
let g:GetLatestVimScripts_options = ""
|
||||
endif
|
||||
endif
|
||||
|
||||
" options that wget and curl require:
|
||||
if !exists("g:GetLatestVimScripts_options")
|
||||
if g:GetLatestVimScripts_wget == "wget"
|
||||
let g:GetLatestVimScripts_options= "-q -O"
|
||||
elseif g:GetLatestVimScripts_wget == "curl"
|
||||
let g:GetLatestVimScripts_options= "-s -O"
|
||||
else
|
||||
let g:GetLatestVimScripts_options= ""
|
||||
endif
|
||||
endif
|
||||
|
||||
" by default, allow autoinstall lines to work
|
||||
if !exists("g:GetLatestVimScripts_allowautoinstall")
|
||||
let g:GetLatestVimScripts_allowautoinstall= 1
|
||||
endif
|
||||
|
||||
"" For debugging:
|
||||
"let g:GetLatestVimScripts_wget = "echo"
|
||||
"let g:GetLatestVimScripts_options = "options"
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" Check If AutoInstall Capable: {{{1
|
||||
let s:autoinstall= ""
|
||||
if g:GetLatestVimScripts_allowautoinstall
|
||||
|
||||
if (has("win32") || has("gui_win32") || has("gui_win32s") || has("win16") || has("win64") || has("win32unix") || has("win95")) && &shell != "bash"
|
||||
" windows (but not cygwin/bash)
|
||||
let s:dotvim= "vimfiles"
|
||||
if !exists("g:GetLatestVimScripts_mv")
|
||||
let g:GetLatestVimScripts_mv= "ren"
|
||||
endif
|
||||
|
||||
else
|
||||
" unix
|
||||
let s:dotvim= ".vim"
|
||||
if !exists("g:GetLatestVimScripts_mv")
|
||||
let g:GetLatestVimScripts_mv= "mv"
|
||||
endif
|
||||
endif
|
||||
|
||||
if exists('$HOME') && isdirectory(expand("$HOME")."/".s:dotvim)
|
||||
let s:autoinstall= $HOME."/".s:dotvim
|
||||
endif
|
||||
" call Decho("s:autoinstall<".s:autoinstall.">")
|
||||
"else "Decho
|
||||
" call Decho("g:GetLatestVimScripts_allowautoinstall=".g:GetLatestVimScripts_allowautoinstall.": :AutoInstall: disabled")
|
||||
endif
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" Public Interface: {{{1
|
||||
com! -nargs=0 GetLatestVimScripts call getscript#GetLatestVimScripts()
|
||||
com! -nargs=0 GetScript call getscript#GetLatestVimScripts()
|
||||
silent! com -nargs=0 GLVS call getscript#GetLatestVimScripts()
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" GetOneScript: (Get Latest Vim Script) this function operates {{{1
|
||||
" on the current line, interpreting two numbers and text as
|
||||
" ScriptID, SourceID, and Filename.
|
||||
" It downloads any scripts that have newer versions from vim.sf.net.
|
||||
fun! s:GetOneScript(...)
|
||||
" call Dfunc("GetOneScript()")
|
||||
|
||||
" set options to allow progress to be shown on screen
|
||||
let rega= @a
|
||||
let t_ti= &t_ti
|
||||
let t_te= &t_te
|
||||
let rs = &rs
|
||||
set t_ti= t_te= nors
|
||||
|
||||
" put current line on top-of-screen and interpret it into
|
||||
" a script identifer : used to obtain webpage
|
||||
" source identifier : used to identify current version
|
||||
" and an associated comment: used to report on what's being considered
|
||||
if a:0 >= 3
|
||||
let scriptid = a:1
|
||||
let srcid = a:2
|
||||
let fname = a:3
|
||||
let cmmnt = ""
|
||||
" call Decho("scriptid<".scriptid.">")
|
||||
" call Decho("srcid <".srcid.">")
|
||||
" call Decho("fname <".fname.">")
|
||||
else
|
||||
let curline = getline(".")
|
||||
if curline =~ '^\s*#'
|
||||
let @a= rega
|
||||
" call Dret("GetOneScript : skipping a pure comment line")
|
||||
return
|
||||
endif
|
||||
let parsepat = '^\s*\(\d\+\)\s\+\(\d\+\)\s\+\(.\{-}\)\(\s*#.*\)\=$'
|
||||
try
|
||||
let scriptid = substitute(curline,parsepat,'\1','e')
|
||||
catch /^Vim\%((\a\+)\)\=:E486/
|
||||
let scriptid= 0
|
||||
endtry
|
||||
try
|
||||
let srcid = substitute(curline,parsepat,'\2','e')
|
||||
catch /^Vim\%((\a\+)\)\=:E486/
|
||||
let srcid= 0
|
||||
endtry
|
||||
try
|
||||
let fname= substitute(curline,parsepat,'\3','e')
|
||||
catch /^Vim\%((\a\+)\)\=:E486/
|
||||
let fname= ""
|
||||
endtry
|
||||
try
|
||||
let cmmnt= substitute(curline,parsepat,'\4','e')
|
||||
catch /^Vim\%((\a\+)\)\=:E486/
|
||||
let cmmnt= ""
|
||||
endtry
|
||||
" call Decho("curline <".curline.">")
|
||||
" call Decho("parsepat<".parsepat.">")
|
||||
" call Decho("scriptid<".scriptid.">")
|
||||
" call Decho("srcid <".srcid.">")
|
||||
" call Decho("fname <".fname.">")
|
||||
endif
|
||||
|
||||
if scriptid == 0 || srcid == 0
|
||||
" When looking for :AutoInstall: lines, skip scripts that have 0 0 scriptname
|
||||
let @a= rega
|
||||
" call Dret("GetOneScript : skipping a scriptid==srcid==0 line")
|
||||
return
|
||||
endif
|
||||
|
||||
let doautoinstall= 0
|
||||
if fname =~ ":AutoInstall:"
|
||||
" call Decho("case AutoInstall: fname<".fname.">")
|
||||
let aicmmnt= substitute(fname,'\s\+:AutoInstall:\s\+',' ','')
|
||||
" call Decho("aicmmnt<".aicmmnt."> s:autoinstall=".s:autoinstall)
|
||||
if s:autoinstall != ""
|
||||
let doautoinstall = g:GetLatestVimScripts_allowautoinstall
|
||||
endif
|
||||
else
|
||||
let aicmmnt= fname
|
||||
endif
|
||||
" call Decho("aicmmnt<".aicmmnt.">: doautoinstall=".doautoinstall)
|
||||
|
||||
exe "norm z\<CR>"
|
||||
redraw!
|
||||
" call Decho('considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid)
|
||||
echomsg 'considering <'.aicmmnt.'> scriptid='.scriptid.' srcid='.srcid
|
||||
|
||||
" grab a copy of the plugin's vim.sf.net webpage
|
||||
let scriptaddr = 'http://vim.sf.net/script.php?script_id='.scriptid
|
||||
let tmpfile = tempname()
|
||||
let v:errmsg = ""
|
||||
|
||||
" make up to three tries at downloading the description
|
||||
let itry= 1
|
||||
while itry <= 3
|
||||
" call Decho("try#".itry." to download description of <".aicmmnt."> with addr=".scriptaddr)
|
||||
if has("win32") || has("win16") || has("win95")
|
||||
" call Decho("new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.tmpfile.g:getscript_shq.' '.g:getscript_shq.scriptaddr.g:getscript_shq."|q!")
|
||||
new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.tmpfile.g:getscript_shq.' '.g:getscript_shq.scriptaddr.g:getscript_shq|q!
|
||||
else
|
||||
" call Decho("exe silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.tmpfile.g:getscript_shq." ".g:getscript_shq.scriptaddr.g:getscript_shq)
|
||||
exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.tmpfile.g:getscript_shq." ".g:getscript_shq.scriptaddr.g:getscript_shq
|
||||
endif
|
||||
if itry == 1
|
||||
exe "silent vsplit ".tmpfile
|
||||
else
|
||||
silent! e %
|
||||
endif
|
||||
|
||||
" find the latest source-id in the plugin's webpage
|
||||
silent! 1
|
||||
let findpkg= search('Click on the package to download','W')
|
||||
if findpkg > 0
|
||||
break
|
||||
endif
|
||||
let itry= itry + 1
|
||||
endwhile
|
||||
" call Decho(" --- end downloading tries while loop --- itry=".itry)
|
||||
|
||||
" testing: did finding "Click on the package..." fail?
|
||||
if findpkg == 0 || itry >= 4
|
||||
silent q!
|
||||
call delete(tmpfile)
|
||||
" restore options
|
||||
let &t_ti = t_ti
|
||||
let &t_te = t_te
|
||||
let &rs = rs
|
||||
let s:downerrors = s:downerrors + 1
|
||||
" call Decho("***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">")
|
||||
echomsg "***warning*** couldn'".'t find "Click on the package..." in description page for <'.aicmmnt.">"
|
||||
" call Dret("GetOneScript : srch for /Click on the package/ failed")
|
||||
let @a= rega
|
||||
return
|
||||
endif
|
||||
" call Decho('found "Click on the package to download"')
|
||||
|
||||
let findsrcid= search('src_id=','W')
|
||||
if findsrcid == 0
|
||||
silent q!
|
||||
call delete(tmpfile)
|
||||
" restore options
|
||||
let &t_ti = t_ti
|
||||
let &t_te = t_te
|
||||
let &rs = rs
|
||||
let s:downerrors = s:downerrors + 1
|
||||
" call Decho("***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">")
|
||||
echomsg "***warning*** couldn'".'t find "src_id=" in description page for <'.aicmmnt.">"
|
||||
let @a= rega
|
||||
" call Dret("GetOneScript : srch for /src_id/ failed")
|
||||
return
|
||||
endif
|
||||
" call Decho('found "src_id=" in description page')
|
||||
|
||||
let srcidpat = '^\s*<td class.*src_id=\(\d\+\)">\([^<]\+\)<.*$'
|
||||
let latestsrcid= substitute(getline("."),srcidpat,'\1','')
|
||||
let sname = substitute(getline("."),srcidpat,'\2','') " script name actually downloaded
|
||||
" call Decho("srcidpat<".srcidpat."> latestsrcid<".latestsrcid."> sname<".sname.">")
|
||||
silent q!
|
||||
call delete(tmpfile)
|
||||
|
||||
" convert the strings-of-numbers into numbers
|
||||
let srcid = srcid + 0
|
||||
let latestsrcid = latestsrcid + 0
|
||||
" call Decho("srcid=".srcid." latestsrcid=".latestsrcid." sname<".sname.">")
|
||||
|
||||
" has the plugin's most-recent srcid increased, which indicates
|
||||
" that it has been updated
|
||||
if latestsrcid > srcid
|
||||
" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."]: need to update <".sname.">")
|
||||
|
||||
let s:downloads= s:downloads + 1
|
||||
if sname == bufname("%")
|
||||
" GetLatestVimScript has to be careful about downloading itself
|
||||
let sname= "NEW_".sname
|
||||
endif
|
||||
|
||||
" the plugin has been updated since we last obtained it, so download a new copy
|
||||
" call Decho("...downloading new <".sname.">")
|
||||
echomsg "...downloading new <".sname.">"
|
||||
if has("win32") || has("win16") || has("win95")
|
||||
" call Decho("new|exe silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid.g:getscript_shq."|q")
|
||||
new|exe "silent r!".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid.g:getscript_shq|q
|
||||
else
|
||||
" call Decho("silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid.g:getscript_shq)
|
||||
exe "silent !".g:GetLatestVimScripts_wget." ".g:GetLatestVimScripts_options." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.'http://vim.sf.net/scripts/download_script.php?src_id='.latestsrcid.g:getscript_shq
|
||||
endif
|
||||
|
||||
" AutoInstall: only if doautoinstall has been requested by the plugin itself
|
||||
if doautoinstall
|
||||
" call Decho("attempting to do autoinstall: getcwd<".getcwd()."> filereadable(".sname.")=".filereadable(sname))
|
||||
if filereadable(sname)
|
||||
" call Decho("silent !".g:GetLatestVimScripts_mv." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.s:autoinstall.g:getscript_shq)
|
||||
exe "silent !".g:GetLatestVimScripts_mv." ".g:getscript_shq.sname.g:getscript_shq." ".g:getscript_shq.s:autoinstall.g:getscript_shq
|
||||
let curdir = escape(substitute(getcwd(),'\','/','ge'),"|[]*'\" #")
|
||||
let installdir= curdir."/Installed"
|
||||
if !isdirectory(installdir)
|
||||
call mkdir(installdir)
|
||||
endif
|
||||
" call Decho("exe cd ".s:autoinstall)
|
||||
exe "cd ".escape(s:autoinstall,' ')
|
||||
|
||||
" decompress
|
||||
if sname =~ '\.bz2$'
|
||||
" call Decho("decompress: attempt to bunzip2 ".sname)
|
||||
exe "silent !bunzip2 ".g:getscript_shq.sname.g:getscript_shq
|
||||
let sname= substitute(sname,'\.bz2$','','')
|
||||
" call Decho("decompress: new sname<".sname."> after bunzip2")
|
||||
elseif sname =~ '\.gz$'
|
||||
" call Decho("decompress: attempt to gunzip ".sname)
|
||||
exe "silent !gunzip ".g:getscript_shq.sname.g:getscript_shq
|
||||
let sname= substitute(sname,'\.gz$','','')
|
||||
" call Decho("decompress: new sname<".sname."> after gunzip")
|
||||
endif
|
||||
|
||||
" distribute archive(.zip, .tar, .vba) contents
|
||||
if sname =~ '\.zip$'
|
||||
" call Decho("dearchive: attempt to unzip ".sname)
|
||||
exe "silent !unzip -o ".g:getscript_shq.sname.g:getscript_shq
|
||||
elseif sname =~ '\.tar$'
|
||||
" call Decho("dearchive: attempt to untar ".sname)
|
||||
exe "silent !tar -xvf ".g:getscript_shq.sname.g:getscript_shq
|
||||
elseif sname =~ '\.vba$'
|
||||
" call Decho("dearchive: attempt to handle a vimball: ".sname)
|
||||
silent 1split
|
||||
exe "silent e ".escape(sname,' ')
|
||||
silent so %
|
||||
silent q
|
||||
endif
|
||||
|
||||
if sname =~ '.vim$'
|
||||
" call Decho("dearchive: attempt to simply move ".sname." to plugin")
|
||||
exe "silent !".g:GetLatestVimScripts_mv." ".g:getscript_shq.sname.g:getscript_shq." plugin"
|
||||
else
|
||||
" call Decho("dearchive: move <".sname."> to installdir<".installdir.">")
|
||||
exe "silent !".g:GetLatestVimScripts_mv." ".g:getscript_shq.sname.g:getscript_shq." ".installdir
|
||||
endif
|
||||
|
||||
" helptags step
|
||||
let docdir= substitute(&rtp,',.*','','e')."/doc"
|
||||
" call Decho("helptags: docdir<".docdir.">")
|
||||
exe "helptags ".docdir
|
||||
exe "cd ".curdir
|
||||
endif
|
||||
if fname !~ ':AutoInstall:'
|
||||
let modline=scriptid." ".latestsrcid." :AutoInstall: ".fname.cmmnt
|
||||
else
|
||||
let modline=scriptid." ".latestsrcid." ".fname.cmmnt
|
||||
endif
|
||||
else
|
||||
let modline=scriptid." ".latestsrcid." ".fname.cmmnt
|
||||
endif
|
||||
|
||||
" update the data in the <GetLatestVimScripts.dat> file
|
||||
call setline(line("."),modline)
|
||||
" call Decho("update data in ".expand("%")."#".line(".").": modline<".modline.">")
|
||||
" else " Decho
|
||||
" call Decho("[latestsrcid=".latestsrcid."] <= [srcid=".srcid."], no need to update")
|
||||
endif
|
||||
|
||||
" restore options
|
||||
let &t_ti = t_ti
|
||||
let &t_te = t_te
|
||||
let &rs = rs
|
||||
let @a = rega
|
||||
|
||||
" call Dret("GetOneScript")
|
||||
endfun
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" GetLatestVimScripts: this function gets the latest versions of {{{1
|
||||
" scripts based on the list in
|
||||
" (first dir in runtimepath)/GetLatest/GetLatestVimScripts.dat
|
||||
fun! getscript#GetLatestVimScripts()
|
||||
" call Dfunc("GetLatestVimScripts() autoinstall<".s:autoinstall.">")
|
||||
|
||||
" insure that wget is executable
|
||||
if executable(g:GetLatestVimScripts_wget) != 1
|
||||
echoerr "GetLatestVimScripts needs ".g:GetLatestVimScripts_wget." which apparently is not available on your system"
|
||||
" call Dret("GetLatestVimScripts : wget not executable/availble")
|
||||
return
|
||||
endif
|
||||
|
||||
" Find the .../GetLatest subdirectory under the runtimepath
|
||||
for datadir in split(&rtp,',') + ['']
|
||||
if isdirectory(datadir."/GetLatest")
|
||||
" call Decho("found directory<".datadir.">")
|
||||
let datadir= datadir . "/GetLatest"
|
||||
break
|
||||
endif
|
||||
if filereadable(datadir."GetLatestVimScripts.dat")
|
||||
" call Decho("found ".datadir."/GetLatestVimScripts.dat")
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
|
||||
" Sanity checks: readability and writability
|
||||
if datadir == ""
|
||||
echoerr 'Missing "GetLatest/" on your runtimepath - see :help glvs-dist-install'
|
||||
" call Dret("GetLatestVimScripts : unable to find a GetLatest subdirectory")
|
||||
return
|
||||
endif
|
||||
|
||||
if filewritable(datadir) != 2
|
||||
echoerr "(getLatestVimScripts) Your ".datadir." isn't writable"
|
||||
" call Dret("GetLatestVimScripts : non-writable directory<".datadir.">")
|
||||
return
|
||||
endif
|
||||
let datafile= datadir."/GetLatestVimScripts.dat"
|
||||
if !filereadable(datafile)
|
||||
echoerr "Your data file<".datafile."> isn't readable"
|
||||
" call Dret("GetLatestVimScripts : non-readable datafile<".datafile.">")
|
||||
return
|
||||
endif
|
||||
if !filewritable(datafile)
|
||||
echoerr "Your data file<".datafile."> isn't writable"
|
||||
" call Dret("GetLatestVimScripts : non-writable datafile<".datafile.">")
|
||||
return
|
||||
endif
|
||||
" call Decho("datadir <".datadir.">")
|
||||
" call Decho("datafile <".datafile.">")
|
||||
|
||||
" don't let any events interfere (like winmanager's, taglist's, etc)
|
||||
let eikeep= &ei
|
||||
set ei=all
|
||||
|
||||
" record current directory, change to datadir, open split window with
|
||||
" datafile
|
||||
let origdir= getcwd()
|
||||
exe "cd ".escape(substitute(datadir,'\','/','ge'),"|[]*'\" #")
|
||||
split
|
||||
exe "e ".escape(substitute(datafile,'\','/','ge'),"|[]*'\" #")
|
||||
res 1000
|
||||
let s:downloads = 0
|
||||
let s:downerrors= 0
|
||||
|
||||
" Check on dependencies mentioned in plugins
|
||||
" call Decho(" ")
|
||||
" call Decho("searching plugins for GetLatestVimScripts dependencies")
|
||||
let lastline = line("$")
|
||||
" call Decho("lastline#".lastline)
|
||||
let plugins = split(globpath(&rtp,"plugin/*.vim"),'\n')
|
||||
let foundscript = 0
|
||||
let firstdir= ""
|
||||
|
||||
for plugin in plugins
|
||||
|
||||
" don't process plugins in system directories
|
||||
if firstdir == ""
|
||||
let firstdir= substitute(plugin,'[/\\][^/\\]\+$','','')
|
||||
" call Decho("setting firstdir<".firstdir.">")
|
||||
else
|
||||
let curdir= substitute(plugin,'[/\\][^/\\]\+$','','')
|
||||
" call Decho("curdir<".curdir.">")
|
||||
if curdir != firstdir
|
||||
" call Decho("skipping subsequent plugins: curdir<".curdir."> != firstdir<".firstdir.">")
|
||||
break
|
||||
endif
|
||||
endif
|
||||
|
||||
" read plugin in
|
||||
$
|
||||
" call Decho(" ")
|
||||
" call Decho(".dependency checking<".plugin."> line$=".line("$"))
|
||||
exe "silent r ".escape(plugin,"[]#*$%'\" ?`!&();<>\\")
|
||||
|
||||
while search('^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+','W') != 0
|
||||
let newscript= substitute(getline("."),'^"\s\+GetLatestVimScripts:\s\+\d\+\s\+\d\+\s\+\(.*\)$','\1','e')
|
||||
let llp1 = lastline+1
|
||||
" call Decho("..newscript<".newscript.">")
|
||||
|
||||
" don't process ""GetLatestVimScripts lines -- those that have been doubly-commented out
|
||||
if newscript !~ '^"'
|
||||
" found a "GetLatestVimScripts: # #" line in the script; check if its already in the datafile
|
||||
let curline = line(".")
|
||||
let noai_script = substitute(newscript,'\s*:AutoInstall:\s*','','e')
|
||||
exe llp1
|
||||
let srchline = search('\<'.noai_script.'\>','bW')
|
||||
" call Decho("..noai_script<".noai_script."> srch=".srchline."curline#".line(".")." lastline#".lastline)
|
||||
|
||||
if srchline == 0
|
||||
" found a new script to permanently include in the datafile
|
||||
let keep_rega = @a
|
||||
let @a = substitute(getline(curline),'^"\s\+GetLatestVimScripts:\s\+','','')
|
||||
exe lastline."put a"
|
||||
echomsg "Appending <".@a."> to ".datafile." for ".newscript
|
||||
" call Decho("..APPEND (".noai_script.")<".@a."> to GetLatestVimScripts.dat")
|
||||
let @a = keep_rega
|
||||
let lastline = llp1
|
||||
let curline = curline + 1
|
||||
let foundscript = foundscript + 1
|
||||
" else " Decho
|
||||
" call Decho("..found <".noai_script."> (already in datafile at line#".srchline.")")
|
||||
endif
|
||||
|
||||
let curline = curline + 1
|
||||
exe curline
|
||||
endif
|
||||
endwhile
|
||||
|
||||
let llp1= lastline + 1
|
||||
" call Decho(".deleting lines: ".llp1.",$d")
|
||||
exe "silent! ".llp1.",$d"
|
||||
endfor
|
||||
" call Decho("--- end dependency checking loop --- foundscript=".foundscript)
|
||||
" call Decho(" ")
|
||||
|
||||
if foundscript == 0
|
||||
setlocal nomod
|
||||
endif
|
||||
|
||||
" Check on out-of-date scripts using GetLatest/GetLatestVimScripts.dat
|
||||
" call Decho("begin: checking out-of-date scripts using datafile<".datafile.">")
|
||||
setlocal lz
|
||||
1
|
||||
" /^-----/,$g/^\s*\d/call Decho(getline("."))
|
||||
1
|
||||
/^-----/,$g/^\s*\d/call s:GetOneScript()
|
||||
" call Decho("--- end out-of-date checking --- ")
|
||||
|
||||
" Final report (an echomsg)
|
||||
try
|
||||
silent! ?^-------?
|
||||
catch /^Vim\%((\a\+)\)\=:E114/
|
||||
" call Dret("GetLatestVimScripts : nothing done!")
|
||||
return
|
||||
endtry
|
||||
exe "norm! kz\<CR>"
|
||||
redraw!
|
||||
let s:msg = ""
|
||||
if s:downloads == 1
|
||||
let s:msg = "Downloaded one updated script to <".datadir.">"
|
||||
elseif s:downloads == 2
|
||||
let s:msg= "Downloaded two updated scripts to <".datadir.">"
|
||||
elseif s:downloads > 1
|
||||
let s:msg= "Downloaded ".s:downloads." updated scripts to <".datadir.">"
|
||||
else
|
||||
let s:msg= "Everything was already current"
|
||||
endif
|
||||
if s:downerrors > 0
|
||||
let s:msg= s:msg." (".s:downerrors." downloading errors)"
|
||||
endif
|
||||
echomsg s:msg
|
||||
" save the file
|
||||
if &mod
|
||||
silent! w!
|
||||
endif
|
||||
q
|
||||
|
||||
" restore events and current directory
|
||||
exe "cd ".escape(substitute(origdir,'\','/','ge'),"|[]*'\" #")
|
||||
let &ei= eikeep
|
||||
setlocal nolz
|
||||
" call Dret("GetLatestVimScripts : did ".s:downloads." downloads")
|
||||
endfun
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" Restore Options: {{{1
|
||||
let &cpo= s:keepcpo
|
||||
unlet s:keepcpo
|
||||
|
||||
" ---------------------------------------------------------------------
|
||||
" Modelines: {{{1
|
||||
" vim: ts=8 sts=2 fdm=marker nowrap
|
||||
471
autoload/mark.vim
Normal file
471
autoload/mark.vim
Normal file
@@ -0,0 +1,471 @@
|
||||
" Script Name: mark.vim
|
||||
" Description: Highlight several words in different colors simultaneously.
|
||||
"
|
||||
" Copyright: (C) 2005-2008 by Yuheng Xie
|
||||
" (C) 2008-2010 by Ingo Karkat
|
||||
" The VIM LICENSE applies to this script; see ':help copyright'.
|
||||
"
|
||||
" Maintainer: Ingo Karkat <ingo@karkat.de>
|
||||
"
|
||||
" Dependencies:
|
||||
" - SearchSpecial.vim autoload script (optional, for improved search messages).
|
||||
"
|
||||
" Version: 2.3.3
|
||||
" Changes:
|
||||
" 19-Feb-2010, Andy Wokula
|
||||
" - BUG: Clearing of an accidental zero-width match (e.g. via :Mark \zs) results
|
||||
" in endless loop. Thanks to Andy Wokula for the patch.
|
||||
"
|
||||
" 17-Nov-2009, Ingo Karkat + Andy Wokula
|
||||
" - BUG: Creation of literal pattern via '\V' in {Visual}<Leader>m mapping
|
||||
" collided with individual escaping done in <Leader>m mapping so that an
|
||||
" escaped '\*' would be interpreted as a multi item when both modes are used
|
||||
" for marking. Replaced \V with s:EscapeText() to be consistent. Replaced the
|
||||
" (overly) generic mark#GetVisualSelectionEscaped() with
|
||||
" mark#GetVisualSelectionAsRegexp() and
|
||||
" mark#GetVisualSelectionAsLiteralPattern(). Thanks to Andy Wokula for the
|
||||
" patch.
|
||||
"
|
||||
" 06-Jul-2009, Ingo Karkat
|
||||
" - Re-wrote s:AnyMark() in functional programming style.
|
||||
" - Now resetting 'smartcase' before the search, this setting should not be
|
||||
" considered for *-command-alike searches and cannot be supported because all
|
||||
" mark patterns are concatenated into one large regexp, anyway.
|
||||
"
|
||||
" 04-Jul-2009, Ingo Karkat
|
||||
" - Re-wrote s:Search() to handle v:count:
|
||||
" - Obsoleted s:current_mark_position; mark#CurrentMark() now returns both the
|
||||
" mark text and start position.
|
||||
" - s:Search() now checks for a jump to the current mark during a backward
|
||||
" search; this eliminates a lot of logic at its calling sites.
|
||||
" - Reverted negative logic at calling sites; using empty() instead of != "".
|
||||
" - Now passing a:isBackward instead of optional flags into s:Search() and
|
||||
" around its callers.
|
||||
" - ':normal! zv' moved from callers into s:Search().
|
||||
" - Removed delegation to SearchSpecial#ErrorMessage(), because the fallback
|
||||
" implementation is perfectly fine and the SearchSpecial routine changed its
|
||||
" output format into something unsuitable anyway.
|
||||
" - Using descriptive text instead of "@" (and appropriate highlighting) when
|
||||
" querying for the pattern to mark.
|
||||
"
|
||||
" 02-Jul-2009, Ingo Karkat
|
||||
" - Split off functions into autoload script.
|
||||
|
||||
"- functions ------------------------------------------------------------------
|
||||
function! s:EscapeText( text )
|
||||
return substitute( escape(a:text, '\' . '^$.*[~'), "\n", '\\n', 'ge' )
|
||||
endfunction
|
||||
" Mark the current word, like the built-in star command.
|
||||
" If the cursor is on an existing mark, remove it.
|
||||
function! mark#MarkCurrentWord()
|
||||
let l:regexp = mark#CurrentMark()[0]
|
||||
if empty(l:regexp)
|
||||
let l:cword = expand("<cword>")
|
||||
|
||||
" The star command only creates a \<whole word\> search pattern if the
|
||||
" <cword> actually only consists of keyword characters.
|
||||
if l:cword =~# '^\k\+$'
|
||||
let l:regexp = '\<' . s:EscapeText(l:cword) . '\>'
|
||||
elseif l:cword != ''
|
||||
let l:regexp = s:EscapeText(l:cword)
|
||||
endif
|
||||
endif
|
||||
|
||||
if ! empty(l:regexp)
|
||||
call mark#DoMark(l:regexp)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:GetVisualSelection()
|
||||
let save_a = @a
|
||||
silent normal! gv"ay
|
||||
let res = @a
|
||||
let @a = save_a
|
||||
return res
|
||||
endfunction
|
||||
function! mark#GetVisualSelectionAsLiteralPattern()
|
||||
return s:EscapeText(s:GetVisualSelection())
|
||||
endfunction
|
||||
function! mark#GetVisualSelectionAsRegexp()
|
||||
return substitute(s:GetVisualSelection(), '\n', '', 'g')
|
||||
endfunction
|
||||
|
||||
" Manually input a regular expression.
|
||||
function! mark#MarkRegex( regexpPreset )
|
||||
call inputsave()
|
||||
echohl Question
|
||||
let l:regexp = input('Input pattern to mark: ', a:regexpPreset)
|
||||
echohl None
|
||||
call inputrestore()
|
||||
if ! empty(l:regexp)
|
||||
call mark#DoMark(l:regexp)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:Cycle( ... )
|
||||
let l:currentCycle = g:mwCycle
|
||||
let l:newCycle = (a:0 ? a:1 : g:mwCycle) + 1
|
||||
let g:mwCycle = (l:newCycle < g:mwCycleMax ? l:newCycle : 0)
|
||||
return l:currentCycle
|
||||
endfunction
|
||||
|
||||
" Set / clear matches in the current window.
|
||||
function! s:MarkMatch( indices, expr )
|
||||
for l:index in a:indices
|
||||
if w:mwMatch[l:index] > 0
|
||||
silent! call matchdelete(w:mwMatch[l:index])
|
||||
let w:mwMatch[l:index] = 0
|
||||
endif
|
||||
endfor
|
||||
|
||||
if ! empty(a:expr)
|
||||
" Make the match according to the 'ignorecase' setting, like the star command.
|
||||
" (But honor an explicit case-sensitive regexp via the /\C/ atom.)
|
||||
let l:expr = ((&ignorecase && a:expr !~# '\\\@<!\\C') ? '\c' . a:expr : a:expr)
|
||||
|
||||
" Info: matchadd() does not consider the 'magic' (it's always on),
|
||||
" 'ignorecase' and 'smartcase' settings.
|
||||
let w:mwMatch[a:indices[0]] = matchadd('MarkWord' . (a:indices[0] + 1), l:expr, -10)
|
||||
endif
|
||||
endfunction
|
||||
" Set / clear matches in all windows.
|
||||
function! s:MarkScope( indices, expr )
|
||||
let l:currentWinNr = winnr()
|
||||
|
||||
" By entering a window, its height is potentially increased from 0 to 1 (the
|
||||
" minimum for the current window). To avoid any modification, save the window
|
||||
" sizes and restore them after visiting all windows.
|
||||
let l:originalWindowLayout = winrestcmd()
|
||||
|
||||
noautocmd windo call s:MarkMatch(a:indices, a:expr)
|
||||
execute l:currentWinNr . 'wincmd w'
|
||||
silent! execute l:originalWindowLayout
|
||||
endfunction
|
||||
" Update matches in all windows.
|
||||
function! mark#UpdateScope()
|
||||
let l:currentWinNr = winnr()
|
||||
|
||||
" By entering a window, its height is potentially increased from 0 to 1 (the
|
||||
" minimum for the current window). To avoid any modification, save the window
|
||||
" sizes and restore them after visiting all windows.
|
||||
let l:originalWindowLayout = winrestcmd()
|
||||
|
||||
noautocmd windo call mark#UpdateMark()
|
||||
execute l:currentWinNr . 'wincmd w'
|
||||
silent! execute l:originalWindowLayout
|
||||
endfunction
|
||||
" Mark or unmark a regular expression.
|
||||
function! mark#DoMark(...) " DoMark(regexp)
|
||||
let regexp = (a:0 ? a:1 : '')
|
||||
|
||||
" clear all marks if regexp is null
|
||||
if empty(regexp)
|
||||
let i = 0
|
||||
let indices = []
|
||||
while i < g:mwCycleMax
|
||||
if !empty(g:mwWord[i])
|
||||
let g:mwWord[i] = ''
|
||||
call add(indices, i)
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
let g:mwLastSearched = ""
|
||||
call s:MarkScope(l:indices, '')
|
||||
return
|
||||
endif
|
||||
|
||||
" clear the mark if it has been marked
|
||||
let i = 0
|
||||
while i < g:mwCycleMax
|
||||
if regexp == g:mwWord[i]
|
||||
if g:mwLastSearched == g:mwWord[i]
|
||||
let g:mwLastSearched = ''
|
||||
endif
|
||||
let g:mwWord[i] = ''
|
||||
call s:MarkScope([i], '')
|
||||
return
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
" add to history
|
||||
if stridx(g:mwHistAdd, "/") >= 0
|
||||
call histadd("/", regexp)
|
||||
endif
|
||||
if stridx(g:mwHistAdd, "@") >= 0
|
||||
call histadd("@", regexp)
|
||||
endif
|
||||
|
||||
" choose an unused mark group
|
||||
let i = 0
|
||||
while i < g:mwCycleMax
|
||||
if empty(g:mwWord[i])
|
||||
let g:mwWord[i] = regexp
|
||||
call s:Cycle(i)
|
||||
call s:MarkScope([i], regexp)
|
||||
return
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
" choose a mark group by cycle
|
||||
let i = s:Cycle()
|
||||
if g:mwLastSearched == g:mwWord[i]
|
||||
let g:mwLastSearched = ''
|
||||
endif
|
||||
let g:mwWord[i] = regexp
|
||||
call s:MarkScope([i], regexp)
|
||||
endfunction
|
||||
" Initialize mark colors in a (new) window.
|
||||
function! mark#UpdateMark()
|
||||
if ! exists('w:mwMatch')
|
||||
let w:mwMatch = repeat([0], g:mwCycleMax)
|
||||
endif
|
||||
|
||||
let i = 0
|
||||
while i < g:mwCycleMax
|
||||
if empty(g:mwWord[i])
|
||||
call s:MarkMatch([i], '')
|
||||
else
|
||||
call s:MarkMatch([i], g:mwWord[i])
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
endfunction
|
||||
|
||||
" Return [mark text, mark start position] of the mark under the cursor (or
|
||||
" ['', []] if there is no mark); multi-lines marks not supported.
|
||||
function! mark#CurrentMark()
|
||||
let line = getline(".")
|
||||
let i = 0
|
||||
while i < g:mwCycleMax
|
||||
if !empty(g:mwWord[i])
|
||||
" Note: col() is 1-based, all other indexes zero-based!
|
||||
let start = 0
|
||||
while start >= 0 && start < strlen(line) && start < col(".")
|
||||
let b = match(line, g:mwWord[i], start)
|
||||
let e = matchend(line, g:mwWord[i], start)
|
||||
if b < col(".") && col(".") <= e
|
||||
return [g:mwWord[i], [line("."), (b + 1)]]
|
||||
endif
|
||||
if b == e
|
||||
break
|
||||
endif
|
||||
let start = e
|
||||
endwhile
|
||||
endif
|
||||
let i += 1
|
||||
endwhile
|
||||
return ['', []]
|
||||
endfunction
|
||||
|
||||
" Search current mark.
|
||||
function! mark#SearchCurrentMark( isBackward )
|
||||
let [l:markText, l:markPosition] = mark#CurrentMark()
|
||||
if empty(l:markText)
|
||||
if empty(g:mwLastSearched)
|
||||
call mark#SearchAnyMark(a:isBackward)
|
||||
let g:mwLastSearched = mark#CurrentMark()[0]
|
||||
else
|
||||
call s:Search(g:mwLastSearched, a:isBackward, [], 'same-mark')
|
||||
endif
|
||||
else
|
||||
call s:Search(l:markText, a:isBackward, l:markPosition, (l:markText ==# g:mwLastSearched ? 'same-mark' : 'new-mark'))
|
||||
let g:mwLastSearched = l:markText
|
||||
endif
|
||||
endfunction
|
||||
|
||||
silent! call SearchSpecial#DoesNotExist() " Execute a function to force autoload.
|
||||
if exists('*SearchSpecial#WrapMessage')
|
||||
function! s:WrapMessage( searchType, searchPattern, isBackward )
|
||||
redraw
|
||||
call SearchSpecial#WrapMessage(a:searchType, a:searchPattern, a:isBackward)
|
||||
endfunction
|
||||
function! s:EchoSearchPattern( searchType, searchPattern, isBackward )
|
||||
call SearchSpecial#EchoSearchPattern(a:searchType, a:searchPattern, a:isBackward)
|
||||
endfunction
|
||||
else
|
||||
function! s:Trim( message )
|
||||
" Limit length to avoid "Hit ENTER" prompt.
|
||||
return strpart(a:message, 0, (&columns / 2)) . (len(a:message) > (&columns / 2) ? "..." : "")
|
||||
endfunction
|
||||
function! s:WrapMessage( searchType, searchPattern, isBackward )
|
||||
redraw
|
||||
let v:warningmsg = printf('%s search hit %s, continuing at %s', a:searchType, (a:isBackward ? 'TOP' : 'BOTTOM'), (a:isBackward ? 'BOTTOM' : 'TOP'))
|
||||
echohl WarningMsg
|
||||
echo s:Trim(v:warningmsg)
|
||||
echohl None
|
||||
endfunction
|
||||
function! s:EchoSearchPattern( searchType, searchPattern, isBackward )
|
||||
let l:message = (a:isBackward ? '?' : '/') . a:searchPattern
|
||||
echohl SearchSpecialSearchType
|
||||
echo a:searchType
|
||||
echohl None
|
||||
echon s:Trim(l:message)
|
||||
endfunction
|
||||
endif
|
||||
function! s:ErrorMessage( searchType, searchPattern, isBackward )
|
||||
if &wrapscan
|
||||
let v:errmsg = a:searchType . ' not found: ' . a:searchPattern
|
||||
else
|
||||
let v:errmsg = printf('%s search hit %s without match for: %s', a:searchType, (a:isBackward ? 'TOP' : 'BOTTOM'), a:searchPattern)
|
||||
endif
|
||||
echohl ErrorMsg
|
||||
echomsg v:errmsg
|
||||
echohl None
|
||||
endfunction
|
||||
|
||||
" Wrapper around search() with additonal search and error messages and "wrapscan" warning.
|
||||
function! s:Search( pattern, isBackward, currentMarkPosition, searchType )
|
||||
let l:save_view = winsaveview()
|
||||
|
||||
" searchpos() obeys the 'smartcase' setting; however, this setting doesn't
|
||||
" make sense for the mark search, because all patterns for the marks are
|
||||
" concatenated as branches in one large regexp, and because patterns that
|
||||
" result from the *-command-alike mappings should not obey 'smartcase' (like
|
||||
" the * command itself), anyway. If the :Mark command wants to support
|
||||
" 'smartcase', it'd have to emulate that into the regular expression.
|
||||
let l:save_smartcase = &smartcase
|
||||
set nosmartcase
|
||||
|
||||
let l:count = v:count1
|
||||
let [l:startLine, l:startCol] = [line('.'), col('.')]
|
||||
let l:isWrapped = 0
|
||||
let l:isMatch = 0
|
||||
let l:line = 0
|
||||
while l:count > 0
|
||||
" Search for next match, 'wrapscan' applies.
|
||||
let [l:line, l:col] = searchpos( a:pattern, (a:isBackward ? 'b' : '') )
|
||||
|
||||
"****D echomsg '****' a:isBackward string([l:line, l:col]) string(a:currentMarkPosition) l:count
|
||||
if a:isBackward && l:line > 0 && [l:line, l:col] == a:currentMarkPosition && l:count == v:count1
|
||||
" On a search in backward direction, the first match is the start of the
|
||||
" current mark (if the cursor was positioned on the current mark text, and
|
||||
" not at the start of the mark text).
|
||||
" In contrast to the normal search, this is not considered the first
|
||||
" match. The mark text is one entity; if the cursor is positioned anywhere
|
||||
" inside the mark text, the mark text is considered the current mark. The
|
||||
" built-in '*' and '#' commands behave in the same way; the entire <cword>
|
||||
" text is considered the current match, and jumps move outside that text.
|
||||
" In normal search, the cursor can be positioned anywhere (via offsets)
|
||||
" around the search, and only that single cursor position is considered
|
||||
" the current match.
|
||||
" Thus, the search is retried without a decrease of l:count, but only if
|
||||
" this was the first match; repeat visits during wrapping around count as
|
||||
" a regular match. The search also must not be retried when this is the
|
||||
" first match, but we've been here before (i.e. l:isMatch is set): This
|
||||
" means that there is only the current mark in the buffer, and we must
|
||||
" break out of the loop and indicate that no other mark was found.
|
||||
if l:isMatch
|
||||
let l:line = 0
|
||||
break
|
||||
endif
|
||||
|
||||
" The l:isMatch flag is set so if the final mark cannot be reached, the
|
||||
" original cursor position is restored. This flag also allows us to detect
|
||||
" whether we've been here before, which is checked above.
|
||||
let l:isMatch = 1
|
||||
elseif l:line > 0
|
||||
let l:isMatch = 1
|
||||
let l:count -= 1
|
||||
|
||||
" Note: No need to check 'wrapscan'; the wrapping can only occur if
|
||||
" 'wrapscan' is actually on.
|
||||
if ! a:isBackward && (l:startLine > l:line || l:startLine == l:line && l:startCol >= l:col)
|
||||
let l:isWrapped = 1
|
||||
elseif a:isBackward && (l:startLine < l:line || l:startLine == l:line && l:startCol <= l:col)
|
||||
let l:isWrapped = 1
|
||||
endif
|
||||
else
|
||||
break
|
||||
endif
|
||||
endwhile
|
||||
let &smartcase = l:save_smartcase
|
||||
|
||||
" We're not stuck when the search wrapped around and landed on the current
|
||||
" mark; that's why we exclude a possible wrap-around via v:count1 == 1.
|
||||
let l:isStuckAtCurrentMark = ([l:line, l:col] == a:currentMarkPosition && v:count1 == 1)
|
||||
if l:line > 0 && ! l:isStuckAtCurrentMark
|
||||
normal! zv
|
||||
|
||||
if l:isWrapped
|
||||
call s:WrapMessage(a:searchType, a:pattern, a:isBackward)
|
||||
else
|
||||
call s:EchoSearchPattern(a:searchType, a:pattern, a:isBackward)
|
||||
endif
|
||||
return 1
|
||||
else
|
||||
if l:isMatch
|
||||
" The view has been changed by moving through matches until the end /
|
||||
" start of file, when 'nowrapscan' forced a stop of searching before the
|
||||
" l:count'th match was found.
|
||||
" Restore the view to the state before the search.
|
||||
call winrestview(l:save_view)
|
||||
endif
|
||||
call s:ErrorMessage(a:searchType, a:pattern, a:isBackward)
|
||||
return 0
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" Combine all marks into one regexp.
|
||||
function! s:AnyMark()
|
||||
return join(filter(copy(g:mwWord), '! empty(v:val)'), '\|')
|
||||
endfunction
|
||||
|
||||
" Search any mark.
|
||||
function! mark#SearchAnyMark( isBackward )
|
||||
let l:markPosition = mark#CurrentMark()[1]
|
||||
let l:markText = s:AnyMark()
|
||||
call s:Search(l:markText, a:isBackward, l:markPosition, 'any-mark')
|
||||
let g:mwLastSearched = ""
|
||||
endfunction
|
||||
|
||||
" Search last searched mark.
|
||||
function! mark#SearchNext( isBackward )
|
||||
let l:markText = mark#CurrentMark()[0]
|
||||
if empty(l:markText)
|
||||
return 0
|
||||
else
|
||||
if empty(g:mwLastSearched)
|
||||
call mark#SearchAnyMark(a:isBackward)
|
||||
else
|
||||
call mark#SearchCurrentMark(a:isBackward)
|
||||
endif
|
||||
return 1
|
||||
endif
|
||||
endfunction
|
||||
|
||||
"- initializations ------------------------------------------------------------
|
||||
augroup Mark
|
||||
autocmd!
|
||||
autocmd VimEnter * if ! exists('w:mwMatch') | call mark#UpdateMark() | endif
|
||||
autocmd WinEnter * if ! exists('w:mwMatch') | call mark#UpdateMark() | endif
|
||||
autocmd TabEnter * call mark#UpdateScope()
|
||||
augroup END
|
||||
|
||||
" Define global variables and initialize current scope.
|
||||
function! s:InitMarkVariables()
|
||||
if !exists("g:mwHistAdd")
|
||||
let g:mwHistAdd = "/@"
|
||||
endif
|
||||
if !exists("g:mwCycleMax")
|
||||
let i = 1
|
||||
while hlexists("MarkWord" . i)
|
||||
let i = i + 1
|
||||
endwhile
|
||||
let g:mwCycleMax = i - 1
|
||||
endif
|
||||
if !exists("g:mwCycle")
|
||||
let g:mwCycle = 0
|
||||
endif
|
||||
if !exists("g:mwWord")
|
||||
let g:mwWord = repeat([''], g:mwCycleMax)
|
||||
endif
|
||||
if !exists("g:mwLastSearched")
|
||||
let g:mwLastSearched = ""
|
||||
endif
|
||||
endfunction
|
||||
call s:InitMarkVariables()
|
||||
call mark#UpdateScope()
|
||||
|
||||
" vim: ts=2 sw=2
|
||||
433
autoload/snipMate.vim
Normal file
433
autoload/snipMate.vim
Normal file
@@ -0,0 +1,433 @@
|
||||
fun! Filename(...)
|
||||
let filename = expand('%:t:r')
|
||||
if filename == '' | return a:0 == 2 ? a:2 : '' | endif
|
||||
return !a:0 || a:1 == '' ? filename : substitute(a:1, '$1', filename, 'g')
|
||||
endf
|
||||
|
||||
fun s:RemoveSnippet()
|
||||
unl! g:snipPos s:curPos s:snipLen s:endCol s:endLine s:prevLen
|
||||
\ s:lastBuf s:oldWord
|
||||
if exists('s:update')
|
||||
unl s:startCol s:origWordLen s:update
|
||||
if exists('s:oldVars') | unl s:oldVars s:oldEndCol | endif
|
||||
endif
|
||||
aug! snipMateAutocmds
|
||||
endf
|
||||
|
||||
fun snipMate#expandSnip(snip, col)
|
||||
let lnum = line('.') | let col = a:col
|
||||
|
||||
let snippet = s:ProcessSnippet(a:snip)
|
||||
" Avoid error if eval evaluates to nothing
|
||||
if snippet == '' | return '' | endif
|
||||
|
||||
" Expand snippet onto current position with the tab stops removed
|
||||
let snipLines = split(substitute(snippet, '$\d\+\|${\d\+.\{-}}', '', 'g'), "\n", 1)
|
||||
|
||||
let line = getline(lnum)
|
||||
let afterCursor = strpart(line, col - 1)
|
||||
" Keep text after the cursor
|
||||
if afterCursor != "\t" && afterCursor != ' '
|
||||
let line = strpart(line, 0, col - 1)
|
||||
let snipLines[-1] .= afterCursor
|
||||
else
|
||||
let afterCursor = ''
|
||||
" For some reason the cursor needs to move one right after this
|
||||
if line != '' && col == 1 && &ve != 'all' && &ve != 'onemore'
|
||||
let col += 1
|
||||
endif
|
||||
endif
|
||||
|
||||
call setline(lnum, line.snipLines[0])
|
||||
|
||||
" Autoindent snippet according to previous indentation
|
||||
let indent = matchend(line, '^.\{-}\ze\(\S\|$\)') + 1
|
||||
call append(lnum, map(snipLines[1:], "'".strpart(line, 0, indent - 1)."'.v:val"))
|
||||
|
||||
" Open any folds snippet expands into
|
||||
if &fen | sil! exe lnum.','.(lnum + len(snipLines) - 1).'foldopen' | endif
|
||||
|
||||
let [g:snipPos, s:snipLen] = s:BuildTabStops(snippet, lnum, col - indent, indent)
|
||||
|
||||
if s:snipLen
|
||||
aug snipMateAutocmds
|
||||
au CursorMovedI * call s:UpdateChangedSnip(0)
|
||||
au InsertEnter * call s:UpdateChangedSnip(1)
|
||||
aug END
|
||||
let s:lastBuf = bufnr(0) " Only expand snippet while in current buffer
|
||||
let s:curPos = 0
|
||||
let s:endCol = g:snipPos[s:curPos][1]
|
||||
let s:endLine = g:snipPos[s:curPos][0]
|
||||
|
||||
call cursor(g:snipPos[s:curPos][0], g:snipPos[s:curPos][1])
|
||||
let s:prevLen = [line('$'), col('$')]
|
||||
if g:snipPos[s:curPos][2] != -1 | return s:SelectWord() | endif
|
||||
else
|
||||
unl g:snipPos s:snipLen
|
||||
" Place cursor at end of snippet if no tab stop is given
|
||||
let newlines = len(snipLines) - 1
|
||||
call cursor(lnum + newlines, indent + len(snipLines[-1]) - len(afterCursor)
|
||||
\ + (newlines ? 0: col - 1))
|
||||
endif
|
||||
return ''
|
||||
endf
|
||||
|
||||
" Prepare snippet to be processed by s:BuildTabStops
|
||||
fun s:ProcessSnippet(snip)
|
||||
let snippet = a:snip
|
||||
" Evaluate eval (`...`) expressions.
|
||||
" Using a loop here instead of a regex fixes a bug with nested "\=".
|
||||
if stridx(snippet, '`') != -1
|
||||
while match(snippet, '`.\{-}`') != -1
|
||||
let snippet = substitute(snippet, '`.\{-}`',
|
||||
\ substitute(eval(matchstr(snippet, '`\zs.\{-}\ze`')),
|
||||
\ "\n\\%$", '', ''), '')
|
||||
endw
|
||||
let snippet = substitute(snippet, "\r", "\n", 'g')
|
||||
endif
|
||||
|
||||
" Place all text after a colon in a tab stop after the tab stop
|
||||
" (e.g. "${#:foo}" becomes "${:foo}foo").
|
||||
" This helps tell the position of the tab stops later.
|
||||
let snippet = substitute(snippet, '${\d\+:\(.\{-}\)}', '&\1', 'g')
|
||||
|
||||
" Update the a:snip so that all the $# become the text after
|
||||
" the colon in their associated ${#}.
|
||||
" (e.g. "${1:foo}" turns all "$1"'s into "foo")
|
||||
let i = 1
|
||||
while stridx(snippet, '${'.i) != -1
|
||||
let s = matchstr(snippet, '${'.i.':\zs.\{-}\ze}')
|
||||
if s != ''
|
||||
let snippet = substitute(snippet, '$'.i, s.'&', 'g')
|
||||
endif
|
||||
let i += 1
|
||||
endw
|
||||
|
||||
if &et " Expand tabs to spaces if 'expandtab' is set.
|
||||
return substitute(snippet, '\t', repeat(' ', &sts ? &sts : &sw), 'g')
|
||||
endif
|
||||
return snippet
|
||||
endf
|
||||
|
||||
" Counts occurences of haystack in needle
|
||||
fun s:Count(haystack, needle)
|
||||
let counter = 0
|
||||
let index = stridx(a:haystack, a:needle)
|
||||
while index != -1
|
||||
let index = stridx(a:haystack, a:needle, index+1)
|
||||
let counter += 1
|
||||
endw
|
||||
return counter
|
||||
endf
|
||||
|
||||
" Builds a list of a list of each tab stop in the snippet containing:
|
||||
" 1.) The tab stop's line number.
|
||||
" 2.) The tab stop's column number
|
||||
" (by getting the length of the string between the last "\n" and the
|
||||
" tab stop).
|
||||
" 3.) The length of the text after the colon for the current tab stop
|
||||
" (e.g. "${1:foo}" would return 3). If there is no text, -1 is returned.
|
||||
" 4.) If the "${#:}" construct is given, another list containing all
|
||||
" the matches of "$#", to be replaced with the placeholder. This list is
|
||||
" composed the same way as the parent; the first item is the line number,
|
||||
" and the second is the column.
|
||||
fun s:BuildTabStops(snip, lnum, col, indent)
|
||||
let snipPos = []
|
||||
let i = 1
|
||||
let withoutVars = substitute(a:snip, '$\d\+', '', 'g')
|
||||
while stridx(a:snip, '${'.i) != -1
|
||||
let beforeTabStop = matchstr(withoutVars, '^.*\ze${'.i.'\D')
|
||||
let withoutOthers = substitute(withoutVars, '${\('.i.'\D\)\@!\d\+.\{-}}', '', 'g')
|
||||
|
||||
let j = i - 1
|
||||
call add(snipPos, [0, 0, -1])
|
||||
let snipPos[j][0] = a:lnum + s:Count(beforeTabStop, "\n")
|
||||
let snipPos[j][1] = a:indent + len(matchstr(withoutOthers, '.*\(\n\|^\)\zs.*\ze${'.i.'\D'))
|
||||
if snipPos[j][0] == a:lnum | let snipPos[j][1] += a:col | endif
|
||||
|
||||
" Get all $# matches in another list, if ${#:name} is given
|
||||
if stridx(withoutVars, '${'.i.':') != -1
|
||||
let snipPos[j][2] = len(matchstr(withoutVars, '${'.i.':\zs.\{-}\ze}'))
|
||||
let dots = repeat('.', snipPos[j][2])
|
||||
call add(snipPos[j], [])
|
||||
let withoutOthers = substitute(a:snip, '${\d\+.\{-}}\|$'.i.'\@!\d\+', '', 'g')
|
||||
while match(withoutOthers, '$'.i.'\(\D\|$\)') != -1
|
||||
let beforeMark = matchstr(withoutOthers, '^.\{-}\ze'.dots.'$'.i.'\(\D\|$\)')
|
||||
call add(snipPos[j][3], [0, 0])
|
||||
let snipPos[j][3][-1][0] = a:lnum + s:Count(beforeMark, "\n")
|
||||
let snipPos[j][3][-1][1] = a:indent + (snipPos[j][3][-1][0] > a:lnum
|
||||
\ ? len(matchstr(beforeMark, '.*\n\zs.*'))
|
||||
\ : a:col + len(beforeMark))
|
||||
let withoutOthers = substitute(withoutOthers, '$'.i.'\ze\(\D\|$\)', '', '')
|
||||
endw
|
||||
endif
|
||||
let i += 1
|
||||
endw
|
||||
return [snipPos, i - 1]
|
||||
endf
|
||||
|
||||
fun snipMate#jumpTabStop(backwards)
|
||||
let leftPlaceholder = exists('s:origWordLen')
|
||||
\ && s:origWordLen != g:snipPos[s:curPos][2]
|
||||
if leftPlaceholder && exists('s:oldEndCol')
|
||||
let startPlaceholder = s:oldEndCol + 1
|
||||
endif
|
||||
|
||||
if exists('s:update')
|
||||
call s:UpdatePlaceholderTabStops()
|
||||
else
|
||||
call s:UpdateTabStops()
|
||||
endif
|
||||
|
||||
" Don't reselect placeholder if it has been modified
|
||||
if leftPlaceholder && g:snipPos[s:curPos][2] != -1
|
||||
if exists('startPlaceholder')
|
||||
let g:snipPos[s:curPos][1] = startPlaceholder
|
||||
else
|
||||
let g:snipPos[s:curPos][1] = col('.')
|
||||
let g:snipPos[s:curPos][2] = 0
|
||||
endif
|
||||
endif
|
||||
|
||||
let s:curPos += a:backwards ? -1 : 1
|
||||
" Loop over the snippet when going backwards from the beginning
|
||||
if s:curPos < 0 | let s:curPos = s:snipLen - 1 | endif
|
||||
|
||||
if s:curPos == s:snipLen
|
||||
let sMode = s:endCol == g:snipPos[s:curPos-1][1]+g:snipPos[s:curPos-1][2]
|
||||
call s:RemoveSnippet()
|
||||
return sMode ? "\<tab>" : TriggerSnippet()
|
||||
endif
|
||||
|
||||
call cursor(g:snipPos[s:curPos][0], g:snipPos[s:curPos][1])
|
||||
|
||||
let s:endLine = g:snipPos[s:curPos][0]
|
||||
let s:endCol = g:snipPos[s:curPos][1]
|
||||
let s:prevLen = [line('$'), col('$')]
|
||||
|
||||
return g:snipPos[s:curPos][2] == -1 ? '' : s:SelectWord()
|
||||
endf
|
||||
|
||||
fun s:UpdatePlaceholderTabStops()
|
||||
let changeLen = s:origWordLen - g:snipPos[s:curPos][2]
|
||||
unl s:startCol s:origWordLen s:update
|
||||
if !exists('s:oldVars') | return | endif
|
||||
" Update tab stops in snippet if text has been added via "$#"
|
||||
" (e.g., in "${1:foo}bar$1${2}").
|
||||
if changeLen != 0
|
||||
let curLine = line('.')
|
||||
|
||||
for pos in g:snipPos
|
||||
if pos == g:snipPos[s:curPos] | continue | endif
|
||||
let changed = pos[0] == curLine && pos[1] > s:oldEndCol
|
||||
let changedVars = 0
|
||||
let endPlaceholder = pos[2] - 1 + pos[1]
|
||||
" Subtract changeLen from each tab stop that was after any of
|
||||
" the current tab stop's placeholders.
|
||||
for [lnum, col] in s:oldVars
|
||||
if lnum > pos[0] | break | endif
|
||||
if pos[0] == lnum
|
||||
if pos[1] > col || (pos[2] == -1 && pos[1] == col)
|
||||
let changed += 1
|
||||
elseif col < endPlaceholder
|
||||
let changedVars += 1
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
let pos[1] -= changeLen * changed
|
||||
let pos[2] -= changeLen * changedVars " Parse variables within placeholders
|
||||
" e.g., "${1:foo} ${2:$1bar}"
|
||||
|
||||
if pos[2] == -1 | continue | endif
|
||||
" Do the same to any placeholders in the other tab stops.
|
||||
for nPos in pos[3]
|
||||
let changed = nPos[0] == curLine && nPos[1] > s:oldEndCol
|
||||
for [lnum, col] in s:oldVars
|
||||
if lnum > nPos[0] | break | endif
|
||||
if nPos[0] == lnum && nPos[1] > col
|
||||
let changed += 1
|
||||
endif
|
||||
endfor
|
||||
let nPos[1] -= changeLen * changed
|
||||
endfor
|
||||
endfor
|
||||
endif
|
||||
unl s:endCol s:oldVars s:oldEndCol
|
||||
endf
|
||||
|
||||
fun s:UpdateTabStops()
|
||||
let changeLine = s:endLine - g:snipPos[s:curPos][0]
|
||||
let changeCol = s:endCol - g:snipPos[s:curPos][1]
|
||||
if exists('s:origWordLen')
|
||||
let changeCol -= s:origWordLen
|
||||
unl s:origWordLen
|
||||
endif
|
||||
let lnum = g:snipPos[s:curPos][0]
|
||||
let col = g:snipPos[s:curPos][1]
|
||||
" Update the line number of all proceeding tab stops if <cr> has
|
||||
" been inserted.
|
||||
if changeLine != 0
|
||||
let changeLine -= 1
|
||||
for pos in g:snipPos
|
||||
if pos[0] >= lnum
|
||||
if pos[0] == lnum | let pos[1] += changeCol | endif
|
||||
let pos[0] += changeLine
|
||||
endif
|
||||
if pos[2] == -1 | continue | endif
|
||||
for nPos in pos[3]
|
||||
if nPos[0] >= lnum
|
||||
if nPos[0] == lnum | let nPos[1] += changeCol | endif
|
||||
let nPos[0] += changeLine
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
elseif changeCol != 0
|
||||
" Update the column of all proceeding tab stops if text has
|
||||
" been inserted/deleted in the current line.
|
||||
for pos in g:snipPos
|
||||
if pos[1] >= col && pos[0] == lnum
|
||||
let pos[1] += changeCol
|
||||
endif
|
||||
if pos[2] == -1 | continue | endif
|
||||
for nPos in pos[3]
|
||||
if nPos[0] > lnum | break | endif
|
||||
if nPos[0] == lnum && nPos[1] >= col
|
||||
let nPos[1] += changeCol
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
endif
|
||||
endf
|
||||
|
||||
fun s:SelectWord()
|
||||
let s:origWordLen = g:snipPos[s:curPos][2]
|
||||
let s:oldWord = strpart(getline('.'), g:snipPos[s:curPos][1] - 1,
|
||||
\ s:origWordLen)
|
||||
let s:prevLen[1] -= s:origWordLen
|
||||
if !empty(g:snipPos[s:curPos][3])
|
||||
let s:update = 1
|
||||
let s:endCol = -1
|
||||
let s:startCol = g:snipPos[s:curPos][1] - 1
|
||||
endif
|
||||
if !s:origWordLen | return '' | endif
|
||||
let l = col('.') != 1 ? 'l' : ''
|
||||
if &sel == 'exclusive'
|
||||
return "\<esc>".l.'v'.s:origWordLen."l\<c-g>"
|
||||
endif
|
||||
return s:origWordLen == 1 ? "\<esc>".l.'gh'
|
||||
\ : "\<esc>".l.'v'.(s:origWordLen - 1)."l\<c-g>"
|
||||
endf
|
||||
|
||||
" This updates the snippet as you type when text needs to be inserted
|
||||
" into multiple places (e.g. in "${1:default text}foo$1bar$1",
|
||||
" "default text" would be highlighted, and if the user types something,
|
||||
" UpdateChangedSnip() would be called so that the text after "foo" & "bar"
|
||||
" are updated accordingly)
|
||||
"
|
||||
" It also automatically quits the snippet if the cursor is moved out of it
|
||||
" while in insert mode.
|
||||
fun s:UpdateChangedSnip(entering)
|
||||
if exists('g:snipPos') && bufnr(0) != s:lastBuf
|
||||
call s:RemoveSnippet()
|
||||
elseif exists('s:update') " If modifying a placeholder
|
||||
if !exists('s:oldVars') && s:curPos + 1 < s:snipLen
|
||||
" Save the old snippet & word length before it's updated
|
||||
" s:startCol must be saved too, in case text is added
|
||||
" before the snippet (e.g. in "foo$1${2}bar${1:foo}").
|
||||
let s:oldEndCol = s:startCol
|
||||
let s:oldVars = deepcopy(g:snipPos[s:curPos][3])
|
||||
endif
|
||||
let col = col('.') - 1
|
||||
|
||||
if s:endCol != -1
|
||||
let changeLen = col('$') - s:prevLen[1]
|
||||
let s:endCol += changeLen
|
||||
else " When being updated the first time, after leaving select mode
|
||||
if a:entering | return | endif
|
||||
let s:endCol = col - 1
|
||||
endif
|
||||
|
||||
" If the cursor moves outside the snippet, quit it
|
||||
if line('.') != g:snipPos[s:curPos][0] || col < s:startCol ||
|
||||
\ col - 1 > s:endCol
|
||||
unl! s:startCol s:origWordLen s:oldVars s:update
|
||||
return s:RemoveSnippet()
|
||||
endif
|
||||
|
||||
call s:UpdateVars()
|
||||
let s:prevLen[1] = col('$')
|
||||
elseif exists('g:snipPos')
|
||||
if !a:entering && g:snipPos[s:curPos][2] != -1
|
||||
let g:snipPos[s:curPos][2] = -2
|
||||
endif
|
||||
|
||||
let col = col('.')
|
||||
let lnum = line('.')
|
||||
let changeLine = line('$') - s:prevLen[0]
|
||||
|
||||
if lnum == s:endLine
|
||||
let s:endCol += col('$') - s:prevLen[1]
|
||||
let s:prevLen = [line('$'), col('$')]
|
||||
endif
|
||||
if changeLine != 0
|
||||
let s:endLine += changeLine
|
||||
let s:endCol = col
|
||||
endif
|
||||
|
||||
" Delete snippet if cursor moves out of it in insert mode
|
||||
if (lnum == s:endLine && (col > s:endCol || col < g:snipPos[s:curPos][1]))
|
||||
\ || lnum > s:endLine || lnum < g:snipPos[s:curPos][0]
|
||||
call s:RemoveSnippet()
|
||||
endif
|
||||
endif
|
||||
endf
|
||||
|
||||
" This updates the variables in a snippet when a placeholder has been edited.
|
||||
" (e.g., each "$1" in "${1:foo} $1bar $1bar")
|
||||
fun s:UpdateVars()
|
||||
let newWordLen = s:endCol - s:startCol + 1
|
||||
let newWord = strpart(getline('.'), s:startCol, newWordLen)
|
||||
if newWord == s:oldWord || empty(g:snipPos[s:curPos][3])
|
||||
return
|
||||
endif
|
||||
|
||||
let changeLen = g:snipPos[s:curPos][2] - newWordLen
|
||||
let curLine = line('.')
|
||||
let startCol = col('.')
|
||||
let oldStartSnip = s:startCol
|
||||
let updateTabStops = changeLen != 0
|
||||
let i = 0
|
||||
|
||||
for [lnum, col] in g:snipPos[s:curPos][3]
|
||||
if updateTabStops
|
||||
let start = s:startCol
|
||||
if lnum == curLine && col <= start
|
||||
let s:startCol -= changeLen
|
||||
let s:endCol -= changeLen
|
||||
endif
|
||||
for nPos in g:snipPos[s:curPos][3][(i):]
|
||||
" This list is in ascending order, so quit if we've gone too far.
|
||||
if nPos[0] > lnum | break | endif
|
||||
if nPos[0] == lnum && nPos[1] > col
|
||||
let nPos[1] -= changeLen
|
||||
endif
|
||||
endfor
|
||||
if lnum == curLine && col > start
|
||||
let col -= changeLen
|
||||
let g:snipPos[s:curPos][3][i][1] = col
|
||||
endif
|
||||
let i += 1
|
||||
endif
|
||||
|
||||
" "Very nomagic" is used here to allow special characters.
|
||||
call setline(lnum, substitute(getline(lnum), '\%'.col.'c\V'.
|
||||
\ escape(s:oldWord, '\'), escape(newWord, '\&'), ''))
|
||||
endfor
|
||||
if oldStartSnip != s:startCol
|
||||
call cursor(0, startCol + s:startCol - oldStartSnip)
|
||||
endif
|
||||
|
||||
let s:oldWord = newWord
|
||||
let g:snipPos[s:curPos][2] = newWordLen
|
||||
endf
|
||||
" vim:noet:sw=4:ts=4:ft=vim
|
||||
699
autoload/vimwiki.vim
Normal file
699
autoload/vimwiki.vim
Normal file
@@ -0,0 +1,699 @@
|
||||
" Vimwiki autoload plugin file
|
||||
" Author: Maxim Kim <habamax@gmail.com>
|
||||
" Home: http://code.google.com/p/vimwiki/
|
||||
|
||||
if exists("g:loaded_vimwiki_auto") || &cp
|
||||
finish
|
||||
endif
|
||||
let g:loaded_vimwiki_auto = 1
|
||||
|
||||
if has("win32")
|
||||
let s:os_sep = '\'
|
||||
else
|
||||
let s:os_sep = '/'
|
||||
endif
|
||||
|
||||
let s:badsymbols = '['.g:vimwiki_badsyms.g:vimwiki_stripsym.'<>|?*:"]'
|
||||
|
||||
" MISC helper functions {{{
|
||||
|
||||
" This function is double defined.
|
||||
" TODO: refactor common functions into new module.
|
||||
function! s:chomp_slash(str) "{{{
|
||||
return substitute(a:str, '[/\\]\+$', '', '')
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_windows()
|
||||
return has("win32") || has("win64") || has("win95") || has("win16")
|
||||
endfunction
|
||||
|
||||
function! vimwiki#mkdir(path) "{{{
|
||||
let path = expand(a:path)
|
||||
if !isdirectory(path) && exists("*mkdir")
|
||||
let path = s:chomp_slash(path)
|
||||
if s:is_windows() && !empty(g:vimwiki_w32_dir_enc)
|
||||
let path = iconv(path, &enc, g:vimwiki_w32_dir_enc)
|
||||
endif
|
||||
call mkdir(path, "p")
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#safe_link(string) "{{{
|
||||
return substitute(a:string, s:badsymbols, g:vimwiki_stripsym, 'g')
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#unsafe_link(string) "{{{
|
||||
return substitute(a:string, g:vimwiki_stripsym, s:badsymbols, 'g')
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#subdir(path, filename)"{{{
|
||||
let path = expand(a:path)
|
||||
let filename = expand(a:filename)
|
||||
let idx = 0
|
||||
while path[idx] == filename[idx]
|
||||
let idx = idx + 1
|
||||
endwhile
|
||||
|
||||
let p = split(strpart(filename, idx), '[/\\]')
|
||||
let res = join(p[:-2], s:os_sep)
|
||||
if len(res) > 0
|
||||
let res = res.s:os_sep
|
||||
endif
|
||||
return res
|
||||
endfunction"}}}
|
||||
|
||||
function! vimwiki#current_subdir()"{{{
|
||||
return vimwiki#subdir(VimwikiGet('path'), expand('%:p'))
|
||||
endfunction"}}}
|
||||
|
||||
function! vimwiki#open_link(cmd, link, ...) "{{{
|
||||
if s:is_link_to_non_wiki_file(a:link)
|
||||
call s:edit_file(a:cmd, a:link)
|
||||
else
|
||||
if a:0
|
||||
let vimwiki_prev_link = [a:1, []]
|
||||
elseif &ft == 'vimwiki'
|
||||
let vimwiki_prev_link = [expand('%:p'), getpos('.')]
|
||||
endif
|
||||
|
||||
call s:edit_file(a:cmd, VimwikiGet('path').a:link.VimwikiGet('ext'))
|
||||
|
||||
if exists('vimwiki_prev_link')
|
||||
let b:vimwiki_prev_link = vimwiki_prev_link
|
||||
endif
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:filename(link) "{{{
|
||||
let result = vimwiki#safe_link(a:link)
|
||||
if a:link =~ '|'
|
||||
let result = vimwiki#safe_link(split(a:link, '|')[0])
|
||||
elseif a:link =~ ']['
|
||||
let result = vimwiki#safe_link(split(a:link, '][')[0])
|
||||
endif
|
||||
return result
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:is_wiki_word(str) "{{{
|
||||
if a:str =~ g:vimwiki_word1 && a:str !~ '[[:space:]\\/]'
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:edit_file(command, filename) "{{{
|
||||
let fname = escape(a:filename, '% ')
|
||||
call vimwiki#mkdir(fnamemodify(a:filename, ":p:h"))
|
||||
execute a:command.' '.fname
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:search_word(wikiRx, cmd) "{{{
|
||||
let match_line = search(a:wikiRx, 's'.a:cmd)
|
||||
if match_line == 0
|
||||
echomsg "vimwiki: Wiki link not found."
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:get_word_at_cursor(wikiRX) "{{{
|
||||
let col = col('.') - 1
|
||||
let line = getline('.')
|
||||
let ebeg = -1
|
||||
let cont = match(line, a:wikiRX, 0)
|
||||
while (ebeg >= 0 || (0 <= cont) && (cont <= col))
|
||||
let contn = matchend(line, a:wikiRX, cont)
|
||||
if (cont <= col) && (col < contn)
|
||||
let ebeg = match(line, a:wikiRX, cont)
|
||||
let elen = contn - ebeg
|
||||
break
|
||||
else
|
||||
let cont = match(line, a:wikiRX, contn)
|
||||
endif
|
||||
endwh
|
||||
if ebeg >= 0
|
||||
return strpart(line, ebeg, elen)
|
||||
else
|
||||
return ""
|
||||
endif
|
||||
endf "}}}
|
||||
|
||||
function! s:strip_word(word) "{{{
|
||||
let result = a:word
|
||||
if strpart(a:word, 0, 2) == "[["
|
||||
" get rid of [[ and ]]
|
||||
let w = strpart(a:word, 2, strlen(a:word)-4)
|
||||
|
||||
if w =~ '|'
|
||||
" we want "link" from [[link|link desc]]
|
||||
let w = split(w, "|")[0]
|
||||
elseif w =~ ']['
|
||||
" we want "link" from [[link][link desc]]
|
||||
let w = split(w, "][")[0]
|
||||
endif
|
||||
|
||||
let result = vimwiki#safe_link(w)
|
||||
endif
|
||||
return result
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:is_link_to_non_wiki_file(word) "{{{
|
||||
" Check if word is link to a non-wiki file.
|
||||
" The easiest way is to check if it has extension like .txt or .html
|
||||
if a:word =~ '\.\w\{1,4}$'
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:print_wiki_list() "{{{
|
||||
let idx = 0
|
||||
while idx < len(g:vimwiki_list)
|
||||
if idx == g:vimwiki_current_idx
|
||||
let sep = ' * '
|
||||
echohl PmenuSel
|
||||
else
|
||||
let sep = ' '
|
||||
echohl None
|
||||
endif
|
||||
echo (idx + 1).sep.VimwikiGet('path', idx)
|
||||
let idx += 1
|
||||
endwhile
|
||||
echohl None
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#select(wnum)"{{{
|
||||
if a:wnum < 1 || a:wnum > len(g:vimwiki_list)
|
||||
return
|
||||
endif
|
||||
if &ft == 'vimwiki'
|
||||
let b:vimwiki_idx = g:vimwiki_current_idx
|
||||
endif
|
||||
let g:vimwiki_current_idx = a:wnum - 1
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:update_wiki_link(fname, old, new) " {{{
|
||||
echo "Updating links in ".a:fname
|
||||
let has_updates = 0
|
||||
let dest = []
|
||||
for line in readfile(a:fname)
|
||||
if !has_updates && match(line, a:old) != -1
|
||||
let has_updates = 1
|
||||
endif
|
||||
call add(dest, substitute(line, a:old, escape(a:new, "&"), "g"))
|
||||
endfor
|
||||
" add exception handling...
|
||||
if has_updates
|
||||
call rename(a:fname, a:fname.'#vimwiki_upd#')
|
||||
call writefile(dest, a:fname)
|
||||
call delete(a:fname.'#vimwiki_upd#')
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:update_wiki_links_dir(dir, old_fname, new_fname) " {{{
|
||||
let old_fname = substitute(a:old_fname, '[/\\]', '[/\\\\]', 'g')
|
||||
let new_fname = a:new_fname
|
||||
|
||||
if !s:is_wiki_word(new_fname)
|
||||
let new_fname = '[['.new_fname.']]'
|
||||
endif
|
||||
if !s:is_wiki_word(old_fname)
|
||||
let old_fname = '\[\['.vimwiki#unsafe_link(old_fname).
|
||||
\ '\%(|.*\)\?\%(\]\[.*\)\?\]\]'
|
||||
else
|
||||
let old_fname = '\<'.old_fname.'\>'
|
||||
endif
|
||||
let files = split(glob(VimwikiGet('path').a:dir.'*'.VimwikiGet('ext')), '\n')
|
||||
for fname in files
|
||||
call s:update_wiki_link(fname, old_fname, new_fname)
|
||||
endfor
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:tail_name(fname) "{{{
|
||||
let result = substitute(a:fname, ":", "__colon__", "g")
|
||||
let result = fnamemodify(result, ":t:r")
|
||||
let result = substitute(result, "__colon__", ":", "g")
|
||||
return result
|
||||
endfunction "}}}
|
||||
|
||||
function! s:update_wiki_links(old_fname, new_fname) " {{{
|
||||
let old_fname = s:tail_name(a:old_fname)
|
||||
let new_fname = s:tail_name(a:new_fname)
|
||||
|
||||
let subdirs = split(a:old_fname, '[/\\]')[: -2]
|
||||
|
||||
" TODO: Use Dictionary here...
|
||||
let dirs_keys = ['']
|
||||
let dirs_vals = ['']
|
||||
if len(subdirs) > 0
|
||||
let dirs_keys = ['']
|
||||
let dirs_vals = [join(subdirs, '/').'/']
|
||||
let idx = 0
|
||||
while idx < len(subdirs) - 1
|
||||
call add(dirs_keys, join(subdirs[: idx], '/').'/')
|
||||
call add(dirs_vals, join(subdirs[idx+1 :], '/').'/')
|
||||
let idx = idx + 1
|
||||
endwhile
|
||||
call add(dirs_keys,join(subdirs, '/').'/')
|
||||
call add(dirs_vals, '')
|
||||
endif
|
||||
|
||||
let idx = 0
|
||||
while idx < len(dirs_keys)
|
||||
let dir = dirs_keys[idx]
|
||||
let new_dir = dirs_vals[idx]
|
||||
call s:update_wiki_links_dir(dir,
|
||||
\ new_dir.old_fname, new_dir.new_fname)
|
||||
let idx = idx + 1
|
||||
endwhile
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:get_wiki_buffers() "{{{
|
||||
let blist = []
|
||||
let bcount = 1
|
||||
while bcount<=bufnr("$")
|
||||
if bufexists(bcount)
|
||||
let bname = fnamemodify(bufname(bcount), ":p")
|
||||
if bname =~ VimwikiGet('ext')."$"
|
||||
let bitem = [bname, getbufvar(bname, "vimwiki_prev_link")]
|
||||
call add(blist, bitem)
|
||||
endif
|
||||
endif
|
||||
let bcount = bcount + 1
|
||||
endwhile
|
||||
return blist
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:open_wiki_buffer(item) "{{{
|
||||
call s:edit_file('e', a:item[0])
|
||||
if !empty(a:item[1])
|
||||
call setbufvar(a:item[0], "vimwiki_prev_link", a:item[1])
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" }}}
|
||||
|
||||
" SYNTAX highlight {{{
|
||||
function! vimwiki#WikiHighlightWords() "{{{
|
||||
" search all wiki files in 'path' and its subdirs.
|
||||
let subdir = vimwiki#current_subdir()
|
||||
let wikies = glob(VimwikiGet('path').subdir.'**/*'.VimwikiGet('ext'))
|
||||
|
||||
" remove .wiki extensions
|
||||
let wikies = substitute(wikies, '\'.VimwikiGet('ext'), "", "g")
|
||||
let g:vimwiki_wikiwords = split(wikies, '\n')
|
||||
|
||||
" remove backup files (.wiki~)
|
||||
call filter(g:vimwiki_wikiwords, 'v:val !~ ''.*\~$''')
|
||||
|
||||
" remove paths
|
||||
let rem_path = escape(expand(VimwikiGet('path')).subdir, '\')
|
||||
call map(g:vimwiki_wikiwords, 'substitute(v:val, rem_path, "", "g")')
|
||||
|
||||
" Links with subdirs should be highlighted for linux and windows separators
|
||||
" Change \ or / to [/\\]
|
||||
let os_p = '[/\\]'
|
||||
let os_p2 = escape(os_p, '\')
|
||||
call map(g:vimwiki_wikiwords, 'substitute(v:val, os_p, os_p2, "g")')
|
||||
|
||||
for word in g:vimwiki_wikiwords
|
||||
if g:vimwiki_camel_case &&
|
||||
\ word =~ g:vimwiki_word1 && !s:is_link_to_non_wiki_file(word)
|
||||
execute 'syntax match VimwikiWord /\%(^\|[^!]\)\@<=\<'.word.'\>/'
|
||||
endif
|
||||
execute 'syntax match VimwikiWord /\[\[\<'.
|
||||
\ vimwiki#unsafe_link(word).
|
||||
\ '\>\%(|\+.*\)*\]\]/'
|
||||
execute 'syntax match VimwikiWord /\[\[\<'.
|
||||
\ vimwiki#unsafe_link(word).
|
||||
\ '\>\]\[.\+\]\]/'
|
||||
endfor
|
||||
execute 'syntax match VimwikiWord /\[\[.\+\.\%(jpg\|png\|gif\)\%(|\+.*\)*\]\]/'
|
||||
execute 'syntax match VimwikiWord /\[\[.\+\.\%(jpg\|png\|gif\)\]\[.\+\]\]/'
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#hl_exists(hl)"{{{
|
||||
if !hlexists(a:hl)
|
||||
return 0
|
||||
endif
|
||||
redir => hlstatus
|
||||
exe "silent hi" a:hl
|
||||
redir END
|
||||
return (hlstatus !~ "cleared")
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#nested_syntax(filetype, start, end, textSnipHl) abort "{{{
|
||||
" From http://vim.wikia.com/wiki/VimTip857
|
||||
let ft=toupper(a:filetype)
|
||||
let group='textGroup'.ft
|
||||
if exists('b:current_syntax')
|
||||
let s:current_syntax=b:current_syntax
|
||||
" Remove current syntax definition, as some syntax files (e.g. cpp.vim)
|
||||
" do nothing if b:current_syntax is defined.
|
||||
unlet b:current_syntax
|
||||
endif
|
||||
|
||||
" Some syntax files set up iskeyword which might scratch vimwiki a bit.
|
||||
" Let us save and restore it later.
|
||||
" let b:skip_set_iskeyword = 1
|
||||
let is_keyword = &iskeyword
|
||||
|
||||
execute 'syntax include @'.group.' syntax/'.a:filetype.'.vim'
|
||||
try
|
||||
execute 'syntax include @'.group.' after/syntax/'.a:filetype.'.vim'
|
||||
catch
|
||||
endtry
|
||||
|
||||
let &iskeyword = is_keyword
|
||||
|
||||
if exists('s:current_syntax')
|
||||
let b:current_syntax=s:current_syntax
|
||||
else
|
||||
unlet b:current_syntax
|
||||
endif
|
||||
execute 'syntax region textSnip'.ft.'
|
||||
\ matchgroup='.a:textSnipHl.'
|
||||
\ start="'.a:start.'" end="'.a:end.'"
|
||||
\ contains=@'.group
|
||||
endfunction "}}}
|
||||
|
||||
"}}}
|
||||
|
||||
" WIKI functions {{{
|
||||
function! vimwiki#WikiNextWord() "{{{
|
||||
call s:search_word(g:vimwiki_rxWikiWord.'\|'.g:vimwiki_rxWeblink, '')
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#WikiPrevWord() "{{{
|
||||
call s:search_word(g:vimwiki_rxWikiWord.'\|'.g:vimwiki_rxWeblink, 'b')
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#WikiFollowWord(split) "{{{
|
||||
if a:split == "split"
|
||||
let cmd = ":split "
|
||||
elseif a:split == "vsplit"
|
||||
let cmd = ":vsplit "
|
||||
else
|
||||
let cmd = ":e "
|
||||
endif
|
||||
|
||||
let link = s:strip_word(s:get_word_at_cursor(g:vimwiki_rxWikiWord))
|
||||
if link == ""
|
||||
let weblink = s:strip_word(s:get_word_at_cursor(g:vimwiki_rxWeblink))
|
||||
if weblink != ""
|
||||
call VimwikiWeblinkHandler(weblink)
|
||||
else
|
||||
execute "normal! \n"
|
||||
endif
|
||||
return
|
||||
endif
|
||||
|
||||
let subdir = vimwiki#current_subdir()
|
||||
call vimwiki#open_link(cmd, subdir.link)
|
||||
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#WikiGoBackWord() "{{{
|
||||
if exists("b:vimwiki_prev_link")
|
||||
" go back to saved WikiWord
|
||||
let prev_word = b:vimwiki_prev_link
|
||||
execute ":e ".substitute(prev_word[0], '\s', '\\\0', 'g')
|
||||
call setpos('.', prev_word[1])
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#WikiGoHome(index) "{{{
|
||||
call vimwiki#select(a:index)
|
||||
call vimwiki#mkdir(VimwikiGet('path'))
|
||||
|
||||
try
|
||||
execute ':e '.fnameescape(
|
||||
\ VimwikiGet('path').VimwikiGet('index').VimwikiGet('ext'))
|
||||
catch /E37/ " catch 'No write since last change' error
|
||||
" this is really unsecure!!!
|
||||
execute ':'.VimwikiGet('gohome').' '.
|
||||
\ VimwikiGet('path').
|
||||
\ VimwikiGet('index').
|
||||
\ VimwikiGet('ext')
|
||||
catch /E325/ " catch 'ATTENTION' error (:h E325)
|
||||
endtry
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#WikiDeleteWord() "{{{
|
||||
"" file system funcs
|
||||
"" Delete WikiWord you are in from filesystem
|
||||
let val = input('Delete ['.expand('%').'] (y/n)? ', "")
|
||||
if val != 'y'
|
||||
return
|
||||
endif
|
||||
let fname = expand('%:p')
|
||||
try
|
||||
call delete(fname)
|
||||
catch /.*/
|
||||
echomsg 'vimwiki: Cannot delete "'.expand('%:t:r').'"!'
|
||||
return
|
||||
endtry
|
||||
execute "bdelete! ".escape(fname, " ")
|
||||
|
||||
" reread buffer => deleted WikiWord should appear as non-existent
|
||||
if expand('%:p') != ""
|
||||
execute "e"
|
||||
endif
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#WikiRenameWord() "{{{
|
||||
"" Rename WikiWord, update all links to renamed WikiWord
|
||||
let subdir = vimwiki#current_subdir()
|
||||
let old_fname = subdir.expand('%:t')
|
||||
|
||||
" there is no file (new one maybe)
|
||||
if glob(expand('%:p')) == ''
|
||||
echomsg 'vimwiki: Cannot rename "'.expand('%:p').
|
||||
\'". It does not exist! (New file? Save it before renaming.)'
|
||||
return
|
||||
endif
|
||||
|
||||
let val = input('Rename "'.expand('%:t:r').'" (y/n)? ', "")
|
||||
if val!='y'
|
||||
return
|
||||
endif
|
||||
|
||||
let new_link = input('Enter new name: ', "")
|
||||
|
||||
if new_link =~ '[/\\]'
|
||||
" It is actually doable but I do not have free time to do it.
|
||||
echomsg 'vimwiki: Cannot rename to a filename with path!'
|
||||
return
|
||||
endif
|
||||
|
||||
let new_link = subdir.new_link
|
||||
|
||||
" check new_fname - it should be 'good', not empty
|
||||
if substitute(new_link, '\s', '', 'g') == ''
|
||||
echomsg 'vimwiki: Cannot rename to an empty filename!'
|
||||
return
|
||||
endif
|
||||
if s:is_link_to_non_wiki_file(new_link)
|
||||
echomsg 'vimwiki: Cannot rename to a filename with extension (ie .txt .html)!'
|
||||
return
|
||||
endif
|
||||
|
||||
let new_link = s:strip_word(new_link)
|
||||
let new_fname = VimwikiGet('path').s:filename(new_link).VimwikiGet('ext')
|
||||
|
||||
" do not rename if word with such name exists
|
||||
let fname = glob(new_fname)
|
||||
if fname != ''
|
||||
echomsg 'vimwiki: Cannot rename to "'.new_fname.
|
||||
\ '". File with that name exist!'
|
||||
return
|
||||
endif
|
||||
" rename WikiWord file
|
||||
try
|
||||
echomsg "Renaming ".VimwikiGet('path').old_fname." to ".new_fname
|
||||
let res = rename(expand('%:p'), expand(new_fname))
|
||||
if res != 0
|
||||
throw "Cannot rename!"
|
||||
end
|
||||
catch /.*/
|
||||
echomsg 'vimwiki: Cannot rename "'.expand('%:t:r').'" to "'.new_fname.'"'
|
||||
return
|
||||
endtry
|
||||
|
||||
let &buftype="nofile"
|
||||
|
||||
let cur_buffer = [expand('%:p'),
|
||||
\getbufvar(expand('%:p'), "vimwiki_prev_link")]
|
||||
|
||||
let blist = s:get_wiki_buffers()
|
||||
|
||||
" save wiki buffers
|
||||
for bitem in blist
|
||||
execute ':b '.escape(bitem[0], ' ')
|
||||
execute ':update'
|
||||
endfor
|
||||
|
||||
execute ':b '.escape(cur_buffer[0], ' ')
|
||||
|
||||
" remove wiki buffers
|
||||
for bitem in blist
|
||||
execute 'bwipeout '.escape(bitem[0], ' ')
|
||||
endfor
|
||||
|
||||
let setting_more = &more
|
||||
setlocal nomore
|
||||
|
||||
" update links
|
||||
call s:update_wiki_links(old_fname, new_link)
|
||||
|
||||
" restore wiki buffers
|
||||
for bitem in blist
|
||||
if bitem[0] != cur_buffer[0]
|
||||
call s:open_wiki_buffer(bitem)
|
||||
endif
|
||||
endfor
|
||||
|
||||
call s:open_wiki_buffer([new_fname,
|
||||
\ cur_buffer[1]])
|
||||
" execute 'bwipeout '.escape(cur_buffer[0], ' ')
|
||||
|
||||
echomsg old_fname." is renamed to ".new_fname
|
||||
|
||||
let &more = setting_more
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#WikiUISelect()"{{{
|
||||
call s:print_wiki_list()
|
||||
let idx = input("Select Wiki (specify number): ")
|
||||
if idx == ""
|
||||
return
|
||||
endif
|
||||
call vimwiki#WikiGoHome(idx)
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
" }}}
|
||||
|
||||
" TEXT OBJECTS functions {{{
|
||||
|
||||
function! vimwiki#TO_header(inner, visual) "{{{
|
||||
if !search('^\(=\+\)[^=]\+\1\s*$', 'bcW')
|
||||
return
|
||||
endif
|
||||
|
||||
let sel_start = line("'<")
|
||||
let sel_end = line("'>")
|
||||
let block_start = line(".")
|
||||
let advance = 0
|
||||
|
||||
let level = vimwiki#count_first_sym(getline('.'))
|
||||
|
||||
let is_header_selected = sel_start == block_start
|
||||
\ && sel_start != sel_end
|
||||
|
||||
if a:visual && is_header_selected
|
||||
if level > 1
|
||||
let level -= 1
|
||||
call search('^\(=\{'.level.'\}\)[^=]\+\1\s*$', 'bcW')
|
||||
else
|
||||
let advance = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
normal! V
|
||||
|
||||
if a:visual && is_header_selected
|
||||
call cursor(sel_end + advance, 0)
|
||||
endif
|
||||
|
||||
if search('^\(=\{1,'.level.'}\)[^=]\+\1\s*$', 'W')
|
||||
call cursor(line('.') - 1, 0)
|
||||
else
|
||||
call cursor(line('$'), 0)
|
||||
endif
|
||||
|
||||
if a:inner && getline(line('.')) =~ '^\s*$'
|
||||
let lnum = prevnonblank(line('.') - 1)
|
||||
call cursor(lnum, 0)
|
||||
endif
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#count_first_sym(line) "{{{
|
||||
let first_sym = matchstr(a:line, '\S')
|
||||
return len(matchstr(a:line, first_sym.'\+'))
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#AddHeaderLevel() "{{{
|
||||
let lnum = line('.')
|
||||
let line = getline(lnum)
|
||||
|
||||
if line =~ '^\s*$'
|
||||
return
|
||||
endif
|
||||
|
||||
if line =~ '^\s*\(=\+\).\+\1\s*$'
|
||||
let level = vimwiki#count_first_sym(line)
|
||||
if level < 6
|
||||
let line = substitute(line, '\(=\+\).\+\1', '=&=', '')
|
||||
call setline(lnum, line)
|
||||
endif
|
||||
else
|
||||
let line = substitute(line, '^\s*', '&= ', '')
|
||||
let line = substitute(line, '\s*$', ' =&', '')
|
||||
call setline(lnum, line)
|
||||
endif
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#RemoveHeaderLevel() "{{{
|
||||
let lnum = line('.')
|
||||
let line = getline(lnum)
|
||||
|
||||
if line =~ '^\s*$'
|
||||
return
|
||||
endif
|
||||
|
||||
if line =~ '^\s*\(=\+\).\+\1\s*$'
|
||||
let level = vimwiki#count_first_sym(line)
|
||||
let old = repeat('=', level)
|
||||
let new = repeat('=', level - 1)
|
||||
|
||||
let chomp = line =~ '=\s'
|
||||
|
||||
let line = substitute(line, old, new, 'g')
|
||||
|
||||
if level == 1 && chomp
|
||||
let line = substitute(line, '^\s', '', 'g')
|
||||
let line = substitute(line, '\s$', '', 'g')
|
||||
endif
|
||||
call setline(lnum, line)
|
||||
endif
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
" }}}
|
||||
216
autoload/vimwiki_diary.vim
Normal file
216
autoload/vimwiki_diary.vim
Normal file
@@ -0,0 +1,216 @@
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Handle diary notes
|
||||
" Author: Maxim Kim <habamax@gmail.com>
|
||||
" Home: http://code.google.com/p/vimwiki/
|
||||
|
||||
" Load only once {{{
|
||||
if exists("g:loaded_vimwiki_diary_auto") || &cp
|
||||
finish
|
||||
endif
|
||||
let g:loaded_vimwiki_diary_auto = 1
|
||||
"}}}
|
||||
|
||||
function! s:prefix_zero(num) "{{{
|
||||
if a:num < 10
|
||||
return '0'.a:num
|
||||
endif
|
||||
return a:num
|
||||
endfunction "}}}
|
||||
|
||||
function! s:desc(d1, d2) "{{{
|
||||
return a:d1 == a:d2 ? 0 : a:d1 < a:d2 ? 1 : -1
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_date_link(fmt) "{{{
|
||||
return strftime(a:fmt)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:link_exists(lines, link) "{{{
|
||||
let link_exists = 0
|
||||
for line in a:lines
|
||||
if line =~ escape(a:link, '[]\')
|
||||
let link_exists = 1
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
return link_exists
|
||||
endfunction "}}}
|
||||
|
||||
function! s:diary_path() "{{{
|
||||
return VimwikiGet('path').VimwikiGet('diary_rel_path')
|
||||
endfunction "}}}
|
||||
|
||||
function! s:diary_index() "{{{
|
||||
return s:diary_path().VimwikiGet('diary_index').VimwikiGet('ext')
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_diary_range(lines, header) "{{{
|
||||
let rx = '\[\[\d\{4}-\d\d-\d\d\]\]'
|
||||
let idx = 0
|
||||
let ln_start = -1
|
||||
let ln_end = -1
|
||||
for line in a:lines
|
||||
if ln_start != -1
|
||||
if line =~ '^\s*\(=\)\+.*\1\s*$' || (line !~ rx && line !~ '^\s*$')
|
||||
break
|
||||
endif
|
||||
endif
|
||||
if line =~ '^\s*\(=\)\+\s*'.a:header.'\s*\1\s*$'
|
||||
let ln_start = idx + 1
|
||||
endif
|
||||
let idx += 1
|
||||
endfor
|
||||
|
||||
let ln_end = idx - 1
|
||||
return [ln_start, ln_end]
|
||||
endfunction "}}}
|
||||
|
||||
function! s:diary_date_link() "{{{
|
||||
return s:get_date_link(VimwikiGet('diary_link_fmt'))
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_file_contents(file_name) "{{{
|
||||
let lines = []
|
||||
let bufnr = bufnr(expand(a:file_name))
|
||||
if bufnr != -1
|
||||
let lines = getbufline(bufnr, 1, '$')
|
||||
else
|
||||
try
|
||||
let lines = readfile(expand(a:file_name))
|
||||
catch
|
||||
endtry
|
||||
endif
|
||||
return [lines, bufnr]
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_links() "{{{
|
||||
let rx = '\d\{4}-\d\d-\d\d'
|
||||
let s_links = glob(VimwikiGet('path').VimwikiGet('diary_rel_path').'*.wiki')
|
||||
|
||||
"let s_links = substitute(s_links, '\'.VimwikiGet('ext'), "", "g")
|
||||
let s_links = substitute(s_links, '\.wiki', "", "g")
|
||||
let links = split(s_links, '\n')
|
||||
|
||||
" remove backup files (.wiki~)
|
||||
call filter(links, 'v:val !~ ''.*\~$''')
|
||||
|
||||
" remove paths
|
||||
call map(links, 'fnamemodify(v:val, ":t")')
|
||||
|
||||
call filter(links, 'v:val =~ "'.escape(rx, '\').'"')
|
||||
call map(links, '"[[".v:val."]]"')
|
||||
return links
|
||||
endfunction "}}}
|
||||
|
||||
function! s:format_links(links) "{{{
|
||||
let lines = []
|
||||
let line = '| '
|
||||
let idx = 0
|
||||
let trigger = 0
|
||||
while idx < len(a:links)
|
||||
if idx/VimwikiGet('diary_link_count') > trigger
|
||||
let trigger = idx/VimwikiGet('diary_link_count')
|
||||
call add(lines, substitute(line, '\s\+$', '', ''))
|
||||
let line = '| '
|
||||
endif
|
||||
let line .= a:links[idx].' | '
|
||||
let idx += 1
|
||||
endwhile
|
||||
call add(lines, substitute(line, '\s\+$', '', ''))
|
||||
call extend(lines, [''])
|
||||
|
||||
return lines
|
||||
endfunction "}}}
|
||||
|
||||
function! s:add_link(page, header, link) "{{{
|
||||
let [lines, bufnr] = s:get_file_contents(a:page)
|
||||
|
||||
let [ln_start, ln_end] = s:get_diary_range(lines, a:header)
|
||||
|
||||
let link = '[['.a:link.']]'
|
||||
|
||||
let link_exists = s:link_exists(lines[ln_start : ln_end], link)
|
||||
|
||||
if !link_exists
|
||||
|
||||
if ln_start == -1
|
||||
call insert(lines, '= '.a:header.' =')
|
||||
let ln_start = 1
|
||||
endif
|
||||
|
||||
" removing 'old' links
|
||||
let idx = ln_end - ln_start
|
||||
while idx > 0
|
||||
call remove(lines, ln_start)
|
||||
let idx -= 1
|
||||
endwhile
|
||||
|
||||
" get all diary links from filesystem
|
||||
let links = s:get_links()
|
||||
|
||||
" add current link
|
||||
if index(links, link) == -1
|
||||
call add(links, link)
|
||||
endif
|
||||
|
||||
let links = sort(links, 's:desc')
|
||||
call extend(lines, s:format_links(links), ln_start)
|
||||
|
||||
if bufnr != -1
|
||||
exe 'buffer '.bufnr
|
||||
if !&readonly
|
||||
1,$delete _
|
||||
call append(1, lines)
|
||||
1,1delete _
|
||||
endif
|
||||
else
|
||||
call writefile(lines, expand(a:page))
|
||||
endif
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:make_date_link(...) "{{{
|
||||
if a:0
|
||||
let link = a:1
|
||||
else
|
||||
let link = s:diary_date_link()
|
||||
endif
|
||||
let header = VimwikiGet('diary_header')
|
||||
call s:add_link(s:diary_index(), header, link)
|
||||
return VimwikiGet('diary_rel_path').link
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_diary#make_note(index, ...) "{{{
|
||||
call vimwiki#select(a:index)
|
||||
call vimwiki#mkdir(VimwikiGet('path').VimwikiGet('diary_rel_path'))
|
||||
if a:0
|
||||
let link = s:make_date_link(a:1)
|
||||
else
|
||||
let link = s:make_date_link()
|
||||
endif
|
||||
call vimwiki#open_link(':e ', link, s:diary_index())
|
||||
endfunction "}}}
|
||||
|
||||
" Calendar.vim callback.
|
||||
function! vimwiki_diary#calendar_action(day, month, year, week, dir) "{{{
|
||||
let day = s:prefix_zero(a:day)
|
||||
let month = s:prefix_zero(a:month)
|
||||
|
||||
let link = a:year.'-'.month.'-'.day
|
||||
if winnr('#') == 0
|
||||
if a:dir == 'V'
|
||||
vsplit
|
||||
else
|
||||
split
|
||||
endif
|
||||
else
|
||||
wincmd p
|
||||
if !&hidden && &modified
|
||||
new
|
||||
endif
|
||||
endif
|
||||
|
||||
" Create diary note for a selected date in default wiki.
|
||||
call vimwiki_diary#make_note(1, link)
|
||||
endfunction
|
||||
|
||||
1123
autoload/vimwiki_html.vim
Normal file
1123
autoload/vimwiki_html.vim
Normal file
File diff suppressed because it is too large
Load Diff
361
autoload/vimwiki_lst.vim
Normal file
361
autoload/vimwiki_lst.vim
Normal file
@@ -0,0 +1,361 @@
|
||||
" Vimwiki autoload plugin file
|
||||
" Todo lists related stuff here.
|
||||
" Author: Maxim Kim <habamax@gmail.com>
|
||||
" Home: http://code.google.com/p/vimwiki/
|
||||
|
||||
if exists("g:loaded_vimwiki_list_auto") || &cp
|
||||
finish
|
||||
endif
|
||||
let g:loaded_vimwiki_lst_auto = 1
|
||||
|
||||
" Script variables {{{
|
||||
let s:rx_li_box = '\[.\?\]'
|
||||
" }}}
|
||||
|
||||
" Script functions {{{
|
||||
|
||||
" Get checkbox regexp
|
||||
function! s:rx_li_symbol(rate) "{{{
|
||||
let result = ''
|
||||
if a:rate == 100
|
||||
let result = g:vimwiki_listsyms[4]
|
||||
elseif a:rate == 0
|
||||
let result = g:vimwiki_listsyms[0]
|
||||
elseif a:rate >= 67
|
||||
let result = g:vimwiki_listsyms[3]
|
||||
elseif a:rate >= 34
|
||||
let result = g:vimwiki_listsyms[2]
|
||||
else
|
||||
let result = g:vimwiki_listsyms[1]
|
||||
endif
|
||||
|
||||
return '\['.result.'\]'
|
||||
endfunction "}}}
|
||||
|
||||
" Get regexp of the list item.
|
||||
function! s:rx_list_item() "{{{
|
||||
return '\('.g:vimwiki_rxListBullet.'\|'.g:vimwiki_rxListNumber.'\)'
|
||||
endfunction "}}}
|
||||
|
||||
" Get regexp of the list item with checkbox.
|
||||
function! s:rx_cb_list_item() "{{{
|
||||
" return s:rx_list_item().'\s*\zs\[.\?\]'
|
||||
return s:rx_list_item().'\s*\zs\[.\?\]'
|
||||
endfunction "}}}
|
||||
|
||||
" Get level of the list item.
|
||||
function! s:get_level(lnum) "{{{
|
||||
if VimwikiGet('syntax') == 'media'
|
||||
let level = vimwiki#count_first_sym(getline(a:lnum))
|
||||
else
|
||||
let level = indent(a:lnum)
|
||||
endif
|
||||
return level
|
||||
endfunction "}}}
|
||||
|
||||
" Get previous list item.
|
||||
" Returns: line number or 0.
|
||||
function! s:prev_list_item(lnum) "{{{
|
||||
let c_lnum = a:lnum - 1
|
||||
while c_lnum >= 1
|
||||
let line = getline(c_lnum)
|
||||
if line =~ s:rx_list_item()
|
||||
return c_lnum
|
||||
endif
|
||||
if line =~ '^\s*$'
|
||||
return 0
|
||||
endif
|
||||
let c_lnum -= 1
|
||||
endwhile
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
" Get next list item in the list.
|
||||
" Returns: line number or 0.
|
||||
function! s:next_list_item(lnum) "{{{
|
||||
let c_lnum = a:lnum + 1
|
||||
while c_lnum <= line('$')
|
||||
let line = getline(c_lnum)
|
||||
if line =~ s:rx_list_item()
|
||||
return c_lnum
|
||||
endif
|
||||
if line =~ '^\s*$'
|
||||
return 0
|
||||
endif
|
||||
let c_lnum += 1
|
||||
endwhile
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
" Find next list item in the buffer.
|
||||
" Returns: line number or 0.
|
||||
function! s:find_next_list_item(lnum) "{{{
|
||||
let c_lnum = a:lnum + 1
|
||||
while c_lnum <= line('$')
|
||||
let line = getline(c_lnum)
|
||||
if line =~ s:rx_list_item()
|
||||
return c_lnum
|
||||
endif
|
||||
let c_lnum += 1
|
||||
endwhile
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
" Set state of the list item on line number "lnum" to [ ] or [x]
|
||||
function! s:set_state(lnum, rate) "{{{
|
||||
let line = getline(a:lnum)
|
||||
let state = s:rx_li_symbol(a:rate)
|
||||
let line = substitute(line, s:rx_li_box, state, '')
|
||||
call setline(a:lnum, line)
|
||||
endfunction "}}}
|
||||
|
||||
" Get state of the list item on line number "lnum"
|
||||
function! s:get_state(lnum) "{{{
|
||||
let state = 0
|
||||
let line = getline(a:lnum)
|
||||
let opt = matchstr(line, s:rx_cb_list_item())
|
||||
if opt =~ s:rx_li_symbol(100)
|
||||
let state = 100
|
||||
elseif opt =~ s:rx_li_symbol(0)
|
||||
let state = 0
|
||||
elseif opt =~ s:rx_li_symbol(25)
|
||||
let state = 25
|
||||
elseif opt =~ s:rx_li_symbol(50)
|
||||
let state = 50
|
||||
elseif opt =~ s:rx_li_symbol(75)
|
||||
let state = 75
|
||||
endif
|
||||
return state
|
||||
endfunction "}}}
|
||||
|
||||
" Returns 1 if there is checkbox on a list item, 0 otherwise.
|
||||
function! s:is_cb_list_item(lnum) "{{{
|
||||
return getline(a:lnum) =~ s:rx_cb_list_item()
|
||||
endfunction "}}}
|
||||
|
||||
" Returns start line number of list item, 0 if it is not a list.
|
||||
function! s:is_list_item(lnum) "{{{
|
||||
let c_lnum = a:lnum
|
||||
while c_lnum >= 1
|
||||
let line = getline(c_lnum)
|
||||
if line =~ s:rx_list_item()
|
||||
return c_lnum
|
||||
endif
|
||||
if line =~ '^\s*$'
|
||||
return 0
|
||||
endif
|
||||
if indent(c_lnum) > indent(a:lnum)
|
||||
return 0
|
||||
endif
|
||||
let c_lnum -= 1
|
||||
endwhile
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
" Returns char column of checkbox. Used in parent/child checks.
|
||||
function! s:get_li_pos(lnum) "{{{
|
||||
return stridx(getline(a:lnum), '[')
|
||||
endfunction "}}}
|
||||
|
||||
" Returns list of line numbers of parent and all its child items.
|
||||
function! s:get_child_items(lnum) "{{{
|
||||
let result = []
|
||||
let lnum = a:lnum
|
||||
let p_pos = s:get_level(lnum)
|
||||
|
||||
" add parent
|
||||
call add(result, lnum)
|
||||
|
||||
let lnum = s:next_list_item(lnum)
|
||||
while lnum != 0 && s:is_list_item(lnum) && s:get_level(lnum) > p_pos
|
||||
call add(result, lnum)
|
||||
let lnum = s:next_list_item(lnum)
|
||||
endwhile
|
||||
|
||||
return result
|
||||
endfunction "}}}
|
||||
|
||||
" Returns list of line numbers of all items of the same level.
|
||||
function! s:get_sibling_items(lnum) "{{{
|
||||
let result = []
|
||||
let lnum = a:lnum
|
||||
let ind = s:get_level(lnum)
|
||||
|
||||
while s:get_level(lnum) >= ind &&
|
||||
\ lnum != 0
|
||||
|
||||
if s:get_level(lnum) == ind && s:is_cb_list_item(lnum)
|
||||
call add(result, lnum)
|
||||
endif
|
||||
let lnum = s:next_list_item(lnum)
|
||||
endwhile
|
||||
|
||||
let lnum = s:prev_list_item(a:lnum)
|
||||
while s:get_level(lnum) >= ind &&
|
||||
\ lnum != 0
|
||||
|
||||
if s:get_level(lnum) == ind && s:is_cb_list_item(lnum)
|
||||
call add(result, lnum)
|
||||
endif
|
||||
let lnum = s:prev_list_item(lnum)
|
||||
endwhile
|
||||
|
||||
return result
|
||||
endfunction "}}}
|
||||
|
||||
" Returns line number of the parent of lnum item
|
||||
function! s:get_parent_item(lnum) "{{{
|
||||
let lnum = a:lnum
|
||||
let ind = s:get_level(lnum)
|
||||
|
||||
let lnum = s:prev_list_item(lnum)
|
||||
while lnum != 0 && s:is_list_item(lnum) && s:get_level(lnum) >= ind
|
||||
let lnum = s:prev_list_item(lnum)
|
||||
endwhile
|
||||
|
||||
if s:is_cb_list_item(lnum)
|
||||
return lnum
|
||||
else
|
||||
return a:lnum
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
" Creates checkbox in a list item.
|
||||
function! s:create_cb_list_item(lnum) "{{{
|
||||
let line = getline(a:lnum)
|
||||
let m = matchstr(line, s:rx_list_item())
|
||||
if m != ''
|
||||
let li_content = substitute(strpart(line, len(m)), '^\s*', '', '')
|
||||
let line = m.'[ ] '.li_content
|
||||
call setline(a:lnum, line)
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
" Tells if all of the sibling list items are checked or not.
|
||||
function! s:all_siblings_checked(lnum) "{{{
|
||||
let result = 0
|
||||
let cnt = 0
|
||||
let siblings = s:get_sibling_items(a:lnum)
|
||||
for lnum in siblings
|
||||
let cnt += s:get_state(lnum)/100.0
|
||||
endfor
|
||||
let result = (cnt*100.0)/len(siblings)
|
||||
return result
|
||||
endfunction "}}}
|
||||
|
||||
" Creates checkbox on a list item if there is no one.
|
||||
function! s:TLI_create_checkbox(lnum) "{{{
|
||||
if a:lnum && !s:is_cb_list_item(a:lnum)
|
||||
if g:vimwiki_auto_checkbox
|
||||
call s:create_cb_list_item(a:lnum)
|
||||
endif
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
" Switch state of the child list items.
|
||||
function! s:TLI_switch_child_state(lnum) "{{{
|
||||
let current_state = s:get_state(a:lnum)
|
||||
if current_state == 100
|
||||
let new_state = 0
|
||||
else
|
||||
let new_state = 100
|
||||
endif
|
||||
for lnum in s:get_child_items(a:lnum)
|
||||
call s:set_state(lnum, new_state)
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
" Switch state of the parent list items.
|
||||
function! s:TLI_switch_parent_state(lnum) "{{{
|
||||
let c_lnum = a:lnum
|
||||
while s:is_cb_list_item(c_lnum)
|
||||
let parent_lnum = s:get_parent_item(c_lnum)
|
||||
if parent_lnum == c_lnum
|
||||
break
|
||||
endif
|
||||
call s:set_state(parent_lnum, s:all_siblings_checked(c_lnum))
|
||||
|
||||
let c_lnum = parent_lnum
|
||||
endwhile
|
||||
endfunction "}}}
|
||||
|
||||
function! s:TLI_toggle(lnum) "{{{
|
||||
if !s:TLI_create_checkbox(a:lnum)
|
||||
call s:TLI_switch_child_state(a:lnum)
|
||||
endif
|
||||
call s:TLI_switch_parent_state(a:lnum)
|
||||
endfunction "}}}
|
||||
|
||||
" Script functions }}}
|
||||
|
||||
" Toggle list item between [ ] and [X]
|
||||
function! vimwiki_lst#ToggleListItem(line1, line2) "{{{
|
||||
let line1 = a:line1
|
||||
let line2 = a:line2
|
||||
|
||||
if line1 != line2 && !s:is_list_item(line1)
|
||||
let line1 = s:find_next_list_item(line1)
|
||||
endif
|
||||
|
||||
let c_lnum = line1
|
||||
while c_lnum != 0 && c_lnum <= line2
|
||||
let li_lnum = s:is_list_item(c_lnum)
|
||||
|
||||
if li_lnum
|
||||
let li_level = s:get_level(li_lnum)
|
||||
if c_lnum == line1
|
||||
let start_li_level = li_level
|
||||
endif
|
||||
|
||||
if li_level <= start_li_level
|
||||
call s:TLI_toggle(li_lnum)
|
||||
let start_li_level = li_level
|
||||
endif
|
||||
endif
|
||||
|
||||
let c_lnum = s:find_next_list_item(c_lnum)
|
||||
endwhile
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_lst#insertCR() "{{{
|
||||
" This function is heavily relies on proper 'set comments' option.
|
||||
let cr = "\<CR>"
|
||||
if getline('.') =~ s:rx_cb_list_item()
|
||||
let cr .= '[ ] '
|
||||
endif
|
||||
return cr
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_lst#insertOo(cmd) "{{{
|
||||
" cmd should be 'o' or 'O'
|
||||
|
||||
let beg_lnum = foldclosed('.')
|
||||
let end_lnum = foldclosedend('.')
|
||||
if end_lnum != -1 && a:cmd ==# 'o'
|
||||
let lnum = end_lnum
|
||||
let line = getline(beg_lnum)
|
||||
else
|
||||
let line = getline('.')
|
||||
let lnum = line('.')
|
||||
endif
|
||||
|
||||
let res = ''
|
||||
if line =~ s:rx_cb_list_item()
|
||||
let res = matchstr(line, s:rx_list_item()).'[ ] '
|
||||
elseif line =~ s:rx_list_item()
|
||||
let res = matchstr(line, s:rx_list_item())
|
||||
elseif &autoindent || &smartindent
|
||||
let res = matchstr(line, '^\s*')
|
||||
endif
|
||||
if a:cmd ==# 'o'
|
||||
call append(lnum, res)
|
||||
call cursor(lnum + 1, col('$'))
|
||||
else
|
||||
call append(lnum - 1, res)
|
||||
call cursor(lnum, col('$'))
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
335
autoload/vimwiki_tbl.vim
Normal file
335
autoload/vimwiki_tbl.vim
Normal file
@@ -0,0 +1,335 @@
|
||||
" Vimwiki autoload plugin file
|
||||
" Desc: Tables
|
||||
" | Easily | manageable | text | tables | ! |
|
||||
" |--------+------------+-------+--------+---------|
|
||||
" | Have | fun! | Drink | tea | Period. |
|
||||
"
|
||||
" Author: Maxim Kim <habamax@gmail.com>
|
||||
" Home: http://code.google.com/p/vimwiki/
|
||||
|
||||
" Load only once {{{
|
||||
if exists("g:loaded_vimwiki_tbl_auto") || &cp
|
||||
finish
|
||||
endif
|
||||
let g:loaded_vimwiki_tbl_auto = 1
|
||||
"}}}
|
||||
|
||||
let s:textwidth = &tw
|
||||
|
||||
" Misc functions {{{
|
||||
function! s:wide_len(str) "{{{
|
||||
return strlen(substitute(a:str, '.', 'x', 'g'))
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_table(line) "{{{
|
||||
return a:line =~ '^\s*\%(|[^|]\+\)\+|\s*$' || s:is_separator(a:line)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_separator(line) "{{{
|
||||
return a:line =~ '^\s*|\s*-\+'
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_last_column(lnum, cnum) "{{{
|
||||
return strpart(getline(a:lnum), a:cnum - 1) =~ '^[^|]*|\s*$'
|
||||
endfunction "}}}
|
||||
|
||||
function! s:count_separators(lnum) "{{{
|
||||
let lnum = a:lnum + 1
|
||||
while lnum < line('$')
|
||||
if !s:is_separator(getline(lnum))
|
||||
break
|
||||
endif
|
||||
let lnum += 1
|
||||
endwhile
|
||||
|
||||
return (lnum-a:lnum)
|
||||
endfunction "}}}
|
||||
|
||||
function! s:create_empty_row(cols) "{{{
|
||||
let first_cell = "| |"
|
||||
let cell = " |"
|
||||
let row = first_cell
|
||||
|
||||
for c in range(a:cols - 1)
|
||||
let row .= cell
|
||||
endfor
|
||||
|
||||
return row
|
||||
endfunction "}}}
|
||||
|
||||
function! s:create_row_sep(cols) "{{{
|
||||
let first_cell = "|---+"
|
||||
let cell = "---+"
|
||||
let last_cell = "---|"
|
||||
|
||||
if a:cols < 2
|
||||
return "|---|"
|
||||
endif
|
||||
|
||||
let row = first_cell
|
||||
|
||||
for c in range(a:cols - 2)
|
||||
let row .= cell
|
||||
endfor
|
||||
|
||||
let row .= last_cell
|
||||
|
||||
return row
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_values(line) "{{{
|
||||
let cells = []
|
||||
let cnt = 0
|
||||
let idx = 0
|
||||
while idx != -1 && idx < strlen(a:line) - 1
|
||||
let cell = matchstr(a:line, '|\zs[^|]\+\ze|', idx)
|
||||
let cell = substitute(cell, '^\s*\(.\{-}\)\s*$', '\1', 'g')
|
||||
call add(cells, [cnt, cell])
|
||||
let cnt += 1
|
||||
let idx = matchend(a:line, '|\zs[^|]\+\ze|', idx)
|
||||
endwhile
|
||||
return cells
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_rows(lnum) "{{{
|
||||
if !s:is_table(getline(a:lnum))
|
||||
return
|
||||
endif
|
||||
|
||||
let upper_rows = []
|
||||
let lower_rows = []
|
||||
|
||||
let lnum = a:lnum - 1
|
||||
while lnum > 1
|
||||
let line = getline(lnum)
|
||||
if s:is_table(line)
|
||||
call add(upper_rows, [lnum, line])
|
||||
else
|
||||
break
|
||||
endif
|
||||
let lnum -= 1
|
||||
endwhile
|
||||
call reverse(upper_rows)
|
||||
|
||||
let lnum = a:lnum
|
||||
while lnum <= line('$')
|
||||
let line = getline(lnum)
|
||||
if s:is_table(line)
|
||||
call add(lower_rows, [lnum, line])
|
||||
else
|
||||
break
|
||||
endif
|
||||
let lnum += 1
|
||||
endwhile
|
||||
|
||||
return upper_rows + lower_rows
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_cell_max_lens(lnum) "{{{
|
||||
let max_lens = {}
|
||||
for [lnum, row] in s:get_rows(a:lnum)
|
||||
if s:is_separator(row)
|
||||
continue
|
||||
endif
|
||||
for [idx, cell] in s:get_values(row)
|
||||
if has_key(max_lens, idx)
|
||||
let max_lens[idx] = max([s:wide_len(cell), max_lens[idx]])
|
||||
else
|
||||
let max_lens[idx] = s:wide_len(cell)
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
return max_lens
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_aligned_rows(lnum, max_lens) "{{{
|
||||
let rows = []
|
||||
for [lnum, row] in s:get_rows(a:lnum)
|
||||
if s:is_separator(row)
|
||||
let new_row = s:fmt_sep(a:max_lens)
|
||||
else
|
||||
let new_row = s:fmt_row(row, a:max_lens)
|
||||
endif
|
||||
call add(rows, [lnum, new_row])
|
||||
endfor
|
||||
return rows
|
||||
endfunction "}}}
|
||||
" }}}
|
||||
|
||||
" Format functions {{{
|
||||
function! s:fmt_cell(cell, max_len) "{{{
|
||||
let cell = ' '.a:cell.' '
|
||||
|
||||
let diff = a:max_len - s:wide_len(a:cell)
|
||||
if diff == 0 && empty(a:cell)
|
||||
let diff = 1
|
||||
endif
|
||||
|
||||
let cell .= repeat(' ', diff)
|
||||
return cell
|
||||
endfunction "}}}
|
||||
|
||||
function! s:fmt_row(line, max_lens) "{{{
|
||||
let new_line = '|'
|
||||
let values = s:get_values(a:line)
|
||||
for [idx, cell] in values
|
||||
let new_line .= s:fmt_cell(cell, a:max_lens[idx]).'|'
|
||||
endfor
|
||||
|
||||
let idx = len(values)
|
||||
while idx < len(a:max_lens)
|
||||
let new_line .= s:fmt_cell('', a:max_lens[idx]).'|'
|
||||
let idx += 1
|
||||
endwhile
|
||||
return new_line
|
||||
endfunction "}}}
|
||||
|
||||
function! s:fmt_cell_sep(max_len) "{{{
|
||||
if a:max_len == 0
|
||||
return repeat('-', 3)
|
||||
else
|
||||
return repeat('-', a:max_len+2)
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:fmt_sep(max_lens) "{{{
|
||||
let sep = '|'
|
||||
for idx in range(len(a:max_lens))
|
||||
let sep .= s:fmt_cell_sep(a:max_lens[idx]).'+'
|
||||
endfor
|
||||
let sep = substitute(sep, '+$', '|', '')
|
||||
return sep
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" Keyboard functions "{{{
|
||||
function! s:kbd_create_new_row(cols, goto_first) "{{{
|
||||
let cmd = "\<ESC>o".s:create_empty_row(a:cols)
|
||||
let cmd .= "\<ESC>:call vimwiki_tbl#format(line('.'))\<CR>"
|
||||
if a:goto_first
|
||||
let cmd .= "0f|T|a"
|
||||
else
|
||||
let cmd .= "0".(col('.')-1)."lT|a"
|
||||
endif
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
|
||||
function! s:kbd_goto_next_row() "{{{
|
||||
let cmd = "\<ESC>jt|T|a"
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
|
||||
function! s:kbd_goto_next_col(last) "{{{
|
||||
if col('.') == 1
|
||||
let cmd = "\<ESC>la"
|
||||
else
|
||||
if a:last
|
||||
let seps = s:count_separators(line('.'))
|
||||
let cmd = "\<ESC>".seps."j0f|F|la"
|
||||
else
|
||||
let cmd = "\<ESC>f|la"
|
||||
endif
|
||||
endif
|
||||
return cmd
|
||||
endfunction "}}}
|
||||
|
||||
"}}}
|
||||
|
||||
" Global functions {{{
|
||||
function! vimwiki_tbl#kbd_cr() "{{{
|
||||
let lnum = line('.')
|
||||
if !s:is_table(getline(lnum))
|
||||
return "\<CR>"
|
||||
endif
|
||||
|
||||
if s:is_separator(getline(lnum+1)) || !s:is_table(getline(lnum+1))
|
||||
let cols = len(s:get_values(getline(lnum)))
|
||||
return s:kbd_create_new_row(cols, 0)
|
||||
else
|
||||
return s:kbd_goto_next_row()
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#kbd_tab() "{{{
|
||||
let lnum = line('.')
|
||||
if !s:is_table(getline(lnum))
|
||||
return "\<Tab>"
|
||||
endif
|
||||
|
||||
let last = s:is_last_column(lnum, col('.'))
|
||||
if last && !s:is_table(getline(lnum+1))
|
||||
let cols = len(s:get_values(getline(lnum)))
|
||||
return s:kbd_create_new_row(cols, 1)
|
||||
endif
|
||||
return s:kbd_goto_next_col(last)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#format(lnum) "{{{
|
||||
let line = getline(a:lnum)
|
||||
if !s:is_table(line)
|
||||
return
|
||||
endif
|
||||
|
||||
let max_lens = s:get_cell_max_lens(a:lnum)
|
||||
|
||||
for [lnum, row] in s:get_aligned_rows(a:lnum, max_lens)
|
||||
call setline(lnum, row)
|
||||
endfor
|
||||
|
||||
let &tw = s:textwidth
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#create(...) "{{{
|
||||
if a:0 > 1
|
||||
let cols = a:1
|
||||
let rows = a:2
|
||||
elseif a:0 == 1
|
||||
let cols = a:1
|
||||
let rows = 2
|
||||
elseif a:0 == 0
|
||||
let cols = 5
|
||||
let rows = 2
|
||||
endif
|
||||
|
||||
if cols < 1
|
||||
let cols = 5
|
||||
endif
|
||||
|
||||
if rows < 1
|
||||
let rows = 2
|
||||
endif
|
||||
|
||||
let lines = []
|
||||
let row = s:create_empty_row(cols)
|
||||
|
||||
call add(lines, row)
|
||||
if rows > 1
|
||||
call add(lines, s:create_row_sep(cols))
|
||||
endif
|
||||
|
||||
for r in range(rows - 1)
|
||||
call add(lines, row)
|
||||
endfor
|
||||
|
||||
call append(line('.'), lines)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#align_or_cmd(cmd) "{{{
|
||||
if s:is_table(getline('.'))
|
||||
call vimwiki_tbl#format(line('.'))
|
||||
else
|
||||
exe 'normal! '.a:cmd
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#reset_tw(lnum) "{{{
|
||||
let line = getline(a:lnum)
|
||||
if !s:is_table(line)
|
||||
return
|
||||
endif
|
||||
|
||||
let s:textwidth = &tw
|
||||
let &tw = 0
|
||||
endfunction "}}}
|
||||
|
||||
"}}}
|
||||
99
autoload/vst/default.css
Normal file
99
autoload/vst/default.css
Normal file
@@ -0,0 +1,99 @@
|
||||
body { color: #000; background-color: #fff; margin: 0px 10%; min-width: 720px; font-family: Verdana, sans-serif;
|
||||
counter-reset: chapter section subsection subsubsection paragraph lchapter lsection lsubsection lsubsubsection lparagraph}
|
||||
div.footnote { border-left: 1px solid #000; margin-left: 0em; clear: both }
|
||||
div.ftext { position: relative; margin-left: 50px }
|
||||
div.fnumber { float: left; width: 40px; padding: 0em; margin-left: 0.5em; margin-top: 0em }
|
||||
div.fnumber a { margin: 0px; padding: 0px }
|
||||
div.ctext { position: relative; margin-left: 100px }
|
||||
div.cnumber { float: left; width: 90px; padding: 0em; margin-left: 0.5em; margin-top: 0em }
|
||||
div.cnumber a { margin: 0px; padding: 0px }
|
||||
div.tip { border: 2px solid #0d0; margin: 0.5em 2em 1em 2em; padding: 0em 1em }
|
||||
div.warning, div.caution, div.danger, div.error { border: 2px solid #f00; margin: 0.5em 2em 1em 2em; padding: 0em 1em }
|
||||
div.note, div.hint, div.important { border: 2px solid #000; margin: 0.5em 2em 1em 2em; padding: 0em 1em }
|
||||
div.figure { display: block; padding: 1em; width: 400px; clear: both}
|
||||
div.topic { margin: 2em }
|
||||
div.vstsidebar, div.sidebar { border: 2px solid #aaa; color: #000; background-color: #ffffee; float: right; width: 40%; margin-left: 1em; margin-right: -1em; padding: 1em }
|
||||
span.strike { text-decoration: line-through }
|
||||
span.big { font-size: large }
|
||||
span.small { font-size: small }
|
||||
span.title { font-style: italic }
|
||||
span.notetitle { font-size: large; font-weight: 900; font-family: Verdana, sans-serif }
|
||||
p.toc { font-size: large; font-weight: 900 }
|
||||
p.notesubtitle { font-weight: 900; font-family: Verdana, sans-serif }
|
||||
p.attribution { font-style: italic; margin-left: 8em; text-indent: -1.4em }
|
||||
.vstright { float: right; margin: 1em }
|
||||
.vstleft { float: left; margin: 1em }
|
||||
.vstcenter { margin: 1em auto }
|
||||
blockquote.pull { font-size: large }
|
||||
p.rubric { font-size: large; margin-left: 2em }
|
||||
dd.normal { margin-bottom: 0.5em }
|
||||
dt.option { float: left; margin: 0em 0em 5px 2em; padding: 0px; font-family: monospace }
|
||||
dd.option { padding: 0px; margin: 0em 0em 5px 10em; text-indent: 0.5em }
|
||||
dd.option > p { margin: 0px }
|
||||
dd.normal > p { margin: 0px }
|
||||
table { border-collapse: collapse; margin: 0.5em 0em }
|
||||
thead, tfoot { text-align: center; font-weight: bold }
|
||||
td { border: 1px solid #000; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
td blockquote p{ margin: 0px; padding: 0px}
|
||||
td blockquote { margin: 0px; padding: 0px}
|
||||
table.vstbless td { border: 0px solid #000; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
td > p { margin: 0px }
|
||||
table.field { border: 0px solid #000; margin-left: 2em; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
td.fkey { font-weight: 900 }
|
||||
td.fval { border: 0px solid #000; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
td.fkey { font-weight: 900; border: 0px solid #000; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
td.fdkey { text-align: center; font-weight: 900 }
|
||||
td.fdval { text-align: center; font-style: italic }
|
||||
td.fakey { text-align: center; font-weight: 900 }
|
||||
td.faval { border: 0px solid #000; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
hr { width: 80%; margin: 1.5em auto }
|
||||
h1 { text-align: center; clear: both }
|
||||
h2, h3, h4, h5, h6 { text-align: left; margin-top: 1em; clear: both }
|
||||
h2 { counter-reset: section subsection subsubsection paragraph }
|
||||
h3 { counter-reset: subsection subsubsection paragraph }
|
||||
h4 { counter-reset: subsubsection paragraph }
|
||||
h5 { counter-reset: paragraph }
|
||||
h1 a { color: #000; background-color: transparent }
|
||||
h2 a { color: #000; background-color: transparent }
|
||||
h3 a { color: #000; background-color: transparent }
|
||||
h4 a { color: #000; background-color: transparent }
|
||||
h5 a { color: #000; background-color: transparent }
|
||||
h6 a { color: #000; background-color: transparent }
|
||||
p.subh1 { text-align: center; font-size: 120%; font-variant: small-caps }
|
||||
p.subh2, p.subh3, p.subh4, p.subh5, p.subh6 { text-align: left; font-size: 120%; font-variant: small-caps }
|
||||
h2:before { content: counter(chapter)" "; counter-increment: chapter }
|
||||
h3:before { content: counter(chapter)"."counter(section)" "; counter-increment: section }
|
||||
h4:before { content: counter(chapter)"."counter(section)"."counter(subsection)" "; counter-increment: subsection }
|
||||
h5:before { content: counter(chapter)"."counter(section)"."counter(subsection)"."counter(subsubsection)" "; counter-increment: subsubsection }
|
||||
h6:before { content: counter(chapter)"."counter(section)"."counter(subsection)"."counter(subsubsection)"."counter(paragraph)" "; counter-increment: paragraph}
|
||||
li.h1 { margin-left: 0em }
|
||||
li.h2 { margin-left: 1em; counter-reset: lsection lsubsection lsubsubsection lparagraph }
|
||||
li.h3 { margin-left: 2em; counter-reset: lsubsection lsubsubsection lparagraph }
|
||||
li.h4 { margin-left: 3em; counter-reset: lsubsubsection lparagraph }
|
||||
li.h5 { margin-left: 4em; counter-reset: lparagraph }
|
||||
li.h2:before { content: counter(lchapter)" "; counter-increment: lchapter }
|
||||
li.h3:before { content: counter(lchapter)"."counter(lsection)" "; counter-increment: lsection }
|
||||
li.h4:before { content: counter(lchapter)"."counter(lsection)"."counter(lsubsection)" "; counter-increment: lsubsection }
|
||||
li.h5:before { content: counter(lchapter)"."counter(lsection)"."counter(lsubsection)"."counter(lsubsubsection)" "; counter-increment: lsubsubsection }
|
||||
li.h6:before { content: counter(lchapter)"."counter(lsection)"."counter(lsubsection)"."counter(lsubsubsection)"."counter(lparagraph)" "; counter-increment: lparagraph}
|
||||
li.h6 { margin-left: 5em }
|
||||
ol, ul { margin-bottom: 0.5em; margin-top: 0.5em }
|
||||
ol.loweralpha { list-style-type: lower-alpha }
|
||||
ol.upperalpha { list-style-type: upper-alpha }
|
||||
ol.lowerroman { list-style-type: lower-roman }
|
||||
ol.upperroman { list-style-type: upper-roman }
|
||||
ol.decimal { list-style-type: decimal }
|
||||
ul.square { list-style-type: square }
|
||||
ul.circle { list-style-type: circle }
|
||||
ul.disc { list-style-type: disc }
|
||||
li > p { margin: 0em }
|
||||
img { border: 1px solid #000; padding: 0em; display: block; margin: 1em auto }
|
||||
img.inline { border: 1px solid #000; padding: 0em; margin: 0em; display: inline }
|
||||
pre { color: #000; background-color: #eee; margin-left: 2em; clear: both; overflow: auto }
|
||||
div.unknown { font-family: monospace; color: #000; background-color: #fff; margin: 1em; padding: 1em; clear: both; border: 3px solid red}
|
||||
pre.quoted { color: #000; background-color: #eee; margin-left: 0em; clear: both; overflow: auto }
|
||||
pre.rawlatex { color: #000; background-color: #ddd; border: 1px solid #000; padding: 0.1em; clear: both; overflow: auto }
|
||||
pre.address { font-family: Verdana, sans-serif; display: inline; margin: 0px; color: #000; background-color: #fff; overflow: auto }
|
||||
span.target { text-decoration: underline }
|
||||
div.vstfooter hr { width: 100%; margin: 0px }
|
||||
div.vstfooter p { margin: 0px }
|
||||
110
autoload/vst/lightblue.css
Normal file
110
autoload/vst/lightblue.css
Normal file
@@ -0,0 +1,110 @@
|
||||
/* Vim reStructured Text CSS */
|
||||
|
||||
body { background-color: #fff; margin: 0px 10%; width: 45em; font-family: Georgia, serif;}
|
||||
div.footnote { border-left: 1px solid silver; margin-left: 0em; clear: both }
|
||||
div.ftext { position: relative; margin-left: 50px }
|
||||
div.fnumber { float: left; width: 40px; padding: 0em; margin-left: 0.5em; margin-top: 0em }
|
||||
div.fnumber a { margin: 0px; padding: 0px }
|
||||
div.ctext { position: relative; margin-left: 100px }
|
||||
div.cnumber { float: left; width: 90px; padding: 0em; margin-left: 0.5em; margin-top: 0em }
|
||||
div.cnumber a { margin: 0px; padding: 0px }
|
||||
div.tip { border: 2px solid #0d0; margin: 0.5em 2em 1em 2em; padding: 0em 1em }
|
||||
div.warning, div.caution, div.danger, div.error { border: 2px solid #f00; margin: 0.5em 2em 1em 2em; padding: 0em 1em }
|
||||
div.note, div.hint, div.important { border: 2px solid silver; margin: 0.5em 2em 1em 2em; padding: 0em 1em }
|
||||
div.figure { display: block; padding: 1em; width: 400px; clear: both}
|
||||
div.topic { margin: 2em }
|
||||
div.vstsidebar, div.sidebar { border: 2px solid #aaa; background-color: #ffffee; float: right; width: 40%; margin-left: 1em; margin-right: -1em; padding: 1em }
|
||||
span.strike { text-decoration: line-through }
|
||||
span.big { font-size: large }
|
||||
span.small { font-size: small }
|
||||
span.title { font-style: italic }
|
||||
span.toc { font-size: large; font-weight: 900 }
|
||||
span.notetitle { font-size: large; font-weight: 900; font-family: Arial, sans-serif }
|
||||
p.notesubtitle { font-weight: 900; font-family: Arial, sans-serif }
|
||||
p.attribution { font-style: italic; margin-left: 8em; text-indent: -1.4em }
|
||||
.vstright { float: right; margin: 1em }
|
||||
.vstleft { float: left; margin: 1em }
|
||||
.vstcenter { margin: 1em; margin-left: auto; margin-right: auto }
|
||||
blockquote.pull { font-size: large }
|
||||
p.rubric { font-size: large; margin-left: 2em }
|
||||
dd.normal { margin-bottom: 0.5em }
|
||||
dt.option { float: left; margin: 0em 0em 5px 2em; padding: 0px; font-family: monospace }
|
||||
dd.option { margin: 0px; padding: 0px; margin: 0em 0em 5px 10em; text-indent: 0.5em }
|
||||
dd.option > p { margin: 0px }
|
||||
dd.normal > p { margin: 0px }
|
||||
table { border-collapse: collapse; border-top: 1px solid navy; border-bottom: 1px solid navy; margin: 0.5em; margin-left: 0em; margin-right: 0em }
|
||||
thead, tfoot { text-align: center; font-weight: bold }
|
||||
thead { font-family: Arial, sans-serif; border-bottom: 1px solid silver; }
|
||||
td { border: 0px solid #000; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
td blockquote p{ margin: 0px; padding: 0px}
|
||||
td blockquote { margin: 0px; padding: 0px}
|
||||
table.vstbless { border: 0px solid #000; }
|
||||
table.vstbless thead { border: 0px solid #000; }
|
||||
table.vstbless td { border: 0px solid #000; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
td > p { margin: 0px }
|
||||
table.field { border: 0px solid #000; margin-left: 2em; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
td.fkey { font-weight: 900 }
|
||||
td.fval { border: 0px solid #000; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
td.fkey { font-weight: 900; border: 0px solid #000; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
td.fdkey { text-align: center; font-weight: 900 }
|
||||
td.fdval { text-align: center; font-style: italic }
|
||||
td.fakey { text-align: center; font-weight: 900 }
|
||||
td.faval { border: 0px solid #000; padding: 0.25em; _top: 0%; vertical-align: top }
|
||||
hr { width: 80%; margin: 1.5em auto; border: 1px solid silver }
|
||||
h1 { border-bottom: 2px solid silver; text-align: center; clear: both }
|
||||
h2, h3, h4, h5, h6 { text-align: left; margin-top: 1em; clear: both; padding-top: 0.5em;}
|
||||
h2, h3 { border-bottom: 1px solid silver; }
|
||||
h1 a { color: dodgerblue4 }
|
||||
h2 a { color: dodgerblue4 }
|
||||
h3 a { color: dodgerblue4 }
|
||||
h4 a { color: dodgerblue4 }
|
||||
h5 a { color: dodgerblue4 }
|
||||
h6 a { color: dodgerblue4 }
|
||||
p.subh1 { text-align: center; font-size: 120%; font-variant: small-caps }
|
||||
p.subh2, p.subh3, p.subh4, p.subh5, p.subh6 { text-align: left; font-size: 120%; font-variant: small-caps }
|
||||
li.h1 { margin-left: 0em }
|
||||
li.h2 { margin-left: 1em;}
|
||||
li.h3 { margin-left: 2em;}
|
||||
li.h4 { margin-left: 3em;}
|
||||
li.h5 { margin-left: 4em;}
|
||||
li.h6 { margin-left: 5em }
|
||||
ol, ul { margin-bottom: 0.5em; margin-top: 0.5em }
|
||||
ol.loweralpha { list-style-type: lower-alpha }
|
||||
ol.upperalpha { list-style-type: upper-alpha }
|
||||
ol.lowerroman { list-style-type: lower-roman }
|
||||
ol.upperroman { list-style-type: upper-roman }
|
||||
ol.decimal { list-style-type: decimal }
|
||||
ul.square { list-style-type: square }
|
||||
ul.circle { list-style-type: circle }
|
||||
ul.disc { list-style-type: disc }
|
||||
li > p { margin: 0em }
|
||||
img { border: 1px solid #000; padding: 0em; display: block; margin: 1em; margin-left: auto; margin-right: auto }
|
||||
img.inline { border: 1px solid #000; padding: 0em; margin: 0em; display: inline }
|
||||
pre { background-color: #f9f9f9; margin-left: 2em; clear: both; overflow: auto }
|
||||
div.unknown { font-family: monospace; background-color: #fff; margin: 1em; padding: 1em; clear: both; border: 3px solid red}
|
||||
pre.quoted { background-color: #eee; margin-left: 0em; clear: both; overflow: auto }
|
||||
pre.rawlatex { background-color: #ddd; border: 1px solid #000; padding: 0.1em; clear: both; overflow: auto }
|
||||
pre.address { font-family: Georgia, serif; display: inline; margin: 0px; background-color: #fff; overflow: auto }
|
||||
span.target { text-decoration: underline }
|
||||
div.vstfooter hr { width: 100%; margin: 0px; margin-top: 0em }
|
||||
div.vstfooter p { margin: 0px }
|
||||
|
||||
/* Debug borders */
|
||||
p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
|
||||
/*
|
||||
border: 1px solid red;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
a { color: dodgerblue4; }
|
||||
a:visited { color: fuchsia; }
|
||||
tt { color: dodgerblue4; }
|
||||
|
||||
h1, h2, h3, h4, h5, h6 {
|
||||
color: dodgerblue4;
|
||||
font-family: Arial, sans-serif;
|
||||
margin-top: 1.2em;
|
||||
margin-bottom: 0.5em;
|
||||
line-height: 1.3;
|
||||
}
|
||||
18
autoload/vst/myhtmlvst.vim
Normal file
18
autoload/vst/myhtmlvst.vim
Normal file
@@ -0,0 +1,18 @@
|
||||
" Author: Mikolaj Machowski
|
||||
" Example of macro for g:vst_html_post file
|
||||
call cursor(1,1)
|
||||
while search('^\s*{read\w\{-}:.\{-}}\s*$', 'W')
|
||||
let data = matchlist(getline('.'), '^\s*{read\(\w\{-}\):\(.\{-}\)}\s*$')
|
||||
silent s/.*//ge
|
||||
if data[1] == ''
|
||||
let output = readfile(data[2])
|
||||
else
|
||||
if data[1] == 'bang'
|
||||
let data[1] = ''
|
||||
endif
|
||||
let output = split(system(data[1].' '.data[2]), "\n")
|
||||
endif
|
||||
call map(output, "' '.v:val")
|
||||
let jout = "<pre>\n".join(output, "\n")."\n</pre>"
|
||||
put =jout
|
||||
endwhile
|
||||
BIN
autoload/vst/s5ui/blank.gif
Normal file
BIN
autoload/vst/s5ui/blank.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 49 B |
23
autoload/vst/s5ui/framing.css
Normal file
23
autoload/vst/s5ui/framing.css
Normal file
@@ -0,0 +1,23 @@
|
||||
/* The following styles size, place, and layer the slide components.
|
||||
Edit these if you want to change the overall slide layout.
|
||||
The commented lines can be uncommented (and modified, if necessary)
|
||||
to help you with the rearrangement process. */
|
||||
|
||||
/* target = 1024x768 */
|
||||
|
||||
div#header, div#footer, .slide {width: 100%; top: 0; left: 0;}
|
||||
div#header {top: 0; height: 3em; z-index: 1;}
|
||||
div#footer {top: auto; bottom: 0; height: 2.5em; z-index: 5;}
|
||||
.slide {top: 0; width: 92%; padding: 3.5em 4% 4%; z-index: 2; list-style: none;}
|
||||
div#controls {left: 50%; bottom: 0; width: 50%; z-index: 100;}
|
||||
div#controls form {position: absolute; bottom: 0; right: 0; width: 100%;
|
||||
margin: 0;}
|
||||
#currentSlide {position: absolute; width: 10%; left: 45%; bottom: 1em; z-index: 10;}
|
||||
html>body #currentSlide {position: fixed;}
|
||||
|
||||
/*
|
||||
div#header {background: #FCC;}
|
||||
div#footer {background: #CCF;}
|
||||
div#controls {background: #BBD;}
|
||||
div#currentSlide {background: #FFC;}
|
||||
*/
|
||||
42
autoload/vst/s5ui/iepngfix.htc
Normal file
42
autoload/vst/s5ui/iepngfix.htc
Normal file
@@ -0,0 +1,42 @@
|
||||
<public:component>
|
||||
<public:attach event="onpropertychange" onevent="doFix()" />
|
||||
|
||||
<script>
|
||||
|
||||
// IE5.5+ PNG Alpha Fix v1.0 by Angus Turnbull http://www.twinhelix.com
|
||||
// Free usage permitted as long as this notice remains intact.
|
||||
|
||||
// This must be a path to a blank image. That's all the configuration you need here.
|
||||
var blankImg = 'v11rc1/default/blank.gif';
|
||||
|
||||
var f = 'DXImageTransform.Microsoft.AlphaImageLoader';
|
||||
|
||||
function filt(s, m) {
|
||||
if (filters[f]) {
|
||||
filters[f].enabled = s ? true : false;
|
||||
if (s) with (filters[f]) { src = s; sizingMethod = m }
|
||||
} else if (s) style.filter = 'progid:'+f+'(src="'+s+'",sizingMethod="'+m+'")';
|
||||
}
|
||||
|
||||
function doFix() {
|
||||
if ((parseFloat(navigator.userAgent.match(/MSIE (\S+)/)[1]) < 5.5) ||
|
||||
(event && !/(background|src)/.test(event.propertyName))) return;
|
||||
|
||||
if (tagName == 'IMG') {
|
||||
if ((/\.png$/i).test(src)) {
|
||||
filt(src, 'image'); // was 'scale'
|
||||
src = blankImg;
|
||||
} else if (src.indexOf(blankImg) < 0) filt();
|
||||
} else if (style.backgroundImage) {
|
||||
if (style.backgroundImage.match(/^url[("']+(.*\.png)[)"']+$/i)) {
|
||||
var s = RegExp.$1;
|
||||
style.backgroundImage = '';
|
||||
filt(s, 'crop');
|
||||
} else filt();
|
||||
}
|
||||
}
|
||||
|
||||
doFix();
|
||||
|
||||
</script>
|
||||
</public:component>
|
||||
7
autoload/vst/s5ui/opera.css
Normal file
7
autoload/vst/s5ui/opera.css
Normal file
@@ -0,0 +1,7 @@
|
||||
/* DO NOT CHANGE THESE unless you really want to break Opera Show */
|
||||
.slide {
|
||||
visibility: visible !important;
|
||||
position: static !important;
|
||||
page-break-before: always;
|
||||
}
|
||||
#slide0 {page-break-before: avoid;}
|
||||
15
autoload/vst/s5ui/outline.css
Normal file
15
autoload/vst/s5ui/outline.css
Normal file
@@ -0,0 +1,15 @@
|
||||
/* don't change this unless you want the layout stuff to show up in the outline view! */
|
||||
|
||||
.layout div, #footer *, #controlForm * {display: none;}
|
||||
#footer, #controls, #controlForm, #navLinks, #toggle {
|
||||
display: block; visibility: visible; margin: 0; padding: 0;}
|
||||
#toggle {float: right; padding: 0.5em;}
|
||||
html>body #toggle {position: fixed; top: 0; right: 0;}
|
||||
|
||||
/* making the outline look pretty-ish */
|
||||
|
||||
#slide0 h1, #slide0 h2, #slide0 h3, #slide0 h4 {border: none; margin: 0;}
|
||||
#slide0 h1 {padding-top: 1.5em;}
|
||||
.slide h1 {margin: 1.5em 0 0; padding-top: 0.25em;
|
||||
border-top: 1px solid #888; border-bottom: 1px solid #AAA;}
|
||||
#toggle {border: 1px solid; border-width: 0 0 1px 1px; background: #FFF;}
|
||||
86
autoload/vst/s5ui/pretty.css
Normal file
86
autoload/vst/s5ui/pretty.css
Normal file
@@ -0,0 +1,86 @@
|
||||
/* Following are the presentation styles -- edit away! */
|
||||
|
||||
body {background: #FFF url(bodybg.gif) -16px 0 no-repeat; color: #000; font-size: 2em;}
|
||||
:link, :visited {text-decoration: none; color: #00C;}
|
||||
#controls :active {color: #88A !important;}
|
||||
#controls :focus {outline: 1px dotted #227;}
|
||||
h1, h2, h3, h4 {font-size: 100%; margin: 0; padding: 0; font-weight: inherit;}
|
||||
ul, pre {margin: 0; line-height: 1em;}
|
||||
html, body {margin: 0; padding: 0;}
|
||||
|
||||
blockquote, q {font-style: italic;}
|
||||
blockquote {padding: 0 2em 0.5em; margin: 0 1.5em 0.5em; text-align: center; font-size: 1em;}
|
||||
blockquote p {margin: 0;}
|
||||
blockquote i {font-style: normal;}
|
||||
blockquote b {display: block; margin-top: 0.5em; font-weight: normal; font-size: smaller; font-style: normal;}
|
||||
blockquote b i {font-style: italic;}
|
||||
|
||||
kbd {font-weight: bold; font-size: 1em;}
|
||||
sup {font-size: smaller; line-height: 1px;}
|
||||
|
||||
.slide code {padding: 2px 0.25em; font-weight: bold; color: #533;}
|
||||
.slide code.bad, code del {color: red;}
|
||||
.slide code.old {color: silver;}
|
||||
.slide pre {padding: 0; margin: 0.25em 0 0.5em 0.5em; color: #533; font-size: 90%;}
|
||||
.slide pre code {display: block;}
|
||||
.slide ul {margin-left: 5%; margin-right: 7%; list-style: disc;}
|
||||
.slide li {margin-top: 0.75em; margin-right: 0;}
|
||||
.slide ul ul {line-height: 1;}
|
||||
.slide ul ul li {margin: .2em; font-size: 85%; list-style: square;}
|
||||
.slide img.leader {display: block; margin: 0 auto;}
|
||||
|
||||
div#header, div#footer {background: #005; color: #AAB;
|
||||
font-family: Verdana, Helvetica, sans-serif;}
|
||||
div#header {background: #005 url(bodybg.gif) -16px 0 no-repeat;
|
||||
line-height: 1px;}
|
||||
div#footer {font-size: 0.5em; font-weight: bold; padding: 1em 0;}
|
||||
#footer h1, #footer h2 {display: block; padding: 0 1em;}
|
||||
#footer h2 {font-style: italic;}
|
||||
|
||||
div.long {font-size: 0.75em;}
|
||||
.slide h1 {position: absolute; top: 0.7em; left: 87px; z-index: 1;
|
||||
margin: 0; padding: 0.3em 0 0 50px; white-space: nowrap;
|
||||
font: bold 150%/1em Helvetica, sans-serif; text-transform: capitalize;
|
||||
color: #DDE; background: #005;}
|
||||
.slide h3 {font-size: 130%;}
|
||||
h1 abbr {font-variant: small-caps;}
|
||||
|
||||
div#controls {position: absolute; left: 50%; bottom: 0;
|
||||
width: 50%;
|
||||
text-align: right; font: bold 0.9em Verdana, Helvetica, sans-serif;}
|
||||
html>body div#controls {position: fixed; padding: 0 0 1em 0;
|
||||
top: auto;}
|
||||
div#controls form {position: absolute; bottom: 0; right: 0; width: 100%;
|
||||
margin: 0; padding: 0;}
|
||||
#controls #navLinks a {padding: 0; margin: 0 0.5em;
|
||||
background: #005; border: none; color: #779;
|
||||
cursor: pointer;}
|
||||
#controls #navList {height: 1em;}
|
||||
#controls #navList #jumplist {position: absolute; bottom: 0; right: 0; background: #DDD; color: #227;}
|
||||
|
||||
#currentSlide {text-align: center; font-size: 0.5em; color: #449;}
|
||||
|
||||
#slide0 {padding-top: 3.5em; font-size: 90%;}
|
||||
#slide0 h1 {position: static; margin: 1em 0 0; padding: 0;
|
||||
font: bold 2em Helvetica, sans-serif; white-space: normal;
|
||||
color: #000; background: transparent;}
|
||||
#slide0 h2 {font: bold italic 1em Helvetica, sans-serif; margin: 0.25em;}
|
||||
#slide0 h3 {margin-top: 1.5em; font-size: 1.5em;}
|
||||
#slide0 h4 {margin-top: 0; font-size: 1em;}
|
||||
|
||||
ul.urls {list-style: none; display: inline; margin: 0;}
|
||||
.urls li {display: inline; margin: 0;}
|
||||
.note {display: none;}
|
||||
.external {border-bottom: 1px dotted gray;}
|
||||
html>body .external {border-bottom: none;}
|
||||
.external:after {content: " \274F"; font-size: smaller; color: #77B;}
|
||||
|
||||
.incremental, .incremental *, .incremental *:after {color: #DDE; visibility: visible;}
|
||||
img.incremental {visibility: hidden;}
|
||||
.slide .current {color: #B02;}
|
||||
|
||||
|
||||
/* diagnostics
|
||||
|
||||
li:after {content: " [" attr(class) "]"; color: #F88;}
|
||||
*/
|
||||
1
autoload/vst/s5ui/print.css
Normal file
1
autoload/vst/s5ui/print.css
Normal file
@@ -0,0 +1 @@
|
||||
/* The following rule is necessary to have all slides appear in print! DO NOT REMOVE IT! */
|
||||
9
autoload/vst/s5ui/s5-core.css
Normal file
9
autoload/vst/s5ui/s5-core.css
Normal file
@@ -0,0 +1,9 @@
|
||||
/* Do not edit or override these styles! The system will likely break if you do. */
|
||||
|
||||
div#header, div#footer, div#controls, .slide {position: absolute;}
|
||||
html>body div#header, html>body div#footer,
|
||||
html>body div#controls, html>body .slide {position: fixed;}
|
||||
.handout {display: none;}
|
||||
.layout {display: block;}
|
||||
.slide, .hideme, .incremental {visibility: hidden;}
|
||||
#slide0 {visibility: visible;}
|
||||
3
autoload/vst/s5ui/slides.css
Normal file
3
autoload/vst/s5ui/slides.css
Normal file
@@ -0,0 +1,3 @@
|
||||
@import url(s5-core.css); /* required to make the slide show run at all */
|
||||
@import url(framing.css); /* sets basic placement and size of slide components */
|
||||
@import url(pretty.css); /* stuff that makes the slides look better than blah */
|
||||
552
autoload/vst/s5ui/slides.js
Normal file
552
autoload/vst/s5ui/slides.js
Normal file
@@ -0,0 +1,552 @@
|
||||
// S5 v1.1 slides.js -- released into the Public Domain
|
||||
//
|
||||
// Please see http://www.meyerweb.com/eric/tools/s5/credits.html for information
|
||||
// about all the wonderful and talented contributors to this code!
|
||||
|
||||
var undef;
|
||||
var slideCSS = '';
|
||||
var snum = 0;
|
||||
var smax = 1;
|
||||
var incpos = 0;
|
||||
var number = undef;
|
||||
var s5mode = true;
|
||||
var defaultView = 'slideshow';
|
||||
var controlVis = 'visible';
|
||||
|
||||
var isIE = navigator.appName == 'Microsoft Internet Explorer' ? 1 : 0;
|
||||
var isOp = navigator.userAgent.indexOf('Opera') > -1 ? 1 : 0;
|
||||
var isGe = navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('Safari') < 1 ? 1 : 0;
|
||||
|
||||
function hasClass(object, className) {
|
||||
if (!object.className) return false;
|
||||
return (object.className.search('(^|\\s)' + className + '(\\s|$)') != -1);
|
||||
}
|
||||
|
||||
function hasValue(object, value) {
|
||||
if (!object) return false;
|
||||
return (object.search('(^|\\s)' + value + '(\\s|$)') != -1);
|
||||
}
|
||||
|
||||
function removeClass(object,className) {
|
||||
if (!object) return;
|
||||
object.className = object.className.replace(new RegExp('(^|\\s)'+className+'(\\s|$)'), RegExp.$1+RegExp.$2);
|
||||
}
|
||||
|
||||
function addClass(object,className) {
|
||||
if (!object || hasClass(object, className)) return;
|
||||
if (object.className) {
|
||||
object.className += ' '+className;
|
||||
} else {
|
||||
object.className = className;
|
||||
}
|
||||
}
|
||||
|
||||
function GetElementsWithClassName(elementName,className) {
|
||||
var allElements = document.getElementsByTagName(elementName);
|
||||
var elemColl = new Array();
|
||||
for (var i = 0; i< allElements.length; i++) {
|
||||
if (hasClass(allElements[i], className)) {
|
||||
elemColl[elemColl.length] = allElements[i];
|
||||
}
|
||||
}
|
||||
return elemColl;
|
||||
}
|
||||
|
||||
function isParentOrSelf(element, id) {
|
||||
if (element == null || element.nodeName=='BODY') return false;
|
||||
else if (element.id == id) return true;
|
||||
else return isParentOrSelf(element.parentNode, id);
|
||||
}
|
||||
|
||||
function nodeValue(node) {
|
||||
var result = "";
|
||||
if (node.nodeType == 1) {
|
||||
var children = node.childNodes;
|
||||
for (var i = 0; i < children.length; ++i) {
|
||||
result += nodeValue(children[i]);
|
||||
}
|
||||
}
|
||||
else if (node.nodeType == 3) {
|
||||
result = node.nodeValue;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
function slideLabel() {
|
||||
var slideColl = GetElementsWithClassName('*','slide');
|
||||
var list = document.getElementById('jumplist');
|
||||
smax = slideColl.length;
|
||||
for (var n = 0; n < smax; n++) {
|
||||
var obj = slideColl[n];
|
||||
|
||||
var did = 'slide' + n.toString();
|
||||
obj.setAttribute('id',did);
|
||||
if (isOp) continue;
|
||||
|
||||
var otext = '';
|
||||
var menu = obj.firstChild;
|
||||
if (!menu) continue; // to cope with empty slides
|
||||
while (menu && menu.nodeType == 3) {
|
||||
menu = menu.nextSibling;
|
||||
}
|
||||
if (!menu) continue; // to cope with slides with only text nodes
|
||||
|
||||
var menunodes = menu.childNodes;
|
||||
for (var o = 0; o < menunodes.length; o++) {
|
||||
otext += nodeValue(menunodes[o]);
|
||||
}
|
||||
list.options[list.length] = new Option(n + ' : ' + otext, n);
|
||||
}
|
||||
}
|
||||
|
||||
function currentSlide() {
|
||||
var cs;
|
||||
if (document.getElementById) {
|
||||
cs = document.getElementById('currentSlide');
|
||||
} else {
|
||||
cs = document.currentSlide;
|
||||
}
|
||||
cs.innerHTML = '<span id="csHere">' + snum + '<\/span> ' +
|
||||
'<span id="csSep">\/<\/span> ' +
|
||||
'<span id="csTotal">' + (smax-1) + '<\/span>';
|
||||
if (snum == 0) {
|
||||
cs.style.visibility = 'hidden';
|
||||
} else {
|
||||
cs.style.visibility = 'visible';
|
||||
}
|
||||
}
|
||||
|
||||
function go(step) {
|
||||
if (document.getElementById('slideProj').disabled || step == 0) return;
|
||||
var jl = document.getElementById('jumplist');
|
||||
var cid = 'slide' + snum;
|
||||
var ce = document.getElementById(cid);
|
||||
if (incrementals[snum].length > 0) {
|
||||
for (var i = 0; i < incrementals[snum].length; i++) {
|
||||
removeClass(incrementals[snum][i], 'current');
|
||||
removeClass(incrementals[snum][i], 'incremental');
|
||||
}
|
||||
}
|
||||
if (step != 'j') {
|
||||
snum += step;
|
||||
lmax = smax - 1;
|
||||
if (snum > lmax) snum = lmax;
|
||||
if (snum < 0) snum = 0;
|
||||
} else
|
||||
snum = parseInt(jl.value);
|
||||
var nid = 'slide' + snum;
|
||||
var ne = document.getElementById(nid);
|
||||
if (!ne) {
|
||||
ne = document.getElementById('slide0');
|
||||
snum = 0;
|
||||
}
|
||||
if (step < 0) {incpos = incrementals[snum].length} else {incpos = 0;}
|
||||
if (incrementals[snum].length > 0 && incpos == 0) {
|
||||
for (var i = 0; i < incrementals[snum].length; i++) {
|
||||
if (hasClass(incrementals[snum][i], 'current'))
|
||||
incpos = i + 1;
|
||||
else
|
||||
addClass(incrementals[snum][i], 'incremental');
|
||||
}
|
||||
}
|
||||
if (incrementals[snum].length > 0 && incpos > 0)
|
||||
addClass(incrementals[snum][incpos - 1], 'current');
|
||||
ce.style.visibility = 'hidden';
|
||||
ne.style.visibility = 'visible';
|
||||
jl.selectedIndex = snum;
|
||||
currentSlide();
|
||||
number = 0;
|
||||
}
|
||||
|
||||
function goTo(target) {
|
||||
if (target >= smax || target == snum) return;
|
||||
go(target - snum);
|
||||
}
|
||||
|
||||
function subgo(step) {
|
||||
if (step > 0) {
|
||||
removeClass(incrementals[snum][incpos - 1],'current');
|
||||
removeClass(incrementals[snum][incpos], 'incremental');
|
||||
addClass(incrementals[snum][incpos],'current');
|
||||
incpos++;
|
||||
} else {
|
||||
incpos--;
|
||||
removeClass(incrementals[snum][incpos],'current');
|
||||
addClass(incrementals[snum][incpos], 'incremental');
|
||||
addClass(incrementals[snum][incpos - 1],'current');
|
||||
}
|
||||
}
|
||||
|
||||
function toggle() {
|
||||
var slideColl = GetElementsWithClassName('*','slide');
|
||||
var slides = document.getElementById('slideProj');
|
||||
var outline = document.getElementById('outlineStyle');
|
||||
if (!slides.disabled) {
|
||||
slides.disabled = true;
|
||||
outline.disabled = false;
|
||||
s5mode = false;
|
||||
fontSize('1em');
|
||||
for (var n = 0; n < smax; n++) {
|
||||
var slide = slideColl[n];
|
||||
slide.style.visibility = 'visible';
|
||||
}
|
||||
} else {
|
||||
slides.disabled = false;
|
||||
outline.disabled = true;
|
||||
s5mode = true;
|
||||
fontScale();
|
||||
for (var n = 0; n < smax; n++) {
|
||||
var slide = slideColl[n];
|
||||
slide.style.visibility = 'hidden';
|
||||
}
|
||||
slideColl[snum].style.visibility = 'visible';
|
||||
}
|
||||
}
|
||||
|
||||
function showHide(action) {
|
||||
var obj = GetElementsWithClassName('*','hideme')[0];
|
||||
switch (action) {
|
||||
case 's': obj.style.visibility = 'visible'; break;
|
||||
case 'h': obj.style.visibility = 'hidden'; break;
|
||||
case 'k':
|
||||
if (obj.style.visibility != 'visible') {
|
||||
obj.style.visibility = 'visible';
|
||||
} else {
|
||||
obj.style.visibility = 'hidden';
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 'keys' code adapted from MozPoint (http://mozpoint.mozdev.org/)
|
||||
function keys(key) {
|
||||
if (!key) {
|
||||
key = event;
|
||||
key.which = key.keyCode;
|
||||
}
|
||||
if (key.which == 84) {
|
||||
toggle();
|
||||
return;
|
||||
}
|
||||
if (s5mode) {
|
||||
switch (key.which) {
|
||||
case 10: // return
|
||||
case 13: // enter
|
||||
if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
|
||||
if (key.target && isParentOrSelf(key.target, 'controls')) return;
|
||||
if(number != undef) {
|
||||
goTo(number);
|
||||
break;
|
||||
}
|
||||
case 32: // spacebar
|
||||
case 34: // page down
|
||||
case 39: // rightkey
|
||||
case 40: // downkey
|
||||
if(number != undef) {
|
||||
go(number);
|
||||
} else if (!incrementals[snum] || incpos >= incrementals[snum].length) {
|
||||
go(1);
|
||||
} else {
|
||||
subgo(1);
|
||||
}
|
||||
break;
|
||||
case 33: // page up
|
||||
case 37: // leftkey
|
||||
case 38: // upkey
|
||||
if(number != undef) {
|
||||
go(-1 * number);
|
||||
} else if (!incrementals[snum] || incpos <= 0) {
|
||||
go(-1);
|
||||
} else {
|
||||
subgo(-1);
|
||||
}
|
||||
break;
|
||||
case 36: // home
|
||||
goTo(0);
|
||||
break;
|
||||
case 35: // end
|
||||
goTo(smax-1);
|
||||
break;
|
||||
case 67: // c
|
||||
showHide('k');
|
||||
break;
|
||||
}
|
||||
if (key.which < 48 || key.which > 57) {
|
||||
number = undef;
|
||||
} else {
|
||||
if (window.event && isParentOrSelf(window.event.srcElement, 'controls')) return;
|
||||
if (key.target && isParentOrSelf(key.target, 'controls')) return;
|
||||
number = (((number != undef) ? number : 0) * 10) + (key.which - 48);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function clicker(e) {
|
||||
number = undef;
|
||||
var target;
|
||||
if (window.event) {
|
||||
target = window.event.srcElement;
|
||||
e = window.event;
|
||||
} else target = e.target;
|
||||
if (target.href != null || hasValue(target.rel, 'external') || isParentOrSelf(target, 'controls') || isParentOrSelf(target,'embed') || isParentOrSelf(target, 'object')) return true;
|
||||
if (!e.which || e.which == 1) {
|
||||
if (!incrementals[snum] || incpos >= incrementals[snum].length) {
|
||||
go(1);
|
||||
} else {
|
||||
subgo(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function findSlide(hash) {
|
||||
var target = null;
|
||||
var slides = GetElementsWithClassName('*','slide');
|
||||
for (var i = 0; i < slides.length; i++) {
|
||||
var targetSlide = slides[i];
|
||||
if ( (targetSlide.name && targetSlide.name == hash)
|
||||
|| (targetSlide.id && targetSlide.id == hash) ) {
|
||||
target = targetSlide;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while(target != null && target.nodeName != 'BODY') {
|
||||
if (hasClass(target, 'slide')) {
|
||||
return parseInt(target.id.slice(5));
|
||||
}
|
||||
target = target.parentNode;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function slideJump() {
|
||||
if (window.location.hash == null) return;
|
||||
var sregex = /^#slide(\d+)$/;
|
||||
var matches = sregex.exec(window.location.hash);
|
||||
var dest = null;
|
||||
if (matches != null) {
|
||||
dest = parseInt(matches[1]);
|
||||
} else {
|
||||
dest = findSlide(window.location.hash.slice(1));
|
||||
}
|
||||
if (dest != null)
|
||||
go(dest - snum);
|
||||
}
|
||||
|
||||
function fixLinks() {
|
||||
var thisUri = window.location.href;
|
||||
thisUri = thisUri.slice(0, thisUri.length - window.location.hash.length);
|
||||
var aelements = document.getElementsByTagName('A');
|
||||
for (var i = 0; i < aelements.length; i++) {
|
||||
var a = aelements[i].href;
|
||||
var slideID = a.match('\#slide[0-9]{1,2}');
|
||||
if ((slideID) && (slideID[0].slice(0,1) == '#')) {
|
||||
var dest = findSlide(slideID[0].slice(1));
|
||||
if (dest != null) {
|
||||
if (aelements[i].addEventListener) {
|
||||
aelements[i].addEventListener("click", new Function("e",
|
||||
"if (document.getElementById('slideProj').disabled) return;" +
|
||||
"go("+dest+" - snum); " +
|
||||
"if (e.preventDefault) e.preventDefault();"), true);
|
||||
} else if (aelements[i].attachEvent) {
|
||||
aelements[i].attachEvent("onclick", new Function("",
|
||||
"if (document.getElementById('slideProj').disabled) return;" +
|
||||
"go("+dest+" - snum); " +
|
||||
"event.returnValue = false;"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function externalLinks() {
|
||||
if (!document.getElementsByTagName) return;
|
||||
var anchors = document.getElementsByTagName('a');
|
||||
for (var i=0; i<anchors.length; i++) {
|
||||
var anchor = anchors[i];
|
||||
if (anchor.href && hasValue(anchor.rel, 'external')) {
|
||||
anchor.target = '_blank';
|
||||
addClass(anchor,'external');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createControls() {
|
||||
var controlsDiv = document.getElementById("controls");
|
||||
if (!controlsDiv) return;
|
||||
var hider = ' onmouseover="showHide(\'s\');" onmouseout="showHide(\'h\');"';
|
||||
var hideDiv, hideList = '';
|
||||
if (controlVis == 'hidden') {
|
||||
hideDiv = hider;
|
||||
} else {
|
||||
hideList = hider;
|
||||
}
|
||||
controlsDiv.innerHTML = '<form action="#" id="controlForm"' + hideDiv + '>' +
|
||||
'<div id="navLinks">' +
|
||||
'<a accesskey="t" id="toggle" href="javascript:toggle();">Ø<\/a>' +
|
||||
'<a accesskey="z" id="prev" href="javascript:go(-1);">«<\/a>' +
|
||||
'<a accesskey="x" id="next" href="javascript:go(1);">»<\/a>' +
|
||||
'<div id="navList"' + hideList + '><select id="jumplist" onchange="go(\'j\');"><\/select><\/div>' +
|
||||
'<\/div><\/form>';
|
||||
if (controlVis == 'hidden') {
|
||||
var hidden = document.getElementById('navLinks');
|
||||
} else {
|
||||
var hidden = document.getElementById('jumplist');
|
||||
}
|
||||
addClass(hidden,'hideme');
|
||||
}
|
||||
|
||||
function fontScale() { // causes layout problems in FireFox that get fixed if browser's Reload is used; same may be true of other Gecko-based browsers
|
||||
if (!s5mode) return false;
|
||||
var vScale = 22; // both yield 32 (after rounding) at 1024x768
|
||||
var hScale = 32; // perhaps should auto-calculate based on theme's declared value?
|
||||
if (window.innerHeight) {
|
||||
var vSize = window.innerHeight;
|
||||
var hSize = window.innerWidth;
|
||||
} else if (document.documentElement.clientHeight) {
|
||||
var vSize = document.documentElement.clientHeight;
|
||||
var hSize = document.documentElement.clientWidth;
|
||||
} else if (document.body.clientHeight) {
|
||||
var vSize = document.body.clientHeight;
|
||||
var hSize = document.body.clientWidth;
|
||||
} else {
|
||||
var vSize = 700; // assuming 1024x768, minus chrome and such
|
||||
var hSize = 1024; // these do not account for kiosk mode or Opera Show
|
||||
}
|
||||
var newSize = Math.min(Math.round(vSize/vScale),Math.round(hSize/hScale));
|
||||
fontSize(newSize + 'px');
|
||||
if (isGe) { // hack to counter incremental reflow bugs
|
||||
var obj = document.getElementsByTagName('body')[0];
|
||||
obj.style.display = 'none';
|
||||
obj.style.display = 'block';
|
||||
}
|
||||
}
|
||||
|
||||
function fontSize(value) {
|
||||
if (!(s5ss = document.getElementById('s5ss'))) {
|
||||
if (!isIE) {
|
||||
document.getElementsByTagName('head')[0].appendChild(s5ss = document.createElement('style'));
|
||||
s5ss.setAttribute('media','screen, projection');
|
||||
s5ss.setAttribute('id','s5ss');
|
||||
} else {
|
||||
document.createStyleSheet();
|
||||
document.s5ss = document.styleSheets[document.styleSheets.length - 1];
|
||||
}
|
||||
}
|
||||
if (!isIE) {
|
||||
while (s5ss.lastChild) s5ss.removeChild(s5ss.lastChild);
|
||||
s5ss.appendChild(document.createTextNode('body {font-size: ' + value + ' !important;}'));
|
||||
} else {
|
||||
document.s5ss.addRule('body','font-size: ' + value + ' !important;');
|
||||
}
|
||||
}
|
||||
|
||||
function notOperaFix() {
|
||||
slideCSS = document.getElementById('slideProj').href;
|
||||
var slides = document.getElementById('slideProj');
|
||||
var outline = document.getElementById('outlineStyle');
|
||||
slides.setAttribute('media','screen');
|
||||
outline.disabled = true;
|
||||
if (isGe) {
|
||||
slides.setAttribute('href','null'); // Gecko fix
|
||||
slides.setAttribute('href',slideCSS); // Gecko fix
|
||||
}
|
||||
if (isIE && document.styleSheets && document.styleSheets[0]) {
|
||||
document.styleSheets[0].addRule('img', 'behavior: url(ui/default/iepngfix.htc)');
|
||||
document.styleSheets[0].addRule('div', 'behavior: url(ui/default/iepngfix.htc)');
|
||||
document.styleSheets[0].addRule('.slide', 'behavior: url(ui/default/iepngfix.htc)');
|
||||
}
|
||||
}
|
||||
|
||||
function getIncrementals(obj) {
|
||||
var incrementals = new Array();
|
||||
if (!obj)
|
||||
return incrementals;
|
||||
var children = obj.childNodes;
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
var child = children[i];
|
||||
if (hasClass(child, 'incremental')) {
|
||||
if (child.nodeName == 'OL' || child.nodeName == 'UL') {
|
||||
removeClass(child, 'incremental');
|
||||
for (var j = 0; j < child.childNodes.length; j++) {
|
||||
if (child.childNodes[j].nodeType == 1) {
|
||||
addClass(child.childNodes[j], 'incremental');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
incrementals[incrementals.length] = child;
|
||||
removeClass(child,'incremental');
|
||||
}
|
||||
}
|
||||
if (hasClass(child, 'show-first')) {
|
||||
if (child.nodeName == 'OL' || child.nodeName == 'UL') {
|
||||
removeClass(child, 'show-first');
|
||||
if (child.childNodes[isGe].nodeType == 1) {
|
||||
removeClass(child.childNodes[isGe], 'incremental');
|
||||
}
|
||||
} else {
|
||||
incrementals[incrementals.length] = child;
|
||||
}
|
||||
}
|
||||
incrementals = incrementals.concat(getIncrementals(child));
|
||||
}
|
||||
return incrementals;
|
||||
}
|
||||
|
||||
function createIncrementals() {
|
||||
var incrementals = new Array();
|
||||
for (var i = 0; i < smax; i++) {
|
||||
incrementals[i] = getIncrementals(document.getElementById('slide'+i));
|
||||
}
|
||||
return incrementals;
|
||||
}
|
||||
|
||||
function defaultCheck() {
|
||||
var allMetas = document.getElementsByTagName('meta');
|
||||
for (var i = 0; i< allMetas.length; i++) {
|
||||
if (allMetas[i].name == 'defaultView') {
|
||||
defaultView = allMetas[i].content;
|
||||
}
|
||||
if (allMetas[i].name == 'controlVis') {
|
||||
controlVis = allMetas[i].content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Key trap fix, new function body for trap()
|
||||
function trap(e) {
|
||||
if (!e) {
|
||||
e = event;
|
||||
e.which = e.keyCode;
|
||||
}
|
||||
try {
|
||||
modifierKey = e.ctrlKey || e.altKey || e.metaKey;
|
||||
}
|
||||
catch(e) {
|
||||
modifierKey = false;
|
||||
}
|
||||
return modifierKey || e.which == 0;
|
||||
}
|
||||
|
||||
function startup() {
|
||||
defaultCheck();
|
||||
if (!isOp) createControls();
|
||||
slideLabel();
|
||||
fixLinks();
|
||||
externalLinks();
|
||||
fontScale();
|
||||
if (!isOp) {
|
||||
notOperaFix();
|
||||
incrementals = createIncrementals();
|
||||
slideJump();
|
||||
if (defaultView == 'outline') {
|
||||
toggle();
|
||||
}
|
||||
document.onkeyup = keys;
|
||||
document.onkeypress = trap;
|
||||
document.onclick = clicker;
|
||||
}
|
||||
}
|
||||
|
||||
window.onload = startup;
|
||||
window.onresize = function(){setTimeout('fontScale()', 50);}
|
||||
6151
autoload/vst/vst.vim
Normal file
6151
autoload/vst/vst.vim
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user