Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'hypb:buffer-file-name' to support explicit buttons in indirect buffers #642

Merged
merged 2 commits into from
Jan 5, 2025
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
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
2025-01-05 Bob Weiner <[email protected]>

* hypb.el: Add 'hypb:buffer-file-name' to handle indirect buffers whose
file name is only in its base buffer and replace all uses of the
variable 'buffer-file-name' with this call. This allows creation
of explicit buttons in indirect buffers.
hbmap.el, hmail.el, hmoccur.el, hmouse-info.el, hsys-org.el, hsys-org-roam.el:
Add (require 'hypb) for 'hypb:buffer-file-name’ definition.

* hyperbole.el (hkey-initialize): Override {C-w} in 'hyperbole-mode-map'
as has long been done with {M-w}.
hui.el (hui:kill-region, hui-kill-region): Add to kill delimited things
Expand Down
16 changes: 8 additions & 8 deletions hactypes.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 23-Sep-91 at 20:34:36
;; Last-Mod: 24-Nov-24 at 12:09:18 by Bob Weiner
;; Last-Mod: 5-Jan-25 at 11:15:09 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -327,7 +327,7 @@ Interactively, KEY-FILE defaults to the current buffer's file name."
normalized-file)
(if key-file
(setq normalized-file (hpath:normalize key-file))
(setq normalized-file buffer-file-name))
(setq normalized-file (hypb:buffer-file-name)))

