Skip to content

Commit d0e7092

Browse files
committed
hywiki.el - Fix hywiki-display-* functions to all take ref values
test/hywiki-tests.el (hywiki-tests--add-activity, hywiki-tests--add-org-roam-node): Change 'require' to 'hypb:require-package' so prompt user to install package when needed.
1 parent db61733 commit d0e7092

File tree

3 files changed

+56
-56
lines changed

3 files changed

+56
-56
lines changed

ChangeLog

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
2024-12-27 Bob Weiner <[email protected]>
22

3+
* test/hywiki-tests.el (hywiki-tests--add-activity,
4+
hywiki-tests--add-org-roam-node): Change 'require'
5+
to 'hypb:require-package' so prompt user to install package when needed.
6+
7+
* hywiki.el (hywiki-word-read, hywiki-word-read-new): Fix by replacing call
8+
to 'hywiki-get-wikiwords-obarray' with 'hywiki-get-referent-hasht'.
9+
(hywiki-get-wikiwords-obarray): Remove, no longer used.
10+
(hywiki-display-*): Fix to take referent-value rather than referent
11+
since already know the type when such functions are called.
12+
313
* hywiki.el (hywiki-display-referent): Stop removing any #section from
414
wikiword sent to referent functions.
515
(hywiki-add-prompted-referent): Remove #section from wikiword
@@ -8,6 +18,9 @@
818
referent value. Use in 'hywiki-get-referent'.
919
(hywiki-display-page , hywiki-display-referent, hywiki-get-referent):
1020
Exclude # from 'section' for consistency.
21+
(hywiki-add-activity, hywiki-add-org-roam-node): Use
22+
'hypb:require-package' to install activity or org-roam package as required
23+
when invoking these functions.
1124

1225
2024-12-26 Bob Weiner <[email protected]>
1326

hywiki.el

