From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Hansen Newsgroups: gmane.emacs.devel Subject: Re: [david.hansen@gmx.net: Re: comint's directory tracking doesn't understand \( or \)] Date: Sun, 04 Mar 2007 14:13:22 +0100 Organization: disorganized Message-ID: <871wk56tjh.fsf@localhorst.mine.nu> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1173014657 18540 80.91.229.12 (4 Mar 2007 13:24:17 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 4 Mar 2007 13:24:17 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Mar 04 14:24:11 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 1HNqh7-0001qy-Pp for ged-emacs-devel@m.gmane.org; Sun, 04 Mar 2007 14:24:10 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HNqh7-0001kN-6t for ged-emacs-devel@m.gmane.org; Sun, 04 Mar 2007 08:24:09 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HNqgu-0001kE-MF for emacs-devel@gnu.org; Sun, 04 Mar 2007 08:23:56 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HNqgu-0001k2-4J for emacs-devel@gnu.org; Sun, 04 Mar 2007 08:23:56 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HNqgu-0001jz-1P for emacs-devel@gnu.org; Sun, 04 Mar 2007 08:23:56 -0500 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1HNqgt-0005sd-DN for emacs-devel@gnu.org; Sun, 04 Mar 2007 08:23:55 -0500 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HNqgd-0002OP-De for emacs-devel@gnu.org; Sun, 04 Mar 2007 14:23:39 +0100 Original-Received: from e178058052.adsl.alicedsl.de ([85.178.58.52]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 04 Mar 2007 14:23:39 +0100 Original-Received: from david.hansen by e178058052.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 04 Mar 2007 14:23:39 +0100 X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: emacs-devel@gnu.org Original-Lines: 169 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: e178058052.adsl.alicedsl.de Mail-Copies-To: nobody User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.93 (gnu/linux) Cancel-Lock: sha1:/DLyElRva8ERHEe676m33w43vnY= X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) 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:67290 Archived-At: On Fri, 02 Mar 2007 12:44:48 -0500 Richard Stallman wrote: > Would someone please study this, install it if it is safe, then ack? Alone it's doing not that much. The attached patch should fix all problems with shell-modes directory tracking and special characters in directory names. I'm sorry that it's a bit longish, but the original regexps are a bit to much for my small brain ;) David *** comint.el 04 Mar 2007 13:04:02 +0100 1.358 --- comint.el 04 Mar 2007 14:07:56 +0100 *************** *** 105,110 **** --- 105,112 ---- ;;; Code: (require 'ring) + (eval-when-compile (require 'cl)) + ;; Buffer Local Variables: ;;============================================================================ *************** *** 1344,1371 **** (t nth)))) (comint-arguments string nth mth))))) - (defun comint-delim-arg (arg) - "Return a list of arguments from ARG. - Break it up at the delimiters in `comint-delimiter-argument-list'. - Returned list is backwards." - (if (null comint-delimiter-argument-list) - (list arg) - (let ((args nil) - (pos 0) - (len (length arg))) - (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))) - (defun comint-arguments (string nth mth) "Return from STRING the NTH to MTH arguments. NTH and/or MTH can be nil, which means the last argument. --- 1346,1351 ---- *************** *** 1375,1423 **** Also, a run of one or more of a single character in `comint-delimiter-argument-list' is a separate argument. Argument 0 is the command name." ! ;; The first line handles ordinary characters and backslash-sequences ! ;; (except with w32 msdos-like shells, where backslashes are valid). ! ;; The second matches "-quoted strings. ! ;; 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. ! (setq str (substring string beg pos) ! 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 ! (setq str (substring string beg pos) ! args (if quotes (cons str args) ! (nconc (comint-delim-arg str) args)))) ! (setq count (length args)) ! (let ((n (or nth (1- count))) ! (m (if mth (1- (- count mth)) 0))) ! (mapconcat ! (function (lambda (a) a)) (nthcdr n (nreverse (nthcdr m args))) " ")))) ;; ;; Input processing stuff --- 1355,1414 ---- Also, a run of one or more of a single character in `comint-delimiter-argument-list' is a separate argument. Argument 0 is the command name." ! (let ((esc (unless (and (fboundp 'w32-shell-dos-semantics) ! (w32-shell-dos-semantics)) ! ?\\)) ! (ifs '(?\n ?\t ?\ )) ! (len (length string)) ! (i 0) (beg 0) state args) ! (flet ((push-arg (new-beg) ! ;; with I at the end of an arg push it to `args' and set the ! ;; beginning of the next arg `beg' to NEW-BEG ! (push (substring string beg i) args) ! (and mth (decf mth)) ! (setq beg new-beg))) ! (while (and (<= i len) (or (not mth) (>= mth 0))) ! (let ((s (car state)) ! (c (and (< i len) (aref string i)))) ! (cond ((and (integerp s) (not (eq s c))) ! (push-arg i) ! (pop state) ! (decf i)) ; parse this character again ! ((eq 'escaped s) ! (pop state)) ! ((eq ?\' c) ! (if (eq 'single-quote s) ! (pop state) ! (or s (push 'single-quote state)))) ! ((eq ?\" c) ! (if (eq 'double-quote s) ! (pop state) ! (push 'double-quote state))) ! ((and esc (eq esc c) (not (eq 'single-quote s))) ! (push 'escaped state)) ! ((and (not s) (member c ifs)) ! (if (= beg i) ! (incf beg) ; just a second whitespace ! (push-arg (1+ i)))) ! ((and (not s) (member c comint-delimiter-argument-list)) ! (push c state) ! (when (/= beg i) ; no whitespace before this character ! (push-arg i))) ! ((not c) ; end of the string ! (unless (= beg len) ! (push-arg len)))) ! (incf i))) ! (if (not nth) ! ;; if MTH is non nil only return the last argument if there are no ! ;; non parsed arguments left ! (or (and (or (not mth) ! (>= i len) ! (string-match "[\t\n ]*$" string i)) ! (car args)) ! "") ! (setf (nthcdr (- (length args) nth) args) nil) ! (mapconcat #'identity (nreverse args) " "))))) ! ;; ;; Input processing stuff