Skip to content

Instantly share code, notes, and snippets.

@d5884
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d5884/a2a38bb6971fe0eb43ce to your computer and use it in GitHub Desktop.
Save d5884/a2a38bb6971fe0eb43ce to your computer and use it in GitHub Desktop.
windows drive mapper for emacs on cygwin
;; windows drive mapper for emacs on cygwin
(add-to-list 'file-name-handler-alist
'("\\<[a-zA-Z]:" . w32-map-drive))
(defun w32-map-drive (operation &rest args)
(let ((fn (get operation 'w32-map-drive)))
(if fn
(apply fn args)
(w32-map-drive-run-real-handler operation args))))
(defun w32-map-drive-run-real-handler (operation args)
(let ((inhibit-file-name-handlers
(cons 'w32-map-drive
(and (eq inhibit-file-name-operation operation)
inhibit-file-name-handlers)))
(inhibit-file-name-operation operation))
(apply operation args)))
(put 'file-name-directory 'w32-map-drive 'w32-map-drive-file-name-directory)
(put 'expand-file-name 'w32-map-drive 'w32-map-drive-expand-file-name)
(put 'substitute-in-file-name 'w32-map-drive 'w32-map-drive-substitute-in-file-name)
(defun w32-map-drive-file-name-directory (filename)
(if (string-match-p "\\`[a-zA-Z]:\\'" filename)
(concat filename "/")
(w32-map-drive-run-real-handler 'file-name-directory (list filename))))
(defun w32-map-drive-expand-file-name (name &optional default-directory)
(w32-map-drive-run-real-handler
'expand-file-name
(list (cygwin-convert-file-name-from-windows name)
default-directory)))
(defun w32-map-drive-substitute-in-file-name (filename)
(save-match-data
(w32-map-drive-run-real-handler
'substitute-in-file-name
(list (cygwin-convert-file-name-from-windows
(replace-regexp-in-string "^.*\\<\\([a-zA-Z]:\\)" "\\1" filename))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment