Hello,

Peter Slizik <[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 in a normal context, but nothing at all,
> if it's called from a comment or string context. I know this has been done
> many times before,

Indeed.

> I need only a hint to know where to start.

<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).

You can dig into the code and copy-paste it, or you can simply use the functions
I provide. lh-map-tool can be seen as a kind of library plugin that define many
(documented) functions useful to ftplugin writers.

HTH,

PS: regarding the packaged bracketing system, I haven't uploaded yet the lastest
version of the plugin that works correctly in UTF-8.

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:
  ...
  "--if    insert "if" statement                   {{{
    Inoreabbr <buffer> <silent> if <C-R>=Def_AbbrC('if ',
        \ '\<c-f\>if (!cursorhere!) {\n!mark!\n}!mark!')<cr>
  "--,if    insert "if" statement
    " todo provide smappings
    vnoremap <buffer> <silent> <localleader>if
        \ <c-\><c-n>@=Surround('if (!cursorhere!) {', '}!mark!',
        \ 1, 1, '', 1, 'if ')<cr>
    vnoremap <buffer> <silent> <LocalLeader><localleader>if
        \ <c-\><c-n>@=Surround('if (', '!cursorhere!) {\n!mark!\n}!mark!',
        \ 0, 1, '', 1, 'if ')<cr>
      nmap <buffer> <LocalLeader>if V<LocalLeader>if
      nmap <buffer> <LocalLeader><LocalLeader>if V<LocalLeader><LocalLeader>if
  " }}}
  ...

--
Luc Hermitte

Reply via email to