Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Lisp Function Guide?

Tags:

emacs

elisp

I have been using Emacs for more than three years now but it still takes me days to write even small functions in Lisp. I've looked through GNU Emacs Lisp Reference Manual but it's huge and structured completely opposite from JavaDoc, not from functions to descriptions but the other way around.

What will make my life much easier is some sort of small JavaDoc like document with most commonly used Emacs internal functions and they quick description.

    (point) - returns current position in buffer
    (save-excursion (p)) - saves current position in buffer before 
                           executing (p) and restores it afterward.

Does anyone know where I can find something like that?

like image 859
vava Avatar asked Feb 18 '09 02:02

vava


People also ask

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.

How do I Lisp in Emacs?

In a fresh Emacs window, type ESC-x lisp-interaction-mode . That will turn your buffer into a LISP terminal; pressing Ctrl+j will feed the s-expression that your cursor (called "point" in Emacs manuals' jargon) stands right behind to LISP, and will print the result.

Is Emacs functional Lisp?

Emacs Lisp supports multiple programming styles or paradigms, including functional and object-oriented. Emacs Lisp is not a purely functional programming language since side effects are common. Instead, Emacs Lisp is considered an early functional flavored language.

How do I run a function in Emacs?

This function can be run simply. The command [Alt][x] is used to a run a function interactively. Typing [Alt][x] switches the focus in Emacs to the minibuffer - if you then type in a function name it will be executed. To run doodlebug simply type [Alt][x] and then doodlebug.


2 Answers

Have you tried the build-in manual in emacs? Open any lisp buffer (or any buffer in lisp mode), move your point to any function or variable, and hit C-h f (for function) or C-h v (for variable). Emacs will give you a fairly concise description of the function/variable.

For example, the manual content for (save-excursion) is

save-excursion is a special form in `C source code'.
(save-excursion &rest BODY)

Save point, mark, and current buffer; execute BODY; restore those things.
Executes BODY just like `progn'.
The values of point, mark and the current buffer are restored
even in case of abnormal exit (throw or error).
The state of activation of the mark is also restored.

This construct does not save `deactivate-mark', and therefore
functions that change the buffer will still cause deactivation
of the mark at the end of the command.  To prevent that, bind
`deactivate-mark' with `let'.

The good thing also is the build-in manual give you "link" to to the source code of the function and to other functions that might be related, which make it nice to browse around.

Of course you can't learn lisp this way, but for looking up documentation of function this is a nice starter. When you find the build-in manual not understandable (which sometimes does happen), then it's time for you to google the function ;)

like image 54
polyglot Avatar answered Sep 28 '22 02:09

polyglot


This site has some emacs lisp summary information that may be useful: http://xahlee.org/emacs/elisp.html.

In particularly, check out these links on that page: Basic Text-editing Functions, Emacs Lisp Idioms and Batch Text Processing

like image 20
luapyad Avatar answered Sep 28 '22 01:09

luapyad