sequence `(,command "monitor" ,localname)))
;; "gvfs-monitor-dir".
((setq command (tramp-get-remote-gvfs-monitor-dir v))
- (setq filter 'tramp-sh-gvfs-monitor-dir-process-filter
+ (setq filter #'tramp-sh-gvfs-monitor-dir-process-filter
events
(cond
((and (memq 'change flags) (memq 'attribute-change flags))
(list tramp-encoding-shell))))))
;; Set sentinel and query flag. Initialize variables.
- (set-process-sentinel p 'tramp-process-sentinel)
+ (set-process-sentinel p #'tramp-process-sentinel)
(process-put p 'vector vec)
(process-put p 'adjust-window-size-function #'ignore)
(set-process-query-on-exit-flag p nil)
(command &optional output-buffer error-buffer)
"Like `shell-command' for Tramp files."
(let* ((asynchronous (string-match-p "[ \t]*&[ \t]*\\'" command))
- ;; We cannot use `shell-file-name' and `shell-command-switch',
- ;; they are variables of the local host.
- (args (append
- (cons
- (tramp-get-method-parameter
- (tramp-dissect-file-name default-directory)
- 'tramp-remote-shell)
- (tramp-get-method-parameter
- (tramp-dissect-file-name default-directory)
- 'tramp-remote-shell-args))
- (list (substring command 0 asynchronous))))
+ (command (substring command 0 asynchronous))
current-buffer-p
(output-buffer
(cond
(cond
((bufferp error-buffer) error-buffer)
((stringp error-buffer) (get-buffer-create error-buffer))))
- (buffer
- (if (and (not asynchronous) error-buffer)
- (with-parsed-tramp-file-name default-directory nil
- (list output-buffer (tramp-make-tramp-temp-file v)))
- output-buffer))
- (p (get-buffer-process output-buffer)))
-
- ;; Check whether there is another process running. Tramp does not
- ;; support 2 (asynchronous) processes in parallel.
+ (bname (buffer-name output-buffer))
+ (p (get-buffer-process output-buffer))
+ buffer)
+
+ ;; The following code is taken from `shell-command', slightly
+ ;; adapted. Shouldn't it be factored out?
(when p
- (if (yes-or-no-p "A command is running. Kill it? ")
- (ignore-errors (kill-process p))
- (tramp-user-error p "Shell command in progress")))
+ (cond
+ ((eq async-shell-command-buffer 'confirm-kill-process)
+ ;; If will kill a process, query first.
+ (if (yes-or-no-p
+ "A command is running in the default buffer. Kill it? ")
+ (kill-process p)
+ (tramp-user-error p "Shell command in progress")))
+ ((eq async-shell-command-buffer 'confirm-new-buffer)
+ ;; If will create a new buffer, query first.
+ (if (yes-or-no-p
+ "A command is running in the default buffer. Use a new buffer? ")
+ (setq output-buffer (generate-new-buffer bname))
+ (tramp-user-error p "Shell command in progress")))
+ ((eq async-shell-command-buffer 'new-buffer)
+ ;; It will create a new buffer.
+ (setq output-buffer (generate-new-buffer bname)))
+ ((eq async-shell-command-buffer 'confirm-rename-buffer)
+ ;; If will rename the buffer, query first.
+ (if (yes-or-no-p
+ "A command is running in the default buffer. Rename it? ")
+ (progn
+ (with-current-buffer output-buffer
+ (rename-uniquely))
+ (setq output-buffer (get-buffer-create bname)))
+ (tramp-user-error p "Shell command in progress")))
+ ((eq async-shell-command-buffer 'rename-buffer)
+ ;; It will rename the buffer.
+ (with-current-buffer output-buffer
+ (rename-uniquely))
+ (setq output-buffer (get-buffer-create bname)))))
+
+ (setq buffer (if (and (not asynchronous) error-buffer)
+ (with-parsed-tramp-file-name default-directory nil
+ (list output-buffer (tramp-make-tramp-temp-file v)))
+ output-buffer))
(if current-buffer-p
(progn
(if (and (not current-buffer-p) (integerp asynchronous))
(prog1
;; Run the process.
- (setq p (apply #'start-file-process "*Async Shell*" buffer args))
+ (setq p (start-file-process-shell-command
+ "*Async Shell*" buffer command))
;; Display output.
(with-current-buffer output-buffer
(display-buffer output-buffer '(nil (allow-no-window . t)))
(setq mode-line-process '(":%s"))
(shell-mode)
(set-process-sentinel p #'shell-command-sentinel)
- (set-process-filter p 'comint-output-filter)))
+ (set-process-filter p #'comint-output-filter)))
(prog1
;; Run the process.
- (apply #'process-file (car args) nil buffer nil (cdr args))
+ (process-file-shell-command command nil buffer nil)
;; Insert error messages if they were separated.
(when (listp buffer)
(with-current-buffer error-buffer
Similar to `call-process-shell-command', but calls `process-file'."
(declare (advertised-calling-convention
(command &optional infile buffer display) "24.5"))
- (process-file
- (if (file-remote-p default-directory) "/bin/sh" shell-file-name)
- infile buffer display
- (if (file-remote-p default-directory) "-c" shell-command-switch)
- (mapconcat 'identity (cons command args) " ")))
+ ;; On remote hosts, the local `shell-file-name' might be useless.
+ (with-connection-local-variables
+ (process-file
+ shell-file-name infile buffer display shell-command-switch
+ (mapconcat 'identity (cons command args) " "))))
(defun call-shell-region (start end command &optional delete buffer)
"Send text from START to END as input to an inferior shell running COMMAND.
"Check `shell-command'."
:tags '(:expensive-test)
(skip-unless (tramp--test-enabled))
- (skip-unless (tramp--test-sh-p))
+ ;; Prior Emacs 27, `shell-file-name' was hard coded as "/bin/sh" for
+ ;; remote processes in Emacs. That doesn't work for tramp-adb.el.
+ (skip-unless (or (and (tramp--test-adb-p) (tramp--test-emacs27-p))
+ (tramp--test-sh-p)))
(dolist (quoted (if (tramp--test-expensive-test) '(nil t) '(nil)))
(let ((tmp-name (tramp--test-make-temp-name nil quoted))
;; Cleanup.
(ignore-errors (delete-file tmp-name)))
+ ;; tramp-adb.el is not fit yet for asynchronous processes.
+ (unless (tramp--test-adb-p)
(unwind-protect
(with-temp-buffer
(write-region "foo" nil tmp-name)
(buffer-string))))
;; Cleanup.
- (ignore-errors (delete-file tmp-name)))
+ (ignore-errors (delete-file tmp-name))))
+ ;; tramp-adb.el is not fit yet for asynchronous processes.
+ (unless (tramp--test-adb-p)
(unwind-protect
(with-temp-buffer
(write-region "foo" nil tmp-name)
(buffer-string))))
;; Cleanup.
- (ignore-errors (delete-file tmp-name))))))
+ (ignore-errors (delete-file tmp-name)))))))
(defun tramp--test-shell-command-to-string-asynchronously (command)
"Like `shell-command-to-string', but for asynchronous processes."
;; do not work properly for `nextcloud'.
;; * Fix `tramp-test29-start-file-process' and
;; `tramp-test30-make-process' on MS Windows (`process-send-eof'?).
+;; * Fix `tramp-test29-start-file-process',
+;; `tramp-test30-make-process' and `tramp-test32-shell-command' for
+;; `adb' (see comment in `tramp-adb-send-command').
;; * Fix Bug#16928 in `tramp-test43-asynchronous-requests'.
(provide 'tramp-tests)