Skip to content

Commit 31562f0

Browse files
authored
Merge pull request #642 from rswgnu/rsw
Add 'hypb:buffer-file-name' to support explicit buttons in indirect buffers
2 parents 895da1a + 4304c66 commit 31562f0

34 files changed

+220
-174
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
2025-01-05 Bob Weiner <[email protected]>
22

3+
* hypb.el: Add 'hypb:buffer-file-name' to handle indirect buffers whose
4+
file name is only in its base buffer and replace all uses of the
5+
variable 'buffer-file-name' with this call. This allows creation
6+
of explicit buttons in indirect buffers.
7+
hbmap.el, hmail.el, hmoccur.el, hmouse-info.el, hsys-org.el, hsys-org-roam.el:
8+
Add (require 'hypb) for 'hypb:buffer-file-name’ definition.
9+
310
* hyperbole.el (hkey-initialize): Override {C-w} in 'hyperbole-mode-map'
411
as has long been done with {M-w}.
512
hui.el (hui:kill-region, hui-kill-region): Add to kill delimited things

hactypes.el

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Bob Weiner
44
;;
55
;; Orig-Date: 23-Sep-91 at 20:34:36
6-
;; Last-Mod: 24-Nov-24 at 12:09:18 by Bob Weiner
6+
;; Last-Mod: 5-Jan-25 at 11:15:09 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -327,7 +327,7 @@ Interactively, KEY-FILE defaults to the current buffer's file name."
327327
normalized-file)
328328
(if key-file
329329
(setq normalized-file (hpath:normalize key-file))
330-
(setq normalized-file buffer-file-name))
330+
(setq normalized-file (hypb:buffer-file-name)))
331331

