From: Jeffery Zhang
Subject: Is there a way to do this?
Date: 
Message-ID: <e2mtup$8l4$1@ruby.cit.cornell.edu>
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.

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.

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.

-Jeffery
learning emacs so I can be lazy

From: Deon Garrett
Subject: Re: Is there a way to do this?
Date: 
Message-ID: <87bquokfq9.fsf@clapton.csm.astate.edu>
Jeffery Zhang <····@cornell.edu> 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
·····@acm.org
From: Zach Beane
Subject: Re: Is there a way to do this?
Date: 
Message-ID: <m364kwiofd.fsf@unnamed.xach.com>
Jeffery Zhang <····@cornell.edu> writes:

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

Don't work that way. Write your definition in a buffer, and use C-M-x
or C-c C-c to send it to Lisp. When you have it working properly, save
the buffer to a file.

Zach
From: ·············@specastro.com
Subject: Re: Is there a way to do this?
Date: 
Message-ID: <1146080200.963602.82780@j33g2000cwa.googlegroups.com>
Zach Beane wrote:
> Jeffery Zhang <····@cornell.edu> writes:
>
> > 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.
>
> Don't work that way. Write your definition in a buffer, and use C-M-x
> or C-c C-c to send it to Lisp. When you have it working properly, save
> the buffer to a file.
>
> Zach

I second this.  Doing coding / testing in the REPL is harder than
writing it in a buffer.  If you haven't seen Marco Baringer's SLIME
movie yet, I suggest you do, because it illustrates very well the
"flow" of writing / testing / debugging that SLIME best supports.

http://common-lisp.net/movies/slime.mov

Glenn