Skip to content

Commit 827ad80

Browse files
authored
Merge pull request #915 from rswgnu/rsw
Update HyWiki Backlink menu items and ModeSet/ menu in manual.
2 parents ff2dba3 + 1bf9013 commit 827ad80

6 files changed

Lines changed: 152 additions & 49 deletions

File tree

ChangeLog

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
2026-03-22 Bob Weiner <rsw@gnu.org>
22

3+
* man/hyperbole.texi (HyWiki Menu): Move ModeSet/ menu description here.
4+
5+
* hui-menu.el (hui-menu-hywiki): Change item from 'Backlink-To' to
6+
'Backlink-Consult'.
7+
hui-mini.el (hui:menu-hywiki): Change item from 'BacklinkTo' to
8+
'BacklinkConsult'.
9+
man/hyperbole.texi (HyWiki Menu): Add BacklinkConsult entry.
10+
11+
* hibtypes.el (grep-single-file): Add to handle grep -n on a single file
12+
where the lines do not show the filename.
13+
man/hyperbole.texi (Implicit Button Types): Add 'grep-single-file'.
14+
hpath.el (hpath:get-grep-filename): Add, used by 'grep-single-file'.
15+
16+
* hibtypes.el (hib-python-traceback, debugger-source, grep-msg,
17+
hyrolo-stuck-msg): Flash whole line as the button label.
18+
319
* hibtypes.el (hib-link-to-file-line): Fix that a filename both in the current
420
dir and in the 'load-path' variable is expanded into a 'load-path' dir
521
first rather than the current directory, which should be preferred.

