All,
Andy Wokula suggested a solution to the problem that
buffer-local mappings have to wait if they are prefixes of
global mappings. Below is a patch that implements his
suggestion.
A new 'localmaplinger' option is introduced. When set (the
default), Vim behaves in the traditional way. When reset,
complete buffer-local mappings will be accepted immediately
without waiting for incomplete global mappings.
As I'd commented in a previous thread, it's hard to know what
name to choose for this option; improvements to the name are
welcome.
The patch includes documentation along with the minor code
change. I didn't know how to implement a test for this
functionality. If anyone has a suggestion on that front, I'd be
happy to try to implement something.
Michael Henry
diff -r 274c841f033a runtime/doc/map.txt
--- a/runtime/doc/map.txt Fri Jan 25 20:11:01 2013 +0100
+++ b/runtime/doc/map.txt Tue Jan 29 08:26:29 2013 -0500
@@ -654,6 +654,15 @@
you type slowly, or your system is slow, reset the 'timeout' option.
Then you
might want to set the 'ttimeout' option.
+ *map-linger*
+By default, the presence of any incomplete matches will cause Vim to
wait for
+more input, as described above in |map-typing|. This can be undesirable
+when a short buffer-local mapping is a prefix of a longer global mapping,
+since it's likely that the user wants the specialized local mapping to
+be used right away. To cause Vim to accept complete buffer-local mappings
+immediately despite the presence of incomplete global mappings, reset the
+'localmaplinger' option.
+
*map-keys-fails*
There are situations where key codes might not be recognized:
- Vim can only read part of the key code. Mostly this is only the first
diff -r 274c841f033a runtime/doc/options.txt
--- a/runtime/doc/options.txt Fri Jan 25 20:11:01 2013 +0100
+++ b/runtime/doc/options.txt Tue Jan 29 08:26:29 2013 -0500
@@ -4649,6 +4649,26 @@
Note that using the "-u NONE" and "--noplugin" command line arguments
reset this option. |-u| |--noplugin|
+ *'localmaplinger'* *'nolocalmaplinger'*
+'localmaplinger' boolean (default on)
+ global
+ {not in Vi}
+ When 'localmaplinger' is set (the default), Vim gives equal
priority
+ to buffer-local and global mappings in the traditional way. As
+ explained in |map-typing|, it compares what you type against all
+ mapped sequences. If it finds at least one incomplete match,
it will
+ get more characters until no more incomplete matches exist,
then use
+ the longest complete match it has found (if any).
+
+ When 'localmaplinger' is reset, Vim will treat buffer-local
mappings
+ as more important than global mappings. When it finds a complete
+ match for a buffer-local mapping with no incomplete buffer-local
+ matches, it will not wait for any incomplete matches of global
+ mappings. This is useful for plugins that make buffer-local
mappings
+ which are prefixes of longer global mappings, resulting in forced
+ delays of 'timeoutlen' before the incomplete global mapping
times out
+ and allows the local mapping to take effect.
+
*'macatsui'* *'nomacatsui'*
'macatsui' boolean (default on)
global
diff -r 274c841f033a src/getchar.c
--- a/src/getchar.c Fri Jan 25 20:11:01 2013 +0100
+++ b/src/getchar.c Tue Jan 29 08:26:29 2013 -0500
@@ -1912,6 +1912,7 @@
mapblock_T *mp;
#ifdef FEAT_LOCALMAP
mapblock_T *mp2;
+ int expecting_global_mappings;
#endif
mapblock_T *mp_match;
int mp_match_len = 0;
@@ -2093,6 +2094,7 @@
/* First try buffer-local mappings. */
mp = curbuf->b_maphash[MAP_HASH(local_State, c1)];
mp2 = maphash[MAP_HASH(local_State, c1)];
+ expecting_global_mappings = (mp && mp2);
if (mp == NULL)
{
mp = mp2;
@@ -2116,6 +2118,22 @@
#endif
(mp = mp->m_next))
{
+#ifdef FEAT_LOCALMAP
+ if (expecting_global_mappings && mp2 == NULL)
+ {
+ /*
+ * This is the first global mapping. If we've
+ * got a complete buffer-local match and we
+ * shouldn't linger for a longer global match,
+ * use the current match.
+ */
+ if (mp_match && !p_lmlinger)
+ {
+ break;
+ }
+ expecting_global_mappings = FALSE;
+ }
+#endif
/*
* Only consider an entry if the first character
* matches and it is for the current state.
diff -r 274c841f033a src/option.c
--- a/src/option.c Fri Jan 25 20:11:01 2013 +0100
+++ b/src/option.c Tue Jan 29 08:26:29 2013 -0500
@@ -1706,6 +1706,11 @@
{"loadplugins", "lpl", P_BOOL|P_VI_DEF,
(char_u *)&p_lpl, PV_NONE,
{(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
+#ifdef FEAT_LOCALMAP
+ {"localmaplinger",NULL, P_BOOL|P_VI_DEF,
+ (char_u *)&p_lmlinger, PV_NONE,
+ {(char_u *)TRUE, (char_u *)0L} SCRIPTID_INIT},
+#endif
#ifdef FEAT_GUI_MAC
{"macatsui", NULL, P_BOOL|P_VI_DEF|P_RCLR,
(char_u *)&p_macatsui, PV_NONE,
diff -r 274c841f033a src/option.h
--- a/src/option.h Fri Jan 25 20:11:01 2013 +0100
+++ b/src/option.h Tue Jan 29 08:26:29 2013 -0500
@@ -592,6 +592,9 @@
EXTERN int p_lz; /* 'lazyredraw' */
EXTERN int p_lpl; /* 'loadplugins' */
+#ifdef FEAT_LOCALMAP
+EXTERN int p_lmlinger; /* 'localmaplinger' */
+#endif
#ifdef FEAT_GUI_MAC
EXTERN int p_macatsui; /* 'macatsui' */
#endif
--
--
You received this message from the "vim_dev" 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_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.