patch 9.1.0852: No warning when X11 registers are not available

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>
diff --git a/src/clipboard.c b/src/clipboard.c
index 6c8b60c..75e0f4f 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -2220,10 +2220,12 @@
 	    *rp = ((clip_unnamed_saved & CLIP_UNNAMED_PLUS)
 					   && clip_plus.available) ? '+' : '*';
     }
-    if (!clip_star.available && *rp == '*')
+    if ((!clip_star.available && *rp == '*') ||
+           (!clip_plus.available && *rp == '+'))
+    {
+	msg_warn_missing_clipboard();
 	*rp = 0;
-    if (!clip_plus.available && *rp == '+')
-	*rp = 0;
+    }
 }
 
 #endif // FEAT_CLIPBOARD
diff --git a/src/message.c b/src/message.c
index 03c7072..576d922 100644
--- a/src/message.c
+++ b/src/message.c
@@ -55,6 +55,9 @@
 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_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.
diff --git a/src/proto/message.pro b/src/proto/message.pro
index 6657a08..54a0a77 100644
--- a/src/proto/message.pro
+++ b/src/proto/message.pro
@@ -73,6 +73,7 @@
 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);
diff --git a/src/register.c b/src/register.c
index 279c214..c9bc752 100644
--- a/src/register.c
+++ b/src/register.c
@@ -198,6 +198,13 @@
 #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 @@
 	return OK;
 
 #ifdef FEAT_CLIPBOARD
-    if (!clip_star.available && oap->regname == '*')
+    if ((!clip_star.available && oap->regname == '*') ||
+	(!clip_plus.available && oap->regname == '+'))
+    {
 	oap->regname = 0;
-    else if (!clip_plus.available && oap->regname == '+')
-	oap->regname = 0;
+	msg_warn_missing_clipboard();
+    }
 #endif
 
     if (!deleting)		    // op_delete() already set y_current
diff --git a/src/testdir/test_registers.vim b/src/testdir/test_registers.vim
index b2261d4..f2d38d8 100644
--- a/src/testdir/test_registers.vim
+++ b/src/testdir/test_registers.vim
@@ -1045,4 +1045,16 @@
   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
diff --git a/src/version.c b/src/version.c
index 665b30b..ceb17ac 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    852,
+/**/
     851,
 /**/
     850,