branch: externals/hyperbole
commit ce9633ca26562f8d8da1e9b08daa76a3644eda50
Author: Mats Lidell <[email protected]>
Commit: Mats Lidell <[email protected]>
Fix hpath
---
ChangeLog | 3 ++
hpath.el | 115 +++++++++++++++++++++-------------------------------
test/hpath-tests.el | 4 +-
3 files changed, 51 insertions(+), 71 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 319d289d38..4c9ae5bc71 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
2025-11-30 Mats Lidell <[email protected]>
+* hpath.el (hpath:find-file-mailcap): Remove unused.
+ (hmail:editor-p): Declare function.
+
* test/hpath-tests.el (hpath--posix-path-p)
(hpath--posix-to-mswindows-separators)
(hpath--mswindows-to-posix-separators, hpath--posix-to-mswindows)
diff --git a/hpath.el b/hpath.el
index ec83e19974..6df81aabbc 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: 23-Nov-25 at 13:16:50 by Bob Weiner
+;; Last-Mod: 30-Nov-25 at 19:58:24 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -131,22 +131,22 @@ The format is ${variable}. Match grouping 1 is the name
of the variable.")
;;; ************************************************************************
;;; Public Declarations
;;; ************************************************************************
-(declare-function br-quit "ext:br")
+
+(declare-function Info-find-node "info")
(declare-function br-in-browser "ext:br")
+(declare-function br-quit "ext:br")
(declare-function br-to-view-window "ext:br")
-
-(declare-function mm-mailcap-command "mm-decode")
-(declare-function hypb:decode-url "hypb")
+(declare-function hargs:delimited "hargs")
(declare-function hattr:get "hbut")
-(declare-function kbd-key:key-series-to-events "hib-kbd")
-(declare-function hbut:label-to-key "hbut")
(declare-function hbut:key-to-label "hbut")
-(declare-function hargs:delimited "hargs")
+(declare-function hbut:label-to-key "hbut")
+(declare-function hmail:editor-p "hmail")
+(declare-function hypb:decode-url "hypb")
(declare-function hypb:object-p "hypb")
-(declare-function Info-find-node "info")
-
+(declare-function kbd-key:key-series-to-events "hib-kbd")
(declare-function kcell-view:indent "kcell-view")
(declare-function klink:act "klink")
+(declare-function mm-mailcap-command "mm-decode")
;;; ************************************************************************
;;; MS WINDOWS PATH CONVERSIONS
@@ -207,17 +207,16 @@ converted path with the value of
`hpath:mswindows-mount-prefix'."
(when (and (stringp path) (not (equal path "\\\\")))
(setq path (hpath:mswindows-to-posix-separators path))
(when (string-match hpath:mswindows-drive-regexp path)
- (when (string-match hpath:mswindows-drive-regexp path)
- (let* ((drive-prefix (downcase (match-string 2 path)))
- (rest-of-path (substring path (match-end 0)))
- (absolute-p (and (not (string-empty-p rest-of-path))
- (= (aref rest-of-path 0) ?/))))
- ;; Convert MSWindows disk drive paths to POSIX-style with a mount
prefix.
- (setq path (concat hpath:mswindows-mount-prefix drive-prefix
- (cond (hyperb:microsoft-os-p ":")
- (absolute-p "")
- (t "/"))
- rest-of-path))))))
+ (let* ((drive-prefix (downcase (match-string 2 path)))
+ (rest-of-path (substring path (match-end 0)))
+ (absolute-p (and (not (string-empty-p rest-of-path))
+ (= (aref rest-of-path 0) ?/))))
+ ;; Convert MSWindows disk drive paths to POSIX-style with a mount
prefix.
+ (setq path (concat hpath:mswindows-mount-prefix drive-prefix
+ (cond (hyperb:microsoft-os-p ":")
+ (absolute-p "")
+ (t "/"))
+ rest-of-path)))))
path)
(defun hpath:mswindows-to-posix-separators (path)
@@ -242,23 +241,18 @@ If path begins with an optional mount prefix,
letter, remove the mount prefix."
(interactive "sPOSIX path to convert to MSWindows: ")
(when (stringp path)
- (setq path (hpath:posix-to-mswindows-separators path))
- ;; Remove any POSIX mount prefix preceding an MSWindows path.
- (if (eq 0 (string-match hpath:mswindows-mount-prefix path))
- (setq path (substring path (match-end 0))))
(when (string-match hpath:mswindows-drive-regexp path)
- (when (string-match hpath:mswindows-drive-regexp path)
- (let* ((drive-prefix (downcase (match-string 2 path)))
- (rest-of-path (substring path (match-end 0)))
- (absolute-p (= (aref path (1- (match-end 0))) ?\\)))
- ;; Convert formerly Posix-style Windows disk drive paths to
MSWindows-style.
- (setq path (concat drive-prefix ":"
- (if (or (not absolute-p)
- (string-match "\\`[~/]" rest-of-path))
- ""
- "\\")
- rest-of-path))))))
- path)
+ (let* ((drive-prefix (downcase (match-string 2 path)))
+ (absolute-p (= (aref path (1- (match-end 0))) ?/))
+ (rest-of-path (substring path (match-end 0))))
+ ;; Convert formerly Posix-style Windows disk drive paths to
MSWindows-style.
+ (setq path (concat drive-prefix ":"
+ (if (or (not absolute-p)
+ (string-match "\\`[~/]" rest-of-path))
+ ""
+ "/")
+ rest-of-path))))
+ (hpath:posix-to-mswindows-separators path)))
(defun hpath:posix-to-mswindows-separators (path)
"Replace forward slashes with backslashes and abbreviate the PATH if
possible.
@@ -1409,20 +1403,22 @@ If PATH is absolute, return it unchanged."
(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."
- (when (and (stringp path-line-and-col)
- (string-match hpath:section-line-and-column-regexp
path-line-and-col))
- ;; Ensure any variables and heading suffixes following [#,] are removed
before returning file.
- (let ((file (save-match-data (hpath:expand (match-string-no-properties 1
path-line-and-col))))
- (line-num (string-to-number (match-string-no-properties 3
path-line-and-col)))
- (col-num (when (match-end 4)
- (string-to-number (match-string-no-properties 5
path-line-and-col)))))
- (when (and (save-match-data (setq file (hpath:is-p file)))
- file)
- (if line-num
- (if col-num
- (list file line-num col-num)
- (list file line-num))
- (list file))))))
+ (when (stringp path-line-and-col)
+ (cond ((string-match hpath:section-line-and-column-regexp
path-line-and-col)
+ ;; Ensure any variables and heading suffixes following [#,] are
removed before returning file.
+ (let ((file (save-match-data (hpath:expand
(match-string-no-properties 1 path-line-and-col))))
+ (line-num (string-to-number (match-string-no-properties 3
path-line-and-col)))
+ (col-num (when (match-end 4)
+ (string-to-number (match-string-no-properties 5
path-line-and-col)))))
+ (when (and (save-match-data (setq file (hpath:is-p file)))
+ file)
+ (if line-num
+ (if col-num
+ (list file line-num col-num)
+ (list file line-num))))))
+ (t (let ((file (hpath:is-p (hpath:expand path-line-and-col))))
+ (when file
+ (list file)))))))
(defun hpath:file-position-to-line-and-column (path position)
"Return \"path:L<line-num>:C<col-num>\" given PATH and character POSITION.
@@ -2559,23 +2555,6 @@ from path or t."
(or suffix t)
return-path))))
-;; Next function from: 2006-11-02 Mats Lidell
-(defun hpath:find-file-mailcap (file-name)
- "Find command to view FILE-NAME according to the mailcap file."
- (when (featurep 'mailcap)
- (mailcap-parse-mailcaps)
- (let (mime-type method)
- (when (and (string-match "\\.[^\\.]+$" file-name)
- (setq mime-type
- (mailcap-extension-to-mime
- (match-string-no-properties 0 file-name)))
- (stringp
- (setq method
- (cdr (assoc 'viewer
- (car (mailcap-mime-info mime-type
- 'all)))))))
- (mm-mailcap-command method file-name nil)))))
-
(defun hpath:find-program (filename)
"Return one or a list of shell or Lisp commands to execute to display
FILENAME.
Return nil if FILENAME is a directory name or an image file that
diff --git a/test/hpath-tests.el b/test/hpath-tests.el
index 5a77054049..3f77edfa92 100644
--- a/test/hpath-tests.el
+++ b/test/hpath-tests.el
@@ -3,7 +3,7 @@
;; Author: Mats Lidell <[email protected]>
;;
;; Orig-Date: 28-Feb-21 at 23:26:00
-;; Last-Mod: 2-Dec-25 at 12:45:48 by Mats Lidell
+;; Last-Mod: 2-Dec-25 at 12:46:06 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
@@ -93,7 +93,6 @@
(ert-deftest hpath--posix-to-mswindows ()
"Verify `hpath:posix-to-mswindows'."
- :expected-result :failed
(dolist (v '(("/dir/subdir/file" . "\\dir\\subdir\\file")
("/mnt/a/dir/subdir/file" . "a:\\dir\\subdir\\file")))
(let ((posix (car v))
@@ -689,7 +688,6 @@ dir/subdir:
(ert-deftest hpath--file-line-and-column ()
"Verify `hpath:file-line-and-column'."
- :expected-result :failed
(should-not (hpath:file-line-and-column 'not-a-string))
(should-not (hpath:file-line-and-column "does-not-exist"))
(should (equal (hpath:file-line-and-column "/tmp") '("/tmp")))