branch: externals/hyperbole
commit 0c11f4124a253b0758623cc662e7c0b9f1904587
Merge: 3662af9801 ebd6c5536a
Author: Robert Weiner <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #876 from rswgnu/rsw
hywiki-completion-exit-function - insert any needed closing delim
hywiki-word-set-auto-highlighting - Fix when going from :pages to :all.
set:difference was returning nil because the larger set of buffers
was not given as the first argument.
---
ChangeLog | 9 +++++++++
hywiki.el | 44 +++++++++++++++++++++++++++++++++-----------
2 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d8ce3db9e0..841e8c5a31 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2026-02-28 Bob Weiner <[email protected]>
+* hywiki.el (hywiki--char-before): Add to communicate between
+ 'hywiki-completion-at-point' and its :exit-function.
+ (hywiki-delimiter-hasht): Add to lookup matching ending delimiters.
+ (hywiki-completion-exit-function): Expand to add any needed closing
+ delimiter and to leave point on the last character of the ref so can
activate
+ with {M-RET} if desired.
+ (hywiki-word-set-auto-highlighting): Reverse order of
'set:difference'
+ args when going from :pages to :all, as the bigger set, :all, must come
+ first or the difference will always be nil.
* hsys-consult.el (hsys-consult-require-version): Add to make this flag use
and version check callable from other libraries.
(hsys-consult-grep, hsys-consult--grep-paths): Call above
diff --git a/hywiki.el b/hywiki.el
index 2283ccf159..900366d6d9 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: 28-Feb-26 at 13:24:20 by Bob Weiner
+;; Last-Mod: 28-Feb-26 at 15:37:59 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -144,6 +144,7 @@
(require 'hpath)
(require 'hproperty)
(require 'hsys-consult)
+(eval-when-compile (require 'consult nil t))
(require 'hui) ;; For `hui:actype'
(require 'hui-mini) ;; For `hui:menu-act'
(require 'hypb) ;; Requires `seq'
@@ -197,9 +198,13 @@ checks it to determine if any buffer modification has
occurred or not.")
Each such key self-inserts before highlighting any prior HyWikiWord
in `hywiki-mode'.")
-(defvar hywiki--word-and-buttonize-character-regexp nil
- "Regexp matching HyWikiWord#section plus a valid word separating character.
-Group 1 is the entire HyWikiWord#section:Lnum:Cnum expression.")
+(defvar hywiki--delimiter-hasht (hash-make '(("\"" . ?\")
+ ("\'" . ?\')
+ ("{" . ?})
+ ("[" . ?\])
+ ("<" . ?>)
+ ("(" . ?\))) t)
+ "Delimiter htable with (open-delim-string . close-delim-char) key-value
pairs.")
(defvar hywiki--directory-checksum ""
"String checksum for `hywiki-directory' page names.")
@@ -227,6 +232,10 @@ Each element is of the form: (\"wikiword\" .
(referent-type . referent-value))."
(defvar hywiki--referent-hasht nil
"HyWiki hash table for fast WikiWord referent lookup.")
+(defvar hywiki--word-and-buttonize-character-regexp nil
+ "Regexp matching HyWikiWord#section plus a valid word separating character.
+Group 1 is the entire HyWikiWord#section:Lnum:Cnum expression.")
+
;; Globally set these values to avoid using 'let' with stack allocations
;; within `hywiki-maybe-highlight-reference' frequently.
(defvar hywiki--any-wikiword-regexp-list nil)
@@ -245,6 +254,7 @@ Each element is of the form: (\"wikiword\" . (referent-type
. referent-value))."
(defvar-local hywiki--buttonize-end (make-marker)) ;; This must always stay
a marker
(defvar-local hywiki--buttonize-start (make-marker)) ;; This must always stay
a marker
(defvar-local hywiki--buttonize-range nil)
+(defvar-local hywiki--char-before nil)
(defvar-local hywiki--end nil)
(defvar-local hywiki--range nil)
(defvar-local hywiki--start nil)
@@ -1491,12 +1501,11 @@ 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))
- (partial-page-name ref))
+ (end (nth 2 ref-start-end)))
(when start
(let* ((default-directory hywiki-directory)
(cmd (format "grep -nEH '^([ \t]*\\*+|#\\+TITLE:) +' ./*%s*%s"
- (regexp-quote partial-page-name)
+ (regexp-quote ref)
hywiki-file-suffix))
(output (shell-command-to-string cmd))
(lines (split-string output "\n" t))
@@ -1506,6 +1515,7 @@ Each candidate is an alist with keys: file, line, text,
and display."
(nconc (hywiki-get-page-list)
(mapcar #'hywiki-format-grep-to-reference
lines))))))
(when candidate-alist
+ (setq hywiki--char-before (char-before start))
(list start end candidate-alist
:exclusive 'no
;; For company, allow any non-delim chars in prefix
@@ -3903,12 +3913,14 @@ occurs with one of these hooks, the problematic hook is
removed."
hywiki-to-mode)))
((and (eq hywiki-from-mode :all) (eq hywiki-to-mode :pages))
(hywiki-word-dehighlight-buffers
- (set:difference (hywiki-get-buffers hywiki-from-mode)
- (hywiki-get-buffers hywiki-to-mode))))
+ (set:difference (hywiki-get-buffers :all)
+ (hywiki-get-buffers :pages))))
((and (eq hywiki-from-mode :pages) (eq hywiki-to-mode :all))
(hywiki-word-highlight-buffers
- (set:difference (hywiki-get-buffers hywiki-from-mode)
- (hywiki-get-buffers hywiki-to-mode))))
+ ;; Here the larger set must always be given first to compute any
+ ;; difference
+ (set:difference (hywiki-get-buffers :all)
+ (hywiki-get-buffers :pages))))
(t
(error "(hywiki-word-set-auto-highlighting): Inputs must be nil,
:pages or :all, not '%s' and '%s'"
hywiki-from-mode hywiki-to-mode))))
@@ -3950,6 +3962,16 @@ occurs with one of these hooks, the problematic hook is
removed."
(defun hywiki-completion-exit-function (&rest _)
"Function called when HyWiki reference completion ends."
+ ;; Find possibly needed closing delimiter and insert it if not already there
+ (let ((end-delim (when (characterp hywiki--char-before)
+ (hash-get (char-to-string hywiki--char-before)
+ hywiki--delimiter-hasht))))
+ (if (and end-delim
+ (or (>= (point) (point-max))
+ (not (eq (char-after (point)) end-delim))))
+ (progn (insert end-delim)
+ (goto-char (- (point) 2)))
+ (goto-char (1- (point)))))
(hywiki-maybe-highlight-reference))
(defun hywiki-word-add-completion-at-point ()