branch: externals/hyperbole
commit 4789ab611520667faf8e1b229c46f97b6e06bc43
Author: bw <[email protected]>
Commit: bw <[email protected]>
hywiki-completion-at-point - Limit candidates to matching prefix
hywiki-tests--completion-at-point - Fix to newest HyWiki completion
policies.
---
ChangeLog | 6 ++++++
hywiki.el | 29 +++++++++++++++++------------
test/hywiki-tests.el | 14 ++++++--------
3 files changed, 29 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 315160385a..7ef310454e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -12,6 +12,12 @@
(hywiki-word-at): Make char after # optional so when doing
completion and # is followed by a closing delimiter, it does not stop
completing because of failure to recognize the WikiWord reference.
+ (hywiki-completion-at-point): Rewrite to limit candidates to those
+ that start with a match to the WikiWord prefix at point; allowing for
+ matches anywhere within the WikiWord made it harder to find the references
+ desired.
+* test/hywiki-tests.el (hywiki-tests--completion-at-point): Fix to newest
+ HyWiki completion policies.
2026-02-28 Bob Weiner <[email protected]>
diff --git a/hywiki.el b/hywiki.el
index a9e42579d6..d0ffc58310 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: 1-Mar-26 at 01:28:37 by Bob Weiner
+;; Last-Mod: 1-Mar-26 at 12:12:41 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -1504,23 +1504,28 @@ Each candidate is an alist with keys: file, line, text,
and display."
(hywiki-word-at t t)))
(ref (nth 0 ref-start-end))
(start (nth 1 ref-start-end))
- (end (nth 2 ref-start-end)))
- (when start
+ (end (nth 2 ref-start-end))
+ (prefix (and start end (buffer-substring-no-properties start end)))
+ (existing-wikiword-prefix (when ref (hywiki-word-strip-suffix ref))))
+ (when prefix
(let* ((default-directory hywiki-directory)
- (cmd (format "grep -nEH '^([ \t]*\\*+|#\\+TITLE:) +' ./*%s*%s"
- (hywiki-word-strip-suffix ref)
+ (cmd (format "grep -nEH '^([ \t]*\\*+|#\\+TITLE:) +' ./%s*%s"
+ existing-wikiword-prefix
hywiki-file-suffix))
(output (shell-command-to-string cmd))
(lines (split-string output "\n" t))
- (candidate-alist
- (mapcar #'list
- (delq nil
- (nconc (hywiki-get-page-list)
- (mapcar #'hywiki-format-grep-to-reference
lines))))))
- (when candidate-alist
+ (candidates (delq nil
+ (nconc
+ ;; Return only candidates that start with
'existing-wikiword-prefix'
+ (seq-filter (lambda (str)
+ (string-prefix-p
existing-wikiword-prefix str))
+ (hywiki-get-page-list))
+ (mapcar #'hywiki-format-grep-to-reference
lines))))
+ (candidates-alist (when candidates (mapcar #'list candidates))))
+ (when candidates-alist
(setq hywiki--char-before (char-before start)
hywiki--end-pos end)
- (list start end candidate-alist
+ (list start end candidates-alist
:exclusive 'no
;; For company, allow any non-delim chars in prefix
;; :company-prefix-length t
diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el
index e18b3a689c..820dc43c54 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: 9-Feb-26 at 00:26:10 by Bob Weiner
+;; Last-Mod: 1-Mar-26 at 11:20:52 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -2215,10 +2215,10 @@ expected result."
(skip-unless (version<= "9.6" (org-version)))
(hywiki-tests--preserve-hywiki-mode
(ert-info ("Nothing to complete")
- (should-not (hywiki-tests--remove-keyword-args
(hywiki-completion-at-point))))
+ (should-not (hywiki-completion-at-point)))
(ert-info ("String 'ab' can't be completed")
(insert "ab")
- (should-not (hywiki-tests--remove-keyword-args
(hywiki-completion-at-point))))
+ (should-not (hywiki-completion-at-point)))
(ert-info ("Word 'Wi' can be completed")
(erase-buffer)
(insert "Wi")
@@ -2226,8 +2226,7 @@ expected result."
(hywiki-tests--remove-keyword-args
(hywiki-completion-at-point)))))
(ert-info ("Word is extended to 'Wixx' so it can't be completed")
(insert "xx")
- (should (equal (list 1 5 '(("WikiWord")))
- (hywiki-tests--remove-keyword-args
(hywiki-completion-at-point)))))
+ (should-not (hywiki-completion-at-point)))
(save-excursion
(with-current-buffer (find-file wiki-page)
(insert "\
@@ -2237,9 +2236,8 @@ expected result."
")
(save-buffer)))
(ert-info ("Word 'Wixx' can't be completed, no headers are returned")
- (should (equal (list 1 5 '(("WikiWord")))
- (hywiki-tests--remove-keyword-args
(hywiki-completion-at-point)))))
- (ert-info ("Word 'Wiki' can be completed so headers too are returned")
+ (should-not (hywiki-completion-at-point)))
+ (ert-info ("Word 'Wiki' can be completed so headers are returned")
(erase-buffer)
(insert "Wiki")
(should (equal (list 1 5 '(("WikiWord") ("WikiWord#Header")
("WikiWord#SubHeader") ("WikiWord#SubSubHeader")))