From 4804192e2a3c77f2a7d6e646925086065b4c6a07 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Mon, 6 Jan 2020 10:30:52 +0100 Subject: add potwiki vim plugin --- .vim/plugin/potwiki.vim | 685 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 685 insertions(+) create mode 100644 .vim/plugin/potwiki.vim diff --git a/.vim/plugin/potwiki.vim b/.vim/plugin/potwiki.vim new file mode 100644 index 0000000..6c282d5 --- /dev/null +++ b/.vim/plugin/potwiki.vim @@ -0,0 +1,685 @@ +" potwiki.vim +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Name: potwiki +" Description: Maintain a simple Plain Old Text Wiki +" Author: Edwin Steiner +" Maintainer: -- '' -- +" +" Licence: This program is free software; you can redistribute it +" and/or modify it under the terms of the GNU General Public +" License. See http://www.gnu.org/copyleft/gpl.txt +" +" Credits: Mathieu Clabaut +" for the organization of the documentation and +" the automatic documentation installing +" (taken from his script vimspell.vim) +" Michael Fitz +" NextWord/PrevWord bugfix +" Anders Carling +" potwiki_suffix feature +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" +" Section: Documentation +"---------------------------- +" +" Documentation should be available by ":help potwiki" command, once the +" script has been copied into your .vim/plugin directory. +" +" You still can read the documentation at the end of this file. Locate it by +" searching the "potwiki-contents" string (and set ft=help to have +" appropriate syntactic coloration). +" + +if exists('loaded_potwiki') + finish +endif +let loaded_potwiki = 1 + +let s:save_cpo = &cpo +set cpo&vim + +"---------------------------------------------------------------------- +" Revision + +let s:revision = "1.25" + +"---------------------------------------------------------------------- +" Configuration + +function s:default(varname,value) + if !exists('g:potwiki_'.a:varname) + let g:potwiki_{a:varname} = a:value + endif +endfunction + +call s:default('suffix','') +call s:default('home',"~/Wiki/HomePage".g:potwiki_suffix) +call s:default('home_dir',fnamemodify(g:potwiki_home,':p:h')) + +call s:default('upper','A-Z') +call s:default('lower','a-z') +call s:default('other','0-9_') + +call s:default('autowrite',0) + +call s:default('slash',has('unix') ? '/' : '\') + +call s:default('ignore','') +call s:default('opendirs',0) + +"---------------------------------------------------------------------- +" Functions + +function s:PotWikiInit() + let upp = g:potwiki_upper + let low = g:potwiki_lower + let oth = g:potwiki_other + let nup = low.oth + let nlo = upp.oth + let any = upp.nup + + "A PotWikiWord must start with an upper case character and contain at + "least one lower case and another upper case character in that order. + + let inner = '['.upp.']['.nlo.']*['.low.']['.nup.']*['.upp.']['.any.']*' + call s:PotWikiBuildIgnore() + if s:ignorerx != "" + let s:wordrx = '\C\<\(\('.s:ignorerx.'\)\>\)\@!'.inner.'\>' + else + let s:wordrx = '\C\<'.inner.'\>' + endif + + call s:PotWikiMap() + call s:PotWikiMenu() + call s:PotWikiAutoCommands() + + au Filetype potwiki call PotWikiBufferInit() + au Syntax potwiki call PotWikiDefineSyntax() +endfunction + +function s:PotWikiBufferInit() + call s:PotWikiBufferMap() +endfunction + +function s:PotWikiDir() + if &filetype == 'potwiki' + return expand('%:p:h') + endif + return g:potwiki_home_dir +endfunction + +function s:PotWikiDefineSyntax() + syntax clear + syntax case match + execute 'syntax match PotwikiWordNotFound "'.s:wordrx.'"' + + call s:PotWikiDefineWords() + + " Define the default highlighting. + hi def link PotwikiWordNotFound Error + hi def link PotwikiWord Identifier + + let b:current_syntax = "potwiki" +endfunction + +" external interface +function PotwikiSyntax() + call s:PotWikiDefineSyntax() +endfunction + +function s:PotWikiBuildIgnore() + let s:ignorerx = "" + let words=g:potwiki_ignore + while words != "" + let pos = stridx(words,",") + if pos < 0 + let pos = strlen(words) + endif + let word = strpart(words,0,pos) + let words = strpart(words,pos+1) + if s:ignorerx != "" + let s:ignorerx = s:ignorerx.'\|' + endif + let s:ignorerx = s:ignorerx.word + endwhile +endfunction + +function s:PotWikiDefineWords() + let files=globpath(s:PotWikiDir(),"*") + while files != "" + let pos = stridx(files,"\n") + if pos < 0 + let pos = strlen(files) + endif + let file = strpart(files,0,pos) + let files = strpart(files,pos+1) + let suffix_len = strlen(g:potwiki_suffix) + let file_len = strlen(file) + if strpart(file, file_len-suffix_len, suffix_len) == g:potwiki_suffix + let word=strpart(file,0,file_len-suffix_len) + else + let word="" + endif + let word = matchstr(word,s:wordrx.'\%$') + if word != "" + if filereadable(file) || (g:potwiki_opendirs && isdirectory(file)) + execute "syntax match PotwikiWord ".'"\<'.word.'\>"' + endif + endif + endwhile +endfunction + +function s:PotWikiEdit(file) + if isdirectory(a:file) && !g:potwiki_opendirs + echo a:file." is a directory" + return + endif + execute "e ".a:file + if &filetype != 'potwiki' + setlocal filetype=potwiki + endif +endfunction + +function s:PotWikiAutowrite() + if &filetype == 'potwiki' && g:potwiki_autowrite + execute "update" + endif +endfunction + +"---------------------------------------------------------------------- +" Autocommands + +function s:PotWikiAutoCommands() + let dir = g:potwiki_home_dir + if !has('unix') + let dir = substitute(dir,'\','/','g') + endif + " 'setf potwiki' is too weak -- we may have to override a wrong filetype: + execute 'au BufNewFile,BufReadPost '.dir.'/*'.g:potwiki_suffix.' setlocal filetype=potwiki' +endfunction + +"---------------------------------------------------------------------- +" Maps + +function s:PotWikiMap() + noremap