branch: externals/hyperbole
commit a59461a41465c7db62af19d1d275e7602e7a7ba6
Merge: f8870db3c0 a8a9532015
Author: Robert Weiner <r...@gnu.org>
Commit: GitHub <nore...@github.com>

    Merge pull request #704 from rswgnu/rsw
    
    Fix hywiki-word-at' and hypb:in-string-p' issues
---
 ChangeLog            | 17 +++++++++++++++--
 hypb.el              | 26 +++++++++++++-------------
 hywiki.el            | 35 ++++++++++++++++++-----------------
 test/hywiki-tests.el |  3 +--
 4 files changed, 47 insertions(+), 34 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ef1624a64a..3603898373 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2025-04-18  Bob Weiner  <r...@gnu.org>
+
+* hywiki.el (hywiki-word-at): Remove unneeded clause that checks for opening
+    delimiters a second time within a delimited set of WikiWords.  This fixes
+    an error of returning the prior WikiWord within a delimited group due to
+    moving back past leading whitespace.
+
+* hypb.el (hypb:in-string-p): Fix by removing `syntax-ppss' calls and using
+    regexp searches for double quoted delimiters instead.
+
 2025-04-17  Mats Lidell  <ma...@gnu.org>
 
 * test/hywiki-tests.el
@@ -6,11 +16,14 @@
     failure flag.
 
 * man/im/*.eps: Remove embedded postscript files.
-
 * HY-TALK/improve-performance.png: Not used.
-
 * man/im/wgrid4x3.png: Not used.
 
+2025-04-15  Bob Weiner  <r...@gnu.org>
+
+* hypb.el (hypb:in-string-p): Add optional 'max-lines' arg to limit the
+   search to that many full buffer lines starting with the line beginning
+
 2025-04-15  Mats Lidell  <ma...@gnu.org>
 
 * test/hywiki-tests.el (hywiki-tests--command)
diff --git a/hypb.el b/hypb.el
index 1ca259e9d6..80aab6ae5d 100644
--- a/hypb.el
+++ b/hypb.el
@@ -3,7 +3,7 @@
 ;; Author:       Bob Weiner
 ;;
 ;; Orig-Date:     6-Oct-91 at 03:42:38
-;; Last-Mod:     12-Apr-25 at 16:58:59 by Bob Weiner
+;; Last-Mod:     18-Apr-25 at 21:38:23 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -663,18 +663,18 @@ This will this install the Emacs helm package when 
needed."
               (error "(hypb:hkey-help-file): Non-existent file: \"%s\""
                      help-file))))))
 
-(defun hypb:in-string-p ()
-  "Return non-nil iff point is in the first line of a double quoted string."
-  (if (derived-mode-p 'change-log-mode)
-      ;; limited to single line strings; count must be odd to be
-      ;; inside a string
-      (when (cl-oddp (count-matches "\"" (line-beginning-position) (point)))
-       (save-excursion (search-backward "\"" (line-beginning-position) t)))
-    (syntax-ppss-flush-cache (line-beginning-position))
-    (let ((sexp-state-list (syntax-ppss)))
-      (when (eq ?\" (nth 3 sexp-state-list))   ; in a double quoted string
-       ;; return start of str position (opening quote)
-       (nth 8 sexp-state-list)))))
+(defun hypb:in-string-p (&optional max-lines)
+  "Return t iff point is within a double quoted string."
+  (save-restriction
+    (when (integerp max-lines)
+      (narrow-to-region (line-beginning-position)
+                       (line-end-position max-lines)))
+    ;; Don't use `syntax-ppss' here as it fails to ignore backquoted
+    ;; double quote characters in strings and doesn't work in
+    ;; `change-log-mode' due to its syntax-table.
+    (and (cl-oddp (count-matches "\\(^\\|[^\\]\\)\"" (point-min) (point)))
+        (save-excursion (re-search-forward "\\(^\\|[^\\]\\)\"" nil t))
+        t)))
 
 (defun hypb:indirect-function (obj)
   "Return the function at the end of OBJ's function chain.
diff --git a/hywiki.el b/hywiki.el
index 379c5006d7..19236728ee 100644
--- a/hywiki.el
+++ b/hywiki.el
@@ -3,7 +3,7 @@
 ;; Author:       Bob Weiner
 ;;
 ;; Orig-Date:    21-Acpr-24 at 22:41:13
-;; Last-Mod:     14-Apr-25 at 15:54:03 by Mats Lidell
+;; Last-Mod:     18-Apr-25 at 21:59:30 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -3045,22 +3045,23 @@ or this will return nil."
                             ;; Move to start of wikiword reference
                             (skip-chars-backward "-_*#:[:alnum:]" bol)
                             (skip-syntax-backward "-" bol))
-                          (when (and (or (bolp)
-                                         (string-match (regexp-quote
-                                                        (char-to-string 
(char-before)))
-                                                       "\[\(\{\<\""))
-                                     (progn
-                                       (skip-chars-forward " \t")
-                                       (hywiki-maybe-at-wikiword-beginning))
-                                     (looking-at (concat
-                                                  hywiki-word-regexp
-                                                  
"\\(#[^][#()<>{}\"\n\r\f]+\\)?"
-                                                  
hywiki-word-line-and-column-numbers-regexp "?"))
-                                     ;; Can't be followed by a # character
-                                     (/= (or (char-after (match-end 0)) 0)
-                                         ?#)
-                                     (progn (goto-char (match-end 0))
-                                            (skip-syntax-forward "-")))
+                          (when (and
+                                 ;; (or (bolp)
+                                 ;;     (string-match (regexp-quote
+                                 ;;                 (char-to-string 
(char-before)))
+                                 ;;                "\[\(\{\<\""))
+                                 (progn
+                                   (skip-chars-forward " \t")
+                                   (hywiki-maybe-at-wikiword-beginning))
+                                 (looking-at (concat
+                                              hywiki-word-regexp
+                                              "\\(#[^][#()<>{}\"\n\r\f]+\\)?"
+                                              
hywiki-word-line-and-column-numbers-regexp "?"))
+                                 ;; Can't be followed by a # character
+                                 (/= (or (char-after (match-end 0)) 0)
+                                     ?#)
+                                 (progn (goto-char (match-end 0))
+                                        (skip-syntax-forward "-")))
                             (setq start (match-beginning 0)
                                   end   (match-end 0)
                                   ;; No following char
diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el
index c38bc74f47..4efdaafb8f 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:     12-Apr-25 at 17:00:40 by Bob Weiner
+;; Last-Mod:     18-Apr-25 at 22:22:11 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -1443,7 +1443,6 @@ Insert test in the middle of other text."
 
 (ert-deftest hywiki-tests--wikiword-identified-in-strings-in-emacs-lisp-mode ()
   "Verify WikiWord is identified when in strings in `emacs-lisp-mode'."
-  (skip-unless hy-test-run-failing-flag)
   (hywiki-tests--preserve-hywiki-mode
     (unwind-protect
         (let ((words '("Foo" "Bar" "Baz" "Qux")))

Reply via email to