Monday, December 8, 2014

Re: Is there a way to get info when Vim enters into operator-pending-mode and leaves it?

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On December 8, 2014 11:43:55 AM EAT, Igor Forca <igor2x@gmail.com> wrote:
>Ben,
>thanks for your comment. I have already tested this solution few weeks
>ago and I didn't like it. Why? Because I am switching between
>applications (gVim and others) and I am using Caps Locks in other
>applications and when switching to gVim your suggested solution
>requires! to disable Caps Lock. I often forget to press Caps Lock to
>disable it in gVim and also I actually don't want to disable it for
>other applications.
>
>Currently I have managed to write a program in AutoHotKey to have Caps
>Lock zero effect on gVim, but it works perfectly in other applications.
>So if I press Caps Lock and type some text e.g. in Notepad then upper
>case letters are displayed. Switching to gVim and Caps Lock has no
>effect despite being turned on (caps lock light on keyboard), switching
>back to Notepad and I still have Caps lock enabled so upper case. This
>is exactly what I want.
>
>So the main problem is still there. Is there any way to get info from
>gVim to tell me that it is currently in operator-pending-mode?
>
>--
>--
>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.

I know the following ways to get the current mode with mode():

1. Hack &statusline: 'let &statusline.="%{SomeFunctionThatNotifiesSystemAboutCurrentModeAndReturnsEmptyString()}"'. This is not working for operator-pending mode.
2. Try using 'vim.Function("mode")(1)' and query Vim from a separate thread repeatedly. 'vim.Function("mode")' needs to be saved in some object from a main thread. If you try this solution beware that Vim is single-threaded and this variant may only work by accident. I think that there are good chances that it will work by accident always and to increase these chances you *must* use vim.Function object so that vim will not try to access the current scope or any other unrelated global (which will be the case for 'vim.eval("mode(1)")').
3. Try using 'remote_expr()'. Needs Vim with +clientserver. Note that I have no idea how it is able to run concurrently given Vim is single-threaded application with a hell lot of the global state.
4. If you can create some app which tells Vim it was resized (i.e. on linux it is as simple as using 'kill -WINCH') repeatedly you can try using VimResized event. Never tried using mode() in it there though.

Any solution except for the first (which is the only known not to work) has potential concurrency problems that may lead to crashing Vim. *All* solutions use polling, there is no event like OperatorPendingEnter (AFAIK such events only exist for insert mode entering/leaving).
-----BEGIN PGP SIGNATURE-----
Version: APG v1.1.1

iQI1BAEBCgAfBQJUhZdkGBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj
HhHSvhJLD/4zBhJj2CDGSuPsGb62aCy5Dei0u3jYfg+XdRU05rHRRhOCy9yw8HR/
lWJzA4u8Cca+eXVHtg3+LeRX6JP/VCSQN5T/Xwhg+LYv6XSUu3ALKWRzeP8F//sf
yVRYFMrcL8i5BD1JKj7YogLwgoipo9F49qMVcoHxys+4H6RqFCjp2aRSy02xszLd
bmTxownvHHV7WFW+29MhlugoEzLKmvU5WjfpiJd/LmD2qdBgukyY4+JXJ5AgNpcc
sVizQw4+Q5ALZFqeGjg3CySJDEfcOaflCJkN1m7mb/MxlgXaOBLbG6zf8YrbEtsJ
SXW1bx+I6QEos6RODJ43KprJsRLncOU2cnO98b0HClsO3YyPnzoxKl96hxBii+ey
kaYEHI+iRowgAvMLOF3BuL8JjHXn8Jxm8cGiEyHUrxc+vc0wkTFqsuirN9KsiR2O
mY4VmV1tmcGcp6WnfxcOnyMpkqtBWoVol1Sg7wdJTeIc0CajSCpw6JA/6SODGdzM
aTIu0ef9CQpzadH9JfCVsLa4KxNyVdAAYYj7eRe+j4duhmok0aYVWfwmji0e7qvt
KEym9K/Ml+dqs6IdTzdhnmu7679Z4wetvSxxwanor4FQg792qAyG2gCEImVhD13u
MeEnAR5JR3tBUY2hbWeG5gPgwejZlJCCLwNkhjct7xphWBk58lCqsw==
=0Mri
-----END PGP SIGNATURE-----

--
--
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