332332
(if (setq but (when normalized-file (ebut:get key nil normalized-file)))
333333
(hbut:act but)
@@ -528,7 +528,7 @@ on the implicit button to which to link."
528528
(interactive
529529
(let ((ibut-name-key (ibut:at-p t)))
530530
(cond (ibut-name-key
531-
(list ibut-name-key (or buffer-file-name (buffer-name)) (point)))
531+
(list ibut-name-key (or (hypb:buffer-file-name) (buffer-name)) (point)))
532532
;; !! TODO: If default is null below and are creating, rather than editing
533533
;; the link, it would be better to throw an error than create
534534
;; an invalid link, but it is difficult to tell which operation
@@ -546,9 +546,9 @@ on the implicit button to which to link."
546546
normalized-file)
547547
(if but-src
548548
(unless (and (get-buffer but-src)
549-
(not (buffer-file-name (get-buffer but-src))))
549+
(not (hypb:buffer-file-name (get-buffer but-src))))
550550
(setq normalized-file (hpath:normalize but-src)))
551-
(setq normalized-file (hpath:normalize buffer-file-name)))
551+
(setq normalized-file (hpath:normalize (hypb:buffer-file-name))))
552552
(when but-src
553553
(set-buffer (or (get-buffer but-src) (get-file-buffer normalized-file))))
554554
(widen)
@@ -584,12 +584,12 @@ If CELL-REF is nil, show the first cell in the view."
584584
;; matching of path is likely to be wrong in
585585
;; certain cases, e.g. with mount point or os path
586586
;; alterations.
587-
buffer-file-name
587+
(hypb:buffer-file-name)
588588
file
589589
(or (null file)
590590
(string-empty-p file)
591591
(equal (file-name-nondirectory file)
592-
(file-name-nondirectory buffer-file-name))))
592+
(file-name-nondirectory (hypb:buffer-file-name)))))
593593
(when (or (null file) (string-empty-p file))
594594
(setq file (hbut:get-key-src t)))
595595
(if (stringp file)
@@ -698,7 +698,7 @@ FILE may be a string or nil, in which case the current buffer is used."
698698
(setq file (expand-file-name file (hpath:expand "${hyperb:dir}/man/"))))
699699
(if file
700700
(set-buffer (find-file-noselect (hpath:substitute-value file)))
701-
(setq file buffer-file-name))
701+
(setq file (hypb:buffer-file-name)))
702702
(save-excursion
703703
(goto-char (point-min))
704704
(if (re-search-forward (format "^@node[ \t]+%s *[,\n\r]" node) nil t)

hargs.el

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ Handles all of the interactive argument types that `hargs:iform-read' does."
678678
(no-default nil)
679679
;; Possibly non-existent file name
680680
((hpath:at-p 'file 'non-exist))
681-
((buffer-file-name))))
681+
((hypb:buffer-file-name))))
682682
((eq hargs:reading-type 'directory)
683683
(cond ((derived-mode-p 'dired-mode)
684684
(let ((dir (or (smart-dired-pathname-up-to-point t)
@@ -715,8 +715,8 @@ Handles all of the interactive argument types that `hargs:iform-read' does."
715715
(concat "(" file ")" node))
716716
(t node)))))
717717
((eq hargs:reading-type 'mail)
718-
(and (hmail:reader-p) buffer-file-name
719-
(prin1-to-string (list (rmail:msg-id-get) buffer-file-name))))
718+
(and (hmail:reader-p) (hypb:buffer-file-name)
719+
(prin1-to-string (list (rmail:msg-id-get) (hypb:buffer-file-name)))))
720720
((eq hargs:reading-type 'symbol)
721721
(let ((sym (hargs:find-tag-default)))
722722
(when (or (fboundp sym) (boundp sym)) sym)))

hasht.el

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
;; AUTHOR: Bob Weiner
99
;;
1010
;; ORIG-DATE: 16-Mar-90 at 03:38:48
11-
;; LAST-MOD: 29-Dec-24 at 12:37:57 by Mats Lidell
11+
;; LAST-MOD: 5-Jan-25 at 12:21:16 by Bob Weiner
1212
;;
1313
;; Copyright (C) 1990-1995, 1997, 2016 Free Software Foundation, Inc.
1414
;; See the file BR-COPY for license information.
@@ -45,6 +45,12 @@
4545
;; Public and private function names are alphabetized for easy location.
4646

4747
;;; Code:
48+
;;; ************************************************************************
49+
;;; Other required Elisp libraries
50+
;;; ************************************************************************
51+
52+
(require 'subr-x) ; for `hash-table-keys/values', `hash-table-empty-p'
53+
4854
;;; ************************************************************************
4955
;;; Public variables
5056
;;; ************************************************************************

hbdata.el

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Bob Weiner
44
;;
55
;; Orig-Date: 2-Apr-91
6-
;; Last-Mod: 2-Dec-24 at 01:48:15 by Bob Weiner
6+
;; Last-Mod: 5-Jan-25 at 11:15:10 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -196,7 +196,7 @@ If the hbdata buffer is blank/empty, kill it and remove the associated file."
196196
(when (looking-at empty-hbdata-file)
197197
(setq kill t)))
198198
(when kill
199-
(let ((fname buffer-file-name))
199+
(let ((fname (hypb:buffer-file-name)))
200200
(erase-buffer) (save-buffer) (kill-buffer nil)
201201
(hbmap:dir-remove (file-name-directory fname))
202202
(delete-file fname))))))))
@@ -390,7 +390,7 @@ Return value of evaluation when a matching entry is found or nil."
390390
(progn
391391
(when (get-buffer key-src)
392392
(set-buffer key-src)
393-
(unless buffer-file-name
393+
(unless (hypb:buffer-file-name)
394394
(cond ((hmail:editor-p)
395395
(setq end-func (lambda ()
396396
(hmail:msg-narrow))))
@@ -421,7 +421,7 @@ Return value of evaluation when a matching entry is found or nil."
421421
(hmail:hbdata-start))))))))
422422
(setq found (hbdata:to-entry-buf key-src directory create-flag)))
423423
(when found
424-
(unless buffer-file-name
424+
(unless (hypb:buffer-file-name)
425425
;; Point must be left after hbdata separator or the logic
426426
;; below could fail. Buffer should be widened already.
427427
(goto-char (point-min))
@@ -445,14 +445,14 @@ Return value of evaluation when a matching entry is found or nil."
445445

446446
(defun hbdata:is-but-data-stored-in-buffer (key-src)
447447
"True if we store but-data in the buffer rather than in a file."
448-
;; Drafts of mail messages now have a buffer-file-name since they
448+
;; Drafts of mail messages now have a `buffer-file-name' since they
449449
;; are temporarily saved to a file until sent. But but-data still
450450
;; should be stored in the mail buffer itself, so check explicitly
451451
;; whether is a mail composition buffer in such cases.
452452
(or (hmail:mode-is-p)
453453
(and (get-buffer key-src)
454454
(set-buffer key-src)
455-
(not buffer-file-name))))
455+
(not (hypb:buffer-file-name)))))
456456

