emacs-devel
[Top][All Lists]
Advanced

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

Patch for remote files in dnd.el


From: Jason Rumney
Subject: Patch for remote files in dnd.el
Date: Thu, 27 Jul 2006 23:22:28 +0100

The following patch to dnd.el adds support for remote files via a new
variable dnd-open-remote-file-function.

On Windows, this defaults to the new function dnd-open-unc-file, on
other platforms it is nil, giving the old behavior. If other platforms
can receive remote files by drag and drop, then appropriate methods
for accessing them can be added (perhaps via tramp).


Any objections to installing this now?


*** dnd.el      05 Jun 2006 22:10:29 +0100      1.9
--- dnd.el      27 Jul 2006 23:14:05 +0100      
***************
*** 59,64 ****
--- 59,78 ----
    :group 'dnd)
  
  
+ (defcustom dnd-open-remote-file-function
+   (if (eq system-type 'windows-nt)
+       'dnd-open-unc-file
+     nil)
+   "The function to call when opening a file on a remote machine.
+ The function will be called with two arguments; URI and ACTION. See
+ `dnd-open-file' for details.
+ If nil, then dragging remote files into Emacs will result in an error.
+ Predefined functions are `dnd-open-unc-file', which attempts to open
+ the file using its UNC name and is the default on MS-Windows."
+   :version "22.1"
+   :type 'function
+   :group 'dnd)
+ 
  
  (defcustom dnd-open-file-other-window nil
    "If non-nil, always use find-file-other-window to open dropped files."
***************
*** 158,163 ****
--- 172,195 ----
          'private)
        (error "Can not read %s" uri))))
  
+ 
+ (defun dnd-open-unc-file (uri action)
+   "Open a remote file using its unc path.
+ The file is opened in the current window, or a new window if
+ `dnd-open-file-other-window' is set. URI is the url for the file,
+ and must have the format file://hostname/file-name. ACTION is ignored.
+ //hostname/file-name is the unc path."
+   (let ((unc-file (if (string-match "^file:" uri)
+                     (substring uri 5))))
+     (if (and unc-file (file-readable-p unc-file))
+       (progn
+         (if dnd-open-file-other-window
+             (find-file-other-window unc-file)
+           (find-file unc-file))
+         'private)
+       (error "Invalid file url"))))
+ 
+ 
  (defun dnd-open-file (uri action)
    "Open a local or remote file.
  The file is opened in the current window, or a new window if
***************
*** 169,175 ****
    ;; file.  Otherwise return nil.
    (let ((local-file (dnd-get-local-file-uri uri)))
      (if local-file (dnd-open-local-file local-file action)
!       (error "Remote files not supported"))))
  
  
  (defun dnd-insert-text (window action text)
--- 201,209 ----
    ;; file.  Otherwise return nil.
    (let ((local-file (dnd-get-local-file-uri uri)))
      (if local-file (dnd-open-local-file local-file action)
!       (if dnd-open-remote-file-function
!         (funcall dnd-open-remote-file-function uri action)
!       (error "Remote files not supported")))))
  
  
  (defun dnd-insert-text (window action text)




reply via email to

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