I am new to Emacs and struggling to learn it.
How to get rid of the line Emacs: command not found?
~/Documents $ eshell-source-file hello.el
Emacs: command not found
Hello World
~/Documents $
I am new to Emacs and struggling to learn it.
How to get rid of the line Emacs: command not found?
~/Documents $ eshell-source-file hello.el
Emacs: command not found
Hello World
~/Documents $
A couple of options:
eshell
can be configured to route specific commands (and subcommands) to the regular terminal. See the documentation for visual commands. Whether or not this is worth the trouble, depends on how much getting a tool to perform in a way it was not really designed to perform is worth.
A good tool for interactive sessions with elisp is interactive elisp mode
which is invoked using M-x ielm
. It provides a full elisp REPL. Files can be loaded using (load name-of-file)
.
The *scratch*
buffer (or any other elisp buffer) is another way of working with elisp files interactively. Using eval-print-last-sexp
will print the results of the sexp
directly in the buffer. Like any Emacs function eval-print-last-sexp
can have any keybinding the user wishes assigned.
Put (just) this in "hello.el":
(prin1 "Hello, world!")
Then from the eshell prompt:
~/temp $ eshell-source-file "hello.el"
Hello, world!
~/temp $
I may be misunderstanding your general intent but from your questions, it seems as though you're trying to "run programs" the way you would run C programs - write a source file hello.c, compile it, run it at the command line, it prints "Hello, world!" and exits, and you get a command prompt again. If you're trying to learn elisp using ielm or eshell, you're working with an interpreter (REPL) - programs are built interactively. So if you want to print "Hello world!" you don't need to make a separate source file; just do this:
~/temp $ (prin1 "hello, world!")
hello, world!
But you can also define functions, apply them, and so on:
~/temp $ (defun f (x) (* x x))
f
~/temp $ (f 17)
289
~/temp $
You don't need to build a separate source file just to load it into eshell: Just build your program line-by-line in eshell or ielm.
As other people have suggested, in emacs, do C-h-i to bring up info, and check out the documentation there. Good luck!