help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What's the best way to do "string-memq"?


From: Alan Mackenzie
Subject: Re: What's the best way to do "string-memq"?
Date: Mon, 10 Nov 2008 19:02:58 +0000
User-agent: Mutt/1.5.9i

Hi, Drew!

On Mon, Nov 10, 2008 at 10:17:54AM -0800, Drew Adams wrote:
> > I need a predicate which I'd ideally like to write as
> >     (string-memq (char-after) skip-chars)
> > , where skip-chars is a string like "^;{}?:", and the predicate should
> > return t when (char-after) is one of (?^ ?\; ?\{ ?\} ?\? ?\:).

> Here are a couple of ways:

> (string-match (regexp-quote
>                (char-to-string (char-after)))
>               skip-chars)

> (member (char-after) (string-to-list skip-chars))

> (They return non-nil, not t, but you can fix that.) Someone else will
> probably show you a better way. And you're right that cl offers this
> out of the box.

The non-nil isn't a problem at all.

But thanks for the tip!  I probably won't want to use `string-to-list',
since it's in mule, and mule wasn't included as standard in some previous
Emacs, (Was it 20 or 21?).

But string-to-list is nothing more than:

    (defsubst string-to-list (string)
      "Return a list of characters in STRING."
      (append string nil))

, so I think I can use `append' directly.  But what a kludge it is!

    (append "asdf" "1234!)  => (?a ?s ?d ?f "1234)

.  It's almost embarrassing.  ;-(

Thanks again!  This list always comes up with the goods.

-- 
Alan Mackenzie (Nuremberg, Germany).




reply via email to

[Prev in Thread] Current Thread [Next in Thread]