]> code.delx.au - gnu-emacs/commitdiff
Make [:graph:] act like [:print:] sans space
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 15 Apr 2015 07:26:32 +0000 (00:26 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 15 Apr 2015 07:27:18 +0000 (00:27 -0700)
In POSIX [[:print:]] is equivalent to [ [:graph:]], so change
[:graph:] so that it matches everything that [:print:] does,
except for space.
* doc/lispref/searching.texi (Char Classes):
* etc/NEWS:
* lisp/emacs-lisp/rx.el (rx):
Document [:graph:] to be [:print:] sans ' '.
* src/character.c, src/character.h (graphicp): New function.
* src/regex.c (ISGRAPH) [emacs]: Use it.
(BIT_GRAPH): New macro.
(BIT_PRINT): Increase to 0x200, to make room for BIT_GRAPH.
(re_wctype_to_bit) [! WIDE_CHAR_SUPPORT]:
Return BIT_GRAPH for RECC_GRAPH.
(re_match_2_internal) [emacs]: Use ISGRAPH if BIT_GRAPH,
and ISPRINT if BIT_PRINT.

doc/lispref/searching.texi
etc/NEWS
lisp/emacs-lisp/rx.el
src/character.c
src/character.h
src/regex.c

index 238d814a9dcccb7797993daa8ec9216e0ff8f8e9..10ea411d4369b7f6a8ffd15e52da0cc4ac2c3bc2 100644 (file)
@@ -558,8 +558,11 @@ This matches any @acronym{ASCII} control character.
 This matches @samp{0} through @samp{9}.  Thus, @samp{[-+[:digit:]]}
 matches any digit, as well as @samp{+} and @samp{-}.
 @item [:graph:]
-This matches graphic characters---everything except @acronym{ASCII} control
-characters, space, and the delete character.
+This matches graphic characters---everything except space,
+@acronym{ASCII} and non-@acronym{ASCII} control characters,
+surrogates, and codepoints unassigned by Unicode, as indicated by the
+Unicode @samp{general-category} property (@pxref{Character
+Properties}).
 @item [:lower:]
 This matches any lower-case letter, as determined by the current case
 table (@pxref{Case Tables}).  If @code{case-fold-search} is
@@ -569,11 +572,8 @@ This matches any multibyte character (@pxref{Text Representations}).
 @item [:nonascii:]
 This matches any non-@acronym{ASCII} character.
 @item [:print:]
-This matches printing characters---everything except @acronym{ASCII}
-and non-@acronym{ASCII} control characters (including the delete
-character), surrogates, and codepoints unassigned by Unicode, as
-indicated by the Unicode @samp{general-category} property
-(@pxref{Character Properties}).
+This matches any printing character---either space, or a graphic
+character matched by @samp{[:graph:]}.
 @item [:punct:]
 This matches any punctuation character.  (At present, for multibyte
 characters, it matches anything that has non-word syntax.)
index 907787a1f3e43602fabf5feadaf47890dafcb800..d97e80a7171f1a6ae24079245e3627475d0b5ed9 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -629,12 +629,12 @@ notifications, if Emacs is compiled with file notification support.
 *** gulp.el
 
 +++
-** The character class [:print:] in regular expressions
-no longer matches any multibyte character.  Instead, Emacs now
+** The character classes [:graph:] and [:print:] in regular expressions
+no longer match every multibyte character.  Instead, Emacs now
 consults the Unicode character properties to determine which
-characters are printable.  In particular, surrogates and unassigned
-codepoints are now rejected by this class.  If you want the old
-behavior, use [:multibyte:] instead.
+characters are graphic or printable.  In particular, surrogates and
+unassigned codepoints are now rejected.  If you want the old behavior,
+use [:multibyte:] instead.
 
 \f
 * New Modes and Packages in Emacs 25.1
index a5a228e58765464608cd92028aeb943be4ec3ef2..ab9beb6092894ebf66a3959dbb7a4650583bc183 100644 (file)
@@ -965,12 +965,12 @@ CHAR
      matches space and tab only.
 
 `graphic', `graph'
-     matches graphic characters--everything except ASCII control chars,
-     space, and DEL.
+     matches graphic characters--everything except space, ASCII
+     and non-ASCII control characters, surrogates, and codepoints
+     unassigned by Unicode.
 
 `printing', `print'
-     matches printing characters--everything except ASCII and non-ASCII
-     control characters, surrogates, and codepoints unassigned by Unicode.
+     matches space and graphic characters.
 
 `alphanumeric', `alnum'
      matches alphabetic characters and digits.  (For multibyte characters,
index b357dd5a334d1a63a860396680d73b191b350b61..ea98cf68e6cfca7e1217f831ae57a69c0e2872da 100644 (file)
@@ -1022,6 +1022,14 @@ decimalnump (int c)
   return gen_cat == UNICODE_CATEGORY_Nd;
 }
 
+/* Return 'true' if C is a graphic character as defined by its
+   Unicode properties.  */
+bool
+graphicp (int c)
+{
+  return c == ' ' || printablep (c);
+}
+
 /* Return 'true' if C is a printable character as defined by its
    Unicode properties.  */
 bool
index 1a5d2c8a670c512508975da953b3089749c6bb00..859d717a0bac2c42ff133d1fd4b45e61b36527f1 100644 (file)
@@ -662,6 +662,7 @@ extern Lisp_Object string_escape_byte8 (Lisp_Object);
 
 extern bool alphabeticp (int);
 extern bool decimalnump (int);
+extern bool graphicp (int);
 extern bool printablep (int);
 
 /* Return a translation table of id number ID.  */
index b9d09d02c22cf111b256ed1c998d9dc3a630c289..4af70c62cf5dca8b5584d44b94c7ada034ee0ec1 100644 (file)
@@ -314,7 +314,7 @@ enum syntaxcode { Swhitespace = 0, Sword = 1, Ssymbol = 2 };
 
 # define ISGRAPH(c) (SINGLE_BYTE_CHAR_P (c)                            \
                    ? (c) > ' ' && !((c) >= 0177 && (c) <= 0237)        \
-                   : 1)
+                    : graphicp (c))
 
 # define ISPRINT(c) (SINGLE_BYTE_CHAR_P (c)                            \
                    ? (c) >= ' ' && !((c) >= 0177 && (c) <= 0237)       \
