unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Stefan Monnier <monnier@iro.umontreal.ca>,
	Noam Postavsky <npostavs@gmail.com>
Cc: "Mattias Engdegård" <mattiase@acm.org>,
	"Emacs developers" <emacs-devel@gnu.org>
Subject: Re: Regexp error scan (March 26)
Date: Wed, 27 Mar 2019 11:50:29 -0700	[thread overview]
Message-ID: <e74157b5-b2cc-1af5-31ee-f0e84dbb8d86@cs.ucla.edu> (raw)
In-Reply-To: <jwvpnqc1fpq.fsf-monnier+emacs@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 586 bytes --]

On 3/27/19 8:48 AM, Stefan Monnier wrote:
>> Or use string-to-list?
> That would be too obvious.

Thanks to everybody who helped improve that code with "obvious" changes
that weren't obvious to me. I installed the attached patches to try to
incorporate all the comments. I'm not sure what to do about
footnote.el's blithe overuse of "+" and "*" so I merely left a FIXME
comment for that, stealing its wording from Mattias's email.

I avoided regexp-opt before because its doc string implied that
(regexp-opt '("a" "a")) was invalid. The first patch attempts to fix
that confusion too.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Use-regexp-opt-charset-to-improve-regexp-tweaks.patch --]
[-- Type: text/x-patch; name="0001-Use-regexp-opt-charset-to-improve-regexp-tweaks.patch", Size: 3653 bytes --]

From 92acab73e0dd3921b53eac4f3fba327b7aa4d3aa Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 27 Mar 2019 11:36:13 -0700
Subject: [PATCH] Use regexp-opt-charset to improve regexp tweaks

* lisp/emacs-lisp/regexp-opt.el (regexp-opt):
Reword confusing sentence in doc string.
* lisp/erc/erc.el (erc-lurker-maybe-trim):
* lisp/mail/footnote.el (footnote-hebrew-numeric-regex):
Improve by using regexp-opt-charset.
---
 lisp/emacs-lisp/regexp-opt.el |  6 +++---
 lisp/erc/erc.el               |  4 +---
 lisp/mail/footnote.el         | 12 ++++++++----
 3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/lisp/emacs-lisp/regexp-opt.el b/lisp/emacs-lisp/regexp-opt.el
