Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
2026-03-21 Bob Weiner <rsw@gnu.org>

* hypb.el (hypb:grep-has-pcre-p, hypb:ripgrep-has-pcre-p): Add.
hywiki.el (hywiki-consult-backlink): Add and use call
above functions.
(hywiki-word-grep): Call above function instead of
obsolete 'hywiki-word-consult-grep'.
(hywiki-word-consult-grep): Remove. Replaced by backlink
function.
hui-mini.el (hui:menu-hywiki):
hui-menu.el (hui-menu-hywiki): Add Backlinks menu item and remove
WikiWordConsult / HyWiki-Word-Consult menu items since Backlinks
replaces them.

* test/hywiki-tests.el (hywiki-tests--referent-test): Remove these
lines for testing the cache every time this is called. Test
that in a single test instead.
Expand Down
8 changes: 4 additions & 4 deletions hui-menu.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 28-Oct-94 at 10:59:44
;; Last-Mod: 30-Nov-25 at 17:56:58 by Bob Weiner
;; Last-Mod: 22-Mar-26 at 01:23:25 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -307,6 +307,8 @@ Return t if cutoff, else nil."
["Manual" (id-info "(hyperbole)HyWiki") t]
"----"
["Activate-HyWiki-Word" hywiki-word-activate t]
(when (fboundp 'consult-grep) ;; allow for autoloading
["Backlink-To" hywiki-consult-backlink t])
["Create-HyWiki-Word" hywiki-word-create-and-display t]
["Dired-HyWiki-Pages" hywiki-directory-edit t]
["Find-HyWiki-Page" hywiki-find-page t]
Expand All @@ -327,9 +329,7 @@ Return t if cutoff, else nil."
["HyWiki-Tag-Find" hywiki-tags-view t]
["Insert-HyWiki-Link" hywiki-insert-link t]
hui-menu-org-meta-return-options
["Publish-HyWiki" hywiki-publish-to-html t]
(when (fboundp 'consult-grep) ;; allow for autoloading
["HyWiki-Word-Consult" hywiki-word-consult-grep t])))
["Publish-HyWiki" hywiki-publish-to-html t]))
"Menu items for HyWiki editing and publishing.")

(defvar infodock-hyperbole-menu nil)
Expand Down
12 changes: 6 additions & 6 deletions hui-mini.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 15-Oct-91 at 20:13:17
;; Last-Mod: 19-Feb-26 at 22:59:55 by Bob Weiner
;; Last-Mod: 22-Mar-26 at 01:24:46 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -1054,6 +1054,9 @@ support underlined faces as well."
'("HyWiki>")
'("Act" hywiki-word-activate
"Create and display page for HyWikiWord at point or when none, emulate a press of a Smart Key.")
(when (fboundp 'consult-grep) ;; allow for autoloading
'("BacklinkTo" hywiki-consult-backlink
"Use Consult to select a backlink (reference) to a prompted for HyWikiWord."))
'("Create" hywiki-word-create-and-display
"Create and display a new or existing HyWikiWord referent, prompting with any existing referent names.")
'("DiredHyWiki" hywiki-directory-edit
Expand All @@ -1064,7 +1067,7 @@ support underlined faces as well."
"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."))
"Grep over HyWiki pages with interactive `consult-grep'."))
'("Help" hywiki-help
"Report on a HyWikiWord's attributes or HyWikiWords in general.")
'("Info" (id-info "(hyperbole)HyWiki")
Expand All @@ -1079,10 +1082,7 @@ With a prefix arg, insert a HyWikiWord instead.")
'("Publish" hywiki-publish-to-html
"Publish modified pages in the HyWiki to HTML; prefix arg to publish all pages.")
'("TagFind" hywiki-tags-view
"Find HyWiki Org tags.")
(when (fboundp 'consult-grep) ;; allow for autoloading
'("WikiWordConsult" hywiki-word-consult-grep
"Use `hywiki-consult-grep' to show occurrences of a prompted for HyWikiWord."))))
"Find HyWiki Org tags.")))
"Hyperbole minibuffer HyWiki menu items of the form:
\(LABEL-STRING ACTION-SEXP DOC-STR)."
:set (lambda (var value)
Expand Down
12 changes: 11 additions & 1 deletion hypb.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 6-Oct-91 at 03:42:38
;; Last-Mod: 7-Mar-26 at 16:40:23 by Bob Weiner
;; Last-Mod: 22-Mar-26 at 01:29:41 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -668,6 +668,10 @@ Assist Key on any log line will display its committed changes."
(interactive "sGrep git commits containing: ")
(compile (format "git log -G'%s' --line-prefix='commit ' --oneline" regexp)))

