Your code works fine, for me.
(when (member last-command (list 'foo 'bar 'bob 'baz)) (do-something))
First, last-command
is typically a symbol, not a string. There is no reason to use string-equal
for two symbols. It works, but it is slower - it just converts the symbols to strings and then compares those strings.
The best way to compare two symbols is with eq
. eq
compares two Lisp objects, i.e., they must be the same object to return non-nil
. For a list, memq
tests membership using eq
.
Second, even if the things to compare were strings, member
uses the test equal
, which uses string-equal
for string comparison.
If the question is really about last-command
, and not about comparing symbols or strings, then be aware that last-command
doesn't always return a symbol - see C-h v last-command
.
The last command executed.
Normally a symbol with a function definition, but can be whatever was found
in the keymap, or whatever the variable `this-command' was set to by that
command.
All the more reason to test with member
, which uses equal
.
(Also, you can just write '(foo bar bob baz)
instead of (list 'foo 'bar 'bob 'baz)
. But this is unimportant.)