+41-54
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Bob Weiner
44
;;
55
;; Orig-Date: 21-Apr-24 at 22:41:13
6-
;; Last-Mod: 27-Dec-24 at 11:10:28 by Bob Weiner
6+
;; Last-Mod: 27-Dec-24 at 12:44:20 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -786,12 +786,12 @@ Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
786786
calling this function."
787787
(interactive (list (or (hywiki-word-at)
788788
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
789-
(require 'activities)
789+
(hypb:require-package 'activities)
790790
(let ((activity (activities-completing-read :prompt "Resume activity" :default nil)))
791791
(hywiki-add-referent wikiword (cons 'activity activity))))
792792

793-
(defun hywiki-display-activity (_wikiword referent)
794-
(activities-resume (cdr referent) :resetp nil))
793+
(defun hywiki-display-activity (_wikiword activity)
794+
(activities-resume activity :resetp nil))
795795

796796
(defun hywiki-add-bookmark (wikiword)
797797
"Make WIKIWORD display a bookmark and return the action.
@@ -812,9 +812,8 @@ calling this function."
812812
(error "(hywiki-add-bookmark): No bookmark specified")
813813
(hywiki-add-referent wikiword (cons 'bookmark bookmark)))))
814814

815-
(defun hywiki-display-bookmark (_wikiword referent)
816-
(let* ((bookmark (cdr referent))
817-
(loc (bookmark-location bookmark)))
815+
(defun hywiki-display-bookmark (_wikiword bookmark)
816+
(let ((loc (bookmark-location bookmark)))
818817
;; Use Hyperbole-specified display location
819818
(cond ((bufferp loc)
820819
(hpath:display-buffer loc))
@@ -842,11 +841,10 @@ calling this function."
842841
(let ((command (hui:actype nil (format "Command for %s: " wikiword))))
843842
(hywiki-add-referent wikiword (cons 'command command))))
844843

845-
(defun hywiki-display-command (wikiword referent)
846-
(let ((command (cdr referent)))
847-
(if (fboundp command)
848-
(actype:act command wikiword)
849-
(error "(hywiki-display-command): Unbound referent command, '%s'" command))))
844+
(defun hywiki-display-command (wikiword command)
845+
(if (fboundp command)
846+
(actype:act command wikiword)
847+
(error "(hywiki-display-command): Unbound referent command, '%s'" command)))
850848

851849
(defun hywiki-add-find (wikiword)
852850
"Make WIKIWORD grep across `hywiki-directory' for matches to itself.
@@ -863,11 +861,10 @@ calling this function."
863861
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
864862
(hywiki-add-referent wikiword (cons 'find #'hywiki-word-grep)))
865863

866-
(defun hywiki-display-find (wikiword referent)
867-
(let ((func (cdr referent)))
868-
(if (fboundp func)
869-
(actype:act func wikiword)
870-
(error "(hywiki-display-find): Unbound referent function, '%s'" func))))
864+
(defun hywiki-display-find (wikiword func)
865+
(if (fboundp func)
866+
(actype:act func wikiword)
867+
(error "(hywiki-display-find): Unbound referent function, '%s'" func)))
871868

872869
(defun hywiki-add-global-button (wikiword)
873870
"Make WIKIWORD evaluate a prompted for global button.
@@ -886,8 +883,8 @@ calling this function."
886883
nil t nil 'gbut)))
887884
(hywiki-add-referent wikiword (cons 'global-button gbut-name))))
888885

889-
(defun hywiki-display-global-button (_wikiword referent)
890-
(gbut:act (cdr referent)))
886+
(defun hywiki-display-global-button (_wikiword gbut-name)
887+
(gbut:act gbut-name))
891888

892889
(defun hywiki-add-hyrolo (wikiword)
893890
"Make WIKIWORD search and display `hyrolo-file-list' matches.
@@ -905,8 +902,8 @@ calling this function."
905902
;; !! TODO: Change PaulAllenWinter to search for "Winter, Paul Allen".
906903
(hywiki-add-referent wikiword (cons 'hyrolo #'hyrolo-fgrep)))
907904

908-
(defun hywiki-display-hyrolo (wikiword referent)
909-
(funcall (cdr referent) wikiword))
905+
(defun hywiki-display-hyrolo (wikiword search-func)
906+
(funcall search-func wikiword))
910907

911908
(defun hywiki-add-info-index (wikiword)
912909
"Make WIKIWORD display an Info manual index item and return it.
@@ -951,8 +948,8 @@ calling this function."
951948
(setq node (format "(%s)%s" (Info-current-filename-sans-extension) node)))
952949
(hywiki-add-referent wikiword (cons 'info-node node)))))
953950

954-
(defun hywiki-display-info-node (_wikiword referent)
955-
(Info-goto-node (cdr referent)))
951+
(defun hywiki-display-info-node (_wikiword node)
952+
(Info-goto-node node))
956953

957954
(defun hywiki-add-key-series (wikiword)
958955
"Make WIKIWORD invoke a prompted for key series and return it.
@@ -971,8 +968,8 @@ calling this function."
971968
(setq key-series (concat "{" (string-trim key-series) "}")))
972969
(hywiki-add-referent wikiword (cons 'key-series key-series))))
973970

974-
(defun hywiki-display-key-series (_wikiword referent)
975-
(hact 'kbd-key (cdr referent)))
971+
(defun hywiki-display-key-series (_wikiword key-series)
972+
(hact 'kbd-key key-series))
976973

977974
(defun hywiki-add-org-id (wikiword)
978975
"Make WIKIWORD display an Org file or headline with an Org id.
@@ -1004,8 +1001,8 @@ calling this function."
10041001
(setq org-id (org-id-get-create)))
10051002
(hywiki-add-referent wikiword (cons 'org-id (concat "ID: " org-id)))))))
10061003

1007-
(defun hywiki-display-org-id (_wikiword referent)
1008-
(hact 'link-to-org-id (cdr referent)))
1004+
(defun hywiki-display-org-id (_wikiword org-id)
1005+
(hact 'link-to-org-id org-id))
10091006

10101007
(defun hywiki-add-org-roam-node (wikiword)
10111008
"Make WIKIWORD display an Org Roam Node and return the action.
@@ -1019,7 +1016,7 @@ Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
10191016
calling this function."
10201017
(interactive (list (or (hywiki-word-at)
10211018
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
1022-
(require 'org-roam)
1019+
(hypb:require-package 'org-roam)
10231020
(let ((org-roam-node (org-roam-node-read)))
10241021
(hywiki-add-referent wikiword (cons 'org-roam-node org-roam-node))))
10251022

@@ -1098,12 +1095,11 @@ Use `hywiki-get-referent' to determine whether a HyWiki page exists."
10981095
(hywiki-display-page normalized-word)))
10991096
(t (user-error "(hywiki-create-page-and-display): Invalid HyWikiWord: '%s'; must be capitalized, all alpha" wikiword)))))
11001097

1101-
(defun hywiki-display-page (&optional wikiword referent)
1098+
(defun hywiki-display-page (&optional wikiword file-name)
11021099
"Display an optional WIKIWORD page and return the page file.
11031100
Use `hywiki-display-page-function' to display the page.
11041101
1105-
If REFERENT is provided, its `cdr' is the page file with any #section
1106-
from the WIKIWORD included.
1102+
If FILE is provided, it includes any #section from the WIKIWORD.
11071103
11081104
If WIKIWORD is omitted or nil and `hywiki-display-page-function'
11091105
is an interactive function, it is called interactively and prompts for
@@ -1112,15 +1108,10 @@ an existing or new HyWikiWord."
11121108
(call-interactively hywiki-display-page-function)
11131109
(when (null wikiword)
11141110
(setq wikiword (hywiki-word-read-new "Find HyWiki page: ")))
1115-
(let ((file (hywiki-get-file
1116-
(cond ((consp referent)
1117-
(cdr referent))
1118-
((stringp referent)
1119-
referent)
1120-
(t wikiword)))))
1111+
(let ((file (hywiki-get-file (or file-name wikiword))))
11211112
(funcall hywiki-display-page-function file)
11221113
;; Set 'referent attribute of current implicit button
1123-
(hattr:set 'hbut:current 'referent referent)
1114+
(hattr:set 'hbut:current 'referent (cons 'page file))
11241115
file)))
11251116

11261117
(defun hywiki-add-path-link (wikiword &optional file pos)
@@ -1147,8 +1138,8 @@ calling this function."
11471138
(when path-link
11481139
(hywiki-add-referent wikiword (cons 'path-link path-link)))))
11491140

1150-
(defun hywiki-display-path-link (_wikiword referent)
1151-
(funcall hywiki-display-page-function (cdr referent)))
1141+
(defun hywiki-display-path-link (_wikiword path)
1142+
(funcall hywiki-display-page-function path))
11521143

11531144
(defun hywiki-add-sexpression (wikiword)
11541145
"Make WIKIWORD evaluate a prompted for sexpression and return it.
@@ -1165,8 +1156,8 @@ calling this function."
11651156
(hywiki-add-referent wikiword (cons 'sexpression
11661157
(read--expression "Sexpression: "))))
11671158

1168-
(defun hywiki-display-sexpression (_wikiword referent)
1169-
(eval (cdr referent)))
1159+
(defun hywiki-display-sexpression (_wikiword sexpression)
1160+
(eval sexpression))
11701161

11711162
(defun hywiki-add-to-referent (wikiword text position)
11721163
"Display WIKIWORD referent and insert TEXT at POSITION.
@@ -2079,10 +2070,6 @@ regexps of wikiwords, if the hash table is out-of-date."
20792070
"Return a list of the HyWiki page names."
20802071
(hash-map #'cdr (hywiki-get-referent-hasht)))
20812072

2082-
(defun hywiki-get-wikiwords-obarray ()
2083-
"Return an obarray of existing HyWikiWords."
2084-
(cdr (hywiki-get-referent-hasht)))
2085-
20862073
(defun hywiki-get-plural-wikiword (wikiword)
20872074
"Return the pluralized version of the given WIKIWORD.
20882075
`hywiki-allow-plurals-flag' must be non-nil or nil is always returned."
@@ -2539,21 +2526,21 @@ these are handled by the Org mode link handler."
25392526
(eq (string-match (concat "\\`" hywiki-word-with-optional-section-regexp "\\'") word)
25402527
0)))))
25412528

2542-
(defun hywiki-word-read-new (&optional prompt)
2543-
"Prompt with completion for and return a new HyWiki page name."
2544-
(let ((completion-ignore-case t))
2545-
(completing-read (if (stringp prompt) prompt "HyWikiWord: ")
2546-
(hywiki-get-wikiwords-obarray)
2547-
nil nil nil nil (hywiki-word-at))))
2548-
25492529
(defun hywiki-word-read (&optional prompt)
25502530
"Prompt with completion for and return an existing HyWiki page name.
25512531
If on a page name, immediately pressing RET will use that name as the default."
25522532
(let ((completion-ignore-case t))
25532533
(completing-read (if (stringp prompt) prompt "HyWikiWord: ")
2554-
(hywiki-get-wikiwords-obarray)
2534+
(hywiki-get-referent-hasht)
25552535
nil t nil nil (hywiki-word-at))))
25562536

2537+
(defun hywiki-word-read-new (&optional prompt)
2538+
"Prompt with completion for and return a new HyWiki page name."
2539+
(let ((completion-ignore-case t))
2540+
(completing-read (if (stringp prompt) prompt "HyWikiWord: ")
2541+
(hywiki-get-referent-hasht)
2542+
nil nil nil nil (hywiki-word-at))))
2543+
25572544
(defun hywiki-word-highlight-flag-changed (symbol set-to-value operation _where)
25582545
"Watch function for variable ``hywiki-word-highlight-flag'.
25592546
Function is called with 4 arguments: (SYMBOL SET-TO-VALUE OPERATION WHERE).

test/hywiki-tests.el

+2-2
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ Note special meaning of `hywiki-allow-plurals-flag'."
668668
(let ((hywiki-directory (make-temp-file "hywiki" t))
669669
(wikiword "WikiWord"))
670670
(unwind-protect
671-
(mocklet ((require => t)
671+
(mocklet (((hypb:require-package 'activities) => t)
672672
(activities-completing-read => "activity"))
673673
(hywiki-add-activity wikiword)
674674
(should (equal '(activity . "activity")
@@ -802,7 +802,7 @@ Note special meaning of `hywiki-allow-plurals-flag'."
802802
(let ((hywiki-directory (make-temp-file "hywiki" t))
803803
(wikiword "WikiWord"))
804804
(unwind-protect
805-
(mocklet ((require => t)
805+
(mocklet (((hypb:require-package 'org-roam) => t)
806806
((org-roam-node-read) => "org-roam-node"))
807807
(hywiki-add-org-roam-node wikiword)
808808
(should (equal '(org-roam-node . "org-roam-node")

0 commit comments

Comments
 (0)