]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0852: No warning when X11 registers are not available v9.1.0852
authorChristian Brabandt <cb@256bit.org>
Mon, 11 Nov 2024 19:52:55 +0000 (20:52 +0100)
committerChristian Brabandt <cb@256bit.org>
Mon, 11 Nov 2024 19:52:55 +0000 (20:52 +0100)
Problem:  No warning when X11 registers are not available
          (delvh)
Solution: Output W23 once when connection to X11 clipboard/selection
          is not possible, mention in the documentation, that register 0
          will be used instead

Vim silently uses the 0 register, when clipboard or selection register * or +
are not available. This might be a bit unexpected for the user.

So let's just warn once when this happens.

fixes: #14768
closes: #16013

Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/doc/gui.txt
runtime/doc/gui_x11.txt
runtime/doc/tags
src/clipboard.c
src/message.c
src/proto/message.pro
src/register.c
src/testdir/test_registers.vim
src/version.c

index 071de9c4b133c88ca7916d2d256ddae0337a75ca..4fdfc0f05a7dd1144cac5031167b1b10b4580974 100644 (file)
@@ -1,4 +1,4 @@
-*gui.txt*       For Vim version 9.1.  Last change: 2024 Jul 17
+*gui.txt*       For Vim version 9.1.  Last change: 2024 Nov 07
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -474,6 +474,8 @@ When the "unnamed" string is included in the 'clipboard' option, the unnamed
 register is the same as the "* register.  Thus you can yank to and paste the
 selection without prepending "* to commands.
 
+See also |W23|.
+
 ==============================================================================
 5. Menus                                               *menus*
 
index dbd4b10843673ae14879d7410c2a30fa8729efc5..0658bfab983457d975877475313cf45522efe140 100644 (file)
@@ -1,4 +1,4 @@
-*gui_x11.txt*   For Vim version 9.1.  Last change: 2024 Apr 22
+*gui_x11.txt*   For Vim version 9.1.  Last change: 2024 Nov 11
 
 
                  VIM REFERENCE MANUAL    by Bram Moolenaar
@@ -708,6 +708,14 @@ Examples: (assuming the default option values)
 Note that the text in the "+ register remains available when making a Visual
 selection, which makes other text available in the "* register.  That allows
 overwriting selected text.
+
+                                                               *W23*
+When you are yanking into the "* or "+ register and Vim cannot establish a
+connection to the X11 selection (or clipboard), it will use register 0 and
+output a warning:
+
+  Warning: Clipboard register not available, using register 0 ~
+
                                                        *x11-cut-buffer*
 There are, by default, 8 cut-buffers: CUT_BUFFER0 to CUT_BUFFER7.  Vim only
 uses CUT_BUFFER0, which is the one that xterm uses by default.
