BlueMoonMelinda · 2022-10-26 12:37
I am following a beginner elisp tutorial. What did I do wrong?
(setq os "Gentoo")
(defun fetchOS () (insert "os: " os))
(fetchOS)
Debugger entered--Lisp error: (void-function fetchOS)
(fetchOS)
(progn (fetchOS))
elisp--eval-last-sexp(nil)
eval-last-sexp(nil)
funcall-interactively(eval-last-sexp nil)
command-execute(eval-last-sexp record)
execute-extended-command(nil "eval-last-sexp" nil)
funcall-interactively(execute-extended-command nil "eval-last-sexp" nil)
command-execute(execute-extended-command)
twleo · 2022-10-26 13:19
need to add `(interactive)` in your `defun` if you want to execute it by something like `M-x`
globalcandyamnesia · 2022-10-26 13:24
eval-last-sexp only evaluates, well, the last sexp. You have three s-expressions in your code, so you will need to call eval-last-sexp with the cursor behind each of them. There's also eval-buffer which will evaluate all expressions in the buffer.
andyjda · 2022-10-26 13:54
This is true but from the stack trace it doesn’t look like this was the problem. The function was called using eval-last-sexp, not with M-x
twleo · 2022-10-26 14:32
Yeah, it's just my guess because I saw `funcall-interactively` in the trace.
BlueMoonMelinda · 2022-10-26 14:50
eval-buffer fixed it, thank you very much!
andyjda · 2022-10-26 14:52
Yeah good point. I just wanted to clarify since OP is a beginner.
Functions need to be (interactive) in order to be called interactively (ie, using M-x). But an interactive function can then call any non-interactive function without issue.
From the stack trace, it looks like “eval-last-sexp” was called interactively, and then that function tried to evaluate (fetchOS).
As another comment pointed out, the issue is probably that the definition of fetchOS was never evaluated.