Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2026-02-02 Bob Weiner <rsw@gnu.org>

* test/hywiki-tests.el (hywiki-tests--edit-string-pairs): Enable two more tests
that now pass.

* hywiki.el (hywiki-word-at): Near the end, change the string-match to not
have to match the entire string since it may contain disallowed characters.
Cut the reference string off at the first invalid character.
This fixes a problem that prevented highlighting a reference when a trailing
double quote was deleted.
(hywiki-delimited-p): Remove doc constraint that only delimiters around
a single HyWikiWord reference are allowed; also trim any trailing whitespace.
(hywiki-delimited-p): Fix to handle matching quotes when checking
matching delimiters.

2026-02-02 Mats Lidell <matsl@gnu.org>

* hibtypes.el (hywiki-active-in-current-buffer-p)
Expand Down
4 changes: 2 additions & 2 deletions hibtypes.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 19-Sep-91 at 20:45:31
;; Last-Mod: 5-Jan-26 at 23:42:19 by Bob Weiner
;; Last-Mod: 2-Feb-26 at 18:22:19 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -65,8 +65,8 @@
(declare-function htype:def-symbol "hact")
(declare-function hui:help-ebut-highlight "hui")
(declare-function hyperb:stack-frame "hversion")
(declare-function hywiki-active-in-current-buffer-p "hywiki")
(declare-function hyrolo-get-file-list "hyrolo")
(declare-function hywiki-active-in-current-buffer-p "hywiki")
(declare-function hywiki-get-singular-wikiword "hywiki")
(declare-function hywiki-highlight-word-get-range "hywiki")
(declare-function hywiki-referent-exists-p "hywiki")
Expand Down
46 changes: 31 additions & 15 deletions hywiki.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 21-Apr-24 at 22:41:13
;; Last-Mod: 1-Feb-26 at 19:16:29 by Bob Weiner
;; Last-Mod: 2-Feb-26 at 23:16:23 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -3432,14 +3432,19 @@ non-nil or this will return nil."
end (match-end 0)
;; No following char
wikiword (string-trim (match-string-no-properties 0)))))))))
;; If `wikiword' reference has a #section, ensure there are
;; no invalid chars. One set of \n\r characters is allowed.
;; If `wikiword' reference has a #section, ensure
;; it stops when there are any disallowed characters
;; and reset the value of 'end' to match any reduction.
;; One set of \n\r characters is allowed but no
;; whitespace at the end of the reference.
(if (and (stringp wikiword) (string-match "#" wikiword))
(string-match "#[^][#()<>{}\"\f]+\\'" wikiword)
(when (string-match "#[^][#()<>{}\"\f]*[^][#()<>{}\"\f\t\n\r ]" wikiword)
(setq end (- end (- (length wikiword)
(match-end 0)))
wikiword (substring wikiword 0 (match-end 0))))
t))
(if range-flag
(progn
(list wikiword start end))
(list wikiword start end)
wikiword)
(when range-flag
'(nil nil nil))))))
Expand Down Expand Up @@ -3533,9 +3538,6 @@ or this will return nil."
Any non-nil value returned is a list of (hywikiword-ref start-pos end-pos).
The delimited range must be two lines or less with point on the first line.

Matching delimiters around anything other than a single HyWikiWord reference
are ignored.

Use `hywiki-word-at', which calls this, to determine whether there is
a HyWikiWord at point."
(save-excursion
Expand All @@ -3545,13 +3547,27 @@ a HyWikiWord at point."
;; Limit balanced pair checks to current through next lines for speed.
;; Point must be either on the opening line.
(narrow-to-region (line-beginning-position) (line-end-position 2))
(or (hypb:in-string-p nil t)
(let ((range (hargs:delimited "[\[<\(\{]" "[\]\}\)\>]" t t t)))
(and range
;; Ensure closing delimiter is a match for the opening one
(eq (matching-paren (char-before (nth 1 range)))
(let* ((range (or (hypb:in-string-p nil t)
(hargs:delimited "[\[<\(\{]" "[\]\}\)\>]" t t t)))
(wikiword (car range))
range-trimmed
wikiword-trimmed)
(if (and wikiword (string-match "[ \t\n\r\f]+\\'" wikiword))
;; Strip any trailing whitespace
(setq wikiword-trimmed (substring wikiword 0 (match-beginning 0))
range-trimmed (list wikiword-trimmed (nth 1 range)
(- (nth 2 range) (length (match-string
0 wikiword)))))
(setq range-trimmed range))
(and range-trimmed
;; Ensure closing delimiter is a match for the opening one
(or (eq (matching-paren (char-before (nth 1 range)))
(char-after (nth 2 range)))
range))))))
;; May be string quotes where matching-paren returns nil.
(and (eq (char-before (nth 1 range))
(char-after (nth 2 range)))
(eq (char-syntax (char-before (nth 1 range))) ?\")))
range-trimmed)))))

(defun hywiki-word-face-at-p (&optional pos)
"Non-nil if point or optional POS has the `hywiki-word-face' property.
Expand Down
8 changes: 4 additions & 4 deletions test/hywiki-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell
;;
;; Orig-Date: 18-May-24 at 23:59:48
;; Last-Mod: 2-Feb-26 at 00:32:30 by Bob Weiner
;; Last-Mod: 2-Feb-26 at 23:37:48 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand All @@ -28,12 +28,12 @@

(defconst hywiki-tests--edit-string-pairs
[
;; !! TODO: These tests fail
;; ("Hi#a<insert-char ?b> cd" "{Hi#ab} cd")
;; !! TODO: This test fails
;; ("\"WikiWord#section with spaces\"<backward-delete-char 1>" "\"{WikiWord#section} with spaces") ;; shrink highlight to "{WikiWord#section}
;; ("\"WikiWord#a b c<backward-delete-char 2>" "\"{WikiWord#a} b")

;; These tests pass
("Hi#a<insert-char ?b> cd" "{Hi#ab} cd")
("\"WikiWord#a b c<backward-delete-char 2>" "\"{WikiWord#a} b")
("Hi" "{Hi}")
("HyWikiW<kill-word 1>ord<yank 1> HyW<kill-word 1>ikiWord<yank 1>"
"{HyWikiWord} {HyWikiWord}")
Expand Down