@@ -1875,7 +1875,8 @@ struct range_table_work_area
 #define BIT_MULTIBYTE  0x20
 #define BIT_ALPHA      0x40
 #define BIT_ALNUM      0x80
-#define BIT_PRINT      0x100
+#define BIT_GRAPH      0x100
+#define BIT_PRINT      0x200
 \f
 
 /* Set the bit for character C in a list.  */
@@ -2074,7 +2075,7 @@ re_wctype_to_bit (re_wctype_t cc)
 {
   switch (cc)
     {
-    case RECC_NONASCII: case RECC_GRAPH:
+    case RECC_NONASCII:
     case RECC_MULTIBYTE: return BIT_MULTIBYTE;
     case RECC_ALPHA: return BIT_ALPHA;
     case RECC_ALNUM: return BIT_ALNUM;
@@ -2083,6 +2084,7 @@ re_wctype_to_bit (re_wctype_t cc)
     case RECC_UPPER: return BIT_UPPER;
     case RECC_PUNCT: return BIT_PUNCT;
     case RECC_SPACE: return BIT_SPACE;
+    case RECC_GRAPH: return BIT_GRAPH;
     case RECC_PRINT: return BIT_PRINT;
     case RECC_ASCII: case RECC_DIGIT: case RECC_XDIGIT: case RECC_CNTRL:
     case RECC_BLANK: case RECC_UNIBYTE: case RECC_ERROR: return 0;
@@ -5522,7 +5524,9 @@ re_match_2_internal (struct re_pattern_buffer *bufp, const_re_char *string1,
                    | (class_bits & BIT_UPPER && ISUPPER (c))
                    | (class_bits & BIT_WORD  && ISWORD  (c))
                    | (class_bits & BIT_ALPHA && ISALPHA (c))
-                   | (class_bits & BIT_ALNUM && ISALNUM (c)))
+                   | (class_bits & BIT_ALNUM && ISALNUM (c))
+                   | (class_bits & BIT_GRAPH && ISGRAPH (c))
+                   | (class_bits & BIT_PRINT && ISPRINT (c)))
                  not = !not;
                else
                  CHARSET_LOOKUP_RANGE_TABLE_RAW (not, c, range_table, count);