1 |
|
2 (defvar cygwin-winpath-cygdrive-prefix "/cygdrive") |
|
3 |
|
4 (defconst cygwin-winpath-regex-forward-slash "\\`\\([a-zA-Z]\\):/") |
|
5 (defconst cygwin-winpath-regex-backward-slash "\\`\\([a-zA-Z]\\):\\\\") |
|
6 (defconst cygwin-winpath-regex-list (list cygwin-winpath-regex-forward-slash cygwin-winpath-regex-backward-slash)) |
|
7 |
|
8 (defun cygwin-winpath-cygwin-file-name (winpath) |
|
9 (cond |
|
10 ((string-match cygwin-winpath-regex-forward-slash winpath) |
|
11 (concat cygwin-winpath-cygdrive-prefix "/" (downcase (match-string 1 winpath)) "/" (substring winpath (match-end 0)))) |
|
12 ((string-match cygwin-winpath-regex-backward-slash winpath) |
|
13 (concat cygwin-winpath-cygdrive-prefix "/" (downcase (match-string 1 winpath)) "/" (replace-regexp-in-string "\\\\" "/" (substring winpath (match-end 0))))) |
|
14 (t winpath))) |
|
15 |
|
16 ;; (cygwin-winpath-cygwin-file-name "c:/home/my.txt") |
|
17 ;; (cygwin-winpath-cygwin-file-name "c:\\home\\my.txt") |
|
18 |
|
19 (defun cygwin-winpath--mapping-function (op winname &rest args) |
|
20 (let ((inhibit-file-name-handlers (cons #'cygwin-winpath--mapping-function inhibit-file-name-handlers)) |
|
21 (inhibit-file-name-operation op)) |
|
22 (apply op (cygwin-winpath-cygwin-file-name winname) args))) |
|
23 |
|
24 (defvar cygwin-winpath-activated nil) |
|
25 |
|
26 (defun cygwin-winpath--fail-if-not-cygwin () |
|
27 (unless (eq system-type 'cygwin) |
|
28 (error "Mode is suppose to work only inside Cygwin"))) |
|
29 |
|
30 ;;;###autoload |
|
31 (defun cygwin-winpath-activate () |
|
32 "Start interpret Windows paths inside Cygwin Emacs." |
|
33 (interactive) |
|
34 (cygwin-winpath--fail-if-not-cygwin) |
|
35 (unless cygwin-winpath-activated |
|
36 (mapc (lambda (regex) |
|
37 (add-to-list 'file-name-handler-alist (cons regex #'cygwin-winpath--mapping-function))) |
|
38 cygwin-winpath-regex-list) |
|
39 (setq cygwin-winpath-activated t))) |
|
40 |
|
41 ;;;###autoload |
|
42 (defun cygwin-winpath-deactivate () |
|
43 "Stop interpret Windows paths inside Cygwin Emacs." |
|
44 (interactive) |
|
45 (cygwin-winpath--fail-if-not-cygwin) |
|
46 (when cygwin-winpath-activated |
|
47 (mapc (lambda (regex) |
|
48 (setf file-name-handler-alist (cl-delete regex file-name-handler-alist :key #'car :test #'equal))) |
|
49 cygwin-winpath-regex-list) |
|
50 (setq cygwin-winpath-activated t))) |
|
51 |
|
52 (provide 'cygwin-winpath) |
|