Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion cnoremap <C-\>e maps within the expression register
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Christian Brabandt  
View profile  
 More options Oct 1 2012, 8:49 am
From: "Christian Brabandt" <cbli...@256bit.org>
Date: Mon, 1 Oct 2012 14:49:14 +0200
Local: Mon, Oct 1 2012 8:49 am
Subject: Re: cnoremap <C-\>e maps within the expression register

On Mon, October 1, 2012 13:16, Marcin Szamotulski wrote:
> On 09:20 Sun 23 Sep     , Marcin Szamotulski wrote:
>> Hello

>> The c_CTRL-\_e (<C-\>e) maps inside expression register are not working.
>> There is a very nice emacscommandline
>> (http://www.vim.org/scripts/script.php?script_id=3554)
>> plugin which defines lots of nice maps in this way, but then when one
>> tries to write to expression register one gets errors. The minimal setup
>> to reproduce this is:

>> fun X()
>>   return 'echo "X"'
>> endfun
>> cnoremap X <C-\>eX()<CR>

>> Now please try in insert mode:
>> <c-r>=X
>> and after pressing X I get the following error:
>> E15: invalid expression: ^eX()
>> E15: invalid expression: ^eX()

>> I got it twice. I think it would be nice to have the <C-\>e maps
>> working inside expression register (and in this case it would be nice of
>> vim script knew it, for example through including the '=' into to
>> getcmdline()) or to disable the <C-\>e maps inside the expression
>> register.

>> Best regards,
>> Marcin

> In case somebody will stumble across this post, the solution that
> I found for this is to define another map:
>     cnoremap <C-b> <C-R>
> etc ... . It will not trigger the emacscommand line maps. One just has
> to remember to not to use <C-W> while entering things into the
> expression register (which is used rarely, so there is not much
> opportunity to learn it, and lots of chances to forget it ;)

> But this is far from perfect.

Would it be enough to simply disallow mappings in expression evalution mode?

diff --git a/src/ex_getln.c b/src/ex_getln.c
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -1128,7 +1128,6 @@
                    i = Ctrl_R;         /* CTRL-R CTRL-O == CTRL-R CTRL-R */
                if (i == Ctrl_R)
                    c = plain_vgetc();  /* CTRL-R CTRL-R <char> */
-               --no_mapping;
 #ifdef FEAT_EVAL
                /*
                 * Insert the result of an expression.
@@ -1136,6 +1135,10 @@
                 * a new one...
                 */
                new_cmdpos = -1;
+               /* allow special keys like BS, but don't allow mappings.
+                * prevents from trying to evaluate c_Ctrl-\_e mappings
+                * where the ctrl-\ e makes the following expression invalid */
+               ++allow_keys;
                if (c == '=')
                {
                    if (ccline.cmdfirstc == '=')/* can't do this recursively */
@@ -1150,7 +1153,10 @@
                        restore_cmdline(&save_ccline);
                    }
                }
-#endif
+               --allow_keys;
+#endif
+               --no_mapping;
+
                if (c != ESC)       /* use ESC to cancel inserting register */
                {
                    cmdline_paste(c, i == Ctrl_R, FALSE);

regards,
Christian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.