Bram Moolenaar wrote:
Ben Schmidt wrote:
I started this patch as it seemed a while ago some aspects it may be
helpful for MacVim. Recently I have dug it up and further revised it,
as I was coming across some other troubles using --remote-expr when
Vim is running in different modes. It extends the mode() function to
return a more full set of modes.
The one bearing most comment is the one for when a shell is running
(:shell in the GUI). I'm not entirely convinced having this as a
separate 'mode' is really the best thing. Hoewver, the alternative
would be somehow delaying a server's processing and reply to
--remote-expr et al. and I suspect this is pretty non-trivial. Having
mode() return something different is a good step even if it isn't the
final one, I think.
Would you be able to include this?
Problem with this change is that it's not backwards compatible. E.g.,
currently Vim would return n in operator-pending mode, after the
change it would return o.
How about giving mode() an argument? When present and non-zero it would
switch to return more information. I would then return both the major
mode and the detail. E.g., for Vim Ex mode it would be cv, normal Ex
mode ce and for command-line mode c. Then for those places where it
doesn't matter what kind of command-line mode is being used you would
only check the first letter. Also makes it easier for future changes,
so long as it fits in the current major modes.
Yep, sounds good. Here's a revised patch.
I made the '-- more --' prompt a separate minor mode, as that seemed
sensible--can't really see any use for the distinction, but better to have it
than
try to add it later once we figure out what it's for and then have more
compatibility issues (no pun intended!).
I kept '!' as a major mode as really none of the other modes apply--even though
the function used to return 'n', it's not necessarily true that you will be in
normal mode after an external command finishes. So I'd view that change as a
bugfix not a breaking of compatibility. If you think that's a bad call, it
could
be changed to 'n!' I suppose.
Ben.
--~--~-~--~~~---~--~~
You received this message from the vim_dev maillist.
For more information, visit http://www.vim.org/maillist.php
-~--~~~~--~~--~--~---
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index fc6aa5d..3d9402b 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -1750,7 +1750,7 @@ max({list}) Number maximum value of items in {list}
min({list}) Number minimum value of items in {list}
mkdir({name} [, {path} [, {prot}]])
Number create directory {name}
-mode()String current editing mode
+mode( [expr]) String current editing mode
nextnonblank( {lnum}) Number line nr of non-blank line = {lnum}
nr2char( {expr}) String single char with ASCII value {expr}
pathshorten( {expr}) String shorten directory names in a path
@@ -3846,8 +3846,12 @@ mkdir({name} [, {path} [, {prot}]])
:if exists(*mkdir)
*mode()*
-mode() Return a string that indicates the current mode:
+mode([expr]) Return a string that indicates the current mode.
+ If an expression is supplied that results in a non-zero number
+ or a non-empty string, then the full mode is returned,
+ otherwise only the first letter is returned.
n Normal
+ no Operator-pending
v Visual by character
V Visual by line
CTRL-V Visual blockwise
@@ -3857,9 +3861,15 @@ mode() Return a string that indicates the current mode:
i Insert
R Replace
c Command-line
+ cv Vim Ex mode |gQ|
+ ce Normal Ex mode |Q|
r Hit-enter prompt
- This is useful in the 'statusline' option. In most other
- places it always returns c or n.
+ rm The -- more -- prompt
+ r? A |:confirm| query of some sort
+ ! Shell or external command is executing
+ This is useful in the 'statusline' option or when used
+ with |remote_expr()| In most other places it always returns
+ c or n.
nextnonblank({lnum}) *nextnonblank()*
Return the line number of the first line at or below {lnum}
diff --git a/src/eval.c b/src/eval.c
index 4ec28fd..508935d 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -7197,7 +7197,7 @@ static struct fst
#ifdef vim_mkdir
{mkdir, 1, 3, f_mkdir},
#endif
-{mode, 0, 0, f_mode},
+{mode, 0, 1, f_mode},
{nextnonblank, 1, 1, f_nextnonblank},
{nr2char, 1, 1, f_nr2char},
{pathshorten, 1, 1, f_pathshorten},
@@ -12865,7 +12865,9 @@ f_mode(argvars, rettv)
typval_T *argvars;
typval_T *rettv;
{
-char_u buf[2];
+char_u buf[3];
+
+buf[1] = NUL;
#ifdef FEAT_VISUAL
if (VIsual_active)
@@ -12877,8 +12879,17 @@ f_mode(argvars, rettv)
}
else
#endif
- if (State == HITRETURN || State == ASKMORE || State == SETWSIZE)
+ if (State == HITRETURN || State == ASKMORE || State == SETWSIZE ||
+ State == CONFIRM)
+{
buf[0] = 'r';
+ if (State ==