branch: externals/hyperbole
commit fd51e186ee9fe27ae6f053e3c3bef3cf88a9c2dd
Author: bw <[email protected]>
Commit: bw <[email protected]>

    hywiki-insert-link - Fix transposition typo quoting double quote.
    
    hsys-consult-require-version - Add to make this flag use and version check 
callable
    from other libraries.
    
    hywiki-page-read-reference - Fix to always return a string or nil, not a 
list.
    
    hywiki-format-reference-to-grep - Remove, unused.
    hywiki-get-page-headings - Remove 'shell-quote-argument' around 'page' name.
    
    hywiki-completion-at-point - Remove 'hywiki-get-singular-wikiword' call 
because
    it can be wrong.
---
 ChangeLog       | 14 +++++++++++++-
 hsys-consult.el | 40 ++++++++++++++++++----------------------
 hywiki.el       | 39 ++++++++-------------------------------
 3 files changed, 39 insertions(+), 54 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 7bd105b41b..d8ce3db9e0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,18 @@
 2026-02-28  Bob Weiner  <[email protected]>
 
-* hywiki.el (hywiki-completion-at-point): Remove 'hywiki-get-singular-wikiword'
+* 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
+    new function.
+
+* hywiki.el (hywiki-consult-page-and-headline): Call above new function.
+            (hywiki-page-read-reference): Fix to always return a string or nil,
+    not a list.
+            (hywiki-format-reference-to-grep): Remove, unused.
+           (hywiki-get-page-headings): Remove 'shell-quote-argument' around
+    'page' name.  Not used in other grep calls.
+            (hywiki-insert-link): Fix transposition typo quoting double quote.
+            (hywiki-completion-at-point): Remove 'hywiki-get-singular-wikiword'
     call because it can be wrong.
             (hywiki-completion-exit-function): Allow completion function to
     send any number of arguments (unused right now).
diff --git a/hsys-consult.el b/hsys-consult.el
index 13d11296d6..a94145fe41 100644
--- a/hsys-consult.el
+++ b/hsys-consult.el
@@ -2,7 +2,7 @@
 ;; Author:       Bob Weiner
 ;;
 ;; Orig-Date:     4-Jul-24 at 09:57:18
