]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
new "enable-active-region" readline variable
authorChet Ramey <chet.ramey@case.edu>
Fri, 30 Apr 2021 20:56:05 +0000 (16:56 -0400)
committerChet Ramey <chet.ramey@case.edu>
Fri, 30 Apr 2021 20:56:05 +0000 (16:56 -0400)
CWRU/CWRU.chlog
arrayfunc.c
builtins/common.c
command.h
doc/bash.1
lib/readline/bind.c
lib/readline/doc/readline.3
lib/readline/doc/rluser.texi
lib/readline/doc/version.texi
make_cmd.c
subst.c

index bbfbd5e8633418e5cd16bad6fac4e4220d99f66d..986036c21d46c8a3de409b17344403863b92437a 100644 (file)
@@ -10108,3 +10108,24 @@ bashline.c
          pattern, make sure to set rl_filename_completion_desired, so we get
          quoting and appending -- we are completing a filename, after all.
          From a report from Manuel Boni <ziosombrero@gmail.com>
+
+lib/readline/bind.c
+       - enable-active-region: separate control of the active region and
+         bracketed paste. Still set to the same default value as bracketed
+         paste, and enabling bracketed paste enables the active region.
+         Now you can enable bracketed paste and then turn off the active
+         region.
+
+doc/bash.1,lib/readline/doc/{readline.3,rltech.texi}
+       - enable-active-region: document new bindable readline variable and
+         its effects
+
+                                  4/30
+                                  ----
+command.h
+       - W_ARRAYREF: new flag, meaning the word is a valid array reference
+         with subscript, replaces W_DOLLARSTAR, which was unused
+
+subst.c        
+       - expand_subscript_string,expand_array_subscript: new functions to
+         parse and expand-and-quote array subscripts. For future use
index f57d7837dab8d3c076bb74dda0b72676091594e0..468935a6000f4da1dc908bf629bb75a52b21e7d5 100644 (file)
@@ -344,7 +344,7 @@ assign_array_element (name, value, flags)
      (ASS_ALLOWALLSUB) we allow it. */
   if (((isassoc == 0 || (flags & (ASS_NOEXPAND|ASS_ALLOWALLSUB)) == 0) &&
        (ALL_ELEMENT_SUB (sub[0]) && sub[1] == ']')) ||
-       (sublen <= 1))
+      (sublen <= 1))
     {
       free (vname);
       err_badarraysub (name);
index 9459900e453c4480d3db8c714823b9c25d385db1..89c94066f3dbb0382cb8274e55c3b6e1d51321e6 100644 (file)
@@ -1001,7 +1001,7 @@ builtin_bind_var_to_int (name, val)
 {
   SHELL_VAR *v;
 
-  v = bind_var_to_int (name, val, ASS_ALLOWALLSUB);    /* XXX */
+  v = bind_var_to_int (name, val, ASS_ALLOWALLSUB);
   return v;
 }
 
index 137608de7fcd0963f45b8c54891c6e479b6709a9..e0dc2f955764f7a15ea35505c32f76bf3cf72fa3 100644 (file)
--- a/command.h
+++ b/command.h
@@ -82,7 +82,7 @@ enum command_type { cm_for, cm_case, cm_while, cm_if, cm_simple, cm_select,
 #define W_NOSPLIT2     (1 << 6)        /* Don't split word except for $@ expansion (using spaces) because context does not allow it. */
 #define W_TILDEEXP     (1 << 7)        /* Tilde expand this assignment word */
 #define W_DOLLARAT     (1 << 8)        /* UNUSED - $@ and its special handling */
-#define W_DOLLARSTAR   (1 << 9)        /* UNUSED - $* and its special handling */
+#define W_ARRAYREF     (1 << 9)        /* word is a valid array reference */
 #define W_NOCOMSUB     (1 << 10)       /* Don't perform command substitution on this word */
 #define W_ASSIGNRHS    (1 << 11)       /* Word is rhs of an assignment statement */
 #define W_NOTILDE      (1 << 12)       /* Don't perform tilde expansion on this word */
index 4dd91545b5afe104183d117d79fadec23624d1b9..c5ccacd6da8565d76b80e8146e082e72a02a9182 100644 (file)
@@ -5,12 +5,12 @@
 .\"    Case Western Reserve University
 .\"    chet.ramey@case.edu
 .\"
-.\"    Last Change: Wed Mar 31 11:01:34 EDT 2021
+.\"    Last Change: Wed Apr 28 14:35:46 EDT 2021
 .\"
 .\" bash_builtins, strip all but Built-Ins section
 .if \n(zZ=1 .ig zZ
 .if \n(zY=1 .ig zY
-.TH BASH 1 "2021 March 30" "GNU Bash 5.1"
+.TH BASH 1 "2021 April 28" "GNU Bash 5.1"
 .\"
 .\" There's some problem with having a `@'
 .\" in a tagged paragraph with the BSD man macros.
@@ -5865,6 +5865,17 @@ Use the \e1 and \e2 escapes to begin and end sequences of
 non-printing characters, which can be used to embed a terminal control
 sequence into the mode string.
 .TP
+.B enable\-active\-region (On)
+The \fIpoint\fP is the current cursor position, and \fImark\fP refers  
+to a saved cursor position.   
+The text between the point and mark is referred to as the \fIregion\fP.  
+When this variable is set to \fIOn\fP, readline allows certain commands
+to designate the region as \fIactive\fP.  
+When the region is active, readline highlights the text in the region using
+the terminal's standout mode.
+The active region shows the text inserted by bracketed-paste and any
+matching text found by incremental and non-incremental history searches.
+.TP
 .B enable\-bracketed\-paste (On)
 When set to \fBOn\fP, readline will configure the terminal in a way
 that will enable it to insert each paste into the editing buffer as a
index fe73e3cb11f54816d531bfe29225e5fdd33a985f..f43baf45dd7eafe2f1a06259a9319b401fa93ed4 100644 (file)
@@ -1819,6 +1819,7 @@ static const struct {
   { "convert-meta",            &_rl_convert_meta_chars_to_ascii, 0 },
   { "disable-completion",      &rl_inhibit_completion,         0 },
   { "echo-control-characters", &_rl_echo_control_chars,        0 },
+  { "enable-active-region",    &_rl_enable_active_region,      0 },
   { "enable-bracketed-paste",  &_rl_enable_bracketed_paste,    V_SPECIAL },
   { "enable-keypad",           &_rl_enable_keypad,             0 },
   { "enable-meta-key",         &_rl_enable_meta,               0 },
index 832e69ef0081d4af302994d2f079a44fac01db8a..398c8a7306a7cf0071dab9363253108e828cc8e6 100644 (file)
@@ -6,9 +6,9 @@
 .\"    Case Western Reserve University
 .\"    chet.ramey@case.edu
 .\"
-.\"    Last Change: Tue Mar 24 09:27:30 EDT 2020
+.\"    Last Change: Wed Apr 28 14:31:09 EDT 2021
 .\"
-.TH READLINE 3 "2020 October 29" "GNU Readline 8.1"
+.TH READLINE 3 "2021 April 28" "GNU Readline 8.1"
 .\"
 .\" File Name macro.  This used to be `.PN', for Path Name,
 .\" but Sun doesn't seem to like that very much.
@@ -447,6 +447,17 @@ Use the \e1 and \e2 escapes to begin and end sequences of
 non-printing characters, which can be used to embed a terminal control 
 sequence into the mode string.
 .TP
+.B enable\-active\-region (On)
+The \fIpoint\fP is the current cursor position, and \fImark\fP refers
+to a saved cursor position.
+The text between the point and mark is referred to as the \fIregion\fP.
+When this variable is set to \fIOn\fP, readline allows certain commands
+to designate the region as \fIactive\fP.
+When the region is active, readline highlights the text in the region using
+the terminal's standout mode.
+The active region shows the text inserted by bracketed-paste and any
+matching text found by incremental and non-incremental history searches.
+.TP
 .B enable\-bracketed\-paste (On)
 When set to \fBOn\fP, readline will configure the terminal in a way
 that will enable it to insert each paste into the editing buffer as a
index 70e751caa369d4d16f8a04226a0632f990750f3e..f4d4860d4c7e05587d203be7f13415da187153ee 100644 (file)
@@ -540,6 +540,19 @@ non-printing characters, which can be used to embed a terminal control
 sequence into the mode string.
 The default is @samp{@@}.
 
+@item enable-active-region
+@vindex enable-active-region
+The @dfn{point} is the current cursor position, and @dfn{mark} refers
+to a saved cursor position (@pxref{Commands For Moving}).
+The text between the point and mark is referred to as the @dfn{region}.
+When this variable is set to @samp{On}, Readline allows certain commands
+to designate the region as @dfn{active}.
+When the region is active, Readline highlights the text in the region using
+the terminal's standout mode.
+The active region shows the text inserted by bracketed-paste and any
+matching text found by incremental and non-incremental history searches.
+The default is @samp{On}.
+
 @item enable-bracketed-paste
 @vindex enable-bracketed-paste
 When set to @samp{On}, Readline will configure the terminal in a way
index e90db4c18f271da9f8cf379f1eb1704ed4d1795e..cd0998e80d835163dcf2df7d9cd72154095df158 100644 (file)
@@ -4,7 +4,7 @@ Copyright (C) 1988-2021 Free Software Foundation, Inc.
 
 @set EDITION 8.1
 @set VERSION 8.1
-@set UPDATED 16 April 2021
+@set UPDATED 28 April 2021
 @set UPDATED-MONTH April 2021
 
-@set LASTCHANGE Fri Apr 16 14:51:06 EDT 2021
+@set LASTCHANGE Wed Apr 28 14:30:42 EDT 2021
index 38cc0892b360c9f2b0296d5cf99e6e8866a005d2..86f56042113eb2736b7d4d19acbec07dee0f00f5 100644 (file)
@@ -251,10 +251,7 @@ make_arith_for_expr (s)
   if (s == 0 || *s == '\0')
     return ((WORD_LIST *)NULL);
   wd = make_word (s);
-  wd->flags |= W_NOGLOB|W_NOSPLIT|W_QUOTED|W_NOTILDE;  /* no word splitting or globbing */
-#if defined (PROCESS_SUBSTITUTION)
-  wd->flags |= W_NOPROCSUB;    /* no process substitution */
-#endif
+  wd->flags |= W_NOGLOB|W_NOSPLIT|W_QUOTED|W_NOTILDE|W_NOPROCSUB;      /* no word splitting or globbing */
   result = make_word_list (wd, (WORD_LIST *)NULL);
   return result;
 }
diff --git a/subst.c b/subst.c
index 8fd36724e6cad0d072499886022e197ac6d5a156..8187245d73200cccd8534f1b3e170d0884c1d66a 100644 (file)
--- a/subst.c
+++ b/subst.c
@@ -458,10 +458,10 @@ dump_word_flags (flags)
       f &= ~W_NOCOMSUB;
       fprintf (stderr, "W_NOCOMSUB%s", f ? "|" : "");
     }
-  if (f & W_DOLLARSTAR)
+  if (f & W_ARRAYREF)
     {
-      f &= ~W_DOLLARSTAR;
-      fprintf (stderr, "W_DOLLARSTAR%s", f ? "|" : "");
+      f &= ~W_ARRAYREF;
+      fprintf (stderr, "W_ARRAYREF%s", f ? "|" : "");
     }
   if (f & W_DOLLARAT)
     {
@@ -3278,7 +3278,7 @@ do_assignment_internal (word, expand)
          report_error (_("%s: cannot assign list to array member"), name);
          ASSIGN_RETURN (0);
        }
-      aflags |= ASS_ALLOWALLSUB;
+      aflags |= ASS_ALLOWALLSUB;       /* allow a[@]=value for existing associative arrays */
       entry = assign_array_element (name, value, aflags);
       if (entry == 0)
        ASSIGN_RETURN (0);
@@ -10117,6 +10117,118 @@ return0:
   return ret;
 }
 
+#if defined (ARRAY_VARS)
+/* Characters that need to be backslash-quoted after expanding array subscripts */
+static char abstab[256] = { '\1' };
+
+/* Run an array subscript through the appropriate word expansions. */
+char *
+expand_subscript_string (string, quoted)
+     char *string;
+     int quoted;
+{
+  WORD_DESC td;
+  WORD_LIST *tlist;
+  int oe;
+  char *ret;
+
+  if (string == 0 || *string == 0)
+    return (char *)NULL;
+
+  oe = expand_no_split_dollar_star;
+  ret = (char *)NULL;
+
+  td.flags = W_NOPROCSUB|W_NOTILDE|W_NOSPLIT2; /* XXX - W_NOCOMSUB? */
+  td.word = string;
+
+  expand_no_split_dollar_star = 1;
+  tlist = call_expand_word_internal (&td, quoted, 0, (int *)NULL, (int *)NULL);
+  expand_no_split_dollar_star = oe;
+
+  if (tlist)
+    {
+      if (tlist->word)
+       {
+         remove_quoted_nulls (tlist->word->word);
+         tlist->word->flags &= ~W_HASQUOTEDNULL;
+       }
+      dequote_list (tlist);
+      ret = string_list (tlist);
+      dispose_words (tlist);
+    }
+
+  return (ret);
+}
+
+/* Expand the subscript in STRING, which is an array reference. To ensure we
+   only expand it once, we quote the characters that would start another
+   expansion and the bracket characters that are special to array subscripts. */
+static char *
+expand_array_subscript (string, sindex, quoted, flags)
+     char *string;
+     int *sindex;
+     int quoted, flags;
+{
+  char *ret, *exp, *t;
+  size_t slen;
+  int si, ni;
+
+  si = *sindex;
+  slen = STRLEN (string);
+
+  if (abstab[0] == '\1')
+    {
+      /* These are basically the characters that start shell expansions plus
+        the characters that delimit subscripts. */
+      memset (abstab, '\0', sizeof (abstab));
+      abstab[LBRACK] = abstab[RBRACK] = 1;
+      abstab['$'] = abstab['`'] = abstab['~'] = 1;
+      abstab['\\'] = abstab['\''] = 1;
+    }
+
+  /* string[si] == LBRACK */
+  ni = skipsubscript (string, si, 0);
+  /* These checks mirror the ones in valid_array_subscript. The check for
+     (ni - si) == 1 checks for empty subscripts. We don't check that the
+     subscript is a separate word if we're parsing an arithmetic expression. */
+  if (ni >= slen || string[ni] != RBRACK || (ni - si) == 1 ||
+      (string[ni+1] != '\0' && (quoted & Q_ARITH) == 0))
+    {
+/* let's check and see what fails this check */
+itrace("expand_array_subscript: bad subscript string: `%s'", string+si);
+      ret = (char *)xmalloc (2);       /* badly-formed subscript */
+      ret[0] = string[si];
+      ret[1] = '\0';
+      *sindex = si + 1;
+      return ret;
+    }
+
+  /* STRING[ni] == RBRACK */
+  exp = substring (string, si+1, ni);
+  t = expand_subscript_string (exp, quoted & ~(Q_ARITH|Q_DOUBLE_QUOTES));
+  free (exp);
+  /* Only quote `@' and `*' if they are the only character in the subscript */
+  if (ALL_ELEMENT_SUB (t[0]) && t[1] == '\0')
+    abstab['*'] = abstab['@'] = 1;
+  else
+    abstab['*'] = abstab['@'] = 0;
+  exp = sh_backslash_quote (t, abstab, 0);
+  free (t);
+
+  slen = STRLEN (exp);
+  ret = xmalloc (slen + 2 + 1);
+  ret[0] ='[';
+  strcpy (ret + 1, exp);
+  ret[slen + 1] = ']';
+  ret[slen + 2] = '\0';
+
+  free (exp);
+  *sindex = ni + 1;
+
+  return ret;
+}
+#endif
+
 void
 invalidate_cached_quoted_dollar_at ()
 {