From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: "Stefan Monnier" Newsgroups: gmane.emacs.devel Subject: Re: shell-quote-argument: make it behave as if on Unix? Date: Fri, 12 Apr 2002 00:09:43 -0400 Sender: emacs-devel-admin@gnu.org Message-ID: <200204120409.g3C49h707814@rum.cs.yale.edu> References: <2950-Wed10Apr2002195652+0300-eliz@is.elta.co.il> <200204120311.g3C3Bjg22167@aztec.santafe.edu> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1018584737 14890 127.0.0.1 (12 Apr 2002 04:12:17 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Fri, 12 Apr 2002 04:12:17 +0000 (UTC) Cc: Kai.Grossjohann@CS.Uni-Dortmund.DE, eliz@is.elta.co.il, emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 16vsQ5-0003s3-00 for ; Fri, 12 Apr 2002 06:12:17 +0200 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 16vsg9-0004C7-00 for ; Fri, 12 Apr 2002 06:28:53 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16vsPt-00060Z-00; Fri, 12 Apr 2002 00:12:05 -0400 Original-Received: from rum.cs.yale.edu ([128.36.229.169]) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 16vsNc-0005hK-00; Fri, 12 Apr 2002 00:09:44 -0400 Original-Received: (from monnier@localhost) by rum.cs.yale.edu (8.11.6/8.11.6) id g3C49h707814; Fri, 12 Apr 2002 00:09:43 -0400 X-Mailer: exmh version 2.4 06/23/2000 with nmh-1.0.4 Original-To: Richard Stallman Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:2566 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:2566 > > It strikes me that we should add to shell-quote-argument an optional > > argument that will cause it to quote a shell argument for specific OS. > > If the optional argument is omitted or nil, let it default to > > system-type. > > > > What do you think? > > This sounds like a good idea. > > It is more modular to keep this complexity within the Tramp module > rather than complicate other parts of Emacs. So I'd rather you put > the code you want into Tramp. If the patch below is too much complexity for Emacs, than the best bet for Tramp is probably to temporarily bind system-type. Stefan @@ -1621,9 +1622,12 @@ (setq matches (cons (substring string start l) matches)) ; leftover (apply #'concat (nreverse matches))))) -(defun shell-quote-argument (argument) - "Quote an argument for passing as argument to an inferior shell." - (if (eq system-type 'ms-dos) +(defun shell-quote-argument (argument &optional shell-type) + "Quote an argument for passing as argument to an inferior shell. +SHELL-TYPE is the type of shell to which this will be passed. +It defaults to the value of `system-type'." + (unless shell-type (setq shell-type system-type)) + (if (eq shell-type 'ms-dos) ;; Quote using double quotes, but escape any existing quotes in ;; the argument with backslashes. (let ((result "") @@ -1637,7 +1641,7 @@ "\\" (substring argument end (1+ end))) start (1+ end)))) (concat "\"" result (substring argument start) "\"")) - (if (eq system-type 'windows-nt) + (if (eq shell-type 'windows-nt) (concat "\"" argument "\"") (if (equal argument "") "''"