I am new to Emacs and ELISP
A file (message "Hello World")
saved as hello.el
.
Now, how to run (evaluate) this file on Eshell?
~/Documents $ ....... hello.el
I am new to Emacs and ELISP
A file (message "Hello World")
saved as hello.el
.
Now, how to run (evaluate) this file on Eshell?
~/Documents $ ....... hello.el
The one word you request can also be just a dot .
.
After running that command you get:
~/Documents $ . hello.el
Hello World
~/Documents $
If this is too strange for you you can also use:
~/Documents $ eshell-source-file hello.el
Hello World
~/Documents $
Why that works:
The dot runs the eshell/\.
command which in turn runs eshell-source-file
.
The current eshell sources the file hello.el
, i.e., it interprets its contents as eshell-commands.
Since message
returns the generated message as string and eshell
prints the return values of the executed commands you get "Hello World" printed out in the eshell buffer.
Note that this is not the same as load
ing hello.el
! The content of hello.el
is not interpreted as sequence of elisp forms but as sequence of eshell-commands! eshell
just happens to understand elisp forms.
Be aware that the comment character of eshell is the hash-sign #
and not the semi-colon ;
as for elisp!
Because of the difference in the comment syntax this method will fail for most elisp-files.
Your example file hello.el
is both - a valid elisp file and a valid eshell file.
Note: I wrote this as a separate answer since it is a completely different approach (no elisp but eshell interpretation).
You asked:
A file (message "Hello World") saved as 'hello.el'. Now, how to run (evaluate) this file on Eshell?
~/Documents $ ....... hello.el
I just fill in the command at the dots:
~/Documents $ load hello.el
t
~/Documents $
The reply t
of the load
command says that the file was loaded successfully Type C-h f load
RET to obtain a more detailed description for the load
command.
You find the actual message Hello World
in the *Messages*
buffer.
Note that there are many ways to execute elisp code. I list some of them:
*Messages*
buffer and in the view-area (i.e., the inactive minibuffer).*scratch*
buffer. lisp-interaction
mode is active in *scratch*
. You can input your form and press C-j right behind it. The form is evaluated with eval-print-last-sexp
and the result is printed in *scratch*
at the point where you pressed C-j. If you place point in the form and press C-u M-C-x the lisp form is instrumented for edebug and evaluated. That shows you what is going on step-by-step.hello.el
actually stands for a fully fledged library which you want to test and if this library is in load-path
you can use M-x load-library
RET, input the name of the library, and press RET. This loads (i.e., executes) the library.emacs-lisp
mode for the file buffer. If you visit that buffer there is a menu item Emacs-Lisp
in the menu bar where you find Evaluate Buffer
. Sometimes it is easier to use the find-library
command (M-x find-library
RET) to open a library instead of find-file
(the usual C-x C-f). Another important item of the Emacs-Lisp
menu is Instrument Function for Debugging
.ielm
-- an interactive emacs-lisp repl where you can input your lisp forms and get emacs' answer as response in the same buffer.babel
package from org-mode
offers an interesting way for literate programming. There you can write your documentation and embed the corresponding lisp snippets in source code blocks. These lisp snippets can be evaluated by C-c C-c on the header lines of the source blocks.To run program written in Emacs Lisp from shell like other general languages, use (elisp) Batch Mode:
~ $ cat ~/Documents/hello.el
(message "Hello World")
~ $ emacs --batch --load ~/Documents/hello.el
Hello World
~ $
However, it is just much easier to run Emacs Lisp code within Emacs, see (emacs) Lisp Eval. since Emacs is the IDE of Emacs Lisp.