delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/1998/03/11/12:22:23

From: buehring AT i2 DOT com (Walt Buehring)
Subject: Emacs and Cygwin pathnames
11 Mar 1998 12:22:23 -0800 :
Message-ID: <u7m61eizc.fsf.cygnus.gnu-win32@xyzzy.com>
To: ntemacs-users AT cs DOT washington DOT edu, gnu-win32 AT cygnus DOT com

Here's a bit of (dangerous) fun.  It gives emacs the ability to
understand basic Cygwin-style pathnames (no, it doesn't deal with the
mount table).  It's best use is in shell buffers where you can get
completion without remembering to use dos syntax.

This is probably like running with scissors, but I've used it for, oh,
hours now without incident.  You should probably just move on to the
next message and pretend you didn't see this :)

-----------------------------------------------------------------------------
;;; Support slash-only paths in DOSish environment.  For example:
;;;
;;;    /d/gorf    => d:/gorf
;;;    /usr/local => c:/usr/local
;;;
;;; Shouldn't interfere with ange-ftp except for hostname completion.
;;; Mucks with low level file handling -- if disaster strikes after
;;; loading this file, run:
;;;
;;;    (setq file-name-handler-alist dosfile-handler-alist-backup)
;;;
;;; Author is not responsible for any damage caused by this code,
;;; although it performed admirably thru several minutes of testing.
;;;	Walt Buehring <buehring AT i2 DOT com>

(or (eq system-type 'windows-nt)
    (error "Only load 'dosfile' when running on NT"))

(defvar dosfile-root-drive-letter "c"
  "String with single character for drive which should be considered 'root'.")

(defvar dosfile-handler-alist-backup (copy-alist file-name-handler-alist))

(or (rassq 'dosfile-hook file-name-handler-alist)
    (setq file-name-handler-alist
	  (append '(("^/[A-Za-z]/" 		  . dosfile-hook)
		    ("^/[^/][^/:@]+\\(/\\|\\'\\)" . dosfile-hook))
		  file-name-handler-alist)))

(defun dosfile-convert-name (name)
  (if (not (stringp name))
      name
    (let ((rootp (not (string-match "^/[A-Za-z]/" name))))
      (if rootp
	  (concat dosfile-root-drive-letter ":" name)
	(setq name (substring name 1))
	(aset name 1 ?:)
	name))))

(defun dosfile-hook (operation &rest args)
  (let ((inhibit-file-name-handlers (cons 'dosfile-hook
					  (and (eq inhibit-file-name-operation operation)
					       inhibit-file-name-handlers)))
	(inhibit-file-name-operation operation))
    (cond ((memq operation '(verify-visited-file-modtime))
	   ;; nothing needed
	   (apply operation args))
	  ((memq operation '(expand-file-name copy-file rename-file
					      file-name-all-completions file-name-completion))
	   ;; filenames in first and second args
	   (apply operation
		  (dosfile-convert-name (nth 0 args))
		  (dosfile-convert-name (nth 1 args))
		  (cdr (cdr args))))
	  ((memq operation '(read-file-name-internal))
	   ;; filename in second arg
	   (apply operation
		  (nth 0 args)
		  (dosfile-convert-name (nth 1 args))
		  (cdr (cdr args))))
	  ((memq operation '(write-region))
	   ;; filename in third arg
	   (apply operation
		  (nth 0 args)
		  (nth 1 args)
		  (dosfile-convert-name (nth 2 args))
		  (cdr (cdr (cdr args)))))
	  (t
	   ;; all others have file in first arg
	   (apply operation
		  (dosfile-convert-name (nth 0 args))
		  (cdr args))))))

;;;-----------------------------------------------------------------------------
;;; list snarfed from ange-ftp to identify location of 
;;; filename arg(s) in all file handlers

;;;filename as second arg
;;; (read-file-name-internal string dir action)

;;;filename as third arg
;;; (write-region start end filename)

;;;filenames as first and second args
;;; (expand-file-name fname def-dir)
;;; (copy-file old new)
;;; (rename-file old new)
;;; (file-name-all-completions file dir)
;;; (file-name-completion file dir)

;; calls handler, but no filename arg
;; (verify-visited-file-modtime buffer)

;;;filename as first arg
;;; (file-name-directory)
;;; (file-name-nondirectory)
;;; (file-name-as-directory)
;;; (directory-file-name)
;;; (make-directory)
;;; (delete-directory)
;;; (insert-file-contents)
;;; (directory-files)
;;; (file-directory-p)
;;; (file-writable-p)
;;; (file-readable-p)
;;; (file-executable-p)
;;; (file-symlink-p)
;;; (delete-file)
;;; (file-exists-p)
;;; (backup-buffer)
;;; (file-attributes)
;;; (insert-directory)
;;; (file-local-copy)
;;; (unhandled-file-name-directory)
;;; (file-name-sans-versions)
;;; (dired-uncache)
;;; (dired-compress-file)
;;; (load)
;;; (find-backup-file-name)

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request AT cygnus DOT com" with one line of text: "help".

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019