branch: externals/hyperbole
commit 8fa9e4e19880b6270c138c634855edab8779c2f8
Merge: 12c4a31a82 53f757ce03
Author: Robert Weiner <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #578 from rswgnu/rsw
hibtypes.el - Add new 'hywiki-existing-word' ibtype and other fixes
---
ChangeLog | 23 ++++++++++++++
hibtypes.el | 15 +++++++++
hui-menu.el | 14 ++++----
hui-mini.el | 11 ++++---
hui-mouse.el | 3 +-
hywiki.el | 102 +++++++++++++++++++++++++++++++++++++++++++----------------
6 files changed, 127 insertions(+), 41 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index de7e3b4d12..8c5a236c28 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2024-08-18 Bob Weiner <[email protected]>
+
+* hywiki.el (hywiki-maybe-at-wikiword-beginning): Fix to handle word
+ preceded by a single square bracket.
+
+* hibtypes.el (hywiki-existing-word): Add this new ibtype to match to
+ HyWikiWords with an existing page at a higher priority than those
+ without an existing page, so can be handled separately. Must be
+ defined in this file to set its priority at a high level.
+
+* hywiki.el (hywiki-is-wikiword): Rename to 'hywiki-word-is-p'.
+ (hywiki-word-activate , hywiki-page-strip-section,
+ hywiki-page-exists-p): Add.
+ (hywiki-word-consult-grep): Rename from `hywiki-word-search'.
+ hui-mini.el (hui:menus): Change "Act" item from 'hui:ibut-act' to
+ new 'hywiki-word-activate'.
+
+* hui-menu.el (infodock-hyperbole-menu):
+ hui-mini.el (HyWiki, IButton): Change help function from 'hui:hbut-help'
+ to 'hkey-help' so handles more contexts without erroring.
+
+* hui-menu.el (hui-menu-org-meta-return-options): Remove wrong extra parens.
+
2024-08-18 Mats Lidell <[email protected]>
* kotl/klink.el (klink:ignore-modes, klink:c-style-modes):
diff --git a/hibtypes.el b/hibtypes.el
index 11f6338543..faeaac5ea9 100644
--- a/hibtypes.el
+++ b/hibtypes.el
@@ -1634,6 +1634,21 @@ If a boolean function or variable, display its value."
(apply #'actype:eval actype args)))
(error "(action:help): No action button labeled: %s" label)))))
+;;; ========================================================================
+;;; Activates HyWikiWords with existing HyWiki pages.
+;;; Non-existing HyWikiWords are handled by the (load "hywiki") at a low
+;;; priority earlier in this file which defines the `hywiki-word' ibtype.
+;;; ========================================================================
+
+(defib hywiki-existing-word ()
+ "When on a HyWiki word with an existing page, display its page and optional
section."
+ (cl-destructuring-bind (page-name start end)
+ (hywiki-page-exists-p 'range)
+ (when page-name
+ (when (and start end)
+ (ibut:label-set page-name (match-beginning 0) (match-end 0)))
+ (hact 'hywiki-find-page page-name))))
+
;;; ========================================================================
;;; Inserts completion into minibuffer or other window.
;;; ========================================================================
diff --git a/hui-menu.el b/hui-menu.el
index cf19c8c443..799ee50486 100644
--- a/hui-menu.el
+++ b/hui-menu.el
@@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 28-Oct-94 at 10:59:44
-;; Last-Mod: 17-Aug-24 at 17:44:53 by Bob Weiner
+;; Last-Mod: 18-Aug-24 at 15:33:29 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -210,7 +210,7 @@ Return t if cutoff, else nil."
t))
(defconst hui-menu-org-meta-return-options
- '(("Org-M-RETURN"
+ '("Org-M-RETURN"
"----"
"----"
["All-Programmed-Contexts"
@@ -224,7 +224,7 @@ Return t if cutoff, else nil."
["Ignored-by-Hyperbole"
(customize-save-variable 'hsys-org-enable-smart-keys nil)
:style radio :selected (when (boundp 'hsys-org-enable-smart-keys)
- (eq hsys-org-enable-smart-keys nil))]))
+ (eq hsys-org-enable-smart-keys nil))])
"Settings for Hyperbole Smart Key overrides to {M-RET} within Org mode.")
(defconst hui-menu-options
@@ -450,16 +450,16 @@ REBUILD-FLAG is non-nil, in which case the menu is
rebuilt."
(list "HyWiki"
["Manual" (id-info "(hyperbole)HyWiki") t]
"----"
- ["Activate" hui:ibut-act t]
+ ["Activate" hywiki-word-activate t]
["Create" hywiki-add-page-and-display t]
["Edit" hywiki-find-page t]
["Grep-Consult" hywiki-consult-grep t]
- ["Help" hui:hbut-help t]
+ ["Help" hkey-help t]
["Link" hywiki-add-link t]
hui-menu-org-meta-return-options
["Publish" hywiki-publish-to-html t]
["Toggle-HyWiki-Mode" hywiki-mode t]
- ["WikiWord-Consult" hywiki-word-search t])
+ ["WikiWord-Consult" hywiki-word-consult-grep t])
'("Implicit-Button"
["Manual" (id-info "(hyperbole)Implicit Buttons") t]
"----"
@@ -467,7 +467,7 @@ REBUILD-FLAG is non-nil, in which case the menu is rebuilt."
["Create" hui:ibut-create t]
["Delete-Type" (hui:htype-delete 'ibtypes) t]
["Edit" hui:ibut-edit t]
- ["Help" hui:hbut-help t]
+ ["Help" hkey-help t]
["Link" hui:ibut-link-directly t]
["Name" hui:ibut-label-create t]
["Rename" hui:ibut-rename t]
diff --git a/hui-mini.el b/hui-mini.el
index 26f1a5a0a4..9b0522626c 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: 17-Aug-24 at 17:45:49 by Bob Weiner
+;; Last-Mod: 18-Aug-24 at 15:33:00 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -843,14 +843,15 @@ command instead. Typically prevents clashes over
{\\`C-c' /}."
("Rename" hui:gbut-rename "Rename a global button.")))
'(hywiki .
(("HyWiki>")
- ("Act" hui:ibut-act "Activate HyWikiWord link at
point.")
+ ("Act" hywiki-word-activate
+ "Activate HyWikiWord link at point or emulate a press of a Smart
Key.")
("Create" hywiki-add-page-and-display
"Create and display a new HyWiki page. Shows existing page names
to aid in new naming.")
("Edit" hywiki-find-page
"Prompt with completion for and display a HyWiki page ready for
editing.")
("GrepConsult" hywiki-consult-grep
"Grep over HyWiki pages with interactive consult-grep.")
- ("Help" hui:hbut-help
+ ("Help" hkey-help
"Report on a HyWikiWord's attributes.")
("Info" (id-info "(hyperbole)HyWiki")
"Display Hyperbole manual section on HyWiki.")
@@ -862,7 +863,7 @@ command instead. Typically prevents clashes over {\\`C-c'
/}."
"Publish modified pages in the HyWiki to HTML; prefix arg to publish
all pages.")
("Toggle" hywiki-mode
"Toggle whether HyWikiWords are highlighted and active in buffers
outside of the HyWiki page directory.")
- ("WikiWordConsult" hywiki-word-search
+ ("WikiWordConsult" hywiki-word-consult-grep
"Use `hywiki-consult-grep' to show occurrences of a prompted for
HyWikiWord.")))
'(ibut .
(("IButton>")
@@ -873,7 +874,7 @@ command instead. Typically prevents clashes over {\\`C-c'
/}."
("DeleteType" (hui:htype-delete 'ibtypes)
"Delete specified implicit button type.")
("Edit" hui:ibut-edit "Edit/modify named implicit button
attributes.")
- ("Help" hui:hbut-help "Report on button's attributes.")
+ ("Help" hkey-help "Report on button's attributes.")
("Info" (id-info "(hyperbole)Implicit Buttons")
"Display manual section on implicit buttons.")
("Link" hui:ibut-link-directly "Insert an ibut link at
point to other/another window.")
diff --git a/hui-mouse.el b/hui-mouse.el
index be78372ec8..b73e9f6f21 100644
--- a/hui-mouse.el
+++ b/hui-mouse.el
@@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 04-Feb-89
-;; Last-Mod: 18-Aug-24 at 09:35:51 by Mats Lidell
+;; Last-Mod: 18-Aug-24 at 22:03:38 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -253,7 +253,6 @@ Its default value is `smart-scroll-down'. To disable it,
set it to
(setq hkey-value (ert-results-filter-status-p)))
. ((smart-ert-results hkey-value) . (smart-ert-results-assist
hkey-value)))
;;
- ;;
;; Handle Emacs push buttons in buffers
((and (fboundp 'button-at) (button-at (point)))
. ((smart-push-button nil (mouse-event-p last-command-event))
diff --git a/hywiki.el b/hywiki.el
index 35d757f69c..1d58c2ed91 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: 13-Aug-24 at 01:44:00 by Bob Weiner
+;; Last-Mod: 18-Aug-24 at 18:02:28 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -480,7 +480,8 @@ See the Info documentation at \"(hyperbole)HyWiki\".
;;; ************************************************************************
(defib hywiki-word ()
- "When on a HyWiki word, display its page and optional section."
+ "When on a HyWiki word, display its page and optional section.
+If the associated HyWiki page does not exist, create it automatically."
(let ((page-name (hywiki-word-at)))
(when page-name
(ibut:label-set page-name (match-beginning 0) (match-end 0))
@@ -530,10 +531,9 @@ successfully finding a page and reading it into a buffer,
run
(hywiki-maybe-highlight-page-names)
(run-hooks 'hywiki-find-page-hook)
page-file)))
- ;; When called from without a page-name and outside
- ;; hywiki-directory, just find as a regular file and use next
- ;; line to highlight HyWikiWords only if buffer was not
- ;; previously highlighted.
+ ;; When called without a page-name and outside hywiki-directory,
+ ;; just find as a regular file and use next line to highlight
+ ;; HyWikiWords only if buffer was not previously highlighted.
(hywiki-maybe-highlight-page-names))))
;;; ************************************************************************
@@ -563,7 +563,7 @@ not.
Use `hywiki-get-page' to determine whether a HyWiki page exists."
(interactive (list (hywiki-read-new-page-name "Add HyWiki page: ")))
- (if (hywiki-is-wikiword page-name)
+ (if (hywiki-word-is-p page-name)
(progn
(when (match-string-no-properties 2 page-name)
;; Remove any #section suffix in PAGE-NAME.
@@ -658,17 +658,29 @@ per file to the absolute value of MAX-MATCHES, if given
and not 0. If
Does not test whether or not a page exists for the HyWiki word.
Use `hywiki-get-page' to determine whether a HyWiki page exists."
;; Ignore wikiwords preceded by any non-whitespace character, except
- ;; any of these: ({<"'`'
- (when (or (bolp) (cl-find (char-before) "\(\{\<\"'`\t\n\r\f "))
+ ;; any of these: [({<"'`'
+ (when (or (bolp) (cl-find (char-before) "\[\(\{\<\"'`\t\n\r\f "))
t))
-(defun hywiki-word-at ()
+(defun hywiki-word-activate (&optional arg)
+ "Display HyWiki page for wiki word at point, creating the page if needed.
+If found, return the full path of the page.
+
+If not on a wiki word and optional prefix ARG is null, emulate an
+Action Key press; with a prefix ARG, emulate an Assist Key press."
+ (interactive "P")
+ (let ((word hywiki-word-at))
+ (if word
+ (hywiki-find-page word)
+ (hkey-either arg))))
+
+(defun hywiki-word-at (&optional)
"Return HyWiki word and optional #section at point or nil if not on one.
-Does not test whether or not a page exists for the HyWiki word; use
-`hywiki-get-page' for that.
+Does not test whether or not a page exists for the HyWiki word; call
+`hywiki-page-exists-p' without an argument for that.
-A call to `hywiki-active-in-current-buffer-p' must return non-nil or
-this will return nil."
+A call to `hywiki-active-in-current-buffer-p' at point must return non-nil
+or this will return nil."
(when (hywiki-active-in-current-buffer-p)
(if (setq hywiki--range
(hproperty:char-property-range (point) 'face hywiki-word-face))
@@ -688,7 +700,7 @@ this will return nil."
(format "[ \t\n\r]*\\(%s:\\)?"
hywiki-org-link-type)))
;; Ignore prefixed, typed hy:HyWikiWord since Org mode will
display those.
- (when (hywiki-is-wikiword wikiword)
+ (when (hywiki-word-is-p wikiword)
wikiword))
;; Handle a HyWiki word with optional #section; if it is an Org
;; link, it may optionally have a hy: link-type prefix.
@@ -707,13 +719,23 @@ this will return nil."
(buffer-substring-no-properties (match-beginning 0)
(match-end
0)))))))))))))
-(defun hywiki-word-search (word)
+(defun hywiki-word-consult-grep (word)
"Use `hywiki-consult-grep' to show occurrences of a prompted for HyWikiWord.
Default to any HyWikiWord at point."
(interactive (list (hywiki-read-page-name)))
(if (and (stringp word) (not (string-empty-p word)))
(hywiki-consult-grep (concat "\\b" (regexp-quote word) "\\b"))
- (user-error "(hywiki-word-search): Invalid HyWikiWord: '%s'; must be
capitalized, all alpha" word)))
+ (user-error "(hywiki-word-consult-grep): Invalid HyWikiWord: '%s'; must be
capitalized, all alpha" word)))
+
+(defun hywiki-word-is-p (word)
+ "Return non-nil if WORD is a HyWiki word and optional #section.
+The page for the word may not yet exist. Use `hywiki-get-page'
+to determine whether a HyWiki word page exists."
+ (and (stringp word) (not (string-empty-p word))
+ (let (case-fold-search)
+ (or (string-match hywiki-word-with-optional-section-exact-regexp word)
+ (eq (string-match (concat "\\`"
hywiki-word-with-optional-section-regexp "\\'") word)
+ 0)))))
;;;###autoload
(defun hywiki-maybe-dehighlight-page-names (&optional region-start region-end)
@@ -1059,16 +1081,6 @@ are typed in the buffer."
(or default-directory ""))
(setq hywiki-page-flag t))))
-(defun hywiki-is-wikiword (word)
- "Return non-nil if WORD is a HyWiki word and optional #section.
-The page for the word may not yet exist. Use `hywiki-get-page'
-to determine whether a HyWiki word page exists."
- (and (stringp word) (not (string-empty-p word))
- (let (case-fold-search)
- (or (string-match hywiki-word-with-optional-section-exact-regexp word)
- (eq (string-match (concat "\\`"
hywiki-word-with-optional-section-regexp "\\'") word)
- 0)))))
-
(defun hywiki-get-buffer-page-name ()
"Extract the page name from the buffer file name or else buffer name."
(file-name-sans-extension (file-name-nondirectory
@@ -1280,6 +1292,42 @@ variables."
:follow #'hywiki-find-page
:store #'hywiki-org-link-store))
+(defun hywiki-page-exists-p (&optional word)
+ "Return an existing HyWiki page name from optional WORD or word at point.
+Word may be of form: HyWikiWord#section with an optional #section.
+If no such page exists, return nil.
+
+If WORD is the symbol, 'range, rather than a string, and there is a
+HyWikiWord at point with an existing page, then return the tuple of
+values: (word word-start word-end).
+
+When using the word at point, a call to
+`hywiki-active-in-current-buffer-p' at point must return non-nil or
+this will return nil."
+ (setq hywiki--page-name word)
+ (if (or (stringp word)
+ (setq word (hywiki-word-at)))
+ (progn (setq word (hywiki-page-strip-section word))
+ (unless (hywiki-get-page word)
+ (setq word nil)))
+ (setq word nil))
+ (if (eq hywiki--page-name 'range)
+ (if (setq hywiki--range
+ (hproperty:char-property-range (point) 'face hywiki-word-face))
+ (list word (car hywiki--range) (cdr hywiki--range))
+ (list word nil nil))
+ word))
+
+(defun hywiki-page-strip-section (page-name)
+ "Return PAGE-NAME with any optional #section stripped off.
+If an empty string or not a string, return nil."
+ (when (and (stringp page-name) (not (string-empty-p page-name)))
+ (if (and (string-match hywiki-word-with-optional-section-exact-regexp
page-name)
+ (match-string-no-properties 2 page-name))
+ ;; Remove any #section suffix in PAGE-NAME.
+ (match-string-no-properties 1 page-name)
+ page-name)))
+
(defun hywiki-publish-to-html (&optional all-pages-flag)
"Publish/export updated HyWiki pages to html.
With an optional prefix arg, ALL-PAGES-FLAG, regenerate all html