hibtypes.el

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Bob Weiner
44
;;
55
;; Orig-Date: 19-Sep-91 at 20:45:31
6-
;; Last-Mod: 22-Mar-26 at 14:08:04 by Bob Weiner
6+
;; Last-Mod: 22-Mar-26 at 18:18:45 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -1074,6 +1074,22 @@ than a helm completion buffer)."
10741074
(ibut:label-set (concat file ":" line-num))
10751075
(hact 'hib-link-to-file-line file line-num)))))))
10761076

1077+
(defib grep-single-file ()
1078+
"Jump to the source line from a single file, line-numbered grep msg.
1079+
Such grep msgs start with the line number followed by a colon. The buffer
1080+
may contain the file searched prior to any such line or it may not,
1081+
e.g. {M-!} in which case `hpath:get-grep-filename' will extract a best
1082+
guess from the `command-history'.
1083+
1084+
Avoid this situation and force prefixing each line with the filename by
1085+
including the -H option."
1086+
(let ((file-and-line (hpath:get-grep-filename)))
1087+
(when file-and-line
1088+
(ibut:label-set (concat (file-name-nondirectory (nth 0 file-and-line))
1089+
":" (nth 1 file-and-line))
1090+
(line-beginning-position) (line-end-position))
1091+
(apply #'hact 'hib-link-to-file-line file-and-line))))
1092+
10771093
(defib ripgrep-msg ()
10781094
"Jump to the line associated with a ripgrep (rg) line numbered msg.
10791095
Ripgrep outputs each pathname once followed by all matching lines
@@ -1125,11 +1141,12 @@ buffer)."
11251141
(but-label (concat buffer-name ":P" pos)))
11261142
(when (buffer-live-p (get-buffer buffer-name))
11271143
(setq pos (string-to-number pos))
1128-
(ibut:label-set but-label)
1144+
(ibut:label-set but-label
1145+
(line-beginning-position) (line-end-position))
11291146
(hact 'link-to-buffer-tmp buffer-name pos)))))))
11301147

11311148
(defib grep-msg ()
1132-
"Jump to the line associated with line numbered grep or compilation error msgs.
1149+
"Jump to the source line from a line-numbered grep or compilation msg.
11331150
Messages are recognized in any buffer (other than a helm completion
11341151
buffer) except for grep -A<num> context lines which are matched only
11351152
in grep and shell buffers."
@@ -1180,7 +1197,8 @@ in grep and shell buffers."
11801197
(looking-at "\\([^ \t\n\r:\"'`]+\\)-\\([1-9][0-9]*\\)-")))
11811198
(let* ((file (match-string-no-properties 1))
11821199
(line-num (or (match-string-no-properties 2) "1")))
1183-
(ibut:label-set (concat file ":" line-num))
1200+
(ibut:label-set (concat file ":" line-num)
1201+
(line-beginning-position) (line-end-position))
11841202
(hact 'hib-link-to-file-line file line-num))))))
11851203

11861204
;;; ========================================================================
@@ -1196,7 +1214,8 @@ in grep and shell buffers."
11961214
(line-num (match-string-no-properties 3))
11971215
(but-label (concat file ":" line-num)))
11981216
(setq line-num (string-to-number line-num))
1199-
(ibut:label-set but-label (match-beginning 2) (match-end 2))
1217+
(ibut:label-set but-label
1218+
(line-beginning-position) (line-end-position))
12001219
(hact 'link-to-file-line file line-num))))
12011220

12021221
(defib debugger-source ()
@@ -1227,7 +1246,8 @@ xdb. Such lines are recognized in any buffer."
12271246

12281247
(setq but-label (concat file ":" line-num)
12291248
line-num (string-to-number line-num))
1230-
(ibut:label-set but-label)
1249+
(ibut:label-set but-label
1250+
(line-beginning-position) (line-end-position))
12311251
(hact 'link-to-file-line file line-num)))
12321252

12331253
;; GDB or WDB
@@ -1249,7 +1269,8 @@ xdb. Such lines are recognized in any buffer."
12491269
;; guess.
12501270
(when gdb-last-file
12511271
(setq file (expand-file-name file (file-name-directory gdb-last-file))))
1252-
(ibut:label-set but-label)
1272+
(ibut:label-set but-label
1273+
(line-beginning-position) (line-end-position))
12531274
(hact 'link-to-file-line file line-num)))
12541275

12551276
;; XEmacs assertion failure
@@ -1258,7 +1279,8 @@ xdb. Such lines are recognized in any buffer."
12581279
(line-num (match-string-no-properties 2))
12591280
(but-label (concat file ":" line-num)))
12601281
(setq line-num (string-to-number line-num))
1261-
(ibut:label-set but-label)
1282+
(ibut:label-set but-label
1283+
(line-beginning-position) (line-end-position))
12621284
(hact 'link-to-file-line file line-num)))
12631285

12641286
;; New DBX
@@ -1267,7 +1289,8 @@ xdb. Such lines are recognized in any buffer."
12671289
(line-num (match-string-no-properties 1))
12681290
(but-label (concat file ":" line-num)))
12691291
(setq line-num (string-to-number line-num))
1270-
(ibut:label-set but-label)
1292+
(ibut:label-set but-label
1293+
(line-beginning-position) (line-end-position))
12711294
(hact 'link-to-file-line file line-num)))
12721295

12731296
;; Old DBX and HP-UX xdb
@@ -1277,7 +1300,8 @@ xdb. Such lines are recognized in any buffer."
12771300
(line-num (match-string-no-properties 2))
12781301
(but-label (concat file ":" line-num)))
12791302
(setq line-num (string-to-number line-num))
1280-
(ibut:label-set but-label)
1303+
(ibut:label-set but-label
1304+
(line-beginning-position) (line-end-position))
12811305
(hact 'link-to-file-line file line-num))))))
12821306

12831307
;;; ========================================================================
@@ -1804,7 +1828,7 @@ not yet existing HyWikiWords."
18041828
;;; Follows Org mode links and radio targets and cycles Org heading views
18051829
;;; ========================================================================
18061830

1807-
;; See `smart-org' in "hui-mouse.el"; this is higher priority than all ibtypes.
1831+
;;; See `smart-org' in "hui-mouse.el"; this is higher priority than all ibtypes.
18081832

18091833
;; If you want to to disable ALL Hyperbole support within Org major
18101834
;; and minor modes, set the custom option `hsys-org-enable-smart-keys' to nil.

hpath.el

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Bob Weiner
44
;;
55
;; Orig-Date: 1-Nov-91 at 00:44:23
6-
;; Last-Mod: 22-Mar-26 at 13:41:04 by Bob Weiner
6+
;; Last-Mod: 22-Mar-26 at 18:26:12 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -1336,7 +1336,7 @@ ${variable} per path."
13361336
paths))
13371337

13381338
(defun hpath:prepend-shell-directory (&optional filename)
1339-
"Prepend subdir to a filename in an \\='ls'-file listing.
1339+
"Prepend subdir to an optional FILENAME in an \\='ls'-file listing.
13401340
When in a shell buffer and on a filename result of an \\='ls *' or
13411341
recursive \\='ls -R' or \\='dir' command, prepend the subdir to the
13421342
filename at point, or optional FILENAME, when needed and return
@@ -1414,6 +1414,53 @@ If PATH is absolute, return it unchanged."
14141414
(setq auto-variable-alist nil)))))
14151415
(concat path compression-suffix))))
14161416

1417+
(defun hpath:get-grep-filename ()
1418+
"Return a list of (filename-with-path line-number) for grep line without file.
1419+
If grep is run over a single file, it omits the filename from each line
1420+
unless the -H option is given.
1421+
1422+
This function extracts both the filename searched and the line number
1423+
selected. For the filename, first it checks if the grep command precedes
1424+
the numbered lines. If not, it finds the most recent grep command in the
1425+
`command-history' and uses the last argument if it is an existing filename."
1426+
(let ((grep-process (apply #'derived-mode-p '(grep-mode shell-mode)))
1427+
;; for shell command output buffers
1428+
(grep-output (and (not buffer-file-name) (not (get-buffer-process (current-buffer))))))
1429+
(when (or grep-process grep-output)
1430+
(save-excursion
1431+
(forward-line 0)
1432+
(when (looking-at "\\([1-9][0-9]*\\):.+")
1433+
(let ((line-num (match-string 1))
1434+
cmd
1435+
file)
1436+
;; Skip over lines starting with line numbers
1437+
(while (re-search-backward "^[1-9][0-9]*:.+" nil t))
1438+
(cond (grep-process
1439+
;; If there is a prior line, move to its end
1440+
(unless (or (= (point) (point-min)) (not (bolp)))
1441+
(skip-chars-backward "\n\r\t \"'`")
1442+
;; If last item can be expanded as a filename, return a
1443+
;; list of the filename and the line number from the
1444+
;; original line
1445+
(setq file (thing-at-point 'existing-filename))
1446+
(when file
1447+
(list file line-num))))
1448+
(grep-output
1449+
;; Command line is not in output buffer; have to get
1450+
;; it from the command history
1451+
(setq cmd (cadr (seq-find (lambda (item)
1452+
(when (eq (car item) 'eval-expression)
1453+
(setq item (cadr item)))
1454+
(memq (car item) '(grep rgrep zrgrep hui-select-rgrep hypb:rgrep shell-command async-shell-command)))
1455+
command-history)))
1456+
(when cmd
1457+
(setq file (expand-file-name
1458+
(string-trim (car (last (split-string cmd)))
1459+
"[\"'`]" "[\"'`]")))
1460+
(when (and (file-readable-p file)
1461+
(not (file-directory-p file)))
1462+
(list file line-num)))))))))))
1463+
14171464
(defun hpath:file-line-and-column (path-line-and-col)
14181465
"Return list of parts from PATH-LINE-AND-COL string of format path:line:col.
14191466
Parse out the parts and return a list, else nil."

hui-menu.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Bob Weiner
44
;;
55
;; Orig-Date: 28-Oct-94 at 10:59:44
6-
;; Last-Mod: 22-Mar-26 at 01:23:25 by Bob Weiner
6+
;; Last-Mod: 22-Mar-26 at 23:16:11 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -308,7 +308,7 @@ Return t if cutoff, else nil."
308308
"----"
309309
["Activate-HyWiki-Word" hywiki-word-activate t]
310310
(when (fboundp 'consult-grep) ;; allow for autoloading
311-
["Backlink-To" hywiki-consult-backlink t])
311+
["Backlink-Consult" hywiki-consult-backlink t])
312312
["Create-HyWiki-Word" hywiki-word-create-and-display t]
313313
["Dired-HyWiki-Pages" hywiki-directory-edit t]
314314
["Find-HyWiki-Page" hywiki-find-page t]

hui-mini.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Bob Weiner
44
;;
55
;; Orig-Date: 15-Oct-91 at 20:13:17
6-
;; Last-Mod: 22-Mar-26 at 01:24:46 by Bob Weiner
6+
;; Last-Mod: 22-Mar-26 at 23:15:20 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -1055,7 +1055,7 @@ support underlined faces as well."
10551055
'("Act" hywiki-word-activate
10561056
"Create and display page for HyWikiWord at point or when none, emulate a press of a Smart Key.")
10571057
(when (fboundp 'consult-grep) ;; allow for autoloading
1058-
'("BacklinkTo" hywiki-consult-backlink
1058+
'("BacklinkConsult" hywiki-consult-backlink
10591059
"Use Consult to select a backlink (reference) to a prompted for HyWikiWord."))
10601060
'("Create" hywiki-word-create-and-display
10611061
"Create and display a new or existing HyWikiWord referent, prompting with any existing referent names.")

0 commit comments

Comments
 (0)