emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] scratch/hyperbole-merge-7.0.2b 09e646e 17/23: Add implicit path b


From: Stefan Monnier
Subject: [elpa] scratch/hyperbole-merge-7.0.2b 09e646e 17/23: Add implicit path button support for MSWindows paths
Date: Tue, 5 Feb 2019 16:11:21 -0500 (EST)

branch: scratch/hyperbole-merge-7.0.2b
commit 09e646e163135178d504a126bb4d1658aa45300e
Author: Bob Weiner <address@hidden>
Commit: Bob Weiner <address@hidden>

    Add implicit path button support for MSWindows paths
---
 Changes      | 10 +++++++
 HY-NEWS      |  7 ++---
 hargs.el     |  9 ++++---
 hpath.el     | 87 ++++++++++++++++++++++++++++++++++++++++--------------------
 hyperbole.el | 11 +++++---
 5 files changed, 83 insertions(+), 41 deletions(-)

diff --git a/Changes b/Changes
index a9a9bae..11b6821 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,13 @@
+2019-01-21  Bob Weiner  <address@hidden>
+
+* hpath.el (hpath:mswindows-mount-prefix, hpath:mswindows-drive-regexp)
+    (hpath:mswindows-to-posix-path, hpath:mswindows-to-posix-separators):
+      Added to handle MSWindows path under POSIX OSes, e.g. Windows Subsystem 
for Linux.
+    (hpath:find-program): Commented out call to hpath:find-file-mailcap to 
prevent use of
+      MIME external viewers on text files.
+  hargs.el (hargs:delimited): Added call to hpath:mswindows-to-posix-path.
+  hyperbole.el (hyperb:init): Abbreviated MSWindows mount point paths.
+
 2017-12-29  Bob Weiner  <address@hidden>
 
 * hsettings.el (inhibit-hyperbole-messaging): Moved this from hyperbole.el to 
here to prevent
diff --git a/HY-NEWS b/HY-NEWS
index 2c9ef33..40fcdca 100644
--- a/HY-NEWS
+++ b/HY-NEWS
@@ -149,7 +149,7 @@
       explicit buttons are highlighted with a special colored face or not.  By
       default, they are.
 
-    - Python PDB Backtraces: Action Key presses jump to the associated source
+    - Python Backtraces: Action Key presses jump to the associated source
       line.
 
     - Python Symbols: Action Key presses now look these up in any buffer whose
@@ -164,7 +164,7 @@
       source of any such lines.
 
     - Dired Quit: An Action Key press at the end of the first line in a Dired
-      buffer nows quit and execute requested actions, just as presses at the
+      buffer now quits and executes requested actions, just as presses at the
       end of the buffer do.
 
     - Image Thumbnail Browsing: See the Info manual section,
@@ -356,9 +356,6 @@
       new settings with {M-x hmouse-update-smart-keys RET}.  No need to reload
       or restart Hyperbole.
 
-    - Find Web: Added Find Web key binding entry to Hyperbole menus.  This key
-      displays the Hyperbole Web search menu.
-
     - Jump Thing: Added Jump Thing key binding entry to Hyperbole menus.  This
       key jumps between the start and end of a matching delimiter or tag pair.
 
diff --git a/hargs.el b/hargs.el
index 50cea02..bb3ac5f 100644
--- a/hargs.el
+++ b/hargs.el
@@ -4,7 +4,7 @@
 ;;
 ;; Orig-Date:    31-Oct-91 at 23:17:35
 ;;
-;; Copyright (C) 1991-2016  Free Software Foundation, Inc.
+;; Copyright (C) 1991-2019  Free Software Foundation, Inc.
 ;; See the "HY-COPY" file for license information.
 ;;
 ;; This file is part of GNU Hyperbole.
@@ -128,9 +128,10 @@ With optional LIST-POSITIONS-FLAG, return list of 
(string-matched start-pos end
                 (setq end (1- end))
               t)
             (< start end)
-            (let ((string (substring-no-properties
-                           (hypb:replace-match-string
-                            "[\n\r]\\s-*" (buffer-substring start end) " " 
t))))
+            (let ((string (buffer-substring-no-properties start end)))
+              (setq string (hypb:replace-match-string "[\n\r]\\s-*" string " " 
t))
+              (unless hyperb:microcruft-os-p
+                (setq string (hpath:mswindows-to-posix-path string)))
               (if list-positions-flag
                   (list string start end)
                 string)))))))
diff --git a/hpath.el b/hpath.el
index a391447..8e13d55 100755
--- a/hpath.el
+++ b/hpath.el
@@ -1,10 +1,10 @@
-;;; hpath.el --- GNU Hyperbole support routines for handling UNIX paths
+;;; hpath.el --- GNU Hyperbole support routines for handling POSIX and 
MSWindows paths
 ;;
 ;; Author:       Bob Weiner
 ;;
 ;; Orig-Date:     1-Nov-91 at 00:44:23
 ;;
-;; Copyright (C) 1991-2016  Free Software Foundation, Inc.
+;; Copyright (C) 1991-2019  Free Software Foundation, Inc.
 ;; See the "HY-COPY" file for license information.
 ;;
 ;; This file is part of GNU Hyperbole.