457457
(defun hbdata:to-entry-in-buffer (create)
458458
"Move point to end of line in but data in current buffer.
@@ -541,7 +541,7 @@ a button instance string to append to button label or t when first instance.
541541
On failure, return nil."
542542
(let ((cons (hbdata:ebut-build orig-lbl-key but-sym new-lbl-key))
543543
entry lbl-instance)
544-
(unless (or (and buffer-file-name (not (file-writable-p buffer-file-name)))
544+
(unless (or (and (hypb:buffer-file-name) (not (file-writable-p (hypb:buffer-file-name))))
545545
(null cons))
546546
(setq entry (car cons) lbl-instance (cdr cons))
547547
(prin1 entry (current-buffer))

hbmap.el

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Bob Weiner
44
;;
55
;; Orig-Date: 6-Oct-91 at 06:34:05
6-
;; Last-Mod: 3-Oct-23 at 17:49:44 by Mats Lidell
6+
;; Last-Mod: 5-Jan-25 at 12:00:29 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -15,6 +15,12 @@
1515
;;; Commentary:
1616

1717
;;; Code:
18+
;;; ************************************************************************
19+
;;; Other required Elisp libraries
20+
;;; ************************************************************************
21+
22+
(require 'hypb)
23+
1824
;;; ************************************************************************
1925
;;; Public variables
2026
;;; ************************************************************************
@@ -120,7 +126,7 @@ the error. Optional NO-SAVE disables saving of the map after operation."
120126
(eval form)
121127
(cond (no-save
122128
t)
123-
((file-writable-p buffer-file-name)
129+
((file-writable-p (hypb:buffer-file-name))
124130
(save-buffer)
125131
t)
126132
(t 'hbmap-not-writable))))

hbut.el

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Bob Weiner
44
;;
55
;; Orig-Date: 18-Sep-91 at 02:57:09
6-
;; Last-Mod: 5-Jan-25 at 01:12:45 by Bob Weiner
6+
;; Last-Mod: 5-Jan-25 at 11:27:31 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -552,7 +552,7 @@ button is found in the current buffer."
552552
(re-search-backward regexp nil t)))
553553
(goto-char (+ (match-beginning 0) (length ebut:label-start))))))
554554

555-
(when (or (not buffer-file-name) (hmail:editor-p) (hmail:reader-p))
555+
(when (or (not (hypb:buffer-file-name)) (hmail:editor-p) (hmail:reader-p))
556556
(widen)
557557
(hmail:msg-narrow))
558558

@@ -614,7 +614,7 @@ labels only; optional MATCH-PART enables partial matches."
614614
(setq currbuf (and (file-readable-p currfile)
615615
(find-file-noselect currfile))
616616
dir (file-name-directory currfile))
617-
(setq currfile (buffer-file-name currbuf)))
617+
(setq currfile (hypb:buffer-file-name currbuf)))
618618
(and currfile currbuf
619619
(unwind-protect
620620
(setq src-matches
@@ -834,7 +834,7 @@ delimiters. With POS-FLAG non-nil, return the list of label-or-key,
834834
but-start-position, but-end-position. Positions include
835835
delimiters. With TWO-LINES-FLAG non-nil, constrain label search
836836
to two lines."
837-
(when (equal buffer-file-name (gbut:file))
837+
(when (equal (hypb:buffer-file-name) (gbut:file))
838838
(hbut:label-p as-label start-delim end-delim pos-flag two-lines-flag)))
839839

840840
(defun gbut:save-buffer ()
@@ -1055,7 +1055,7 @@ Default is the symbol hbut:current."
10551055
(delim-text-start (hattr:get hbut 'lbl-start))
10561056
(delim-text-end (hattr:get hbut 'lbl-end)))
10571057
(if (and name-key
1058-
(or (equal loc buffer-file-name)
1058+
(or (equal loc (hypb:buffer-file-name))
10591059
(equal loc (current-buffer)))
10601060
(equal name-key (ibut:label-to-key (hattr:get hbut 'name))))
10611061
(unless (and delim-text-start delim-text-end
@@ -1064,7 +1064,7 @@ Default is the symbol hbut:current."
10641064
(goto-char delim-text-start)
10651065
(skip-chars-forward "^-_a-zA-Z0-9"))
10661066
;; Here handle when there is no name preceding the implicit button.
1067-
(unless (and (or (equal loc buffer-file-name)
1067+
(unless (and (or (equal loc (hypb:buffer-file-name))
10681068
(equal loc (current-buffer)))
10691069
delim-text-start delim-text-end
10701070
(< delim-text-start (point))
@@ -1297,10 +1297,10 @@ is given."
12971297
cd 0 (string-match "\\s +\\'" cd)))
12981298
(expand-file-name cd wd))
12991299
wd)))
1300-
(buffer-file-name
1300+
((hypb:buffer-file-name)
13011301
(if full-flag
1302-
buffer-file-name
1303-
(file-name-nondirectory buffer-file-name)))
1302+
(hypb:buffer-file-name)
1303+
(file-name-nondirectory (hypb:buffer-file-name))))
13041304
;; Handle any preceding @loc hyp-source implicit button location references.
13051305
;; This is used in report buffers of explicit buttons, i.e. hui:hbut-report
13061306
;; as well as the *HyRolo* display matches buffer.
@@ -1347,10 +1347,10 @@ This is used to obtain the source of Hyperbole buttons for buffers that
13471347
represent the output of particular document formatters."
13481348
(when (or (eq major-mode 'Info-mode)
13491349
(string-match "\\.info\\(-[0-9]+\\)?$" (buffer-name)))
1350-
(let ((src (and buffer-file-name
1350+
(let ((src (and (hypb:buffer-file-name)
13511351
(substring
1352-
buffer-file-name
1353-
0 (string-match "\\.[^.]+$" buffer-file-name)))))
1352+
(hypb:buffer-file-name)
1353+
0 (string-match "\\.[^.]+$" (hypb:buffer-file-name))))))
13541354
(cond ((file-exists-p (concat src ".texi"))
13551355
(concat src ".texi"))
13561356
((file-exists-p (concat src ".texinfo"))
@@ -1747,7 +1747,7 @@ button label. Return the symbol for the button, else nil."
17471747
Keys in optional KEY-SRC or the current buffer."
17481748
(save-excursion
17491749
(save-restriction
1750-
(if (hbdata:to-entry-buf (or key-src (buffer-file-name)))
1750+
(if (hbdata:to-entry-buf (or key-src (hypb:buffer-file-name)))
17511751
(let (hbuts)
17521752
(save-restriction
17531753
(narrow-to-region (point) (if (search-forward "\f" nil t)

hibtypes.el

Lines changed: 7 additions & 7 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: 1-Dec-24 at 20:33:59 by Bob Weiner
6+
;; Last-Mod: 5-Jan-25 at 11:15:09 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -230,7 +230,7 @@ in all buffers."
230230
(not (or (hmail:lister-p) (hnews:lister-p))))
231231
(when (boundp 'hyrolo-display-buffer)
232232
(equal (buffer-name) hyrolo-display-buffer))
233-
(and buffer-file-name
233+
(and (hypb:buffer-file-name)
234234
(boundp 'hyrolo-file-list)
235235
(set:member (current-buffer)
236236
(mapcar #'get-file-buffer (hyrolo-get-file-list))))))
@@ -418,7 +418,7 @@ in buffers whose names begin with a space or asterisk character, must
418418
not be in a programming mode, Markdown or Org buffer and must have an
419419
attached file."
420420
(and (not (bolp))
421-
buffer-file-name
421+
(hypb:buffer-file-name)
422422
(let ((chr (aref (buffer-name) 0)))
423423
(not (or (eq chr ?\ ) (eq chr ?*))))
424424
(not (apply #'derived-mode-p
@@ -515,7 +515,7 @@ Url links are handled elsewhere."
515515
(ibut:label-set (match-string-no-properties 0) (match-beginning 0) (match-end 0))
516516
(setq npoint (point))
517517
(goto-char opoint)
518-
(hact 'link-to-file buffer-file-name npoint))
518+
(hact 'link-to-file (hypb:buffer-file-name) npoint))
519519
;; Follows an absolute file link.
520520
(markdown-follow-inline-link-p opoint))
521521
;; May be on the name of an infile link, so move to the
@@ -730,8 +730,8 @@ line."
730730
Display selected files. Each file name must be at the beginning of the line
731731
or may be preceded by some semicolons and must be followed by one or more
732732
spaces and then another non-space, non-parenthesis, non-brace character."
733-
(when buffer-file-name
734-
(let ((file (file-name-nondirectory buffer-file-name))
733+
(when (hypb:buffer-file-name)
734+
(let ((file (file-name-nondirectory (hypb:buffer-file-name)))
735735
entry start end)
736736
(when (and (or (string-equal file "DIR")
737737
(string-match "\\`MANIFEST\\(\\..+\\)?\\'" file))
@@ -1416,7 +1416,7 @@ documentation string is displayed."
14161416
(match-string-no-properties 2))
14171417
;; Derive file name from the source file name.
14181418
(let ((nodename (match-string-no-properties 2))
1419-
(file (file-name-nondirectory buffer-file-name)))
1419+
(file (file-name-nondirectory (hypb:buffer-file-name))))
14201420
(if show-texinfo-node
14211421
nodename
14221422
(format "(%s)%s"

hmail.el

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
;; Author: Bob Weiner
44
;;
55
;; Orig-Date: 9-Oct-91 at 18:38:05
6-
;; Last-Mod: 10-Mar-24 at 11:52:34 by Bob Weiner
6+
;; Last-Mod: 5-Jan-25 at 12:01:15 by Bob Weiner
77
;;
88
;; SPDX-License-Identifier: GPL-3.0-or-later
99
;;
@@ -31,6 +31,12 @@
3131
;; with Hyperbole.
3232

3333
;;; Code:
34+
;;; ************************************************************************
35+
;;; Other required Elisp libraries
36+
;;; ************************************************************************
37+
38+
(require 'hypb)
39+
3440
;;; ************************************************************************
3541
;;; Public declarations
3642
;;; ************************************************************************
@@ -101,7 +107,7 @@ Return t if button data is found, else nil."
101107
(hmail:msg-narrow)
102108
t)
103109
((or (hmail:lister-p) (hnews:lister-p)) t)
104-
((or (not buffer-file-name)
110+
((or (not (hypb:buffer-file-name))
105111
(memq major-mode (list hmail:composer hnews:reader
106112
hnews:composer)))
107113
(widen)

0 commit comments

Comments
 (0)