Alright I apologize if this has been asked, but I cannot seem to find this problem through searching. I am trying to figure out how to work on code in Emacs and when I come back open it again to edit the code. I was working with Emacs in the REPL learning Common Lisp and I used the "save as" feature and saved my work. I come to it this morning and try to open it to finish up on it and when I load the file it opens either as read only or it "kills" the REPL and doesn't let me use the functions that I coded originally. When the file is loaded I can't compile it to use in the REPL and it seems to not want to work in the REPL when I try to copy.. I am new to Emacs and I am needing some help figuring out what I did wrong so I don't do this again. Til now I have only coded a few lines and just been starting from scratch and copying what is loaded in the file and completing my exercises, but that limits productivity. I am spending more time trying to figure out how to use Emacs than I am learning Common Lisp. I am not sure what I did wrong, but if there are any Emacs gurus out there that could help me out I would greatly appreciate it! Thank you in advance!
2 Answers
There are two other methods of interacting with Common Lisp, besides SLIME. Although they both use SLIME as a back end.
Org mode
To make org-babel understand CL, you need to add this to your config (after you've configured SLIME):
(require 'ob-lisp)
(org-babel-do-load-languages
'org-babel-load-languages
'((lisp . t)))
Here's an example Org content:
* CL is a LISP-2
So you need to quote the ='+= function.
#+begin_src lisp
(mapcar '+ '(1 2 3) '(1 2 3))
#+end_src
#+RESULTS:
| 2 | 4 | 6 |
When you navigate to a source block, you can edit it with C-c ' in its native lisp-mode.
You can evaluate it with C-c C-c, once SLIME was started.
lispy
You can install lispy from the
package manager. Then open e.g. test.lisp file, navigate to an open
or close paren and press e. If SLIME isn't running yet, it
will automatically start and evaluate the current expression. The
result will be shown in the Echo Area.
If you'd like to see the result in the buffer, press E instead of e. You can also insert the result as a comment by pressing 2e.
You can think of pressing e as:
- copying the expression from source buffer to the kill ring
- switching to the SLIME REPL
- inserting the expression
- switching back to the source buffer
-
So in the end after using REPL how do I save the code I have written and use it again/edit the code when I am finished? I ask this, because I can barely navigate Emacs.Exodus5656– Exodus56562015-07-31 23:43:42 +00:00Commented Jul 31, 2015 at 23:43
-
The code is always in a file. The methods that I described allow you to send a portion of a file to a REPL. Just save the file normally.abo-abo– abo-abo2015-08-01 13:31:09 +00:00Commented Aug 1, 2015 at 13:31
I figured out what I wasn't doing. So to save my source code I have to create a file via C-x C-f and then input the source code into that buffer. Then when I come back to emacs I can open the file and edit the code. At least this worked for me. Thanks for the input.
emacs -Q(no init file), that might help people help you more. I'm guessing that you are following some kind of tutorial - perhaps you are reading the manual An Introduction to Programming in Emacs Lisp, which is included with Emacs (C-h i)?emacs24.4tag while you're at it.