all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Patch of shell-command-to-string in simple for tramp support
@ 2018-01-25 12:11 Shuguang Sun
  2018-01-25 13:08 ` Michael Albinus
  0 siblings, 1 reply; 5+ messages in thread
From: Shuguang Sun @ 2018-01-25 12:11 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 449 bytes --]

Hi,

The shell-command-to-string calls shell-file-name directly and it doesn't
work in the case of local Windows and remoter Unix. I borrow the some code
from shell.el and make a patch to simple.el.

Example: in find-file-in-project, shell-command-to-string was called to get
the list of filenames. If it is in a remote directry via tramp, it will put
error message c:/.../cmdproxy.exe not found.
The patch solves the issue.

Best Regards,
Shuguang

[-- Attachment #1.2: Type: text/html, Size: 583 bytes --]

[-- Attachment #2: simple.el.diff --]
[-- Type: text/plain, Size: 2217 bytes --]

diff --git a/lisp/simple.el b/lisp/simple.el
index e51bc132a6..1c3c1f8a9b 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3844,7 +3844,42 @@ shell-command-to-string
   (with-output-to-string
     (with-current-buffer
       standard-output
-      (process-file shell-file-name nil t nil shell-command-switch command))))
+      (when (file-remote-p default-directory)
+        ;; Borrow from shell in shell.el
+        ;; Apply connection-local variables.
+        (hack-connection-local-variables-apply
+         `(:application tramp
+                        :protocol ,(file-remote-p default-directory 'method)
+                        :user ,(file-remote-p default-directory 'user)
+                        :machine ,(file-remote-p default-directory 'host)))
+
+        ;; On remote hosts, the local `shell-file-name' might be useless.
+        (if (and (called-interactively-p 'any)
+                 (null explicit-shell-file-name)
+                 (null (getenv "ESHELL")))
+            (set (make-local-variable 'explicit-shell-file-name)
+                 (file-local-name
+                  (expand-file-name
+                   (read-file-name
+                    "Remote shell path: " default-directory shell-file-name
+                    t shell-file-name))))))
+
+      (unless (comint-check-proc standard-output)
+        (let* ((prog (or explicit-shell-file-name
+                         (getenv "ESHELL") shell-file-name))
+               ;; we can't use "-i"
+               ;; (name (file-name-nondirectory prog))
+               ;; (xargs-name (intern-soft (concat "explicit-" name "-args")))
+               )
+          (process-file prog nil t nil
+                        ;; here we can't use "-i"
+                        ;; (if (and xargs-name (boundp xargs-name))
+                        ;;     (mapconcat 'identity (symbol-value xargs-name) " ")
+                        ;;   shell-command-switch)
+                        shell-command-switch
+                        command)
+          ))
+      )))

 (defun process-file (program &optional infile buffer display &rest args)
   "Process files synchronously in a separate process.

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: Patch of shell-command-to-string in simple for tramp support
  2018-01-25 12:11 Patch of shell-command-to-string in simple for tramp support Shuguang Sun
@ 2018-01-25 13:08 ` Michael Albinus
  2018-01-25 14:11   ` Shuguang Sun
  2018-01-25 14:12   ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Albinus @ 2018-01-25 13:08 UTC (permalink / raw)
  To: Shuguang Sun; +Cc: emacs-devel

Shuguang Sun <shuguang@gmail.com> writes:

> Hi,

Hi Shuguang,

> The shell-command-to-string calls shell-file-name directly and it
> doesn't work in the case of local Windows and remoter Unix. I borrow
> the some code from shell.el and make a patch to simple.el.

I believe it is wrong to make `shell-command-to-string' Tramp-aware. We
have `shell-command', which runs a (Tramp) file name handler if
needed. The proper change should be:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/simple.el b/lisp/simple.el
index e51bc132a6..44f738f07e 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3844,7 +3844,7 @@ shell-command-to-string
   (with-output-to-string
     (with-current-buffer
       standard-output
-      (process-file shell-file-name nil t nil shell-command-switch command))))
+      (shell-command command t))))
 
 (defun process-file (program &optional infile buffer display &rest args)
   "Process files synchronously in a separate process.
--8<---------------cut here---------------end--------------->8---

Could you, pls, test it in your environment?

> Best Regards,
> Shuguang

Best regards, Michael.



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: Patch of shell-command-to-string in simple for tramp support
  2018-01-25 13:08 ` Michael Albinus
@ 2018-01-25 14:11   ` Shuguang Sun
  2018-01-25 14:31     ` Michael Albinus
  2018-01-25 14:12   ` Stefan Monnier
  1 sibling, 1 reply; 5+ messages in thread
From: Shuguang Sun @ 2018-01-25 14:11 UTC (permalink / raw)
  To: Michael Albinus; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1341 bytes --]

It works as I expected.
Thanks.

On Thu, Jan 25, 2018 at 9:08 PM, Michael Albinus <michael.albinus@gmx.de>
wrote:

> Shuguang Sun <shuguang@gmail.com> writes:
>
> > Hi,
>
> Hi Shuguang,
>
> > The shell-command-to-string calls shell-file-name directly and it
> > doesn't work in the case of local Windows and remoter Unix. I borrow
> > the some code from shell.el and make a patch to simple.el.
>
> I believe it is wrong to make `shell-command-to-string' Tramp-aware. We
> have `shell-command', which runs a (Tramp) file name handler if
> needed. The proper change should be:
>
> --8<---------------cut here---------------start------------->8---
> diff --git a/lisp/simple.el b/lisp/simple.el
> index e51bc132a6..44f738f07e 100644
> --- a/lisp/simple.el
> +++ b/lisp/simple.el
> @@ -3844,7 +3844,7 @@ shell-command-to-string
>    (with-output-to-string
>      (with-current-buffer
>        standard-output
> -      (process-file shell-file-name nil t nil shell-command-switch
> command))))
> +      (shell-command command t))))
>
>  (defun process-file (program &optional infile buffer display &rest args)
>    "Process files synchronously in a separate process.
> --8<---------------cut here---------------end--------------->8---
>
> Could you, pls, test it in your environment?
>
> > Best Regards,
> > Shuguang
>
> Best regards, Michael.
>

[-- Attachment #2: Type: text/html, Size: 1927 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Patch of shell-command-to-string in simple for tramp support
  2018-01-25 13:08 ` Michael Albinus
  2018-01-25 14:11   ` Shuguang Sun
@ 2018-01-25 14:12   ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2018-01-25 14:12 UTC (permalink / raw)
  To: emacs-devel

> @@ -3844,7 +3844,7 @@ shell-command-to-string
>    (with-output-to-string
>      (with-current-buffer
>        standard-output
> -      (process-file shell-file-name nil t nil shell-command-switch command))))
> +      (shell-command command t))))
>  
>  (defun process-file (program &optional infile buffer display &rest args)
>    "Process files synchronously in a separate process.

shell-command does a *lot* more than run shell-file-name with
shell-command-switch and for the purpose of shell-command-to-string

Could you give more details about why you think using process-file here
is wrong?

BTW, I have my own reservations w.r.t shell-command-to-string: a quick
grep for that function shows that the vast majority of its users don't
actually need a shell, so it would make sense to provide some other
function:

    (defun YOUNAMEIT-to-string (program &rest args)
      "Execute PROGRAM with arguments ARGS and return its output as a string."
      (with-output-to-string
        (with-current-buffer
          standard-output
          (apply #'process-file program nil t nil args))))



        Stefan




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Patch of shell-command-to-string in simple for tramp support
  2018-01-25 14:11   ` Shuguang Sun
@ 2018-01-25 14:31     ` Michael Albinus
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Albinus @ 2018-01-25 14:31 UTC (permalink / raw)
  To: Shuguang Sun; +Cc: emacs-devel

Shuguang Sun <shuguang@gmail.com> writes:

Hi Shuguang,

> It works as I expected.

Thanks for testing. As usual, I'm not able to test under MS Windows.

I've pushed this to master.

> Thanks.

Best regards, Michael.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-01-25 14:31 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-25 12:11 Patch of shell-command-to-string in simple for tramp support Shuguang Sun
2018-01-25 13:08 ` Michael Albinus
2018-01-25 14:11   ` Shuguang Sun
2018-01-25 14:31     ` Michael Albinus
2018-01-25 14:12   ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.