]> git.eshelyaron.com Git - emacs.git/commitdiff
Add file-local-name
authorMichael Albinus <michael.albinus@gmx.de>
Sun, 20 Nov 2016 15:29:47 +0000 (16:29 +0100)
committerMichael Albinus <michael.albinus@gmx.de>
Sun, 20 Nov 2016 15:29:47 +0000 (16:29 +0100)
* doc/lispref/files.texi (Magic File Names): Add `file-local-name'.
(Unique File Names): Use it.

* etc/NEWS: Mention `file-local-name'.

* lisp/files.el (file-local-name): New defun.
(file-expand-wildcards):
* lisp/eshell/em-tramp.el (eshell/su, eshell/sudo):
* lisp/eshell/esh-ext.el (eshell-remote-command):
* lisp/eshell/esh-proc.el (eshell-gather-process-output):
* lisp/org/ob-core.el (org-babel-local-file-name):
* lisp/progmodes/gud.el (gud-common-init, gud-format-command):
* lisp/progmodes/python.el (python-shell-send-file):
* lisp/shell.el (shell):
* lisp/vc/ediff-diff.el (ediff-same-file-contents):
* lisp/vc/vc-git.el (vc-git-checkin): Use it.

12 files changed:
doc/lispref/files.texi
etc/NEWS
lisp/eshell/em-tramp.el
lisp/eshell/esh-ext.el
lisp/eshell/esh-proc.el
lisp/files.el
lisp/org/ob-core.el
lisp/progmodes/gud.el
lisp/progmodes/python.el
lisp/shell.el
lisp/vc/ediff-diff.el
lisp/vc/vc-git.el

index e189da9fbe247ee6d168001ff102529c6724990c..d9e366be1babb024d0a1e3382064f77aee47ec1f 100644 (file)
@@ -2546,14 +2546,7 @@ that remote host.  If such a directory does not exist, or
 @end defun
 
 In order to extract the local part of the path name from a temporary