(if (setq but (when normalized-file (ebut:get key nil normalized-file)))
(hbut:act but)
Expand Down Expand Up @@ -528,7 +528,7 @@ on the implicit button to which to link."
(interactive
(let ((ibut-name-key (ibut:at-p t)))
(cond (ibut-name-key
(list ibut-name-key (or buffer-file-name (buffer-name)) (point)))
(list ibut-name-key (or (hypb:buffer-file-name) (buffer-name)) (point)))
;; !! TODO: If default is null below and are creating, rather than editing
;; the link, it would be better to throw an error than create
;; an invalid link, but it is difficult to tell which operation
Expand All @@ -546,9 +546,9 @@ on the implicit button to which to link."
normalized-file)
(if but-src
(unless (and (get-buffer but-src)
(not (buffer-file-name (get-buffer but-src))))
(not (hypb:buffer-file-name (get-buffer but-src))))
(setq normalized-file (hpath:normalize but-src)))
(setq normalized-file (hpath:normalize buffer-file-name)))
(setq normalized-file (hpath:normalize (hypb:buffer-file-name))))
(when but-src
(set-buffer (or (get-buffer but-src) (get-file-buffer normalized-file))))
(widen)
Expand Down Expand Up @@ -584,12 +584,12 @@ If CELL-REF is nil, show the first cell in the view."
;; matching of path is likely to be wrong in
;; certain cases, e.g. with mount point or os path
;; alterations.
buffer-file-name
(hypb:buffer-file-name)
file
(or (null file)
(string-empty-p file)
(equal (file-name-nondirectory file)
(file-name-nondirectory buffer-file-name))))
(file-name-nondirectory (hypb:buffer-file-name)))))
(when (or (null file) (string-empty-p file))
(setq file (hbut:get-key-src t)))
(if (stringp file)
Expand Down Expand Up @@ -698,7 +698,7 @@ FILE may be a string or nil, in which case the current buffer is used."
(setq file (expand-file-name file (hpath:expand "${hyperb:dir}/man/"))))
(if file
(set-buffer (find-file-noselect (hpath:substitute-value file)))
(setq file buffer-file-name))
(setq file (hypb:buffer-file-name)))
(save-excursion
(goto-char (point-min))
(if (re-search-forward (format "^@node[ \t]+%s *[,\n\r]" node) nil t)
Expand Down
6 changes: 3 additions & 3 deletions hargs.el
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ Handles all of the interactive argument types that `hargs:iform-read' does."
(no-default nil)
;; Possibly non-existent file name
((hpath:at-p 'file 'non-exist))
((buffer-file-name))))
((hypb:buffer-file-name))))
((eq hargs:reading-type 'directory)
(cond ((derived-mode-p 'dired-mode)
(let ((dir (or (smart-dired-pathname-up-to-point t)
Expand Down Expand Up @@ -715,8 +715,8 @@ Handles all of the interactive argument types that `hargs:iform-read' does."
(concat "(" file ")" node))
(t node)))))
((eq hargs:reading-type 'mail)
(and (hmail:reader-p) buffer-file-name
(prin1-to-string (list (rmail:msg-id-get) buffer-file-name))))
(and (hmail:reader-p) (hypb:buffer-file-name)
(prin1-to-string (list (rmail:msg-id-get) (hypb:buffer-file-name)))))
((eq hargs:reading-type 'symbol)
(let ((sym (hargs:find-tag-default)))
(when (or (fboundp sym) (boundp sym)) sym)))
Expand Down
8 changes: 7 additions & 1 deletion hasht.el
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
;; AUTHOR: Bob Weiner
;;
;; ORIG-DATE: 16-Mar-90 at 03:38:48
;; LAST-MOD: 29-Dec-24 at 12:37:57 by Mats Lidell
;; LAST-MOD: 5-Jan-25 at 12:21:16 by Bob Weiner
;;
;; Copyright (C) 1990-1995, 1997, 2016 Free Software Foundation, Inc.
;; See the file BR-COPY for license information.
Expand Down Expand Up @@ -45,6 +45,12 @@
;; Public and private function names are alphabetized for easy location.

;;; Code:
;;; ************************************************************************
;;; Other required Elisp libraries
;;; ************************************************************************

(require 'subr-x) ; for `hash-table-keys/values', `hash-table-empty-p'

;;; ************************************************************************
;;; Public variables
;;; ************************************************************************
Expand Down
14 changes: 7 additions & 7 deletions hbdata.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 2-Apr-91
;; Last-Mod: 2-Dec-24 at 01:48:15 by Bob Weiner
;; Last-Mod: 5-Jan-25 at 11:15:10 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -196,7 +196,7 @@ If the hbdata buffer is blank/empty, kill it and remove the associated file."
(when (looking-at empty-hbdata-file)
(setq kill t)))
(when kill
(let ((fname buffer-file-name))
(let ((fname (hypb:buffer-file-name)))
(erase-buffer) (save-buffer) (kill-buffer nil)
(hbmap:dir-remove (file-name-directory fname))
(delete-file fname))))))))
Expand Down Expand Up @@ -390,7 +390,7 @@ Return value of evaluation when a matching entry is found or nil."
(progn
(when (get-buffer key-src)
(set-buffer key-src)
(unless buffer-file-name
(unless (hypb:buffer-file-name)
(cond ((hmail:editor-p)
(setq end-func (lambda ()
(hmail:msg-narrow))))
Expand Down Expand Up @@ -421,7 +421,7 @@ Return value of evaluation when a matching entry is found or nil."
(hmail:hbdata-start))))))))
(setq found (hbdata:to-entry-buf key-src directory create-flag)))
(when found
(unless buffer-file-name
(unless (hypb:buffer-file-name)
;; Point must be left after hbdata separator or the logic
;; below could fail. Buffer should be widened already.
(goto-char (point-min))
Expand All @@ -445,14 +445,14 @@ Return value of evaluation when a matching entry is found or nil."

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

(defun hbdata:to-entry-in-buffer (create)
"Move point to end of line in but data in current buffer.
Expand Down Expand Up @@ -541,7 +541,7 @@ a button instance string to append to button label or t when first instance.
On failure, return nil."
(let ((cons (hbdata:ebut-build orig-lbl-key but-sym new-lbl-key))
entry lbl-instance)
(unless (or (and buffer-file-name (not (file-writable-p buffer-file-name)))
(unless (or (and (hypb:buffer-file-name) (not (file-writable-p (hypb:buffer-file-name))))
(null cons))
(setq entry (car cons) lbl-instance (cdr cons))
(prin1 entry (current-buffer))
Expand Down
10 changes: 8 additions & 2 deletions hbmap.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 06:34:05
;; Last-Mod: 3-Oct-23 at 17:49:44 by Mats Lidell
;; Last-Mod: 5-Jan-25 at 12:00:29 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand All @@ -15,6 +15,12 @@
;;; Commentary:

;;; Code:
;;; ************************************************************************
;;; Other required Elisp libraries
;;; ************************************************************************

(require 'hypb)

;;; ************************************************************************
;;; Public variables
;;; ************************************************************************
Expand Down Expand Up @@ -120,7 +126,7 @@ the error. Optional NO-SAVE disables saving of the map after operation."
(eval form)
(cond (no-save
t)
((file-writable-p buffer-file-name)
((file-writable-p (hypb:buffer-file-name))
(save-buffer)
t)
(t 'hbmap-not-writable))))
Expand Down
26 changes: 13 additions & 13 deletions hbut.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 18-Sep-91 at 02:57:09
;; Last-Mod: 5-Jan-25 at 01:12:45 by Bob Weiner
;; Last-Mod: 5-Jan-25 at 11:27:31 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -552,7 +552,7 @@ button is found in the current buffer."
(re-search-backward regexp nil t)))
(goto-char (+ (match-beginning 0) (length ebut:label-start))))))

(when (or (not buffer-file-name) (hmail:editor-p) (hmail:reader-p))
(when (or (not (hypb:buffer-file-name)) (hmail:editor-p) (hmail:reader-p))
(widen)
(hmail:msg-narrow))

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

(defun gbut:save-buffer ()
Expand Down Expand Up @@ -1055,7 +1055,7 @@ Default is the symbol hbut:current."
(delim-text-start (hattr:get hbut 'lbl-start))
(delim-text-end (hattr:get hbut 'lbl-end)))
(if (and name-key
(or (equal loc buffer-file-name)
(or (equal loc (hypb:buffer-file-name))
(equal loc (current-buffer)))
(equal name-key (ibut:label-to-key (hattr:get hbut 'name))))
(unless (and delim-text-start delim-text-end
Expand All @@ -1064,7 +1064,7 @@ Default is the symbol hbut:current."
(goto-char delim-text-start)
(skip-chars-forward "^-_a-zA-Z0-9"))
;; Here handle when there is no name preceding the implicit button.
(unless (and (or (equal loc buffer-file-name)
(unless (and (or (equal loc (hypb:buffer-file-name))
(equal loc (current-buffer)))
delim-text-start delim-text-end
(< delim-text-start (point))
Expand Down Expand Up @@ -1297,10 +1297,10 @@ is given."
cd 0 (string-match "\\s +\\'" cd)))
(expand-file-name cd wd))
wd)))
(buffer-file-name
((hypb:buffer-file-name)
(if full-flag
buffer-file-name
(file-name-nondirectory buffer-file-name)))
(hypb:buffer-file-name)
(file-name-nondirectory (hypb:buffer-file-name))))
;; Handle any preceding @loc hyp-source implicit button location references.
;; This is used in report buffers of explicit buttons, i.e. hui:hbut-report
;; as well as the *HyRolo* display matches buffer.
Expand Down Expand Up @@ -1347,10 +1347,10 @@ This is used to obtain the source of Hyperbole buttons for buffers that
represent the output of particular document formatters."
(when (or (eq major-mode 'Info-mode)
(string-match "\\.info\\(-[0-9]+\\)?$" (buffer-name)))
(let ((src (and buffer-file-name
(let ((src (and (hypb:buffer-file-name)
(substring
buffer-file-name
0 (string-match "\\.[^.]+$" buffer-file-name)))))
(hypb:buffer-file-name)
0 (string-match "\\.[^.]+$" (hypb:buffer-file-name))))))
(cond ((file-exists-p (concat src ".texi"))
(concat src ".texi"))
((file-exists-p (concat src ".texinfo"))
Expand Down Expand Up @@ -1747,7 +1747,7 @@ button label. Return the symbol for the button, else nil."
Keys in optional KEY-SRC or the current buffer."
(save-excursion
(save-restriction
(if (hbdata:to-entry-buf (or key-src (buffer-file-name)))
(if (hbdata:to-entry-buf (or key-src (hypb:buffer-file-name)))
(let (hbuts)
(save-restriction
(narrow-to-region (point) (if (search-forward "\f" nil t)
Expand Down
14 changes: 7 additions & 7 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: 1-Dec-24 at 20:33:59 by Bob Weiner
;; Last-Mod: 5-Jan-25 at 11:15:09 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -230,7 +230,7 @@ in all buffers."
(not (or (hmail:lister-p) (hnews:lister-p))))
(when (boundp 'hyrolo-display-buffer)
(equal (buffer-name) hyrolo-display-buffer))
(and buffer-file-name
(and (hypb:buffer-file-name)
(boundp 'hyrolo-file-list)
(set:member (current-buffer)
(mapcar #'get-file-buffer (hyrolo-get-file-list))))))
Expand Down Expand Up @@ -418,7 +418,7 @@ in buffers whose names begin with a space or asterisk character, must
not be in a programming mode, Markdown or Org buffer and must have an
attached file."
(and (not (bolp))
buffer-file-name
(hypb:buffer-file-name)
(let ((chr (aref (buffer-name) 0)))
(not (or (eq chr ?\ ) (eq chr ?*))))
(not (apply #'derived-mode-p
Expand Down Expand Up @@ -515,7 +515,7 @@ Url links are handled elsewhere."
(ibut:label-set (match-string-no-properties 0) (match-beginning 0) (match-end 0))
(setq npoint (point))
(goto-char opoint)
(hact 'link-to-file buffer-file-name npoint))
(hact 'link-to-file (hypb:buffer-file-name) npoint))
;; Follows an absolute file link.
(markdown-follow-inline-link-p opoint))
;; May be on the name of an infile link, so move to the
Expand Down Expand Up @@ -730,8 +730,8 @@ line."
Display selected files. Each file name must be at the beginning of the line
or may be preceded by some semicolons and must be followed by one or more
spaces and then another non-space, non-parenthesis, non-brace character."
(when buffer-file-name
(let ((file (file-name-nondirectory buffer-file-name))
(when (hypb:buffer-file-name)
(let ((file (file-name-nondirectory (hypb:buffer-file-name)))
entry start end)
(when (and (or (string-equal file "DIR")
(string-match "\\`MANIFEST\\(\\..+\\)?\\'" file))
Expand Down Expand Up @@ -1416,7 +1416,7 @@ documentation string is displayed."
(match-string-no-properties 2))
;; Derive file name from the source file name.
(let ((nodename (match-string-no-properties 2))
(file (file-name-nondirectory buffer-file-name)))
(file (file-name-nondirectory (hypb:buffer-file-name))))
(if show-texinfo-node
nodename
(format "(%s)%s"
Expand Down
10 changes: 8 additions & 2 deletions hmail.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 9-Oct-91 at 18:38:05
;; Last-Mod: 10-Mar-24 at 11:52:34 by Bob Weiner
;; Last-Mod: 5-Jan-25 at 12:01:15 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -31,6 +31,12 @@
;; with Hyperbole.

;;; Code:
;;; ************************************************************************
;;; Other required Elisp libraries
;;; ************************************************************************

(require 'hypb)

;;; ************************************************************************
;;; Public declarations
;;; ************************************************************************
Expand Down Expand Up @@ -101,7 +107,7 @@ Return t if button data is found, else nil."
(hmail:msg-narrow)
t)
((or (hmail:lister-p) (hnews:lister-p)) t)
((or (not buffer-file-name)
((or (not (hypb:buffer-file-name))
(memq major-mode (list hmail:composer hnews:reader
hnews:composer)))
(widen)
Expand Down
Loading
Loading