Re: Is there a way to do this?



Jeffery Zhang <jz87@xxxxxxxxxxx> writes:

I've been having a lot of fun with Lisp, and in an effort to reduce
repetitive typing, I've been wondering if there is a way to do this
with Emacs and Slime. (I never know whether to post this in c.l.l or
in the emacs group, because it involves Lisp).

Say I'm testing out some new function/macro in the REPL, and after
some tweaking I get it working. So I want to copy this thing into
another emacs buffer (presumably a file buffer) to save it for
later. I know emacs can access the lisp symbol table through slime
because I can do completions in other emacs file buffers.

So suppose I have some code
(defun foo ()
'foo)

Is there a way for me to type something like M-x
insert-symbol-definition <enter> foo <enter> and have it paste
(defun foo ()
'foo)
into the file buffer I'm currently editing at my current cursor
position? That would save a lot of typing and save the whole find
function definition, select, copy, switch buffer, paste that I've been
doing.

There's no built-in way to do this, and getting an elegant solution would
require substantial slime hackery, I think. You could probably get a
almost-good-enough solution by writing an elisp function like the
following.

(defun insert-symbol-definition (symbol)
;; switch to the *slime-repl* buffer
;; search the *slime-repl* buffer for "(defun symbol"
;; set the mark, use the sexp motion commands to move to
;; the end of the defun expression, copy the region
;; switch to the target buffer, yank the region
)

The code is left as an exercise...

This would obviously fail for multiple definitions. I suppose you could
search from the end of the buffer on the assumption that the last defun
was the correct one.

To make it even lazier, is there a way for me to save all the symbol
definitions I defined in the current session into a file so that I can
quit and load back all the symbol bindings/definitions with one
command? I would like to be able to easily continue where I left off
without trying to remember where I left off. (this may include loading
certain external files in a specific sequence, and then entering my
own code in a sequence). I would like to be able to do this with one
command each for save and load.

Probably not without some sort of slime hacking. You could probably get
80% of the way there by writing an elisp function or a keyboard macro like
the one above to search the *slime-repl* buffer for any of the various
(defun, defmacro, defvar, ...) commands you are interested in, use the
sexp motion commands to copy the entire definition, and then paste it into
some other buffer.

Another thing, does emacs or Lisp or slime keep track of symbol
definition histories? Suppose I'm trying to write some function foo,
and I got some basic functionality working. Then I proceed to extend
it but screw it up. Instead of pressing M-p a lot looking for my last
definition, or my nth to last definition of foo, I would like to be
able to just do something like M-x search-def-of <enter> foo <enter>
and then press M-p to browse through previous definitions of foo,
pressing <enter> when I find it and rebind foo to that definition.

Lisp definitely does not, and I don't believe slime does either.

-Jeffery
learning emacs so I can be lazy

I think I was lazy first. :)

--
Deon Garrett
Department of Computer Science
The University of Memphis
deong@xxxxxxx
.



Relevant Pages

  • Re: I wish Id never met Lisp
    ... >> use other Lisps with emacs, you might as well stick with SLIME. ... > The last time I used SLIME on ACL it did not ... When any thread hits the debugger we create an *SLDB...* buffer ...
    (comp.lang.lisp)
  • Re: How To Learn Lisp
    ... emacs slime. ... no-cost, whatever Common Lisp ... feel similar regarding packages I used many years ago that to me have never ...
    (comp.lang.lisp)
  • Re: effective emacs
    ... Emacs deals pretty well with proportional fonts in general. ... a few commands, and to eliminate most hotkeys altogether. ... some point of time, hotkey sequences get ingrained, and then they are ... were built on top of a more flexible buffer type. ...
    (comp.emacs)
  • Re: Who is using SBCL on OSX 10.3.2?
    ... I do plan to setup a web page for OS X Lisp stuff. ... I updated SLIME from CVS. ... Darwin Ports has both OpenMCL and CLISP. ... I think the work done by people on Carbon Emacs, ...
    (comp.lang.lisp)
  • Re: Great SWT Program
    ... And the emacs term "buffer" is not identical to this. ... Emacs generally doesn't care about your own standard. ... launching "flashlight" is still carrying a concealed gun. ...
    (comp.lang.java.programmer)