From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: [david.hansen@gmx.net: Re: comint's directory tracking doesn't understand \( or \)] Date: Sat, 10 Mar 2007 15:18:31 -0500 Message-ID: <874poslunc.fsf@stupidchicken.com> References: <871wk56tjh.fsf@localhorst.mine.nu> <87k5xw8b07.fsf@localhorst.mine.nu> <87irddev4c.fsf@catnip.gol.com> <873b4hjegy.fsf@localhorst.mine.nu> <87lki62nuw.fsf@stupidchicken.com> <87ejnyj754.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1173557948 28469 80.91.229.12 (10 Mar 2007 20:19:08 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sat, 10 Mar 2007 20:19:08 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Mar 10 21:19:04 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HQ81s-0006QA-Gq for ged-emacs-devel@m.gmane.org; Sat, 10 Mar 2007 21:19:00 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HQ82H-0003aP-AL for ged-emacs-devel@m.gmane.org; Sat, 10 Mar 2007 15:19:25 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HQ825-0003aK-C4 for emacs-devel@gnu.org; Sat, 10 Mar 2007 15:19:13 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HQ824-0003aB-1M for emacs-devel@gnu.org; Sat, 10 Mar 2007 15:19:12 -0500 Original-Received: from south-station-annex.mit.edu ([18.72.1.2]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HQ81a-0000Yr-FY for emacs-devel@gnu.org; Sat, 10 Mar 2007 15:18:42 -0500 Original-Received: from central-city-carrier-station.mit.edu (CENTRAL-CITY-CARRIER-STATION.MIT.EDU [18.7.7.72]) by south-station-annex.mit.edu (8.13.6/8.9.2) with ESMTP id l2AKIeWK019120 for ; Sat, 10 Mar 2007 15:18:40 -0500 (EST) Original-Received: from outgoing-legacy.mit.edu (OUTGOING-LEGACY.MIT.EDU [18.7.22.104]) by central-city-carrier-station.mit.edu (8.13.6/8.9.2) with ESMTP id l2AKIXW3008449 for ; Sat, 10 Mar 2007 15:18:33 -0500 (EST) Original-Received: from localhost (MAIN-TWELVE-TWO-FIFTY-SIX.MIT.EDU [18.19.6.1]) ) by outgoing-legacy.mit.edu (8.13.6/8.12.4) with ESMTP id l2AKIWXF015511 for ; Sat, 10 Mar 2007 15:18:32 -0500 (EST) Original-Received: from cyd by localhost with local (Exim 3.36 #1 (Debian)) id 1HQ81Q-0000lS-00 for ; Sat, 10 Mar 2007 15:18:32 -0500 In-Reply-To: <87ejnyj754.fsf@stupidchicken.com> (Chong Yidong's message of "Fri\, 09 Mar 2007 19\:04\:39 -0500") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.95 (gnu/linux) X-Scanned-By: MIMEDefang 2.42 X-Spam-Score: -2.599 X-detected-kernel: Solaris 9.1 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:67692 Archived-At: David Hansen wrote: > The string gets still splitted at members of > `comint-delimiter-argument-list' (note that it's buffer local) no > matter if they are escaped or not. > > I have to admit that it probably can be fixed with far less than a > 200 line patch but I'm not willing to touch these regexps and i > don't think it will result in anything "safer". I think there is an easy way to get around this difficulty: once backslash-escaped characters have been identified, put a text property on the string saying that character is literal, then make comint-delim-arg avoid splitting when such a text property is present. Here is a patch to implement this. I can verify that it solves the original bug. As far as safety goes, I think it is a little safer than the other candidate patch, if only because it's simpler to read. *** /home/cyd/emacs/lisp/comint.el.~1.358.~ 2007-02-27 19:43:48.000000000 -0500 --- /home/cyd/emacs/lisp/comint.el 2007-03-10 15:15:40.000000000 -0500 *************** *** 1356,1367 **** (while (< pos len) (let ((char (aref arg pos)) (start pos)) ! (if (memq char comint-delimiter-argument-list) (while (and (< pos len) (eq (aref arg pos) char)) (setq pos (1+ pos))) (while (and (< pos len) ! (not (memq (aref arg pos) ! comint-delimiter-argument-list))) (setq pos (1+ pos)))) (setq args (cons (substring arg start pos) args)))) args))) --- 1356,1371 ---- (while (< pos len) (let ((char (aref arg pos)) (start pos)) ! (if (and (memq char comint-delimiter-argument-list) ! ;; Ignore backslash-escaped characters. ! (not (get-text-property pos 'literal arg))) (while (and (< pos len) (eq (aref arg pos) char)) (setq pos (1+ pos))) (while (and (< pos len) ! (not (and (memq (aref arg pos) ! comint-delimiter-argument-list) ! (not (get-text-property ! pos 'literal arg))))) (setq pos (1+ pos)))) (setq args (cons (substring arg start pos) args)))) args))) *************** *** 1381,1404 **** ;; The third matches '-quoted strings. ;; The fourth matches `-quoted strings. ;; This seems to fit the syntax of BASH 2.0. ! (let* ((first (if (if (fboundp 'w32-shell-dos-semantics) ! (w32-shell-dos-semantics)) ! "[^ \n\t\"'`]+\\|" ! "[^ \n\t\"'`\\]+\\|\\\\[\"'`\\ \t]+\\|")) (argpart (concat first "\\(\"\\([^\"\\]\\|\\\\.\\)*\"\\|\ '[^']*'\\|\ `[^`]*`\\)")) (args ()) (pos 0) (count 0) beg str quotes) ;; Build a list of all the args until we have as many as we want. (while (and (or (null mth) (<= count mth)) (string-match argpart string pos)) (if (and beg (= pos (match-beginning 0))) ;; It's contiguous, part of the same arg. (setq pos (match-end 0) ! quotes (or quotes (match-beginning 1))) ;; It's a new separate arg. (if beg ;; Put the previous arg, if there was one, onto ARGS. --- 1385,1414 ---- ;; The third matches '-quoted strings. ;; The fourth matches `-quoted strings. ;; This seems to fit the syntax of BASH 2.0. ! (let* ((backslash-escape (not (and (fboundp 'w32-shell-dos-semantics) ! (w32-shell-dos-semantics)))) ! (first (if backslash-escape ! "[^ \n\t\"'`\\]\\|\\(\\\\.\\)\\|" ! "[^ \n\t\"'`]+\\|")) (argpart (concat first "\\(\"\\([^\"\\]\\|\\\\.\\)*\"\\|\ '[^']*'\\|\ `[^`]*`\\)")) + (quote-subexpr (if backslash-escape 2 1)) (args ()) (pos 0) (count 0) beg str quotes) ;; Build a list of all the args until we have as many as we want. (while (and (or (null mth) (<= count mth)) (string-match argpart string pos)) + (and backslash-escape + (match-beginning 1) + (put-text-property (match-beginning 1) (match-end 1) + 'literal t string)) (if (and beg (= pos (match-beginning 0))) ;; It's contiguous, part of the same arg. (setq pos (match-end 0) ! quotes (or quotes (match-beginning quote-subexpr))) ;; It's a new separate arg. (if beg ;; Put the previous arg, if there was one, onto ARGS. *************** *** 1406,1412 **** args (if quotes (cons str args) (nconc (comint-delim-arg str) args)))) (setq count (length args)) ! (setq quotes (match-beginning 1)) (setq beg (match-beginning 0)) (setq pos (match-end 0)))) (if beg --- 1416,1422 ---- args (if quotes (cons str args) (nconc (comint-delim-arg str) args)))) (setq count (length args)) ! (setq quotes (match-beginning quote-subexpr)) (setq beg (match-beginning 0)) (setq pos (match-end 0)))) (if beg