Why is (string-match "lisp" major-mode) not working, while (string-equal "lisp-interaction-mode" major-mode) is working?

string-match results in debugger message: (wrong-type-argument stringp lisp-interaction-mode)

But help states:

(string-equal S1 S2)

(string-match REGEXP STRING &optional START)

(S1 and S2 is a placeholder for STRING, right?)

I already know that (string-match "lisp" (prin1-to-string major-mode)) can be used to get the expected result.

  • 3
    (string-match "lisp" (symbol-name major-mode)) would be more precise, depending on what you want (derived-mode-p 'emacs-lisp-mode) might make sense.
    – npostavs
    Commented May 30, 2017 at 14:17
  • In addition, if you only want to check whether a pattern matches a string, so you don't care what the matched part is, then consider using string-match-p instead of string-match.
    – Drew
    Commented May 30, 2017 at 15:33

1 Answer 1


string-match doesn't allow symbols but string-equal does.

(string-equal S1 S2)

Return t if two strings have identical contents. Case is significant, but text properties are ignored. Symbols are also allowed; their print names are used instead.

Note that result of evaluating major-mode is not a string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.