vim, ctags and taglist stuff

Q&A's, tips, howto's
Locked
Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

vim, ctags and taglist stuff

Post by Tim Johnson »

To make a long story short, I'm transitioning back to vim
after using emacs for some years now.

I'm using newlisp.vim, thanks to Cyril. I just got done adding
some code to using ctags and the taglist plugin.

I did the following:
1)in the taglist plugin added the following

Code: Select all

" newlisp language
let s:tlist_def_newlisp_settings = 'newlisp;c:class;m:member;f:function'
2)In the .ctags file added this:

Code: Select all

--langdef=newlisp
--langmap=newlisp:.lsp
--regex-newlisp=/\(define \(*([^ ]+)[ ]*[ \)]/\1/f,function/
--regex-newlisp=/\(context '*([^ ]+)[ ]*[\)]/\1/c,class/
This perhaps could be helpful to some vim/newlisp users.
BTW: I'm weak on regexes, every time I use them lately, it seems
like I'm learning the protocol all over again, so if anyone can improve
on them, I'd be grateful.
If any vim users are unfamiliar with taglist, I'd certainly recommend that
you look into it, because it is a nice feature that makes vim more
of an IDE.
Thanks
Tim

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Great idea, thanks!

BTW I have written some macros for newLisp and VIM, including an online help. You can find it here:

http://www.turtle.dds.nl/newlisp/#vim

Regards
Peter

Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

Post by Tim Johnson »

cool! Thanks. I wrote these functions:

Code: Select all

" --------------------------------------------------------------------
function! NextNewlispFunction()
	execute '/(define\|(defun'
	execute ':nohls'
endfunction
" --------------------------------------------------------------------
function! PrevNewlispFunction()
 	let wrd=expand("<cWORD>")
	if wrd == "(define" || wrd == "(defun"
		exe "norm! k"
	endif
	execute '?(define\|(defun'
	execute ':nohls'
endfunction 
And are called in turn from these:

Code: Select all

" --------------------------------------------------------------------
function! StdNextFunction()
	let fileType = &ft
	if fileType == 'python'
		execute ':call PythonDec("function", 1)'
	elseif fileType == 'javascript'
		execute ':call NextJavascriptFunction()'
	elseif fileType == 'javascript.jquery'
		execute ':call NextJavascriptFunction()'
	elseif fileType == 'rebol'
		execute ':call NextRebolFunction()'
	elseif fileType == 'newlisp'
		execute ':call NextNewlispFunction()'
	else
		execute 'echo "StdNextFunction() has not (yet) been implemented for this file-type"'
	endif
endfunction
" --------------------------------------------------------------------
function! StdPrevFunction()
	let fileType = &ft
	if fileType == 'python'
		execute ':call PythonDec("function", -1)'
	elseif fileType == 'javascript'
		execute ':call PrevJavascriptFunction()'
	elseif fileType == 'javascript.jquery'
		execute ':call PrevJavascriptFunction()'
	elseif fileType == 'rebol'
		execute ':call PrevRebolFunction()'
	elseif fileType == 'newlisp'
		execute ':call PrevNewlispFunction()'
	else
		execute 'echo "StdPrevFunction() has not (yet) been implemented for this file-type"'
	endif
endfunction 
and map'ed to gn and gp
And I'm also working up to an evaluating function to work like
emacs *scratch* buffer....

Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

Post by Tim Johnson »

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 {&mdash;} buff {})')
	call add(prog,'    (replace {&rarr;} 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

Code: Select all

noremap ,hh :call DoHelp()<CR>
Comments _and_ _or_ corrections are invited. I'm about as new to
vim as I am to newlisp.
Cheers
Tim

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

I like your help function, but I couldn't get it to work!
What platform are you using? For me it works in MacOSX and Linux. As I do not have Win32 it may fail in there.

Also, the online help only prints the first 1000 characters or until the next keyword, whatever comes first.

Anyway I'll check your adjustments!

Thanks,
Peter

Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

Post by Tim Johnson »

Using kubuntu 7.10, vim 7.10 (console and gui)
1)Got an error message about a file on the /tmp path, couldn't tell
if the message was coming from vim or from newlisp.
modifying to the list/writefile method bypassed any premission issues.
2)Then, had to change the "<a name" tokens to "<a NAME"
I haven't fully grok'ed the (search) function as to case sensitivity....
tim
Last edited by Tim Johnson on Fri Jan 09, 2009 4:27 pm, edited 1 time in total.

pjot
Posts: 733
Joined: Thu Feb 26, 2004 10:19 pm
Location: The Hague, The Netherlands
Contact:

Post by pjot »

Hm, the /tmp probably is from VIM, it always tries to store some hidden file to keep track of the changes.

Funny about the "< NAME" change, because it used to be like that; just recently I changed it to "< name" with small letters! Maybe it should search both capital and small.

Thanks for your feedback,
Peter

Locked