-file, the following code could be used:
-
-@example
-@group
-(let ((tmpfile (make-nearby-temp-file "foo")))
-  (or (file-remote-p tmpfile 'localname) tmpfile))
-@end group
-@end example
+file, @code{file-local-name} could be used.
 
 @node File Name Completion
 @subsection File Name Completion
@@ -3233,6 +3226,13 @@ non-magic directory to serve as its current directory, and this function
 is a good way to come up with one.
 @end defun
 
+@defun file-local-name filename
+This function returns the local part of file @var{filename}.  For a
+remote @var{filename}, it returns a file name which could be used
+directly as argument of a remote process.  If @var{filename} is local,
+this function returns the file name.
+@end defun
+
 @defopt remote-file-name-inhibit-cache
 The attributes of remote files can be cached for better performance.  If
 they are changed outside of Emacs's control, the cached values become
index 21cda7c6b0a4d8c3742b909bd02a43cc21cf6b44..619d56ba7b79bc1ed517ba99b6ec17d9e2b7166d 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -699,6 +699,10 @@ collection).
 ** The new functions 'make-nearby-temp-file' and 'temporary-file-directory'
 can be used for creation of temporary files of remote or mounted directories.
 
++++
+** The new function 'file-local-name' can be used to specify arguments
+of remote processes.
+
 +++
 ** The new error 'file-missing', a subcategory of 'file-error', is now
 signaled instead of 'file-error' if a file operation acts on a file
index 9105c482b38908b29196e5f976bd59d06b20adfd..3eff20d1a1bb31f71fbfd42ae380e23eed67575c 100644 (file)
@@ -72,8 +72,7 @@ Become another USER during a login session.")
            (let ((user "root")
                  (host (or (file-remote-p default-directory 'host)
                            "localhost"))
-                 (dir (or (file-remote-p default-directory 'localname)
-                          (expand-file-name default-directory)))
+                 (dir (file-local-name (expand-file-name default-directory)))
                  (prefix (file-remote-p default-directory)))
              (dolist (arg args)
                (if (string-equal arg "-") (setq login t) (setq user arg)))
@@ -111,8 +110,7 @@ Execute a COMMAND as the superuser or another USER.")
            (let ((user (or user "root"))
                  (host (or (file-remote-p default-directory 'host)
                            "localhost"))
-                 (dir (or (file-remote-p default-directory 'localname)
-                          (expand-file-name default-directory)))
+                 (dir (file-local-name (expand-file-name default-directory)))
                  (prefix (file-remote-p default-directory)))
              ;; `eshell-eval-using-options' reads options of COMMAND.
              (while (and (stringp (car orig-args))
index ca62d0cf8b02277f34b2a5db82dcb596d5775b8d..4d658cd718e8953e1183ff5c0246c924506abae8 100644 (file)
@@ -203,7 +203,7 @@ all the output from the remote command, and sends it all at once,
 causing the user to wonder if anything's really going on..."
   (let ((outbuf (generate-new-buffer " *eshell remote output*"))
        (errbuf (generate-new-buffer " *eshell remote error*"))
-       (command (or (file-remote-p command 'localname) command))
+       (command (file-local-name command))
        (exitcode 1))
     (unwind-protect
        (progn
index 8c6bad089c58d3fad7914e7579f048d4decb8d71..21680df765d15756626056dd30e572b6e504e9a5 100644 (file)
@@ -279,7 +279,7 @@ See `eshell-needs-pipe'."
            (let ((process-connection-type
                   (unless (eshell-needs-pipe-p command)
                     process-connection-type))
-                 (command (or (file-remote-p command 'localname) command)))
+                 (command (file-local-name command)))
              (apply 'start-file-process
                     (file-name-nondirectory command) nil
                     ;; `start-process' can't deal with relative filenames.
index c50e6aa4146af8618c2c4889ddc7fd410a6bae66..7c56f54a463101f7a5b0d2a3cdeb27a64965bdc0 100644 (file)
@@ -1128,6 +1128,12 @@ consecutive checks.  For example:
                   :format "Do not use file name cache older then %v seconds"
                   :value 10)))
 
+(defun file-local-name (file)
+  "Return the local name component of FILE.
+It returns a file name which can be used directly as argument of
+`process-file', `start-file-process', or `shell-command'."
+  (or (file-remote-p file 'localname) file))
+
 (defun file-local-copy (file)
   "Copy the file FILE into a temporary file on this machine.
 Returns the name of the local copy, or nil, if FILE is directly
@@ -6212,9 +6218,7 @@ default directory.  However, if FULL is non-nil, they are absolute."
           ;; This can be more than one dir
           ;; if DIRPART contains wildcards.
           (dirs (if (and dirpart
-                         (string-match "[[*?]"
-                                       (or (file-remote-p dirpart 'localname)
-                                           dirpart)))
+                         (string-match "[[*?]" (file-local-name dirpart)))
                     (mapcar 'file-name-as-directory
                             (file-expand-wildcards (directory-file-name dirpart)))
                   (list dirpart)))
index e3d778f73b4ef7fb0d280b2cd423b184486af3a3..c76d276369f4817fa843ce818e2563b4a48c46a9 100644 (file)
@@ -2680,9 +2680,12 @@ Fixes a bug in `tramp-handle-call-process-region'."
     (apply org-babel-call-process-region-original
            start end program delete buffer display args)))
 
-(defun org-babel-local-file-name (file)
-  "Return the local name component of FILE."
-  (or (file-remote-p file 'localname) file))
+(defalias 'org-babel-local-file-name
+  (if (fboundp 'file-local-name)
+      'file-local-name
+    (lambda (file)
+      "Return the local name component of FILE."
+      (or (file-remote-p file 'localname) file))))
 
 (defun org-babel-process-file-name (name &optional no-quote-p)
   "Prepare NAME to be used in an external process.
index 9052aa403583c01e6ce4a4e972d0a03950cbfd98..0bdafdbac6eaadd684d871f9acb132bbfb580f6d 100644 (file)
@@ -2621,12 +2621,8 @@ comint mode, which see."
     (let ((w args))
       (while (and w (not (eq (car w) t)))
        (setq w (cdr w)))
-      (if w
-         (setcar w
-                 (if (file-remote-p file)
-                     ;; Tramp has already been loaded if we are here.
-                     (setq file (file-remote-p file 'localname))
-                   file))))
+      ;; Tramp has already been loaded if we are here.
+      (if w (setcar w (setq file (file-local-name file)))))
     (apply 'make-comint (concat "gud" filepart) program nil
           (if massage-args (funcall massage-args file args) args))
     ;; Since comint clobbered the mode, we don't set it until now.
@@ -2854,8 +2850,7 @@ Obeying it means displaying in another window the specified file and line."
        (frame (or gud-last-frame gud-last-last-frame))
        (buffer-file-name-localized
          (and (buffer-file-name)
-              (or (file-remote-p (buffer-file-name) 'localname)
-                  (buffer-file-name))))
+              (file-local-name (buffer-file-name))))
        result)
     (while (and str
                (let ((case-fold-search nil))
index be96ac32a01a9dac2b0b8f5ad6bdb99122277d4e..af8b791a90ea5e366409b1f00144dcf4ef671658 100644 (file)
@@ -3150,13 +3150,10 @@ t when called interactively."
                      (insert-file-contents
                       (or temp-file-name file-name))
                      (python-info-encoding)))
-         (file-name (expand-file-name
-                     (or (file-remote-p file-name 'localname)
-                         file-name)))
+         (file-name (expand-file-name (file-local-name file-name)))
          (temp-file-name (when temp-file-name
                            (expand-file-name
-                            (or (file-remote-p temp-file-name 'localname)
-                                temp-file-name)))))
+                            (file-local-name temp-file-name)))))
     (python-shell-send-string
      (format
       (concat
index 34bd77282ab0c7ce1b731f57dd6068453e555ee6..d1b2e87574639af952156f34d4fc5d05a61c025d 100644 (file)
@@ -714,12 +714,11 @@ Otherwise, one argument `-i' is passed to the shell.
           (null (getenv "ESHELL")))
       (with-current-buffer buffer
        (set (make-local-variable 'explicit-shell-file-name)
-            (file-remote-p
-             (expand-file-name
+             (expand-file-name
+              (file-local-name
               (read-file-name
                "Remote shell path: " default-directory shell-file-name
-               t shell-file-name))
-             'localname))))
+               t shell-file-name))))))
 
   ;; The buffer's window must be correctly set when we call comint (so
   ;; that comint sets the COLUMNS env var properly).
index b1ac32d7019d7f196b2affc7717013325d9e1332..56bfebb579c0128cc35e29ee332118cda0589b75 100644 (file)
@@ -1347,10 +1347,8 @@ arguments to `skip-chars-forward'."
                 ;; located on the same remote host.
                 (apply 'process-file ediff-cmp-program nil nil nil
                        (append ediff-cmp-options
-                               (list (or (file-remote-p f1 'localname)
-                                         (expand-file-name f1))
-                                     (or (file-remote-p f2 'localname)
-                                         (expand-file-name f2)))))
+                               (list (expand-file-name (file-local-name f1))
+                                     (expand-file-name (file-local-name f2)))))
                 ))
            (and (numberp res) (eq res 0)))
 
index 9df581dda5bb83c3f4d39b3f85af3b0584d84233..ec0e081743d9ba05b97d863b2b4d490425205729 100644 (file)
@@ -704,13 +704,10 @@ It is based on `log-edit-mode', and has Git-specific extensions.")
           ;; file, to work around the limitation that command-line
           ;; arguments must be in the system codepage, and therefore
           ;; might not support the non-ASCII characters in the log
-          ;; message.
+          ;; message.  Handle also remote files.
           (if (eq system-type 'windows-nt)
-              (if (file-remote-p file1)
-                  (let ((default-directory (file-name-directory file1)))
-                    (file-remote-p
-                     (make-nearby-temp-file "git-msg") 'localname))
-                (make-temp-file "git-msg")))))
+              (let ((default-directory (file-name-directory file1)))
+                (file-local-name (make-nearby-temp-file "git-msg"))))))
     (cl-flet ((boolean-arg-fn
                (argument)
                (lambda (value) (when (equal value "yes") (list argument)))))