From: Kevin Rodgers <ihs_4664@yahoo.com>
Subject: Re: Split string into shell words?
Date: Tue, 20 Jan 2004 16:19:48 -0700 [thread overview]
Message-ID: <400DB794.7060601@yahoo.com> (raw)
In-Reply-To: 87broy5zjp.fsf@emptyhost.emptydomain.de
Kai Grossjohann wrote:
> Given a string as in the following line:
>
> foo "a b" 'c d' e\ f bar
>
> I'd like a function that returns the following list:
>
> ("foo" "a b" "c d" "e f" "bar")
>
> That is, the string should be split into words like a shell would
> split it into words.
As Stefan points out, this is hard because of things like command substitution.
> I thought there must be a function in comint*.el or shell*.el
> somewhere, but couldn't find it. Probably I'm blind.
Shell Mode's completion mechanism seems to just ignore quoting. E.g.
if you've typed
cat /dev/nul""
on the command line, TAB doesn't complete it to
cat /dev/nul""l
and it reports "No completions of /dev/nul\" for both
cat /dev/nul\
and
cat /dev/nul\\
Here's what I tried in the *scratch* buffer for your example, to see if the
Emacs Lisp reader could do most of the work:
(setq string "foo \"a b\" 'c d' e\\ f bar")
"foo \"a b\" 'c d' e\\ f bar"
;; Everything looks good:
(read-from-string string)
(foo . 3)
(read-from-string string 3)
("a b" . 9)
;; Until this:
(read-from-string string 9)
((quote c) . 12)
(read-from-string string 12)
(d . 14)
;; And now things are OK again:
(read-from-string string 14)
((quote e\ f) . 20)
(read-from-string string 20)
(bar . 24)
It might be nice if the 'form -> (quote form) implementation in
src/lread.c:read1() could be customized (e.g. by temporarily making the
single quote behave like a double quote), but Emacs Lisp doesn't have
the notion of reader macros and its semantics are hard-coded:
case '\'':
{
return Fcons (Qquote, Fcons (read0 (readcharfun), Qnil));
}
--
Kevin Rodgers
next prev parent reply other threads:[~2004-01-20 23:19 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-01-20 16:56 Split string into shell words? Kai Grossjohann
2004-01-20 18:04 ` Stefan Monnier
2004-01-28 8:37 ` Kai Grossjohann
2004-01-20 23:19 ` Kevin Rodgers [this message]
2004-01-20 23:47 ` Stefan Monnier
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=400DB794.7060601@yahoo.com \
--to=ihs_4664@yahoo.com \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).