Hello,
* On Sat, Jun 24, 2006 at 08:52:47AM +0800, Dr Bean [EMAIL PROTECTED] wrote:
On Fri, 23 Jun 2006, [EMAIL PROTECTED] wrote:
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.
Done. I'll finish to play with svn latter.
Your bracketing system is great.
Thanks ^^
I wish I could only use the repeat . command to save even
more typing labor.
That's something I miss too. I'm not sure there is a workaround. We can
always play with recorded macros, or quick'n'dirty mappings.
...
--ifinsert if statement {{{
Inoreabbr buffer silent if C-R=Def_AbbrC('if ',
\ '\c-f\if (!cursorhere!) {\n!mark!\n}!mark!')cr
[...]
'if' is what is expanded.
'if' is what is expanded within comment/string context.
C-R= inserts the results of the Def_AbbrC function,
which does some whitespace substitutions.
Def_AbbrC() does some other things like:
- adding \n before (,{ and after ),} according to options.
- removing markers/placeholder according to another option.
[...]
I don't know what the c-f does.
It forces to reindent the line where the cursor is, it works in
INSERT-mode.
I see I have hard-coded c-f. It is not the best solution as I should
have used what is defined after the `!' in 'cinkeys'.
--,ifinsert if statement
todo provide smappings
vnoremap buffer silent localleaderif
\ 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.
Indeed.
Surround() has also another responsibility. I wrote it before vim7
permit to distinguish between visual-mode mappings and select-mode
mappings. Surround() checks if the current selection is a
marker/placeholder. If so, it expands 'if' in insert-mode (which will
result in the activation of the previous `if' abbreviation), otherwise
it does its surrounding work.
It also accepts some other options regarding reindentation, ...
[...]
Otherwise, your analysis of my examples are correct.
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.
May be, you can look into InsertIfNotAfter() that I define at the end
of ftplugin/cpp/cpp_set.vim (check the newly uploaded lh-cpp.tar.gz
tarball archive). I use it to define the abbreviation for `namespace'
and the mapping on m-t.
What you will need is to analyze the lines before the cursor. if the
`if' you are typing starts a new instruction, then you can expand
`if (!cursorhere!) {\n!mark!\n}!mark!', otherwise just
`if (!cursorhere!);!mark!'.
checking for the previous non comment code can be a little tricky.
I forgot there is quite a lot of documentation. I need to look at it
more.
Feel free to ask for any precision.
--
Luc Hermitte
http://hermitte.free.fr/vim/