index d38c8958e89abcfd1c9a42c0d6202677d2b35e11..00d65eb12b0e0df9a91f3132c5fae5f6975f545a 100644 (file)
@@ -5818,6 +5818,7 @@ W19       autocmd.txt     /*W19*
 W20    if_pyth.txt     /*W20*
 W21    if_pyth.txt     /*W21*
 W22    userfunc.txt    /*W22*
+W23    gui_x11.txt     /*W23*
 WORD   motion.txt      /*WORD*
 WSL    os_win32.txt    /*WSL*
 WWW    intro.txt       /*WWW*
index 6c8b60c2e74115816af0203e7cb572855dca6ccb..75e0f4f320ad00bcdc74ed6eb4e90ff128e345b4 100644 (file)
@@ -2220,10 +2220,12 @@ adjust_clip_reg(int *rp)
            *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS)
                                           && clip_plus.available) ? '+' : '*';
     }
-    if (!clip_star.available && *rp == '*')
-       *rp = 0;
-    if (!clip_plus.available && *rp == '+')
+    if ((!clip_star.available && *rp == '*') ||
+           (!clip_plus.available && *rp == '+'))
+    {
+       msg_warn_missing_clipboard();
        *rp = 0;
+    }
 }
 
 #endif // FEAT_CLIPBOARD
index 03c7072a719e4d4bd19096755b30d3a6653ff301..576d92268e8709f1efd7b26183f508ff221b596d 100644 (file)
@@ -55,6 +55,9 @@ static int msg_hist_len = 0;
 static FILE *verbose_fd = NULL;
 static int  verbose_did_open = FALSE;
 
+static int  did_warn_clipboard = FALSE;
+static char *warn_clipboard = "W23: Clipboard register not available, using register 0";
+
 /*
  * When writing messages to the screen, there are many different situations.
  * A number of variables is used to remember the current state:
@@ -4060,6 +4063,19 @@ msg_advance(int col)
            msg_putchar(' ');
 }
 
+/*
+ * Warn about missing Clipboard Support
+ */
+    void
+msg_warn_missing_clipboard(void)
+{
+    if (!global_busy && !did_warn_clipboard)
+    {
+       msg(_(warn_clipboard));
+       did_warn_clipboard = TRUE;
+    }
+}
+
 #if defined(FEAT_CON_DIALOG) || defined(PROTO)
 /*
  * Used for "confirm()" function, and the :confirm command prefix.
index 6657a08ec3b7a59ff2a63f129e17a43da55f157c..54a0a7765141338a079839c7f119975d0f759660 100644 (file)
@@ -73,6 +73,7 @@ void give_warning(char_u *message, int hl);
 void give_warning_with_source(char_u *message, int hl, int with_source);
 void give_warning2(char_u *message, char_u *a1, int hl);
 void msg_advance(int col);
+void msg_warn_missing_clipboard(void);
 int do_dialog(int type, char_u *title, char_u *message, char_u *buttons, int dfltbutton, char_u *textfield, int ex_cmd);
 int vim_dialog_yesno(int type, char_u *title, char_u *message, int dflt);
 int vim_dialog_yesnocancel(int type, char_u *title, char_u *message, int dflt);
index 279c2140a6658f0e5637eb4593faf3ac3ad546a6..c9bc7522407d4597ce7fecdc0fb7a4e1a7b6a76c 100644 (file)
@@ -198,6 +198,13 @@ valid_yank_reg(
 #endif
                                                        )
        return TRUE;
+    // clipboard support not enabled in this build
+    else if (regname == '*' || regname == '+')
+    {
+       // Warn about missing clipboard support once
+       msg_warn_missing_clipboard();
+       return FALSE;
+    }
     return FALSE;
 }
 
@@ -1173,10 +1180,12 @@ op_yank(oparg_T *oap, int deleting, int mess)
        return OK;
 
 #ifdef FEAT_CLIPBOARD
-    if (!clip_star.available && oap->regname == '*')
-       oap->regname = 0;
-    else if (!clip_plus.available && oap->regname == '+')
+    if ((!clip_star.available && oap->regname == '*') ||
+       (!clip_plus.available && oap->regname == '+'))
+    {
        oap->regname = 0;
+       msg_warn_missing_clipboard();
+    }
 #endif
 
     if (!deleting)                 // op_delete() already set y_current
index b2261d4d6c16af3d007c1c0c02152b57163ed2c2..f2d38d8391cd112f8ab367a53d65172768644ab6 100644 (file)
@@ -1045,4 +1045,16 @@ func Test_insert_small_delete_replace_mode()
   bwipe!
 endfunc
 
+" Test for W23 when clipboard is not available
+func Test_clipboard_regs_not_working()
+  CheckNotGui
+  if !has("clipboard")
+    new
+    call append(0, "text for clipboard test")
+    let mess = execute(':norm "*yiw')
+    call assert_match('W23', mess)
+    bw!
+  endif
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 665b30b0f6947422a3cd6ba3b8971eafbda140fd..ceb17ac42f0133b3faee4558f3941044f0eb6fe2 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    852,
 /**/
     851,
 /**/