(defun hypb:grep-has-pcre-p ()
"Return t if grep supports the -P option, pcre Perl-style regexps."
(eq 0 (shell-command "echo '' | grep -P '' > /dev/null 2>&1")))

(defun hypb:help-buf-name (&optional suffix)
"Return a Hyperbole help buffer name for current buffer.
With optional SUFFIX string, uses it rather than buffer name."
Expand All @@ -676,6 +680,7 @@ With optional SUFFIX string, uses it rather than buffer name."
(buffer-name (generate-new-buffer bn))
(concat hypb:help-buf-prefix bn "*"))))


;;;###autoload
(defun hypb:helm-apropos (&optional symbol-name)
"Prompt for and display the doc for a command, function, variable or face.
Expand Down Expand Up @@ -1093,6 +1098,11 @@ Removes any trailing newline at the end of the output."
(kill-buffer buf))
output))

(defun hypb:ripgrep-has-pcre-p ()
"Return t if rg supports pcre Perl-style regexps."
(when (executable-find "rg")
(eq 0 (shell-command "rg --pcre2-version > /dev/null 2>&1"))))

;;;###autoload
(defalias 'hypb:rgrep 'hui-select-rgrep)

Expand Down
85 changes: 63 additions & 22 deletions hywiki.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 21-Apr-24 at 22:41:13
;; Last-Mod: 16-Mar-26 at 21:18:30 by Bob Weiner
;; Last-Mod: 22-Mar-26 at 01:34:22 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -1711,6 +1711,67 @@ nil, else return \\='(page . \"<page-file-path>\")."
(and (or at-tag-flag (hsys-org-at-tags-p))
(or (hywiki-in-page-p) (string-prefix-p "*HyWiki Tags*" (buffer-name)))))

