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
16 changes: 16 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
2026-03-22 Bob Weiner <rsw@gnu.org>

* 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'.
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.
Expand Down
46 changes: 35 additions & 11 deletions hibtypes.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<num> context lines which are matched only
in grep and shell buffers."
Expand Down Expand Up @@ -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))))))

;;; ========================================================================
Expand All @@ -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 ()
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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))))))

;;; ========================================================================
Expand Down Expand Up @@ -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.
Expand Down
51 changes: 49 additions & 2 deletions hpath.el
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 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: 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
;;
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 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: 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
;;
Expand Down Expand Up @@ -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.")
Expand Down
Loading
Loading