unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Albinus <michael.albinus@gmx.de>
To: Jim Porter <jporterbugs@gmail.com>
Cc: 54487@debbugs.gnu.org
Subject: bug#54487: 29.0.50; connection-local value for `shell-file-name' not set in Dired buffers over Tramp
Date: Mon, 21 Mar 2022 11:25:28 +0100	[thread overview]
Message-ID: <87y213bo13.fsf@gmx.de> (raw)
In-Reply-To: <eeb8675a-9c86-2ac8-a155-8a2eb66beb43@gmail.com> (Jim Porter's message of "Sun, 20 Mar 2022 21:58:56 -0700")

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

Jim Porter <jporterbugs@gmail.com> writes:

Hi Jim,

> Hopefully I've summarized the issue correctly in the bug title. To see
> this in action, run the following from `emacs -Q' on an MS-Windows
> system ("host" in this example is a remote GNU/Linux system):
>
>   C-x C-f /ssh:host:~
>   M-x rgrep RET
>   some text RET RET RET
>
> The rgrep output will look something like:
>
>   find [...] --null -e "some text" "{}" +
>   find: paths must precede expression: `^^!^'

I confirm the bug, it happens also for me.

> You can click the "[...]" to see the full invocation. However, even
> without doing that, if you look carefully, you'll notice that the
> shell-quoting uses the MS-Windows rules, not that of /bin/sh. For the
> MS-Windows shell, spaces are quoted by wrapping the entire argument in
> double-quotes ("like this"); for /bin/sh, spaces are escaped via a
> backslash (like\ this).
>
> Presumably, that's because if you eval `shell-file-name' in the Dired
> buffer, it reports ".../path/to/cmdproxy.exe". When in a remote
> *file*, `shell-file-name' is correctly set to "/bin/sh".

It is not a problem of shell-file-name, if you check the Tramp debug
buffer you'll see, that a proper shell ("/bin/sh" in my case) is
applied.

The problem is rather quoting the arguments with shell-quote-argument. It
applies the quoting according to the value of system-type. If this is
'ms-dos or 'windows-nt, MS Windows quoting rules are applied.

The appended patch fixes this for me, could you pls check?

Best regards, Michael.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 5239 bytes --]

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index ccc58e6773..85e872bfc2 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -611,6 +611,11 @@ grep-hello-file
       (write-region "Copyright\n" nil result))
     result))

+(defun grep-shell-quote-argument (argument)
+  (let ((system-type
+         (if (file-remote-p default-directory) 'not-windows system-type)))
+    (shell-quote-argument argument)))
+
 ;;;###autoload
 (defun grep-compute-defaults ()
   "Compute the defaults for the `grep' command.
@@ -636,8 +641,8 @@ grep-compute-defaults
 	  (intern (or (file-remote-p default-directory) "localhost")))
 	 (host-defaults (assq host-id grep-host-defaults-alist))
 	 (defaults (assq nil grep-host-defaults-alist))