@@ -43,30 +43,55 @@ Default is `nil' since this can slow down normal file 
finding."
 ;;; 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
+;; This section adds automatic recognition of MSWindows implicit path
+;; links and converts disk drive and path separators to whatever
+;; format is needed by the underlying OS upon which Emacs is one,
+;; notably either for POSIX or MSWindows (with no POSIC layer).
+
+;; Especially useful when running Emacs under Windows Subsystem for
+;; Linux (WSL) where the system-type variable is gnu/linux but
+;; MSWindows is underneath so the user likely has many Windows
+;; formatted links.
+
+;; See "https://docs.microsoft.com/en-us/dotnet/standard/io/file-path-formats";
+;; and "https://docs.microsoft.com/en-us/windows/wsl/interop"; for
+;; Windows path specifications and use under WSL.
+
+(defvar hpath:mswindows-mount-prefix
+  (cond ((eq system-type 'cygwin)
+        "/cygdrive/")
+       (hyperb:microcruft-os-p
+        "")
+       (t ;; POSIX
+       "/mnt/"))
+  "Path prefix to add when converting MSWindows drive paths to POSIX-style.
+Must include a trailing directory separator or be nil.")
+
+(defconst hpath:mswindows-drive-regexp "\\`[\\/]?\\([a-zA-Z]\\)[:/]"
+  "Regular expression matching an MSWindows drive letter at the beginning of a 
path string.")
+
+(defconst hpath:mswindows-path-regexp "\\`.*\\.*[a-zA-Z0-9_.]"
+  "Regular expression matching the start of an MSWindows path that does not 
start with a drive letter but contains directory separators.")
+
+(defun hpath:mswindows-to-posix-path (path)
+  "Convert a recognizable MSWindows PATH to a POSIX-style path or return the 
path unchanged.
+If path begins with an MSWindows drive letter, prefix the converted path with 
the value of 'hpath:mswindows-mount-prefix'."
+  (when (stringp path)
+    (cond ((string-match hpath:mswindows-drive-regexp path)
+          ;; Convert Windows disk drive paths to POSIX-style with a mount 
prefix.
+          (setq path (concat hpath:mswindows-mount-prefix (downcase 
(match-string 1 path))
+                             (if hyperb:microcruft-os-p ":" "/")
+                             (substring path (match-end 0)))
+                path (hpath:mswindows-to-posix-separators path)))
+         ((string-match hpath:mswindows-path-regexp path)
+          (setq path (hpath:mswindows-to-posix-separators path)))))
+  path)
+
+(defun hpath:mswindows-to-posix-separators (path)
+  "Replace all backslashes with forward slashes in PATH and abbreviate the 
path if possible.
+Path must be a string or an error will be triggered.  See
+'abbreviate-file-name' for how path abbreviation is handled."
+  (abbreviate-file-name (replace-regexp-in-string "\\\\" "/" path)))
 
 ;;; ************************************************************************
 ;;; FILE VIEWER COMMAND SETTINGS
@@ -831,7 +856,7 @@ See also `hpath:internal-display-alist' for internal, 
window-system independent
                             (cons "next" 
hpath:external-display-alist-macos)))))))
 
 (defun hpath:is-p (path &optional type non-exist)
-  "Returns PATH if PATH is a Unix path, else nil.
+  "Returns PATH if PATH is a Posix path, else nil.
 If optional TYPE is the symbol 'file or 'directory, then only that path type
 is accepted as a match.  The existence of the path is checked only for
 locally reachable paths (Info paths are not checked).  Single spaces are
@@ -1021,7 +1046,7 @@ After any match, the resulting path will contain a 
varible reference like ${vari
       )))
 
 ;;
-;; The following function recursively resolves all UNIX links to their
+;; The following function recursively resolves all POSIX links to their
 ;; final referents.
 ;; Works with variable-based and other strange links like:
 ;; /usr/local -> $(SERVER_LOCAL)/usr/local, /usr/bin ->
@@ -1359,7 +1384,11 @@ See also documentation for the function 
(hpath:get-external-display-alist) and t
        ((and (fboundp 'image-mode)
              (string-match hpath:native-image-suffixes filename))
         nil)
-       (t (hpath:find-file-mailcap filename))))
+       ;; 01/21/2019 - RSW commented this next line out since it can
+       ;; trigger external viewers on many file types that Emacs
+       ;; displays natively.
+       ;; (t (hpath:find-file-mailcap filename))
+       ))
 
 (defun hpath:match (filename regexp-alist)
   "If FILENAME matches the car of any element in REGEXP-ALIST, return its cdr.
diff --git a/hyperbole.el b/hyperbole.el
index c1fbcbe..76f5af2 100644
--- a/hyperbole.el
+++ b/hyperbole.el
@@ -1,12 +1,12 @@
 ;;; hyperbole.el --- GNU Hyperbole: The Everyday Hypertextual Information 
Manager
 
-;; Copyright (C) 1992-2017  Free Software Foundation, Inc.
+;; Copyright (C) 1992-2019  Free Software Foundation, Inc.
 
 ;; Author:           Bob Weiner
 ;; Maintainer:       Bob Weiner <address@hidden> and Mats Lidell 
<address@hidden>
 ;; Created:          06-Oct-92 at 11:52:51
-;; Released:         23-Nov-17
-;; Version:          7.0.2a
+;; Released:         21-Jan-19
+;; Version:          7.0.3
 ;; Keywords:         comm, convenience, files, frames, hypermedia, languages, 
mail, matching, mouse, multimedia, outlines, tools, wp
 ;; Package:          hyperbole
 ;; Package-Requires: ((emacs "24.4"))
@@ -681,6 +681,11 @@ If FLAG is nil then text is shown, while if FLAG is t the 
text is hidden."
   ;; Conditionally initialize Hyperbole key bindings (when hkey-init is t)
   (hkey-initialize)
   ;;
+  ;; Abbreviate MSWindows mount point paths.
+  (when (or (file-exists-p "/mnt/c")
+           (file-exists-p "/cygdrive"))
+    (add-to-list 'directory-abbrev-alist '("\\`\\(/mnt\\|/cygdrive\\)/" . 
"/")))
+  ;;
   ;; Save button attribute file whenever same dir file is saved and
   ;; `ebut:hattr-save' is non-nil.
   (add-hook (if (boundp 'write-file-functions)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]