branch: externals/hyperbole commit ea527fab08f655acf79ce246aa81e77168e4d66b Author: bw <r...@gnu.org> Commit: bw <r...@gnu.org>
hywiki fix bugs; hui-select fix narrowed defun selection hsys-org-link-at-p - Fix checks to ensure point is within any Org link when triggered. hywiki-tests--org-link-resolve - Fix to use full path of wikipage. hywiki-tests--org-link-export - Add (find-file wikipage) call to fix that relative directory setting in `hywiki-org-link-export' is set properly. kbd-key:act - Normalize 'key-series' prior to processing if not already done. Fixes bugs where SPC characters can be removed improperly if called with a non-normalized 'key-series'. hbut:is-p - Change to return the hbut symbol passed in, if any. hkey-at-hbut - Add this boolean to communicate between Smart Key predicates that point is at a Hyperbole button. hywiki-get-page-list - Add to return a list of HyWikiWords with existing pages. hywiki-page-read-new - Add. hywiki-find-page - Add to mirror 'hywiki-find-referent'. hui:menu-hywiki - Change 'EditPages' to 'EditPage' and from command 'hywiki-edirectory-edit' to 'hywiki-find-page'. Add new entry 'DiredHyWiki' with 'hywiki-edirectory-edit' command. hui-menu-hywiki - Rename 'Edit-HyWiki-Pages' to 'Dired-HyWiki-Pages'. Add new entry 'Find-HyWiki-Page' with command 'hywiki-find-page'. hash-map - Fix that always returned nil when using a lambda function. Second argument to 'push' call was wrong. It was 'key' and should be 'result'. hproperty:char-property-face-p - Add. hywiki-ignore-face-list - Add. hywiki-maybe-highlight-page-names, hywiki-highlight-word-get-range - Call above function and skip HyWikiWord highlighting if any face in 'hywiki-ignore-face-list' is found. hkey-alist - Make 'hui-select-thing' and 'hui-select-at-delimited-sexp-p' ignore delimiters in the middle of an hbut, e.g. when on closing paren of "(hyperbole)HyWiki", so that button activation is always consistent. hargs:search - Add to skip over backquoted search matches. hargs:delimited - Replace search calls with calls to `hargs:search'. This improves HyWikiWord highlighting when quoted delimiters are used. hkey-help - Print hbut attributes only when 'hkey-alist' 'hbut:at-p' clause triggers, not anytime an hbut actype attribute exists. hywiki-word-to-org-link - Ensure a valid link is always returned from a valid input. hywiki-org-link-resolve - Fix so pathname is expanded relative to 'hywiki-directory' since don't know the 'default-directory' of the caller. hywiki-maybe-highlight-page-names - Add missing 'save-match-data'. --- ChangeLog | 92 +++++++++++++++++++++++++++++++++++++ hact.el | 7 ++- hargs.el | 35 ++++++++++---- hasht.el | 10 ++-- hbut.el | 9 ++-- hib-kbd.el | 17 +++++-- hmouse-drv.el | 8 ++-- hproperty.el | 9 +++- hsys-org.el | 79 +++++++++++++++++--------------- hui-menu.el | 5 +- hui-mini.el | 8 ++-- hui-mouse.el | 26 ++++++++--- hui-select.el | 15 +++--- hywiki.el | 127 ++++++++++++++++++++++++++++++++++----------------- man/hyperbole.texi | 13 ++++-- test/hywiki-tests.el | 42 +++++++++-------- 16 files changed, 347 insertions(+), 155 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2b95b598b0..fce6b83e68 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,95 @@ +2025-08-29 Bob Weiner <r...@gnu.org> + +* hui-select.el (hui-select-set-region): Fix so selection of a whole + narrowed buffer performs the selection and is not treated as a whole + buffer selection. + +* hywiki.el (hywiki-word-to-org-link): Rewrite to minimize text in the + Org links created. Use 'hy:' protocol prefix. + (hywiki-org-link-resolve): Rename to 'hywiki-reference-to-referent'. + (hywiki-word-to-org-link): Rename to 'hywiki-reference-to-org-link'. + (hywiki-convert-words-to-org-links): Rename to + 'hywiki-references-to-org-links'. + test/hywiki-tests.el (hywiki-tests--convert-words-to-org-link): Rename to + 'hywiki-tests--references-to-org-link'. Fix to prefix Org HyWikiWord + Org link referents with 'hy:' protocol. + (hywiki-tests--org-link-resolve): Rename to + 'hywiki-tests--reference-to-referent'. + +* hsys-org.el (hsys-org-link-at-p): Fix checks to ensure point is within + any Org link when trigger. Was missing check that point is after start + of match, replace with call to 'hargs:delimited-p' to simplify the code. + (hsys-org-link-label-start-end): Add to fix Org link label + extraction. Call from 'hsys-org-link-at-p' when in 'org-mode' and use + custom code to get proper label when not. + +* test/hywiki-tests.el (hywiki-tests--org-link-resolve): Fix to use full path + of wikipage. + (hywiki-tests--org-link-export): Add (find-file wikipage) + call to fix that relative directory setting in `hywiki-org-link-export' is + set properly. + +* hib-kbd.el (kbd-key:act): Normalize 'key-series' prior to processing if not + already done. Fixes bugs where SPC characters can be removed improperly + if called with a non-normalized 'key-series'. + +* hui-select.el (hui-select-at-delimited-thing-p): Update doc string to say + that global 'hkey-value' is set to the function that selects the syntactic + thing at point. + hbut.el (hbut:is-p): Change to return the hbut symbol passed in, if any. + hact.el (actype:doc): Remove unneeded duplicate 'hbut:is-p' call. + hui-mouse.el (hkey-at-hbut): Add this boolean to communicate between Smart + Key predicates that point is at a Hyperbole button. + +* hywiki.el (hywiki-get-page-list): Add to return a list of HyWikiWords with + existing pages. Use 'hywiki-get-wikiword-list' to include existing WikiWords + with referents of all types, not just pages. + (hywiki-page-read-new): Add. + (hywiki-find-page): Add to mirror 'hywiki-find-referent'. + hui-mini.el (hui:menu-hywiki): Change 'EditPages' to 'EditPage' and from command + 'hywiki-edirectory-edit' to 'hywiki-find-page'. Add new entry 'DiredHyWiki' + with 'hywiki-edirectory-edit' command. +* hui-menu.el (hui-menu-hywiki): Rename 'Edit-HyWiki-Pages' to 'Dired-HyWiki-Pages'. + Add new entry 'Find-HyWiki-Page' with command 'hywiki-find-page'. + +* hasht.el (hash-map): Fix that always returned nil when using a lambda function. + Second argument to 'push' call was wrong. It was 'key' and should be 'result'. + +2025-08-28 Bob Weiner <r...@gnu.org> + +* hproperty.el (hproperty:char-property-face-p): Add. +* hywiki.el (hywiki-ignore-face-list): Add constant. + (hywiki-maybe-highlight-page-names, + hywiki-highlight-word-get-range): Call above function and skip + HyWikiWord highlighting if any face in 'hywiki-ignore-face-list' is found. + +* hui-mouse.el (hkey-alist): Make 'hui-select-thing' and + 'hui-select-at-delimited-sexp-p' ignore delimiters in the middle of an hbut, + e.g. when on closing paren of "(hyperbole)HyWiki", so that button activation + is always consistent. + +2025-08-27 Bob Weiner <r...@gnu.org> + +* hargs.el (hargs:search): Add to skip over backquoted search matches. + (hargs:delimited): Replace search calls with calls to `hargs:search'. + This improves HyWikiWord highlighting when quoted delimiters are used. + +* hmouse-drv.el (hkey-help): Print hbut attributes only when 'hkey-alist' + 'hbut:at-p' clause triggers, not anytime an hbut actype attribute exists. + Otherwise, can have hui-select-thing trigger via an Action Key press + but also display the hbut attributes that the delimited thing is within. + Then user can't tell what action will trigger at point. + +* hywiki.el (hywiki-word-to-org-link): Remove set of 'path' to nil when no + buffer-file-name or when it matches buffer-file-name without a dir. This + ensures a valid link is always returned from a valid input. + +2025-08-26 Bob Weiner <r...@gnu.org> + +* hywiki.el (hywiki-org-link-resolve): Fix so pathname is expanded relative + to 'hywiki-directory' since don't know the 'default-directory' of the + caller. + 2025-08-25 Bob Weiner <r...@gnu.org> * hywiki.el (hywiki-maybe-highlight-page-names): Add missing 'save-match-data' diff --git a/hact.el b/hact.el index 6771936938..e50190210f 100644 --- a/hact.el +++ b/hact.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 18-Sep-91 at 02:57:09 -;; Last-Mod: 27-Jul-25 at 16:39:01 by Bob Weiner +;; Last-Mod: 29-Aug-25 at 14:20:04 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -330,7 +330,7 @@ TYPE and TYPE-CATEGORY are both symbols. TYPE-CATEGORY must be one of (list 'function (cons 'lambda (cons param-list body))))) (defun action:kbd-macro (macro &optional repeat-count) - "Return Hyperbole action that execute a keyboard MACRO REPEAT-COUNT times." + "Return Hyperbole action that executes a keyboard MACRO REPEAT-COUNT times." (list 'execute-kbd-macro macro repeat-count)) (defun action:param-count (action) @@ -551,8 +551,7 @@ With optional FULL, returns full documentation string. Return nil when no documentation." (let* ((is-hbut (hbut:is-p but)) (act (if is-hbut - (and (hbut:is-p but) (or (hattr:get but 'action) - (hattr:get but 'actype))) + (or (hattr:get but 'action) (hattr:get but 'actype)) (let ((attrs (hattr:list but))) (or (plist-get attrs 'action) (when (plist-get attrs 'follow-link) diff --git a/hargs.el b/hargs.el index 726de96e47..5f14c7c2e4 100644 --- a/hargs.el +++ b/hargs.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 31-Oct-91 at 23:17:35 -;; Last-Mod: 6-Jul-25 at 15:28:05 by Bob Weiner +;; Last-Mod: 27-Aug-25 at 23:10:25 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -90,7 +90,7 @@ "Minibuffer content the last time a completions buffer was generated, or nil.") ;;; ************************************************************************ -;;; Private functions +;;; Public functions ;;; ************************************************************************ (defalias 'hargs:find-tag-default #'find-tag--default) @@ -151,8 +151,8 @@ normalized as a Hyperbole button key (no spaces)." (end-search-func (if end-regexp-flag 're-search-forward 'search-forward)) (count 0) first - start ;; excludes delimiter - end ;; excludes delimiter + start ;; excludes delimiter + end ;; excludes delimiter end-pos string-start-end) @@ -167,7 +167,7 @@ normalized as a Hyperbole button key (no spaces)." (beginning-of-line 0) ;; start of previous line (if (string-equal start-delim end-delim) (progn - (while (and (setq end-pos (funcall start-search-func start-delim limit t)) + (while (and (setq end-pos (hargs:search start-search-func start-delim limit t)) ;; Prevent infinite loop where regexp match does not ;; move end-pos forward, e.g. match to bol. (not (eq first end-pos)) @@ -178,7 +178,7 @@ normalized as a Hyperbole button key (no spaces)." ;; end delimiters that precede the current argument and are ;; therefore false matches, hence the search is limited to ;; prior to the original point. - (funcall end-search-func end-delim opoint t) + (hargs:search end-search-func end-delim opoint t) (setq count (1+ count))) (setq first (or first start) start nil)) @@ -200,7 +200,7 @@ normalized as a Hyperbole button key (no spaces)." ;; Use forward rather than reverse search here to perform greedy ;; searches when optional matches within a regexp. (while (and (<= (point) limit) - (setq end-pos (funcall start-search-func start-delim limit t)) + (setq end-pos (hargs:search start-search-func start-delim limit t)) ;; Prevent infinite loop where regexp match does not ;; move end-pos forward, e.g. match to bol. (not (eq start end-pos))) @@ -216,7 +216,7 @@ normalized as a Hyperbole button key (no spaces)." (forward-line 2) (setq limit (point)) (goto-char opoint) - (and (funcall end-search-func end-delim limit t) + (and (hargs:search end-search-func end-delim limit t) (setq end (match-beginning 0)))))) (when (and start end) @@ -501,6 +501,23 @@ Optional DEFAULT-PROMPT is used to describe default value." default) prompt)) +(defun hargs:search (func delim &optional bound noerror count) + "Call search FUNC for the next non-backslash-quoted instance of DELIM. +See `search-forward' doc string for use of the optional BOUND NOERROR and +COUNT args." + (let (result) + (while (and (setq result (funcall func delim bound noerror count)) + (save-excursion + ;; string is embedded within a doc string, except when + ;; the string starts with 2 backslashes or an MSWindows + ;; disk drive prefix, in which case the backslash is + ;; considered part of a pathname. + (save-match-data + (goto-char (match-beginning 0)) + ;; Ignore any backslash quoted match to `delim' + (= (or (preceding-char) 0) ?\\))))) + result)) + (defun hargs:select-event-window () "Select window, if any, that mouse was over during last event." (let ((window (posn-window (event-start last-command-event)))) @@ -555,7 +572,7 @@ that point is within is returned or nil if none." (t (save-excursion (up-list 1) (hargs:sexpression-p t)))))))) ;;; ************************************************************************ -;;; Public functions +;;; More Public functions ;;; ************************************************************************ (defun hargs:actype-get (actype &optional editing-flag) diff --git a/hasht.el b/hasht.el index b36d8774c7..af5b2576b5 100644 --- a/hasht.el +++ b/hasht.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 16-Mar-90 at 03:38:48 -;; Last-Mod: 26-Jan-25 at 18:30:30 by Bob Weiner +;; Last-Mod: 29-Aug-25 at 02:16:00 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -197,8 +197,7 @@ in reverse order of occurrence (they are prepended to the list). See hash-table)) (defun hash-map (func hash-table) - "Return list result of calling FUNC over each (<value> . <key>) in HASH-TABLE. -<key> is a symbol. + "Return the list from calling FUNC on (<value> . <string-key>) in HASH-TABLE. If FUNC is in \\='(cdr key second symbol-name), then return all <key>s as strings. If FUNC is in \\='(car value first symbol-value), then @@ -213,10 +212,9 @@ return all <value>s." (maphash (lambda (key value) (push (funcall func (cons value (symbol-name key))) - key) - result) + result)) hash-table) - result)))) + (nreverse result))))) (defun hash-merge (&rest hash-tables) "Merge any number of HASH-TABLES. Return resultant hash table. diff --git a/hbut.el b/hbut.el index 1c7435707d..bf4b675db9 100644 --- a/hbut.el +++ b/hbut.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 18-Sep-91 at 02:57:09 -;; Last-Mod: 17-Aug-25 at 00:25:01 by Bob Weiner +;; Last-Mod: 29-Aug-25 at 10:36:35 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1346,9 +1346,10 @@ is given." (defalias 'hbut:help #'hbut:report) (defun hbut:is-p (object) - "Return non-nil if OBJECT is a symbol representing a Hyperbole button." - (when (symbolp object) - (hattr:get object 'categ))) + "Return the symbol if OBJECT is a symbol representing a Hyperbole button." + (and (symbolp object) + (hattr:get object 'categ) + object)) (defun hbut:key (hbut) "Return the key for Hyperbole button symbol HBUT." diff --git a/hib-kbd.el b/hib-kbd.el index dc19509f8c..9c58fc64b4 100644 --- a/hib-kbd.el +++ b/hib-kbd.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 22-Nov-91 at 01:37:57 -;; Last-Mod: 25-Feb-25 at 02:14:39 by Bob Weiner +;; Last-Mod: 29-Aug-25 at 12:52:43 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -171,6 +171,12 @@ Any key sequence within the series must be a string of one of the following: Return t if KEY-SERIES appears valid, else nil." (interactive "sKey series to execute (no {}): ") (setq current-prefix-arg nil) ;; Execution of the key-series may set it. + + ;; Normalize `key-series' prior to processing if not already done + (unless (hypb:object-p key-series) + (when (stringp key-series) + (setq key-series (kbd-key:normalize key-series)))) + (let ((binding (kbd-key:binding key-series))) (cond ((null binding) (if (kbd-key:special-sequence-p key-series) @@ -199,9 +205,9 @@ Return t if KEY-SERIES is a valid key series that is executed, else nil." (if (memq (key-binding [?\M-x]) '(execute-extended-command counsel-M-x)) (kbd-key:key-series-to-events key-series) ;; Disable helm while processing M-x commands; helm - ;; gobbles final RET key. Counsel works without modification. + ;; gobbles final RET key. Counsel and Vertico work without modification. (let ((orig-binding (global-key-binding [?\M-x])) - (helm-flag (when (boundp 'helm-mode) helm-mode)) + (helm-flag (bound-and-true-p helm-mode)) (minibuffer-completion-confirm)) (unwind-protect (progn @@ -220,8 +226,9 @@ Restore \\`M-x' binding to ORIG-M-X-BINDING." (defun kbd-key:key-series-to-events (key-series) "Insert the KEY-SERIES as a series of keyboard events. -The events are inserted into Emacs unread input stream. Emacs -then executes them when its command-loop regains control." +The events are inserted into Emacs `unread-command-events' +stream. Emacs then executes them when its command-loop regains +control." (setq unread-command-events (nconc unread-command-events ;; Cons t here to ensure events ;; are added to command-keys. diff --git a/hmouse-drv.el b/hmouse-drv.el index 397fd48384..722201eb7a 100644 --- a/hmouse-drv.el +++ b/hmouse-drv.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 04-Feb-90 -;; Last-Mod: 17-Aug-25 at 00:03:53 by Bob Weiner +;; Last-Mod: 27-Aug-25 at 10:40:25 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1123,7 +1123,8 @@ documentation is found." (hypb:error "(Hyperbole): `%s' predicate left point at %s and failed to restore it to %s" pred (point) pred-point))) (set-marker pred-point nil)) (if pred-value - (setq call (if assisting (cdr (cdr hkey-form)) + (setq call (if assisting + (cddr hkey-form) (cadr hkey-form)) cmd-sym (if (eq (car call) #'funcall) (cadr call) @@ -1171,8 +1172,7 @@ documentation is found." (if mouse-flag "Mouse " ""))) ;; Print Hyperbole button attributes - (when (or (memq cmd-sym '(hui:hbut-act hui:hbut-help)) - (hattr:get 'hbut:current 'actype)) + (when (memq cmd-sym '(hui:hbut-act hui:hbut-help)) (let* ((actype (or (actype:elisp-symbol (hattr:get 'hbut:current 'actype)) (hattr:get 'hbut:current 'actype))) ;; (lbl-key (hattr:get 'hbut:current 'lbl-key)) diff --git a/hproperty.el b/hproperty.el index 01fec682df..757da76fcd 100644 --- a/hproperty.el +++ b/hproperty.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 21-Aug-92 -;; Last-Mod: 6-Jul-25 at 23:45:41 by Bob Weiner +;; Last-Mod: 28-Aug-25 at 14:58:04 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -371,6 +371,13 @@ See `hproperty:but-get'." (and (listp val) (memq value val))) value))) +(defun hproperty:char-property-face-p (pos face-list) + "At POS, skip HyWikiWord highlighting if find any face in FACE-LIST. +Return non-nil in any such case, else nil." + (save-excursion + (goto-char pos) + (seq-intersection (face-at-point nil t) face-list #'eq))) + (defun hproperty:char-property-start (pos property value) "From POS, return the start of text PROPERTY with VALUE overlapping POS. Otherwise, return nil. Value must be a symbol." diff --git a/hsys-org.el b/hsys-org.el index 12324dfa80..11a6c58f69 100644 --- a/hsys-org.el +++ b/hsys-org.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 2-Jul-16 at 14:54:14 -;; Last-Mod: 31-May-25 at 15:35:55 by Mats Lidell +;; Last-Mod: 29-Aug-25 at 18:38:32 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -31,6 +31,7 @@ ;;; ************************************************************************ (eval-when-compile (require 'hmouse-drv)) +(require 'hargs) ;; for `hargs:delimited-p' (require 'hproperty) ;; requires 'hbut (require 'hsys-consult) (require 'hypb) @@ -505,49 +506,55 @@ Match to all todos if `keyword' is nil or the empty string." (defun hsys-org-link-at-p () "Return (start . end) iff point is on an Org mode link, else nil. -Start and end are the buffer positions of the label that point is on -delimited by square brackets. +Start and end are the buffer positions of the label of the link. This +is either the optional description or if none, then the referent, i.e. +either [[referent][description]] or [[referent]]. Ignore [[hy:HyWiki]] buttons and return nil (handle these as implicit buttons). Assume caller has already checked that the current buffer is in `org-mode' or is looking for an Org link in a non-Org buffer type." (unless (or (smart-eolp) (smart-eobp)) - (if (derived-mode-p 'org-mode) - (let* ((org-plist (hsys-org-thing-at-p)) - (type (plist-get org-plist :type)) - label-start-end) - (when (eq type 'link) - (save-match-data - ;; If this Org link matches a potential HyWiki word, ignore it. - (when (not (and (fboundp 'hywiki-word-at) (hywiki-word-at))) - (if (setq label-start-end (ibut:label-p t "[" "]" t)) - (cons (nth 1 label-start-end) (nth 2 label-start-end)) - t))))) - ;; non-Org mode (can't call org-element (which - ;; hsys-org-thing-at-p calls) outside of Org mode - (when (bound-and-true-p org-link-bracket-re) - (let ((pos (point))) - (when (save-excursion - (or - ;; Check if point is inside a link - (and (re-search-backward org-link-bracket-re - (line-beginning-position) t) - (> pos (point)) - (< pos (match-end 0))) - ;; If not found before, check if we're in the middle of a link - (and (forward-line 0) - (re-search-forward org-link-bracket-re - (line-end-position 2) t) - (> (point) pos) - (< pos (match-end 0))))) + (let (label-start-end) + (if (derived-mode-p 'org-mode) + ;; Must be in `org-mode' to use `org-element-property' + (when (org-element-property :raw-link (org-element-context)) + ;; At an Org link (save-match-data ;; If this Org link matches a potential HyWiki word, ignore it. - (when (not (and (fboundp 'hywiki-word-at) (hywiki-word-at))) - (let ((label-start-end (ibut:label-p t "[" "]" t))) - (if label-start-end - (cons (nth 1 label-start-end) (nth 2 label-start-end)) - t)))))))))) + (when (and (not (and (fboundp 'hywiki-word-at) (hywiki-word-at))) + (setq label-start-end (hsys-org-link-label-start-end))) + (cons (nth 1 label-start-end) (nth 2 label-start-end))))) + ;; non-Org mode (can't call org-element (which + ;; hsys-org-thing-at-p calls) outside of Org mode. + ;; Check if point is inside a link + (save-match-data + ;; If any Org link matches a potential HyWiki word, ignore it. + (when (and (not (and (fboundp 'hywiki-word-at) (hywiki-word-at))) + (setq label-start-end (hargs:delimited "[[" "]]" nil nil t))) + (let* ((start (nth 1 label-start-end)) + (end (nth 2 label-start-end)) + (label (buffer-substring-no-properties start end))) + (when (string-match "][" label) + (setq start (match-end 0))) + (cons start end)))))))) + +(defun hsys-org-link-label-start-end () + "With point on an Org link, return the list of (<label> <start> <end>), else nil. +<label> is either the optional link description or the link +referent. <start> and <end> are buffer positions where <label> +starts and ends, excludes delimiters." + (let ((thing (org-element-context))) + (when thing + (let ((ol-desc-start (org-element-property :contents-begin thing)) + (ol-desc-end (org-element-property :contents-end thing))) + (if (and ol-desc-start ol-desc-end) + (list (buffer-substring-no-properties ol-desc-start ol-desc-end) + ol-desc-start ol-desc-end) + (let ((ol-referent (org-element-property :raw-link thing)) + (ol-referent-start (+ (org-element-property :begin thing) 2)) + (ol-referent-end (- (org-element-property :end thing) 2))) + (list ol-referent ol-referent-start ol-referent-end))))))) ;; Assume caller has already checked that the current buffer is in org-mode. (defun hsys-org-heading-at-p (&optional _) diff --git a/hui-menu.el b/hui-menu.el index c59cf6986c..630ffaa051 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: 10-Aug-25 at 14:52:00 by Bob Weiner +;; Last-Mod: 29-Aug-25 at 03:45:17 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -308,7 +308,8 @@ Return t if cutoff, else nil." "----" ["Activate-HyWiki-Word" hywiki-word-activate t] ["Create-HyWiki-Word" hywiki-word-create-and-display t] - ["Edit-HyWiki-Pages" hywiki-directory-edit t] + ["Dired-HyWiki-Pages" hywiki-directory-edit t] + ["Find-HyWiki-Page" hywiki-find-page t] ["Find-HyWiki-Referent" hywiki-find-referent t] (when (fboundp 'consult-grep) ;; allow for autoloading ["Grep-Consult-Pages" hywiki-consult-grep t]) diff --git a/hui-mini.el b/hui-mini.el index aaf9e0442e..490b4044ad 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: 10-Aug-25 at 14:52:15 by Bob Weiner +;; Last-Mod: 29-Aug-25 at 03:49:50 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1038,10 +1038,12 @@ support underlined faces as well." "Create and display page for HyWikiWord at point or when none, emulate a press of a Smart Key.") '("Create" hywiki-word-create-and-display "Create and display a new or existing HyWikiWord referent, prompting with any existing referent names.") - '("EditPages" hywiki-directory-edit + '("DiredHyWiki" hywiki-directory-edit "Display and edit HyWiki directory.") + '("EditPage" hywiki-find-page + "Prompt with completion for and display a HyWikiWord page.") '("FindReferent" hywiki-find-referent - "Prompt with completion for and display a HyWikiWord referent.") + "Prompt with completion for and display any kind of HyWikiWord referent.") (when (fboundp 'consult-grep) ;; allow for autoloading '("GrepConsult" hywiki-consult-grep "Grep over HyWiki pages with interactive consult-grep.")) diff --git a/hui-mouse.el b/hui-mouse.el index f48a3b5e53..a4deb456ee 100644 --- a/hui-mouse.el +++ b/hui-mouse.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 04-Feb-89 -;; Last-Mod: 16-Aug-25 at 13:20:13 by Bob Weiner +;; Last-Mod: 29-Aug-25 at 11:03:18 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -231,6 +231,10 @@ Its default value is `smart-scroll-down'. To disable it, set it to ;;; Hyperbole context-sensitive keys dispatch table ;;; ************************************************************************ +(defvar hkey-at-hbut nil + "Non-nil communicates between Smart Key predicates that point is at a Hyperbole button. +The button's attributes are stored in the symbol, `hbut:current'.") + (defvar hkey-value nil "Communicates a value between a Smart Key predicate and its actions.") @@ -338,8 +342,13 @@ Its default value is `smart-scroll-down'. To disable it, set it to ;; Select or select-and-kill a markup pair (e.g. hmtl tags), list, ;; array/vector, set, function, comment or string that begins or ;; ends at point. For markup pairs, point must be at the first - ;; character of the opening or closing tag. - ((hui-select-at-delimited-thing-p) + ;; character of the opening or closing tag. Ignore delimiters in + ;; the middle of a Hyperbole button. + ((and (if (setq hkey-at-hbut (hbut:at-p)) + (or (eq (point) (hattr:get 'hbut:current 'lbl-end)) + (eq (point) (hattr:get 'hbut:current 'name-end))) + t) + (hui-select-at-delimited-thing-p)) . ((hui-select-thing) . (progn (hui-select-thing) (hmouse-kill-region)))) ;; @@ -347,13 +356,18 @@ Its default value is `smart-scroll-down'. To disable it, set it to ;; sexpression, mark it for editing or kill it (assist key). This ;; only handles the special case where point is just after the ;; closing delimiter and not at an end-of-line, so this may be - ;; removed someday. - ((hui-select-at-delimited-sexp-p) + ;; removed someday. Ignore delimiters in the middle of a + ;; Hyperbole button. + ((and (if hkey-at-hbut + (or (eq (point) (hattr:get 'hbut:current 'lbl-end)) + (eq (point) (hattr:get 'hbut:current 'name-end))) + t) + (hui-select-at-delimited-sexp-p)) . ((hui-select-mark-delimited-sexp) . (progn (hui-select-mark-delimited-sexp) (hmouse-kill-region)))) ;; ;; If on a Hyperbole button, perform action or give help. - ((hbut:at-p) + (hkey-at-hbut . ((hui:hbut-act 'hbut:current) . (hui:hbut-help 'hbut:current))) ;; ;; This potentially displays a Smart Menu. diff --git a/hui-select.el b/hui-select.el index ce370bd42c..265e47a3ef 100644 --- a/hui-select.el +++ b/hui-select.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 19-Oct-96 at 02:25:27 -;; Last-Mod: 10-Aug-25 at 21:26:00 by Mats Lidell +;; Last-Mod: 29-Aug-25 at 21:52:32 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -935,11 +935,12 @@ If an error occurs during syntax scanning, return nil." (defun hui-select-at-delimited-thing-p () "Return non-nil if point is at a delimited thing, else nil. +Ignore any match if on an Emacs button and instead return nil. + A delimited thing is a markup pair, list, array/vector, set, comment or string. The non-nil value returned is the function to -call to select that syntactic unit. - -Ignore any match if on an Emacs button and instead return nil." +call to select that syntactic unit, if any. The global `hkey-value' +is set to this value." (unless (button-at (point)) (setq hkey-value (hui-select-delimited-thing-call #'hui-select-at-p)) (cond ((eq hkey-value 'hui-select-punctuation) @@ -1106,9 +1107,9 @@ Return the updated cons cell." (setcdr hui-select-old-region nil)) (if (and (not (memq hui-select-previous '(buffer markup-pair))) (integerp beginning) (integerp end) - (= beginning (point-min)) (= end (point-max))) - ;; If we selected the whole buffer and not matching a markup-pair, - ;; make sure that 'thing' type is 'buffer'. + (= beginning 1) (= end (1+ (buffer-size)))) + ;; If we selected the whole widened buffer and not matching a + ;; markup-pair, make sure that 'thing' type is 'buffer'. nil hui-select-region)) diff --git a/hywiki.el b/hywiki.el index c169383523..0459311860 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: 26-Aug-25 at 10:46:27 by Bob Weiner +;; Last-Mod: 29-Aug-25 at 19:39:57 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -149,7 +149,7 @@ (require 'hui-mini) ;; For `hui:menu-act' (require 'hypb) ;; Requires `seq' (require 'outline) ;; For `outline-mode-syntax-table' -(require 'seq) ;; For 'seq-contains-p' and 'seq-difference' +(require 'seq) ;; For `seq-contains-p', `seq-difference' and `seq-intersection' (require 'subr-x) ;; For `string-remove-prefix' (require 'thingatpt) @@ -291,6 +291,9 @@ Use nil for no HyWiki mode indicator." :type 'string :group 'hyperbole-hywiki) +(defconst hywiki-ignore-face-list '(button hbut-face hbut-item-face ibut-face) + "Skip highlighting of HyWikiWords in regions which have any of these faces.") + (defvar hywiki-allow-suffix-referent-types '(page path-link) "List of referent type symbols that support # and :L line number suffixes.") @@ -1422,7 +1425,7 @@ Use `hywiki-get-referent' to determine whether a HyWiki page exists." "Display an optional WIKIWORD page and return the page file. Use `hywiki-display-page-function' to display the page. -If FILE is provided, it includes any #section from the WIKIWORD. +If FILE-NAME is provided, it includes any #section from the WIKIWORD. If WIKIWORD is omitted or nil and `hywiki-display-page-function' is an interactive function, it is called interactively and prompts for @@ -1529,21 +1532,19 @@ omit any trailing colon and space in the prompt." "Grep HyWiki dir headlines" "Grep HyWiki dir"))))) -(defun hywiki-convert-words-to-org-links () +(defun hywiki-references-to-org-links () "Convert all highlighted HyWiki words in current buffer to Org links. -Use when publishing a HyWiki file to another format, e.g. html. +Org publishing is then used to convert HyWiki files to other formats such +as html. -For example, the link: +For example, the reference: \"WikiWord#Multi-Word Section\" is converted to: \"[[hy:WikiWord#Multi-Word Section]]\". If the reference is within the WikiWord page to which it refers, it simplifies to: - \"[[Multi-Word Section]]\". - -The finalized Org link is then exported to html format by the Org -publish process." + \"[[Multi-Word Section]]\"." (barf-if-buffer-read-only) ;; Need to be explicit about the region here so does not use markers ;; from a region pointing to another buffer @@ -1562,10 +1563,10 @@ publish process." (delete-region (overlay-start overlay) (overlay-end overlay)) (delete-overlay overlay) - (if (setq org-link (hywiki-word-to-org-link wikiword-and-section nil)) + (if (setq org-link (hywiki-reference-to-org-link wikiword-and-section nil)) (insert org-link) (message - "(hywiki-convert-words-to-org-links): \"%s\" in \"%s\" produced nil org link output" + "(hywiki-references-to-org-links): \"%s\" in \"%s\" produced nil org link output" wikiword-and-section (buffer-name))) (when make-index (when (string-match (concat hywiki-org-link-type ":") @@ -1573,12 +1574,12 @@ publish process." (setq wikiword (substring wikiword-and-section (match-end 0)))) (insert "\n#+INDEX: " wikiword "\n")))))) -(defun hywiki-word-to-org-link (link &optional description) - "From a HyWikiWord reference LINK with an optional DESCRIPTION to an Org link." -;; \"[[file:<hywiki-directory>/WikiWord.org::Multi-Word Section][WikiWord#Multi-Word Section]]\". - (let ((resolved-link (hywiki-org-link-resolve link :full-data))) - (when (stringp (car resolved-link)) - (let* ((path-word-suffix resolved-link) +(defun hywiki-reference-to-org-link (reference &optional description) + "Convert a HyWiki REFERENCE and an optional DESCRIPTION to an Org link." + ;; \"[[file:<hywiki-directory>/WikiWord.org::Multi-Word Section][WikiWord#Multi-Word Section]]\". + (let ((referent (hywiki-parse-reference reference :full-data))) + (when (stringp (car referent)) + (let* ((path-word-suffix referent) (path (file-relative-name (nth 0 path-word-suffix))) (path-stem (when path (file-name-sans-extension path))) @@ -1592,9 +1593,9 @@ publish process." (unless (and suffix (not (string-empty-p suffix))) (setq suffix nil)) (setq suffix-no-hashmark (when suffix (substring suffix 1))) - (when (or (not buffer-file-name) - (string-equal path (file-name-nondirectory buffer-file-name))) - (setq path nil)) + ;; (when (or (not buffer-file-name) + ;; (string-equal path (file-name-nondirectory buffer-file-name))) + ;; (setq path nil)) (cond (desc (if path (if suffix @@ -1686,6 +1687,27 @@ Use `time-since' to see the time in seconds since this modification time." (hywiki-directory-set-checksum)) +;;;###autoload +(defun hywiki-find-page (&optional wikiword) + "Display optional HyWiki WIKIWORD page or if nil, use current buffer. +If called interactively, use the WIKIWORD at point or if none, prompt for +an existing or new one. + +Return the absolute path to the file of the page if successfully found +or nil otherwise. + +By default, create any non-existent page. When not in batch +mode, if this is the first HyWiki page in `hywiki-directory', +prompt to create if non-existent. After successfully finding a +page and reading it into a buffer, run +`hywiki-display-page-hook'. + +After successfully finding a page, run `hywiki-find-page-hook'." + (interactive (list (hywiki-page-read-new "Add/Edit HyWikiWord Page: "))) + (let ((page-file (hywiki-display-page wikiword))) + (run-hooks 'hywiki-find-page-hook) + page-file)) + ;;;###autoload (defun hywiki-find-referent (&optional wikiword prompt-flag) "Display optional HyWiki WIKIWORD referent or if nil, use current buffer. @@ -2412,8 +2434,9 @@ value of `hywiki-word-highlight-flag' is changed." (setq hywiki--end (point)) ;; Don't highlight current-page matches unless they ;; include a #section. - (unless (string-equal hywiki--current-page - (buffer-substring-no-properties hywiki--start hywiki--end)) + (unless (or (hproperty:char-property-face-p hywiki--start hywiki-ignore-face-list) + (string-equal hywiki--current-page + (buffer-substring-no-properties hywiki--start hywiki--end))) (hproperty:but-add hywiki--start hywiki--end hywiki-word-face)))))))))) ;; Disable dehighlighting of HyWikiWords between [] and <>. @@ -2526,6 +2549,13 @@ These must end with `hywiki-file-suffix'." hywiki-directory nil (concat "^" hywiki-word-regexp (regexp-quote hywiki-file-suffix) "$"))))) +(defun hywiki-get-page-list () + "Return the list of HyWikiWords with existing pages." + (delq nil (hash-map (lambda (referent-type) + (when (eq (caar referent-type) 'page) + (cdr referent-type))) + (hywiki-get-referent-hasht)))) + (defun hywiki-get-referent (wikiword) "Return the referent of HyWiki WIKIWORD or nil if it does not exist. If it is a pathname, expand it relative to `hywiki-directory'." @@ -2592,7 +2622,7 @@ least partially overlap that region." (hywiki--get-all-references #'hproperty:but-get-all-positions start end)) (defun hywiki-get-wikiword-list () - "Return a list of the HyWiki page names." + "Return the list of existing HyWikiWords." (hash-map #'cdr (hywiki-get-referent-hasht))) (defun hywiki-get-plural-wikiword (wikiword) @@ -2798,7 +2828,7 @@ This is done automatically by loading HyWiki." (when (and (derived-mode-p 'org-mode) (not (string= (hywiki--sitemap-file) (buffer-file-name))) (hyperb:stack-frame '(org-export-copy-buffer))) - (hywiki-convert-words-to-org-links) + (hywiki-references-to-org-links) (hywiki-org-maybe-add-title))) (defun hywiki-org-get-publish-project () @@ -2828,7 +2858,7 @@ If not found, set it up and return the new project properties." "Export a HyWikiWord Org-format `hy:' link to various formats. The LINK, DESCRIPTION, and FORMAT are provided by the export backend." - (let* ((path-word-suffix (hywiki-org-link-resolve link :full-data)) + (let* ((path-word-suffix (hywiki-reference-to-referent link :full-data)) (path (when path-word-suffix (file-relative-name (nth 0 path-word-suffix)))) (path-stem (when path @@ -2856,30 +2886,32 @@ backend." (_ path)) link))) -(defun hywiki-org-link-resolve (link &optional full-data) - "Resolve HyWikiWord LINK to its referent file or other type of referent. +(defun hywiki-parse-reference (reference &optional full-data) + "Resolve HyWikiWord REFERENCE to its referent file or other type of referent. If the referent is not a file type, return (referent-type . referent-value). Otherwise: -Link may end with optional suffix of the form: (#|::)section:Lnum:Cnum. +Reference may end with optional suffix of the form: (#|::)section:Lnum:Cnum. With optional FULL-DATA non-nil, return a list in the form of (pathname -word suffix); otherwise, with a section, return pathname::section, with -just line and optionally column numbers, return pathname:Lnum:Cnum and -without any suffix, return just the pathname." - (when (stringp link) - (when (string-match (concat "\\`" hywiki-org-link-type ":") link) - ;; Remove hy: link prefix - (setq link (substring link (match-end 0)))) - (let* ((suffix-type (and (string-match hywiki-word-suffix-regexp link) - (match-string 1 link))) - (suffix (and suffix-type (match-string 2 link))) +hywikiword suffix); otherwise: + - with a section, return pathname::section; + - with just line and optionally column numbers, return pathname:Lnum:Cnum + - and without any suffix, return just the pathname." + (when (stringp reference) + (when (string-match (concat "\\`" hywiki-org-link-type ":") reference) + ;; Remove hy: reference prefix + (setq reference (substring reference (match-end 0)))) + (let* ((suffix-type (and (string-match hywiki-word-suffix-regexp reference) + (match-string 1 reference))) + (suffix (and suffix-type (match-string 2 reference))) (word (if (and suffix (not (string-empty-p suffix))) - (substring link 0 (match-beginning 0)) - link)) + (substring reference 0 (match-beginning 0)) + reference)) (referent (and word (hywiki-get-referent word))) (referent-type (car referent)) (pathname (when (memq referent-type '(page path-link)) - (cdr referent)))) + (expand-file-name (or (cdr referent) "") + hywiki-directory)))) (if (stringp pathname) (cond (full-data @@ -3326,7 +3358,8 @@ non-nil or this will return nil." (when (and wikiword start end (not (hproperty:but-get start 'face hywiki-word-face)) (hywiki-referent-exists-p wikiword)) - (hproperty:but-add start end hywiki-word-face)) + (unless (hproperty:char-property-face-p start hywiki-ignore-face-list) + (hproperty:but-add start end hywiki-word-face))) (list wikiword start end))) (defun hywiki-highlight-word-move-range () @@ -3444,6 +3477,14 @@ If point is on one, press RET immediately to use that one." (hywiki-get-referent-hasht) nil nil nil nil (hywiki-word-at-point)))) +(defun hywiki-page-read-new (&optional prompt) + "Prompt with completion for and return an existing/new HyWikiWord with a page. +If point is on one, press RET immediately to use that one." + (let ((completion-ignore-case t)) + (completing-read (if (stringp prompt) prompt "HyWikiWord page: ") + (hywiki-get-page-list) + nil nil nil nil (hywiki-word-at-point)))) + (defun hywiki-word-highlight-flag-changed (symbol set-to-value operation _where) "Watch function for variable ``hywiki-word-highlight-flag'. Function is called with 4 arguments: (SYMBOL SET-TO-VALUE OPERATION WHERE). diff --git a/man/hyperbole.texi b/man/hyperbole.texi index e3049beec1..5c97c49c72 100644 --- a/man/hyperbole.texi +++ b/man/hyperbole.texi @@ -7,7 +7,7 @@ @c Author: Bob Weiner @c @c Orig-Date: 6-Nov-91 at 11:18:03 -@c Last-Mod: 10-Aug-25 at 18:35:50 by Bob Weiner +@c Last-Mod: 29-Aug-25 at 03:42:13 by Bob Weiner @c %**start of header (This is for running Texinfo on a region.) @setfilename hyperbole.info @@ -4691,7 +4691,7 @@ It looks like this: @smallexample @noindent -HyWiki> Act Create EditPages FindPage GrepConsult Help Info Link ModeToggle Org-M-RET/ Publish TagFind WikiWordConsult +HyWiki> Act Create DiredHyWiki EditPage FindReferent GrepConsult Help Info Link ModeToggle Org-M-RET/ Publish TagFind WikiWordConsult @end smallexample @noindent @@ -4723,18 +4723,21 @@ aid in new naming. @cindex HyWiki dired @cindex HyWiki treemacs @cindex HyWiki edit pages -@item EditPages +@item DiredHyWiki Display and edit HyWiki pages in current @code{hywiki-directory}. Use @code{dired} unless @code{action-key-modeline-buffer-id-function} is set to @code{smart-treemacs-modeline}, then use the @code{treemacs} package. - @cindex HyWiki find/edit a page -@item FindPage +@item EditPage Prompt with completion for and find a HyWiki page, typically editable. If the page is already in a buffer, point is left unchanged. +@cindex HyWiki find/edit a referent +@item FindReferent +Prompt with completion for and find any kind of HyWiki referent. + @cindex HyWiki interactive grep @findex hywiki-consult-grep @item GrepConsult diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el index e27043b5ed..a6e8c3e799 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: 20-Aug-25 at 00:01:57 by Bob Weiner +;; Last-Mod: 29-Aug-25 at 19:42:51 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -169,7 +169,7 @@ Assume no nesting of braces, nor any quoting of braces." (run-hooks 'pre-command-hook) ;; `command-execute' runs only `post-self-insert-hook' since ;; this is run during the command; pre- and post-command hooks - ;; must be manually run. + ;; therefore are run manually. (command-execute this-command) (run-hooks 'post-command-hook))))) @@ -805,8 +805,8 @@ Both mod-time and checksum must be changed for a test to return true." (hy-delete-files-and-buffers (list wikipage)) (hy-delete-dir-and-buffer hywiki-directory))))) -(ert-deftest hywiki-tests--convert-words-to-org-link () - "Verify `hywiki-convert-words-to-org-links' converts WikiWords to org links." +(ert-deftest hywiki-tests--references-to-org-link () + "Verify `hywiki-references-to-org-links' converts WikiWords to org links." (skip-unless (not noninteractive)) (hywiki-tests--preserve-hywiki-mode (let* ((hywiki-directory (make-temp-file "hywiki" t)) @@ -815,18 +815,19 @@ Both mod-time and checksum must be changed for a test to return true." (progn (hywiki-mode 1) (with-temp-buffer - (insert "WikiWord") + (setq default-directory hywiki-directory) + (insert "WikiWord#section:L2:C4") (hywiki-tests--command-execute #'self-insert-command 1 ? ) (goto-char 4) - (hywiki-convert-words-to-org-links) - (should (string= "[[WikiWord]] " + (hywiki-references-to-org-links) + (should (string= "[[hy:WikiWord#section:L2:C4]] " (buffer-substring-no-properties (point-min) (point-max))))) (with-temp-buffer (insert "WikiWor") (hywiki-tests--command-execute #'self-insert-command 1 ?d) (goto-char 4) - (hywiki-convert-words-to-org-links) - (should (string= "[[WikiWord]]" + (hywiki-references-to-org-links) + (should (string= "[[hy:WikiWord]]" (buffer-substring-no-properties (point-min) (point-max)))))) (hy-delete-file-and-buffer wikipage) (hy-delete-dir-and-buffer hywiki-directory))))) @@ -867,20 +868,20 @@ Both mod-time and checksum must be changed for a test to return true." (mocklet (((hywiki-org-set-publish-project) => '("project"))) (should (equal '("project") (hywiki-org-get-publish-project)))))) -(ert-deftest hywiki-tests--org-link-resolve () - "Verify `hywiki-org-link-resolve' resolves a link to page." - (should-not (hywiki-org-link-resolve 88)) ; Number - (should-not (hywiki-org-link-resolve '("string"))) ; List +(ert-deftest hywiki-tests--reference-to-referent () + "Verify `hywiki-reference-to-referent' resolves a reference to a referent." + (should-not (hywiki-reference-to-referent 88)) ; Number + (should-not (hywiki-reference-to-referent '("string"))) ; List (let* ((hywiki-directory (make-temp-file "hywiki" t)) (wikipage (cdr (hywiki-add-page "WikiWord"))) (filename (when wikipage (file-name-nondirectory wikipage)))) (unwind-protect (progn - (should-not (hywiki-org-link-resolve "NoWikiWord")) - (should (when filename (string= filename (hywiki-org-link-resolve "WikiWord")))) - (should (when filename (string= filename (hywiki-org-link-resolve "hy:WikiWord")))) - (should (when filename (string= (concat filename "::section") - (hywiki-org-link-resolve "WikiWord#section"))))) + (should-not (hywiki-reference-to-referent "NoWikiWord")) + (should (when wikipage (string= wikipage (hywiki-reference-to-referent "WikiWord")))) + (should (when wikipage (string= wikipage (hywiki-reference-to-referent "hy:WikiWord")))) + (should (when wikipage (string= (concat wikipage "::section") + (hywiki-reference-to-referent "WikiWord#section"))))) (hy-delete-file-and-buffer wikipage) (hy-delete-dir-and-buffer hywiki-directory)))) @@ -892,6 +893,7 @@ Both mod-time and checksum must be changed for a test to return true." (filename-stem (when filename (file-name-sans-extension filename)))) (unwind-protect (progn + (find-file wikipage) (should (string-match-p (format "\\[hy\\] <doc:.*%s>" filename) (hywiki-org-link-export "WikiWord" "doc" 'ascii))) @@ -1324,12 +1326,12 @@ named WikiReferent with a non-page referent type." (hywiki-add-find wiki-word-non-page))) (ert-deftest hywiki-tests--save-referent-find-use-menu () - "Verify saving and loading a referent find works using Hyperbole's menu.." + "Verify saving and loading a referent find works using Hyperbole's menu." (skip-unless (not noninteractive)) ;; (skip-unless (not (version< emacs-version "29"))) ;; Fails on 28!? (hywiki-tests--referent-test (cons 'find #'hywiki-word-grep) - (should (hact 'kbd-key "C-u C-h hhc WikiReferent RET f hywikiword RET")) + (should (hact 'kbd-key "C-u C-h hhc WikiReferent RET f RET")) (hy-test-helpers:consume-input-events))) ;; Global-button