aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2016-11-20 16:29:47 +0100
committerMichael Albinus2016-11-20 16:29:47 +0100
commit22946702b4296c0e42e4baf6221e205b52d05cbf (patch)
treea81e506e5176351677c8f677e32cde6236d1b070
parent26c45889259682af0fbf05bccf7f084408860125 (diff)
downloademacs-22946702b4296c0e42e4baf6221e205b52d05cbf.tar.gz
emacs-22946702b4296c0e42e4baf6221e205b52d05cbf.zip
Add file-local-name
* 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.
-rw-r--r--doc/lispref/files.texi16
-rw-r--r--etc/NEWS4
-rw-r--r--lisp/eshell/em-tramp.el6
-rw-r--r--lisp/eshell/esh-ext.el2
-rw-r--r--lisp/eshell/esh-proc.el2
-rw-r--r--lisp/files.el10
-rw-r--r--lisp/org/ob-core.el9
-rw-r--r--lisp/progmodes/gud.el11
-rw-r--r--lisp/progmodes/python.el7
-rw-r--r--lisp/shell.el7
-rw-r--r--lisp/vc/ediff-diff.el6
-rw-r--r--lisp/vc/vc-git.el9
12 files changed, 42 insertions, 47 deletions
diff --git a/doc/lispref/files.texi b/doc/lispref/files.texi
index e189da9fbe2..d9e366be1ba 100644
--- a/doc/lispref/files.texi
+++ b/doc/lispref/files.texi
@@ -2546,14 +2546,7 @@ that remote host. If such a directory does not exist, or
2546@end defun 2546@end defun
2547 2547
2548In order to extract the local part of the path name from a temporary 2548In order to extract the local part of the path name from a temporary
2549file, the following code could be used: 2549file, @code{file-local-name} could be used.
2550
2551@example
2552@group
2553(let ((tmpfile (make-nearby-temp-file "foo")))
2554 (or (file-remote-p tmpfile 'localname) tmpfile))
2555@end group
2556@end example
2557 2550
2558@node File Name Completion 2551@node File Name Completion
2559@subsection File Name Completion 2552@subsection File Name Completion
@@ -3233,6 +3226,13 @@ non-magic directory to serve as its current directory, and this function
3233is a good way to come up with one. 3226is a good way to come up with one.
3234@end defun 3227@end defun
3235 3228
3229@defun file-local-name filename
3230This function returns the local part of file @var{filename}. For a
3231remote @var{filename}, it returns a file name which could be used
3232directly as argument of a remote process. If @var{filename} is local,
3233this function returns the file name.
3234@end defun
3235
3236@defopt remote-file-name-inhibit-cache 3236@defopt remote-file-name-inhibit-cache
3237The attributes of remote files can be cached for better performance. If 3237The attributes of remote files can be cached for better performance. If
3238they are changed outside of Emacs's control, the cached values become 3238they are changed outside of Emacs's control, the cached values become
diff --git a/etc/NEWS b/etc/NEWS
index 21cda7c6b0a..619d56ba7b7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -700,6 +700,10 @@ collection).
700can be used for creation of temporary files of remote or mounted directories. 700can be used for creation of temporary files of remote or mounted directories.
701 701
702+++ 702+++
703** The new function 'file-local-name' can be used to specify arguments
704of remote processes.
705
706+++
703** The new error 'file-missing', a subcategory of 'file-error', is now 707** The new error 'file-missing', a subcategory of 'file-error', is now
704signaled instead of 'file-error' if a file operation acts on a file 708signaled instead of 'file-error' if a file operation acts on a file
705that does not exist. 709that does not exist.
diff --git a/lisp/eshell/em-tramp.el b/lisp/eshell/em-tramp.el
index 9105c482b38..3eff20d1a1b 100644
--- a/lisp/eshell/em-tramp.el
+++ b/lisp/eshell/em-tramp.el
@@ -72,8 +72,7 @@ Become another USER during a login session.")
72 (let ((user "root") 72 (let ((user "root")
73 (host (or (file-remote-p default-directory 'host) 73 (host (or (file-remote-p default-directory 'host)
74 "localhost")) 74 "localhost"))
75 (dir (or (file-remote-p default-directory 'localname) 75 (dir (file-local-name (expand-file-name default-directory)))
76 (expand-file-name default-directory)))
77 (prefix (file-remote-p default-directory))) 76 (prefix (file-remote-p default-directory)))
78 (dolist (arg args) 77 (dolist (arg args)
79 (if (string-equal arg "-") (setq login t) (setq user arg))) 78 (if (string-equal arg "-") (setq login t) (setq user arg)))
@@ -111,8 +110,7 @@ Execute a COMMAND as the superuser or another USER.")
111 (let ((user (or user "root")) 110 (let ((user (or user "root"))
112 (host (or (file-remote-p default-directory 'host) 111 (host (or (file-remote-p default-directory 'host)
113 "localhost")) 112 "localhost"))
114 (dir (or (file-remote-p default-directory 'localname) 113 (dir (file-local-name (expand-file-name default-directory)))
115 (expand-file-name default-directory)))
116 (prefix (file-remote-p default-directory))) 114 (prefix (file-remote-p default-directory)))
117 ;; `eshell-eval-using-options' reads options of COMMAND. 115 ;; `eshell-eval-using-options' reads options of COMMAND.
118 (while (and (stringp (car orig-args)) 116 (while (and (stringp (car orig-args))
diff --git a/lisp/eshell/esh-ext.el b/lisp/eshell/esh-ext.el
index ca62d0cf8b0..4d658cd718e 100644
--- a/lisp/eshell/esh-ext.el
+++ b/lisp/eshell/esh-ext.el
@@ -203,7 +203,7 @@ all the output from the remote command, and sends it all at once,
203causing the user to wonder if anything's really going on..." 203causing the user to wonder if anything's really going on..."
204 (let ((outbuf (generate-new-buffer " *eshell remote output*")) 204 (let ((outbuf (generate-new-buffer " *eshell remote output*"))
205 (errbuf (generate-new-buffer " *eshell remote error*")) 205 (errbuf (generate-new-buffer " *eshell remote error*"))
206 (command (or (file-remote-p command 'localname) command)) 206 (command (file-local-name command))
207 (exitcode 1)) 207 (exitcode 1))
208 (unwind-protect 208 (unwind-protect
209 (progn 209 (progn
diff --git a/lisp/eshell/esh-proc.el b/lisp/eshell/esh-proc.el
index 8c6bad089c5..21680df765d 100644
--- a/lisp/eshell/esh-proc.el
+++ b/lisp/eshell/esh-proc.el
@@ -279,7 +279,7 @@ See `eshell-needs-pipe'."
279 (let ((process-connection-type 279 (let ((process-connection-type
280 (unless (eshell-needs-pipe-p command) 280 (unless (eshell-needs-pipe-p command)
281 process-connection-type)) 281 process-connection-type))
282 (command (or (file-remote-p command 'localname) command))) 282 (command (file-local-name command)))
283 (apply 'start-file-process 283 (apply 'start-file-process
284 (file-name-nondirectory command) nil 284 (file-name-nondirectory command) nil
285 ;; `start-process' can't deal with relative filenames. 285 ;; `start-process' can't deal with relative filenames.
diff --git a/lisp/files.el b/lisp/files.el
index c50e6aa4146..7c56f54a463 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -1128,6 +1128,12 @@ consecutive checks. For example:
1128 :format "Do not use file name cache older then %v seconds" 1128 :format "Do not use file name cache older then %v seconds"
1129 :value 10))) 1129 :value 10)))
1130 1130
1131(defun file-local-name (file)
1132 "Return the local name component of FILE.
1133It returns a file name which can be used directly as argument of
1134`process-file', `start-file-process', or `shell-command'."
1135 (or (file-remote-p file 'localname) file))
1136
1131(defun file-local-copy (file) 1137(defun file-local-copy (file)
1132 "Copy the file FILE into a temporary file on this machine. 1138 "Copy the file FILE into a temporary file on this machine.
1133Returns the name of the local copy, or nil, if FILE is directly 1139Returns 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."
6212 ;; This can be more than one dir 6218 ;; This can be more than one dir
6213 ;; if DIRPART contains wildcards. 6219 ;; if DIRPART contains wildcards.
6214 (dirs (if (and dirpart 6220 (dirs (if (and dirpart
6215 (string-match "[[*?]" 6221 (string-match "[[*?]" (file-local-name dirpart)))
6216 (or (file-remote-p dirpart 'localname)
6217 dirpart)))
6218 (mapcar 'file-name-as-directory 6222 (mapcar 'file-name-as-directory
6219 (file-expand-wildcards (directory-file-name dirpart))) 6223 (file-expand-wildcards (directory-file-name dirpart)))
6220 (list dirpart))) 6224 (list dirpart)))
diff --git a/lisp/org/ob-core.el b/lisp/org/ob-core.el
index e3d778f73b4..c76d276369f 100644
--- a/lisp/org/ob-core.el
+++ b/lisp/org/ob-core.el
@@ -2680,9 +2680,12 @@ Fixes a bug in `tramp-handle-call-process-region'."
2680 (apply org-babel-call-process-region-original 2680 (apply org-babel-call-process-region-original
2681 start end program delete buffer display args))) 2681 start end program delete buffer display args)))
2682 2682
2683(defun org-babel-local-file-name (file) 2683(defalias 'org-babel-local-file-name
2684 "Return the local name component of FILE." 2684 (if (fboundp 'file-local-name)
2685 (or (file-remote-p file 'localname) file)) 2685 'file-local-name
2686 (lambda (file)
2687 "Return the local name component of FILE."
2688 (or (file-remote-p file 'localname) file))))
2686 2689
2687(defun org-babel-process-file-name (name &optional no-quote-p) 2690(defun org-babel-process-file-name (name &optional no-quote-p)
2688 "Prepare NAME to be used in an external process. 2691 "Prepare NAME to be used in an external process.
diff --git a/lisp/progmodes/gud.el b/lisp/progmodes/gud.el
index 9052aa40358..0bdafdbac6e 100644
--- a/lisp/progmodes/gud.el
+++ b/lisp/progmodes/gud.el
@@ -2621,12 +2621,8 @@ comint mode, which see."
2621 (let ((w args)) 2621 (let ((w args))
2622 (while (and w (not (eq (car w) t))) 2622 (while (and w (not (eq (car w) t)))
2623 (setq w (cdr w))) 2623 (setq w (cdr w)))
2624 (if w 2624 ;; Tramp has already been loaded if we are here.
2625 (setcar w 2625 (if w (setcar w (setq file (file-local-name file)))))
2626 (if (file-remote-p file)
2627 ;; Tramp has already been loaded if we are here.
2628 (setq file (file-remote-p file 'localname))
2629 file))))
2630 (apply 'make-comint (concat "gud" filepart) program nil 2626 (apply 'make-comint (concat "gud" filepart) program nil
2631 (if massage-args (funcall massage-args file args) args)) 2627 (if massage-args (funcall massage-args file args) args))
2632 ;; Since comint clobbered the mode, we don't set it until now. 2628 ;; 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."
2854 (frame (or gud-last-frame gud-last-last-frame)) 2850 (frame (or gud-last-frame gud-last-last-frame))
2855 (buffer-file-name-localized 2851 (buffer-file-name-localized
2856 (and (buffer-file-name) 2852 (and (buffer-file-name)
2857 (or (file-remote-p (buffer-file-name) 'localname) 2853 (file-local-name (buffer-file-name))))
2858 (buffer-file-name))))
2859 result) 2854 result)
2860 (while (and str 2855 (while (and str
2861 (let ((case-fold-search nil)) 2856 (let ((case-fold-search nil))
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index be96ac32a01..af8b791a90e 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -3150,13 +3150,10 @@ t when called interactively."
3150 (insert-file-contents 3150 (insert-file-contents
3151 (or temp-file-name file-name)) 3151 (or temp-file-name file-name))
3152 (python-info-encoding))) 3152 (python-info-encoding)))
3153 (file-name (expand-file-name 3153 (file-name (expand-file-name (file-local-name file-name)))
3154 (or (file-remote-p file-name 'localname)
3155 file-name)))
3156 (temp-file-name (when temp-file-name 3154 (temp-file-name (when temp-file-name
3157 (expand-file-name 3155 (expand-file-name
3158 (or (file-remote-p temp-file-name 'localname) 3156 (file-local-name temp-file-name)))))
3159 temp-file-name)))))
3160 (python-shell-send-string 3157 (python-shell-send-string
3161 (format 3158 (format
3162 (concat 3159 (concat
diff --git a/lisp/shell.el b/lisp/shell.el
index 34bd77282ab..d1b2e875746 100644
--- a/lisp/shell.el
+++ b/lisp/shell.el
@@ -714,12 +714,11 @@ Otherwise, one argument `-i' is passed to the shell.
714 (null (getenv "ESHELL"))) 714 (null (getenv "ESHELL")))
715 (with-current-buffer buffer 715 (with-current-buffer buffer
716 (set (make-local-variable 'explicit-shell-file-name) 716 (set (make-local-variable 'explicit-shell-file-name)
717 (file-remote-p 717 (expand-file-name
718 (expand-file-name 718 (file-local-name
719 (read-file-name 719 (read-file-name
720 "Remote shell path: " default-directory shell-file-name 720 "Remote shell path: " default-directory shell-file-name
721 t shell-file-name)) 721 t shell-file-name))))))
722 'localname))))
723 722
724 ;; The buffer's window must be correctly set when we call comint (so 723 ;; The buffer's window must be correctly set when we call comint (so
725 ;; that comint sets the COLUMNS env var properly). 724 ;; that comint sets the COLUMNS env var properly).
diff --git a/lisp/vc/ediff-diff.el b/lisp/vc/ediff-diff.el
index b1ac32d7019..56bfebb579c 100644
--- a/lisp/vc/ediff-diff.el
+++ b/lisp/vc/ediff-diff.el
@@ -1347,10 +1347,8 @@ arguments to `skip-chars-forward'."
1347 ;; located on the same remote host. 1347 ;; located on the same remote host.
1348 (apply 'process-file ediff-cmp-program nil nil nil 1348 (apply 'process-file ediff-cmp-program nil nil nil
1349 (append ediff-cmp-options 1349 (append ediff-cmp-options
1350 (list (or (file-remote-p f1 'localname) 1350 (list (expand-file-name (file-local-name f1))
1351 (expand-file-name f1)) 1351 (expand-file-name (file-local-name f2)))))
1352 (or (file-remote-p f2 'localname)
1353 (expand-file-name f2)))))
1354 )) 1352 ))
1355 (and (numberp res) (eq res 0))) 1353 (and (numberp res) (eq res 0)))
1356 1354
diff --git a/lisp/vc/vc-git.el b/lisp/vc/vc-git.el
index 9df581dda5b..ec0e081743d 100644
--- a/lisp/vc/vc-git.el
+++ b/lisp/vc/vc-git.el
@@ -704,13 +704,10 @@ It is based on `log-edit-mode', and has Git-specific extensions.")
704 ;; file, to work around the limitation that command-line 704 ;; file, to work around the limitation that command-line
705 ;; arguments must be in the system codepage, and therefore 705 ;; arguments must be in the system codepage, and therefore
706 ;; might not support the non-ASCII characters in the log 706 ;; might not support the non-ASCII characters in the log
707 ;; message. 707 ;; message. Handle also remote files.
708 (if (eq system-type 'windows-nt) 708 (if (eq system-type 'windows-nt)
709 (if (file-remote-p file1) 709 (let ((default-directory (file-name-directory file1)))
710 (let ((default-directory (file-name-directory file1))) 710 (file-local-name (make-nearby-temp-file "git-msg"))))))
711 (file-remote-p
712 (make-nearby-temp-file "git-msg") 'localname))
713 (make-temp-file "git-msg")))))
714 (cl-flet ((boolean-arg-fn 711 (cl-flet ((boolean-arg-fn
715 (argument) 712 (argument)
716 (lambda (value) (when (equal value "yes") (list argument))))) 713 (lambda (value) (when (equal value "yes") (list argument)))))