[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/hyperbole 79441e9b4a 4/6: hywiki.el - Rewrite to standa
From: |
ELPA Syncer |
Subject: |
[elpa] externals/hyperbole 79441e9b4a 4/6: hywiki.el - Rewrite to standardize all referents to (type . value) |
Date: |
Fri, 27 Dec 2024 09:58:26 -0500 (EST) |
branch: externals/hyperbole
commit 79441e9b4a47c01d6660338ac6d8da5fbd018980
Author: bw <rsw@gnu.org>
Commit: bw <rsw@gnu.org>
hywiki.el - Rewrite to standardize all referents to (type . value)
---
ChangeLog | 73 ++++++
hui-menu.el | 4 +-
hui-mini.el | 6 +-
hywiki.el | 712 ++++++++++++++++++++++++++++-----------------------
test/hywiki-tests.el | 228 ++++++++++-------
5 files changed, 595 insertions(+), 428 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 94304d489b..b901872170 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-12-26 Bob Weiner <rsw@gnu.org>
+
+* hywiki.el (hywiki-add-path-link): Add optional FILE and POS arguments
+ to better evaluate intermittent test bug in 'hywiki-tests--add-path-link'.
+ It fails on a call to this function only when all tests are run; never
+ fails interactively.
+
* test/hy-test-dependencies.el (load "pcomplete"): Only on rsw's linux
system, load this library to eliminate cyclic dependency errors in
11 tests.
@@ -14,8 +21,74 @@
* hbut.el (ibut:create): When debug on error, display *Messages* buffer
with error message.
+* hywiki.el (hywiki-make-referent-hasht): Optimize when no non-page
+ entries.
+
+* hywiki.el (hywiki-add-page): Return '(page . "<page-file-path>")
+ rather than just "<page-file-path>". Update doc string.
+ (hywiki-add-to-referent): Update doc string.
+ (hywiki-display-referent): Remove unneeded clauses
+ due to new typed referents. Update doc string.
+ (hywiki-find-referent): Update doc string.
+ (hywiki-display-referent-type): Update doc string with
+ computed display function name.
+ (hywiki-get-referent): Rewrite to handled typed referents.
+ (hywiki-display-page): Fix to allow both typed referents
+ and file-name alone as referent input.
+ (hywiki-add-referent): Trigger error if 'hash-add' call fails
+ and fix doc string to cover all return values.
+ (hywiki-validate-referent): Add to validate referents before
+ adding to the HyWiki hash table. Use in 'hywiki-add-referent'.
+
+2024-12-25 Bob Weiner <rsw@gnu.org>
+
+* hywiki.el (hywiki-org-link-resolve): Fix doc to include all possible
+ return value types and rewrite to new typed referents.
+
+2024-12-24 Bob Weiner <rsw@gnu.org>
+
+* hywiki.el: Rename all 'page(s)-hasht' to 'referent-hasht'.
+ (hywiki-non-page-elts): Rewrite to new typed
+ referents and inline the function.
+ Rename 'hywiki--any-page-regexp-list' to
+ 'hywiki--any-wikiword-regexp-list'.
+ Rename 'hywiki-maybe-highlight-page-names-in-frame'
+ to 'hywiki-maybe-highlight-wikiwords-in-frame'.
+ Rename 'hywiki-get-page-list' to 'hywiki-get-wikiword-list'.
+
+2024-12-23 Bob Weiner <rsw@gnu.org>
+
+* test/hywiki-tests.el (hywiki-tests--add-*): Rewrite to handle typed
+ referents.
+
+* hywiki.el (hywiki-add-link): Rename to 'hywiki-add-path-link'.
+ (hywiki-add-page): Document optional 'force-flag' arg.
+ (hywiki-add-page-and-display): Improve doc on prompting
+ for a referent type.
+ (hywiki-add-page-and-display): Rename to
+ 'hywiki-create-page-and-display'.
+ (hywiki-referent-prompt-flag): Add this new customization.
+ (hywiki-create-page-and-display): Set prompt-flag t if
+ call-interactively and 'hywiki-referent-prompt-flag' is non-nil.
+ (hywiki-display-referent-type): Add to display referents
+ other than pages.
+ (hywiki-display-referent): Call above function.
+ (hywiki-add-*): Rewrite all referent add functions to just
+ store the referent value and add hywiki-display-* functions to perform
+ the referent display instead. This allows for easy addition of new
+ referent types.
+ (hywiki-display-page-function): Fix doc to say function takes
+ a pathname, not a HyWiki page name.
+ (hywiki-create-page): Add type to hash value so is a cons of
+ (page . <page-file-path>).
+
2024-12-22 Bob Weiner <rsw@gnu.org>
+* hywiki.el (hywiki-find-referent): Fix doc string to describe how
+ a prefix arg prompts for the type of referent to link to.
+ (hywiki-add-prompted-referent, hywiki-referent-menu):
+ Set 'hkey-value' to wikiword to pass to expressions in this menu,
+ invoked via the Smart Keys.
* test/hywiki-tests.el (hywiki-tests--add-org-id): Fix so :type
argument is a list as required, not a symbol.
diff --git a/hui-menu.el b/hui-menu.el
index 7b5ef134c1..6d60e2ba29 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: 24-Nov-24 at 16:38:36 by Bob Weiner
+;; Last-Mod: 23-Dec-24 at 14:18:08 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -307,7 +307,7 @@ Return t if cutoff, else nil."
["Manual" (id-info "(hyperbole)HyWiki") t]
"----"
["Activate-HyWiki-Word" hywiki-word-activate t]
- ["Create-HyWiki-Page" hywiki-add-page-and-display t]
+ ["Create-HyWiki-Page" hywiki-create-page-and-display t]
["Edit-HyWiki-Pages" hywiki-directory-edit t]
["Find-HyWiki-Referent" hywiki-find-referent t]
(when (fboundp 'consult-grep) ;; allow for autoloading
diff --git a/hui-mini.el b/hui-mini.el
index b3f465fcde..14cb17862e 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: 15-Dec-24 at 22:43:50 by Bob Weiner
+;; Last-Mod: 23-Dec-24 at 14:18:06 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -1030,7 +1030,7 @@ support underlined faces as well."
'("HyWiki>")
'("Act" hywiki-word-activate
"Activate HyWikiWord link at point or emulate a press of a Smart
Key.")
- '("Create" hywiki-add-page-and-display
+ '("Create" hywiki-create-page-and-display
"Create and display a new HyWiki page. Shows existing page names
to aid in new naming.")
'("EditPages" hywiki-directory-edit
"Display and edit HyWiki directory.")
@@ -1043,7 +1043,7 @@ support underlined faces as well."
"Report on a HyWikiWord's attributes.")
'("Info" (id-info "(hyperbole)HyWiki")
"Display Hyperbole manual section on HyWiki.")
- '("Link" hywiki-add-link
+ '("Link" hywiki-add-path-link
"Prompt for and add a HyWikiWord that links to a path and possible
position.")
'("ModeToggle" hywiki-mode
"Toggle whether HyWikiWords are highlighted and active in buffers
outside of the HyWiki page directory.")
diff --git a/hywiki.el b/hywiki.el
index 9108ce58ae..d5e8f99a8f 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: 22-Dec-24 at 16:31:10 by Bob Weiner
+;; Last-Mod: 26-Dec-24 at 22:52:28 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -142,6 +142,7 @@
(defvar action-key-modeline-buffer-id-function) ;; "hui-mouse.el"
(defvar bookmark-current-bookmark) ;; "bookmark.el"
+(defvar hkey-value) ;; "hui-mouse.el"
(defvar hywiki-referent-menu nil) ;; "hywiki.el"
(defvar org-agenda-buffer-tmp-name) ;; "org-agenda.el"
(defvar org-export-with-broken-links) ;; "ox.el"
@@ -154,6 +155,7 @@
(declare-function bookmark-location "bookmark" (bookmark-name-or-record))
(declare-function hsys-org-at-tags-p "hsys-org")
(declare-function org-link-store-props "ol" (&rest plist))
+(declare-function org-roam-node-open "org-roam" (note &optional cmd force))
(declare-function org-roam-node-read "org-roam" (&optional initial-input
filter-fn sort-fn require-match prompt))
(declare-function org-publish-property "ox-publish" (property project
&optional default))
(declare-function smart-treemacs-edit "hui-treemacs" (&optional dir))
@@ -194,11 +196,11 @@ See `current-time' function for the mod time format.")
"Standard syntax table for Org mode buffers with HyWiki support.")
(defvar hywiki--pages-directory nil)
-(defvar hywiki--pages-hasht nil)
+(defvar hywiki--referent-hasht nil)
;; Globally set these values to avoid using 'let' with stack allocations
;; within `hywiki-maybe-highlight-page-name' frequently.
-(defvar hywiki--any-page-regexp-list nil)
+(defvar hywiki--any-wikiword-regexp-list nil)
(defvar hywiki--buts nil)
(defvar hywiki--but-end nil)
(defvar hywiki--but-start nil)
@@ -257,16 +259,16 @@ Use nil for no HyWiki mode indicator."
;;;###autoload
(defun hywiki-let-directory (option value)
(set option value)
- (hywiki-clear-pages-hasht)
- (hywiki-make-pages-hasht))
+ (hywiki-clear-referent-hasht)
+ (hywiki-make-referent-hasht))
;;;###autoload
(defun hywiki-set-directory (option value)
(unless (and (boundp 'hywiki-directory)
(equal hywiki-directory (file-name-as-directory value)))
(set-default option (file-name-as-directory value))
- (hywiki-clear-pages-hasht)
- (hywiki-make-pages-hasht))
+ (hywiki-clear-referent-hasht)
+ (hywiki-make-referent-hasht))
(hywiki-org-set-publish-project))
(defcustom hywiki-directory "~/hywiki/"
@@ -412,6 +414,12 @@ The file must be below `hywiki-directory'.
For reference, this is set when `window-buffer-change-functions' calls
`hywiki-maybe-highlight-page-names' which calls `hywiki-in-page-p'.")
+(defcustom hywiki-referent-prompt-flag nil
+ "When non-nil, HyWiki/Create always prompts for referent type.
+Nil by default."
+ :type 'boolean
+ :group 'hyperbole-hywiki)
+
(defconst hywiki-word-regexp
"\\<\\([[:upper:]][[:alpha:]]+\\)\\>"
"Regexp that matches a HyWiki word only.")
@@ -452,8 +460,8 @@ the HyWiki word and grouping 2 is the #section with the #
included.")
:group 'hyperbole-hywiki)
(defcustom hywiki-display-page-function #'hpath:find
- "Hyperbole function to display HyWiki pages.
-Only argument is the page name concatenated with optional #section."
+ "Hyperbole function to display HyWiki page pathnames.
+Only argument is the page's pathname."
:initialize #'custom-initialize-default
:type 'string
:group 'hyperbole-hywiki)
@@ -463,7 +471,7 @@ Only argument is the page name concatenated with optional
#section."
:initialize #'custom-initialize-default
:set (lambda (option value)
(set option value)
- (setq hywiki--any-page-regexp-list nil))
+ (setq hywiki--any-wikiword-regexp-list nil))
:type 'boolean
:group 'hyperbole-hywiki)
@@ -500,7 +508,7 @@ deletion commands and those in
`hywiki-non-character-commands'."
(and (symbolp this-command)
(string-match-p "\\`\\(org-\\)?delete-" (symbol-name
this-command))))
(cl-destructuring-bind (start end)
- (hywiki-get-delimited-range)
+ (hywiki-get-delimited-range) ;; includes delimiters
;; Use these to store any range of a delimited HyWikiWord#section
(set-marker hywiki--buttonize-start start)
(set-marker hywiki--buttonize-end end)
@@ -576,14 +584,14 @@ See the Info documentation at \"(hyperbole)HyWiki\".
(hyperbole-mode 1))
(unless hywiki-mode-map
(setq hywiki-mode-map (make-sparse-keymap)))
- ;; Next line triggers a call to
`hywiki-maybe-highlight-page-names-in-frame'
+ ;; Next line triggers a call to
`hywiki-maybe-highlight-wikiwords-in-frame'
(set-variable 'hywiki-word-highlight-flag t))
;; disable mode
;; Dehighlight HyWikiWords in this buffer when 'hywiki-mode' is
;; disabled and this is not a HyWiki page buffer. If this is a
;; HyWiki page buffer, then dehighlight when
;; `hywiki-word-highlight-flag' is nil.
- (hywiki-maybe-highlight-page-names-in-frame t)))
+ (hywiki-maybe-highlight-wikiwords-in-frame t)))
;;; ************************************************************************
;;; Public Implicit Button and Action Types
@@ -603,28 +611,21 @@ prevent any unexpected HyWiki use."
(ibut:label-set wikiword start end)
(hact 'hywiki-find-referent wikiword))))
-(defun hywiki-display-page (&optional wikiword)
- "Display an optional WIKIWORD page and return the page file.
-Use `hywiki-display-page-function' to display the page.
-
-If WIKIWORD is omitted or nil and `hywiki-display-page-function'
-is an interactive function, it is called interactively and prompts for
-an existing or new HyWikiWord."
- (if (and (null wikiword) (commandp hywiki-display-page-function))
- (call-interactively hywiki-display-page-function)
- (when (null wikiword)
- (setq wikiword (hywiki-word-read-new "Find HyWiki page: ")))
- (let ((referent (hywiki-get-file wikiword)))
- (funcall hywiki-display-page-function referent)
- ;; Set 'referent attribute of current implicit button
- (hattr:set 'hbut:current 'referent referent)
- referent)))
+(defun hywiki-display-referent-type (wikiword referent)
+ "Display WIKIWORD REFERENT, a cons of (<referent-type> . <referent-value>).
+Function used to display is \"hywiki-display-<referent-type>\"."
+ (let* ((referent-type (car referent)) ;; a symbol
+ (referent-value (cdr referent))
+ (display-function (intern-soft (concat "hywiki-display-"
+ (symbol-name referent-type)))))
+ (when (fboundp display-function)
+ (funcall display-function wikiword referent-value))))
(defun hywiki-display-referent (&optional wikiword prompt-flag)
"Display HyWiki WIKIWORD or a regular file with WIKIWORD nil.
Return the WIKIWORD's referent if successfully found or nil otherwise.
-
-For details, see documentation for `hywiki-find-referent'.
+The referent is a cons of (<referent-type> . <referent-value>).
+For further details, see documentation for `hywiki-find-referent'.
After successfully finding a page and reading it into a buffer, run
`hywiki-display-referent-hook'."
(let ((in-page-flag (null wikiword))
@@ -641,48 +642,19 @@ After successfully finding a page and reading it into a
buffer, run
(setq wikiword (file-name-sans-extension (file-name-nondirectory
buffer-file-name))))
(when (string-match "#[^#]+$" wikiword)
(setq wikiword (substring wikiword 0 (match-beginning 0))))
- (let* ((section (when (string-match "#[^#]+$" wikiword)
- (substring wikiword (match-beginning 0))))
- (referent (cond (prompt-flag
+ (let* ((referent (cond (prompt-flag
(hywiki-add-prompted-referent wikiword))
((hywiki-get-referent wikiword))
- (t (hywiki-add-page wikiword)))))
+ (t (hywiki-add-page wikiword))))
+ (referent-value (cdr referent)))
(when referent
;; Ensure highlight any page name at point in case called as a
;; Hyperbole action type
(hywiki-maybe-highlight-page-name t)
- (cond ((or (symbolp referent) (functionp referent))
- ;; function or actype symbol
- (hact referent wikiword prompt-flag))
- ((and (consp referent) (fboundp (car referent)))
- ;; e.g. (kbd "key sequence")
- (eval referent))
- ((and (null referent) (stringp section)
- (string-match-p "^\\(#[^#]+\\)$" section))
- ;; "#in-buffer-section"
- (hywiki-display-page section))
- ((stringp referent)
- (let ((case-fold-search t))
- (cond
- ((string-match-p "^\\({.+}\\)$" referent)
- ;; "{key series}"
- (hact 'kbd-key referent))
- ((and (featurep 'org-id)
- (string-match "^\\(CUSTOM_\\)?ID:[ \t]+\\(.*[^
\t]\\)" referent))
- ;; "ID: org-id"
- (setq referent (match-string 2 referent))
- (hact 'link-to-org-id referent))
- ((string-match-p "^\\(<\\[.+\\]>\\|<(.+)>\\)$" referent)
- ;; "<(global explicit button name)>"
- ;; "<[global implicit button name]>"
- (gbut:act (string-trim (substring referent 2 -2))))
- ((string-match-p "^(.+).+$\\|.+\\.info\\([.#]\\|$\\)"
referent)
- ;; (info-manual)node-or-index-item
- (hywiki-display-page referent))
- (t
- ;; page path, the default
- (unless in-page-flag
- (hywiki-display-page (concat referent section))))))))
+ (if (and (consp referent) (not (listp referent-value)))
+ (hywiki-display-referent-type wikiword referent)
+ (error "(hywiki-display-referent): Invalid `%s' referent: %s"
+ wikiword referent))
(hywiki-maybe-highlight-page-names)
(run-hooks 'hywiki-display-referent-hook)
referent)))
@@ -703,42 +675,42 @@ After successfully finding a page and reading it into a
buffer, run
(list
'("HyWiki Add>")
(when (fboundp #'activities-new)
- '("Activity" hywiki-add-activity
+ '("Activity" (hywiki-add-activity hkey-value)
"Add a HyWikiWord that activates a saved activity from the
Activities package."))
- '("Bookmark" hywiki-add-bookmark
+ '("Bookmark" (hywiki-add-bookmark hkey-value)
"Add a HyWikiWord that jumps to an Emacs bookmark.")
- '("Command" hywiki-add-command
+ '("Command" (hywiki-add-command hkey-value)
"Add a HyWikiWord that runs an Emacs command or Hyperbole action
type.")
- '("Find" hywiki-add-find
+ '("Find" (hywiki-add-find hkey-value)
"Add a HyWikiWord that greps through `hywiki-directory' for its
matches.")
;; "<(global explicit button name)>"
;; "<[global implicit button name]>"
- '("Gbut" hywiki-add-global-button
+ '("Gbut" (hywiki-add-global-button hkey-value)
"Add a HyWikiWord that activates a named Hyperbole global button.")
- '("HyRolo" hywiki-add-hyrolo
+ '("HyRolo" (hywiki-add-hyrolo hkey-value)
"Add a HyWikiWord that searches `hyrolo-file-list' for matches.")
;; "{key series}" wikiword)
- '("Keys" hywiki-add-key-series
+ '("Keys" (hywiki-add-key-series hkey-value)
"Add a HyWikiWord that executes a key series.")
;; "(hyperbole)action implicit button"
- '("InfoIndex" hywiki-add-info-index
+ '("InfoIndex" (hywiki-add-info-index hkey-value)
"Add a HyWikiWord that displays an Info index item.")
;; "(hyperbole)Smart Keys"
- '("infoNode" hywiki-add-info-node
+ '("infoNode" (hywiki-add-info-node hkey-value)
"Add a HyWikiWord that displays an Info node.")
- '("LinkPath" hywiki-add-link
+ '("LinkPath" (hywiki-add-path-link hkey-value)
"Add a HyWikiWord that links to a path and possible position.")
;; "ID: org-id"
- '("OrgID" hywiki-add-org-id
+ '("OrgID" (hywiki-add-org-id hkey-value)
"Add a HyWikiWord that displays an Org section given its Org ID.")
- '("orgRoamNode" hywiki-add-org-roam-node
+ '("orgRoamNode" (hywiki-add-org-roam-node hkey-value)
"Add a HyWikiWord that displays an Org Roam node given its title.")
;; "pathname:line:col"
;; "#in-buffer-section"
- '("Page" hywiki-add-page
+ '("Page" (hywiki-add-page hkey-value)
"Add/reset a HyWikiWord to link to its standard HyWiki page.")
;; e.g. (kbd "key sequence")
- '("Sexp" hywiki-add-sexpresion
+ '("Sexp" (hywiki-add-sexpresion hkey-value)
"Add a HyWikiWord that evaluates an Elisp sexpression.")))
"*Menu of HyWikiWord custom referent types of the form:
\(LABEL-STRING ACTION-SEXP DOC-STR)."
@@ -751,10 +723,11 @@ After successfully finding a page and reading it into a
buffer, run
(interactive (list (hywiki-word-read-new "Add/Edit HyWikiWord: ")))
(unless (stringp wikiword)
(setq wikiword (hywiki-word-read-new "Add/Edit HyWikiWord: ")))
+ (setq hkey-value wikiword)
(let ((referent
(hui:menu-act 'hywiki-referent-menu
(list (cons 'hywiki-referent-menu
- (cons (list (format "Set HyWiki '%s' Actype>"
+ (cons (list (format "%s RefType>"
wikiword))
(cdr hywiki-referent-menu)))))))
(or referent
@@ -762,14 +735,22 @@ After successfully finding a page and reading it into a
buffer, run
(user-error "(hywiki-add-prompted-referent): Invalid HyWikiWord:
'%s'; must be capitalized, all alpha" wikiword)))))
(defun hywiki-add-referent (wikiword referent)
+ "Add WIKIWORD that displays REFERENT to HyWiki.
+Return REFERENT if WIKIWORD is of valid format, otherwise return nil.
+REFERENT must be a cons of (<referent-type) . <referent-value>) or
+an error is triggered."
+ (hywiki-validate-referent referent)
(when (hywiki-word-is-p wikiword)
(when (match-string-no-properties 2 wikiword)
;; Remove any #section suffix in PAGE-NAME.
(setq wikiword (match-string-no-properties 1 wikiword)))
- (hash-add referent (hywiki-get-singular-wikiword wikiword)
- (hywiki-get-page-hasht))
- (setq hywiki--any-page-regexp-list nil)
- (unless (hyperb:stack-frame '(hywiki-maybe-highlight-page-names-in-frame))
+ (unless (hash-add referent (hywiki-get-singular-wikiword wikiword)
+ (hywiki-get-referent-hasht))
+ (error "(hywiki-add-referent): Failed: (hash-add %s %s %s)"
+ referent (hywiki-get-singular-wikiword wikiword)
+ (hywiki-get-referent-hasht)))
+ (setq hywiki--any-wikiword-regexp-list nil)
+ (unless (hyperb:stack-frame '(hywiki-maybe-highlight-wikiwords-in-frame))
(hywiki-directory-set-mod-time)
(hywiki-directory-set-checksum))
(run-hooks 'hywiki-add-referent-hook)
@@ -797,13 +778,16 @@ or return nil if not.
After successfully adding the activity, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
(require 'activities)
(let ((activity (activities-completing-read :prompt "Resume activity"
:default nil)))
- (hywiki-add-referent wikiword `(activities-resume ,activity :resetp nil))))
+ (hywiki-add-referent wikiword (cons 'activity activity))))
+
+(defun hywiki-display-activity (_wikiword referent)
+ (activities-resume (cdr referent) :resetp nil))
(defun hywiki-add-bookmark (wikiword)
"Make WIKIWORD display a bookmark and return the action.
@@ -813,41 +797,52 @@ or return nil if not.
After successfully adding the bookmark, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
(require 'bookmark)
- (let* ((bookmark (bookmark-completing-read "Bookmark: "
- bookmark-current-bookmark))
- (loc (bookmark-location bookmark))
- ;; Use Hyperbole-specified display location
- (bkm-display `(progn
- (cond ((bufferp ,loc)
- (hpath:display-buffer ,loc))
- ((get-buffer ,loc)
- (hpath:display-buffer (get-buffer ,loc)))
- ((stringp ,loc)
- (hywiki-display-page ,loc)))
- (bookmark-jump ,bookmark))))
- (hywiki-add-referent wikiword bkm-display)))
+ (let ((bookmark (bookmark-completing-read "Bookmark: "
+ bookmark-current-bookmark)))
+ (if (string-empty-p bookmark)
+ (error "(hywiki-add-bookmark): No bookmark specified")
+ (hywiki-add-referent wikiword (cons 'bookmark bookmark)))))
+
+(defun hywiki-display-bookmark (_wikiword referent)
+ (let* ((bookmark (cdr referent))
+ (loc (bookmark-location bookmark)))
+ ;; Use Hyperbole-specified display location
+ (cond ((bufferp loc)
+ (hpath:display-buffer loc))
+ ((get-buffer loc)
+ (hpath:display-buffer (get-buffer loc)))
+ ((stringp loc)
+ (hywiki-display-page loc)))
+ (bookmark-jump bookmark)))
(defun hywiki-add-command (wikiword)
"Set a custom command symbol for WIKIWORD and return it.
Command is the symbol used in the definition expression, which
-may be an Emacs command or a Hyperbole action type.
+may be an Emacs command or a Hyperbole action type. When invoked,
+it receives the single argument of WIKIWORD.
If WIKIWORD is invalid, trigger a `user-error' if called interactively
or return nil if not.
After successfully adding the actype, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
(let ((command (hui:actype nil (format "Command for %s: " wikiword))))
- (hywiki-add-referent wikiword command)))
+ (hywiki-add-referent wikiword (cons 'command command))))
+
+(defun hywiki-display-command (wikiword referent)
+ (let ((command (cdr referent)))
+ (if (fboundp command)
+ (actype:act command wikiword)
+ (error "(hywiki-display-command): Unbound referent command, '%s'"
command))))
(defun hywiki-add-find (wikiword)
"Make WIKIWORD grep across `hywiki-directory' for matches to itself.
@@ -858,11 +853,17 @@ or return nil if not.
After successfully adding the grep, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
- (hywiki-add-referent wikiword #'hywiki-word-grep))
+ (hywiki-add-referent wikiword (cons 'find #'hywiki-word-grep)))
+
+(defun hywiki-display-find (wikiword referent)
+ (let ((func (cdr referent)))
+ (if (fboundp func)
+ (actype:act func wikiword)
+ (error "(hywiki-display-find): Unbound referent function, '%s'" func))))
(defun hywiki-add-global-button (wikiword)
"Make WIKIWORD evaluate a prompted for global button.
@@ -872,14 +873,17 @@ or return nil if not.
After successfully adding the button link, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
(let ((gbut-name (hargs:read-match "Global button: "
(mapcar #'list (gbut:label-list))
nil t nil 'gbut)))
- (hywiki-add-referent wikiword `(gbut:act ,gbut-name))))
+ (hywiki-add-referent wikiword (cons 'global-button gbut-name))))
+
+(defun hywiki-display-global-button (_wikiword referent)
+ (gbut:act (cdr referent)))
(defun hywiki-add-hyrolo (wikiword)
"Make WIKIWORD search and display `hyrolo-file-list' matches.
@@ -889,13 +893,16 @@ or return nil if not.
After successfully adding the hyrolo search, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
(require 'hyrolo)
;; !! TODO: Change PaulAllenWinter to search for "Winter, Paul Allen".
- (hywiki-add-referent wikiword `(hyrolo-fgrep ,wikiword)))
+ (hywiki-add-referent wikiword (cons 'hyrolo #'hyrolo-fgrep)))
+
+(defun hywiki-display-hyrolo (wikiword referent)
+ (funcall (cdr referent) wikiword))
(defun hywiki-add-info-index (wikiword)
"Make WIKIWORD display an Info manual index item and return it.
@@ -905,7 +912,7 @@ or return nil if not.
After successfully adding the Info index item, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
@@ -915,7 +922,10 @@ calling this function."
(when (stringp item)
(unless (= (aref item 0) ?\()
(setq item (format "(%s)%s" (Info-current-filename-sans-extension)
item)))
- (hywiki-add-referent wikiword `(Info-goto-node ,item)))))
+ (hywiki-add-referent wikiword (cons 'info-index item)))))
+
+(defun hywiki-display-info-index (_wikiword referent)
+ (Info-goto-node (cdr referent)))
(defun hywiki-add-info-node (wikiword)
"Make WIKIWORD display an Info manual node and return it.
@@ -925,7 +935,7 @@ or return nil if not.
After successfully adding the Info node, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
@@ -935,7 +945,10 @@ calling this function."
(when (stringp node)
(unless (= (aref node 0) ?\()
(setq node (format "(%s)%s" (Info-current-filename-sans-extension)
node)))
- (hywiki-add-referent wikiword `(Info-goto-node ,node)))))
+ (hywiki-add-referent wikiword (cons 'info-node node)))))
+
+(defun hywiki-display-info-node (_wikiword referent)
+ (Info-goto-node (cdr referent)))
(defun hywiki-add-key-series (wikiword)
"Make WIKIWORD invoke a prompted for key series and return it.
@@ -945,32 +958,17 @@ or return nil if not.
After successfully adding the key series, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
(let ((key-series (read-string "Key series (with or without {}): ")))
(unless (string-match-p "\\`{.+}\\'" key-series)
(setq key-series (concat "{" (string-trim key-series) "}")))
- (hywiki-add-referent wikiword key-series)))
-
-(defun hywiki-add-link (wikiword)
- "Set a path link and possible position for WIKIWORD and return it.
-
-If WIKIWORD is invalid, trigger a `user-error' if called interactively
-or return nil if not.
+ (hywiki-add-referent wikiword (cons 'key-series key-series))))
-After successfully adding the path link, run `hywiki-add-referent-hook'.
-
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
-calling this function."
- (interactive (list (or (hywiki-word-at)
- (hywiki-word-read-new "Add/Edit HyWikiWord: "))))
- (let ((referent (hactypes:link-to-file-interactively)))
- (when (= (length referent) 2)
- (setq referent (hpath:file-position-to-line-and-column
- (car referent) (cadr referent))))
- (hywiki-add-referent wikiword referent)))
+(defun hywiki-display-key-series (_wikiword referent)
+ (hact 'kbd-key (cdr referent)))
(defun hywiki-add-org-id (wikiword)
"Make WIKIWORD display an Org file or headline with an Org id.
@@ -981,7 +979,7 @@ or return nil if not.
After successfully adding the sexpression, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
@@ -1000,7 +998,10 @@ calling this function."
(buffer-name)))
(unless org-id
(setq org-id (org-id-get-create)))
- (hywiki-add-referent wikiword (concat "ID: " org-id))))))
+ (hywiki-add-referent wikiword (cons 'org-id (concat "ID: " org-id)))))))
+
+(defun hywiki-display-org-id (_wikiword referent)
+ (hact 'link-to-org-id (cdr referent)))
(defun hywiki-add-org-roam-node (wikiword)
"Make WIKIWORD display an Org Roam Node and return the action.
@@ -1010,22 +1011,26 @@ or return nil if not.
After successfully adding the action, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
(require 'org-roam)
- (let* ((org-roam-node (org-roam-node-read))
- (referent `(org-roam-node-open ,org-roam-node
- (or (alist-get 'file
org-link-frame-setup)
- (alist-get hpath:display-where
hpath:display-where-alist)))))
- (hywiki-add-referent wikiword referent)))
+ (let ((org-roam-node (org-roam-node-read)))
+ (hywiki-add-referent wikiword (cons 'org-roam-node org-roam-node))))
+
+(defun hywiki-display-org-roam-node (_wikiword referent)
+ (org-roam-node-open (cdr referent)
+ (or (alist-get 'file org-link-frame-setup)
+ (alist-get hpath:display-where
hpath:display-where-alist))))
(defun hywiki-add-page (page-name &optional force-flag)
- "Add or edit the HyWiki page for PAGE-NAME and return its file.
-If file exists already, just return it. If PAGE-NAME is invalid,
-trigger a `user-error' if called interactively or return nil if
-not.
+ "Add a new or return any existing HyWiki page path for PAGE-NAME.
+Returned format is: '(page . \"<page-file-path>\") or nil when none.
+
+With optional FORCE-FLAG non-nil, force an update to the page's
+modification time. If PAGE-NAME is invalid, trigger a
+`user-error' if called interactively or return nil if not.
By default, create any non-existent page. When not in batch or
ert test results mode, if this is the first HyWiki page in
@@ -1033,13 +1038,13 @@ ert test results mode, if this is the first HyWiki page
in
After successfully adding a page, run `hywiki-add-page-hook'.
-Use `hywiki-get-page' to determine whether a HyWiki page exists."
+Use `hywiki-get-referent' to determine whether a HyWiki page exists."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWiki page: "))
current-prefix-arg))
(if (hywiki-word-is-p page-name)
(when (or noninteractive
- (not (hash-empty-p (hywiki-get-page-hasht)))
+ (not (hash-empty-p (hywiki-get-referent-hasht)))
(hyperb:stack-frame '(ert-run-test))
(y-or-n-p (concat "Create new HyWiki page `" page-name "'? ")))
(when (match-string-no-properties 2 page-name)
@@ -1048,41 +1053,97 @@ Use `hywiki-get-page' to determine whether a HyWiki
page exists."
(let* ((page-file (hywiki-get-file page-name))
(page-file-readable (file-readable-p page-file))
- (pages-hasht (hywiki-get-page-hasht))
+ (referent-hasht (hywiki-get-referent-hasht))
(page-in-hasht (hywiki-get-referent page-name)))
(unless page-file-readable
(if (file-writable-p page-file)
(write-region "" nil page-file nil 0)
(user-error "(hywiki-add-page): No permission to write HyWikiWord
page file:\n \"%s\"" page-name)))
(when (or force-flag (not page-in-hasht))
- (hash-add page-file page-name pages-hasht)
- (setq hywiki--any-page-regexp-list nil))
- (unless (or (hyperb:stack-frame
'(hywiki-maybe-highlight-page-names-in-frame))
+ (hash-add (cons 'page (file-name-nondirectory page-file))
+ page-name referent-hasht)
+ (setq hywiki--any-wikiword-regexp-list nil))
+ (unless (or (hyperb:stack-frame
'(hywiki-maybe-highlight-wikiwords-in-frame))
(and (not force-flag) page-file-readable page-in-hasht))
(hywiki-directory-set-mod-time)
(hywiki-directory-set-checksum))
(run-hooks 'hywiki-add-page-hook)
- page-file))
+ (when page-file (cons 'page page-file))))
(when (called-interactively-p 'interactive)
(user-error "(hywiki-add-page): Invalid HyWikiWord: '%s'; must be
capitalized, all alpha" page-name))))
-(defun hywiki-add-page-and-display (wikiword &optional prompt-flag)
+(defun hywiki-create-page-and-display (wikiword &optional prompt-flag)
"Display the HyWiki referent for WIKIWORD and return it.
-If there is no existing WIKIWORD referent, add a HyWiki page for it.
-See doc for `hywiki-find-referent' for use of optional prefix arg
-PROMPT-FLAG.
+If there is no existing WIKIWORD referent, add a HyWiki page for
+it. With optional prefix arg, PROMPT-FLAG, prompt for and choose
+a referent type; see ‘hywiki-referent-menu’ for valid referent
+types.
-Use `hywiki-get-page' to determine whether a HyWiki page exists."
+Use `hywiki-get-referent' to determine whether a HyWiki page exists."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add and display HyWiki page: "))
current-prefix-arg))
+ (when (and (not prompt-flag) hywiki-referent-prompt-flag
+ (called-interactively-p 'interactive))
+ (setq prompt-flag t))
(let* ((normalized-word (hywiki-get-singular-wikiword wikiword))
(referent (hywiki-find-referent normalized-word prompt-flag)))
(cond (referent)
((and (null referent) (hywiki-word-is-p normalized-word))
(when (hywiki-add-page normalized-word)
(hywiki-display-page normalized-word)))
- (t (user-error "(hywiki-add-page-and-display): Invalid HyWikiWord:
'%s'; must be capitalized, all alpha" wikiword)))))
+ (t (user-error "(hywiki-create-page-and-display): Invalid HyWikiWord:
'%s'; must be capitalized, all alpha" wikiword)))))
+
+(defun hywiki-display-page (&optional wikiword referent)
+ "Display an optional WIKIWORD page and return the page file.
+Use `hywiki-display-page-function' to display the page.
+
+If REFERENT is provided, the page file is its `cdr'.
+
+If WIKIWORD is omitted or nil and `hywiki-display-page-function'
+is an interactive function, it is called interactively and prompts for
+an existing or new HyWikiWord."
+ (if (and (null wikiword) (commandp hywiki-display-page-function))
+ (call-interactively hywiki-display-page-function)
+ (when (null wikiword)
+ (setq wikiword (hywiki-word-read-new "Find HyWiki page: ")))
+ (let ((file (hywiki-get-file
+ (cond ((consp referent)
+ (cdr referent))
+ ((stringp referent)
+ referent)
+ (t wikiword)))))
+ (funcall hywiki-display-page-function file)
+ ;; Set 'referent attribute of current implicit button
+ (hattr:set 'hbut:current 'referent referent)
+ file)))
+
+(defun hywiki-add-path-link (wikiword &optional file pos)
+ "Set a path link and possible position for WIKIWORD and return it.
+If WIKIWORD is invalid, trigger a `user-error' if called interactively
+or return nil if not.
+
+Interactively prompt for the file and whether to use the current
+position if a buffer is visiting the file; non-interactively, you may
+optionally provide the FILE and POS arguments.
+
+After successfully adding the path link, run `hywiki-add-referent-hook'.
+
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
+calling this function."
+ (interactive (list (or (hywiki-word-at)
+ (hywiki-word-read-new "Add/Edit HyWikiWord: "))))
+ (let* ((path-args (if (and file pos)
+ (list file pos)
+ (hactypes:link-to-file-interactively)))
+ (path-link (and (= (length path-args) 2)
+ (hpath:file-position-to-line-and-column
+ (car path-args) (cadr path-args)))))
+ (when path-link
+ (hywiki-add-referent wikiword (cons 'path-link path-link)))))
+
+(defun hywiki-display-path-link (_wikiword referent)
+ (funcall hywiki-display-page-function (cdr referent)))
(defun hywiki-add-sexpression (wikiword)
"Make WIKIWORD evaluate a prompted for sexpression and return it.
@@ -1092,32 +1153,35 @@ or return nil if not.
After successfully adding the sexpression, run `hywiki-add-referent-hook'.
-Use `hywiki-get-page' to determine whether WIKIWORD exists prior to
+Use `hywiki-get-referent' to determine whether WIKIWORD exists prior to
calling this function."
(interactive (list (or (hywiki-word-at)
(hywiki-word-read-new "Add/Edit HyWikiWord: "))))
- (hywiki-add-referent wikiword (read--expression "Sexpression: ")))
+ (hywiki-add-referent wikiword (cons 'sexpression
+ (read--expression "Sexpression: "))))
+
+(defun hywiki-display-sexpression (_wikiword referent)
+ (eval (cdr referent)))
(defun hywiki-add-to-referent (wikiword text position)
"Display WIKIWORD referent and insert TEXT at POSITION.
Create page if it does not exist. If WIKIWORD is invalid, return
-nil, else return the file name of the page."
- (let* ((referent (hywiki-add-page wikiword)))
- (when referent
- (hywiki-find-referent wikiword)
- (barf-if-buffer-read-only)
- (save-excursion
- (save-restriction
- (widen)
- (when position
- (goto-char position))
- (unless (bolp)
- (insert (newline)))
- (insert text)
- (unless (bolp)
- (insert (newline)))
- (when position
- (goto-char position)))))
+nil, else return '(page . \"<page-file-path>\")."
+ (when-let ((referent (hywiki-add-page wikiword)))
+ (hywiki-find-referent wikiword)
+ (barf-if-buffer-read-only)
+ (save-excursion
+ (save-restriction
+ (widen)
+ (when position
+ (goto-char position))
+ (unless (bolp)
+ (insert (newline)))
+ (insert text)
+ (unless (bolp)
+ (insert (newline)))
+ (when position
+ (goto-char position))))
referent))
(defun hywiki-at-tags-p (&optional at-tag-flag)
@@ -1165,7 +1229,7 @@ per file to the absolute value of MAX-MATCHES, if given
and not 0. If
(defun hywiki-maybe-at-wikiword-beginning ()
"Return non-nil if previous character is one preceding a HyWiki word.
Do not test whether or not a page exists for the HyWiki word.
-Use `hywiki-get-page' to determine whether a HyWiki page exists."
+Use `hywiki-get-referent' 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 "))
@@ -1234,16 +1298,18 @@ Use `dired' unless
`action-key-modeline-buffer-id-function' is set to
;;;###autoload
(defun hywiki-find-referent (&optional wikiword prompt-flag)
"Display optional HyWiki WIKIWORD referent or if nil, use current buffer.
-If called interactively, prompt for a new or existing WIKIWORD
-and use any prefix argument as PROMPT-FLAG.
+If called interactively, use the WIKIWORD at point or if none, prompt for
+an existing or new one. With a prefix arg PROMPT-FLAG, prompt for the
+type of referent to link to. See `hywiki-referent-menu' for valid
+referent types.
Return the referent if successfully found or nil otherwise.
-See `hywiki-referent-menu' for valid referent types.
+A valid referent is a cons of (<referent-type> . <referent-value>).
If the referent is a HyWiki page:
- Return the absolute path to any page successfully found; nil
- if failed or if displaying a regular file (read in via a
- `find-file' call).
+ Return a cons of the symbol 'page and the absolute path
+ to any page successfully found. Return nil if failed or
+ if displaying a regular file (read in via a `find-file' call).
By default, create any non-existent page. When not in batch
mode, with optional PROMPT-FLAG t or if this is the first
@@ -1259,7 +1325,6 @@ After successfully finding any kind of referent, run
(when current-prefix-arg t)))
(let ((referent (hywiki-display-referent wikiword prompt-flag)))
(run-hooks 'hywiki-find-referent-hook)
-
referent))
(defun hywiki-highlight-on-yank (_prop-value start end)
@@ -1289,40 +1354,43 @@ This includes the delimiters: (), {}, <>, [] and \"\"
(double quotes)."
;; Limit balanced pair checks to the next two lines for speed
(narrow-to-region (line-beginning-position) (line-end-position 2))
(let ((result (ignore-errors
- (cond ((memq (char-before) '(?\[ ?\<))
- (goto-char (1- (point)))
- (hywiki--get-delimited-range-forward))
- ((memq (char-after) '(?\[ ?\<))
- (hywiki--get-delimited-range-forward))
- ((memq (char-before) '(?\( ?\{))
- (goto-char (1- (point)))
- (list (point) (scan-sexps (point) 1)))
- ((memq (char-after) '(?\( ?\{))
- (list (point) (scan-sexps (point) 1)))
- ((and (eq (char-before) ?\")
- (hypb:in-string-p))
- (goto-char (1- (point)))
- (list (point) (scan-sexps (point) 1)))
- ((and (eq (char-after) ?\")
- (hypb:in-string-p))
- (goto-char (1+ (point)))
- (list (point) (scan-sexps (point) -1)))
- ((memq (char-before) '(?\] ?\>))
- (hywiki--get-delimited-range-backward))
- ((memq (char-after) '(?\] ?\>))
- (goto-char (1+ (point)))
- (hywiki--get-delimited-range-backward))
- ((memq (char-before) '(?\) ?\}))
- (list (point) (scan-sexps (point) -1)))
- ((memq (char-after) '(?\) ?\}))
- (goto-char (1+ (point)))
- (list (point) (scan-sexps (point) -1)))
- ((and (eq (char-before) ?\")
- (not (hypb:in-string-p)))
- (list (point) (scan-sexps (point) -1)))
- ((and (eq (char-after) ?\")
- (not (hypb:in-string-p)))
- (list (point) (scan-sexps (point) 1)))))))
+ (cond
+ ;; Handle opening delimiters
+ ((memq (char-before) '(?\[ ?\<))
+ (goto-char (1- (point)))
+ (hywiki--get-delimited-range-forward))
+ ((memq (char-after) '(?\[ ?\<))
+ (hywiki--get-delimited-range-forward))
+ ((memq (char-before) '(?\( ?\{))
+ (goto-char (1- (point)))
+ (list (point) (scan-sexps (point) 1)))
+ ((memq (char-after) '(?\( ?\{))
+ (list (point) (scan-sexps (point) 1)))
+ ((and (eq (char-before) ?\")
+ (hypb:in-string-p))
+ (goto-char (1- (point)))
+ (list (point) (scan-sexps (point) 1)))
+ ((and (eq (char-after) ?\")
+ (hypb:in-string-p))
+ (goto-char (1+ (point)))
+ (list (point) (scan-sexps (point) -1)))
+ ;; Handle closing delimiters
+ ((memq (char-before) '(?\] ?\>))
+ (hywiki--get-delimited-range-backward))
+ ((memq (char-after) '(?\] ?\>))
+ (goto-char (1+ (point)))
+ (hywiki--get-delimited-range-backward))
+ ((memq (char-before) '(?\) ?\}))
+ (list (point) (scan-sexps (point) -1)))
+ ((memq (char-after) '(?\) ?\}))
+ (goto-char (1+ (point)))
+ (list (point) (scan-sexps (point) -1)))
+ ((and (eq (char-before) ?\")
+ (not (hypb:in-string-p)))
+ (list (point) (scan-sexps (point) -1)))
+ ((and (eq (char-after) ?\")
+ (not (hypb:in-string-p)))
+ (list (point) (scan-sexps (point) 1)))))))
(if result
(sort result #'<)
(list nil nil))))))
@@ -1799,7 +1867,7 @@ value of `hywiki-word-highlight-flag' is changed."
(not (hywiki-directory-modified-p)))
(unless skip-lookups-update-flag
;; Rebuild lookup tables if any HyWiki page name has changed
- (hywiki-get-page-hasht))
+ (hywiki-get-referent-hasht))
(unwind-protect
(save-excursion
(save-restriction
@@ -1817,7 +1885,7 @@ value of `hywiki-word-highlight-flag' is changed."
;; Enable dehighlighting in HyWiki pages
(let ((hywiki-word-highlight-flag))
(hywiki-maybe-dehighlight-page-names))
- (dolist (hywiki-words-regexp hywiki--any-page-regexp-list)
+ (dolist (hywiki-words-regexp hywiki--any-wikiword-regexp-list)
(goto-char (point-min))
(let ((highlight-in-comments-only
(and (derived-mode-p 'prog-mode)
@@ -1891,12 +1959,12 @@ value of `hywiki-word-highlight-flag' is changed."
;; buffer. If this is a HyWiki page buffer, then dehighlight
;; when `hywiki-word-highlight-flag' is nil.
(hywiki-maybe-dehighlight-page-names region-start region-end))
- (unless (hyperb:stack-frame '(hywiki-maybe-highlight-page-names-in-frame))
+ (unless (hyperb:stack-frame '(hywiki-maybe-highlight-wikiwords-in-frame))
(hywiki-directory-set-mod-time)
(hywiki-directory-set-checksum))
nil)
-(defun hywiki-maybe-highlight-page-names-in-frame (frame &optional
skip-lookups-update-flag)
+(defun hywiki-maybe-highlight-wikiwords-in-frame (frame &optional
skip-lookups-update-flag)
"Highlight all non-Org link HyWiki page names displayed in FRAME.
If FRAME is t, then highlight in all windows across all frames, even
invisible ones. With optional SKIP-LOOKUPS-UPDATE-FLAG non-nil, HyWiki
@@ -1945,45 +2013,26 @@ value returns nil."
(if (string-suffix-p hywiki-file-suffix file-stem-name)
(expand-file-name file-stem-name hywiki-directory)
(concat (expand-file-name
- file-stem-name hywiki-directory) hywiki-file-suffix))))
+ file-stem-name hywiki-directory)
+ hywiki-file-suffix))))
(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'."
(when (and (stringp wikiword) (not (string-empty-p wikiword))
(string-match hywiki-word-with-optional-section-exact-regexp
wikiword))
- (let* ((section (when (match-string-no-properties 2 wikiword)
- (prog1 (substring wikiword (match-beginning 2))
- ;; Remove any #section suffix in `wikiword'.
- (setq wikiword (match-string-no-properties 1
wikiword)))))
+ (let* ((_section (when (match-string-no-properties 2 wikiword)
+ (prog1 (substring wikiword (match-beginning 2))
+ ;; Remove any #section suffix in `wikiword'.
+ (setq wikiword (match-string-no-properties 1
wikiword)))))
(referent (hash-get (hywiki-get-singular-wikiword wikiword)
- (hywiki-get-page-hasht))))
- (cond ((or (symbolp referent) (functionp referent)
- (and (consp referent)
- (symbolp (car referent))
- (fboundp (car referent))))
- ;; function or actype symbol
- ;; e.g. (kbd "key sequence")
- referent)
- ((stringp referent)
- (let ((case-fold-search t))
- (cond ((and (null referent) (stringp section)
- (string-match-p "^\\(#[^#]+\\)$" section))
- ;; "#in-buffer-section"
- section)
- ((string-match-p "^\\({.+}\\|\\(CUSTOM_\\)?ID:[
\t]+.+\\|<\\[.+\\]>\\|<(.+)>\\)$"
- referent)
- ;; "{key series}"
- ;; "ID: org-id"
- ;; "<(global explicit button name)>"
- ;; "<[global implicit button name]>"
- referent)
- ((string-match-p "^(.+).+$\\|.+\\.info\\([.#]\\|$\\)"
referent)
- ;; (info-manual)node-or-index-item
- referent)
- ;; path, expand to absolute
- (t (hywiki-get-file referent)))))
- (t nil)))))
+ (hywiki-get-referent-hasht)))
+ (referent-type (car referent))
+ (referent-value (cdr referent)))
+ (when (and (consp referent)
+ (symbolp referent-type)
+ (not (listp referent-value)))
+ referent))))
(defun hywiki-get-page-files ()
"Return the list of existing HyWiki page file names.
@@ -1995,42 +2044,44 @@ These must end with `hywiki-file-suffix'."
hywiki-directory nil (concat "^" hywiki-word-regexp
(regexp-quote hywiki-file-suffix) "$")))))
-(defun hywiki-get-page-hasht ()
- "Return hash table of existing HyWiki pages.
-May update the page hash table if out-of-date as well as the list of
-regexps of page names."
- (if (and hywiki--any-page-regexp-list
- (equal hywiki--pages-directory hywiki-directory)
- ;; If page files changed, have to rebuild page hash table
- (not (hywiki-directory-modified-p)))
- (or hywiki--pages-hasht (hywiki-make-pages-hasht))
- ;; Rebuild page hash table
- (hywiki-make-pages-hasht)
- ;; Compute these expensive regexps (matching 50
- ;; hywiki words at a time) only if the set of HyWiki
- ;; page names has changed in `hywiki-directory'.
- (setq hywiki--any-page-regexp-list
- (mapcar (lambda (page-sublist)
- ;; Add plurals to the list
- (setq page-sublist
- (delq nil (nconc page-sublist
- (mapcar #'hywiki-get-plural-wikiword
page-sublist))))
- (concat (regexp-opt page-sublist 'words)
- "\\("
- hywiki-word-section-regexp "?\\)"
- hywiki--buttonize-character-regexp))
- (hypb:split-seq-into-sublists
- (hash-map #'cdr hywiki--pages-hasht) 25)))
- (hywiki-maybe-highlight-page-names-in-frame t t)
- hywiki--pages-hasht))
-
-(defun hywiki-get-page-list ()
+(defun hywiki-get-referent-hasht ()
+ "Return hash table of existing HyWiki referents.
+May recreate the hash table as well as the list of
+regexps of wikiwords, if the hash table is out-of-date."
+ (prog1
+ (if (and (equal hywiki--pages-directory hywiki-directory)
+ ;; If page files changed, have to rebuild referent hash table
+ (not (hywiki-directory-modified-p))
+ hywiki--referent-hasht)
+ hywiki--referent-hasht
+ (setq hywiki--any-wikiword-regexp-list nil)
+ ;; Rebuild referent hash table
+ (hywiki-make-referent-hasht))
+ (unless hywiki--any-wikiword-regexp-list
+ ;; Compute these expensive regexps (matching 50
+ ;; hywiki words at a time) only if the set of
+ ;; HyWikiWords changed in `hywiki-directory'.
+ (setq hywiki--any-wikiword-regexp-list
+ (mapcar (lambda (wikiword-sublist)
+ ;; Add plurals to the list
+ (setq wikiword-sublist
+ (delq nil (nconc wikiword-sublist
+ (mapcar
#'hywiki-get-plural-wikiword wikiword-sublist))))
+ (concat (regexp-opt wikiword-sublist 'words)
+ "\\("
+ hywiki-word-section-regexp "?\\)"
+ hywiki--buttonize-character-regexp))
+ (hypb:split-seq-into-sublists
+ (hash-map #'cdr hywiki--referent-hasht) 25)))
+ (hywiki-maybe-highlight-wikiwords-in-frame t t))))
+
+(defun hywiki-get-wikiword-list ()
"Return a list of the HyWiki page names."
- (hash-map #'cdr (hywiki-get-page-hasht)))
+ (hash-map #'cdr (hywiki-get-referent-hasht)))
(defun hywiki-get-wikiwords-obarray ()
"Return an obarray of existing HyWikiWords."
- (cdr (hywiki-get-page-hasht)))
+ (cdr (hywiki-get-referent-hasht)))
(defun hywiki-get-plural-wikiword (wikiword)
"Return the pluralized version of the given WIKIWORD.
@@ -2077,14 +2128,14 @@ If deleted, update HyWikiWord highlighting across all
frames."
(delete-file buffer-file-name))
(when (hywiki-directory-modified-p)
;; Rebuild lookup tables if any HyWiki page name has changed
- (hywiki-get-page-hasht)
+ (hywiki-get-referent-hasht)
t)
nil))
-(defun hywiki-clear-pages-hasht ()
+(defun hywiki-clear-referent-hasht ()
"Clear all elements from the HyWiki referent hash table and return it."
- (setq hywiki--pages-hasht nil
- hywiki--any-page-regexp-list nil))
+ (setq hywiki--referent-hasht nil
+ hywiki--any-wikiword-regexp-list nil))
(eval-and-compile
'(when (featurep 'company)
@@ -2098,36 +2149,35 @@ If deleted, update HyWikiWord highlighting across all
frames."
('candidates
(let ((prefix (company-grab-word)))
(when prefix
- (cl-loop for key being the hash-keys in (hywiki-get-page-list)
+ (cl-loop for key being the hash-keys in
(hywiki-get-wikiword-list)
when (string-prefix-p prefix key)
collect key))))
('sorted t))))))
-(defun hywiki-make-pages-hasht ()
+(defun hywiki-make-referent-hasht ()
+ "Rebuld referent hasht from list of HyWiki page files and non-page entries."
(let* ((page-files (hywiki-get-page-files))
- (non-page-elts (when (hashp hywiki--pages-hasht)
+ (non-page-elts (when (hashp hywiki--referent-hasht)
(delq nil
- (hash-map #''hywiki-non-page-elts
- hywiki--pages-hasht))))
+ (hash-map 'hywiki-non-page-elt
+ hywiki--referent-hasht))))
(non-page-hasht (hash-make non-page-elts))
(key)
(page-elts (delq nil (mapcar (lambda (file)
(setq key (file-name-sans-extension
file))
(unless (hash-get key non-page-hasht)
- (cons file key)))
+ (cons (cons 'page file) key)))
page-files))))
- (setq hywiki--any-page-regexp-list nil
+ (setq hywiki--any-wikiword-regexp-list nil
hywiki--pages-directory hywiki-directory
- hywiki--pages-hasht (hash-merge (hash-make non-page-elts)
- (hash-make page-elts)))))
+ hywiki--referent-hasht
+ (if non-page-elts
+ (hash-merge non-page-hasht
+ (hash-make page-elts))
+ (hash-make page-elts)))))
-(defun hywiki-non-page-elts (val-key)
- (let ((suffix-regexp (concat (regexp-quote hywiki-file-suffix) "$"))
- value)
- (setq value (car val-key))
- (unless (and (stringp value)
- (string-match-p suffix-regexp value))
- val-key)))
+(defun hywiki-non-page-elt (val-key)
+ (unless (eq (caar val-key) 'page) val-key))
(defun hywiki-org-export-function (&rest _)
"Add to `write-contents-functions' to convert HyWikiWord links to Org links.
@@ -2193,8 +2243,10 @@ backend."
(defun hywiki-org-link-resolve (link &optional full-data)
"Resolve HyWiki word LINK to page, with or without additional section.
-With optional FULL-DATA non-nil, return a list in the form of (path
-word section). If page is not found, return nil."
+With optional FULL-DATA non-nil, return a list in the form of (filename
+word section); otherwise, with a section, return filename::section and
+without a section, return just filename. Filename excludes the path.
+If page is not found, return nil."
(when (stringp link)
(when (string-match (concat "\\`" hywiki-org-link-type ":") link)
;; Remove hy: link prefix
@@ -2204,14 +2256,15 @@ word section). If page is not found, return nil."
(word (if (and section (not (string-empty-p section)))
(substring link 0 (match-beginning 0))
link))
- (path (and word (hywiki-get-referent word))))
- (when path
+ (referent (and word (hywiki-get-referent word)))
+ (filename (cdr referent)))
+ (when (stringp filename)
(cond
(full-data
- (list path word section))
+ (list filename word section))
((and section (not (string-empty-p section)))
- (concat path "::" section))
- (t path))))))
+ (concat filename "::" section))
+ (t filename))))))
(defun hywiki-org-link-store ()
"Store a link to a HyWiki word at point, if any."
@@ -2353,6 +2406,17 @@ optional VIEW-BUFFER-NAME, use that rather than the
default,
,org-agenda-buffer-name)))
(forward-line 2))))
+(defun hywiki-validate-referent (referent)
+ "Return t if REFERENT is valid, otherwise trigger an error."
+ (if (and (consp referent)
+ (symbolp (car referent))
+ (cdr referent))
+ t
+ (error (concat "(hywiki-add-referent): Invalid referent"
+ "\n must be a cons of (<type-symbol) . <value>)"
+ "\n not %S")
+ referent)))
+
(defun hywiki-word-activate (&optional arg)
"Display HyWiki referent for wikiword at point.
If referent is a non-existent HyWiki page, create it. When this
@@ -2464,8 +2528,8 @@ Search across `hywiki-directory'."
(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.
+WORD may not yet have a referent (non-existent). Use `hywiki-get-referent'
+to determine whether a HyWikiWord referent exists.
Return nil if WORD is a prefixed, typed hy:HyWikiWord, since
these are handled by the Org mode link handler."
@@ -2502,18 +2566,18 @@ Highlight/dehighlight HyWiki page names across all
frames on change."
(add-hook 'post-command-hook
'hywiki-buttonize-non-character-commands 95)
(add-hook 'post-self-insert-hook
'hywiki-buttonize-character-commands)
(add-hook 'window-buffer-change-functions
- 'hywiki-maybe-highlight-page-names-in-frame)
+ 'hywiki-maybe-highlight-wikiwords-in-frame)
(add-to-list 'yank-handled-properties
'(hywiki-word-face . hywiki-highlight-on-yank))
- (hywiki-maybe-highlight-page-names-in-frame t))
+ (hywiki-maybe-highlight-wikiwords-in-frame t))
;; disabled
(remove-hook 'pre-command-hook
'hywiki-debuttonize-non-character-commands)
(remove-hook 'post-command-hook
'hywiki-buttonize-non-character-commands)
(remove-hook 'post-self-insert-hook 'hywiki-buttonize-character-commands)
(hywiki-mode 0) ;; also dehighlights HyWiki words outside of HyWiki pages
(remove-hook 'window-buffer-change-functions
- 'hywiki-maybe-highlight-page-names-in-frame)
- (hywiki-maybe-highlight-page-names-in-frame t)
+ 'hywiki-maybe-highlight-wikiwords-in-frame)
+ (hywiki-maybe-highlight-wikiwords-in-frame t)
(setq yank-handled-properties
(delete '(hywiki-word-face . hywiki-highlight-on-yank)
yank-handled-properties)))))
@@ -2530,7 +2594,7 @@ Otherwise, return nil."
(and (char-after)
(goto-char (1+ (point)))
(eq (char-before) (char-before (1- (point))))))
- (sort (list (point) (scan-sexps (point) -1)) #'<))))
+ (nreverse (list (point) (scan-sexps (point) -1))))))
(defun hywiki--get-delimited-range-forward ()
"Return a list of (start end) if not between/before opening [[ or <<.
@@ -2590,14 +2654,14 @@ DIRECTION-NUMBER is 1 for forward scanning and -1 for
backward scanning."
(let* ((sexp-start (point))
(sexp-end (scan-sexps sexp-start direction-number)))
(when (and sexp-start sexp-end)
- (cl-destructuring-bind (sexp-start sexp-end)
+ (cl-destructuring-bind (start end)
;; Point may be at end of sexp, so start and end may
;; need to be reversed
(list (min sexp-start sexp-end) (max sexp-start sexp-end))
;; Increment sexp-start so regexp matching excludes the
;; delimiter and starts with the page name. But include any
;; trailing delimiter or regexp matching will not work
- (funcall func (1+ sexp-start) sexp-end)
+ (funcall func (1+ start) end)
(setq hywiki--highlighting-done-flag nil)))))
;;; ************************************************************************
diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el
index ed925c99f2..5593d3d3fc 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: 22-Dec-24 at 16:22:44 by Bob Weiner
+;; Last-Mod: 26-Dec-24 at 22:49:26 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -24,7 +24,7 @@
(require 'hywiki)
(require 'ox-publish)
-(ert-deftest hywiki-tests--hywiki-add-page--adds-file-in-wiki-folder ()
+(ert-deftest hywiki-tests--hywiki-create-page--adds-file-in-wiki-folder ()
"Verify add page creates file in wiki folder and sets hash table."
(let* ((hsys-org-enable-smart-keys t)
(hywiki-directory (make-temp-file "hywiki" t))
@@ -32,16 +32,16 @@
(unwind-protect
(progn
(should (string= hywiki-page-file
- (hywiki-add-page "WikiWord")))
+ (cdr (hywiki-add-page "WikiWord"))))
;; Verify hash table is updated
(with-mock
- (not-called hywiki-add-page)
- (should (string= hywiki-page-file
- (hywiki-get-referent "WikiWord")))))
+ (not-called hywiki-create-page)
+ (should (string= (file-name-nondirectory hywiki-page-file)
+ (cdr (hywiki-get-referent "WikiWord"))))))
(hy-delete-file-and-buffer hywiki-page-file)
(hy-delete-dir-and-buffer hywiki-directory))))
-(ert-deftest hywiki-tests--hywiki-add-page--adds-no-wiki-word-fails ()
+(ert-deftest hywiki-tests--hywiki-create-page--adds-no-wiki-word-fails ()
"Verify add page requires a WikiWord."
;; Should not leave erroneously created file after test but leaving
;; added error cleanup till later if it is even needed!? No file
@@ -49,27 +49,25 @@
;; considered an error case that is.)
(let ((hywiki-directory (make-temp-file "hywiki" t)))
(unwind-protect
- (should-not (hywiki-add-page "notawikiword"))
+ (should-not (cdr (hywiki-add-page "notawikiword")))
(hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--action-key-on-wikiword-displays-page ()
"Verify `action-key' on a prefixed WikiWord, outside of hywiki-directory,
creates a new page."
- (defvar wikifile)
(let ((hsys-org-enable-smart-keys t)
(hywiki-directory (make-temp-file "hywiki" t))
- (wikifile (make-temp-file "wikifile" nil ".org")))
+ (wikifile "WikiWord.org"))
(unwind-protect
(with-temp-buffer
(hywiki-mode 1)
(insert "[[hy:WikiWord]]")
(goto-char 4)
- (mocklet (((hywiki-display-referent "WikiWord" nil) => wikifile))
- (action-key)))
+ (action-key)
+ (should (equal (cons 'page wikifile) (hywiki-get-referent
"WikiWord"))))
(hy-delete-file-and-buffer wikifile))))
(ert-deftest hywiki-tests--assist-key-on-wikiword-displays-help ()
"Verify `assist-key' on a prefixed WikiWord, outside of hywiki-directory,
displays help for the WikiWord link."
- (defvar wikifile)
(let ((hsys-org-enable-smart-keys t)
(hywiki-directory (make-temp-file "hywiki" t))
(wikifile (make-temp-file "wikifile" nil ".org")))
@@ -170,7 +168,7 @@
(ert-deftest hywiki-tests--in-page-p ()
"Verify `hywiki-in-page-p' identifies a page in and outside of the wiki
directory."
(let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wiki-page (hywiki-add-page "WikiWord"))
+ (wiki-page (cdr (hywiki-add-page "WikiWord")))
(no-wiki-page (make-temp-file "hypb")))
(unwind-protect
(progn
@@ -184,7 +182,7 @@
(ert-deftest hywiki-tests--active-in-current-buffer-p ()
"Verify `hywiki-active-in-current-buffer-p'."
(let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wiki-page (hywiki-add-page "WikiWord"))
+ (wiki-page (cdr (hywiki-add-page "WikiWord")))
(hywiki-word-highlight-flag t))
(unwind-protect
(with-current-buffer (find-file-noselect wiki-page)
@@ -241,76 +239,78 @@ Both mod-time and checksum must be changed for a test to
return true."
(should (hywiki-directory-modified-p)))))
(ert-deftest hywiki-tests--get-page-list ()
- "Verify `hywiki-get-page-list' returns one WikiWord."
+ "Verify `hywiki-get-wikiword-list' returns one WikiWord."
(let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wiki-page (hywiki-add-page "WikiWord")))
+ (wiki-page (cdr (hywiki-add-page "WikiWord"))))
(unwind-protect
(progn
- (should (equal '("WikiWord") (hywiki-get-page-list)))
- (should (equal wiki-page (hywiki-add-page "WikiWord")))
- (should (equal '("WikiWord") (hywiki-get-page-list))))
+ (should (equal '("WikiWord") (hywiki-get-wikiword-list)))
+ (should (equal wiki-page (cdr (hywiki-add-page "WikiWord"))))
+ (should (equal '("WikiWord") (hywiki-get-wikiword-list))))
(hy-delete-file-and-buffer wiki-page)
(hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--get-page-list-after-add-and-delete ()
- "Verify `hywiki-get-page-list' is updated when a page is added and removed."
+ "Verify `hywiki-get-wikiword-list' is updated when a page is added and
removed."
(let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wiki-page (hywiki-add-page "WordOne")))
+ (wiki-page (cdr (hywiki-add-page "WordOne"))))
(unwind-protect
- (let ((wiki-page2 (hywiki-add-page "WordTwo")))
+ (let ((wiki-page2 (cdr (hywiki-add-page "WordTwo"))))
(unwind-protect
(should (set:equal '("WordOne" "WordTwo")
- (hywiki-get-page-list)))
+ (hywiki-get-wikiword-list)))
;; This delay is necessary or the test can fail sporadically
(sit-for 0.01)
(hy-delete-file-and-buffer wiki-page2))
- (should (set:equal '("WordOne") (hywiki-get-page-list))))
+ (should (set:equal '("WordOne") (hywiki-get-wikiword-list))))
(hy-delete-file-and-buffer wiki-page)
(hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--get-page-list-multiple-words ()
- "Verify `hywiki-get-page-list' returns multiple WikiWords."
+ "Verify `hywiki-get-wikiword-list' returns multiple WikiWords."
(let* ((hywiki-directory (make-temp-file "hywiki" t))
(basename "WikiWord")
(wiki-page-list nil))
(unwind-protect
(progn
(dolist (char '("A" "B" "C" "D" "E" "F" "G" "H" "I" "J"))
- (push (hywiki-add-page (format "%s%s" basename char))
wiki-page-list))
+ (push (cdr (hywiki-add-page (format "%s%s" basename char)))
+ wiki-page-list))
(should (= 10 (length wiki-page-list)))
- (should (= 10 (length (hywiki-get-page-list))))
- (should (= 10 (length (seq-uniq (hywiki-get-page-list))))))
+ (should (= 10 (length (hywiki-get-wikiword-list))))
+ (should (= 10 (length (seq-uniq (hywiki-get-wikiword-list))))))
(hy-delete-files-and-buffers wiki-page-list)
(hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--get-page-list-when-new-wiki-directory ()
- "Verify `hywiki-get-page-list' is empty for new `hywiki-directory'."
+ "Verify `hywiki-get-wikiword-list' is empty for new `hywiki-directory'."
(let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wikipage (hywiki-add-page "WikiWord")))
+ (wikipage (cdr (hywiki-add-page "WikiWord"))))
(unwind-protect
(progn
- (should (= 1 (length (hywiki-get-page-list))))
+ (should (= 1 (length (hywiki-get-wikiword-list))))
(let ((hywiki-directory (make-temp-file "hywiki" t)))
(unwind-protect
(progn
- (should (= 0 (length (hywiki-get-page-list)))))
+ (should (= 0 (length (hywiki-get-wikiword-list)))))
(hy-delete-dir-and-buffer hywiki-directory))))
(hy-delete-file-and-buffer wikipage)
(hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest
hywiki-tests--get-page-list-for-new-wiki-directory-after-added-referent ()
- "Verify `hywiki-get-page-list' is empty for new `hywiki-directory'."
+ "Verify `hywiki-get-wikiword-list' is empty for new `hywiki-directory'."
(defvar hywiki-add-referent-hook)
(let ((hywiki-directory (make-temp-file "hywiki" t))
+ (referent '(page . "/tmp/a.org"))
(hywiki-add-referent-hook 'test-func))
(unwind-protect
(progn
(mocklet (((test-func) => t))
- (should (eq 'referent (hywiki-add-referent "WikiWord" 'referent))))
- (should (= 1 (length (hywiki-get-page-list))))
+ (should (equal referent (hywiki-add-referent "WikiWord"
referent))))
+ (should (= 1 (length (hywiki-get-wikiword-list))))
(let ((hywiki-directory (make-temp-file "hywiki" t)))
(unwind-protect
- (should (= 0 (length (hywiki-get-page-list))))
+ (should (zerop (length (hywiki-get-wikiword-list))))
(hy-delete-dir-and-buffer hywiki-directory))))
(hy-delete-dir-and-buffer hywiki-directory))))
@@ -323,7 +323,7 @@ Both mod-time and checksum must be changed for a test to
return true."
(add-hook 'post-command-hook 'hywiki-buttonize-non-character-commands 95)
(add-hook 'post-self-insert-hook 'hywiki-buttonize-character-commands)
(add-hook 'window-buffer-change-functions
- 'hywiki-maybe-highlight-page-names-in-frame)
+ 'hywiki-maybe-highlight-wikiwords-in-frame)
(add-to-list 'yank-handled-properties
'(hywiki-word-face . hywiki-highlight-on-yank)))
@@ -333,7 +333,7 @@ Both mod-time and checksum must be changed for a test to
return true."
(remove-hook 'post-command-hook 'hywiki-buttonize-non-character-commands)
(remove-hook 'post-self-insert-hook 'hywiki-buttonize-character-commands)
(remove-hook 'window-buffer-change-functions
- 'hywiki-maybe-highlight-page-names-in-frame)
+ 'hywiki-maybe-highlight-wikiwords-in-frame)
(setq yank-handled-properties
(delete '(hywiki-word-face . hywiki-highlight-on-yank)
yank-handled-properties)))
@@ -360,7 +360,7 @@ Both mod-time and checksum must be changed for a test to
return true."
(skip-unless (not noninteractive))
(let* ((hsys-org-enable-smart-keys t)
(hywiki-directory (make-temp-file "hywiki" t))
- (wikipage (hywiki-add-page "WikiWord")))
+ (wikipage (cdr (hywiki-add-page "WikiWord"))))
(unwind-protect
(progn
(hywiki-tests--remove-hywiki-hooks)
@@ -403,7 +403,7 @@ Both mod-time and checksum must be changed for a test to
return true."
"Verify face property changes when WikiWord is edited."
(skip-unless (not noninteractive))
(let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wikipage (hywiki-add-page "WikiWord")))
+ (wikipage (cdr (hywiki-add-page "WikiWord"))))
(unwind-protect
(progn
(hywiki-tests--remove-hywiki-hooks)
@@ -430,7 +430,7 @@ Both mod-time and checksum must be changed for a test to
return true."
(ert-deftest
hywiki-tests--verify-face-property-when-editing-wikiword-first-char ()
"Verify face property changes when WikiWord is edited in the first char
position."
(let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wikipage (hywiki-add-page "WikiWord")))
+ (wikipage (cdr (hywiki-add-page "WikiWord"))))
(skip-unless (not noninteractive))
(unwind-protect
(progn
@@ -460,7 +460,7 @@ Both mod-time and checksum must be changed for a test to
return true."
"Verify `hywiki-convert-words-to-org-links' converts WikiWords to org links."
(skip-unless (not noninteractive))
(let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wikipage (hywiki-add-page "WikiWord")))
+ (wikipage (cdr (hywiki-add-page "WikiWord"))))
(unwind-protect
(progn
(hywiki-tests--remove-hywiki-hooks)
@@ -526,40 +526,43 @@ Both mod-time and checksum must be changed for a test to
return true."
(should-not (hywiki-org-link-resolve 88)) ; Number
(should-not (hywiki-org-link-resolve '("string"))) ; List
(let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wikipage (hywiki-add-page "WikiWord")))
+ (wikipage (cdr (hywiki-add-page "WikiWord")))
+ (filename (when wikipage (file-name-nondirectory wikipage))))
(unwind-protect
(progn
(should-not (hywiki-org-link-resolve "NoWikiWord"))
- (should (string= wikipage (hywiki-org-link-resolve "WikiWord")))
- (should (string= wikipage (hywiki-org-link-resolve "hy:WikiWord")))
- (should (string= (concat wikipage "::section")
(hywiki-org-link-resolve "WikiWord#section"))))
+ (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")))))
(hy-delete-file-and-buffer wikipage)
(hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--org-link-export ()
"Verify `hywiki-org-link-export' output for different formats."
(let* ((hywiki-directory (make-temp-file "hywiki" t))
- (wikipage (hywiki-add-page "WikiWord")))
+ (wikipage (cdr (hywiki-add-page "WikiWord")))
+ (filename (when wikipage (file-name-nondirectory wikipage))))
(unwind-protect
(progn
(should (string-match-p
- (format "\\[hy\\] <doc:.*%s>" wikipage)
+ (format "\\[hy\\] <doc:.*%s>" filename)
(hywiki-org-link-export "WikiWord" "doc" 'ascii)))
(should (string-match-p
(format "<a href=\".*%s\">doc</a>"
- (replace-regexp-in-string "\\.org" ".html"
wikipage))
+ (replace-regexp-in-string "\\.org" ".html"
filename))
(hywiki-org-link-export "WikiWord" "doc" 'html)))
(should (string-match-p
- (format "\\[doc\\](.*%s)" wikipage)
+ (format "\\[doc\\](.*%s)" filename)
(hywiki-org-link-export "WikiWord" "doc" 'md)))
(should (string-match-p
- (format "\\href{.*%s}{doc}" wikipage)
+ (format "\\href{.*%s}{doc}" filename)
(hywiki-org-link-export "WikiWord" "doc" 'latex)))
(should (string-match-p
- (format "@uref{.*%s,doc}" wikipage)
+ (format "@uref{.*%s,doc}" filename)
(hywiki-org-link-export "WikiWord" "doc" 'texinfo)))
(should (string-match-p
- (format ".*%s" wikipage)
+ (format ".*%s" filename)
(hywiki-org-link-export "WikiWord" "doc" 'unknown)))
(should (string= "NotAWikiPage" (hywiki-org-link-export
"NotAWikiPage" "doc" 'ascii))))
(hy-delete-file-and-buffer wikipage)
@@ -587,14 +590,14 @@ Note special meaning of `hywiki-allow-plurals-flag'."
(ert-deftest hywiki-tests--add-referent ()
"Verify `hywiki-add-referent'."
(defvar hywiki-add-referent-hook)
- (let ((hywiki-directory (make-temp-file "hywiki" t))
- (hywiki-add-referent-hook 'test-func))
+ (let* ((hywiki-directory (make-temp-file "hywiki" t))
+ (file "/tmp/a.org")
+ (referent (cons 'page file)))
(unwind-protect
(progn
- (should-not (hywiki-add-referent "notawikiword" 'referent))
- (mocklet (((test-func) => t))
- (should (eq 'referent (hywiki-add-referent "WikiWord" 'referent))))
- (should (eq 'referent (hywiki-get-referent "WikiWord"))))
+ (should-not (hywiki-add-referent "notawikiword" referent))
+ (should (hywiki-add-referent "WikiWord" referent))
+ (should (equal referent (hywiki-get-referent "WikiWord"))))
(hy-delete-dir-and-buffer hywiki-directory))))
;; hywiki-add-activity -- Requires activities
@@ -605,63 +608,90 @@ Note special meaning of `hywiki-allow-plurals-flag'."
(unwind-protect
(progn
(mocklet ((bookmark-completing-read => ""))
- (should-error (hywiki-add-bookmark "WikiWord"))))
- (mocklet ((bookmark-completing-read => 'bkmark))
- (should (equal '(bookmark-jump bkmark) (caddr (hywiki-add-bookmark
"WikiWord")))))
+ (should-error (hywiki-add-bookmark "WikiWord")))
+ (mocklet ((bookmark-completing-read => "bkmark"))
+ (should (equal '(bookmark . "bkmark") (hywiki-add-bookmark
"WikiWord")))))
(hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--add-command ()
"Verify `hywiki-add-command'."
- (mocklet ((hui:actype => 'command)
- ((hywiki-add-referent "WikiWord" 'command) => 'command))
- (should (eq 'command (hywiki-add-command "WikiWord")))))
+ (let ((hywiki-directory (make-temp-file "hywiki" t))
+ (wikiword "WikiWord"))
+ (unwind-protect
+ (mocklet ((hui:actype => 'hpath:find))
+ (hywiki-add-command wikiword)
+ (should (equal '(command . hpath:find)
+ (hywiki-get-referent wikiword))))
+ (hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--add-find ()
"Verify `hywiki-add-find'."
- (mocklet (((hywiki-add-referent "WikiWord" #'hywiki-word-grep) =>
'word-grep))
- (should (eq 'word-grep (hywiki-add-find "WikiWord")))))
+ (let* ((wikiword "WikiWord")
+ (referent '(find . hywiki-word-grep)))
+ (hywiki-add-find wikiword)
+ (should (equal referent (hywiki-get-referent wikiword)))))
(ert-deftest hywiki-tests--add-global-button ()
"Verify `hywiki-add-global-button'."
- (mocklet ((hargs:read-match => "gbtn")
- ((hywiki-add-referent "WikiWord" '(gbut:act "gbtn")) =>
'gbut-referent))
- (should (equal 'gbut-referent (hywiki-add-global-button "WikiWord")))))
+ (let ((hywiki-directory (make-temp-file "hywiki" t)))
+ (unwind-protect
+ (mocklet ((hargs:read-match => "gbtn"))
+ (should (equal '(global-button . "gbtn") (hywiki-add-global-button
"WikiWord"))))
+ (hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--add-hyrolo ()
"Verify `hywiki-add-hyrolo'."
- (mocklet (((hywiki-add-referent "WikiWord" '(hyrolo-fgrep "WikiWord")) =>
'hyrolo-referent))
- (should (equal 'hyrolo-referent (hywiki-add-hyrolo "WikiWord")))))
+ (let ((hywiki-directory (make-temp-file "hywiki" t)))
+ (unwind-protect
+ (progn
+ (hywiki-add-hyrolo "WikiWord")
+ (should (equal '(hyrolo . hyrolo-fgrep) (hywiki-get-referent
"WikiWord"))))
+ (hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--add-info-index ()
"Verify `hywiki-add-info-index'."
- (mocklet (((info) => t)
- ((Info-read-index-item-name "Info index item: ") => "index-name")
- ((Info-current-filename-sans-extension) => "info")
- ((hywiki-add-referent "WikiWord" '(Info-goto-node
"(info)index-name")) => 'info-referent))
- (should (equal 'info-referent (hywiki-add-info-index "WikiWord")))))
+ (let ((hywiki-directory (make-temp-file "hywiki" t)))
+ (unwind-protect
+ (mocklet (((info) => t)
+ ((Info-read-index-item-name "Info index item: ") =>
"index-name")
+ ((Info-current-filename-sans-extension) => "info"))
+ (hywiki-add-info-index "WikiWord")
+ (should (equal '(info-index . "(info)index-name")
(hywiki-get-referent "WikiWord"))))
+ (hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--add-info-node ()
"Verify `hywiki-add-info-node'."
- (mocklet (((info) => t)
- ((Info-read-node-name "Info node: ") => "node-name")
- ((Info-current-filename-sans-extension) => "info")
- ((hywiki-add-referent "WikiWord" '(Info-goto-node
"(info)node-name")) => 'info-referent))
- (should (equal 'info-referent (hywiki-add-info-node "WikiWord")))))
+ (let ((hywiki-directory (make-temp-file "hywiki" t)))
+ (unwind-protect
+ (mocklet (((info) => t)
+ ((Info-read-node-name "Info node: ") => "node-name")
+ ((Info-current-filename-sans-extension) => "info"))
+ (hywiki-add-info-node "WikiWord")
+ (should (equal '(info-node . "(info)node-name") (hywiki-get-referent
"WikiWord"))))
+ (hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--add-key-series ()
"Verify `hywiki-add-key-series'."
- (mocklet (((hywiki-add-referent "WikiWord" "{ABC}") => 'key-series-referent))
- (with-simulated-input "ABC RET"
- (should (equal 'key-series-referent (hywiki-add-key-series "WikiWord"))))
- (with-simulated-input "{ABC} RET"
- (should (equal 'key-series-referent (hywiki-add-key-series
"WikiWord"))))))
-
-(ert-deftest hywiki-tests--add-link ()
- "Verify `hywiki-add-link'."
- (mocklet (((hactypes:link-to-file-interactively) => '("file" 20))
- ((hpath:file-position-to-line-and-column "file" 20) =>
"file:L2:C3")
- ((hywiki-add-referent "WikiWord" "file:L2:C3") => 'path-referent))
- (should (equal 'path-referent (hywiki-add-link "WikiWord")))))
+ (let ((hywiki-directory (make-temp-file "hywiki" t)))
+ (unwind-protect
+ (progn
+ (with-simulated-input "ABC RET"
+ (hywiki-add-key-series "WikiWord")
+ (should (equal '(key-series . "{ABC}") (hywiki-get-referent
"WikiWord"))))
+ (with-simulated-input "{ABC} RET"
+ (hywiki-add-key-series "WikiWord")
+ (should (equal '(key-series . "{ABC}") (hywiki-get-referent
"WikiWord")))))
+ (hy-delete-dir-and-buffer hywiki-directory))))
+
+(ert-deftest hywiki-tests--add-path-link ()
+ "Verify `hywiki-add-path-link'."
+ (let ((hywiki-directory (make-temp-file "hywiki" t))
+ (wikiword "WikiWord"))
+ (unwind-protect
+ (progn (hywiki-add-path-link wikiword "file" 20)
+ (should (equal '(path-link . "file:L1")
+ (hywiki-get-referent wikiword))))
+ (hy-delete-dir-and-buffer hywiki-directory))))
(ert-deftest hywiki-tests--add-org-id ()
"Verify `hywiki-add-org-id'."
@@ -687,10 +717,10 @@ Note special meaning of `hywiki-allow-plurals-flag'."
(goto-char (point-max))
(setq buffer-read-only nil)
(defvar hywiki-test--org-id)
- (let ((result (hywiki-add-org-id "WikiWord")))
- (if (stringp result)
- (should (string-prefix-p "ID: " result))
- (error "(hywiki-tests--add-org-id): result value is a
non-string: %s" result)))))
+ (let ((referent-value (cdr (hywiki-add-org-id "WikiWord"))))
+ (if (stringp referent-value)
+ (should (string-prefix-p "ID: " referent-value))
+ (error "(hywiki-tests--add-org-id): referent value is a
non-string: %s" referent-value)))))
(hy-delete-file-and-buffer filea))))
;; hywiki-add-org-roam-node -- Requires org-roam
- [elpa] externals/hyperbole updated (4f8fa6f04d -> 4155006fb4), ELPA Syncer, 2024/12/27
- [elpa] externals/hyperbole bf53ae2171 2/6: hasht.el - Rewrite to use Emacs built-in hash tables, ELPA Syncer, 2024/12/27
- [elpa] externals/hyperbole 79441e9b4a 4/6: hywiki.el - Rewrite to standardize all referents to (type . value),
ELPA Syncer <=
- [elpa] externals/hyperbole 349ffa1ea9 5/6: Merge branch 'master' into rsw and fix a few tests, ELPA Syncer, 2024/12/27
- [elpa] externals/hyperbole 0a6b11fcea 3/6: ibut:create - Display any itype error in *Messages* buffer, ELPA Syncer, 2024/12/27
- [elpa] externals/hyperbole 7f06e076aa 1/6: Fix "pcomplete" cyclic dep errors in Hyperbole tests on on rsw sys, ELPA Syncer, 2024/12/27
- [elpa] externals/hyperbole 4155006fb4 6/6: Merge pull request #629 from rswgnu/rsw, ELPA Syncer, 2024/12/27