branch: externals/hyperbole commit c19720056c3d469bf06021ba091eaec6330d1b75 Author: bw <r...@gnu.org> Commit: bw <r...@gnu.org>
hywiki.el - Improve hywiki-word-at and hywiki-word-is-p #sections --- ChangeLog | 10 ++++++++++ hywiki.el | 36 +++++++++++++++++++++++++++--------- test/hywiki-tests.el | 6 +++--- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index d8dc0fb98b..7d9be92838 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2025-04-05 Bob Weiner <r...@gnu.org> + +* hywiki.el (hywiki-word-at, hywiki-word-is-p): If has a #section, ensure + there are no invalid chars. + (hywiki-word-at): Fix missing test for double quote as an opening + delimiter. + +* test/hywiki-tests.el (hywiki-tests--sections-with-dash-space): Update code + to ensure #section cannot contain quote marks. + 2025-03-30 Bob Weiner <r...@gnu.org> * test/hywiki-tests.el (hywiki-tests--wikiword-step-check): Fix by removing diff --git a/hywiki.el b/hywiki.el index a31ec9819a..98dc426f79 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: 30-Mar-25 at 15:13:08 by Bob Weiner +;; Last-Mod: 5-Apr-25 at 19:00:40 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -148,6 +148,7 @@ (require 'hui-mini) ;; For `hui:menu-act' (require 'hypb) ;; Requires `seq' (require 'outline) ;; For `outline-mode-syntax-table' +(require 'seq) ;; For 'seq-contains-p' (require 'subr-x) ;; For `string-remove-prefix' (require 'thingatpt) @@ -587,6 +588,14 @@ Highlight after inserting any non-word character." t) (setq hywiki--range nil))))) + ;; For some reason this first rehighlighting is needed to ensure + ;; any wikiword before an inserted whitespace character is + ;; properly highlighted when separating two words. When run in + ;; debug mode, it is not needed. + (save-excursion + (goto-char (max (1- (point)) (point-min))) + (hywiki--maybe-rehighlight-at-point)) + (hywiki--maybe-rehighlight-at-point)))) (defun hywiki-buttonize-non-character-commands () @@ -3005,7 +3014,7 @@ or this will return nil." (start (nth 1 wikiword-start-end)) (end (nth 2 wikiword-start-end))) (with-syntax-table hywiki--org-mode-syntax-table - (if (cond (wikiword + (if (and (cond (wikiword ;; Handle an Org link [[HyWikiWord]] [[hy:HyWikiWord]] ;; or [[HyWikiWord#section][Description Text]]. ;; Get the HyWikiWord link reference, ignoring any @@ -3054,7 +3063,7 @@ or this will return nil." ;; the delimiters, so reprocess and do ;; not allow spaces in the #section part (memq (char-syntax (or (char-before) 0)) - '(?\( ?\<)))) + '(?\( ?\< ?\")))) (goto-char opoint) (skip-syntax-backward "^-$()<>._\"\'" bol) ;; Move to start of wikiword reference @@ -3103,6 +3112,11 @@ or this will return nil." ;; No following char wikiword (string-trim (buffer-substring-no-properties start end))))))))) + ;; If `wikiword' has a #section, ensure there are + ;; no invalid chars + (if (and (stringp wikiword) (string-match "#" wikiword)) + (string-match "#[^][#()<>{}\"\n\r\f]+\\'" wikiword) + t)) (if range-flag (list wikiword start end) wikiword) @@ -3170,12 +3184,16 @@ Return nil if WORD is a prefixed, typed hy:HyWikiWord, since these are handled by the Org mode link handler." (and (stringp word) (not (string-empty-p word)) (let (case-fold-search) - (or (string-match hywiki-word-with-optional-suffix-exact-regexp word) - ;; For now this next version allows spaces and tabs in - ;; the suffix part - (eq 0 (string-match - hywiki-word-with-optional-suffix-exact-regexp - word)))))) + (and (or (string-match hywiki-word-with-optional-suffix-exact-regexp word) + ;; For now this next version allows spaces and tabs in + ;; the suffix part + (eq 0 (string-match + hywiki-word-with-optional-suffix-exact-regexp + word))) + ;; If has a #section, ensure there are no invalid chars + (if (string-match "#" word) + (string-match "#[^][#()<>{}\"\n\r\f]+\\'" word) + t))))) (defun hywiki-word-read (&optional prompt) "Prompt with completion for and return an existing HyWikiWord. diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el index 0d21d7897f..139f5863ba 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: 30-Mar-25 at 15:18:37 by Bob Weiner +;; Last-Mod: 5-Apr-25 at 16:34:30 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -330,7 +330,7 @@ line 2 (with-temp-buffer (insert "WikiWord#\"section-within-quotes\"") (goto-char 4) - (should (string= "WikiWord#\"section-within-quotes\"" (hywiki-word-at))))) + (should-not (string= "WikiWord#\"section-within-quotes\"" (hywiki-word-at))))) (hy-delete-dir-and-buffer hywiki-directory))))) (ert-deftest hywiki-tests--word-is-p () @@ -1289,7 +1289,7 @@ up the test." (save-excursion (unwind-protect (progn - (should (hact 'kbd-key "C-u C-h hhcn (emacs) RET")) + (should (hact 'kbd-key "C-u C-h hhc MyWiki RET n (emacs) RET")) (hy-test-helpers:consume-input-events)) (kill-buffer "*info*")))))