2

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!

  • 1
    I, for one, have trouble guessing just what you did. If you could be more explicit, giving a step-by-step recipe that starts with 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)? – Drew Jul 29 '15 at 2:13
  • I am following Practical Common Lisp by Seibel and I briefly covered the built in tutorial. – Exodus5656 Jul 29 '15 at 2:51
  • I am just following Practical Common Lisp. I was in REPL and clicked the "save-as" icon and typed "mp3list.lisp" as my file name and saved it. Closed out the program for this morning. I get on this morning and open Emacs, after initializing I tried to use (load "mp3list.lisp") and (load "mp3list") and neither of those worked. So then I selected the "file" and "open-file" then selected the file I was ready to work on, mp3list.lisp. It opened it in another buffer that was not the REPL and I could not figure out how to take the "defun" and all the list I had coded from that buffer to the REPL. – Exodus5656 Jul 29 '15 at 2:59
  • Are you using SLIME? If not, you certainly should be. Please try to clarify the question. Give us clear list of actions you performed, major modes used, how exactly do you start REPL (name of command), how do you load functions and entire files. Also, state clearly what happened and what you expected to happen instead. Also, try to edit tags of the question, mention major mode (or SLIME if you're using it). As it probably has nothing to do with specific version of Emacs, remove emacs24.4 tag while you're at it. – Mark Karpov Jul 29 '15 at 9:28
  • Ok so I downloaded lispbox and it has CCL 1.6, Emacs 23.2, Quicklisp, and Slime. To open the REPL I just click the .bat file "lispbox" and it opens up directly into the REPL. I have slime-repl clozuecl, scratch, Messages, slime-events, and inferior-lisp as buffers. As a back up plan to this, if you guys can't figure out what I did wrong, I downloaded sbcl and notepad++ to give that a shot. Honestly the hardest part of learning Common Lisp is trying to figure out how to use Emacs. I find that humorous. Thanks again for all the help guys! – Exodus5656 Jul 29 '15 at 19:56
1

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 Jul 31 '15 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 Aug 1 '15 at 13:31
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.