From f810e032d37a5a16e04d001159d683695a183615 Mon Sep 17 00:00:00 2001
From: bw
Date: Sun, 22 Mar 2026 18:29:44 -0400
Subject: [PATCH 1/2] grep-single-file - New ibtype to handle grep -n on a
single file
Single file grep results do not show the filename unless the -H option is
explicitly given. This ibtype copes with that situation to find the best
guess file using the new function `hpath:get-grep-filename'.
hib-python-traceback, debugger-source, grep-msg, hyrolo-stuck-msg - Flash
whole line as the button label.
---
ChangeLog | 8 ++++++++
hibtypes.el | 46 +++++++++++++++++++++++++++++++----------
hpath.el | 51 ++++++++++++++++++++++++++++++++++++++++++++--
man/hyperbole.texi | 22 ++++++++++++++++----
4 files changed, 110 insertions(+), 17 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ded0f081..fd471851 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2026-03-22 Bob Weiner
+* hibtypes.el (grep-single-file): Add to handle grep -n on a single file
+ where the lines do not show the filename.
+ man/hyperbole.texi (Implicit Button Types): Add 'grep-single-file'.
+ hpath.el (hpath:get-grep-filename): Add, used by 'grep-single-file'.
+
+* hibtypes.el (hib-python-traceback, debugger-source, grep-msg,
+ hyrolo-stuck-msg): Flash whole line as the button label.
+
* hibtypes.el (hib-link-to-file-line): Fix that a filename both in the current
dir and in the 'load-path' variable is expanded into a 'load-path' dir
first rather than the current directory, which should be preferred.
diff --git a/hibtypes.el b/hibtypes.el
index 566434cd..84c87e83 100644
--- a/hibtypes.el
+++ b/hibtypes.el
@@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 19-Sep-91 at 20:45:31
-;; Last-Mod: 22-Mar-26 at 14:08:04 by Bob Weiner
+;; Last-Mod: 22-Mar-26 at 18:18:45 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -1074,6 +1074,22 @@ than a helm completion buffer)."
(ibut:label-set (concat file ":" line-num))
(hact 'hib-link-to-file-line file line-num)))))))
+(defib grep-single-file ()
+ "Jump to the source line from a single file, line-numbered grep msg.
+Such grep msgs start with the line number followed by a colon. The buffer
+may contain the file searched prior to any such line or it may not,
+e.g. {M-!} in which case `hpath:get-grep-filename' will extract a best
+guess from the `command-history'.
+
+Avoid this situation and force prefixing each line with the filename by
+including the -H option."
+ (let ((file-and-line (hpath:get-grep-filename)))
+ (when file-and-line
+ (ibut:label-set (concat (file-name-nondirectory (nth 0 file-and-line))
+ ":" (nth 1 file-and-line))
+ (line-beginning-position) (line-end-position))
+ (apply #'hact 'hib-link-to-file-line file-and-line))))
+
(defib ripgrep-msg ()
"Jump to the line associated with a ripgrep (rg) line numbered msg.
Ripgrep outputs each pathname once followed by all matching lines
@@ -1125,11 +1141,12 @@ buffer)."
(but-label (concat buffer-name ":P" pos)))
(when (buffer-live-p (get-buffer buffer-name))
(setq pos (string-to-number pos))
- (ibut:label-set but-label)
+ (ibut:label-set but-label
+ (line-beginning-position) (line-end-position))
(hact 'link-to-buffer-tmp buffer-name pos)))))))
(defib grep-msg ()
- "Jump to the line associated with line numbered grep or compilation error msgs.
+ "Jump to the source line from a line-numbered grep or compilation msg.
Messages are recognized in any buffer (other than a helm completion
buffer) except for grep -A context lines which are matched only
in grep and shell buffers."
@@ -1180,7 +1197,8 @@ in grep and shell buffers."
(looking-at "\\([^ \t\n\r:\"'`]+\\)-\\([1-9][0-9]*\\)-")))
(let* ((file (match-string-no-properties 1))
(line-num (or (match-string-no-properties 2) "1")))
- (ibut:label-set (concat file ":" line-num))
+ (ibut:label-set (concat file ":" line-num)
+ (line-beginning-position) (line-end-position))
(hact 'hib-link-to-file-line file line-num))))))
;;; ========================================================================
@@ -1196,7 +1214,8 @@ in grep and shell buffers."
(line-num (match-string-no-properties 3))
(but-label (concat file ":" line-num)))
(setq line-num (string-to-number line-num))
- (ibut:label-set but-label (match-beginning 2) (match-end 2))
+ (ibut:label-set but-label
+ (line-beginning-position) (line-end-position))
(hact 'link-to-file-line file line-num))))
(defib debugger-source ()
@@ -1227,7 +1246,8 @@ xdb. Such lines are recognized in any buffer."
(setq but-label (concat file ":" line-num)
line-num (string-to-number line-num))
- (ibut:label-set but-label)
+ (ibut:label-set but-label
+ (line-beginning-position) (line-end-position))
(hact 'link-to-file-line file line-num)))
;; GDB or WDB
@@ -1249,7 +1269,8 @@ xdb. Such lines are recognized in any buffer."
;; guess.
(when gdb-last-file
(setq file (expand-file-name file (file-name-directory gdb-last-file))))
- (ibut:label-set but-label)
+ (ibut:label-set but-label
+ (line-beginning-position) (line-end-position))
(hact 'link-to-file-line file line-num)))
;; XEmacs assertion failure
@@ -1258,7 +1279,8 @@ xdb. Such lines are recognized in any buffer."
(line-num (match-string-no-properties 2))
(but-label (concat file ":" line-num)))
(setq line-num (string-to-number line-num))
- (ibut:label-set but-label)
+ (ibut:label-set but-label
+ (line-beginning-position) (line-end-position))
(hact 'link-to-file-line file line-num)))
;; New DBX
@@ -1267,7 +1289,8 @@ xdb. Such lines are recognized in any buffer."
(line-num (match-string-no-properties 1))
(but-label (concat file ":" line-num)))
(setq line-num (string-to-number line-num))
- (ibut:label-set but-label)
+ (ibut:label-set but-label
+ (line-beginning-position) (line-end-position))
(hact 'link-to-file-line file line-num)))
;; Old DBX and HP-UX xdb
@@ -1277,7 +1300,8 @@ xdb. Such lines are recognized in any buffer."
(line-num (match-string-no-properties 2))
(but-label (concat file ":" line-num)))
(setq line-num (string-to-number line-num))
- (ibut:label-set but-label)
+ (ibut:label-set but-label
+ (line-beginning-position) (line-end-position))
(hact 'link-to-file-line file line-num))))))
;;; ========================================================================
@@ -1804,7 +1828,7 @@ not yet existing HyWikiWords."
;;; Follows Org mode links and radio targets and cycles Org heading views
;;; ========================================================================
-;; See `smart-org' in "hui-mouse.el"; this is higher priority than all ibtypes.
+;;; See `smart-org' in "hui-mouse.el"; this is higher priority than all ibtypes.
;; If you want to to disable ALL Hyperbole support within Org major
;; and minor modes, set the custom option `hsys-org-enable-smart-keys' to nil.
diff --git a/hpath.el b/hpath.el
index ab0ec7de..62fe4c4f 100644
--- a/hpath.el
+++ b/hpath.el
@@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 1-Nov-91 at 00:44:23
-;; Last-Mod: 22-Mar-26 at 13:41:04 by Bob Weiner
+;; Last-Mod: 22-Mar-26 at 18:26:12 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -1336,7 +1336,7 @@ ${variable} per path."
paths))
(defun hpath:prepend-shell-directory (&optional filename)
- "Prepend subdir to a filename in an \\='ls'-file listing.
+ "Prepend subdir to an optional FILENAME in an \\='ls'-file listing.
When in a shell buffer and on a filename result of an \\='ls *' or
recursive \\='ls -R' or \\='dir' command, prepend the subdir to the
filename at point, or optional FILENAME, when needed and return
@@ -1414,6 +1414,53 @@ If PATH is absolute, return it unchanged."
(setq auto-variable-alist nil)))))
(concat path compression-suffix))))
+(defun hpath:get-grep-filename ()
+ "Return a list of (filename-with-path line-number) for grep line without file.
+If grep is run over a single file, it omits the filename from each line
+unless the -H option is given.
+
+This function extracts both the filename searched and the line number
+selected. For the filename, first it checks if the grep command precedes
+the numbered lines. If not, it finds the most recent grep command in the
+`command-history' and uses the last argument if it is an existing filename."
+ (let ((grep-process (apply #'derived-mode-p '(grep-mode shell-mode)))
+ ;; for shell command output buffers
+ (grep-output (and (not buffer-file-name) (not (get-buffer-process (current-buffer))))))
+ (when (or grep-process grep-output)
+ (save-excursion
+ (forward-line 0)
+ (when (looking-at "\\([1-9][0-9]*\\):.+")
+ (let ((line-num (match-string 1))
+ cmd
+ file)
+ ;; Skip over lines starting with line numbers
+ (while (re-search-backward "^[1-9][0-9]*:.+" nil t))
+ (cond (grep-process
+ ;; If there is a prior line, move to its end
+ (unless (or (= (point) (point-min)) (not (bolp)))
+ (skip-chars-backward "\n\r\t \"'`")
+ ;; If last item can be expanded as a filename, return a
+ ;; list of the filename and the line number from the
+ ;; original line
+ (setq file (thing-at-point 'existing-filename))
+ (when file
+ (list file line-num))))
+ (grep-output
+ ;; Command line is not in output buffer; have to get
+ ;; it from the command history
+ (setq cmd (cadr (seq-find (lambda (item)
+ (when (eq (car item) 'eval-expression)
+ (setq item (cadr item)))
+ (memq (car item) '(grep rgrep zrgrep hui-select-rgrep hypb:rgrep shell-command async-shell-command)))
+ command-history)))
+ (when cmd
+ (setq file (expand-file-name
+ (string-trim (car (last (split-string cmd)))
+ "[\"'`]" "[\"'`]")))
+ (when (and (file-readable-p file)
+ (not (file-directory-p file)))
+ (list file line-num)))))))))))
+
(defun hpath:file-line-and-column (path-line-and-col)
"Return list of parts from PATH-LINE-AND-COL string of format path:line:col.
Parse out the parts and return a list, else nil."
diff --git a/man/hyperbole.texi b/man/hyperbole.texi
index fcde768e..bbce1954 100644
--- a/man/hyperbole.texi
+++ b/man/hyperbole.texi
@@ -7,7 +7,7 @@
@c Author: Bob Weiner
@c
@c Orig-Date: 6-Nov-91 at 11:18:03
-@c Last-Mod: 15-Mar-26 at 01:56:19 by Bob Weiner
+@c Last-Mod: 22-Mar-26 at 18:10:11 by Bob Weiner
@c %**start of header (This is for running Texinfo on a region.)
@setfilename hyperbole.info
@@ -30,7 +30,7 @@
@set txicodequoteundirected
@set txicodequotebacktick
-@set UPDATED March 15, 2026
+@set UPDATED March 22, 2026
@set UPDATED-MONTH March 2026
@set EDITION 9.0.2pre
@set VERSION 9.0.2pre
@@ -171,7 +171,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Edition 9.0.2pre
-Printed March 15, 2026.
+Printed March 22, 2026.
Published by the Free Software Foundation, Inc.
Author: Bob Weiner
@@ -213,7 +213,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@example
Edition 9.0.2pre
-March 15, 2026 @c AUTO-REPLACE-ON-SAVE
+March 22, 2026 @c AUTO-REPLACE-ON-SAVE
Published by the Free Software Foundation, Inc.
@@ -2663,6 +2663,20 @@ Ripgrep outputs each pathname once, followed by all matching lines in
that pathname. Messages are recognized in any buffer (other than a
helm completion buffer).
+@findex ibtypes grep-single-file
+@cindex grep
+@cindex match lines
+@cindex command history
+@findex hpath:get-grep-filename
+@vindex command-history
+@anchor{grep-single-file}
+@item grep-single-file
+Jump to the source line from a single file, line-numbered grep msg.
+Such grep msgs start with the line number followed by a colon. The
+buffer may contain the file searched prior to any such line or it may
+not, e.g. @bkbd{M-!} in which case @code{hpath:get-grep-filename} will
+extract a best guess from the @code{command-history}.
+
@findex ibtypes ipython-stack-frame
@cindex ipython
@cindex stack frame
From 310b4d2c64737f43c026447f3f6f47cf3bc8675f Mon Sep 17 00:00:00 2001
From: bw
Date: Sun, 22 Mar 2026 23:41:01 -0400
Subject: [PATCH 2/2] Update HyWiki Backlink menu items and ModeSet/ menu in
manual
---
ChangeLog | 8 +++++++
hui-menu.el | 4 ++--
hui-mini.el | 4 ++--
man/hyperbole.texi | 60 ++++++++++++++++++++++++----------------------
4 files changed, 43 insertions(+), 33 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fd471851..a940edb0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2026-03-22 Bob Weiner
+* man/hyperbole.texi (HyWiki Menu): Move ModeSet/ menu description here.
+
+* hui-menu.el (hui-menu-hywiki): Change item from 'Backlink-To' to
+ 'Backlink-Consult'.
+ hui-mini.el (hui:menu-hywiki): Change item from 'BacklinkTo' to
+ 'BacklinkConsult'.
+ man/hyperbole.texi (HyWiki Menu): Add BacklinkConsult entry.
+
* hibtypes.el (grep-single-file): Add to handle grep -n on a single file
where the lines do not show the filename.
man/hyperbole.texi (Implicit Button Types): Add 'grep-single-file'.
diff --git a/hui-menu.el b/hui-menu.el
index 64a937e9..070dc485 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: 22-Mar-26 at 01:23:25 by Bob Weiner
+;; Last-Mod: 22-Mar-26 at 23:16:11 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -308,7 +308,7 @@ Return t if cutoff, else nil."
"----"
["Activate-HyWiki-Word" hywiki-word-activate t]
(when (fboundp 'consult-grep) ;; allow for autoloading
- ["Backlink-To" hywiki-consult-backlink t])
+ ["Backlink-Consult" 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]
diff --git a/hui-mini.el b/hui-mini.el
index c5a08e61..458da0a7 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: 22-Mar-26 at 01:24:46 by Bob Weiner
+;; Last-Mod: 22-Mar-26 at 23:15:20 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -1055,7 +1055,7 @@ support underlined faces as well."
'("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
+ '("BacklinkConsult" 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.")
diff --git a/man/hyperbole.texi b/man/hyperbole.texi
index bbce1954..9d620d7d 100644
--- a/man/hyperbole.texi
+++ b/man/hyperbole.texi
@@ -7,7 +7,7 @@
@c Author: Bob Weiner
@c
@c Orig-Date: 6-Nov-91 at 11:18:03
-@c Last-Mod: 22-Mar-26 at 18:10:11 by Bob Weiner
+@c Last-Mod: 22-Mar-26 at 23:39:23 by Bob Weiner
@c %**start of header (This is for running Texinfo on a region.)
@setfilename hyperbole.info
@@ -4617,24 +4617,10 @@ Action Key does the right thing in this context.
Once Hyperbole has been loaded and activated, HyWikiWords (with or
without delimiters) are automatically highlighted and active based
on the setting of @code{hywiki-mode}. Set it with @bkbd{C-h h h m}
-ModeToggle into one of these three states:
+ModeSet/. @xref{ModeSet/}, for the three settings.
-@table @kbd
-@item All-Editable-Buffers
-This is the default setting. Highlight HyWikiWord references within
-HyWiki page buffers only. The @code{hywiki-mode} variable is set to
-@samp{:pages}.
-
-@vindex hywiki-exclude-major-modes
-@item HyWiki-Pages-Only
-Highlight HyWikiWord references within all editable buffers except
-those with major modes in @code{hywiki-exclude-major-modes}. The
-@code{hywiki-mode} variable is set to @samp{:all}.
+Modeinto one of these three states:
-@item Nowhere
-Disable highlighting HyWikiWord references everywhere. The
-@code{hywiki-mode} variable is set to @samp{nil}.
-@end table
@cindex toggle hywiki-mode
@noindent
@@ -4739,11 +4725,11 @@ It looks like this:
@smallexample
@noindent
-HyWiki> Act Create DiredHyWiki EditPage FindReferent GrepConsult Help Info Link ModeToggle Org-M-RET/ Publish TagFind WikiWordConsult
+HyWiki> Act BacklinkConsult Create DiredHyWiki EditPage FindReferent GrepConsult Help Info Link ModeSet/ Org-M-RET/ Publish TagFind
@end smallexample
@noindent
-The GrepConsult and WikiWordConsult items appear only when the Consult
+The BacklinkConsult and GrepConsult and items appear only when the Consult
package is installed prior to loading Hyperbole. These commands are
especially useful as they allow for fast line-level searching across
many files with interactive search pattern narrowing.
@@ -4758,6 +4744,12 @@ Below are descriptions of each menu item.
@item Act
Activate HyWikiWord link at point.
+@cindex HyWikiWord interactive backlink grep
+@findex hywiki-consult-backlink
+@item BacklinkConsult
+Use @code{hywiki-consult-backlink} to prompt for a HyWikiWord and then
+consult grep over its HyWiki backlink references, selecting one.
+
@cindex HyWiki create a page
@item Create
Create and display a new HyWiki page. Shows existing page names to
@@ -4806,11 +4798,27 @@ Display Hyperbole manual section on HyWiki.
Prompt for and add a link at point to a HyWiki page.
@findex hywiki-mode
-@cindex HyWiki mode
+@cindex hywiki-mode
@cindex HyWikiWords outside hywiki-directory
-@item ModeToggle
-Toggle global minor mode @code{hywiki-mode} that enables HyWikiWord hyperlinks
-in buffers outside of @code{hywiki-directory}.
+@anchor{ModeSet/}
+@item ModeSet/
+Select from three states for the global minor mode, @code{hywiki-mode}.
+@table @kbd
+@item All-Editable-Buffers
+This is the default setting. Highlight HyWikiWord references within
+HyWiki page buffers only. The @code{hywiki-mode} variable is set to
+@samp{:pages}.
+
+@vindex hywiki-exclude-major-modes
+@item HyWiki-Pages-Only
+Highlight HyWikiWord references within all editable buffers except
+those with major modes in @code{hywiki-exclude-major-modes}. The
+@code{hywiki-mode} variable is set to @samp{:all}.
+
+@item Nowhere
+Disable highlighting HyWikiWord references everywhere. The
+@code{hywiki-mode} variable is set to @samp{nil}.
+@end table
@kindex C-h h h o
@kindex HyWiki, C-h h h o
@@ -4839,12 +4847,6 @@ Publish modified pages in the HyWiki to HTML; prefix arg to publish all pages.
@cindex search, HyWiki tag
@item TagFind
Find a matching Org tag across all HyWiki pages.
-
-@cindex HyWikiWord interactive grep
-@findex hywiki-consult-grep
-@item WikiWordConsult
-Use @code{hywiki-consult-grep} to prompt for a HyWikiWord and then
-consult grep for and select an occurrence within the HyWiki.
@end table