Re: Scripting the enter key

2012-07-17 Thread Ben Fritz
On Monday, July 16, 2012 5:32:35 PM UTC-5, skeept wrote:
 
 By coincidence I was also trying to fix the problem that these two plugins 
 conflict by both defining a imap for the enter key.
 The closest I got was to add the following to a file after/plugin/
 
 imap lt;silentgt; lt;crgt; 
 lt;Pluggt;delimitMateCRlt;C-Rgt;=lt;SNRgt;34_SelectCompletion(1)lt;CRgt;
 
 this would be the mapping defined by delimitmate followed by the mapping 
 defined by supertab.
 This solution doesn#39;t really work, whenever I press enter two new lines 
 are entered and the braces in the expansion are not correctly aligned.
 The other way around doesn#39;t work (when I put the mapping from supertab 
 before the mapping from delimitmate). 
 
 Right now I gave up on the mapping for delimitmate and I am just using the 
 mapping for supertab and additionally have the following map:
 
 inoremap {{ {lt;crgt;lt;crgt;}lt;escgt;kcc
 
 if anyone has any idea on how to have the lt;crgt; key work for both 
 plugins it would be nice, otherwise I#39;ll stick to this mapping, once I 
 get used to it is not bad.
 

I assume your problem is with selecting a result from a completion menu using 
CR. Try using the pumvisible() function in an expression mapping, to return 
either the delimitMate mapping or the SuperTab mapping depending on whether the 
completion menu is visible.

I don't use SuperTab, but I use the following:

 always insert a completion menu item with Enter
imap expr CR pumvisible() ? \LTC-Y : \PlugdelimitMateCR

You may be able to replace the first return value with the supertab mapping. Or 
maybe you don't even need the supertab mapping if you use the above, I'm not 
sure what supertab does when you press CR.

-- 
You received this message from the vim_use maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php


Re: Scripting the enter key

2012-07-16 Thread Ben Fritz
On Monday, July 16, 2012 10:39:03 AM UTC-5, Douglas Mayle wrote:
 Hi all, I#39;m trying to write a function to make smarter line breaking when 
 I split a pair of parentheses or braces.  For example, with the text:
 span style=font-family:#39;courier new#39;,monospacefunc (/spanu 
 style=font-family:#39;courier new#39;,monospace)/u/div
 
 
 u style=font-family:#39;courier new#39;,monospace
 /u/div
 (The cursor is on the closing parentheses), when I hi enter, I#39;d like to 
 end with the following state:/div
 font face=courier new, monospacefunc (/font/div
 
 
 font face=courier new, monospace  _/font/div
 font face=courier new, monospace)/font/div
 In this case, the closing parentheses gets pushed down one line, and I end up 
 on the following line with correct indentation following my settings./div
 
 
 
 /div
 I#39;ve written a script to accomplish this, but the indentation is always 
 borked (It always starts at column 0).  Could anyone help me with 
 pointers?/div
 

Here's a few pointers:

1. If you use an expr map (or if start your mapping with C-R= instead of 
:), you can remain in insert mode when the mapping completes, without need for 
the C-\C-O
2. Whenever you leave insert mode, and the line has nothing but whitespace, and 
you have made no changes to the line in insert mode other than whitespace, Vim 
will automatically remove the whitespace on the line. I think this (combined 
with temporarily leaving insert mode) may be why your indent is not what you 
expect it to be.
3. There are plugins which can do your desired task already. For example, 
DelimitMate. http://www.vim.org/scripts/script.php?script_id=2754 Note this 
plugin is primarily for inserting matched pairs together, but it also does 
balanced insertion of spaces and line breaks within empty matched pairs. See 
http://vim.wikia.com/wiki/Automatically_append_closing_characters#Plugins

Were I doing what you ask by hand, I'd have a mapping which basically does one 
of these (starting from insert mode):

CREscO
CRCREsckcc

-- 
You received this message from the vim_use maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php


Re: Scripting the enter key

2012-07-16 Thread Douglas Mayle
Thanks for the tip on expr, I hadn't known about it!

Long story short, I was using 'autoclose' to do what delimitmate does, and
was looking to add the CR expansion myself.  It turns out that delimitmate
does everything that autoclose does, with smarter handling of matching
(e.g. dm: I'm versus ac: I''m), and adds the functionality as you've
mentioned.

The only caveat was that SuperTab (which I don't use, but was hanging
around in my bundle directory) conflicts with delimitmate, and so I had to
remove it.

In any case, I've got exactly what I was looking for, so thanks!

Cheers,
Doug

On Mon, Jul 16, 2012 at 11:07 AM, Ben Fritz fritzophre...@gmail.com wrote:

 On Monday, July 16, 2012 10:39:03 AM UTC-5, Douglas Mayle wrote:
  Hi all, I#39;m trying to write a function to make smarter line breaking
 when I split a pair of parentheses or braces.  For example, with the text:
  span style=font-family:#39;courier
 new#39;,monospacefunc (/spanu style=font-family:#39;courier
 new#39;,monospace)/u/div
 
 
  u style=font-family:#39;courier new#39;,monospace
  /u/div
  (The cursor is on the closing parentheses), when I hi enter, I#39;d
 like to end with the following state:/div
  font face=courier new, monospacefunc (/font/div
 
 
  font face=courier new, monospace  _/font/div
  font face=courier new, monospace)/font/div
  In this case, the closing parentheses gets pushed down one line, and I
 end up on the following line with correct indentation following my
 settings./div
 
 
 
  /div
  I#39;ve written a script to accomplish this, but the indentation is
 always borked (It always starts at column 0).  Could anyone help me with
 pointers?/div
 

 Here's a few pointers:

 1. If you use an expr map (or if start your mapping with C-R= instead
 of :), you can remain in insert mode when the mapping completes, without
 need for the C-\C-O
 2. Whenever you leave insert mode, and the line has nothing but
 whitespace, and you have made no changes to the line in insert mode other
 than whitespace, Vim will automatically remove the whitespace on the line.
 I think this (combined with temporarily leaving insert mode) may be why
 your indent is not what you expect it to be.
 3. There are plugins which can do your desired task already. For example,
 DelimitMate. http://www.vim.org/scripts/script.php?script_id=2754 Note
 this plugin is primarily for inserting matched pairs together, but it also
 does balanced insertion of spaces and line breaks within empty matched
 pairs. See
 http://vim.wikia.com/wiki/Automatically_append_closing_characters#Plugins

 Were I doing what you ask by hand, I'd have a mapping which basically does
 one of these (starting from insert mode):

 CREscO
 CRCREsckcc

 --
 You received this message from the vim_use maillist.
 Do not top-post! Type your reply below the text you are replying to.
 For more information, visit http://www.vim.org/maillist.php


-- 
You received this message from the vim_use maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php


Re: Scripting the enter key

2012-07-16 Thread skeept
On Monday, July 16, 2012 4:13:23 PM UTC-5, Douglas Mayle wrote:
 Thanks for the tip on lt;exprgt;, I hadn#39;t known about it!
 
 /div
 Long story short, I was using #39;autoclose#39; to do what delimitmate 
 does, and was looking to add the CR expansion myself.  It turns out that 
 delimitmate does everything that autoclose does, with smarter handling of 
 matching (e.g. dm: I#39;m versus ac: I#39;#39;m), and adds the 
 functionality as you#39;ve mentioned./div
 
 
 
 /div
 The only caveat was that SuperTab (which I don#39;t use, but was hanging 
 around in my bundle directory) conflicts with delimitmate, and so I had to 
 remove it./div
 
 /div
 In any case, I#39;ve got exactly what I was looking for, so thanks!/div
 
 
 
 /div
 Cheers,/div
 Doug
 

By coincidence I was also trying to fix the problem that these two plugins 
conflict by both defining a imap for the enter key.
The closest I got was to add the following to a file after/plugin/

imap silent cr PlugdelimitMateCRC-R=SNR34_SelectCompletion(1)CR

this would be the mapping defined by delimitmate followed by the mapping 
defined by supertab.
This solution doesn't really work, whenever I press enter two new lines are 
entered and the braces in the expansion are not correctly aligned.
The other way around doesn't work (when I put the mapping from supertab before 
the mapping from delimitmate). 

Right now I gave up on the mapping for delimitmate and I am just using the 
mapping for supertab and additionally have the following map:

inoremap {{ {crcr}esckcc

if anyone has any idea on how to have the cr key work for both plugins it 
would be nice, otherwise I'll stick to this mapping, once I get used to it is 
not bad.

Best Regards,

Jorge

-- 
You received this message from the vim_use maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php