1

I'm newbie with Emacs and I'm experimenting with Lisp on GNU Emacs-26.1. Can't understand why the following simple piece of Elisp code does not work:

    (string-match "^GNU Emacs" emacs-version)

If I just leave as

    (string-match "Emacs" emacs-version)

it still returns nil

However,

    (string-match "^GNU Emacs" "GNU Emacs 26.1")

returns 0 (#o0, #x0, ?\C-@) i.e. position 0 as expected.

It always return nil, although M-x emacs version returns:

GNU Emacs 26.1 (build 1. x86-64-redhat-linux-gnu, GTK+ Version 3.22.30) of 2021-08-05

How to get emacs-version to evaluate to a string such as "GNU Emacs 26.1..."?

1
  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Nov 23, 2022 at 20:56

1 Answer 1

1

Your code uses emacs-version as a variable, not as a function.

Variable emacs-version returns a string such as this: "26.1". Function emacs-version returns a string such as this: "GNU Emacs 26.1 (build 1. x86-64-redhat-linux-gnu, GTK+ Version 3.22.30) of 2021-08-05".

To invoke the function instead of evaluating the variable, use (emacs-version) instead of emacs-version.

When you use M-x emacs-version you invoke the command, that is, the function, emacs-version (a command is a function that can be invoked interactively -- with M-x or with a key bound to it).

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.