-;; Last-Mod:     19-Feb-26 at 00:52:16 by Bob Weiner
+;; Last-Mod:     28-Feb-26 at 10:15:27 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -108,6 +108,21 @@ Requires use of `vertico' for completions."
     "[ \t]+" t)
    include-all-flag))
 
+;;;###autoload
+(defun hsys-consult-require-version ()
+  "Require `hsys-consult-flag' set and minimum `consult' version or error.
+Install `consult' package if not yet installed."
+  (unless hsys-consult-flag
+    (error "`%s' command requires `hsys-consult-flag' set to t" this-command))
+  (unless (package-installed-p 'consult)
+    (package-install 'consult))
+  (require 'consult)
+  (let ((consult-version (hsys-consult-get-version)))
+    ;; Multi-file support added after consult version "0.32"
+    (when (not (and consult-version (string-greaterp consult-version "0.32")))
+      (error "(hsys-consult-grep): consult package version is %s; update 
required"
+            consult-version))))
+
 ;;;###autoload
 (defun hsys-consult-get-version ()
   "Return the string version of the installed consult package or nil."
@@ -135,17 +150,7 @@ per file to the absolute value of MAX-MATCHES, if given 
and not 0.  If
 
 With optional PROMPT string, use this as the first part of the grep prompt;
 omit any trailing colon and space in the prompt."
-  (unless hsys-consult-flag
-    (error "`%s' command requires `hsys-consult-flag' set to t" this-command))
-  (unless (package-installed-p 'consult)
-    (package-install 'consult))
-  (require 'consult)
-
-  (let ((consult-version (hsys-consult-get-version)))
-    ;; Multi-file support added after consult version "0.32"
-    (when (not (and consult-version (string-greaterp consult-version "0.32")))
-      (error "(hsys-consult-grep): consult package version is %s; update 
required"
-            consult-version)))
+  (hsys-consult-require-version)
   (let* ((consult-grep-args
          (if (listp consult-grep-args)
              (append consult-grep-args (list grep-includes))
@@ -327,16 +332,7 @@ start of headline text only (lines that start with a 
'^[*#]+[
 
 With optional PROMPT string, use this as the first part of the
 grep prompt; omit any trailing colon and space in the prompt."
-  (unless hsys-consult-flag
-    (error "`%s' command requires `hsys-consult-flag' set to t" this-command))
-  (unless (package-installed-p 'consult)
-    (package-install 'consult))
-  (require 'consult)
-  (let ((consult-version (hsys-consult-get-version)))
-    ;; Multi-file support added after consult version "0.32"
-    (when (not (and consult-version (string-greaterp consult-version "0.32")))
-      (error "(hsys-consult-grep): consult package version is %s; update 
required"
-            consult-version)))
+  (hsys-consult-require-version)
   (when max-matches
     (setq max-matches (prefix-numeric-value max-matches)))
   (when (and (integerp max-matches) (zerop max-matches))
diff --git a/hywiki.el b/hywiki.el
index 173d748b12..2283ccf159 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 01:39:39 by Bob Weiner
+;; Last-Mod:     28-Feb-26 at 13:24:20 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -1643,6 +1643,7 @@ nil, else return \\='(page . \"<page-file-path>\")."
 (defun hywiki-consult-page-and-headline (&optional prompt initial)
   "Return a string of HyWiki file and headline selected by `consult-grep' or 
nil."
   (interactive)
+  (hsys-consult-require-version)
   (let* ((default-directory (expand-file-name hywiki-directory))
          (dir "./")
          (builder
@@ -2066,7 +2067,8 @@ This includes the delimiters: (), {}, <>, [] and \"\" 
(double quotes)."
          (list nil nil))))))
 
 (defun hywiki-page-read-reference (&optional prompt initial)
-  "With consult package loaded, read a \"file^@line\" string, else a page 
name."
+  "With consult package loaded, read a \"page^@line\" string, else a page name.
+May return nil if no item is selected."
   (interactive)
   (if (featurep 'consult)
       (hywiki-format-grep-to-reference (hywiki-consult-page-and-headline
@@ -2074,8 +2076,7 @@ This includes the delimiters: (), {}, <>, [] and \"\" 
(double quotes)."
                                         
(hywiki-format-reference-to-consult-grep
                                          initial)))
     ;; Without consult, can only complete to a HyWiki page without a section.
-    ;; Make a completion table of page names.
-    (mapcar #'list (hywiki-get-page-list))))
+    (hywiki-page-read prompt initial)))
 
 ;;;###autoload
 (defun hywiki-insert-link (&optional arg)
@@ -2086,7 +2087,7 @@ Add double quotes if the section contains any whitespace 
after trimming."
   (let ((ref (if arg (hywiki-word-read) (hywiki-page-read-reference))))
     (when ref
       (when (string-match-p "\\s-" ref)
-       (setq ref (concat "\"" ref ""\")))
+       (setq ref (concat "\"" ref "\"")))
       (insert ref)
       (skip-chars-backward "\"")
       (goto-char (1- (point)))
@@ -2112,7 +2113,7 @@ therein is invalid, trigger an error."
       nil)))
 
 (defun hywiki-format-reference-to-consult-grep (page-and-section)
-  "From PAGE-AND-SECTION ref, return '|^[ \t]*\\*+.*sect|page.*\.org' grep pat.
+  "From PAGE-AND-SECTION ref, return '|^[ \t]*\\*+.*sect|page' grep pat.
 
 Return t if PAGE-AND-SECTION is a valid string, else nil.  If the page name
 therein is invalid, trigger an error."
@@ -2129,35 +2130,11 @@ therein is invalid, trigger an error."
           (format "|[ \t]*\\\\*+.*%s|%s"
                   (regexp-quote line)
                   (regexp-quote page)
-                  ;; (regexp-quote hywiki-file-suffix)
                   ))
       (message "(hwiki-format-reference-to-consult-grep): Parse error on: %s"
                page-and-section)
       nil)))
 
-(defun hywiki-format-reference-to-grep (page-and-section)
-  "From PAGE-AND-SECTION ref, return '|^[ \t]*\\*+.*sect|page.*\.org' grep pat.
-
-Return t if PAGE-AND-SECTION is a valid string, else nil.  If the page name
-therein is invalid, trigger an error."
-  (when (and page-and-section (stringp page-and-section))
-    (if (string-match hywiki-word-with-optional-suffix-exact-regexp
-                      page-and-section)
-        (let ((page (match-string 1 page-and-section))
-              (line (match-string 2 page-and-section)))
-          (setq line (if line
-                         ;; Remove the # prefix in line
-                         (substring line 1)
-                       ""))
-          ;; Add '* ' prefix
-          (format "[ \t]*\\\\*+.*%s"
-                  (regexp-quote page)
-                  (regexp-quote hywiki-file-suffix)
-                  (regexp-quote line)))
-      (message "(hwiki-format-reference-to-grep): Parse error on: %s"
-               page-and-section)
-      nil)))
-
 (defun hywiki-maybe-dehighlight-balanced-pairs ()
   "Before or after a balanced delimiter, dehighlight HyWikiWords within.
 Include: (), {}, <>, [] and \"\" (double quotes).  Exclude Org links
@@ -2880,7 +2857,7 @@ These must end with `hywiki-file-suffix'."
   "Return a list of all headings found in FILE.
 Strip any leading '*' and space characters from the headings."
   (when (and (stringp page) (file-readable-p page))
-    (let ((grep-command (format "grep -E '^\\*+ ' %s" (shell-quote-argument 
page))))
+    (let ((grep-command (format "grep -E '^\\*+ ' %s" page)))
       (with-temp-buffer
         (shell-command grep-command (current-buffer))
         (goto-char (point-min))

Reply via email to