(tramp-error vec 'file-error "Cannot switch to user `%s'" user))
(unless (process-live-p p)
+ ;; During completion, don't reopen a new connection. We check
+ ;; this for the process related to `tramp-buffer-name';
+ ;; otherwise `start-file-process' wouldn't run ever when
+ ;; `non-essential' is non-nil.
+ (when (and (tramp-completion-mode-p)
+ (null (get-process (tramp-buffer-name vec))))
+ (throw 'non-essential 'non-essential))
+
(save-match-data
(when (and p (processp p)) (delete-process p))
(if (zerop (length device))
;;; Code:
(eval-when-compile (require 'cl-lib))
-(require 'tramp-gvfs)
+;; Sometimes, compilation fails with "Variable binding depth exceeds
+;; max-specpdl-size".
+(eval-and-compile
+ (let ((max-specpdl-size (* 2 max-specpdl-size))) (require 'tramp-gvfs)))
(autoload 'dired-uncache "dired")
(autoload 'url-tramp-convert-url-to-tramp "url-tramp")
(when (tramp-get-connection-process vec)
;; We cannot use `with-connection-property', because we don't want
;; to cache a nil result.
- (or (tramp-get-connection-property
- (tramp-get-connection-process vec) "mounted" nil)
+ (unless (tramp-get-connection-property
+ (tramp-get-connection-process vec) "mounted" nil)
+ (let* ((default-directory temporary-file-directory)
+ (mount (shell-command-to-string "mount -t fuse.rclone")))
+ (tramp-message vec 6 "%s" "mount -t fuse.rclone")
+ (tramp-message vec 6 "\n%s" mount)
(tramp-set-connection-property
(tramp-get-connection-process vec) "mounted"
- (let* ((default-directory temporary-file-directory)
- (mount (shell-command-to-string "mount -t fuse.rclone")))
- (tramp-message vec 6 "%s" "mount -t fuse.rclone")
- (tramp-message vec 6 "\n%s" mount)
- (when (string-match
- (format
- "^\\(%s:\\S-*\\)" (regexp-quote (tramp-file-name-host vec)))
- mount)
- (match-string 1 mount)))))))
+ (when (string-match
+ (format
+ "^\\(%s:\\S-*\\)" (regexp-quote (tramp-file-name-host vec)))
+ mount)
+ (match-string 1 mount)))))))
(defun tramp-rclone-flush-directory-cache (vec)
"Flush directory cache of VEC mount."
(if (zerop (length host))
(tramp-error vec 'file-error "Storage %s not connected" host))
+ ;; During completion, don't reopen a new connection. We check
+ ;; this for the process related to `tramp-buffer-name';
+ ;; otherwise `start-file-process' wouldn't run ever when
+ ;; `non-essential' is non-nil.
+ (when (and (tramp-completion-mode-p)
+ (null (get-process (tramp-buffer-name vec))))
+ (throw 'non-essential 'non-essential))
+
;; We need a process bound to the connection buffer. Therefore,
;; we create a dummy process. Maybe there is a better solution?
(unless (get-buffer-process (tramp-get-connection-buffer vec))
(setq newname
(expand-file-name
(file-name-nondirectory dirname) newname)))
- (when (not (file-directory-p (file-name-directory newname)))
+ (unless (file-directory-p (file-name-directory newname))
(make-directory (file-name-directory newname) parents))
(tramp-do-copy-or-rename-file-out-of-band
'copy dirname newname keep-date))
;; actually check the output it gives. And also, when
;; redirecting "mimencode" output to /dev/null, then as root
;; it might change the permissions of /dev/null!
- (when (not (stringp rem-enc))
+ (unless (stringp rem-enc)
(let ((name (symbol-name rem-enc)))
(while (string-match "-" name)
(setq name (replace-match "_" nil t name)))
vec (format "%s </dev/null" rem-enc) t)
(throw 'wont-work-remote nil))
- (when (not (stringp rem-dec))
+ (unless (stringp rem-dec)
(let ((name (symbol-name rem-dec))
(value (symbol-value rem-dec))
tmpfile)
(when (string-match-p "F" switches)
(mapc
(lambda (x)
- (when (not (zerop (length (car x))))
+ (unless (zerop (length (car x)))
(cond
((char-equal ?d (string-to-char (nth 1 x)))
(setcar x (concat (car x) "/")))
;; Print entries.
(mapc
(lambda (x)
- (when (not (zerop (length (nth 0 x))))
+ (unless (zerop (length (nth 0 x)))
(let ((attr
(when (tramp-smb-get-stat-capability v)
(ignore-errors
"Check, whether a sudo process has finished.
Remove unneeded output."
;; There might be pending output for the exit status.
- (when (not (process-live-p proc))
+ (unless (process-live-p proc)
(while (tramp-accept-process-output proc 0))
;; Delete narrowed region, it would be in the way reading a Lisp form.
(goto-char (point-min))
;; We need a process bound to the connection buffer. Therefore, we
;; create a dummy process. Maybe there is a better solution?
(unless (tramp-get-connection-process vec)
+
+ ;; During completion, don't reopen a new connection. We check
+ ;; this for the process related to `tramp-buffer-name'; otherwise
+ ;; `start-file-process' wouldn't run ever when `non-essential' is
+ ;; non-nil.
+ (when (and (tramp-completion-mode-p)
+ (null (get-process (tramp-buffer-name vec))))
+ (throw 'non-essential 'non-essential))
+
(let ((p (make-network-process
:name (tramp-buffer-name vec)
:buffer (tramp-get-connection-buffer vec)
(tramp-error
v 'file-error
"File `%s' does not include a `.el' or `.elc' suffix" file)))
- (unless noerror
- (when (not (file-exists-p file))
- (tramp-error
- v tramp-file-missing "Cannot load nonexistent file `%s'" file)))
+ (unless (or noerror (file-exists-p file))
+ (tramp-error
+ v tramp-file-missing "Cannot load nonexistent file `%s'" file))
(if (not (file-exists-p file))
nil
(let ((tramp-message-show-message (not nomessage)))
(with-current-buffer (tramp-get-connection-buffer vec)
(tramp-message vec 6 "\n%s" (buffer-string)))
(tramp-message vec 3 "Sending login name `%s'" user)
- (tramp-send-string vec (concat user tramp-local-end-of-line))))
+ (tramp-send-string vec (concat user tramp-local-end-of-line)))
+ t)
(defun tramp-action-password (proc vec)
"Query the user for a password."
(process-send-string
proc (concat (tramp-read-passwd proc) tramp-local-end-of-line))
;; Hide password prompt.
- (narrow-to-region (point-max) (point-max)))))
+ (narrow-to-region (point-max) (point-max))))
+ t)
(defun tramp-action-succeed (_proc _vec)
"Signal success in finding shell prompt."
(throw 'tramp-action 'permission-denied))
(with-current-buffer (tramp-get-connection-buffer vec)
(tramp-message vec 6 "\n%s" (buffer-string)))
- (tramp-send-string vec (concat "yes" tramp-local-end-of-line)))))
+ (tramp-send-string vec (concat "yes" tramp-local-end-of-line))))
+ t)
(defun tramp-action-yn (proc vec)
"Ask the user for confirmation using `y-or-n-p'.
(throw 'tramp-action 'permission-denied))
(with-current-buffer (tramp-get-connection-buffer vec)
(tramp-message vec 6 "\n%s" (buffer-string)))
- (tramp-send-string vec (concat "y" tramp-local-end-of-line)))))
+ (tramp-send-string vec (concat "y" tramp-local-end-of-line))))
+ t)
(defun tramp-action-terminal (_proc vec)
"Tell the remote host which terminal type to use.
(tramp-message vec 5 "Setting `%s' as terminal type." tramp-terminal-type)
(with-current-buffer (tramp-get-connection-buffer vec)
(tramp-message vec 6 "\n%s" (buffer-string)))
- (tramp-send-string vec (concat tramp-terminal-type tramp-local-end-of-line)))
+ (tramp-send-string vec (concat tramp-terminal-type tramp-local-end-of-line))
+ t)
(defun tramp-action-process-alive (proc _vec)
"Check, whether a process has finished."
;;; Functions for processing the actions:
(defun tramp-process-one-action (proc vec actions)
- "Wait for output from the shell and perform one action."
+ "Wait for output from the shell and perform one action.
+See `tramp-process-actions' for the format of ACTIONS."
(let ((case-fold-search t)
found todo item pattern action)
(while (not found)
"Perform ACTIONS until success or TIMEOUT.
PROC and VEC indicate the remote connection to be used. POS, if
set, is the starting point of the region to be deleted in the
-connection buffer."
+connection buffer.
+
+ACTIONS is a list of (PATTERN ACTION). The PATTERN should be a
+symbol, a variable. The value of this variable gives the regular
+expression to search for. Note that the regexp must match at the
+end of the buffer, \"\\'\" is implicitly appended to it.
+
+The ACTION should also be a symbol, but a function. When the
+corresponding PATTERN matches, the ACTION function is called.
+
+An ACTION function has two arguments (PROC VEC). If it returns
+nil, nothing has been done, and the next action shall be called.
+A non-nil return value indicates that the process output has been
+consumed, and new output shall be retrieved, before starting to
+process all ACTIONs, again. The same happens after calling the
+last ACTION.
+
+If an action determines, that all processing has been done (e.g.,
+because the shell prompt has been detected), it shall throw a
+result. The symbol `ok' means that all ACTIONs have been
+performed successfully. Any other value means an error."
;; Enable `auth-source', unless "emacs -Q" has been called. We must
;; use the "password-vector" property in case we have several hops.
(tramp-set-connection-property
nil proc 'file-error "Process has died"))
(setq found (tramp-check-for-regexp proc regexp)))))
(tramp-message proc 6 "\n%s" (buffer-string))
- (when (not found)
+ (unless found
(if timeout
(tramp-error
proc 'file-error "[[Regexp `%s' not found in %d secs]]"