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 $
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityPut (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!
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.
ielm
not working? I can see why configuring eshell using visual commands is to heavy for a new user because eshell
is not really designed to do what you are trying to do anyway. For me, part of being a new user has been learning new ways of doing things and usually those new ways of doing things is not the way "I want". For me, wanting to do things in a 'bad' or 'wrong' way is part of being a new user. As I said, I've spent years learning Emacs and all that learning has been learning to do things in new ways.
Jul 21, 2017 at 21:30
M-x ielm
It took to ELISP> Then I entered ELISP> load hello.el
it displays *** IELM error *** More than one sexp in input
(load "hello.el")
or a more precise path if the file hello.el is not in the current working directory. For example, entering (+ 3 4)
at the ielm prompt will return the value 7
. For what it is worth, my favorite elisp tutorial is dantorop.info/project/emacs-animation and I recommend working through a few tutorials because it is worth the effort for a tool that will be used for many years.
Jul 21, 2017 at 22:01
eshell
, but your question says nothing about eshell. Show or describe the relevant parts of your init ifile.