branch: externals/hyperbole
commit 06608abdf9d069a14579f950bf909f15506fc5f8
Author: bw <[email protected]>
Commit: bw <[email protected]>
hpath:file-position-to-line-and-column: Fix shorten path default-dir
hbut.el (ibut:insert-text): Remove duplicate 'actypes::link-to-file'
clause.
---
ChangeLog | 7 +++++++
hbut.el | 23 +++++++++--------------
hpath.el | 26 ++++++++++++++------------
3 files changed, 30 insertions(+), 26 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ff85eac283..ca85afc522 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-04-26 Bob Weiner <[email protected]>
+
+* hbut.el (ibut:insert-text): Remove duplicate 'actypes::link-to-file' clause.
+
+* hpath.el (hpath:file-position-to-line-and-column): Fix to shorten path
+ in the current directory, not within the buffer of path.
+
2025-04-20 Bob Weiner <[email protected]>
* test/hui-tests.el (hui--link-possible-types): Change Outline Heading
diff --git a/hbut.el b/hbut.el
index 4b4b45525d..fbe82677d0 100644
--- a/hbut.el
+++ b/hbut.el
@@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 18-Sep-91 at 02:57:09
-;; Last-Mod: 20-Apr-25 at 15:16:34 by Bob Weiner
+;; Last-Mod: 26-Apr-25 at 10:12:23 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -2700,13 +2700,6 @@ Summary of operations based on inputs (name arg from
\\='hbut:current attrs):
('actypes::link-to-ebut (progn (insert "<elink:" arg1)
(when arg2 (insert ": " arg2))
(insert ">")))
- ('actypes::link-to-file
- ;; arg2 when given is a buffer position
- (insert "\""
- (if arg2
- (hpath:file-position-to-line-and-column arg1 arg2)
- (hpath:shorten arg1))
- "\""))
('actypes::link-to-ibut (progn (insert "<ilink:" arg1)
(when arg2 (insert ": " arg2))
(insert ">")))
@@ -2735,12 +2728,14 @@ Summary of operations based on inputs (name arg from
\\='hbut:current attrs):
(format "\"%s:%d\"" (hpath:shorten arg1) arg2)
(format "\"%s:%d:%d\"" (hpath:shorten arg1) arg2 arg3))))
('actypes::link-to-file
- (insert (format "\"%s\""
- (if (/= (length args) 2)
- ;; filename only
- (hpath:shorten arg1)
- ;; includes buffer pos that we translate to line:col
- (hpath:file-position-to-line-and-column arg1 arg2)))))
+ ;; arg2 when given is a buffer position
+ (insert "\""
+ (if arg2
+ ;; includes buffer pos that we translate to line:col
+ (hpath:file-position-to-line-and-column arg1 arg2)
+ ;; filename only
+ (hpath:shorten arg1))
+ "\""))
('actypes::link-to-string-match
(insert (format "\"%s#%s%s\"" (hpath:shorten arg3) arg1
(if (<= arg2 1) "" (concat ":I" (number-to-string
arg2))))))
diff --git a/hpath.el b/hpath.el
index 89e1bd60a9..3c0b863b94 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: 13-Apr-25 at 01:06:44 by Bob Weiner
+;; Last-Mod: 26-Apr-25 at 10:22:42 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -1401,17 +1401,19 @@ Parse out the parts and return a list, else nil."
(list file))))))
(defun hpath:file-position-to-line-and-column (path position)
- "Return \"path:line-num:col-num\" given PATH and character POSITION.
-The path in the result is abbreviated when possible."
- (with-current-buffer (find-file-noselect path)
- (save-excursion
- (goto-char position)
- (if (zerop (current-column))
- (format "%s:L%d" (hpath:shorten path) (line-number-at-pos (point) t))
- (format "%s:L%d:C%d"
- (hpath:shorten path)
- (line-number-at-pos (point) t)
- (current-column))))))
+ "Return \"path:L<line-num>:C<col-num>\" given PATH and character POSITION.
+If col-num is 0, the :C<col-num> is excluded. The path in the
+result is abbreviated relative to the caller's buffer directory."
+ (let ((shortened-path (hpath:shorten path)))
+ (with-current-buffer (find-file-noselect path)
+ (save-excursion
+ (goto-char position)
+ (if (zerop (current-column))
+ (format "%s:L%d" shortened-path (line-number-at-pos (point) t))
+ (format "%s:L%d:C%d"
+ shortened-path
+ (line-number-at-pos (point) t)
+ (current-column)))))))
(defun hpath:find-noselect (filename)
"Find but don't display FILENAME.