mirror of
https://github.com/gryf/.vim.git
synced 2025-12-17 11:30:29 +01:00
Commented changes in plugins, updated vimwiki, repaired zoom plugin, added
buffergator, updated pythonhelper, removed leftovers
This commit is contained in:
@@ -1,748 +0,0 @@
|
||||
" ============================================================================
|
||||
" File: autoload/delimitMate.vim
|
||||
" Version: 2.3.1
|
||||
" Modified: 2010-06-06
|
||||
" Description: This plugin provides auto-completion for quotes, parens, etc.
|
||||
" Maintainer: Israel Chauca F. <israelchauca@gmail.com>
|
||||
" Manual: Read ":help delimitMate".
|
||||
|
||||
" Utilities {{{
|
||||
function! delimitMate#Init() "{{{
|
||||
" Initialize variables:
|
||||
|
||||
" delimitMate_autoclose {{{
|
||||
if !exists("b:delimitMate_autoclose") && !exists("g:delimitMate_autoclose")
|
||||
let b:delimitMate_autoclose = 1
|
||||
elseif !exists("b:delimitMate_autoclose") && exists("g:delimitMate_autoclose")
|
||||
let b:delimitMate_autoclose = g:delimitMate_autoclose
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_matchpairs {{{
|
||||
if !exists("b:delimitMate_matchpairs") && !exists("g:delimitMate_matchpairs")
|
||||
let s:matchpairs_temp = &matchpairs
|
||||
elseif exists("b:delimitMate_matchpairs")
|
||||
let s:matchpairs_temp = b:delimitMate_matchpairs
|
||||
else
|
||||
let s:matchpairs_temp = g:delimitMate_matchpairs
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_quotes {{{
|
||||
if exists("b:delimitMate_quotes")
|
||||
let s:quotes = split(b:delimitMate_quotes)
|
||||
elseif exists("g:delimitMate_quotes")
|
||||
let s:quotes = split(g:delimitMate_quotes)
|
||||
else
|
||||
let s:quotes = split("\" ' `")
|
||||
endif
|
||||
let b:delimitMate_quotes_list = s:quotes " }}}
|
||||
|
||||
" delimitMate_excluded_regions {{{
|
||||
if exists("b:delimitMate_excluded_regions")
|
||||
let s:excluded_regions = b:delimitMate_excluded_regions
|
||||
elseif exists("g:delimitMate_excluded_regions")
|
||||
let s:excluded_regions = g:delimitMate_excluded_regions
|
||||
else
|
||||
let s:excluded_regions = "Comment"
|
||||
endif
|
||||
let b:delimitMate_excluded_regions_list = split(s:excluded_regions, ',\s*')
|
||||
let b:delimitMate_excluded_regions_enabled = len(b:delimitMate_excluded_regions_list) " }}}
|
||||
|
||||
" delimitMate_visual_leader {{{
|
||||
if !exists("b:delimitMate_visual_leader") && !exists("g:delimitMate_visual_leader")
|
||||
let b:delimitMate_visual_leader = exists('b:maplocalleader') ? b:maplocalleader :
|
||||
\ exists('g:mapleader') ? g:mapleader : "\\"
|
||||
elseif !exists("b:delimitMate_visual_leader") && exists("g:delimitMate_visual_leader")
|
||||
let b:delimitMate_visual_leader = g:delimitMate_visual_leader
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_expand_space {{{
|
||||
if !exists("b:delimitMate_expand_space") && !exists("g:delimitMate_expand_space")
|
||||
let b:delimitMate_expand_space = 0
|
||||
elseif !exists("b:delimitMate_expand_space") && exists("g:delimitMate_expand_space")
|
||||
let b:delimitMate_expand_space = g:delimitMate_expand_space
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_expand_cr {{{
|
||||
if !exists("b:delimitMate_expand_cr") && !exists("g:delimitMate_expand_cr")
|
||||
let b:delimitMate_expand_cr = 0
|
||||
elseif !exists("b:delimitMate_expand_cr") && exists("g:delimitMate_expand_cr")
|
||||
let b:delimitMate_expand_cr = g:delimitMate_expand_cr
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_smart_quotes {{{
|
||||
if !exists("b:delimitMate_smart_quotes") && !exists("g:delimitMate_smart_quotes")
|
||||
let b:delimitMate_smart_quotes = 1
|
||||
elseif !exists("b:delimitMate_smart_quotes") && exists("g:delimitMate_smart_quotes")
|
||||
let b:delimitMate_smart_quotes = split(g:delimitMate_smart_quotes)
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
" delimitMate_apostrophes {{{
|
||||
if !exists("b:delimitMate_apostrophes") && !exists("g:delimitMate_apostrophes")
|
||||
"let s:apostrophes = split("n't:'s:'re:'m:'d:'ll:'ve:s'",':')
|
||||
let s:apostrophes = []
|
||||
elseif !exists("b:delimitMate_apostrophes") && exists("g:delimitMate_apostrophes")
|
||||
let s:apostrophes = split(g:delimitMate_apostrophes)
|
||||
else
|
||||
let s:apostrophes = split(b:delimitMate_apostrophes)
|
||||
endif
|
||||
let b:delimitMate_apostrophes_list = s:apostrophes " }}}
|
||||
|
||||
" delimitMate_tab2exit {{{
|
||||
if !exists("b:delimitMate_tab2exit") && !exists("g:delimitMate_tab2exit")
|
||||
let b:delimitMate_tab2exit = 1
|
||||
elseif !exists("b:delimitMate_tab2exit") && exists("g:delimitMate_tab2exit")
|
||||
let b:delimitMate_tab2exit = g:delimitMate_tab2exit
|
||||
else
|
||||
" Nothing to do.
|
||||
endif " }}}
|
||||
|
||||
let b:delimitMate_matchpairs_list = split(s:matchpairs_temp, ',')
|
||||
let b:delimitMate_left_delims = split(s:matchpairs_temp, ':.,\=')
|
||||
let b:delimitMate_right_delims = split(s:matchpairs_temp, ',\=.:')
|
||||
|
||||
let b:delimitMate_buffer = []
|
||||
|
||||
call delimitMate#UnMap()
|
||||
if b:delimitMate_autoclose
|
||||
call delimitMate#AutoClose()
|
||||
else
|
||||
call delimitMate#NoAutoClose()
|
||||
endif
|
||||
call delimitMate#VisualMaps()
|
||||
call delimitMate#ExtraMappings()
|
||||
|
||||
let b:loaded_delimitMate = 1
|
||||
let b:delimitMate_enabled = 1
|
||||
endfunction "}}} Init()
|
||||
|
||||
function! delimitMate#ShouldJump() "{{{
|
||||
" Returns 1 if the next character is a closing delimiter.
|
||||
let col = col('.')
|
||||
let lcol = col('$')
|
||||
let char = getline('.')[col - 1]
|
||||
|
||||
for cdel in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
if char == cdel
|
||||
" Closing delimiter on the right.
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
|
||||
let nchar = getline('.')[col]
|
||||
if b:delimitMate_expand_space && char == " "
|
||||
for cdel in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
if nchar == cdel
|
||||
" Closing delimiter with space expansion.
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
let uchar = getline(line('.') + 1)[0]
|
||||
if b:delimitMate_expand_cr && char == ""
|
||||
for cdel in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
if uchar == cdel
|
||||
" Closing delimiter with CR expansion.
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#IsBlockVisual() " {{{
|
||||
if mode() == "\<C-V>"
|
||||
return 1
|
||||
endif
|
||||
" Store unnamed register values for later use in delimitMate#RestoreRegister().
|
||||
let b:save_reg = getreg('"')
|
||||
let b:save_reg_mode = getregtype('"')
|
||||
|
||||
if len(getline('.')) == 0
|
||||
" This for proper wrap of empty lines.
|
||||
let @" = "\n"
|
||||
endif
|
||||
return 0
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#Visual(del) " {{{
|
||||
let mode = mode()
|
||||
if mode == "\<C-V>"
|
||||
redraw
|
||||
echom "delimitMate: delimitMate is disabled on blockwise visual mode."
|
||||
return ""
|
||||
endif
|
||||
" Store unnamed register values for later use in delimitMate#RestoreRegister().
|
||||
let b:save_reg = getreg('"')
|
||||
let b:save_reg_mode = getregtype('"')
|
||||
|
||||
if len(getline('.')) == 0
|
||||
" This for proper wrap of empty lines.
|
||||
let @" = "\n"
|
||||
endif
|
||||
|
||||
if mode ==# "V"
|
||||
let dchar = "\<BS>"
|
||||
else
|
||||
let dchar = ""
|
||||
endif
|
||||
|
||||
let index = index(b:delimitMate_left_delims, a:del)
|
||||
if index >= 0
|
||||
let ld = a:del
|
||||
let rd = b:delimitMate_right_delims[index]
|
||||
endif
|
||||
|
||||
let index = index(b:delimitMate_right_delims, a:del)
|
||||
if index >= 0
|
||||
let ld = b:delimitMate_left_delims[index]
|
||||
let rd = a:del
|
||||
endif
|
||||
|
||||
let index = index(b:delimitMate_quotes_list, a:del)
|
||||
if index >= 0
|
||||
let ld = a:del
|
||||
let rd = ld
|
||||
endif
|
||||
|
||||
return "s" . ld . "\<C-R>\"" . dchar . rd . "\<Esc>:call delimitMate#RestoreRegister()\<CR>"
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#IsEmptyPair(str) "{{{
|
||||
for pair in b:delimitMate_matchpairs_list
|
||||
if a:str == join( split( pair, ':' ),'' )
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
for quote in b:delimitMate_quotes_list
|
||||
if a:str == quote . quote
|
||||
return 1
|
||||
endif
|
||||
endfor
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#IsCRExpansion() " {{{
|
||||
let nchar = getline(line('.')-1)[-1:]
|
||||
let schar = getline(line('.')+1)[:0]
|
||||
let isEmpty = getline('.') == ""
|
||||
if index(b:delimitMate_left_delims, nchar) > -1 &&
|
||||
\ index(b:delimitMate_left_delims, nchar) == index(b:delimitMate_right_delims, schar) &&
|
||||
\ isEmpty
|
||||
return 1
|
||||
elseif index(b:delimitMate_quotes_list, nchar) > -1 &&
|
||||
\ index(b:delimitMate_quotes_list, nchar) == index(b:delimitMate_quotes_list, schar) &&
|
||||
\ isEmpty
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
endif
|
||||
endfunction " }}} delimitMate#IsCRExpansion()
|
||||
|
||||
function! delimitMate#IsSpaceExpansion() " {{{
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if col > 0
|
||||
let pchar = line[col - 1]
|
||||
let nchar = line[col + 2]
|
||||
let isSpaces = (line[col] == line[col+1] && line[col] == " ")
|
||||
|
||||
if index(b:delimitMate_left_delims, pchar) > -1 &&
|
||||
\ index(b:delimitMate_left_delims, pchar) == index(b:delimitMate_right_delims, nchar) &&
|
||||
\ isSpaces
|
||||
return 1
|
||||
elseif index(b:delimitMate_quotes_list, pchar) > -1 &&
|
||||
\ index(b:delimitMate_quotes_list, pchar) == index(b:delimitMate_quotes_list, nchar) &&
|
||||
\ isSpaces
|
||||
return 1
|
||||
endif
|
||||
endif
|
||||
return 0
|
||||
endfunction " }}} IsSpaceExpansion()
|
||||
|
||||
function! delimitMate#WithinEmptyPair() "{{{
|
||||
let cur = strpart( getline('.'), col('.')-2, 2 )
|
||||
return delimitMate#IsEmptyPair( cur )
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#WriteBefore(str) "{{{
|
||||
let len = len(a:str)
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if col < 0
|
||||
call setline('.',line[(col+len+1):])
|
||||
else
|
||||
call setline('.',line[:(col)].line[(col+len+1):])
|
||||
endif
|
||||
return a:str
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#WriteAfter(str) "{{{
|
||||
let len = len(a:str)
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if (col) < 0
|
||||
call setline('.',a:str.line)
|
||||
else
|
||||
call setline('.',line[:(col)].a:str.line[(col+len):])
|
||||
endif
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#RestoreRegister() " {{{
|
||||
" Restore unnamed register values store in delimitMate#IsBlockVisual().
|
||||
call setreg('"', b:save_reg, b:save_reg_mode)
|
||||
echo ""
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#GetSyntaxRegion(line, col) "{{{
|
||||
return synIDattr(synIDtrans(synID(a:line, a:col, 1)), 'name')
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#GetCurrentSyntaxRegion() "{{{
|
||||
let col = col('.')
|
||||
if col == col('$')
|
||||
let col = col - 1
|
||||
endif
|
||||
return delimitMate#GetSyntaxRegion(line('.'), col)
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#GetCurrentSyntaxRegionIf(char) "{{{
|
||||
let col = col('.')
|
||||
let origin_line = getline('.')
|
||||
let changed_line = strpart(origin_line, 0, col - 1) . a:char . strpart(origin_line, col - 1)
|
||||
call setline('.', changed_line)
|
||||
let region = delimitMate#GetSyntaxRegion(line('.'), col)
|
||||
call setline('.', origin_line)
|
||||
return region
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#IsForbidden(char) "{{{
|
||||
if b:delimitMate_excluded_regions_enabled == 0
|
||||
return 0
|
||||
endif
|
||||
"let result = index(b:delimitMate_excluded_regions_list, delimitMate#GetCurrentSyntaxRegion()) >= 0
|
||||
if index(b:delimitMate_excluded_regions_list, delimitMate#GetCurrentSyntaxRegion()) >= 0
|
||||
"echom "Forbidden 1!"
|
||||
return 1
|
||||
endif
|
||||
let region = delimitMate#GetCurrentSyntaxRegionIf(a:char)
|
||||
"let result = index(b:delimitMate_excluded_regions_list, region) >= 0
|
||||
"return result || region == 'Comment'
|
||||
"echom "Forbidden 2!"
|
||||
return index(b:delimitMate_excluded_regions_list, region) >= 0
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#FlushBuffer() " {{{
|
||||
let b:delimitMate_buffer = []
|
||||
return ''
|
||||
endfunction " }}}
|
||||
" }}}
|
||||
|
||||
" Doers {{{
|
||||
function! delimitMate#JumpIn(char) " {{{
|
||||
if delimitMate#IsForbidden(a:char)
|
||||
return ''
|
||||
endif
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if (col) < 0
|
||||
call setline('.',a:char.line)
|
||||
call insert(b:delimitMate_buffer, a:char)
|
||||
else
|
||||
"echom string(col).':'.line[:(col)].'|'.line[(col+1):]
|
||||
call setline('.',line[:(col)].a:char.line[(col+1):])
|
||||
call insert(b:delimitMate_buffer, a:char)
|
||||
endif
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#JumpOut(char) "{{{
|
||||
if delimitMate#IsForbidden(a:char)
|
||||
return a:char
|
||||
endif
|
||||
let line = getline('.')
|
||||
let col = col('.')-2
|
||||
if line[col+1] == a:char
|
||||
return a:char . delimitMate#Del()
|
||||
else
|
||||
return a:char
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#JumpAny(key) " {{{
|
||||
if delimitMate#IsForbidden('')
|
||||
return a:key
|
||||
endif
|
||||
if !delimitMate#ShouldJump()
|
||||
return a:key
|
||||
endif
|
||||
" Let's get the character on the right.
|
||||
let char = getline('.')[col('.')-1]
|
||||
if char == " "
|
||||
" Space expansion.
|
||||
"let char = char . getline('.')[col('.')] . delimitMate#Del()
|
||||
return char . getline('.')[col('.')] . delimitMate#Del() . delimitMate#Del()
|
||||
"call delimitMate#RmBuffer(1)
|
||||
elseif char == ""
|
||||
" CR expansion.
|
||||
"let char = "\<CR>" . getline(line('.') + 1)[0] . "\<Del>"
|
||||
let b:delimitMate_buffer = []
|
||||
return "\<CR>" . getline(line('.') + 1)[0] . "\<Del>"
|
||||
else
|
||||
"call delimitMate#RmBuffer(1)
|
||||
return char . delimitMate#Del()
|
||||
endif
|
||||
endfunction " delimitMate#JumpAny() }}}
|
||||
|
||||
function! delimitMate#SkipDelim(char) "{{{
|
||||
if delimitMate#IsForbidden(a:char)
|
||||
return a:char
|
||||
endif
|
||||
let col = col('.') - 1
|
||||
let line = getline('.')
|
||||
if col > 0
|
||||
let cur = line[col]
|
||||
let pre = line[col-1]
|
||||
else
|
||||
let cur = line[col]
|
||||
let pre = ""
|
||||
endif
|
||||
if pre == "\\"
|
||||
" Escaped character
|
||||
return a:char
|
||||
elseif cur == a:char
|
||||
" Exit pair
|
||||
"return delimitMate#WriteBefore(a:char)
|
||||
return a:char . delimitMate#Del()
|
||||
elseif delimitMate#IsEmptyPair( pre . a:char )
|
||||
" Add closing delimiter and jump back to the middle.
|
||||
call insert(b:delimitMate_buffer, a:char)
|
||||
return delimitMate#WriteAfter(a:char)
|
||||
else
|
||||
" Nothing special here, return the same character.
|
||||
return a:char
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#QuoteDelim(char) "{{{
|
||||
if delimitMate#IsForbidden(a:char)
|
||||
return a:char
|
||||
endif
|
||||
let line = getline('.')
|
||||
let col = col('.') - 2
|
||||
if line[col] == "\\"
|
||||
" Seems like a escaped character, insert one quotation mark.
|
||||
return a:char
|
||||
elseif line[col + 1] == a:char
|
||||
" Get out of the string.
|
||||
"return delimitMate#WriteBefore(a:char)
|
||||
return a:char . delimitMate#Del()
|
||||
elseif (line[col] =~ '[a-zA-Z0-9]' && a:char == "'") ||
|
||||
\(line[col] =~ '[a-zA-Z0-9]' && b:delimitMate_smart_quotes)
|
||||
" Seems like an apostrophe or a closing, insert a single quote.
|
||||
return a:char
|
||||
elseif (line[col] == a:char && line[col + 1 ] != a:char) && b:delimitMate_smart_quotes
|
||||
" Seems like we have an unbalanced quote, insert one quotation mark and jump to the middle.
|
||||
call insert(b:delimitMate_buffer, a:char)
|
||||
return delimitMate#WriteAfter(a:char)
|
||||
else
|
||||
" Insert a pair and jump to the middle.
|
||||
call insert(b:delimitMate_buffer, a:char)
|
||||
call delimitMate#WriteAfter(a:char)
|
||||
return a:char
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#MapMsg(msg) "{{{
|
||||
redraw
|
||||
echomsg a:msg
|
||||
return ""
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#ExpandReturn() "{{{
|
||||
if delimitMate#IsForbidden("")
|
||||
return "\<CR>"
|
||||
endif
|
||||
if delimitMate#WithinEmptyPair()
|
||||
" Expand:
|
||||
call delimitMate#FlushBuffer()
|
||||
"return "\<Esc>a\<CR>x\<CR>\<Esc>k$\"_xa"
|
||||
return "\<CR>\<UP>\<Esc>o"
|
||||
else
|
||||
return "\<CR>"
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#ExpandSpace() "{{{
|
||||
if delimitMate#IsForbidden("\<Space>")
|
||||
return "\<Space>"
|
||||
endif
|
||||
if delimitMate#WithinEmptyPair()
|
||||
" Expand:
|
||||
call insert(b:delimitMate_buffer, 's')
|
||||
return delimitMate#WriteAfter(' ') . "\<Space>"
|
||||
else
|
||||
return "\<Space>"
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#BS() " {{{
|
||||
if delimitMate#IsForbidden("")
|
||||
return "\<BS>"
|
||||
endif
|
||||
if delimitMate#WithinEmptyPair()
|
||||
"call delimitMate#RmBuffer(1)
|
||||
return "\<BS>" . delimitMate#Del()
|
||||
" return "\<Right>\<BS>\<BS>"
|
||||
elseif delimitMate#IsSpaceExpansion()
|
||||
"call delimitMate#RmBuffer(1)
|
||||
return "\<BS>" . delimitMate#Del()
|
||||
elseif delimitMate#IsCRExpansion()
|
||||
return "\<BS>\<Del>"
|
||||
else
|
||||
return "\<BS>"
|
||||
endif
|
||||
endfunction " }}} delimitMate#BS()
|
||||
|
||||
function! delimitMate#Del() " {{{
|
||||
if len(b:delimitMate_buffer) > 0
|
||||
let line = getline('.')
|
||||
let col = col('.') - 2
|
||||
call delimitMate#RmBuffer(1)
|
||||
call setline('.', line[:col] . line[col+2:])
|
||||
return ''
|
||||
else
|
||||
return "\<Del>"
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#Finish() " {{{
|
||||
let len = len(b:delimitMate_buffer)
|
||||
if len > 0
|
||||
let buffer = join(b:delimitMate_buffer, '')
|
||||
" Reset buffer:
|
||||
let b:delimitMate_buffer = []
|
||||
let line = getline('.')
|
||||
let col = col('.') -2
|
||||
"echom 'col: ' . col . '-' . line[:col] . "|" . line[col+len+1:] . '%' . buffer
|
||||
if col < 0
|
||||
call setline('.', line[col+len+1:])
|
||||
else
|
||||
call setline('.', line[:col] . line[col+len+1:])
|
||||
endif
|
||||
let i = 1
|
||||
let lefts = "\<Left>"
|
||||
while i < len
|
||||
let lefts = lefts . "\<Left>"
|
||||
let i += 1
|
||||
endwhile
|
||||
return substitute(buffer, "s", "\<Space>", 'g') . lefts
|
||||
endif
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! delimitMate#RmBuffer(num) " {{{
|
||||
if len(b:delimitMate_buffer) > 0
|
||||
call remove(b:delimitMate_buffer, 0, (a:num-1))
|
||||
endif
|
||||
return ""
|
||||
endfunction " }}}
|
||||
|
||||
" }}}
|
||||
|
||||
" Mappers: {{{
|
||||
function! delimitMate#NoAutoClose() "{{{
|
||||
" inoremap <buffer> ) <C-R>=delimitMate#SkipDelim('\)')<CR>
|
||||
for delim in b:delimitMate_right_delims + b:delimitMate_quotes_list
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=delimitMate#SkipDelim("' . escape(delim,'"\|') . '")<CR>'
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#AutoClose() "{{{
|
||||
" Add matching pair and jump to the midle:
|
||||
" inoremap <buffer> ( ()<Left>
|
||||
let i = 0
|
||||
while i < len(b:delimitMate_matchpairs_list)
|
||||
let ld = b:delimitMate_left_delims[i]
|
||||
let rd = b:delimitMate_right_delims[i]
|
||||
exec 'inoremap <buffer> ' . ld . ' ' . ld . '<C-R>=delimitMate#JumpIn("' . rd . '")<CR>'
|
||||
let i += 1
|
||||
endwhile
|
||||
|
||||
" Exit from inside the matching pair:
|
||||
for delim in b:delimitMate_right_delims
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=delimitMate#JumpOut("\' . delim . '")<CR>'
|
||||
endfor
|
||||
|
||||
" Add matching quote and jump to the midle, or exit if inside a pair of matching quotes:
|
||||
" inoremap <buffer> " <C-R>=delimitMate#QuoteDelim("\"")<CR>
|
||||
for delim in b:delimitMate_quotes_list
|
||||
exec 'inoremap <buffer> ' . delim . ' <C-R>=delimitMate#QuoteDelim("\' . delim . '")<CR>'
|
||||
endfor
|
||||
|
||||
" Try to fix the use of apostrophes (de-activated by default):
|
||||
" inoremap <buffer> n't n't
|
||||
for map in b:delimitMate_apostrophes_list
|
||||
exec "inoremap <buffer> " . map . " " . map
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#VisualMaps() " {{{
|
||||
let VMapMsg = "delimitMate: delimitMate is disabled on blockwise visual mode."
|
||||
let vleader = b:delimitMate_visual_leader
|
||||
" Wrap the selection with matching pairs, but do nothing if blockwise visual mode is active:
|
||||
for del in b:delimitMate_right_delims + b:delimitMate_left_delims + b:delimitMate_quotes_list
|
||||
exec "vnoremap <buffer> <expr> " . vleader . del . ' delimitMate#Visual("' . escape(del, '")') . '")'
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#ExtraMappings() "{{{
|
||||
" If pair is empty, delete both delimiters:
|
||||
inoremap <buffer> <BS> <C-R>=delimitMate#BS()<CR>
|
||||
|
||||
" If pair is empty, delete closing delimiter:
|
||||
inoremap <buffer> <expr> <S-BS> delimitMate#WithinEmptyPair() && !delimitMate#IsForbidden("") ? "\<Del>" : "\<S-BS>"
|
||||
|
||||
" Expand return if inside an empty pair:
|
||||
if b:delimitMate_expand_cr != 0
|
||||
inoremap <buffer> <CR> <C-R>=delimitMate#ExpandReturn()<CR>
|
||||
endif
|
||||
|
||||
" Expand space if inside an empty pair:
|
||||
if b:delimitMate_expand_space != 0
|
||||
inoremap <buffer> <Space> <C-R>=delimitMate#ExpandSpace()<CR>
|
||||
endif
|
||||
|
||||
" Jump out ot any empty pair:
|
||||
if b:delimitMate_tab2exit
|
||||
inoremap <buffer> <S-Tab> <C-R>=delimitMate#JumpAny("\<S-Tab>")<CR>
|
||||
endif
|
||||
|
||||
" Fix the re-do feature:
|
||||
inoremap <buffer> <Esc> <C-R>=delimitMate#Finish()<CR><Esc>
|
||||
|
||||
" Flush the char buffer on mouse click:
|
||||
inoremap <buffer> <LeftMouse> <C-R>=delimitMate#Finish()<CR><LeftMouse>
|
||||
inoremap <buffer> <RightMouse> <C-R>=delimitMate#Finish()<CR><RightMouse>
|
||||
|
||||
" Flush the char buffer on key movements:
|
||||
inoremap <buffer> <Left> <C-R>=delimitMate#Finish()<CR><Left>
|
||||
inoremap <buffer> <Right> <C-R>=delimitMate#Finish()<CR><Right>
|
||||
inoremap <buffer> <Up> <C-R>=delimitMate#Finish()<CR><Up>
|
||||
inoremap <buffer> <Down> <C-R>=delimitMate#Finish()<CR><Down>
|
||||
|
||||
inoremap <buffer> <Del> <C-R>=delimitMate#Del()<CR>
|
||||
|
||||
"the following simply creates an ambiguous mapping so vim fully
|
||||
"processes the escape sequence for terminal keys, see 'ttimeout' for a
|
||||
"rough explanation, this just forces it to work
|
||||
if &term[:4] != "builtin_gui"
|
||||
inoremap <silent> <C-[>OC <RIGHT>
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! delimitMate#UnMap() " {{{
|
||||
let imaps =
|
||||
\ b:delimitMate_right_delims +
|
||||
\ b:delimitMate_left_delims +
|
||||
\ b:delimitMate_quotes_list +
|
||||
\ b:delimitMate_apostrophes_list +
|
||||
\ ['<BS>', '<S-BS>', '<Del>', '<CR>', '<Space>', '<S-Tab>', '<Esc>'] +
|
||||
\ ['<Up>', '<Down>', '<Left>', '<Right>', '<LeftMouse>', '<RightMouse>']
|
||||
|
||||
let vmaps =
|
||||
\ b:delimitMate_right_delims +
|
||||
\ b:delimitMate_left_delims +
|
||||
\ b:delimitMate_quotes_list
|
||||
|
||||
for map in imaps
|
||||
if maparg(map, "i") =~? 'delimitMate'
|
||||
exec 'silent! iunmap <buffer> ' . map
|
||||
endif
|
||||
endfor
|
||||
|
||||
if !exists("b:delimitMate_visual_leader")
|
||||
let vleader = ""
|
||||
else
|
||||
let vleader = b:delimitMate_visual_leader
|
||||
endif
|
||||
for map in vmaps
|
||||
if maparg(vleader . map, "v") =~? "delimitMate"
|
||||
exec 'silent! vunmap <buffer> ' . vleader . map
|
||||
endif
|
||||
endfor
|
||||
|
||||
let b:delimitMate_enabled = 0
|
||||
endfunction " }}} delimitMate#UnMap()
|
||||
|
||||
"}}}
|
||||
|
||||
" Tools: {{{
|
||||
function! delimitMate#TestMappings() "{{{
|
||||
exec "normal i*b:delimitMate_autoclose = " . b:delimitMate_autoclose . "\<CR>"
|
||||
exec "normal i*b:delimitMate_expand_space = " . b:delimitMate_expand_space . "\<CR>"
|
||||
exec "normal i*b:delimitMate_expand_cr = " . b:delimitMate_expand_cr . "\<CR>\<CR>"
|
||||
|
||||
if b:delimitMate_autoclose
|
||||
for i in range(len(b:delimitMate_left_delims))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_left_delims[i]. "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_left_delims[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_left_delims[i] . " |"
|
||||
exec "normal A\<CR>Delete space: " . b:delimitMate_left_delims[i] . " \<BS>|"
|
||||
exec "normal GGA\<CR>Visual-L: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_left_delims[i]
|
||||
exec "normal A\<CR>Visual-R: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_right_delims[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_left_delims[i] . "\<CR>|"
|
||||
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_left_delims[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
for i in range(len(b:delimitMate_quotes_list))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Delete: "
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_quotes_list[i] . " |"
|
||||
exec "normal A\<CR>Delete space: " . b:delimitMate_quotes_list[i] . " \<BS>|"
|
||||
exec "normal GGA\<CR>Visual: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_quotes_list[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_quotes_list[i] . "\<CR>|"
|
||||
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_quotes_list[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
else
|
||||
for i in range(len(b:delimitMate_left_delims))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . b:delimitMate_right_delims[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . " |"
|
||||
exec "normal A\<CR>Delete space: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . " \<BS>|"
|
||||
exec "normal GGA\<CR>Visual-L: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_left_delims[i]
|
||||
exec "normal A\<CR>Visual-R: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_right_delims[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<CR>|"
|
||||
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_left_delims[i] . b:delimitMate_right_delims[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
for i in range(len(b:delimitMate_quotes_list))
|
||||
exec "normal GGAOpen & close: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Delete: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<BS>|"
|
||||
exec "normal A\<CR>Exit: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "|"
|
||||
exec "normal A\<CR>Space: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . " |"
|
||||
exec "normal A\<CR>Delete space: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . " \<BS>|"
|
||||
exec "normal GGA\<CR>Visual: v\<Esc>v" . b:delimitMate_visual_leader . b:delimitMate_quotes_list[i]
|
||||
exec "normal A\<CR>Car return: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<CR>|"
|
||||
exec "normal GGA\<CR>Delete car return: " . b:delimitMate_quotes_list[i] . b:delimitMate_quotes_list[i] . "\<CR>\<BS>|\<Esc>GGA\<CR>\<CR>"
|
||||
endfor
|
||||
endif
|
||||
exec "normal \<Esc>i"
|
||||
endfunction "}}}
|
||||
|
||||
"}}}
|
||||
|
||||
" vim:foldmethod=marker:foldcolumn=4
|
||||
@@ -1,591 +0,0 @@
|
||||
" ---------------------------------------------------------------------
|
||||
" 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
|
||||
@@ -18,14 +18,18 @@ let s:badsymbols = '['.g:vimwiki_badsyms.g:vimwiki_stripsym.'<>|?*:"]'
|
||||
|
||||
" MISC helper functions {{{
|
||||
|
||||
function! vimwiki#chomp_slash(str) "{{{
|
||||
function! vimwiki#base#chomp_slash(str) "{{{
|
||||
return substitute(a:str, '[/\\]\+$', '', '')
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#mkdir(path) "{{{
|
||||
function! vimwiki#base#path_norm(path) "{{{
|
||||
return substitute(a:path, '\', '/', 'g')
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#base#mkdir(path) "{{{
|
||||
let path = expand(a:path)
|
||||
if !isdirectory(path) && exists("*mkdir")
|
||||
let path = vimwiki#chomp_slash(path)
|
||||
let path = vimwiki#base#chomp_slash(path)
|
||||
if s:is_windows() && !empty(g:vimwiki_w32_dir_enc)
|
||||
let path = iconv(path, &enc, g:vimwiki_w32_dir_enc)
|
||||
endif
|
||||
@@ -34,17 +38,30 @@ function! vimwiki#mkdir(path) "{{{
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#safe_link(string) "{{{
|
||||
return substitute(a:string, s:badsymbols, g:vimwiki_stripsym, 'g')
|
||||
function! vimwiki#base#safe_link(link) "{{{
|
||||
" handling Windows absolute paths
|
||||
if a:link =~ '^[[:alpha:]]:[/\\].*'
|
||||
let link_start = a:link[0 : 2]
|
||||
let link = a:link[3 : ]
|
||||
else
|
||||
let link_start = ''
|
||||
let link = a:link
|
||||
endif
|
||||
let link = substitute(link, s:badsymbols, g:vimwiki_stripsym, 'g')
|
||||
return link_start.link
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#unsafe_link(string) "{{{
|
||||
return substitute(a:string, g:vimwiki_stripsym, s:badsymbols, 'g')
|
||||
function! vimwiki#base#unsafe_link(string) "{{{
|
||||
if len(g:vimwiki_stripsym) > 0
|
||||
return substitute(a:string, g:vimwiki_stripsym, s:badsymbols, 'g')
|
||||
else
|
||||
return a:string
|
||||
endif
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#subdir(path, filename)"{{{
|
||||
function! vimwiki#base#subdir(path, filename)"{{{
|
||||
let path = expand(a:path)
|
||||
let filename = expand(a:filename)
|
||||
let idx = 0
|
||||
@@ -60,13 +77,17 @@ function! vimwiki#subdir(path, filename)"{{{
|
||||
return res
|
||||
endfunction"}}}
|
||||
|
||||
function! vimwiki#current_subdir()"{{{
|
||||
return vimwiki#subdir(VimwikiGet('path'), expand('%:p'))
|
||||
function! vimwiki#base#current_subdir()"{{{
|
||||
return vimwiki#base#subdir(VimwikiGet('path'), expand('%:p'))
|
||||
endfunction"}}}
|
||||
|
||||
function! vimwiki#open_link(cmd, link, ...) "{{{
|
||||
if vimwiki#is_non_wiki_link(a:link)
|
||||
call s:edit_file(a:cmd, a:link)
|
||||
function! vimwiki#base#open_link(cmd, link, ...) "{{{
|
||||
if vimwiki#base#is_non_wiki_link(a:link)
|
||||
if s:is_path_absolute(a:link)
|
||||
call vimwiki#base#edit_file(a:cmd, a:link)
|
||||
else
|
||||
call vimwiki#base#edit_file(a:cmd, VimwikiGet('path').a:link)
|
||||
endif
|
||||
else
|
||||
if a:0
|
||||
let vimwiki_prev_link = [a:1, []]
|
||||
@@ -74,17 +95,17 @@ function! vimwiki#open_link(cmd, link, ...) "{{{
|
||||
let vimwiki_prev_link = [expand('%:p'), getpos('.')]
|
||||
endif
|
||||
|
||||
if vimwiki#is_link_to_dir(a:link)
|
||||
if vimwiki#base#is_link_to_dir(a:link)
|
||||
if g:vimwiki_dir_link == ''
|
||||
call s:edit_file(a:cmd, VimwikiGet('path').a:link)
|
||||
call vimwiki#base#edit_file(a:cmd, VimwikiGet('path').a:link)
|
||||
else
|
||||
call s:edit_file(a:cmd,
|
||||
call vimwiki#base#edit_file(a:cmd,
|
||||
\ VimwikiGet('path').a:link.
|
||||
\ g:vimwiki_dir_link.
|
||||
\ VimwikiGet('ext'))
|
||||
endif
|
||||
else
|
||||
call s:edit_file(a:cmd, VimwikiGet('path').a:link.VimwikiGet('ext'))
|
||||
call vimwiki#base#edit_file(a:cmd, VimwikiGet('path').a:link.VimwikiGet('ext'))
|
||||
endif
|
||||
|
||||
if exists('vimwiki_prev_link')
|
||||
@@ -94,7 +115,7 @@ function! vimwiki#open_link(cmd, link, ...) "{{{
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#select(wnum)"{{{
|
||||
function! vimwiki#base#select(wnum)"{{{
|
||||
if a:wnum < 1 || a:wnum > len(g:vimwiki_list)
|
||||
return
|
||||
endif
|
||||
@@ -105,7 +126,7 @@ function! vimwiki#select(wnum)"{{{
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#generate_links()"{{{
|
||||
function! vimwiki#base#generate_links()"{{{
|
||||
let links = s:get_links('*'.VimwikiGet('ext'))
|
||||
|
||||
" We don't want link to itself.
|
||||
@@ -127,8 +148,8 @@ function! vimwiki#generate_links()"{{{
|
||||
endfor
|
||||
endfunction " }}}
|
||||
|
||||
function! vimwiki#goto(key) "{{{
|
||||
call s:edit_file(':e',
|
||||
function! vimwiki#base#goto(key) "{{{
|
||||
call vimwiki#base#edit_file(':e',
|
||||
\ VimwikiGet('path').
|
||||
\ a:key.
|
||||
\ VimwikiGet('ext'))
|
||||
@@ -138,9 +159,13 @@ function! s:is_windows() "{{{
|
||||
return has("win32") || has("win64") || has("win95") || has("win16")
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_path_absolute(path) "{{{
|
||||
return a:path =~ '^/.*' || a:path =~ '^[[:alpha:]]:[/\\].*'
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_links(pat) "{{{
|
||||
" search all wiki files in 'path' and its subdirs.
|
||||
let subdir = vimwiki#current_subdir()
|
||||
let subdir = vimwiki#base#current_subdir()
|
||||
|
||||
" if current wiki is temporary -- was added by an arbitrary wiki file then do
|
||||
" not search wiki files in subdirectories. Or it would hang the system if
|
||||
@@ -173,11 +198,11 @@ function! s:cursor(lnum, cnum) "{{{
|
||||
endfunction "}}}
|
||||
|
||||
function! s:filename(link) "{{{
|
||||
let result = vimwiki#safe_link(a:link)
|
||||
let result = vimwiki#base#safe_link(a:link)
|
||||
if a:link =~ '|'
|
||||
let result = vimwiki#safe_link(split(a:link, '|')[0])
|
||||
let result = vimwiki#base#safe_link(split(a:link, '|')[0])
|
||||
elseif a:link =~ ']['
|
||||
let result = vimwiki#safe_link(split(a:link, '][')[0])
|
||||
let result = vimwiki#base#safe_link(split(a:link, '][')[0])
|
||||
endif
|
||||
return result
|
||||
endfunction
|
||||
@@ -191,10 +216,15 @@ function! s:is_wiki_word(str) "{{{
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! s:edit_file(command, filename) "{{{
|
||||
function! vimwiki#base#edit_file(command, filename) "{{{
|
||||
let fname = escape(a:filename, '% ')
|
||||
call vimwiki#mkdir(fnamemodify(a:filename, ":p:h"))
|
||||
execute a:command.' '.fname
|
||||
call vimwiki#base#mkdir(fnamemodify(a:filename, ":p:h"))
|
||||
try
|
||||
execute a:command.' '.fname
|
||||
catch /E37/ " catch 'No write since last change' error
|
||||
execute ':split '.fname
|
||||
catch /E325/ " catch 'ATTENTION' error (:h E325)
|
||||
endtry
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
@@ -242,13 +272,13 @@ function! s:strip_word(word) "{{{
|
||||
let w = split(w, "][")[0]
|
||||
endif
|
||||
|
||||
let result = vimwiki#safe_link(w)
|
||||
let result = vimwiki#base#safe_link(w)
|
||||
endif
|
||||
return result
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#is_non_wiki_link(lnk) "{{{
|
||||
function! vimwiki#base#is_non_wiki_link(lnk) "{{{
|
||||
let exts = '.\+\.\%('.
|
||||
\ join(split(g:vimwiki_file_exts, '\s*,\s*'), '\|').
|
||||
\ '\)$'
|
||||
@@ -258,7 +288,7 @@ function! vimwiki#is_non_wiki_link(lnk) "{{{
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#is_link_to_dir(link) "{{{
|
||||
function! vimwiki#base#is_link_to_dir(link) "{{{
|
||||
" Check if link is to a directory.
|
||||
" It should be ended with \ or /.
|
||||
if a:link =~ '.\+[/\\]$'
|
||||
@@ -314,10 +344,10 @@ function! s:update_wiki_links_dir(dir, old_fname, new_fname) " {{{
|
||||
endif
|
||||
|
||||
if !s:is_wiki_word(old_fname)
|
||||
let old_fname_r = '\[\[\zs'.vimwiki#unsafe_link(old_fname).
|
||||
let old_fname_r = '\[\[\zs'.vimwiki#base#unsafe_link(old_fname).
|
||||
\ '\ze\%(|.*\)\?\%(\]\[.*\)\?\]\]'
|
||||
else
|
||||
let old_fname_r = '\<'.old_fname.'\>'
|
||||
let old_fname_r = '!\@<!\<'.old_fname.'\>'
|
||||
endif
|
||||
|
||||
let files = split(glob(VimwikiGet('path').a:dir.'*'.VimwikiGet('ext')), '\n')
|
||||
@@ -383,7 +413,7 @@ function! s:get_wiki_buffers() "{{{
|
||||
endfunction " }}}
|
||||
|
||||
function! s:open_wiki_buffer(item) "{{{
|
||||
call s:edit_file('e', a:item[0])
|
||||
call vimwiki#base#edit_file(':e', a:item[0])
|
||||
if !empty(a:item[1])
|
||||
call setbufvar(a:item[0], "vimwiki_prev_link", a:item[1])
|
||||
endif
|
||||
@@ -392,7 +422,7 @@ endfunction " }}}
|
||||
" }}}
|
||||
|
||||
" SYNTAX highlight {{{
|
||||
function! vimwiki#highlight_links() "{{{
|
||||
function! vimwiki#base#highlight_links() "{{{
|
||||
try
|
||||
syntax clear VimwikiNoExistsLink
|
||||
syntax clear VimwikiNoExistsLinkT
|
||||
@@ -442,21 +472,21 @@ function! s:highlight_existed_links() "{{{
|
||||
|
||||
for link in links
|
||||
if g:vimwiki_camel_case &&
|
||||
\ link =~ g:vimwiki_rxWikiWord && !vimwiki#is_non_wiki_link(link)
|
||||
\ link =~ g:vimwiki_rxWikiWord && !vimwiki#base#is_non_wiki_link(link)
|
||||
execute 'syntax match VimwikiLink /!\@<!\<'.link.'\>/ display'
|
||||
endif
|
||||
execute 'syntax match VimwikiLink /\[\['.
|
||||
\ escape(vimwiki#unsafe_link(link), '~&$.*').
|
||||
\ escape(vimwiki#base#unsafe_link(link), '~&$.*').
|
||||
\ '\%(|\+.\{-}\)\{-}\]\]/ display contains=VimwikiLinkChar'
|
||||
execute 'syntax match VimwikiLink /\[\['.
|
||||
\ escape(vimwiki#unsafe_link(link), '~&$.*').
|
||||
\ escape(vimwiki#base#unsafe_link(link), '~&$.*').
|
||||
\ '\]\[.\{-1,}\]\]/ display contains=VimwikiLinkChar'
|
||||
|
||||
execute 'syntax match VimwikiLinkT /\[\['.
|
||||
\ escape(vimwiki#unsafe_link(link), '~&$.*').
|
||||
\ escape(vimwiki#base#unsafe_link(link), '~&$.*').
|
||||
\ '\%(|\+.\{-}\)\{-}\]\]/ display contained'
|
||||
execute 'syntax match VimwikiLinkT /\[\['.
|
||||
\ escape(vimwiki#unsafe_link(link), '~&$.*').
|
||||
\ escape(vimwiki#base#unsafe_link(link), '~&$.*').
|
||||
\ '\]\[.\{-1,}\]\]/ display contained'
|
||||
endfor
|
||||
execute 'syntax match VimwikiLink /\[\[.\+\.\%(jpg\|png\|gif\)\%(|\+.*\)*\]\]/ display contains=VimwikiLinkChar'
|
||||
@@ -485,76 +515,22 @@ function! s:highlight_existed_links() "{{{
|
||||
call map(dirs, 'substitute(v:val, os_p, os_p2, "g")')
|
||||
for dir in dirs
|
||||
execute 'syntax match VimwikiLink /\[\['.
|
||||
\ escape(vimwiki#unsafe_link(dir), '~&$.*').
|
||||
\ escape(vimwiki#base#unsafe_link(dir), '~&$.*').
|
||||
\ '[/\\]*\%(|\+.*\)*\]\]/ display contains=VimwikiLinkChar'
|
||||
execute 'syntax match VimwikiLink /\[\['.
|
||||
\ escape(vimwiki#unsafe_link(dir), '~&$.*').
|
||||
\ escape(vimwiki#base#unsafe_link(dir), '~&$.*').
|
||||
\ '[/\\]*\%(\]\[\+.*\)*\]\]/ display contains=VimwikiLinkChar'
|
||||
|
||||
execute 'syntax match VimwikiLinkT /\[\['.
|
||||
\ escape(vimwiki#unsafe_link(dir), '~&$.*').
|
||||
\ escape(vimwiki#base#unsafe_link(dir), '~&$.*').
|
||||
\ '[/\\]*\%(|\+.*\)*\]\]/ display contained'
|
||||
execute 'syntax match VimwikiLinkT /\[\['.
|
||||
\ escape(vimwiki#unsafe_link(dir), '~&$.*').
|
||||
\ escape(vimwiki#base#unsafe_link(dir), '~&$.*').
|
||||
\ '[/\\]*\%(\]\[\+.*\)*\]\]/ display contained'
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#setup_colors() "{{{
|
||||
|
||||
function! s:set_visible_ignore_color() "{{{
|
||||
if !exists("g:colors_name") || g:colors_name == 'default'
|
||||
if &background == 'light'
|
||||
hi VimwikiIgnore guifg=#d0d0d0
|
||||
else
|
||||
hi VimwikiIgnore guifg=#505050
|
||||
endif
|
||||
else
|
||||
hi link VimwikiIgnore Normal
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
let hlfg_ignore = vimwiki#get_hl_param('Ignore', 'guifg')
|
||||
let hlbg_normal = vimwiki#get_hl_param('Normal', 'guibg')
|
||||
if hlfg_ignore == 'bg' || hlfg_ignore == hlbg_normal
|
||||
call s:set_visible_ignore_color()
|
||||
else
|
||||
hi link VimwikiIgnore Ignore
|
||||
endif
|
||||
|
||||
if g:vimwiki_hl_headers == 0
|
||||
hi def link VimwikiHeader Title
|
||||
return
|
||||
endif
|
||||
|
||||
if &background == 'light'
|
||||
hi def VimwikiHeader1 guibg=bg guifg=#aa5858 gui=bold ctermfg=DarkRed
|
||||
hi def VimwikiHeader2 guibg=bg guifg=#507030 gui=bold ctermfg=DarkGreen
|
||||
hi def VimwikiHeader3 guibg=bg guifg=#1030a0 gui=bold ctermfg=DarkBlue
|
||||
hi def VimwikiHeader4 guibg=bg guifg=#103040 gui=bold ctermfg=Black
|
||||
hi def VimwikiHeader5 guibg=bg guifg=#505050 gui=bold ctermfg=Black
|
||||
hi def VimwikiHeader6 guibg=bg guifg=#636363 gui=bold ctermfg=Black
|
||||
else
|
||||
hi def VimwikiHeader1 guibg=bg guifg=#e08090 gui=bold ctermfg=Red
|
||||
hi def VimwikiHeader2 guibg=bg guifg=#80e090 gui=bold ctermfg=Green
|
||||
hi def VimwikiHeader3 guibg=bg guifg=#6090e0 gui=bold ctermfg=Blue
|
||||
hi def VimwikiHeader4 guibg=bg guifg=#c0c0f0 gui=bold ctermfg=White
|
||||
hi def VimwikiHeader5 guibg=bg guifg=#e0e0f0 gui=bold ctermfg=White
|
||||
hi def VimwikiHeader6 guibg=bg guifg=#f0f0f0 gui=bold ctermfg=White
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function vimwiki#get_hl_param(hgroup, hparam) "{{{
|
||||
redir => hlstatus
|
||||
try
|
||||
exe "silent hi ".a:hgroup
|
||||
catch /E411/
|
||||
endtry
|
||||
redir END
|
||||
return matchstr(hlstatus, a:hparam.'\s*=\s*\zs\S\+')
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#hl_exists(hl) "{{{
|
||||
function! vimwiki#base#hl_exists(hl) "{{{
|
||||
if !hlexists(a:hl)
|
||||
return 0
|
||||
endif
|
||||
@@ -565,7 +541,7 @@ function! vimwiki#hl_exists(hl) "{{{
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#nested_syntax(filetype, start, end, textSnipHl) abort "{{{
|
||||
function! vimwiki#base#nested_syntax(filetype, start, end, textSnipHl) abort "{{{
|
||||
" From http://vim.wikia.com/wiki/VimTip857
|
||||
let ft=toupper(a:filetype)
|
||||
let group='textGroup'.ft
|
||||
@@ -615,21 +591,23 @@ endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" WIKI functions {{{
|
||||
function! vimwiki#find_next_link() "{{{
|
||||
function! vimwiki#base#find_next_link() "{{{
|
||||
call s:search_word(g:vimwiki_rxWikiLink.'\|'.g:vimwiki_rxWeblink, '')
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#find_prev_link() "{{{
|
||||
function! vimwiki#base#find_prev_link() "{{{
|
||||
call s:search_word(g:vimwiki_rxWikiLink.'\|'.g:vimwiki_rxWeblink, 'b')
|
||||
endfunction
|
||||
" }}}
|
||||
|
||||
function! vimwiki#follow_link(split) "{{{
|
||||
function! vimwiki#base#follow_link(split) "{{{
|
||||
if a:split == "split"
|
||||
let cmd = ":split "
|
||||
elseif a:split == "vsplit"
|
||||
let cmd = ":vsplit "
|
||||
elseif a:split == "tabnew"
|
||||
let cmd = ":tabnew "
|
||||
else
|
||||
let cmd = ":e "
|
||||
endif
|
||||
@@ -645,12 +623,12 @@ function! vimwiki#follow_link(split) "{{{
|
||||
return
|
||||
endif
|
||||
|
||||
let subdir = vimwiki#current_subdir()
|
||||
call vimwiki#open_link(cmd, subdir.link)
|
||||
let subdir = vimwiki#base#current_subdir()
|
||||
call vimwiki#base#open_link(cmd, subdir.link)
|
||||
|
||||
endfunction " }}}
|
||||
|
||||
function! vimwiki#go_back_link() "{{{
|
||||
function! vimwiki#base#go_back_link() "{{{
|
||||
if exists("b:vimwiki_prev_link")
|
||||
" go back to saved WikiWord
|
||||
let prev_word = b:vimwiki_prev_link
|
||||
@@ -659,23 +637,13 @@ function! vimwiki#go_back_link() "{{{
|
||||
endif
|
||||
endfunction " }}}
|
||||
|
||||
function! vimwiki#goto_index(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
|
||||
execute ':split '.
|
||||
\ VimwikiGet('path').
|
||||
\ VimwikiGet('index').
|
||||
\ VimwikiGet('ext')
|
||||
catch /E325/ " catch 'ATTENTION' error (:h E325)
|
||||
endtry
|
||||
function! vimwiki#base#goto_index(index) "{{{
|
||||
call vimwiki#base#select(a:index)
|
||||
call vimwiki#base#edit_file('e',
|
||||
\ VimwikiGet('path').VimwikiGet('index').VimwikiGet('ext'))
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#delete_link() "{{{
|
||||
function! vimwiki#base#delete_link() "{{{
|
||||
"" file system funcs
|
||||
"" Delete WikiWord you are in from filesystem
|
||||
let val = input('Delete ['.expand('%').'] (y/n)? ', "")
|
||||
@@ -697,9 +665,9 @@ function! vimwiki#delete_link() "{{{
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#rename_link() "{{{
|
||||
function! vimwiki#base#rename_link() "{{{
|
||||
"" Rename WikiWord, update all links to renamed WikiWord
|
||||
let subdir = vimwiki#current_subdir()
|
||||
let subdir = vimwiki#base#current_subdir()
|
||||
let old_fname = subdir.expand('%:t')
|
||||
|
||||
" there is no file (new one maybe)
|
||||
@@ -727,7 +695,7 @@ function! vimwiki#rename_link() "{{{
|
||||
echomsg 'vimwiki: Cannot rename to an empty filename!'
|
||||
return
|
||||
endif
|
||||
if vimwiki#is_non_wiki_link(new_link)
|
||||
if vimwiki#base#is_non_wiki_link(new_link)
|
||||
echomsg 'vimwiki: Cannot rename to a filename with extension (ie .txt .html)!'
|
||||
return
|
||||
endif
|
||||
@@ -797,13 +765,13 @@ function! vimwiki#rename_link() "{{{
|
||||
let &more = setting_more
|
||||
endfunction " }}}
|
||||
|
||||
function! vimwiki#ui_select()"{{{
|
||||
function! vimwiki#base#ui_select()"{{{
|
||||
call s:print_wiki_list()
|
||||
let idx = input("Select Wiki (specify number): ")
|
||||
if idx == ""
|
||||
return
|
||||
endif
|
||||
call vimwiki#goto_index(idx)
|
||||
call vimwiki#base#goto_index(idx)
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
@@ -811,7 +779,7 @@ endfunction
|
||||
|
||||
" TEXT OBJECTS functions {{{
|
||||
|
||||
function! vimwiki#TO_header(inner, visual) "{{{
|
||||
function! vimwiki#base#TO_header(inner, visual) "{{{
|
||||
if !search('^\(=\+\).\+\1\s*$', 'bcW')
|
||||
return
|
||||
endif
|
||||
@@ -821,7 +789,7 @@ function! vimwiki#TO_header(inner, visual) "{{{
|
||||
let block_start = line(".")
|
||||
let advance = 0
|
||||
|
||||
let level = vimwiki#count_first_sym(getline('.'))
|
||||
let level = vimwiki#base#count_first_sym(getline('.'))
|
||||
|
||||
let is_header_selected = sel_start == block_start
|
||||
\ && sel_start != sel_end
|
||||
@@ -854,7 +822,7 @@ function! vimwiki#TO_header(inner, visual) "{{{
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#TO_table_cell(inner, visual) "{{{
|
||||
function! vimwiki#base#TO_table_cell(inner, visual) "{{{
|
||||
if col('.') == col('$')-1
|
||||
return
|
||||
endif
|
||||
@@ -918,7 +886,7 @@ function! vimwiki#TO_table_cell(inner, visual) "{{{
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#TO_table_col(inner, visual) "{{{
|
||||
function! vimwiki#base#TO_table_col(inner, visual) "{{{
|
||||
let t_rows = vimwiki_tbl#get_rows(line('.'))
|
||||
if empty(t_rows)
|
||||
return
|
||||
@@ -1032,12 +1000,12 @@ function! vimwiki#TO_table_col(inner, visual) "{{{
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#count_first_sym(line) "{{{
|
||||
function! vimwiki#base#count_first_sym(line) "{{{
|
||||
let first_sym = matchstr(a:line, '\S')
|
||||
return len(matchstr(a:line, first_sym.'\+'))
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#AddHeaderLevel() "{{{
|
||||
function! vimwiki#base#AddHeaderLevel() "{{{
|
||||
let lnum = line('.')
|
||||
let line = getline(lnum)
|
||||
|
||||
@@ -1046,7 +1014,7 @@ function! vimwiki#AddHeaderLevel() "{{{
|
||||
endif
|
||||
|
||||
if line =~ '^\s*\(=\+\).\+\1\s*$'
|
||||
let level = vimwiki#count_first_sym(line)
|
||||
let level = vimwiki#base#count_first_sym(line)
|
||||
if level < 6
|
||||
let line = substitute(line, '\(=\+\).\+\1', '=&=', '')
|
||||
call setline(lnum, line)
|
||||
@@ -1059,7 +1027,7 @@ function! vimwiki#AddHeaderLevel() "{{{
|
||||
endfunction
|
||||
"}}}
|
||||
|
||||
function! vimwiki#RemoveHeaderLevel() "{{{
|
||||
function! vimwiki#base#RemoveHeaderLevel() "{{{
|
||||
let lnum = line('.')
|
||||
let line = getline(lnum)
|
||||
|
||||
@@ -1068,7 +1036,7 @@ function! vimwiki#RemoveHeaderLevel() "{{{
|
||||
endif
|
||||
|
||||
if line =~ '^\s*\(=\+\).\+\1\s*$'
|
||||
let level = vimwiki#count_first_sym(line)
|
||||
let level = vimwiki#base#count_first_sym(line)
|
||||
let old = repeat('=', level)
|
||||
let new = repeat('=', level - 1)
|
||||
|
||||
11
autoload/vimwiki/default.tpl
Normal file
11
autoload/vimwiki/default.tpl
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<link rel="Stylesheet" type="text/css" href="%root_path%%css%">
|
||||
<title>%title%</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=%encoding%">
|
||||
</head>
|
||||
<body>
|
||||
%content%
|
||||
</body>
|
||||
</html>
|
||||
@@ -197,19 +197,24 @@ function! s:make_date_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'))
|
||||
function! vimwiki#diary#make_note(index, ...) "{{{
|
||||
call vimwiki#base#select(a:index)
|
||||
call vimwiki#base#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())
|
||||
call vimwiki#base#open_link(':e ', link, s:diary_index())
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki#diary#goto_index(index) "{{{
|
||||
call vimwiki#base#select(a:index)
|
||||
call vimwiki#base#edit_file(':e', s:diary_index())
|
||||
endfunction "}}}
|
||||
|
||||
" Calendar.vim callback function.
|
||||
function! vimwiki_diary#calendar_action(day, month, year, week, dir) "{{{
|
||||
function! vimwiki#diary#calendar_action(day, month, year, week, dir) "{{{
|
||||
let day = s:prefix_zero(a:day)
|
||||
let month = s:prefix_zero(a:month)
|
||||
|
||||
@@ -228,11 +233,11 @@ function! vimwiki_diary#calendar_action(day, month, year, week, dir) "{{{
|
||||
endif
|
||||
|
||||
" Create diary note for a selected date in default wiki.
|
||||
call vimwiki_diary#make_note(1, link)
|
||||
call vimwiki#diary#make_note(1, link)
|
||||
endfunction "}}}
|
||||
|
||||
" Calendar.vim sign function.
|
||||
function vimwiki_diary#calendar_sign(day, month, year) "{{{
|
||||
function vimwiki#diary#calendar_sign(day, month, year) "{{{
|
||||
let day = s:prefix_zero(a:day)
|
||||
let month = s:prefix_zero(a:month)
|
||||
let sfile = VimwikiGet('path').VimwikiGet('diary_rel_path').
|
||||
@@ -240,7 +245,7 @@ function vimwiki_diary#calendar_sign(day, month, year) "{{{
|
||||
return filereadable(expand(sfile))
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_diary#goto_next_day() "{{{
|
||||
function! vimwiki#diary#goto_next_day() "{{{
|
||||
let link = ''
|
||||
let [idx, links] = s:get_position_links(expand('%:t:r'))
|
||||
|
||||
@@ -256,11 +261,11 @@ function! vimwiki_diary#goto_next_day() "{{{
|
||||
endif
|
||||
|
||||
if len(link)
|
||||
call vimwiki#open_link(':e ', link)
|
||||
call vimwiki#base#open_link(':e ', link)
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_diary#goto_prev_day() "{{{
|
||||
function! vimwiki#diary#goto_prev_day() "{{{
|
||||
let link = ''
|
||||
let [idx, links] = s:get_position_links(expand('%:t:r'))
|
||||
|
||||
@@ -276,6 +281,6 @@ function! vimwiki_diary#goto_prev_day() "{{{
|
||||
endif
|
||||
|
||||
if len(link)
|
||||
call vimwiki#open_link(':e ', link)
|
||||
call vimwiki#base#open_link(':e ', link)
|
||||
endif
|
||||
endfunction "}}}
|
||||
@@ -13,12 +13,6 @@ endif
|
||||
let g:loaded_vimwiki_html_auto = 1
|
||||
"}}}
|
||||
|
||||
" SCRIPT VARS "{{{
|
||||
" Warn if html header or html footer do not exist only once.
|
||||
let s:warn_html_header = 0
|
||||
let s:warn_html_footer = 0
|
||||
"}}}
|
||||
|
||||
" UTILITY "{{{
|
||||
function! s:root_path(subdir) "{{{
|
||||
return repeat('../', len(split(a:subdir, '[/\\]')))
|
||||
@@ -35,7 +29,7 @@ function! s:remove_blank_lines(lines) " {{{
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_web_link(lnk) "{{{
|
||||
if a:lnk =~ '^\%(https://\|http://\|www.\|ftp://\|file://\)'
|
||||
if a:lnk =~ '^\%(https://\|http://\|www.\|ftp://\|file://\|mailto:\)'
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
@@ -55,104 +49,69 @@ function! s:has_abs_path(fname) "{{{
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
function! s:find_autoload_file(name) " {{{
|
||||
for path in split(&runtimepath, ',')
|
||||
let fname = path.'/autoload/vimwiki/'.a:name
|
||||
if glob(fname) != ''
|
||||
return fname
|
||||
endif
|
||||
endfor
|
||||
return ''
|
||||
endfunction " }}}
|
||||
|
||||
function! s:create_default_CSS(path) " {{{
|
||||
let path = expand(a:path)
|
||||
let css_full_name = path.VimwikiGet('css_name')
|
||||
if glob(css_full_name) == ""
|
||||
call vimwiki#mkdir(fnamemodify(css_full_name, ':p:h'))
|
||||
let lines = []
|
||||
|
||||
call add(lines, 'body {font-family: Tahoma, sans-serif; margin: 1em 2em 1em 2em; font-size: 100%; line-height: 130%;}')
|
||||
call add(lines, 'h1, h2, h3, h4, h5, h6 {font-family: Trebuchet MS, serif; margin-top: 1.5em; margin-bottom: 0.5em;}')
|
||||
call add(lines, 'h1 {font-size: 2.0em; color: #a77070;}')
|
||||
call add(lines, 'h2 {font-size: 1.6em; color: #779977;}')
|
||||
call add(lines, 'h3 {font-size: 1.3em; color: #555577;}')
|
||||
call add(lines, 'h4 {font-size: 1.2em; color: #222244;}')
|
||||
call add(lines, 'h5 {font-size: 1.1em; color: #222244;}')
|
||||
call add(lines, 'h6 {font-size: 1.0em; color: #222244;}')
|
||||
call add(lines, 'p, pre, blockquote, table, ul, ol, dl {margin-top: 1em; margin-bottom: 1em;}')
|
||||
call add(lines, 'ul ul, ul ol, ol ol, ol ul {margin-top: 0.5em; margin-bottom: 0.5em;}')
|
||||
call add(lines, 'li {margin: 0.3em auto;}')
|
||||
call add(lines, 'ul {margin-left: 2em; padding-left: 0.5em;}')
|
||||
call add(lines, 'dt {font-weight: bold;}')
|
||||
call add(lines, 'img {border: none;}')
|
||||
call add(lines, 'pre {border-left: 1px solid #ccc; margin-left: 2em; padding-left: 0.5em;}')
|
||||
call add(lines, 'blockquote {padding: 0.4em; background-color: #f6f5eb;}')
|
||||
call add(lines, 'th, td {border: 1px solid #ccc; padding: 0.3em;}')
|
||||
call add(lines, 'th {background-color: #f0f0f0;}')
|
||||
call add(lines, 'hr {border: none; border-top: 1px solid #ccc; width: 100%;}')
|
||||
call add(lines, 'del {text-decoration: line-through; color: #777777;}')
|
||||
call add(lines, '.toc li {list-style-type: none;}')
|
||||
call add(lines, '.todo {font-weight: bold; background-color: #f0ece8; color: #a03020;}')
|
||||
call add(lines, '.justleft {text-align: left;}')
|
||||
call add(lines, '.justright {text-align: right;}')
|
||||
call add(lines, '.justcenter {text-align: center;}')
|
||||
call add(lines, '.center {margin-left: auto; margin-right: auto;}')
|
||||
|
||||
call writefile(lines, css_full_name)
|
||||
echomsg "Default style.css is created."
|
||||
call vimwiki#base#mkdir(fnamemodify(css_full_name, ':p:h'))
|
||||
let default_css = s:find_autoload_file('style.css')
|
||||
if default_css != ''
|
||||
let lines = readfile(default_css)
|
||||
call writefile(lines, css_full_name)
|
||||
echomsg "Default style.css has been created."
|
||||
endif
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_html_header(title, subdir, charset) "{{{
|
||||
function! s:template_full_name(name) "{{{
|
||||
if a:name == ''
|
||||
let name = VimwikiGet('template_default')
|
||||
else
|
||||
let name = a:name
|
||||
endif
|
||||
|
||||
let fname = expand(VimwikiGet('template_path').
|
||||
\name.
|
||||
\VimwikiGet('template_ext'))
|
||||
|
||||
if filereadable(fname)
|
||||
return fname
|
||||
else
|
||||
return ''
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_html_template(wikifile, template) "{{{
|
||||
" TODO: refactor it!!!
|
||||
let lines=[]
|
||||
|
||||
if VimwikiGet('html_header') != "" && !s:warn_html_header
|
||||
let template_name = s:template_full_name(a:template)
|
||||
if template_name != ''
|
||||
try
|
||||
let lines = readfile(expand(VimwikiGet('html_header')))
|
||||
call map(lines, 'substitute(v:val, "%title%", "'. a:title .'", "g")')
|
||||
call map(lines, 'substitute(v:val, "%root_path%", "'.
|
||||
\ s:root_path(a:subdir) .'", "g")')
|
||||
let lines = readfile(template_name)
|
||||
return lines
|
||||
catch /E484/
|
||||
let s:warn_html_header = 1
|
||||
echomsg 'vimwiki: Header template '.VimwikiGet('html_header').
|
||||
echomsg 'vimwiki: html template '.template_name.
|
||||
\ ' does not exist!'
|
||||
endtry
|
||||
endif
|
||||
|
||||
let css_name = expand(VimwikiGet('css_name'))
|
||||
let css_name = substitute(css_name, '\', '/', 'g')
|
||||
if !s:has_abs_path(css_name)
|
||||
" Relative css file for deep links: [[dir1/dir2/dir3/filename]]
|
||||
let css_name = s:root_path(a:subdir).css_name
|
||||
" if no VimwikiGet('html_template') set up or error while reading template
|
||||
" file -- use default one.
|
||||
let default_tpl = s:find_autoload_file('default.tpl')
|
||||
if default_tpl != ''
|
||||
let lines = readfile(default_tpl)
|
||||
endif
|
||||
|
||||
" if no VimwikiGet('html_header') set up or error while reading template
|
||||
" file -- use default header.
|
||||
call add(lines, '<html>')
|
||||
call add(lines, '<head>')
|
||||
call add(lines, '<link rel="Stylesheet" type="text/css" href="'.
|
||||
\ css_name.'" />')
|
||||
call add(lines, '<title>'.a:title.'</title>')
|
||||
call add(lines, '<meta http-equiv="Content-Type" content="text/html;'.
|
||||
\ ' charset='.a:charset.'" />')
|
||||
call add(lines, '</head>')
|
||||
call add(lines, '<body>')
|
||||
|
||||
return lines
|
||||
endfunction "}}}
|
||||
|
||||
function! s:get_html_footer() "{{{
|
||||
let lines=[]
|
||||
|
||||
if VimwikiGet('html_footer') != "" && !s:warn_html_footer
|
||||
try
|
||||
let lines = readfile(expand(VimwikiGet('html_footer')))
|
||||
return lines
|
||||
catch /E484/
|
||||
let s:warn_html_footer = 1
|
||||
echomsg 'vimwiki: Footer template '.VimwikiGet('html_footer').
|
||||
\ ' does not exist!'
|
||||
endtry
|
||||
endif
|
||||
|
||||
" if no VimwikiGet('html_footer') set up or error while reading template
|
||||
" file -- use default footer.
|
||||
call add(lines, "")
|
||||
call add(lines, '</body>')
|
||||
call add(lines, '</html>')
|
||||
|
||||
return lines
|
||||
endfunction "}}}
|
||||
|
||||
@@ -174,6 +133,19 @@ endfunction "}}}
|
||||
function! s:delete_html_files(path) "{{{
|
||||
let htmlfiles = split(glob(a:path.'**/*.html'), '\n')
|
||||
for fname in htmlfiles
|
||||
" ignore user html files, e.g. search.html,404.html
|
||||
if stridx(g:vimwiki_user_htmls, fnamemodify(fname, ":t")) >= 0
|
||||
continue
|
||||
endif
|
||||
|
||||
" delete if there is no corresponding wiki file
|
||||
let subdir = vimwiki#base#subdir(VimwikiGet('path_html'), fname)
|
||||
let wikifile = VimwikiGet("path").subdir.
|
||||
\fnamemodify(fname, ":t:r").VimwikiGet("ext")
|
||||
if filereadable(wikifile)
|
||||
continue
|
||||
endif
|
||||
|
||||
try
|
||||
call delete(fname)
|
||||
catch
|
||||
@@ -182,45 +154,6 @@ function! s:delete_html_files(path) "{{{
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! s:remove_comments(lines) "{{{
|
||||
let res = []
|
||||
let multiline_comment = 0
|
||||
|
||||
let idx = 0
|
||||
while idx < len(a:lines)
|
||||
let line = a:lines[idx]
|
||||
let idx += 1
|
||||
|
||||
if multiline_comment
|
||||
let col = matchend(line, '-->',)
|
||||
if col != -1
|
||||
let multiline_comment = 0
|
||||
let line = strpart(line, col)
|
||||
else
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
|
||||
if !multiline_comment && line =~ '<!--.*-->'
|
||||
let line = substitute(line, '<!--.*-->', '', 'g')
|
||||
if line =~ '^\s*$'
|
||||
continue
|
||||
endif
|
||||
endif
|
||||
|
||||
if !multiline_comment
|
||||
let col = match(line, '<!--',)
|
||||
if col != -1
|
||||
let multiline_comment = 1
|
||||
let line = strpart(line, 1, col - 1)
|
||||
endif
|
||||
endif
|
||||
|
||||
call add(res, line)
|
||||
endwhile
|
||||
return res
|
||||
endfunction "}}}
|
||||
|
||||
function! s:mid(value, cnt) "{{{
|
||||
return strpart(a:value, a:cnt, len(a:value) - 2 * a:cnt)
|
||||
endfunction "}}}
|
||||
@@ -283,7 +216,7 @@ function! s:get_html_toc(toc_list) "{{{
|
||||
|
||||
let toc_text = s:process_tags_remove_links(text)
|
||||
let toc_text = s:process_tags_typefaces(toc_text)
|
||||
call add(toc, '<li><a href="#'.id.'">'.toc_text.'</a></li>')
|
||||
call add(toc, '<li><a href="#'.id.'">'.toc_text.'</a>')
|
||||
let plevel = level
|
||||
endfor
|
||||
call s:close_list(toc, level, 0)
|
||||
@@ -293,6 +226,7 @@ endfunction "}}}
|
||||
|
||||
" insert toc into dest.
|
||||
function! s:process_toc(dest, placeholders, toc) "{{{
|
||||
let toc_idx = 0
|
||||
if !empty(a:placeholders)
|
||||
for [placeholder, row, idx] in a:placeholders
|
||||
let [type, param] = placeholder
|
||||
@@ -301,8 +235,9 @@ function! s:process_toc(dest, placeholders, toc) "{{{
|
||||
if !empty(param)
|
||||
call insert(toc, '<h1>'.param.'</h1>')
|
||||
endif
|
||||
let shift = idx * len(toc)
|
||||
let shift = toc_idx * len(toc)
|
||||
call extend(a:dest, toc, row + shift)
|
||||
let toc_idx += 1
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
@@ -321,6 +256,46 @@ function! s:process_title(placeholders, default_title) "{{{
|
||||
return a:default_title
|
||||
endfunction "}}}
|
||||
|
||||
function! s:is_html_uptodate(wikifile) "{{{
|
||||
let tpl_time = -1
|
||||
|
||||
let tpl_file = s:template_full_name('')
|
||||
if tpl_file != ''
|
||||
let tpl_time = getftime(tpl_file)
|
||||
endif
|
||||
|
||||
let wikifile = fnamemodify(a:wikifile, ":p")
|
||||
let subdir = vimwiki#base#subdir(VimwikiGet('path'), wikifile)
|
||||
let htmlfile = expand(VimwikiGet('path_html').subdir.
|
||||
\fnamemodify(wikifile, ":t:r").".html")
|
||||
|
||||
if getftime(wikifile) <= getftime(htmlfile) && tpl_time <= getftime(htmlfile)
|
||||
return 1
|
||||
endif
|
||||
return 0
|
||||
endfunction "}}}
|
||||
|
||||
function! s:html_insert_contents(html_lines, content) "{{{
|
||||
let lines = []
|
||||
for line in a:html_lines
|
||||
if line =~ '%content%'
|
||||
let parts = split(line, '%content%', 1)
|
||||
if empty(parts)
|
||||
call extend(lines, a:content)
|
||||
else
|
||||
for idx in range(len(parts))
|
||||
call add(lines, parts[idx])
|
||||
if idx < len(parts) - 1
|
||||
call extend(lines, a:content)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
else
|
||||
call add(lines, line)
|
||||
endif
|
||||
endfor
|
||||
return lines
|
||||
endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" INLINE TAGS "{{{
|
||||
@@ -376,19 +351,19 @@ function! s:tag_internal_link(value) "{{{
|
||||
if s:is_img_link(a:caption)
|
||||
let link = '<a href="'.a:src.'"><img src="'.a:caption.'"'.style_str.' />'.
|
||||
\ '</a>'
|
||||
elseif vimwiki#is_non_wiki_link(a:src)
|
||||
elseif vimwiki#base#is_non_wiki_link(a:src)
|
||||
let link = '<a href="'.a:src.'">'.a:caption.'</a>'
|
||||
elseif s:is_img_link(a:src)
|
||||
let link = '<img src="'.a:src.'" alt="'.a:caption.'"'. style_str.' />'
|
||||
elseif vimwiki#is_link_to_dir(a:src)
|
||||
elseif vimwiki#base#is_link_to_dir(a:src)
|
||||
if g:vimwiki_dir_link == ''
|
||||
let link = '<a href="'.vimwiki#safe_link(a:src).'">'.a:caption.'</a>'
|
||||
let link = '<a href="'.vimwiki#base#safe_link(a:src).'">'.a:caption.'</a>'
|
||||
else
|
||||
let link = '<a href="'.vimwiki#safe_link(a:src).
|
||||
let link = '<a href="'.vimwiki#base#safe_link(a:src).
|
||||
\ g:vimwiki_dir_link.'.html">'.a:caption.'</a>'
|
||||
endif
|
||||
else
|
||||
let link = '<a href="'.vimwiki#safe_link(a:src).
|
||||
let link = '<a href="'.vimwiki#base#safe_link(a:src).
|
||||
\ '.html">'.a:caption.'</a>'
|
||||
endif
|
||||
|
||||
@@ -574,8 +549,6 @@ function! s:process_tags_typefaces(line) "{{{
|
||||
let line = s:make_tag(line, g:vimwiki_rxSuperScript, 's:tag_super')
|
||||
let line = s:make_tag(line, g:vimwiki_rxSubScript, 's:tag_sub')
|
||||
let line = s:make_tag(line, g:vimwiki_rxCode, 's:tag_code')
|
||||
let line = s:make_tag(line, g:vimwiki_rxPreStart.'.\+'.g:vimwiki_rxPreEnd,
|
||||
\ 's:tag_pre')
|
||||
return line
|
||||
endfunction " }}}
|
||||
|
||||
@@ -624,13 +597,100 @@ function! s:close_tag_table(table, ldest) "{{{
|
||||
" The first element of table list is a string which tells us if table should be centered.
|
||||
" The rest elements are rows which are lists of columns:
|
||||
" ['center',
|
||||
" ['col1', 'col2', 'col3'],
|
||||
" ['col1', 'col2', 'col3'],
|
||||
" ['col1', 'col2', 'col3']
|
||||
" [ CELL1, CELL2, CELL3 ],
|
||||
" [ CELL1, CELL2, CELL3 ],
|
||||
" [ CELL1, CELL2, CELL3 ],
|
||||
" ]
|
||||
" And CELLx is: { 'body': 'col_x', 'rowspan': r, 'colspan': c }
|
||||
|
||||
function! s:sum_rowspan(table) "{{{
|
||||
let table = a:table
|
||||
|
||||
" Get max cells
|
||||
let max_cells = 0
|
||||
for row in table[1:]
|
||||
let n_cells = len(row)
|
||||
if n_cells > max_cells
|
||||
let max_cells = n_cells
|
||||
end
|
||||
endfor
|
||||
|
||||
" Sum rowspan
|
||||
for cell_idx in range(max_cells)
|
||||
let rows = 1
|
||||
|
||||
for row_idx in range(len(table)-1, 1, -1)
|
||||
if cell_idx >= len(table[row_idx])
|
||||
let rows = 1
|
||||
continue
|
||||
endif
|
||||
|
||||
if table[row_idx][cell_idx].rowspan == 0
|
||||
let rows += 1
|
||||
else " table[row_idx][cell_idx].rowspan == 1
|
||||
let table[row_idx][cell_idx].rowspan = rows
|
||||
let rows = 1
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! s:sum_colspan(table) "{{{
|
||||
for row in a:table[1:]
|
||||
let cols = 1
|
||||
|
||||
for cell_idx in range(len(row)-1, 0, -1)
|
||||
if row[cell_idx].colspan == 0
|
||||
let cols += 1
|
||||
else "row[cell_idx].colspan == 1
|
||||
let row[cell_idx].colspan = cols
|
||||
let cols = 1
|
||||
endif
|
||||
endfor
|
||||
endfor
|
||||
endfunction "}}}
|
||||
|
||||
function! s:close_tag_row(row, header, ldest) "{{{
|
||||
call add(a:ldest, '<tr>')
|
||||
|
||||
" Set tag element of columns
|
||||
if a:header
|
||||
let tag_name = 'th'
|
||||
else
|
||||
let tag_name = 'td'
|
||||
end
|
||||
|
||||
" Close tag of columns
|
||||
for cell in a:row
|
||||
if cell.rowspan == 0 || cell.colspan == 0
|
||||
continue
|
||||
endif
|
||||
|
||||
if cell.rowspan > 1
|
||||
let rowspan_attr = ' rowspan="' . cell.rowspan . '"'
|
||||
else "cell.rowspan == 1
|
||||
let rowspan_attr = ''
|
||||
endif
|
||||
if cell.colspan > 1
|
||||
let colspan_attr = ' colspan="' . cell.colspan . '"'
|
||||
else "cell.colspan == 1
|
||||
let colspan_attr = ''
|
||||
endif
|
||||
|
||||
call add(a:ldest, '<' . tag_name . rowspan_attr . colspan_attr .'>')
|
||||
call add(a:ldest, s:process_inline_tags(cell.body))
|
||||
call add(a:ldest, '</'. tag_name . '>')
|
||||
endfor
|
||||
|
||||
call add(a:ldest, '</tr>')
|
||||
endfunction "}}}
|
||||
|
||||
let table = a:table
|
||||
let ldest = a:ldest
|
||||
if len(table)
|
||||
call s:sum_rowspan(table)
|
||||
call s:sum_colspan(table)
|
||||
|
||||
if table[0] == 'center'
|
||||
call add(ldest, "<table class='center'>")
|
||||
else
|
||||
@@ -651,21 +711,15 @@ function! s:close_tag_table(table, ldest) "{{{
|
||||
if head > 0
|
||||
for row in table[1 : head-1]
|
||||
if !empty(filter(row, '!empty(v:val)'))
|
||||
call add(ldest, '<tr>')
|
||||
call extend(ldest, map(row, '"<th>".s:process_inline_tags(v:val)."</th>"'))
|
||||
call add(ldest, '</tr>')
|
||||
call s:close_tag_row(row, 1, ldest)
|
||||
endif
|
||||
endfor
|
||||
for row in table[head+1 :]
|
||||
call add(ldest, '<tr>')
|
||||
call extend(ldest, map(row, '"<td>".s:process_inline_tags(v:val)."</td>"'))
|
||||
call add(ldest, '</tr>')
|
||||
call s:close_tag_row(row, 0, ldest)
|
||||
endfor
|
||||
else
|
||||
for row in table[1 :]
|
||||
call add(ldest, '<tr>')
|
||||
call extend(ldest, map(row, '"<td>".s:process_inline_tags(v:val)."</td>"'))
|
||||
call add(ldest, '</tr>')
|
||||
call s:close_tag_row(row, 0, ldest)
|
||||
endfor
|
||||
endif
|
||||
call add(ldest, "</table>")
|
||||
@@ -741,11 +795,15 @@ function! s:process_tag_list(line, lists) "{{{
|
||||
|
||||
let chk = matchlist(a:line, a:rx_list)
|
||||
if len(chk) > 0
|
||||
if chk[1] == g:vimwiki_listsyms[4]
|
||||
let st_tag .= '<del><input type="checkbox" checked />'
|
||||
let en_tag = '</del>'.a:en_tag
|
||||
else
|
||||
let st_tag .= '<input type="checkbox" />'
|
||||
if len(chk[1])>0
|
||||
"wildcard characters are difficult to match correctly
|
||||
if chk[1] =~ '[.*\\^$~]'
|
||||
let chk[1] ='\'.chk[1]
|
||||
endif
|
||||
let completion = match(g:vimwiki_listsyms, '\C' . chk[1])
|
||||
if completion >= 0 && completion <=4
|
||||
let st_tag = '<li class="done'.completion.'">'
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
return [st_tag, en_tag]
|
||||
@@ -790,7 +848,7 @@ function! s:process_tag_list(line, lists) "{{{
|
||||
|
||||
let checkbox = '\s*\[\(.\?\)\]\s*'
|
||||
let [st_tag, en_tag] = s:add_checkbox(line,
|
||||
\ lstRegExp.checkbox, '<li>', '</li>')
|
||||
\ lstRegExp.checkbox, '<li>', '')
|
||||
|
||||
if !in_list
|
||||
call add(a:lists, [lstTagClose, indent])
|
||||
@@ -948,10 +1006,27 @@ endfunction "}}}
|
||||
|
||||
function! s:process_tag_table(line, table) "{{{
|
||||
function! s:table_empty_cell(value) "{{{
|
||||
if a:value =~ '^\s*$'
|
||||
return ' '
|
||||
let cell = {}
|
||||
|
||||
if a:value =~ '^\s*\\/\s*$'
|
||||
let cell.body = ''
|
||||
let cell.rowspan = 0
|
||||
let cell.colspan = 1
|
||||
elseif a:value =~ '^\s*>\s*$'
|
||||
let cell.body = ''
|
||||
let cell.rowspan = 1
|
||||
let cell.colspan = 0
|
||||
elseif a:value =~ '^\s*$'
|
||||
let cell.body = ' '
|
||||
let cell.rowspan = 1
|
||||
let cell.colspan = 1
|
||||
else
|
||||
let cell.body = a:value
|
||||
let cell.rowspan = 1
|
||||
let cell.colspan = 1
|
||||
endif
|
||||
return a:value
|
||||
|
||||
return cell
|
||||
endfunction "}}}
|
||||
|
||||
function! s:table_add_row(table, line) "{{{
|
||||
@@ -1010,6 +1085,12 @@ function! s:parse_line(line, state) " {{{
|
||||
|
||||
let processed = 0
|
||||
|
||||
if !processed
|
||||
if line =~ g:vimwiki_rxComment
|
||||
let processed = 1
|
||||
endif
|
||||
endif
|
||||
|
||||
" nohtml -- placeholder
|
||||
if !processed
|
||||
if line =~ '^\s*%nohtml'
|
||||
@@ -1027,6 +1108,16 @@ function! s:parse_line(line, state) " {{{
|
||||
endif
|
||||
endif
|
||||
|
||||
" html template -- placeholder "{{{
|
||||
if !processed
|
||||
if line =~ '^\s*%template'
|
||||
let processed = 1
|
||||
let param = matchstr(line, '^\s*%template\s\zs.*')
|
||||
let state.placeholder = ['template', param]
|
||||
endif
|
||||
endif
|
||||
"}}}
|
||||
|
||||
" toc -- placeholder "{{{
|
||||
if !processed
|
||||
if line =~ '^\s*%toc'
|
||||
@@ -1093,6 +1184,7 @@ function! s:parse_line(line, state) " {{{
|
||||
let state.table = s:close_tag_table(state.table, res_lines)
|
||||
let state.pre = s:close_tag_pre(state.pre, res_lines)
|
||||
let state.quote = s:close_tag_quote(state.quote, res_lines)
|
||||
let state.para = s:close_tag_para(state.para, res_lines)
|
||||
|
||||
let line = s:process_inline_tags(line)
|
||||
|
||||
@@ -1189,25 +1281,32 @@ function! s:parse_line(line, state) " {{{
|
||||
|
||||
endfunction " }}}
|
||||
|
||||
function! vimwiki_html#Wiki2HTML(path, wikifile) "{{{
|
||||
function! vimwiki#html#Wiki2HTML(path, wikifile) "{{{
|
||||
|
||||
let starttime = reltime() " start the clock
|
||||
echo 'Generating HTML ... '
|
||||
if !s:syntax_supported()
|
||||
echomsg 'vimwiki: Only vimwiki_default syntax supported!!!'
|
||||
return
|
||||
endif
|
||||
|
||||
let wikifile = fnamemodify(a:wikifile, ":p")
|
||||
let subdir = vimwiki#subdir(VimwikiGet('path'), wikifile)
|
||||
|
||||
let lsource = s:remove_comments(readfile(wikifile))
|
||||
let ldest = []
|
||||
let subdir = vimwiki#base#subdir(VimwikiGet('path'), wikifile)
|
||||
|
||||
let path = expand(a:path).subdir
|
||||
call vimwiki#mkdir(path)
|
||||
let htmlfile = fnamemodify(wikifile, ":t:r").'.html'
|
||||
|
||||
let lsource = readfile(wikifile)
|
||||
let ldest = []
|
||||
|
||||
call vimwiki#base#mkdir(path)
|
||||
|
||||
" nohtml placeholder -- to skip html generation.
|
||||
let nohtml = 0
|
||||
|
||||
" template placeholder
|
||||
let template_name = ''
|
||||
|
||||
" for table of contents placeholders.
|
||||
let placeholders = []
|
||||
|
||||
@@ -1238,43 +1337,70 @@ function! vimwiki_html#Wiki2HTML(path, wikifile) "{{{
|
||||
if state.placeholder[0] == 'nohtml'
|
||||
let nohtml = 1
|
||||
break
|
||||
elseif state.placeholder[0] == 'template'
|
||||
let template_name = state.placeholder[1]
|
||||
else
|
||||
call add(placeholders, [state.placeholder, len(ldest), len(placeholders)])
|
||||
let state.placeholder = []
|
||||
endif
|
||||
let state.placeholder = []
|
||||
endif
|
||||
|
||||
call extend(ldest, lines)
|
||||
endfor
|
||||
|
||||
|
||||
if !nohtml
|
||||
let toc = s:get_html_toc(state.toc)
|
||||
call s:process_toc(ldest, placeholders, toc)
|
||||
call s:remove_blank_lines(ldest)
|
||||
|
||||
"" process end of file
|
||||
"" close opened tags if any
|
||||
let lines = []
|
||||
call s:close_tag_quote(state.quote, lines)
|
||||
call s:close_tag_para(state.para, lines)
|
||||
call s:close_tag_pre(state.pre, lines)
|
||||
call s:close_tag_list(state.lists, lines)
|
||||
call s:close_tag_def_list(state.deflist, lines)
|
||||
call s:close_tag_table(state.table, lines)
|
||||
call extend(ldest, lines)
|
||||
|
||||
let title = s:process_title(placeholders, fnamemodify(a:wikifile, ":t:r"))
|
||||
call extend(ldest, s:get_html_header(title, subdir, &fileencoding), 0)
|
||||
call extend(ldest, s:get_html_footer())
|
||||
|
||||
"" make html file.
|
||||
let wwFileNameOnly = fnamemodify(wikifile, ":t:r")
|
||||
call writefile(ldest, path.wwFileNameOnly.'.html')
|
||||
if nohtml
|
||||
echon "\r"."%nohtml placeholder found"
|
||||
return
|
||||
endif
|
||||
|
||||
let toc = s:get_html_toc(state.toc)
|
||||
call s:process_toc(ldest, placeholders, toc)
|
||||
call s:remove_blank_lines(ldest)
|
||||
|
||||
"" process end of file
|
||||
"" close opened tags if any
|
||||
let lines = []
|
||||
call s:close_tag_quote(state.quote, lines)
|
||||
call s:close_tag_para(state.para, lines)
|
||||
call s:close_tag_pre(state.pre, lines)
|
||||
call s:close_tag_list(state.lists, lines)
|
||||
call s:close_tag_def_list(state.deflist, lines)
|
||||
call s:close_tag_table(state.table, lines)
|
||||
call extend(ldest, lines)
|
||||
|
||||
let title = s:process_title(placeholders, fnamemodify(a:wikifile, ":t:r"))
|
||||
|
||||
let html_lines = s:get_html_template(a:wikifile, template_name)
|
||||
|
||||
" processing template variables (refactor to a function)
|
||||
call map(html_lines, 'substitute(v:val, "%title%", "'. title .'", "g")')
|
||||
call map(html_lines, 'substitute(v:val, "%root_path%", "'.
|
||||
\ s:root_path(subdir) .'", "g")')
|
||||
|
||||
let css_name = expand(VimwikiGet('css_name'))
|
||||
let css_name = substitute(css_name, '\', '/', 'g')
|
||||
call map(html_lines, 'substitute(v:val, "%css%", "'. css_name .'", "g")')
|
||||
|
||||
let enc = &fileencoding
|
||||
if enc == ''
|
||||
let enc = &encoding
|
||||
endif
|
||||
call map(html_lines, 'substitute(v:val, "%encoding%", "'. enc .'", "g")')
|
||||
|
||||
let html_lines = s:html_insert_contents(html_lines, ldest) " %contents%
|
||||
|
||||
"" make html file.
|
||||
call writefile(html_lines, path.htmlfile)
|
||||
|
||||
" measure the elapsed time and cut away miliseconds and smaller
|
||||
let elapsedtimestr = matchstr(reltimestr(reltime(starttime)),'\d\+\(\.\d\d\)\=')
|
||||
echon "\r".htmlfile.' written (time: '.elapsedtimestr.'s)'
|
||||
return path.htmlfile
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_html#WikiAll2HTML(path) "{{{
|
||||
|
||||
function! vimwiki#html#WikiAll2HTML(path) "{{{
|
||||
if !s:syntax_supported()
|
||||
echomsg 'vimwiki: Only vimwiki_default syntax supported!!!'
|
||||
return
|
||||
@@ -1289,9 +1415,9 @@ function! vimwiki_html#WikiAll2HTML(path) "{{{
|
||||
let &eventignore = save_eventignore
|
||||
|
||||
let path = expand(a:path)
|
||||
call vimwiki#mkdir(path)
|
||||
call vimwiki#base#mkdir(path)
|
||||
|
||||
echomsg 'Deleting old html files...'
|
||||
echomsg 'Deleting non-wiki html files...'
|
||||
call s:delete_html_files(path)
|
||||
|
||||
echomsg 'Converting wiki to html files...'
|
||||
@@ -1300,8 +1426,12 @@ function! vimwiki_html#WikiAll2HTML(path) "{{{
|
||||
|
||||
let wikifiles = split(glob(VimwikiGet('path').'**/*'.VimwikiGet('ext')), '\n')
|
||||
for wikifile in wikifiles
|
||||
echomsg 'Processing '.wikifile
|
||||
call vimwiki_html#Wiki2HTML(path, wikifile)
|
||||
if !s:is_html_uptodate(wikifile)
|
||||
echomsg 'Processing '.wikifile
|
||||
call vimwiki#html#Wiki2HTML(path, wikifile)
|
||||
else
|
||||
echomsg 'Skipping '.wikifile
|
||||
endif
|
||||
endfor
|
||||
call s:create_default_CSS(path)
|
||||
echomsg 'Done!'
|
||||
@@ -46,7 +46,7 @@ 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))
|
||||
let level = vimwiki#base#count_first_sym(getline(a:lnum))
|
||||
else
|
||||
let level = indent(a:lnum)
|
||||
endif
|
||||
@@ -287,7 +287,7 @@ endfunction "}}}
|
||||
" Script functions }}}
|
||||
|
||||
" Toggle list item between [ ] and [X]
|
||||
function! vimwiki_lst#ToggleListItem(line1, line2) "{{{
|
||||
function! vimwiki#lst#ToggleListItem(line1, line2) "{{{
|
||||
let line1 = a:line1
|
||||
let line2 = a:line2
|
||||
|
||||
@@ -316,7 +316,7 @@ function! vimwiki_lst#ToggleListItem(line1, line2) "{{{
|
||||
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_lst#kbd_cr() "{{{
|
||||
function! vimwiki#lst#kbd_cr() "{{{
|
||||
" This function is heavily relies on proper 'set comments' option.
|
||||
let cr = "\<CR>"
|
||||
if getline('.') =~ s:rx_cb_list_item()
|
||||
@@ -325,35 +325,45 @@ function! vimwiki_lst#kbd_cr() "{{{
|
||||
return cr
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_lst#kbd_oO(cmd) "{{{
|
||||
function! vimwiki#lst#kbd_oO(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 l:count = v:count1
|
||||
while l:count > 0
|
||||
|
||||
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 line = substitute(m, '\s*$', ' ', '').'[ ] '.li_content
|
||||
let m = matchstr(line, s:rx_list_item())
|
||||
let res = ''
|
||||
if line =~ s:rx_cb_list_item()
|
||||
let res = substitute(m, '\s*$', ' ', '').'[ ] '
|
||||
elseif line =~ s:rx_list_item()
|
||||
let res = substitute(m, '\s*$', ' ', '')
|
||||
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
|
||||
|
||||
let l:count -= 1
|
||||
endwhile
|
||||
|
||||
startinsert!
|
||||
|
||||
" let line = substitute(m, '\s*$', ' ', '').'[ ] '.li_content
|
||||
let m = matchstr(line, s:rx_list_item())
|
||||
let res = ''
|
||||
if line =~ s:rx_cb_list_item()
|
||||
let res = substitute(m, '\s*$', ' ', '').'[ ] '
|
||||
elseif line =~ s:rx_list_item()
|
||||
let res = substitute(m, '\s*$', ' ', '')
|
||||
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 "}}}
|
||||
|
||||
39
autoload/vimwiki/style.css
Normal file
39
autoload/vimwiki/style.css
Normal file
@@ -0,0 +1,39 @@
|
||||
body {font-family: Tahoma, Geneva, sans-serif; margin: 1em 2em 1em 2em; font-size: 100%; line-height: 130%;}
|
||||
h1, h2, h3, h4, h5, h6 {font-family: Trebuchet MS, Helvetica, sans-serif; font-weight: bold; line-height:100%; margin-top: 1.5em; margin-bottom: 0.5em;}
|
||||
h1 {font-size: 2.6em; color: #000000;}
|
||||
h2 {font-size: 2.2em; color: #404040;}
|
||||
h3 {font-size: 1.8em; color: #707070;}
|
||||
h4 {font-size: 1.4em; color: #909090;}
|
||||
h5 {font-size: 1.3em; color: #989898;}
|
||||
h6 {font-size: 1.2em; color: #9c9c9c;}
|
||||
p, pre, blockquote, table, ul, ol, dl {margin-top: 1em; margin-bottom: 1em;}
|
||||
ul ul, ul ol, ol ol, ol ul {margin-top: 0.5em; margin-bottom: 0.5em;}
|
||||
li {margin: 0.3em auto;}
|
||||
ul {margin-left: 2em; padding-left: 0.5em;}
|
||||
dt {font-weight: bold;}
|
||||
img {border: none;}
|
||||
pre {border-left: 1px solid #ccc; margin-left: 2em; padding-left: 0.5em;}
|
||||
blockquote {padding: 0.4em; background-color: #f6f5eb;}
|
||||
th, td {border: 1px solid #ccc; padding: 0.3em;}
|
||||
th {background-color: #f0f0f0;}
|
||||
hr {border: none; border-top: 1px solid #ccc; width: 100%;}
|
||||
del {text-decoration: line-through; color: #777777;}
|
||||
.toc li {list-style-type: none;}
|
||||
.todo {font-weight: bold; background-color: #f0ece8; color: #a03020;}
|
||||
.justleft {text-align: left;}
|
||||
.justright {text-align: right;}
|
||||
.justcenter {text-align: center;}
|
||||
.center {margin-left: auto; margin-right: auto;}
|
||||
/* classes for items of todo lists */
|
||||
.done0:before {content: "\2592\2592\2592\2592"; color: SkyBlue;}
|
||||
.done1:before {content: "\2588\2592\2592\2592"; color: SkyBlue;}
|
||||
.done2:before {content: "\2588\2588\2592\2592"; color: SkyBlue;}
|
||||
.done3:before {content: "\2588\2588\2588\2592"; color: SkyBlue;}
|
||||
.done4:before {content: "\2588\2588\2588\2588"; color: SkyBlue;}
|
||||
/* comment the next four or five lines out *
|
||||
* if you do not want color-coded todo lists */
|
||||
.done0 {color: #c00000;}
|
||||
.done1 {color: #c08000;}
|
||||
.done2 {color: #80a000;}
|
||||
.done3 {color: #00c000;}
|
||||
.done4 {color: #7f7f7f; text-decoration: line-through;}
|
||||
@@ -299,7 +299,7 @@ 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>"
|
||||
let cmd .= "\<ESC>:call vimwiki#tbl#format(line('.'))\<CR>"
|
||||
if a:goto_first
|
||||
let cmd .= "\<ESC>0:call search('|', 'c', line('.'))\<CR>la"
|
||||
else
|
||||
@@ -341,7 +341,7 @@ endfunction "}}}
|
||||
"}}}
|
||||
|
||||
" Global functions {{{
|
||||
function! vimwiki_tbl#kbd_cr() "{{{
|
||||
function! vimwiki#tbl#kbd_cr() "{{{
|
||||
let lnum = line('.')
|
||||
if !s:is_table(getline(lnum))
|
||||
return "\<CR>"
|
||||
@@ -355,7 +355,7 @@ function! vimwiki_tbl#kbd_cr() "{{{
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#kbd_tab() "{{{
|
||||
function! vimwiki#tbl#kbd_tab() "{{{
|
||||
let lnum = line('.')
|
||||
if !s:is_table(getline(lnum))
|
||||
return "\<Tab>"
|
||||
@@ -369,7 +369,7 @@ function! vimwiki_tbl#kbd_tab() "{{{
|
||||
return s:kbd_goto_next_col(last)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#kbd_shift_tab() "{{{
|
||||
function! vimwiki#tbl#kbd_shift_tab() "{{{
|
||||
let lnum = line('.')
|
||||
if !s:is_table(getline(lnum))
|
||||
return "\<S-Tab>"
|
||||
@@ -382,7 +382,7 @@ function! vimwiki_tbl#kbd_shift_tab() "{{{
|
||||
return s:kbd_goto_prev_col(first)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#format(lnum, ...) "{{{
|
||||
function! vimwiki#tbl#format(lnum, ...) "{{{
|
||||
let line = getline(a:lnum)
|
||||
if !s:is_table(line)
|
||||
return
|
||||
@@ -406,7 +406,7 @@ function! vimwiki_tbl#format(lnum, ...) "{{{
|
||||
let &tw = s:textwidth
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#create(...) "{{{
|
||||
function! vimwiki#tbl#create(...) "{{{
|
||||
if a:0 > 1
|
||||
let cols = a:1
|
||||
let rows = a:2
|
||||
@@ -441,15 +441,15 @@ function! vimwiki_tbl#create(...) "{{{
|
||||
call append(line('.'), lines)
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#align_or_cmd(cmd) "{{{
|
||||
function! vimwiki#tbl#align_or_cmd(cmd) "{{{
|
||||
if s:is_table(getline('.'))
|
||||
call vimwiki_tbl#format(line('.'))
|
||||
call vimwiki#tbl#format(line('.'))
|
||||
else
|
||||
exe 'normal! '.a:cmd
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#reset_tw(lnum) "{{{
|
||||
function! vimwiki#tbl#reset_tw(lnum) "{{{
|
||||
let line = getline(a:lnum)
|
||||
if !s:is_table(line)
|
||||
return
|
||||
@@ -461,7 +461,7 @@ endfunction "}}}
|
||||
|
||||
" TODO: move_column_left and move_column_right are good candidates to be
|
||||
" refactored.
|
||||
function! vimwiki_tbl#move_column_left() "{{{
|
||||
function! vimwiki#tbl#move_column_left() "{{{
|
||||
if !s:is_table(getline('.'))
|
||||
return
|
||||
endif
|
||||
@@ -472,7 +472,7 @@ function! vimwiki_tbl#move_column_left() "{{{
|
||||
endif
|
||||
|
||||
if cur_col > 0
|
||||
call vimwiki_tbl#format(line('.'), cur_col-1, cur_col)
|
||||
call vimwiki#tbl#format(line('.'), cur_col-1, cur_col)
|
||||
call cursor(line('.'), 1)
|
||||
if !s:is_separator(getline('.'))
|
||||
call search('\%(|[^|]\+\)\{'.(cur_col-1).'}| .', 'eW')
|
||||
@@ -482,7 +482,7 @@ function! vimwiki_tbl#move_column_left() "{{{
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#move_column_right() "{{{
|
||||
function! vimwiki#tbl#move_column_right() "{{{
|
||||
if !s:is_table(getline('.'))
|
||||
return
|
||||
endif
|
||||
@@ -493,7 +493,7 @@ function! vimwiki_tbl#move_column_right() "{{{
|
||||
endif
|
||||
|
||||
if cur_col < s:col_count(line('.'))-1
|
||||
call vimwiki_tbl#format(line('.'), cur_col, cur_col+1)
|
||||
call vimwiki#tbl#format(line('.'), cur_col, cur_col+1)
|
||||
call cursor(line('.'), 1)
|
||||
if !s:is_separator(getline('.'))
|
||||
call search('\%(|[^|]\+\)\{'.(cur_col+1).'}| .', 'eW')
|
||||
@@ -503,7 +503,7 @@ function! vimwiki_tbl#move_column_right() "{{{
|
||||
endif
|
||||
endfunction "}}}
|
||||
|
||||
function! vimwiki_tbl#get_rows(lnum) "{{{
|
||||
function! vimwiki#tbl#get_rows(lnum) "{{{
|
||||
return s:get_rows(a:lnum)
|
||||
endfunction "}}}
|
||||
|
||||
Reference in New Issue
Block a user