Re: abbreviations + indent + movement commands

2006-09-27 Thread Luc Hermitte
Hello,

* On Mon, Sep 25, 2006 at 08:29:02PM +0200, Kim Schulz [EMAIL PROTECTED] 
wrote:
  I finally converged to the use of search(), on a placeholder
  regex-pattern. This way neither @/ nor the search history are messed
  up by irrelevant patterns.
 
 I have been playing around with the search() but I couldn't quite get
 the hang of it. 

As Benji said, search() returns a value that is not an insert mode
action, but a line number.

 Could you maybe give me an example on how to use it in relation to an
 abbrev. What I tried was:

My use of search() is completely encapsulated. It is called from within a
function that returns the normal mode action that can reselects the
placeholder once out of the function. It is used then in the family of
mappings !jump!, !jumpB!, ...

Then, my smart-abbreviations (they are context-sensitive) insert a text
through
   c-r=InsertSeq(,
   \ 'for (!cursorhere! ; !mark! ; !mark!)\n{\n!mark!\n}')

InsertSeq() is really tricky. Among the may things it does, it replaces
!stuff! by the keys binded to the insert mode-mapping !stuff! -- 99%
of the time the ones I code (and use in InsertSeq()) rely on a function
call. 
!cursorhere! takes a snapshot of cursor position, and InsertSeq() move
the cursor to the snapshotted position -- when it detects !cursorhere!.

Actually I could have used the placeholder inserted by mark, but I
wanted to be able to place the cursor anywhere, not necessarily on the
first placeholder.

IIRC, that's what has been done in Srinath  al. IMAP.vim plugin: the
cursor is moved to the first placeholder.

HTH,
-- 
Luc Hermitte
http://hermitte.free.fr/vim/


Re: abbreviations + indent + movement commands

2006-09-26 Thread Benji Fisher
On Mon, Sep 25, 2006 at 08:29:02PM +0200, Kim Schulz wrote:
 On Sat, 23 Sep 2006 17:08:39 +0200
 Luc Hermitte [EMAIL PROTECTED] wrote:
 [snip]
 
   I guess it is in the mark for place of last change, but I just cant
   get iabbrev to execute my movement command (other than using left
   right up down). Is there any way to do this?
  
  I finally converged to the use of search(), on a placeholder
  regex-pattern. This way neither @/ nor the search history are messed
  up by irrelevant patterns.
 
 I have been playing around with the search() but I couldn't quite get
 the hang of it. 
 Could you maybe give me an example on how to use it in relation to an
 abbrev. What I tried was:
 :iabbrev for( for
 (!cursor!;+++;+++){\n+++\n}C-R=search('!cursor!',b)crc/+/ecr
 
 but this inserts the linenumber where it finds the placeholder. 
 I would rather like it ro remove the placeholder and move the cursor
 there. 
 any ideas? 

 That is because search() returns a value.  It is a little odd that
you mix markers, using both !cursor! and ++, but I guess that makes it
easier to jump back to the first one.  This is a little closer to what
you want:

:iabbrev for( for(!cursor!;+++;+++){\n+++\n}Esc:call 
search('!cursor!','b')crcf!

Instead of using C-R= , I go into Command-Line mode with Esc: .  I
added quotes around the 'b' flag for search() and I used  f!  (in Normal
mode) rather than /+/e because (1) it goes to the end of the first
marker, not the second and (2) it does not affect the search history.
(It does affect the , and ; commands, though.)

HTH --Benji Fisher


Re: abbreviations + indent + movement commands

2006-09-25 Thread Kim Schulz
On Sat, 23 Sep 2006 17:08:39 +0200
Luc Hermitte [EMAIL PROTECTED] wrote:
[snip]

  I guess it is in the mark for place of last change, but I just cant
  get iabbrev to execute my movement command (other than using left
  right up down). Is there any way to do this?
 
 I finally converged to the use of search(), on a placeholder
 regex-pattern. This way neither @/ nor the search history are messed
 up by irrelevant patterns.

I have been playing around with the search() but I couldn't quite get
the hang of it. 
Could you maybe give me an example on how to use it in relation to an
abbrev. What I tried was:
:iabbrev for( for
(!cursor!;+++;+++){\n+++\n}C-R=search('!cursor!',b)crc/+/ecr

but this inserts the linenumber where it finds the placeholder. 
I would rather like it ro remove the placeholder and move the cursor
there. 
any ideas? 
-- 
Kim Schulz| Private :  http://www.schulz.dk
[EMAIL PROTECTED] | Business:  http://www.devteam.dk
+45 5190 4262 | Sparetime: http://www.fundanemt.com


Re: abbreviations + indent + movement commands

2006-09-23 Thread Luc Hermitte

Hi again,

* On Sat, Sep 23, 2006 at 03:38:58PM +0200, Kim Schulz [EMAIL PROTECTED] 
wrote:
 I am playing a bit around with abbreviations, in order to use them for
 simple pattern templates when I code. like:
 iabbrev for( for (%%%;%%%;%%%){CRCR}
 
 How can I get it to obey my indentation rules? 

In my ftplugins set ``lh-cpp'', I interpret c-f (the correct
keybinding should actually match the indent options) from within
abbreviations inserted through i_CTRL-R_=. In the next release, I plan
to support a !reindent! trigger to define my abbreviations. 

In mu-template, I have a template option s:reindent, that triggers a call
to
exe first.','.last.'normal! =='  IIRC
first and last initial values are based on '[ and '] (which are
automatically set), and adjusted according to lines removed from the
template file.

 Second problem:
 
 After the for( is changed to the for (){...} I would like to move
 the cursor to the first spot just inside the () without having to do
 this manually. is there a way to go to that place ?

Use placeholders, and reserve a mapping/trigger that jumps to the
placeholder.  In lh-map-tool, I use !cursorhere! (and !gotocursor!,
which is an implementation detail) to acheive this.

 I guess it is in the mark for place of last change, but I just cant
 get iabbrev to execute my movement command (other than using left
 right up down). Is there any way to do this?

I finally converged to the use of search(), on a placeholder
regex-pattern. This way neither @/ nor the search history are messed up
by irrelevant patterns.

If everytime (i.e., for every keywords - for, if, while, ...) you
count the number of lines or columns you have to move the cursor, it
becomes quickly boring to maintain the end-user mappings. Moreover, you
won't be able to propose customizations like inserting newlines before
and/or after curly- and round-brackets -- because the coding rules in
different projects require different presentations.

HTH,

-- 
Luc Hermitte
http://hermitte.free.fr/vim/