;;;###autoload
(defun hywiki-consult-backlink (reference)
"Select a HyWikiWord backlink to REFERENCE with `hywiki-consult-grep'.
REFERENCE should be a string of \"WikiWord\" and optional \"#suffix\" which
is ignored. Unless `grep' or `rg' have Perl-style pcre2 support, matches
will include filenames that include the WikiWord."
(interactive (list (hywiki-word-read "Select a WikiWord backlink for: "
(hywiki-word-at-point))))
;; Ensure any #suffix is stripped
(let ((wikiword (and (stringp reference) (not (string-empty-p reference))
(hywiki-word-strip-suffix reference))))
(unless wikiword
(user-error "(hywiki-consult-backlink): Invalid HyWikiWord: '%s'; must be capitalized, all alpha" wikiword))
(require 'consult)
(let* ((ignored-exts "kotl|org|otl|html|md")
(ripgrep-pcre (hypb:ripgrep-has-pcre-p))
(grep-pcre (hypb:grep-has-pcre-p))
(consult-ripgrep-args consult-ripgrep-args)
(consult-grep-args consult-grep-args)
(regexp (format "\\b%s\\b\\(?!\\.\\(%s\\)\\)" wikiword ignored-exts)))
(cond (ripgrep-pcre
(setq consult-ripgrep-args
(if (listp consult-ripgrep-args)
(append consult-ripgrep-args (list "-P"))
(concat consult-ripgrep-args " -P"))))
(grep-pcre
(setq consult-grep-args
(if (listp consult-grep-args)
(append consult-grep-args (list "-P"))
(concat consult-grep-args " -P"))))
;; No pcre support, so use a simpler grep expression that doesn't
;; filter out WikiWords embedded within filenames
(t (setq regexp (format "\\b%s\\b" wikiword))))
(minibuffer-with-setup-hook
(lambda ()
;; Disable the Org cache which can cause an 'Invalid search bound' error
(setq-local org-element-use-cache nil)
(setq-local org-fold-core-style 'overlays))
(hywiki-consult-grep regexp nil nil
(format "HyWiki Backlinks [%s]: " wikiword))))))

;;;###autoload
(defun hywiki-consult-grep (&optional regexp max-matches path-list prompt)
"Interactively search HyWiki pages with a consult package grep command.
Search for optional REGEXP up to MAX-MATCHES in PATH-LIST or `hywiki-directory'.

Use ripgrep (rg) if found, otherwise, plain grep. Initialize search with
optional REGEXP and interactively prompt for changes. Limit matches
per file to the absolute value of MAX-MATCHES, if given and not 0. If
0, match to headlines only (lines that start with a '^[*#]+[ \t]+' regexp).
With optional PROMPT string, use this as the first part of the grep prompt;
omit any trailing colon and space in the prompt."
(interactive "i\nP")
(let* ((grep-includes "--include *.org")
(ripgrep-globs "--glob *.org"))
(hsys-consult-grep grep-includes ripgrep-globs
regexp max-matches (or path-list (list hywiki-directory))
(or prompt (if (eq max-matches 0)
"Grep HyWiki dir headlines"
"Grep HyWiki dir")))))

(defun hywiki-consult-page-and-headline (&optional prompt initial)
"Return a string of HyWiki file and headline selected by `consult-grep' or nil."
(interactive)
Expand Down Expand Up @@ -1742,26 +1803,6 @@ nil, else return \\='(page . \"<page-file-path>\")."
:category 'consult-grep)))
selected))

;;;###autoload
(defun hywiki-consult-grep (&optional regexp max-matches path-list prompt)
"Interactively search HyWiki pages with a consult package grep command.
Search for optional REGEXP up to MAX-MATCHES in PATH-LIST or `hywiki-directory'.

Use ripgrep (rg) if found, otherwise, plain grep. Initialize search with
optional REGEXP and interactively prompt for changes. Limit matches
per file to the absolute value of MAX-MATCHES, if given and not 0. If
0, match to headlines only (lines that start with a '^[*#]+[ \t]+' regexp).
With optional PROMPT string, use this as the first part of the grep prompt;
omit any trailing colon and space in the prompt."
(interactive "i\nP")
(let* ((grep-includes "--include *.org")
(ripgrep-globs "--glob *.org"))
(hsys-consult-grep grep-includes ripgrep-globs
regexp max-matches (or path-list (list hywiki-directory))
(or prompt (if (eq max-matches 0)
"Grep HyWiki dir headlines"
"Grep HyWiki dir")))))

(defun hywiki-references-to-org-links ()
"Convert all highlighted HyWikiWords in current buffer to Org links.
Org publishing is then used to convert HyWiki files to other formats such
Expand Down Expand Up @@ -4089,7 +4130,7 @@ call `hywiki-non-hook-context-p' for that."
"Grep for occurrences of WIKIWORD with `consult-grep' or normal-grep'.
Search across `hywiki-directory'."
(if (hsys-consult-active-p) ;; allow for autoloading
(hywiki-word-consult-grep wikiword)
(hywiki-consult-backlink wikiword)
(grep (string-join (list grep-command (format "'%s'" wikiword)
(concat (file-name-as-directory hywiki-directory)
"*" hywiki-file-suffix))
Expand Down
Loading