0

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 $ 
Drew
  • 75,699
  • 9
  • 109
  • 225
tom_kp
  • 81
  • 4
  • You might want to take a look at this: https://www.gnu.org/software/emacs/manual/html_node/emacs/Initial-Options.html –  Jul 21 '17 at 14:49
  • You tagged the question with `eshell`, but your question says nothing about eshell. Show or describe the relevant parts of your init ifile. – Drew Jul 21 '17 at 15:59
  • Echo-area messages are generally logged in buffer `*Messages*`. You should look there to see them: `C-x b *Messages*`. – Drew Jul 21 '17 at 16:00
  • DoMiNeLa10: Sir, this manual is confusing to me since I am a beginner. – tom_kp Jul 21 '17 at 16:13
  • Drew: Sir, The shell I specified (code above) is eshell. Because, I prefer and like Eshell. I believe, for issue of eshell to work, there should be some customization in .init.el. Please advise me if I am wrong. – tom_kp Jul 21 '17 at 16:17
  • Drew: Sir, Buffer > messages is working. But, I wish to see if eshell area also work. – tom_kp Jul 21 '17 at 16:20
  • 1
    For me, part of learning Emacs has improving my skill in regarding reading the manuals and developing the habit of reading them. I've been at it for several years and think I am getting better, but I still have a long way to go. – ben rudgers Jul 21 '17 at 19:03
  • Possible duplicate: https://emacs.stackexchange.com/questions/34239/command-to-run-eval-hello-world-in-elisp-on-eshell# – ben rudgers Jul 21 '17 at 22:04
  • 1
    Possible duplicate of [Command to Run (Eval) "Hello World" in ELISP on Eshell?](https://emacs.stackexchange.com/questions/34239/command-to-run-eval-hello-world-in-elisp-on-eshell) – ben rudgers Jul 21 '17 at 22:04
  • 1
    Please don't edit questions to ask something different. – ben rudgers Jul 21 '17 at 23:05
  • ;; Comment is creating problem. So how to comment a file to evaluate in eshell? Shall I ask it as a different question? – tom_kp Jul 24 '17 at 01:21
  • First, this question should be reverted back to the original so that the answers make sense. If there is are several questions, it is safe to post each individually. For a question regarding `hello.el` it probably makes sense to include the source code in the body of the question. – ben rudgers Jul 24 '17 at 15:47

2 Answers2

2

A couple of options:

  1. 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.

  2. 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).

  3. 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.

ben rudgers
  • 133
  • 9
  • Hello Ben: I tried all the 3 options: (1) Being a total new person, it is too heavy for me. (2) it is not working (3) (a) It prints the result directly to buffer area, (b) Prints the last message call only. Thanks for your effort. – tom_kp Jul 21 '17 at 20:54
  • @user16438 In what ways is `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. – ben rudgers Jul 21 '17 at 21:30
  • Method (2): I did: `M-x ielm` It took to ELISP> Then I entered **ELISP>** `load hello.el` it displays `*** IELM error *** More than one sexp in input` – tom_kp Jul 21 '17 at 21:57
  • @user16438 *ielm* requires elisp code. So the it needs to be `(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 http://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. – ben rudgers Jul 21 '17 at 22:01
  • @user16438 see this question for a more direct solution https://emacs.stackexchange.com/questions/34239/command-to-run-eval-hello-world-in-elisp-on-eshell# – ben rudgers Jul 21 '17 at 22:05
  • This works!!! but there is a small issue. it prints like this: **Emacs: command not found** Hello World How can I get rid of the first line? – tom_kp Jul 21 '17 at 22:20
  • @user16438 I don't know what you mean by 'this works'. – ben rudgers Jul 21 '17 at 22:25
  • It prints: `~/Documents $ eshell-source-file hello.el` **Emacs: command not found** Hello World! `~/Documents $` How can I get rid of the first line **Emacs: command not found**? – tom_kp Jul 21 '17 at 22:32
  • @user16438 I suspect that your source code in `hello.el` might not be valid elisp. Again, I suggest working through tutorials and/or reading the manuals. – ben rudgers Jul 21 '17 at 22:36
2

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!

bikenaga
  • 36
  • 2