Reputation: 686
I am learning how to program in emacs lisp. I thought I would write a simple function that prints a function definition to the messages buffer. This works fine:
(let (
(fDefAsString (symbol-function 'scroll-down))
)
(message "%s" fDefAsString)
(switch-to-buffer-other-frame "*Messages*"))
but I wanted this to be a function that could take an argument, the argument being the name of the function whose definition I want to see. So I tried this:
(defun message-function-definition (nameOfFunction)
(let (
(fDefAsString (symbol-function 'nameOfFunction))
)
(message "%s" fDefAsString)
(switch-to-buffer-other-frame "*Messages*")))
and then I wrote this:
(message-function-definition 'scroll-down)
Then I ran "eval-buffer".
I keep getting this error:
Debugger entered--Lisp error: (void-function nameOfFunction) symbol-function(nameOfFunction) (let ((fDefAsString ...)) (message "%s" fDefAsString) (switch-to-buffer-other-frame "Messages")) message-function-definition(scroll-down) eval((message-function-definition (quote scroll-down))) eval-last-sexp-1(nil) eval-last-sexp(nil) call-interactively(eval-last-sexp nil nil) recursive-edit() byte-code("\306 @\307=\203!
I've tried quoting, unquoting, and I've tried to use "nameOfFunction" but I can not get this to work. What am I doing wrong?
Upvotes: 1
Views: 303
Reputation: 17707
Did you try unquoting? This works for me:
(defun message-function-definition (nameOfFunction)
(let ((fDefAsString (symbol-function nameOfFunction)))
(message "%s" fDefAsString)
(switch-to-buffer-other-frame "*Messages*")))
Some hints:
Your code is not indented correctly. If you select the region and re-indent with tab, it'll be easier to read.
You should spend a couple of hours working through the "Emacs Lisp Intro", you will have a much better idea of how things work in Emacs-lisp, rather than figuring it all by asking one question at a time on StackOverflow.
symbol-function
is not designed to show a human readable definition of
the function. In most cases you won't really see anything useful.
Try this:
(find-function-other-window 'scroll-down)
Upvotes: 1