* 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.
@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
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
** 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
(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)))
(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))
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
(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.
: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
;; 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)))
(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.
(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.
(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))
(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
(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).
;; 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)))
;; 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)))))