-         (quot-braces (shell-quote-argument "{}"))
-         (quot-scolon (shell-quote-argument ";")))
+         (quot-braces (grep-shell-quote-argument "{}"))
+         (quot-scolon (grep-shell-quote-argument ";")))
     ;; There are different defaults on different hosts.  They must be
     ;; computed for every host once.
     (dolist (setting '(grep-command grep-template
@@ -820,7 +825,7 @@ grep-tag-default

 (defun grep-default-command ()
   "Compute the default grep command for \\[universal-argument] \\[grep] to offer."
-  (let ((tag-default (shell-quote-argument (grep-tag-default)))
+  (let ((tag-default (grep-shell-quote-argument (grep-tag-default)))
 	;; This a regexp to match single shell arguments.
 	;; Could someone please add comments explaining it?
 	(sh-arg-re
@@ -963,7 +968,7 @@ grep-expand-keywords
     ("<F>" . files)
     ("<N>" . (null-device))
     ("<X>" . excl)
-    ("<R>" . (shell-quote-argument (or regexp ""))))
+    ("<R>" . (grep-shell-quote-argument (or regexp ""))))
   "List of substitutions performed by `grep-expand-template'.
 If car of an element matches, the cdr is evalled in order to get the
 substitution string.
@@ -1134,10 +1139,10 @@ lgrep
 				    (mapconcat
                                      (lambda (ignore)
                                        (cond ((stringp ignore)
-                                              (shell-quote-argument ignore))
+                                              (grep-shell-quote-argument ignore))
                                              ((consp ignore)
                                               (and (funcall (car ignore) dir)
-                                                   (shell-quote-argument
+                                                   (grep-shell-quote-argument
                                                     (cdr ignore))))))
 				     grep-find-ignored-files
 				     " --exclude=")))
@@ -1245,44 +1250,44 @@ rgrep-default-command
   (grep-expand-template
    grep-find-template
    regexp
-   (concat (shell-quote-argument "(")
+   (concat (grep-shell-quote-argument "(")
            " " find-name-arg " "
            (mapconcat
-            #'shell-quote-argument
+            #'grep-shell-quote-argument
             (split-string files)
             (concat " -o " find-name-arg " "))
            " "
-           (shell-quote-argument ")"))
+           (grep-shell-quote-argument ")"))
    dir
    (concat
     (and grep-find-ignored-directories
          (concat "-type d "
-                 (shell-quote-argument "(")
-                 ;; we should use shell-quote-argument here
+                 (grep-shell-quote-argument "(")
+                 ;; we should use grep-shell-quote-argument here
                  " -path "
-                 (mapconcat (lambda (d) (shell-quote-argument (concat "*/" d)))
+                 (mapconcat (lambda (d) (grep-shell-quote-argument (concat "*/" d)))
                             (rgrep-find-ignored-directories dir)
                             " -o -path ")
                  " "
-                 (shell-quote-argument ")")
+                 (grep-shell-quote-argument ")")
                  " -prune -o "))
     (and grep-find-ignored-files
-         (concat (shell-quote-argument "!") " -type d "
-                 (shell-quote-argument "(")
-                 ;; we should use shell-quote-argument here
+         (concat (grep-shell-quote-argument "!") " -type d "
+                 (grep-shell-quote-argument "(")
+                 ;; we should use grep-shell-quote-argument here
                  " -name "
                  (mapconcat
                   (lambda (ignore)
                     (cond ((stringp ignore)
-                           (shell-quote-argument ignore))
+                           (grep-shell-quote-argument ignore))
                           ((consp ignore)
                            (and (funcall (car ignore) dir)
-                                (shell-quote-argument
+                                (grep-shell-quote-argument
                                  (cdr ignore))))))
                   grep-find-ignored-files
                   " -o -name ")
                  " "
-                 (shell-quote-argument ")")
+                 (grep-shell-quote-argument ")")
                  " -prune -o ")))))

 (defun grep-find-toggle-abbreviation ()

  reply	other threads:[~2022-03-21 10:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-21  4:58 bug#54487: 29.0.50; connection-local value for `shell-file-name' not set in Dired buffers over Tramp Jim Porter
2022-03-21 10:25 ` Michael Albinus [this message]
2022-03-21 12:40   ` Eli Zaretskii
2022-03-21 14:06     ` Michael Albinus
2022-03-21 14:52       ` Eli Zaretskii
2022-03-21 15:02         ` Michael Albinus
2022-03-21 15:05           ` Eli Zaretskii
2022-03-21 15:09             ` Michael Albinus
2022-03-21 18:04       ` Jim Porter
2022-03-22  9:44         ` Michael Albinus
2022-03-23 11:53           ` Michael Albinus
2022-03-23 16:55             ` Jim Porter
2022-03-23 18:58         ` Michael Albinus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y213bo13.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=54487@debbugs.gnu.org \
    --cc=jporterbugs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).