Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define function in .emacs?

Tags:

emacs

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)
like image 954
why Avatar asked Feb 13 '12 02:02

why


People also ask

How do you enter a function in Emacs?

M-. key will take you to the function definition emacs.

What is defun in 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.

How do you define a function in a Lisp?

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.

What does defun mean in Lisp?

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).


1 Answers

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!

like image 189
db48x Avatar answered Oct 18 '22 11:10

db48x