When I write a function in emacs, how can I try it ?
Can I open some window (buffer) for evaluating ?
select the text, and press Alt+x eval-region. Then, you can call it by
Alt+x ‹function name›. (Alt+x is shortcut for execute-extended-
if your function does not have the “(interactive)” clause, then it
won't be visible to user thru execute-extended-command , but you can
still call the function by other fuction.
• Emacs Lisp Basics
You can use the *scratch* buffer, which is in lisp-interactive-mode by
default. You can also use M-: to type an expression in the minibuffer
and evaluate it.
Barry Margolin, bar...@alum.mit.edu
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
Look at the *scratch* buffer. It defaults to a mode called 'Lisp
Interaction', where you can enter forms and then evaluate them with C-j.
mouse, n: A device for pointing at the xterm in which you want to type.
There is also a repl :
M-x ielm RET
"Haris Bogdanović" <fbogd...@xnet.hr> wrote in message
Emacs questions are better asked on news:gnu.emacs.help
Type C-x C-e with the point after the function source to enter it into
the emacs lisp image.
They type (your-function your-argument) C-x C-e to evaluate it.
If you type C-y C-x C-e instead, the result of the expression will be
inserted in the buffer at the point.
(+ 1 2) C-u C-x C-e --> 3
(defun f (x) (if (< x 1) 1 (* x (f (1- x))))) C-x C-e
(f 9) C-u C-x C-e --> 362880
You don't need to compile your emacs lisp functions to use them. At
least not until they're debugged.
>> Can I open some window (buffer) for evaluating ?
Yes. M-x ielm RET gives you an interactive REPL to emacs lisp.
> When I try to compile function it gives me "make -k" command, I press enter
> and I get error message.
> Does emacs have lisp interpreter or I have to install it separatelly ?
You can get information about what an emacs command purpose is with:
C-h f compile RET
As you can see, compile has nothing to do with compiling emacs lisp
It could be used to compile an emacs lisp source, if you defined a
Makefile or used the emacs command to do so. For example, you could
emacs --eval '(byte-compile-file "source.el")'
to compile source.el into source.elc with emacs.
But we prefer to do it more interactively in lisp:
To compile a function: (byte-compile 'your-function) C-x C-e
To compile an emacs lisp source file: M-x byte-compile-file RET source.el RET
To load an emacs lisp source: M-x load-file RET source.el RET
To evaluate a while buffer: M-x eval-buffer RET
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
Q: What is the most annoying thing on usenet and in e-mail?
----------> http://www.netmeister.org/news/learn2quote.html <-----------
---> http://homepage.ntlworld.com/g.mccaughan/g/remarks/uquote.html <---
__Pascal Bourguignon__ http://www.informatimago.com/
Please feel free to post emacs lisp question in comp.lang.lisp.
There are some Common Lisp fanatics, who often sneer emacs lisp (and
any other lisps) and they often try to drive any non Common Lisp
questions outside of comp.lang.lisp.
When I try to compile function it gives me "make -k"
command, I press enter and I get error message. Does
emacs have lisp interpreter or I have to install it
Lisp says, L'emacs c'est moi. And Emacs says, L'isp c'est
moi. More or less. At any rate, Emacs is a text editor
first and foremost, so its model of user interaction is
based on that. If you do want an interactive repl in the
same sense as in a scheme or Common Lisp you can, as Andreas
mentioned, do M-x ielm RET and that will give you a repl.
But typically in Emacs you are in an editing buffer so you
would just write your lisp form, and then with point after
the end-parenthesis that closes the form you want to
evaluate, do C-x C-e and that form will be evaluated,
whatever side-effects it produces will be produced, and
typically the return value will be displayed in the
mini-buffer. If you don't like the result, you just edit
the form, and do it again. You don't have to write out the
whole form again at a repl, and once you have produced a
bunch of those forms that all work together the way you
want, they're already there in the buffer, roughly in the
form that you can directly save as a file and load later.
M-x compile is designed for people writing code in C and
other languages that use external tools like `make' to build
an executable. If you run it and the current directory does
not contain a Makefile it will, not finding it, complain.
You may be looking for `byte-compile' which you can use in
lisp to compile a function. Also you can use
`byte-compile-file' interactively to byte-compile a file;
there is a way to use that in dired, as well, which is nice
when you have a lot of files you want to byte-compile. I
have never used `byte-compile' for a function, but I know
that byte-compiling a file produces a file (a .elc file)
that contains object code (or whatever it's called in Emacs
lisp) but that does not load those expressions into the lisp
image. So other useful functions are `load-file' which
actually loads the .el or .elc file into the lisp, and
`load-library' which is similar (see the docs). Finally, if
you are looking at a buffer full of lisp forms you can use
`eval-buffer' to eval all of it at once, or `eval-region'.
I hope that's helpful. Sorry to be so prolix, but this is
something that I found very confusing myself when I was
starting with Emacs, so I thought I'd try to give a full-ish
(hopefully not to be confused with fool-ish) answer.