Hi pjot:
I like your help function, but I couldn't get it to work!
So I hacked it up a bit, following the procedure that you used,
but building a vimscript list, writing that list to a file and then
using the system call to evaluate it, then added the calling function
to a dispatcher function that works by filetype.
First the heavy lifting:
Code: Select all
" Help for a newLisp command - idea by Cormullion and pjot
function! NewlispHelp(func)
let str = substitute(a:func, '?', "p", "")
let str = substitute(str, '(', "", "")
echo "KEYWORD: " . str
" YOU MUST EDIT THE PATH BELOW!
let pfile = '/home/tim/prj/vim/tmp/nl_help.lsp'
let prog = ['#!/usr/bin/newlisp']
call add(prog,' (silent (setq file (open {/usr/doc/newlisp/newlisp_manual.html} {read}))')
call add(prog,' (if (not file) (setq file (open {/usr/share/doc/newlisp/newlisp_manual.html} {read})))')
call add(prog,' (setq pos (search file (append {<a NAME="} "' . str . '" {">} ) ))')
"call add(prog,' (println "Postion Found: " pos)')
call add(prog,' (read-line file)')
call add(prog,' (read-line file)')
call add(prog," (read-buffer file 'buff 1000 {<a NAME})")
call add(prog,' (replace {<.+>} buff {} 512)')
call add(prog,' (replace {>} buff {>})')
call add(prog,' (replace {<} buff {<})')
call add(prog,' (replace {—} buff {})')
call add(prog,' (replace {→} buff {->})')
call add(prog,' (replace "\t" buff {})')
call add(prog,' (replace {example:} buff "example:\n")')
call add(prog,' (replace {<a name} buff {})')
call add(prog,' (if (< (length buff) 5)')
call add(prog,' (println {SORRY! KEYWORD NOT FOUND!})')
call add(prog,' (print buff {...}))')
call add(prog,' (close file))')
call add(prog,'(exit)')
call writefile(prog,pfile)
let result = system("newlisp " . pfile)
return result
endfunction
" Print on command line for current word.
function! DoNewlispHelp()
let wrd=expand("<cWORD>")
let result = NewlispHelp(wrd)
echo result
endfunction
The temporary file that is written (variable 'pfile') allows
debugging and inspection.
For what it is worth, since I'm a multiple-language programmer and
want vim to be my "IDE" where keymappings give me similar functionality
regardless of the programming language, I then called this from a
wrapper function that checks for filetype:
Code: Select all
" --------------------------------------------------------------------
" Get help information on keywords.
" Only implemented for newlisp so far ..
" --------------------------------------------------------------------
function! DoHelp()
let fileType = &ft
if fileType == 'newlisp'
execute ':call DoNewlispHelp()'
else
execute 'echo "DoHelp() has not (yet) been implemented for this file-type"'
endif
endfunction
And gave this a "normal mode" mapping
Comments _and_ _or_ corrections are invited. I'm about as new to
vim as I am to newlisp.
Cheers
Tim