branch: externals/hyperbole
commit 9f4c5c007b2082c397837d57d3d400326b3c80da
Author: bw <r...@gnu.org>
Commit: bw <r...@gnu.org>

    hywiki.el - Fix 2 highlighting bugs
---
 ChangeLog            | 14 ++++++++++++++
 hywiki.el            | 24 ++++++++++++++----------
 test/hywiki-tests.el |  6 +++++-
 3 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1715945e27..dd6065bead 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2025-08-20  Bob Weiner  <r...@gnu.org>
+
+* test/hywiki-tests.el (hywiki-tests--edit-string-pairs): Add a few more
+    tests based on cases fixed with recent updates.
+
+2025-08-19  Bob Weiner  <r...@gnu.org>
+
+* hywiki.el (hywiki-delimited-p): Fix bug where = was used on a call to
+    'matching-paren' which can return nil.  Change to eq instead.
+            (hywiki--maybe-de/highlight-sexp): Fix to add 1 to region start
+    only when verify that the char after start is an opening delimiter.  This
+    fixes the bug where a substring wikiword is highlighted, e.g. if 'AI' is
+    the wikiword, it is highlighted within 'FAI'.
+
 2025-08-19  Mats Lidell  <ma...@gnu.org>
 
 * test/hmouse-drv-tests.el (hmouse-drv--hkey-actions): Adopted test case
diff --git a/hywiki.el b/hywiki.el
index 80cbf273ad..4ee3fb84ca 100644
--- a/hywiki.el
+++ b/hywiki.el
@@ -3,7 +3,7 @@
 ;; Author:       Bob Weiner
 ;;
 ;; Orig-Date:    21-Apr-24 at 22:41:13
-;; Last-Mod:     17-Aug-25 at 22:55:10 by Bob Weiner
+;; Last-Mod:     20-Aug-25 at 00:27:54 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -2566,7 +2566,7 @@ regexps of wikiwords, if the hash table is out-of-date."
                      (setq wikiword-sublist
                            (delq nil (nconc wikiword-sublist
                                             (mapcar 
#'hywiki-get-plural-wikiword wikiword-sublist))))
-                     (concat (regexp-opt wikiword-sublist 'words)
+                     (concat "\\b" (regexp-opt wikiword-sublist t) "\\b"
                              "\\(" hywiki-word-section-regexp "??" 
hywiki-word-line-and-column-numbers-regexp "?" "\\)"
                              hywiki--buttonize-character-regexp))
                    (hypb:split-seq-into-sublists
@@ -3289,7 +3289,8 @@ non-nil or this will return nil."
                     ;; If `wikiword' reference has a #section, ensure there are
                     ;; no invalid chars.  One set of \n\r characters is 
allowed.
                     (if (and (stringp wikiword) (string-match "#" wikiword))
-                        (string-match "#[^][#()<>{}\"\f]+\\'" wikiword)        
               t))
+                        (string-match "#[^][#()<>{}\"\f]+\\'" wikiword)
+                      t))
                (if range-flag
                    (progn
                      (list wikiword start end))
@@ -3374,8 +3375,8 @@ a HyWikiWord at point."
          (let ((range (hargs:delimited "[\[<\(\{]" "[\]\}\)\>]" t t t)))
            (and range
                 ;; Ensure closing delimiter is a match for the opening one
-                (= (matching-paren (char-before (nth 1 range)))
-                   (char-after (nth 2 range)))
+                (eq (matching-paren (char-before (nth 1 range)))
+                    (char-after (nth 2 range)))
                 range))))))
 
 (defun hywiki-word-face-at-p (&optional pos)
@@ -3688,12 +3689,15 @@ DIRECTION-NUMBER is 1 for forward scanning and -1 for 
backward scanning."
        ;; Point may be at end of sexp, so start and end may
        ;; need to be reversed.
        (list (min sexp-start sexp-end) (max sexp-start sexp-end))
-      ;; Increment sexp-start so regexp matching excludes the
-      ;; delimiter and starts with the HyWikiWord.  But include any
-      ;; trailing delimiter or regexp matching will not work.
+      ;; When `start' is at a delimiter, increment `sexp-start' so
+      ;; regexp matching excludes the delimiter and starts with the
+      ;; HyWikiWord.  But include any trailing delimiter or regexp
+      ;; matching will not work.
       (save-restriction
-       (narrow-to-region (1+ start) end)
-       (prog1 (funcall func (1+ start) end)
+       (when (memq (char-after start) '(?( ?) ?< ?> ?{ ?} ?[ ?] ?\"))
+         (setq start (1+ start)))
+       (narrow-to-region start end)
+       (prog1 (funcall func start end)
          (setq hywiki--highlighting-done-flag nil))))))
 
 (defun hywiki--maybe-dehighlight-at-point ()
diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el
index be0cf6b96d..e27043b5ed 100644
--- a/test/hywiki-tests.el
+++ b/test/hywiki-tests.el
@@ -3,7 +3,7 @@
 ;; Author:       Mats Lidell
 ;;
 ;; Orig-Date:    18-May-24 at 23:59:48
-;; Last-Mod:     19-Aug-25 at 00:15:34 by Mats Lidell
+;; Last-Mod:     20-Aug-25 at 00:01:57 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -29,6 +29,10 @@
 (defconst hywiki-tests--edit-string-pairs
    [
     ("HiHo#s<insert-char ? >" "{HiHo#s} ")
+    ("FAI AI" "FAI {AI}")
+    ("\"WikiWord#a b c\"<backward-delete-char 1>" "\"{WikiWord#a} b c")
+    ("(Non#s n)<backward-delete-char 1>" "({Non#s} n")
+    ("(MyWikiWord)WikiWord" "({MyWikiWord}){WikiWord}")
     ("Hi#a<insert-char ?b> cd" "{Hi#ab} cd")
     ("Hi" "{Hi}")
     ("HyWikiWord" "{HyWikiWord}")

Reply via email to