unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@linkov.net>
To: 60241@debbugs.gnu.org
Subject: bug#60241: 29.0.60; Fix regexp pattern case in hi-lock
Date: Wed, 21 Dec 2022 19:29:11 +0200	[thread overview]
Message-ID: <86pmcc7jr8.fsf@mail.linkov.net> (raw)

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

Version: 29.0.60
Tags: patch

0. emacs -Q
1. Type [ M-< C-s [ M-s h r RET M-s h u

Debugger entered--Lisp error: (invalid-regexp "Unmatched [ or [^")
  hi-lock--regexps-at-point()
  command-execute(unhighlight-regexp)

Here is a patch to fix this error:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: hi-lock--regexps-at-point.patch --]
[-- Type: text/x-diff, Size: 2197 bytes --]

diff --git a/lisp/hi-lock.el b/lisp/hi-lock.el
index a45e74eca26..bc631747e6d 100644
--- a/lisp/hi-lock.el
+++ b/lisp/hi-lock.el
@@ -569,24 +569,29 @@ hi-lock--regexps-at-point
       (when (and face-before face-after (not (eq face-before face-after)))
         (setq face-before nil))
       (when (or face-after face-before)
-        (let* ((hi-text
-                (buffer-substring-no-properties
-                 (if face-before
-                     (or (previous-single-property-change (point) 'face)
-                         (point-min))
-                   (point))
-                 (if face-after
-                     (or (next-single-property-change (point) 'face)
-                         (point-max))
-                   (point)))))
+        (let* ((beg (if face-before
+                        (or (previous-single-property-change (point) 'face)
+                            (point-min))
+                      (point)))
+               (end (if face-after
+                        (or (next-single-property-change (point) 'face)
+                            (point-max))
+                      (point))))
           ;; Compute hi-lock patterns that match the
           ;; highlighted text at point.  Use this later in
           ;; during completing-read.
           (dolist (hi-lock-pattern hi-lock-interactive-patterns)
-            (let ((regexp (or (car (rassq hi-lock-pattern hi-lock-interactive-lighters))
-                              (car hi-lock-pattern))))
-              (if (string-match regexp hi-text)
-                  (push regexp regexps)))))))
+            (let ((pattern (or (rassq hi-lock-pattern hi-lock-interactive-lighters)
+                               (car hi-lock-pattern))))
+              (cond
+               ((stringp pattern)
+                (when (string-match pattern (buffer-substring-no-properties beg end))
+                  (push pattern regexps)))
+               ((functionp (cadr pattern))
+                (save-excursion
+                  (goto-char beg)
+                  (when (funcall (cadr pattern) end)
+                    (push (car pattern) regexps))))))))))
     regexps))
 
 (defvar-local hi-lock--unused-faces nil

             reply	other threads:[~2022-12-21 17:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-21 17:29 Juri Linkov [this message]
2022-12-29 17:45 ` bug#60241: 29.0.60; Fix regexp pattern case in hi-lock Juri Linkov

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=86pmcc7jr8.fsf@mail.linkov.net \
    --to=juri@linkov.net \
    --cc=60241@debbugs.gnu.org \
    /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).