Skip to content
Open
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
11 changes: 11 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
2026-08-12 Bob Weiner <rsw@gnu.org>

* hywiki.el (hywiki-get-referent-hasht): Compute 'hywiki--any-wikiword-regexp-list'
and highlight wikiwords only when the wikiword hash table is non-empty,
to fix bug #81594.
test/hywiki-tests.el (hywiki-tests--bug-81594-file,
hywiki-tests--bug-81594-buffer): Add tests for this.

* test/hy-test-helpers.el (hy-test-helpers:with-time): Add to time any part
of a function.

2026-08-11 Mats Lidell <matsl@gnu.org>

* (check-copyright): Check copyright and SPDX headers.
Expand Down
8 changes: 4 additions & 4 deletions hsys-denote.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 2-Jul-16 at 14:54:14
;; Last-Mod: 14-Jul-26 at 17:00:54 by Mats Lidell
;; Last-Mod: 12-Aug-26 at 12:35:19 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -150,8 +150,8 @@ denote link."

(defact link-to-denote (id-and-section &optional file)
"Display a denote entry given by ID-AND-SECTION and optional FILE.
ID-AND-SECTION optionally may be prefixed with \"denote:\" or \"dn:\" and
may be suffixed with:
ID-AND-SECTION optionally may be prefixed with \"denote:\" and may be
suffixed with:

1. #section or ::*section, where section is any exact match to a denote
in-file heading;
Expand Down Expand Up @@ -179,7 +179,7 @@ and ID-AND-SECTION or FILE is not found, trigger an error."
(hypb:error "(link-to-denote): File is unreadable: \"%s\""
file))
(if (stringp id-and-section)
;; Remove any "denote:" or "dn:" prefix
;; Remove any "denote:" prefix
(let ((file-id (denote-extract-id-from-string id-and-section))
(section (when (and (string-match (hys-denote-get-link-regexp)
id-and-section)
Expand Down
4 changes: 2 additions & 2 deletions hui-mini.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 15-Oct-91 at 20:13:17
;; Last-Mod: 19-Jul-26 at 09:57:15 by Bob Weiner
;; Last-Mod: 9-Aug-26 at 10:46:08 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -1146,7 +1146,7 @@ With a prefix arg, insert a HyWikiWord instead.")
("org-roam-Find" hyrolo-org-roam)
;; ("recent-Files" recentf-open-files)
("Global-Buttons" (find-file (expand-file-name hbmap:filename hbmap:dir-user)))
;; ("Helm" (menu . helm) "Display Hyperbole helm control menu")
;; ("Home or Hyperbole" (menu . ...))
;; ("I")
("Jump-to-Websites" webjump)
("Koutlines" hui:menu-to-personal-section)
Expand Down
6 changes: 4 additions & 2 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: 27-Jul-26 at 10:43:32 by Bob Weiner
;; Last-Mod: 12-Aug-26 at 23:08:13 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -2831,7 +2831,9 @@ regexps of wikiwords, if the hash table is out-of-date."
hywiki--referent-hasht
;; Rebuild referent hash table
(hywiki-make-referent-hasht))
(unless hywiki--any-wikiword-regexp-list
(when (and (null hywiki--any-wikiword-regexp-list)
hywiki--referent-hasht
(not (hash-empty-p hywiki--referent-hasht)))
;; Compute these expensive regexps (matching 50
;; HyWikiWords at a time) only if the set of
;; HyWikiWords changed in `hywiki-directory'.
Expand Down
14 changes: 13 additions & 1 deletion test/hy-test-helpers.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell <matsl@gnu.org>
;;
;; Orig-Date: 30-Jan-21 at 12:00:00
;; Last-Mod: 15-Jul-26 at 22:00:22 by Mats Lidell
;; Last-Mod: 12-Aug-26 at 18:27:28 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand All @@ -23,6 +23,18 @@
(require 'hywiki) ;; For `hywiki-word-face-at-p' and (require 'hypb)
(eval-when-compile (require 'cl-lib))

(defmacro hy-test-helpers:with-time (descrip &rest body)
"Log a message of DESCRIP; return the time in seconds to run rest, BODY."
(declare (indent 1) (debug (form body)))
(let ((start (gensym "start"))
(elapsed (gensym "elapsed")))
`(let* ((,start (float-time))
(,elapsed 0.0))
,@body
(setq ,elapsed (- (float-time) ,start))
(message "(%s): took %.2f seconds" ,descrip ,elapsed)
,elapsed)))

(defun hy-test-helpers:consume-input-events ()
"Use `recursive-edit' to consume the events kbd-key generates."
(run-with-timer 0.5 nil (lambda () (if (> (recursion-depth) 0) (exit-recursive-edit))))
Expand Down
201 changes: 123 additions & 78 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: 27-Jul-26 at 17:22:19 by Bob Weiner
;; Last-Mod: 12-Aug-26 at 23:14:43 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -54,6 +54,7 @@ named WikiReferent with a non-page referent type."

(defconst hywiki-tests--edit-string-pairs
[
("(Non#s n)<backward-delete-char 1>" "(Non#s n")
("\"WikiWord#section with spaces\"<backward-delete-char 1>" "\"{WikiWord#section} with spaces") ;; shrink highlight to "{WikiWord#section}
("Hi#a<insert-char ?b> cd" "{Hi#ab} cd")
("\"WikiWord#a b c<backward-delete-char 2>" "\"{WikiWord#a} b")
Expand All @@ -74,7 +75,6 @@ named WikiReferent with a non-page referent type."
("WikiWord#a b c<backward-delete-char 1>" "{WikiWord#a} b ")
("HiHo#s " "{HiHo#s} ")
("HiHo#s<insert-char ? >" "{HiHo#s} ")
("(Non#s n)<backward-delete-char 1>" "({Non#s} n")
("<kill-word 1>WikiWord unhighlighted" " unhighlighted") ;; dehighlight
;; WikiWord below does not highlight since could be an Info node
;; ibut, like "(hyperbole)WikiWord", that we don't want to trigger
Expand All @@ -85,84 +85,88 @@ named WikiReferent with a non-page referent type."
Last two elements are optional.")

(ert-deftest hywiki-tests--edit ()
(hywiki-tests--preserve-hywiki-mode
(let ((test-num 0)
before
after
name
doc
markedup-before
markedup-after
start
end
hywiki-ref-positions)
(unwind-protect
(progn
(org-mode)
(mapc
(lambda (before-after)
(condition-case err
(progn
(setq before (nth 0 before-after)
after (nth 1 before-after)
name (nth 2 before-after)
doc (nth 3 before-after))
;; Ensure all brace delimited HyWikiWords have their pages
;; created so their references will be highlighted.
(mapc #'hywiki-add-page
(delq nil
(mapcar #'hywiki-get-singular-wikiword
(seq-remove #'string-empty-p
(mapcar #'string-trim
(hywiki-tests--get-brace-strings after))))))
(unwind-protect
(progn
(pop-to-buffer (current-buffer))
(erase-buffer)
(hywiki-tests--insert-by-char before)
(hywiki-tests--interpolate-buffer)
;; Markup before string in temp buffer
;; Surround any HyWikiWord refs with braces to match after string.
(setq hywiki-ref-positions (hywiki-get-reference-positions))
(dolist (start-end hywiki-ref-positions)
(setq start (car start-end)
end (cdr start-end))
(goto-char end)
(hywiki-tests--insert "}")
(goto-char start)
(hywiki-tests--insert "{"))
;; Store the buffer string for comparison
(setq markedup-before (buffer-string))
;; Markup after string
(erase-buffer)
(hywiki-tests--insert after)
(hywiki-tests--interpolate-buffer)
(setq markedup-after (buffer-string))
;; Compare markedup-before to markedup-after
(if (or name doc)
(hy-test-helpers:with-time "hywiki-tests--edit"
(hywiki-tests--preserve-hywiki-mode
(let ((test-num 0)
before
after
name
doc
markedup-before
markedup-after
start
end
hywiki-ref-positions)
(unwind-protect
(progn
(org-mode)
(mapc
(lambda (before-after)
(condition-case err
(hy-test-helpers:with-time (format "Test #%d" test-num)
(cl-incf test-num)
(setq before (nth 0 before-after)
after (nth 1 before-after)
name (nth 2 before-after)
doc (nth 3 before-after))
(message (format "Test #%d: At pos %d, action \"%s\", result \"%s\", name \"%s\", doc \"%s\""
test-num (point) before after name doc))
;; Ensure all brace delimited HyWikiWords expected in
;; `after' string have their pages created so their
;; references will be highlighted.
(mapc #'hywiki-add-page
(delq nil
(mapcar #'hywiki-get-singular-wikiword
(seq-remove #'string-empty-p
(mapcar #'string-trim
(hywiki-tests--get-brace-strings after))))))
(unwind-protect
(progn
(pop-to-buffer (current-buffer))
(erase-buffer)
(hywiki-tests--insert-by-char before)
(hywiki-tests--interpolate-buffer)
;; Markup before string in temp buffer
;; Surround any HyWikiWord refs with braces to match after string.
(setq hywiki-ref-positions (hywiki-get-reference-positions))
(dolist (start-end hywiki-ref-positions)
(setq start (car start-end)
end (cdr start-end))
(goto-char end)
(hywiki-tests--insert "}")
(goto-char start)
(hywiki-tests--insert "{"))
;; Store the buffer string for comparison
(setq markedup-before (buffer-string))
;; Markup after string
(erase-buffer)
(hywiki-tests--insert after)
(hywiki-tests--interpolate-buffer)
(setq markedup-after (buffer-string))
;; Compare markedup-before to markedup-after
(if (or name doc)
(should (equal (list :test-num test-num
:markedup (format "%S" markedup-before)
:test-name name :doc doc
:before before :after after)
(list :test-num test-num
:markedup (format "%S" markedup-after)
:test-name name :doc doc
:before before :after after)))
(should (equal (list :test-num test-num
:markedup (format "%S" markedup-before)
:test-name name :doc doc
:before before :after after)
:markedup (format "%S" markedup-before)
:before before :after after)
(list :test-num test-num
:markedup (format "%S" markedup-after)
:test-name name :doc doc
:before before :after after)))
(should (equal (list :test-num test-num
:markedup (format "%S" markedup-before)
:before before :after after)
(list :test-num test-num
:markedup (format "%S" markedup-after)
:before before :after after))))
(cl-incf test-num))
(goto-char (point-min))))
(error (message "%s ---- %S" err (list :markedup markedup-before
:test-num test-num
:before before :after after)))))
hywiki-tests--edit-string-pairs))
(let ((default-directory hywiki-directory))
(hy-delete-files-and-buffers
'("AI.org" "FAI.org" "Hi.org" "HiHo.org" "HyWiki.org" "HyWikiW.org" "HyWikiWord.org" "MyWikiWord.org" "Non.org" "Wiki.org")))))))
:markedup (format "%S" markedup-after)
:before before :after after)))))
(goto-char (point-min))))
(error (message "%s ---- %S" err (list :markedup markedup-before
:test-num test-num
:before before :after after)))))
hywiki-tests--edit-string-pairs))
(let ((default-directory hywiki-directory))
(hy-delete-files-and-buffers
'("AI.org" "FAI.org" "Hi.org" "HiHo.org" "HyWiki.org" "HyWikiW.org" "HyWikiWord.org" "MyWikiWord.org" "Non.org" "Wiki.org"))))))))

(defun hywiki-tests--get-brace-strings (s)
"Return the substrings in S delimited by curly braces {…}, excluding braces.
Expand Down Expand Up @@ -2372,6 +2376,47 @@ Verifies the behavior controlled by the variables
(let ((hypb:include-major-modes '(dired-mode)))
(should (hywiki-potential-buffer-p)))))

(ert-deftest hywiki-tests--bug-81594-file ()
"Ensure fix for bug#81594 that scrolled window when typing a HyWikiWord."
;; We can't use `hywiki-tests--preserve-hywiki-mode' since the
;; `hywiki-directory' must be empty.
(skip-unless (not noninteractive))
(let* ((prior-hywiki-mode hywiki-mode)
(hywiki-directory (make-temp-file "hywiki" t))
(file (make-temp-file "hypb")))
(unwind-protect
(progn
(hywiki-mode :all)
(find-file file)
(let ((start (window-start)))
(hywiki-tests--insert "\n\n\nC")
(hywiki-tests--command-execute #'self-insert-command 1 ?i)
(should (= start (window-start)))))
(hywiki-mode prior-hywiki-mode)
(hy-delete-file-and-buffer file)
(hy-delete-dir-and-buffer hywiki-directory))))

(ert-deftest hywiki-tests--bug-81594-buffer ()
"Ensure fix for bug#81594 that scrolled window when typing a HyWikiWord."
;; We can't use `hywiki-tests--preserve-hywiki-mode' since the
;; `hywiki-directory' must be empty.
(skip-unless (not noninteractive))
(let* ((prior-hywiki-mode hywiki-mode)
(hywiki-directory (make-temp-file "hywiki" t)))
(unwind-protect
(progn
(hywiki-mode :all)
(with-temp-buffer
(set-window-buffer (selected-window) (current-buffer))
(let ((start (window-start)))
(sit-for 0)
(hywiki-tests--insert "\n\n\nC")
(hywiki-tests--command-execute #'self-insert-command 1 ?i)
(sit-for 0)
(should (= start (window-start)))))))
(hywiki-mode prior-hywiki-mode)
(hy-delete-dir-and-buffer hywiki-directory)))

(provide 'hywiki-tests)

;; This file can't be byte-compiled without the `el-mock' package
Expand Down
Loading