From: Chong Yidong <cyd@stupidchicken.com>
To: emacs-devel@gnu.org
Subject: Re: [david.hansen@gmx.net: Re: comint's directory tracking doesn't understand \( or \)]
Date: Sat, 10 Mar 2007 15:18:31 -0500 [thread overview]
Message-ID: <874poslunc.fsf@stupidchicken.com> (raw)
In-Reply-To: <87ejnyj754.fsf@stupidchicken.com> (Chong Yidong's message of "Fri\, 09 Mar 2007 19\:04\:39 -0500")
David Hansen <david.hansen@gmx.net> 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
prev parent reply other threads:[~2007-03-10 20:18 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-02 17:44 [david.hansen@gmx.net: Re: comint's directory tracking doesn't understand \( or \)] Richard Stallman
2007-03-04 13:13 ` David Hansen
2007-03-04 15:45 ` Chong Yidong
2007-03-04 15:51 ` David Kastrup
2007-03-04 19:26 ` Chong Yidong
2007-03-04 19:32 ` David Kastrup
2007-03-04 19:39 ` Lennart Borgman (gmail)
2007-03-04 20:16 ` David Kastrup
2007-03-04 20:25 ` Lennart Borgman (gmail)
2007-03-04 19:47 ` Miles Bader
2007-03-04 21:45 ` Stefan Monnier
2007-03-04 22:06 ` Andreas Seltenreich
2007-03-04 23:42 ` Stefan Monnier
2007-03-04 23:13 ` David Hansen
2007-03-04 23:30 ` David Kastrup
2007-03-05 2:09 ` David Hansen
2007-03-04 19:40 ` Robert J. Chassell
2007-03-04 20:17 ` David Kastrup
2007-03-04 23:22 ` Chris Moore
2007-03-04 23:23 ` Tom Tromey
2007-03-05 2:55 ` Richard Stallman
2007-03-05 6:23 ` David Hansen
2007-03-05 21:50 ` Richard Stallman
2007-03-06 2:23 ` Stefan Monnier
2007-03-06 3:10 ` David Hansen
2007-03-06 22:36 ` Richard Stallman
2007-03-07 0:48 ` Miles Bader
2007-03-07 14:49 ` David Hansen
2007-03-08 3:16 ` Richard Stallman
2007-03-09 19:55 ` Chong Yidong
2007-03-09 20:28 ` Glenn Morris
2007-03-09 20:45 ` David Hansen
2007-03-09 21:08 ` David Kastrup
2007-03-10 0:04 ` Chong Yidong
2007-03-10 8:06 ` David Hansen
2007-03-10 20:18 ` Chong Yidong [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=874poslunc.fsf@stupidchicken.com \
--to=cyd@stupidchicken.com \
--cc=emacs-devel@gnu.org \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.