Friday, May 23, 2014

Re: Get expansion of digraph in VimL


On May 24, 2014 4:38 AM, "John Little" <John.B.Little@gmail.com> wrote:
>
> On Saturday, May 24, 2014 12:21:27 AM UTC+12, ZyX wrote:
> > Digraphs work also in Ex mode. So I would rather use it, CTRL-\ e and getcmdline() are your friends here: this way there are no or almost no side-effects. At least I do not know any side-effects other then inevitable things like heating the processor a bit. Example I used to test CTRL-K . . expansion:
> >
> >
> >     execute 'normal!' ":\<C-k>..\<C-\>eextend(g:, {'digraph': getcmdline()}).digraph\n"
> >
> > This even did not alter cmd and expr history (it would if I typed :normal! argument myself).
>
> Yes, using the command line instead of a scratch buffer is much nicer.  But saving the result by manipulating the dictionary that holds the global variables, then because the function that manipulates returns the dictionary, using the dict.key syntax to avoid an error, well, (referring to my earlier jocular phrase) this animal got a headache puzzling it out.  If I want an expression to have side effects, I think of a function:

g: dictionary is not the only dictionary out there. There is also l:, but I would suggest just creating a new one inside function.

>
> function! SaveCmd()
>     let g:EDcmd = getcmdline()
> endfunc
> function! ExpandDigraph(dig)
>     if a:dig !~ '^..$'
>         return ""
>     endif
>     exe "norm! :\<c-k>" . a:dig . "\<c-\>eSaveCmd()\n"
>     return g:EDcmd
> endfunc
>
> That relies on the fact that an incomplete "normal" command is abandoned; one could add \<c-c> to explicitly abandon it I suppose.
>
> Regards, John Little
>
> --
> --
> 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 because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
--
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 because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment