0

In emacs, when I evaluate an elisp function, I get the value plus other stuff.

For example, if I evaluate (+ 2 2), I get this:

4 (#04, #x4, ?\C-d)

How can I setup emacs to just return 4?

5
  • Does it happen when you do it in an emacs started with no init file? emacs -Q
    – Lhooq
    Commented Aug 29, 2022 at 20:13
  • I am using emacs mac application. Does that change anything regarding -Q?
    – Vinn
    Commented Aug 29, 2022 at 20:16
  • No it should behave the same as plain emacs here.
    – mmmmmm
    Commented Aug 29, 2022 at 20:26
  • How do you evaluate the function?
    – NickD
    Commented Aug 29, 2022 at 20:39
  • emacs.stackexchange.com/tags/elisp/info
    – Drew
    Commented Aug 29, 2022 at 21:29

1 Answer 1

1

It prints out that extra information as an aid to the user when you evaluate expressions interactively, but they’re not actually part of the return value of the expression itself. What are you actually trying to accomplish?

Edit: Ok, so you just regard it as distracting. Did you try reading the help for eval-expression? You can get the help for a function with C-h f, but I will duplicate it here:

Evaluate EXP and print value in the echo area.

When called interactively, read an Emacs Lisp expression and
evaluate it.  Value is also consed on to front of the variable
values.  Optional argument INSERT-VALUE non-nil (interactively,
with a non - prefix argument) means insert the result into the
current buffer instead of printing it in the echo area.

Normally, this function truncates long output according to the
value of the variables eval-expression-print-length and
eval-expression-print-level.  When NO-TRUNCATE is
non-nil (interactively, with a prefix argument of zero), however,
there is no such truncation.

If the resulting value is an integer, and CHAR-PRINT-LIMIT is
non-nil (interactively, unless given a non-zero prefix argument)
it will be printed in several additional formats (octal,
hexadecimal, and character).  The character format is used only
if the value is below CHAR-PRINT-LIMIT (interactively, if the
prefix argument is -1 or the value doesn't exceed
eval-expression-print-maximum-character).

Runs the hook eval-expression-minibuffer-setup-hook on entering the
minibuffer.

If eval-expression-debug-on-error is non-nil, which is the default,
this command arranges for all errors to enter the debugger.

As you can see, you can control this behavior either by specifying a prefix argument (with C-u as usual) or by customizing eval-expression-print-maximum-character.

2
  • It's distracting. I just want to see the value I expect.
    – Vinn
    Commented Aug 29, 2022 at 20:16
  • @db48x answered your question - how to control what gets printed. And Emacs already does exactly what you requested: "just return 4". You're confusing what's printed with what's returned from evaluation. And
    – Drew
    Commented Aug 29, 2022 at 21:33

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.