" " Vim RC file for use with the wikiEditDaemon. " (c) 2002 Simon Clift " Licensed under the Gnu GPL " " This is executed using the :source command in Vim. " "---------------------------------------------------------------------- " " Change this to reflect where you put the daemon Perl scripts, and how your " perl installation works. " " perl exec---v v-----------v--- installation directory " vvvv vvvvvvvvv vvvvvvvvvv let g:wikiDaemonCmd='perl -I$HOME/bin $HOME/bin/wikiEditDaemon.pl &' " Unless you've changed the Perl script defaults, these should stay unchanged. let g:wikiInputPipe=$HOME . '/.wikiEditDaemon/inputPipe' let g:wikiDaemonLog=$HOME . '/.wikiEditDaemon/log' let g:wikiEditDirectory=$HOME . '/.wikiEditDaemon/edit' let g:wikiURLSupplied="none" "---------------------------------------------------------------------- " function! WikiStartDaemon() " " Check whether the daemon is running already and if not, start it. " let s:isWorking = system( "ls -1 " . g:wikiInputPipe ) let s:daemonPID = system( "grep PID " . g:wikiDaemonLog \. " | cut -c 6-12" ) let s:daemonPID = matchstr( s:daemonPID, '[0-9]\+' ) let s:isPIDGoing = system( "ls -1 /proc/" . s:daemonPID ) if s:isWorking =~ "No such file" || s:isPIDGoing =~ "No such file" echo 'Starting the daemon.' call system( g:wikiDaemonCmd ) else echo 'Daemon is running (apparently) as PID ' . s:daemonPID endif endfunction "---------------------------------------------------------------------- " function! WikiSetURLInteractive( ) " " This function asks the user for the URL, then sets it ... " let s:url = input('Enter Wiki URL (up to CGI directory): ') call WikiSetURL( s:url ) endfunction "---------------------------------------------------------------------- " function! WikiSetURL( url ) " " ... or we use this function and supply a parameter. " call system( '/bin/echo configure wikiURL ' . a:url \ . ' > ' . g:wikiInputPipe . ' ' ) let g:wikiURLSupplied = a:url endfunction "---------------------------------------------------------------------- " function! WikiAuthenticate( ) " " Authentication is done interactively so that we can hide the password " let s:name = input('Enter WikiName: ') let s:passwd = inputsecret('Enter Wiki Password: ') call system( '/bin/echo authenticate ' . s:name . ' ' . s:passwd \ . ' > ' . g:wikiInputPipe . ' ' ) endfunction "---------------------------------------------------------------------- " function! WikiEditFile( webAndTopic ) " " Call this to retrieve the wiki page into the editing directory. " For file editing we allow 20 seconds for the document to be retrieved " if g:wikiURLSupplied == "none" echo "First supply a Wiki URL and authenticate." else call system( '/bin/echo edit '. a:webAndTopic .' > '. g:wikiInputPipe ) " " Do the wait loop until the file is ready locally " let s:counter = 10 let s:localFile = g:wikiEditDirectory . '/' . a:webAndTopic echo "Retrieving " . a:webAndTopic while s:counter > 1 call system( 'sleep 1' ) let s:readable = filereadable( s:localFile ) if s:readable break else echon "." endif let s:counter = s:counter - 1 endwhile " " Edit only if we have the file. " if s:readable execute ':e! ' . s:localFile let b:twikiFile = a:webAndTopic else echo "\nFailed to retrieve and open file " \."after 10 seconds. Log says:" echo system( "tail -12 " . g:wikiDaemonLog ) endif endif endfunction "---------------------------------------------------------------------- " function! WikiSaveBuffer( ) " " We should have the buffer name saved as a buffer local variable, so we " don't need a calling parameter. " call WikiSaveFile( b:twikiFile ) endfunction "---------------------------------------------------------------------- " function! WikiSaveFile( webAndTopic ) " " We may use this to save a file, however, using the web and page name. " if g:wikiURLSupplied == "none" echo "First supply a Wiki URL and authenticate." else execute ':w!' call system( '/bin/echo save ' . a:webAndTopic \ . ' > ' . g:wikiInputPipe ) " " Do the wait loop until the file is gone locally " let s:counter = 10 let s:localFile = g:wikiEditDirectory . '/' . a:webAndTopic echon "Saving " . a:webAndTopic . " to the Wiki " while s:counter > 1 call system( 'sleep 1' ) let s:readable = filereadable( s:localFile ) if s:readable echon "." else break endif let s:counter = s:counter - 1 endwhile if !s:readable if b:twikiFile == a:webAndTopic execute ':q' endif echo a:webAndTopic . "was saved." else echo "Save appears to have failed... check the daemon log." echo system( "tail -12 " . g:wikiDaemonLog ) endif endif endfunction "---------------------------------------------------------------------- " " These are some short-cut commands that we can use. You might even go so " far as to over-ride the vim defaults with these. " command! -nargs=0 WDStart call WikiStartDaemon() command! -nargs=0 WURL call WikiSetURLInteractive( ) command! -nargs=0 WAuth call WikiAuthenticate( ) command! -nargs=1 WE call WikiEditFile( "" ) command! -nargs=1 WS call WikiSaveFile( "" ) command! -nargs=0 WW call WikiSaveBuffer( ) command! -nargs=0 WLog echo system( "tail -20 " . g:wikiDaemonLog )