From 4803595dfd00ce07cd09913ee3c5d40a023f3a08 Mon Sep 17 00:00:00 2001 From: Michael Albinus Date: Fri, 6 Dec 2013 16:34:06 +0100 Subject: [PATCH] Bug#16045 * progmodes/compile.el (compilation-start): * progmodes/grep.el (rgrep): Revert change of 2012-12-20T11:15:38Z!michael.albinus@gmx.de. * net/tramp-sh.el (tramp-sh-handle-start-file-process): Handle long command lines, lasting from "sh -c ...". (Bug#16045) --- lisp/ChangeLog | 8 +++++++ lisp/net/tramp-sh.el | 61 +++++++++++++++++++++++++++++++---------------- lisp/progmodes/compile.el | 6 +---- lisp/progmodes/grep.el | 8 +++---- 4 files changed, 52 insertions(+), 31 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 8e68eb40768..4bad667aa50 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2013-12-06 Michael Albinus + + * progmodes/compile.el (compilation-start): + * progmodes/grep.el (rgrep): Revert change 2012-12-20T11:15:38Z!michael.albinus@gmx.de. + + * net/tramp-sh.el (tramp-sh-handle-start-file-process): + Handle long command lines, lasting from "sh -c ...". (Bug#16045) + 2013-12-06 Dmitry Gutov * progmodes/ruby-mode.el (ruby-syntax-propertize-function): Touch diff --git a/lisp/net/tramp-sh.el b/lisp/net/tramp-sh.el index 6beece526ff..314c1a6f8e7 100644 --- a/lisp/net/tramp-sh.el +++ b/lisp/net/tramp-sh.el @@ -2686,27 +2686,46 @@ the result will be a local, non-Tramp, filename." (defun tramp-sh-handle-start-file-process (name buffer program &rest args) "Like `start-file-process' for Tramp files." (with-parsed-tramp-file-name default-directory nil - ;; When PROGRAM is nil, we just provide a tty. - (let ((command - (when (stringp program) - (format "cd %s; exec env PS1=%s %s" - (tramp-shell-quote-argument localname) - ;; Use a human-friendly prompt, for example for `shell'. - (tramp-shell-quote-argument - (format "%s %s" - (file-remote-p default-directory) - tramp-initial-end-of-output)) - (mapconcat 'tramp-shell-quote-argument - (cons program args) " ")))) - (tramp-process-connection-type - (or (null program) tramp-process-connection-type)) - (bmp (and (buffer-live-p buffer) (buffer-modified-p buffer))) - (name1 name) - (i 0) - ;; We do not want to raise an error when - ;; `start-file-process' has been started several time in - ;; `eshell' and friends. - (tramp-current-connection nil)) + (let* (;; When PROGRAM matches "*sh", and the first arg is "-c", + ;; it might be that the arguments exceed the command line + ;; length. Therefore, we modify the command. + (heredoc (and (stringp program) + (string-match "sh$" program) + (string-equal "-c" (car args)) + (= (length args) 2))) + ;; When PROGRAM is nil, we just provide a tty. + (args (if (not heredoc) args + (let ((i 250)) + (while (and (< i (length (cadr args))) + (string-match " " (cadr args) i)) + (setcdr + args + (list (replace-match " \\\\\n" nil nil (cadr args)))) + (setq i (+ i 250)))) + (cdr args))) + (command + (when (stringp program) + (format "cd %s; exec %s env PS1=%s %s" + (tramp-shell-quote-argument localname) + (if heredoc "<