On Fri, 23 Jun 2006, [EMAIL PROTECTED] wrote: > > I'd like to write a mapping that would expand to a function > > call. I want this function to return a meaningful text..
> <http://hermitte.free.fr/vim/ressources/lh-map-tools.tar.gz> > contains what you are looking for, and a few other things (like > a bracketing system relying on facultatives > placeholders/markers). > PPS: In lh-cpp.tar.gz, you will find many examples of use. The > patched, but not yet uploaded, version contains the following > context-aware mappings and abbreviations: I'm looking forward to seeing those patches. Your bracketing system is great. I wish I could only use the repeat "." command to save even more typing labor. > ... > "--if insert "if" statement {{{ > Inoreabbr <buffer> <silent> if <C-R>=Def_AbbrC('if ', > \ '\<c-f\>if (!cursorhere!) {\n!mark!\n}!mark!')<cr> The <buffer> means the mapping is only local to the buffer. <silent> is for no echoing of the command. 'if' is what is expanded. <C-R>= inserts the results of the Def_AbbrC function, which does some whitespace substitutions. !cursorhere! leaves the cursor between the parentheses of the conditional afterwards. !mark! leaves markers, 1 in the first line of the body between the 2 braces and another after the final brace, to which you can jump. I don't know what the <c-f> does. > "--,if insert "if" statement > " todo provide smappings > vnoremap <buffer> <silent> <localleader>if > \ <c-\><c-n>@=Surround('if (!cursorhere!) {', '}!mark!', > \ 1, 1, '', 1, 'if ')<cr> This allows you to highlight some text, type '\if' and hey presto, the text becomes the body of an if statement. > vnoremap <buffer> <silent> <LocalLeader><localleader>if > \ <c-\><c-n>@=Surround('if (', '!cursorhere!) {\n!mark!\n}!mark!', > \ 0, 1, '', 1, 'if ')<cr> 2 localleaders, on the other hand, make the text the conditional in the if statement. > nmap <buffer> <LocalLeader>if V<LocalLeader>if If the mapping is typed in normal mode, the line under the cursor becomes the body of an if statement. > nmap <buffer> <LocalLeader><LocalLeader>if V<LocalLeader><LocalLeader>if If 2 localleaders are used, it becomes the conditional. One problem I have in using the mappings is in perl many of the conditional keywords can be used in 2 ways. In a compound statement 'if' works just like in C. However it may also be used to modify a single statement, as in 'print "Hello, world" if 1'. I need to work out how to make the mappings context-sensitive to this. Like expand 'if' only if it is the first word in the line. I forgot there is quite a lot of documentation. I need to look at it more. -- Dr Bean Think globally. Act locally. Think one thing, do another.