magit / with-editor

Use the Emacsclient as the $EDITOR of child processes
http://magit.vc/manual/with-editor
GNU General Public License v3.0
188 stars 44 forks source link

shell-command-with-editor-mode: path is treated as local for remote files #129

Closed iostapyshyn closed 2 months ago

iostapyshyn commented 1 year ago

The with-editor-async-shell-command and with-editor-shell-command commands seem to work great with Tramp for remote buffers. However, enabling shell-command-with-editor-mode and running (async-)shell-command does not work this well: the running Emacs instance still tries to opens the file printed by the sleeping editor, but on a local machine instead of remotely.

For example, with remote default-directory

tarsius commented 11 months ago

I don't use Tramp myself and only do one round of tramp-related bug fixes every half a year or so. Could you please try yourself to figure out why this doesn't work?

tarsius commented 10 months ago

Meanwhile, please try if this fixes the issue (and doesn't introduce other issues):

diff --git a/lisp/with-editor.el b/lisp/with-editor.el
index d1a5597775..0d9ee1b63b 100644
--- a/lisp/with-editor.el
+++ b/lisp/with-editor.el
@@ -886,28 +886,13 @@ (defun shell-command--shell-command-with-editor-mode
   ;; intended to be used in buffers in which an interactive shell is
   ;; running, so it has to be removed here.
   (let ((shell-mode-hook (remove 'with-editor-export-editor shell-mode-hook)))
-    (cond ((or (not (or with-editor--envvar shell-command-with-editor-mode))
-               (not (string-suffix-p "&" command)))
-           (funcall fn command output-buffer error-buffer))
-          ((and with-editor-shell-command-use-emacsclient
-                with-editor-emacsclient-executable
-                (not (file-remote-p default-directory)))
-           (with-editor (funcall fn command output-buffer error-buffer)))
-          (t
-           (funcall fn (format "%s=%s %s"
-                               (or with-editor--envvar "EDITOR")
-                               (shell-quote-argument with-editor-sleeping-editor)
-                               command)
-                    output-buffer error-buffer)
-           (ignore-errors
-             (let ((process (get-buffer-process
-                             (or output-buffer
-                                 (get-buffer "*Async Shell Command*")))))
-               (set-process-filter
-                process (lambda (proc str)
-                          (comint-output-filter proc str)
-                          (with-editor-process-filter proc str t)))
-               process))))))
+    (if (or (not (or with-editor--envvar shell-command-with-editor-mode))
+            (not (string-suffix-p "&" command)))
+        (funcall fn command output-buffer error-buffer)
+      (let ((with-editor-emacsclient-executable
+             (and with-editor-shell-command-use-emacsclient
+                  with-editor-emacsclient-executable)))
+        (with-editor (funcall fn command output-buffer error-buffer))))))

 (advice-add 'shell-command :around
             #'shell-command--shell-command-with-editor-mode)