Version 0.2

* (+) Add part of Google's Wiki syntax.
  * (+) Add auto insert # with ENTER.
  * (+) On/Off auto insert bullet with ENTER.
  * (+) Strip `[[complex wiki name]]` from symbols that cannot be used in file names.
  * (+) Links to non-wiki files. Non wiki files are files with extensions ie `[[hello world.txt]]` or `[[my homesite.html]]`
This commit is contained in:
Maxim Kim 2008-05-05 00:00:00 +00:00 committed by Able Scraper
parent 4f28e21f3f
commit 0b416c2834
2 changed files with 82 additions and 67 deletions

View File

@ -4,8 +4,8 @@
" Home: http://code.google.com/p/vimwiki/ " Home: http://code.google.com/p/vimwiki/
" Author: Maxim Kim " Author: Maxim Kim
" Filenames: *.wiki " Filenames: *.wiki
" Last Change: (04.05.2008 17:45) " Last Change: (05.05.2008 19:30)
" Version: 0.1 " Version: 0.2
if exists("b:did_ftplugin") if exists("b:did_ftplugin")
finish finish
@ -35,12 +35,16 @@ function! s:default(varname,value)
endif endif
endfunction endfunction
"" Could be redefined by users
call s:default('index',"") call s:default('index',"")
call s:default('home',"") call s:default('home',"")
call s:default('upper','A-ZА-Я') call s:default('upper','A-ZА-Я')
call s:default('lower','a-zа-я') call s:default('lower','a-zа-я')
call s:default('other','0-9_') call s:default('other','0-9_')
call s:default('ext','.wiki') call s:default('ext','.wiki')
call s:default('smartCR',1)
call s:default('stripsym','_')
call s:default('history',[]) call s:default('history',[])
let upp = g:vimwiki_upper let upp = g:vimwiki_upper
@ -74,6 +78,7 @@ function! s:SearchWord(wikiRx,cmd)
let &hls = hl let &hls = hl
endfunction endfunction
function! s:WikiNextWord() function! s:WikiNextWord()
call s:SearchWord(s:wiki_word, 'n') call s:SearchWord(s:wiki_word, 'n')
endfunction endfunction
@ -104,27 +109,44 @@ function! s:WikiGetWordAtCursor(wikiRX)
endif endif
endf endf
function! s:WikiStripWord(word) function! s:WikiStripWord(word, sym)
function! s:WikiStripWordHelper(word, sym)
return substitute(a:word, '[<>|?*/\:"]', a:sym, 'g')
endfunction
let result = a:word let result = a:word
if strpart(a:word, 0, 2) == "[[" if strpart(a:word, 0, 2) == "[["
let result = strpart(a:word, 2, strlen(a:word)-4) let result = s:WikiStripWordHelper(strpart(a:word, 2, strlen(a:word)-4), a:sym)
endif endif
return result return result
endfunction endfunction
" Check if word is link to a non-wiki file.
" The easiest way is to check if it has extension like .txt or .html
function! s:WikiLinkToNonWikiFile(word)
if a:word =~ '\..\{1,4}$'
return 1
endif
return 0
endfunction
if !exists('*s:WikiFollowWord') if !exists('*s:WikiFollowWord')
function! s:WikiFollowWord() function! s:WikiFollowWord()
let word = s:WikiStripWord(s:WikiGetWordAtCursor(s:wiki_word)) let word = s:WikiStripWord(s:WikiGetWordAtCursor(s:wiki_word), g:vimwiki_stripsym)
" insert doesn't work properly inside :if. Check :help :if. " insert doesn't work properly inside :if. Check :help :if.
if word == "" if word == ""
execute "normal! \n" execute "normal! \n"
return return
endif endif
" history is [['WikiWord.wiki', 11], ['AnotherWikiWord', 3] ... etc] if s:WikiLinkToNonWikiFile(word)
" where numbers are column positions we should return when coming back. execute ":e ".word
call insert(g:vimwiki_history, [expand('%:p'), col('.')]) else
execute ":e ".g:vimwiki_home.word.g:vimwiki_ext " history is [['WikiWord.wiki', 11], ['AnotherWikiWord', 3] ... etc]
" where numbers are column positions we should return when coming back.
call insert(g:vimwiki_history, [expand('%:p'), col('.')])
execute ":e ".g:vimwiki_home.word.g:vimwiki_ext
endif
endfunction endfunction
function! s:WikiGoBackWord() function! s:WikiGoBackWord()
@ -138,30 +160,40 @@ if !exists('*s:WikiFollowWord')
endif endif
function! s:WikiNewLine() function! s:WikiNewLine()
let prevline = getline(line('.')-1) function! WikiAutoListItemInsert(listSym)
let sym = escape(a:listSym, '*')
if prevline =~ '^\s*\*' let prevline = getline(line('.')-1)
let curline = substitute(getline('.'),'^\s\+',"","g") if prevline =~ '^\s*'.sym
if prevline =~ '^\s*\*\s*$' let curline = substitute(getline('.'),'^\s\+',"","g")
" there should be easier way ... if prevline =~ '^\s*'.sym.'\s*$'
execute 'normal kA '."\<ESC>".'"_dF*JX' " there should be easier way ...
return execute 'normal kA '."\<ESC>".'"_dF'.a:listSym.'JX'
return 1
endif
let ind = indent(line('.')-1)
call setline(line('.'), strpart(prevline, 0, ind).a:listSym.' '.curline)
call cursor(line('.'), ind+3)
return 1
endif endif
call setline(line('.'), '* '.curline) return 0
execute "normal ==" endfunction
let ind = indent(line('.')) + 3
call cursor(line('.'), ind) if WikiAutoListItemInsert('*')
return
endif
if WikiAutoListItemInsert('#')
return return
endif endif
" delete <space> " delete <space>
execute 'normal X' execute 'normal x'
endfunction endfunction
" Functions }}} " Functions }}}
"" Keybindings "" Keybindings {{{
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
nmap <buffer> <Up> gk nmap <buffer> <Up> gk
nmap <buffer> k gk nmap <buffer> k gk
@ -182,4 +214,7 @@ nmap <buffer> <BS> :call <SID>WikiGoBackWord()<CR>
nmap <buffer> <TAB> :call <SID>WikiNextWord()<CR> nmap <buffer> <TAB> :call <SID>WikiNextWord()<CR>
nmap <buffer> <S-TAB> :call <SID>WikiPrevWord()<CR> nmap <buffer> <S-TAB> :call <SID>WikiPrevWord()<CR>
inoremap <CR> <CR> <C-O>:call <SID>WikiNewLine()<CR> if g:vimwiki_smartCR
inoremap <CR> <CR> <C-O>:call <SID>WikiNewLine()<CR>
endif
" Keybindings }}}

View File

@ -4,8 +4,8 @@
" Home: http://code.google.com/p/vimwiki/ " Home: http://code.google.com/p/vimwiki/
" Author: Maxim Kim " Author: Maxim Kim
" Filenames: *.wiki " Filenames: *.wiki
" Last Change: (04.05.2008 17:45) " Last Change: (05.05.2008 19:30)
" Version: 0.1 " Version: 0.2
" Based on FlexWiki " Based on FlexWiki
" Quit if syntax file is already loaded " Quit if syntax file is already loaded
@ -26,70 +26,51 @@ syntax match wikiLink `\("[^"(]\+\((\([^)]\+\))\)\?":\)\?\(https\?\|ft
" text: *strong* " text: *strong*
syntax match wikiBold /\(^\|\W\)\zs\*\([^ ].\{-}\)\*/ syntax match wikiBold /\(^\|\W\)\zs\*\([^ ].\{-}\)\*/
" '''bold'''
syntax match wikiBold /'''\([^'].\{-}\)'''/
" text: _emphasis_ " text: _emphasis_
syntax match wikiItalic /\(^\|\W\)\zs_\([^ ].\{-}\)_/ syntax match wikiItalic /_.\{-}_/
" ''italic''
syntax match wikiItalic /''\([^'].\{-}\)''/
" ``deemphasis`` " text: `code`
syntax match wikiDeEmphasis /``\([^`].\{-}\)``/ syntax match wikiCode /`.\{-}`/
" text: @code@ " text: ~~deleted text~~
syntax match wikiCode /\(^\|\s\|(\|\[\)\zs@\([^@]\+\)@/ syntax match wikiDelText /\~\{2}.\{-}\~\{2}/
" text: -deleted text-
syntax match wikiDelText /\(^\|\s\+\)\zs-\([^ <a ]\|[^ <img ]\|[^ -].*\)-/
" text: +inserted text+
syntax match wikiInsText /\(^\|\W\)\zs+\([^ ].\{-}\)+/
" text: ^superscript^ " text: ^superscript^
syntax match wikiSuperScript /\(^\|\W\)\zs^\([^ ].\{-}\)^/ syntax match wikiSuperScript /\^.\{-}\^/
" text: ~subscript~ " text: ,,subscript,,
syntax match wikiSubScript /\(^\|\W\)\zs\~\([^ ].\{-}\)\~/ syntax match wikiSubScript /,,.\{-},,/
" text: ??citation??
syntax match wikiCitation /\(^\|\W\)\zs??\([^ ].\{-}\)??/
" Emoticons: must come after the Textilisms, as later rules take precedence " Emoticons: must come after the Textilisms, as later rules take precedence
" over earlier ones. This match is an approximation for the ~70 distinct " over earlier ones. This match is an approximation for the ~70 distinct
" patterns that FlexWiki knows. " patterns that FlexWiki knows.
syntax match wikiEmoticons /\((.)\|:[()|$@]\|:-[DOPS()\]|$@]\|;)\|:'(\)/ syntax match wikiEmoticons /\((.)\|:[()|$@]\|:-[DOPS()\]|$@]\|;)\|:'(\)/
" Aggregate all the regular text highlighting into flexwikiText " Aggregate all the regular text highlighting into wikiText
syntax cluster wikiText contains=wikiItalic,wikiBold,wikiCode,wikiDeEmphasis,wikiDelText,wikiInsText,wikiSuperScript,wikiSubScript,wikiCitation,wikiLink,wikiWord,wikiEmoticons syntax cluster wikiText contains=wikiItalic,wikiBold,wikiCode,wikiDelText,wikiSuperScript,wikiSubScript,wikiLink,wikiWord,wikiEmoticons
" single-line WikiPropertys " Treat all other lines that start with spaces as PRE-formatted text.
syntax match wikiSingleLineProperty /^:\?[A-Z_][_a-zA-Z0-9]\+:/ syntax match wikiPre /^[ \t]\+.*$/ contains=@wikiText
" Header levels, 1-6 " Header levels, 1-6
syntax match wikiH1 /^!.*$/ syntax match wikiH1 /\(^!\{1}.*$\|^\s*=\{1}.*=\{1}\s*$\)/
syntax match wikiH2 /^!!.*$/ syntax match wikiH2 /\(^!\{2}.*$\|^\s*=\{2}.*=\{2}\s*$\)/
syntax match wikiH3 /^!!!.*$/ syntax match wikiH3 /\(^!\{3}.*$\|^\s*=\{3}.*=\{3}\s*$\)/
syntax match wikiH4 /^!!!!.*$/ syntax match wikiH4 /\(^!\{4}.*$\|^\s*=\{4}.*=\{4}\s*$\)/
syntax match wikiH5 /^!!!!!.*$/ syntax match wikiH5 /\(^!\{5}.*$\|^\s*=\{5}.*=\{5}\s*$\)/
syntax match wikiH6 /^!!!!!!.*$/ syntax match wikiH6 /\(^!\{6}.*$\|^\s*=\{6}.*=\{6}\s*$\)/
" <hr>, horizontal rule " <hr>, horizontal rule
syntax match wikiHR /^----.*$/ syntax match wikiHR /^----.*$/
" Formatting can be turned off by ""enclosing it in pairs of double quotes""
syntax match wikiEscape /"".\{-}""/
" Tables. Each line starts and ends with '||'; each cell is separated by '||' " Tables. Each line starts and ends with '||'; each cell is separated by '||'
syntax match wikiTable /||/ syntax match wikiTable /||/
" Treat all other lines that start with spaces as PRE-formatted text.
syntax match wikiPre /^[ \t]\+.*$/
" Bulleted list items start with whitespace(s), then '*' " Bulleted list items start with whitespace(s), then '*'
" syntax match wikiList /^\s\+\(\*\|[1-9]\+0*\.\).*$/ contains=@wikiText " syntax match wikiList /^\s\+\(\*\|[1-9]\+0*\.\).*$/ contains=@wikiText
" highlight only bullets and digits. " highlight only bullets and digits.
syntax match wikiList /^\s\+\(\*\|[1-9]\+0*\.\)/ syntax match wikiList /^\s\+\(\*\|[1-9]\+0*\.\|#\)/
@ -106,7 +87,7 @@ hi def link wikiHR wikiH6
hi def wikiBold term=bold cterm=bold gui=bold hi def wikiBold term=bold cterm=bold gui=bold
hi def wikiItalic term=italic cterm=italic gui=italic hi def wikiItalic term=italic cterm=italic gui=italic
hi def link wikiCode Statement hi def link wikiCode PreProc
hi def link wikiWord Underlined hi def link wikiWord Underlined
hi def link wikiEscape Todo hi def link wikiEscape Todo
@ -116,7 +97,6 @@ hi def link wikiList Type
hi def link wikiTable Type hi def link wikiTable Type
hi def link wikiEmoticons Constant hi def link wikiEmoticons Constant
hi def link wikiDelText Comment hi def link wikiDelText Comment
hi def link wikiDeEmphasis Comment
hi def link wikiInsText Constant hi def link wikiInsText Constant
hi def link wikiSuperScript Constant hi def link wikiSuperScript Constant
hi def link wikiSubScript Constant hi def link wikiSubScript Constant