"$Id: potwiki.vim,v 1.11 2004/06/29 12:18:49 edwin Exp $ """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " 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) """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " " Section: Documentation "---------------------------- " " Documentation should be available by ":help potwiki" command, once the " script has been copied in you .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 syntaxic coloration). " if exists('loaded_potwiki') finish endif let loaded_potwiki = 1 let s:save_cpo = &cpo set cpo&vim "---------------------------------------------------------------------- " Configuration function s:default(varname,value) if !exists('g:potwiki_'.a:varname) let g:potwiki_{a:varname} = a:value endif endfunction call s:default('home',"~/Wiki/HomePage") 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() endfunction function s:PotWikiBufferInit() if exists('b:did_potwiki_buffer_init') return endif let b:did_potwiki_buffer_init = 1 let s:potwiki_dir = expand('%:p:h') call s:PotWikiDefineSyntax() call s:PotWikiBufferMap() endfunction function s:PotWikiDefineSyntax() syntax case match execute 'syntax match PotwikiWordNotFound "'.s:wordrx.'"' call s:PotWikiDefineWords() " Define the default highlighting. " For version 5.7 and earlier: only when not done already " For version 5.8 and later: only when an item doesn't have highlighting yet if version >= 508 || !exists("did_potwiki_syntax_inits") if version < 508 let did_potwiki_syntax_inits = 1 command -nargs=+ HiLink hi link else command -nargs=+ HiLink hi def link endif HiLink PotwikiWordNotFound Error HiLink PotwikiWord Identifier delcommand HiLink endif let b:current_syntax = "potwiki" endfunction function s:PotWikiClearWords() syntax clear PotwikiWord 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:potwiki_dir,"*") 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 word = matchstr(file,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 call s:PotWikiBufferInit() endfunction "---------------------------------------------------------------------- " Autocommands function s:PotWikiAutoCommands() let dir = g:potwiki_home_dir if !has('unix') let dir = substitute(dir,'\','/','g') endif execute 'au BufNewFile,BufReadPost '.dir.'/* call PotWikiBufferInit()' endfunction "---------------------------------------------------------------------- " Maps function s:PotWikiMap() noremap