I define one function in my .emacs, I want to activate ECB and goto to directory when I enter f12, but it does not work
(defun my-toggle-ecb ()
(ecb-activate)
(ecb-goto-window-directories)
)
(global-set-key (kbd "<f12>") 'my-toggle-ecb)
M-. key will take you to the function definition emacs.
defun is the usual way to define new Lisp functions. It defines the symbol name as a function with argument list args (see Features of Argument Lists) and body forms given by body . Neither name nor args should be quoted.
Use defun to define your own functions in LISP. Defun requires you to provide three things. The first is the name of the function, the second is a list of parameters for the function, and the third is the body of the function -- i.e. LISP instructions that tell the interpreter what to do when the function is called.
In Lisp, a symbol such as mark-whole-buffer has code attached to it that tells the computer what to do when the function is called. This code is called the function definition and is created by evaluating a Lisp expression that starts with the symbol defun (which is an abbreviation for define function).
Yea, that's one of Emacs' odder quirks. Unless you declare that a function is interactive, there's no way way to call it directly. Luckily it's easy:
(defun my-toggle-ecb ()
(interactive)
(ecb-activate)
(ecb-goto-window-directories))
Your keybinding remains the same. Have fun!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With