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

    hywiki-insert-link - Handle both page#section and wikiword refs
---
 ChangeLog   |  5 +++++
 hui-mini.el |  5 +++--
 hywiki.el   | 40 +++++++++++++---------------------------
 3 files changed, 21 insertions(+), 29 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4d4c3198ea..0d5011d1a4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2026-02-19  Bob Weiner  <[email protected]>
 
+* hywiki.el (hywiki-insert-link): Add optional prefix arg to link to a
+    an existing wikiword only.
+            (hywiki-insert-reference): Remove and merge capability into
+    above function when called with a prefix arg.
+
 * hui.el (hui:link-possible-types): Fix to include link-to-wikiword only if
     an existing referent is found.
 
diff --git a/hui-mini.el b/hui-mini.el
index 8c307dc243..fcc8fd7c84 100644
--- a/hui-mini.el
+++ b/hui-mini.el
@@ -3,7 +3,7 @@
 ;; Author:       Bob Weiner
 ;;
 ;; Orig-Date:    15-Oct-91 at 20:13:17
-;; Last-Mod:     19-Feb-26 at 00:16:53 by Bob Weiner
+;; Last-Mod:     19-Feb-26 at 22:59:55 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -1070,7 +1070,8 @@ support underlined faces as well."
         '("Info"           (id-info "(hyperbole)HyWiki")
           "Display Hyperbole manual section on HyWiki.")
         '("Link"           hywiki-insert-link
-          "Prompt for and insert at point a HyWikiWord#section reference.")
+          "Prompt for and insert at point a HyWiki page#section reference.
+With a prefix arg, insert a HyWikiWord instead.")
          '("ModeSet/"       (menu . cust-hywiki-mode)
           "Set hywiki-mode state to determine where HyWikiWord references are 
recognized.")
         '("Org-M-RET/"     (menu . cust-org)
diff --git a/hywiki.el b/hywiki.el
index b48e1caf46..bce235c472 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:     19-Feb-26 at 19:29:13 by Bob Weiner
+;; Last-Mod:     19-Feb-26 at 22:59:49 by Bob Weiner
 ;;
 ;; SPDX-License-Identifier: GPL-3.0-or-later
 ;;
@@ -1648,16 +1648,13 @@ nil, else return \\='(page . \"<page-file-path>\")."
        (or (hywiki-in-page-p) (string-prefix-p "*HyWiki Tags*" 
(buffer-name)))))
 
 (defun hywiki-consult-page-and-line ()
-  "Return a list of the file and line selected by consult or nil.
-Use `hywiki-insert-reference' with the result of this function to insert a
-double-quoted HyWikiWord reference at point."
+  "Return a list of the file and line selected by consult or nil."
   (interactive)
   (let* ((dir (expand-file-name hywiki-directory))
-         (manual-builder
+         (builder
           (lambda (input)
-            (let* (;; Define the regex inside the builder so it's always in 
scope
-                   (headline-pattern (concat "^\\* .*" input))
-                   ;; Ensure all arguments are evaluated as strings
+            (let* (;; Define the regexp inside the builder so it is always in 
scope
+                   (headline-regexp (concat "^\\* .*" input))
                    (args (list "rg"
                                "--null"
                                "--line-buffered"
@@ -1666,11 +1663,11 @@ double-quoted HyWikiWord reference at point."
                                "--line-number"
                                "--smart-case"
                                "-g" "*.org"
-                               "-e" headline-pattern
+                               "-e" headline-regexp
                                dir)))
               (cons args dir))))
          (selected (consult--read
-                    (consult--async-command manual-builder)
+                    (consult--async-command builder)
                     :prompt "HyWiki Headline: "
                     :require-match t
                     :lookup #'consult--lookup-member
@@ -2087,10 +2084,12 @@ This includes the delimiters: (), {}, <>, [] and \"\" 
(double quotes)."
     (hywiki-page-read "Link to HyWiki page: ")))
 
 ;;;###autoload
-(defun hywiki-insert-link ()
-  "Insert at point a link to a HyWiki page#section."
-  (interactive "*")
-  (let ((ref (hywiki-read-page-reference)))
+(defun hywiki-insert-link (&optional arg)
+  "Insert at point a HyWiki page#section reference read from the minibuffer.
+With optional prefix ARG non-nil, insert a HyWikiWord instead.
+Add double quotes if the section contains any whitespace after trimming."
+  (interactive "*P")
+  (let ((ref (if arg (hywiki-word-read) (hywiki-read-page-reference))))
     (when ref
       (insert ref)
       (skip-chars-backward "\"")
@@ -2121,19 +2120,6 @@ therein is invalid, trigger an error."
              page
              line))))
 
-(defun hywiki-insert-reference (page-and-line)
-  "Insert a HyWiki page#section reference from PAGE-AND-LINE.
-Add double quotes if the section contains any whitespace after trimming.
-
-Return t if PAGE-AND-LINE is a valid list, else nil.  If the page name
-therein is invalid, trigger an error."
-  (let ((ref (hywiki-format-reference page-and-line)))
-    (when ref
-      (insert ref)
-      (skip-chars-backward "\"")
-      (goto-char (1- (point)))
-      t)))
-
 (defun hywiki-maybe-dehighlight-balanced-pairs ()
   "Before or after a balanced delimiter, dehighlight HyWikiWords within.
 Include: (), {}, <>, [] and \"\" (double quotes).  Exclude Org links

Reply via email to