]> granicus.if.org Git - vim/commitdiff
patch 8.1.0225: mode() does not indicate using CTRL-O from Insert mode v8.1.0225
authorBram Moolenaar <Bram@vim.org>
Sun, 29 Jul 2018 13:34:26 +0000 (15:34 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 29 Jul 2018 13:34:26 +0000 (15:34 +0200)
Problem:    Mode() does not indicate using CTRL-O from Insert mode.
Solution:   Add "niI", "niR" and "niV" to mode() result. (closes #3000)

runtime/doc/eval.txt
src/evalfunc.c
src/testdir/test_functions.vim
src/version.c

index 964eab125fc091465cf3ce8316ed8bf9fd63ab82..2c9c114396676f6bf3cc32f20e5075c09d9fa6d7 100644 (file)
@@ -6224,32 +6224,38 @@ mode([expr])    Return a string that indicates the current mode.
                a non-empty String (|non-zero-arg|), then the full mode is
                returned, otherwise only the first letter is returned.
 
-                       n       Normal, Terminal-Normal
-                       no      Operator-pending
-                       v       Visual by character
-                       V       Visual by line
-                       CTRL-V  Visual blockwise
-                       s       Select by character
-                       S       Select by line
-                       CTRL-S  Select blockwise
-                       i       Insert
-                       ic      Insert mode completion |compl-generic|
-                       ix      Insert mode |i_CTRL-X| completion
-                       R       Replace |R|
-                       Rc      Replace mode completion |compl-generic|
-                       Rv      Virtual Replace |gR|
-                       Rx      Replace mode |i_CTRL-X| completion
-                       c       Command-line editing
-                       cv      Vim Ex mode |gQ|
-                       ce      Normal Ex mode |Q|
-                       r       Hit-enter prompt
-                       rm      The -- more -- prompt
-                       r?      A |:confirm| query of some sort
-                       !       Shell or external command is executing
-                       t       Terminal-Job mode: keys go to the job
+                  n        Normal, Terminal-Normal
+                  no       Operator-pending
+                  niI      Normal using |i_CTRL-O| in |Insert-mode|
+                  niR      Normal using |i_CTRL-O| in |Replace-mode|
+                  niV      Normal using |i_CTRL-O| in |Virtual-Replace-mode|
+                  v        Visual by character
+                  V        Visual by line
+                  CTRL-V   Visual blockwise
+                  s        Select by character
+                  S        Select by line
+                  CTRL-S   Select blockwise
+                  i        Insert
+                  ic       Insert mode completion |compl-generic|
+                  ix       Insert mode |i_CTRL-X| completion
+                  R        Replace |R|
+                  Rc       Replace mode completion |compl-generic|
+                  Rv       Virtual Replace |gR|
+                  Rx       Replace mode |i_CTRL-X| completion
+                  c        Command-line editing
+                  cv       Vim Ex mode |gQ|
+                  ce       Normal Ex mode |Q|
+                  r        Hit-enter prompt
+                  rm       The -- more -- prompt
+                  r?       A |:confirm| query of some sort
+                  !        Shell or external command is executing
+                  t        Terminal-Job mode: keys go to the job
                This is useful in the 'statusline' option or when used
                with |remote_expr()| In most other places it always returns
                "c" or "n".
+               Note that in the future more modes and more specific modes may
+               be added. It's better not to compare the whole string but only
+               the leading character(s).
                Also see |visualmode()|.
 
 mzeval({expr})                                                 *mzeval()*
index 12eac8d5487d8cb7abfed23979aa2aea98dd1c78..40fbf373a4e1eb99c8a0f833dbac8170b223a82d 100644 (file)
@@ -8366,10 +8366,9 @@ f_mkdir(typval_T *argvars, typval_T *rettv)
     static void
 f_mode(typval_T *argvars, typval_T *rettv)
 {
-    char_u     buf[3];
+    char_u     buf[4];
 
-    buf[1] = NUL;
-    buf[2] = NUL;
+    vim_memset(buf, 0, sizeof(buf));
 
     if (time_for_testing == 93784)
     {
@@ -8435,6 +8434,12 @@ f_mode(typval_T *argvars, typval_T *rettv)
        buf[0] = 'n';
        if (finish_op)
            buf[1] = 'o';
+       else if (restart_edit == 'I' || restart_edit == 'R'
+                                                       || restart_edit == 'V')
+       {
+           buf[1] = 'i';
+           buf[2] = restart_edit;
+       }
     }
 
     /* Clear out the minor mode when the argument is not a non-zero number or
index 14181fb0a45a6f555d46b0cd10215266e18467cb..41996bd451599abe1b41923a7f5e281a8cd703f5 100644 (file)
@@ -464,6 +464,18 @@ func Test_mode()
   call assert_equal('n', mode(0))
   call assert_equal('n', mode(1))
 
+  " i_CTRL-O
+  exe "normal i\<C-O>:call Save_mode()\<Cr>\<Esc>"
+  call assert_equal("n-niI", g:current_modes)
+
+  " R_CTRL-O
+  exe "normal R\<C-O>:call Save_mode()\<Cr>\<Esc>"
+  call assert_equal("n-niR", g:current_modes)
+
+  " gR_CTRL-O
+  exe "normal gR\<C-O>:call Save_mode()\<Cr>\<Esc>"
+  call assert_equal("n-niV", g:current_modes)
+
   " How to test operator-pending mode?
 
   call feedkeys("v", 'xt')
index ab58a5c179e0b1f50ed9aba8723fc8c790962def..1aa6448fbbbf4b96ce6681a37d268b6a5f6ef8eb 100644 (file)
@@ -798,6 +798,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    225,
 /**/
     224,
 /**/