index fce6a47d98..d883752d71 100644
--- a/lisp/emacs-lisp/regexp-opt.el
+++ b/lisp/emacs-lisp/regexp-opt.el
@@ -86,9 +86,9 @@
 ;;;###autoload
 (defun regexp-opt (strings &optional paren keep-order)
   "Return a regexp to match a string in the list STRINGS.
-Each string should be unique in STRINGS and should not contain
-any regexps, quoted or not.  Optional PAREN specifies how the
-returned regexp is surrounded by grouping constructs.
+Each member of STRINGS is treated as a fixed string, not as a regexp.
+Optional PAREN specifies how the returned regexp is surrounded by
+grouping constructs.
 
 If STRINGS is the empty list, the return value is a regexp that
 never matches anything.
diff --git a/lisp/erc/erc.el b/lisp/erc/erc.el
index e34487de27..d1fa5c7f12 100644
--- a/lisp/erc/erc.el
+++ b/lisp/erc/erc.el
@@ -67,7 +67,6 @@
 (load "erc-loaddefs" nil t)
 
 (eval-when-compile (require 'cl-lib))
-(require 'cl-seq)
 (require 'font-lock)
 (require 'pp)
 (require 'thingatpt)
@@ -2523,8 +2522,7 @@ erc-lurker-maybe-trim
 non-nil."
   (if erc-lurker-trim-nicks
       (replace-regexp-in-string
-       (regexp-opt (cl-delete-duplicates
-		    (mapcar #'char-to-string erc-lurker-ignore-chars)))
+       (regexp-opt-charset (string-to-list erc-lurker-ignore-chars))
        "" nick)
     nick))
 
diff --git a/lisp/mail/footnote.el b/lisp/mail/footnote.el
index 7f88e30120..81dc11de76 100644
--- a/lisp/mail/footnote.el
+++ b/lisp/mail/footnote.el
@@ -64,7 +64,6 @@
 ;;; Code:
 
 (eval-when-compile (require 'cl-lib))
-(require 'cl-seq)
 (defvar filladapt-token-table)
 
 (defgroup footnote nil
@@ -364,9 +363,9 @@ footnote-hebrew-numeric
     ("ק" "ר" "ש" "ת" "תק" "תר" "תש" "תת" "תתק")))
 
 (defconst footnote-hebrew-numeric-regex
-  (concat "[" (cl-delete-duplicates
-	       (apply #'concat (apply #'append footnote-hebrew-numeric)))
-	  "']+"))
+  (let ((numchars (string-to-list
+		   (apply #'concat (apply #'append footnote-hebrew-numeric)))))
+    (concat (regexp-opt-charset (cons ?' numchars)) "+")))
 ;; (defconst footnote-hebrew-numeric-regex "\\([אבגדהוזחט]'\\)?\\(ת\\)?\\(ת\\)?\\([קרשת]\\)?\\([טיכלמנסעפצ]\\)?\\([אבגדהוזחט]\\)?")
 
 (defun footnote--hebrew-numeric (n)
@@ -464,6 +463,11 @@ footnote--current-regexp
 			   (nth 0 footnote-style-alist)))))
     (concat
      ;; Hack to avoid repetition of repetition.
+     ;; FIXME: I'm not sure the added * makes sense at all; there is
+     ;; always a single number within the footnote-{start,end}-tag pairs.
+     ;; Worse, the code goes on and adds yet another + later on, in
+     ;; footnote-refresh-footnotes, just in case. That makes even less sense.
+     ;; Likely, both the * and the extra + should go away.
      (if (string-match "[^\\]\\\\\\{2\\}*[*+?]\\'" regexp)
 	 (substring regexp 0 -1)
        regexp)
-- 
2.20.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0001-Tune-css-mode-regexp.patch --]
[-- Type: text/x-patch; name="0001-Tune-css-mode-regexp.patch", Size: 1288 bytes --]

From df167575d1ac2d056c8a2ef1fc83d768c09a3d28 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Wed, 27 Mar 2019 11:43:18 -0700
Subject: [PATCH] Tune css-mode regexp
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/textmodes/css-mode.el (css--font-lock-keywords):
Omit unnecessary \(?: \) in regexp.  Suggested by Mattias Engdegård in:
https://lists.gnu.org/r/emacs-devel/2019-03/msg01042.html
---
 lisp/textmodes/css-mode.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/textmodes/css-mode.el b/lisp/textmodes/css-mode.el
index d3ca2d9558..11a77b5bb7 100644
--- a/lisp/textmodes/css-mode.el
+++ b/lisp/textmodes/css-mode.el
@@ -892,7 +892,7 @@ css--font-lock-keywords
     (,(concat "@" css-ident-re) (0 font-lock-builtin-face))
     ;; Selectors.
     ;; Allow plain ":root" as a selector.
-    ("^[ \t]*\\(:root\\)\\(?:[\n \t]*\\){" (1 'css-selector keep))
+    ("^[ \t]*\\(:root\\)[\n \t]*{" (1 'css-selector keep))
     ;; FIXME: attribute selectors don't work well because they may contain
     ;; strings which have already been highlighted as f-l-string-face and
     ;; thus prevent this highlighting from being applied (actually now that
-- 
2.20.1


  reply	other threads:[~2019-03-27 18:50 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-26 17:38 Regexp error scan (March 26) Mattias Engdegård
2019-03-27  2:10 ` Paul Eggert
2019-03-27  3:43   ` Basil L. Contovounesios
2019-03-27  9:14     ` Mattias Engdegård
2019-03-27 13:55       ` Andy Moreton
2019-03-27 14:36         ` Stefan Monnier
2019-03-27 14:41           ` Mattias Engdegård
2019-03-27 14:45             ` Stefan Monnier
2019-03-27 14:49               ` Noam Postavsky
2019-03-27 15:45                 ` Mattias Engdegård
2019-03-27 15:48                 ` Stefan Monnier
2019-03-27 18:50                   ` Paul Eggert [this message]
2019-03-27 15:28             ` Damien Collard
2019-03-27 12:09   ` Mattias Engdegård

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e74157b5-b2cc-1af5-31ee-f0e84dbb8d86@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=emacs-devel@gnu.org \
    --cc=mattiase@acm.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=npostavs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).