Simon Butler schrieb:
hi, when i write this skill (cadence extension language) fragment in
emacs i get the following:
procedure( vscCheckpointHier( @key lib cell view message inclibs )
let(( ddCVs )
vscPrint0(sprintf( nil "Hierarchy for %s,%s,%s ..." lib cell
view ))
when( ddCVs = vscGetHierarchyDDs( ?lib lib ?cell cell ?view view
?inclibs inclibs )
vscPrint0(sprintf( nil " %d cellviews." length(ddCVs) ))
vscCheckpoint( ddCVs ?message message)
); when ddCVs
); let
); procedure vscCheckpointHier
Notice all the comments placed on the closing brackets. Is there a way
to make vim do this?
TIA
Yep. I just felt the challenge, so I wrote the attached script.
I don't know skill, but I think this comes close to what you want.
Core elements:
:imap <expr> ; ...
searchpair()
Hopefully, filetype "skill" is what you currently use for those
kind of files.
--
Regards,
Andy
EOM
" Vim filetype plugin code snippet
" Language: skill (cadence extension language)
" File: skill_comment.vim
" Date: 2007 Mai 14
" Author: Andy Wokula <[EMAIL PROTECTED]>
" Description:
" After inserting ");", insert the word located before the matching
" opening paren; for some keywords also add their argument. To work
" properly, all must be found on the same line.
"
" Installation: (suggestion)
" 1. make sure filetype "skill" is detected
" 2. copy this script to ~/.vim/
" (to the first entry of 'runtimepath')
" 3. :edit
" ~/.vim/after/ftplugin/skill.vim
" add the following line:
" runtime skill_comment.vim
"
" TODO:
" - ignore ");" in comments
" - ignore (possibly unbalanced) parens in comments
" - extend s:keywords
if v:version < 700
" sorry, Vim7 required
finish
endif
" Mapping for ";" in Insert mode
ino <buffer><expr> ; <sid>CloseKeyword()
" search for arguments to these keywords:
let s:keywords = ['procedure', 'when']
" (to be extended)
function! <sid>CloseKeyword()
if getline(".")[col(".")-2] != ')'
" if char just before ";" is not ")"
return ";"
" (Note: first getline index is 0, first col is 1)
endif
" move cursor to closing paren (this is allowed)
call cursor(".", col(".")-1)
" get position of matching paren:
let pomp = searchpairpos('(','',')','bW')
" [line, column]
if !pomp[0]
return ";"
endif
" getline of matching paren
let glineomp = getline(pomp[0])
" get matching keyword:
let word = matchstr(glineomp[: pomp[1]-2], '\k\+\ze\s*$')
if word == ""
return ";"
endif
if match(s:keywords, '\<'.word.'\>') >= 0
" search for argument
let kwarg = matchstr(glineomp, '\k\+', pomp[1])
" omit trailing space if no argument found
return "; " . word . (kwarg!="" ? " ".kwarg : "")
else
return "; " . word
endif
endfunction