branch: scratch/hyperbole-merge-7.0.2b
commit 2e878cbf1993485fba3b2581e84ce77d22b4e56a
Author: Bob Weiner <[email protected]>
Commit: Bob Weiner <[email protected]>
Initial commit of Windows path handling
---
hibtypes.el | 11 ++++++++---
hpath.el | 33 +++++++++++++++++++++++++++++++--
2 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/hibtypes.el b/hibtypes.el
old mode 100644
new mode 100755
index 47af123..f4dd991
--- a/hibtypes.el
+++ b/hibtypes.el
@@ -177,6 +177,12 @@ See `hpath:find' function documentation for special file
display options."
;;; Displays files at specific lines and optional column number locations.
;;; ========================================================================
+(defconst hibtypes-path-line-and-col-regexp
+ (if (eq system-type 'windows-nt)
+ ;; Allow for 'c:' single letter drive prefixes on Windows
+ "\\([^ \t\n\r:][^ \t\n\r]+\\):\\([0-9]+\\)\\(:\\([0-9]+\\)\\)?"
+ "\\([^ \t\n\r:]+\\):\\([0-9]+\\)\\(:\\([0-9]+\\)\\)?"))
+
(defib pathname-line-and-column ()
"Makes a valid pathname:line-num[:column-num] pattern display the path at
line-num and optional column-num.
Also works for remote pathnames.
@@ -187,8 +193,7 @@ removed from pathname when searching for a valid match.
See `hpath:find' function documentation for special file display options."
(let ((path-line-and-col (hpath:delimited-possible-path)))
(if (and (stringp path-line-and-col)
- (string-match "\\([^ \t\n\r:]+\\):\\([0-9]+\\)\\(:\\([0-9]+\\)\\)?"
- path-line-and-col))
+ (string-match hibtypes-path-line-and-col-regexp path-line-and-col))
(let ((file (expand-file-name (match-string-no-properties 1
path-line-and-col)))
(line-num (string-to-number (match-string-no-properties 2
path-line-and-col)))
(col-num (if (match-end 3) (string-to-number
(match-string-no-properties
@@ -740,7 +745,7 @@ This works with JavaScript and Python tracebacks, gdb, dbx,
and xdb. Such lines
(save-excursion
(beginning-of-line)
(cond
- ;; Python pdb
+ ;; Python pdb or traceback
((looking-at ".+ File \"\\([^\"\n\r]+\\)\", line \\([0-9]+\\)")
(let* ((file (match-string-no-properties 1))
(line-num (match-string-no-properties 2))
diff --git a/hpath.el b/hpath.el
old mode 100644
new mode 100755
index d26678d..a391447
--- a/hpath.el
+++ b/hpath.el
@@ -40,6 +40,35 @@ Default is `nil' since this can slow down normal file
finding."
:group 'hyperbole-buttons)
;;; ************************************************************************
+;;; MS WINDOWS PATH CONVERSIONS
+;;; ************************************************************************
+
+(defvar hpath:windows-mount-prefix "/mnt"
+ "Unix-style path prefix to add when converting MS Windows drive paths.")
+
+(defvar hpath:windows-system-type-list '(cygwin windows-nt ms-dos)
+ "List of 'system-type' values for which Windows paths are not converted to
UNIX-style.")
+
+(defun hpath:windows-to-unix-path(path)
+ "Convert a recognizable Windows path to a UNIX-style path.
+If path begins with a Windows drive letter, prefix the converted path with the
value of 'windows-mount-prefix'."
+ (if (not (memq system-type hpath:windows-system-type-list))
+ ;; Convert Windows disk drive paths to UNIX-style with a mount prefix.
+ (cond ((and (stringp path) (string-match "\\`\\([a-zA-Z]\\):" path))
+ (expand-file-name
+ (concat (match-string 1 path) "/" (substring path (match-end 0)))
+ hpath:windows-mount-prefix))
+ ;; !! Finish handling Windows network paths with forward
+ ;; or backward slashes
+ ((and (stringp path) (string-match "\\`\\(//\\|\\\\\\\\\\)[^/\\]"
path))
+ path)
+ (t path))))
+
+;; Replace all backslashes with forward slashes in path
+;;(defun a (path)
+;; (regexp-re
+
+;;; ************************************************************************
;;; FILE VIEWER COMMAND SETTINGS
;;; ************************************************************************
@@ -854,7 +883,7 @@ nonexistent local paths are allowed."
(not (string-match "[\t\n\r\"`'|{}\\]" path))
(or (not (hpath:www-p path))
(string-match "\\`ftp[:.]" path))
- (let ((remote-path (string-match "@.+:\\|^/.+:\\|.+:/" path)))
+ (let ((remote-path (string-match "@.+:\\|^/.+:\\|..+:/" path)))
(if (cond (remote-path
(cond ((eq type 'file)
(not (string-equal "/" (substring path -1))))
@@ -1271,7 +1300,7 @@ Returns \"anonymous\" if no default user is set."
string)))
(defun hpath:exists-p (path &optional suffix-flag)
- "Return PATH if it exists. (This does not mean you can read it.)
+ "Return PATH if it exists. (This does not mean you can read it).
If PATH exists with or without a suffix from hpath:suffixes, then that
pathname is returned.