January 16, 2011

Mouse-copy for Emacs

Zmacs, MCL's Fred, and the Lispworks editor all contain a very nice time-saving feature absent from Emacs called mouse-copy. Rainer Joswig wrote a good description of mouse-copy; in brief it can be summarized as "hold down Ctrl and click on an s-exp to copy it to the current point."

I first found out about mouse copy from working with Jedi, JazzScheme's IDE, and ever since I've wanted it for my Emacs setup.

Michael Weber's redshank extensions to Paredit/SLIME include mouse-copy, but it depends on buffers being in Paredit mode.

Fortunately there's a simple way to get generic mouse-copy in Emacs. Unfortunately it doesn't do the right thing when it comes to spaces. This is easy to fix by borrowing a couple of lines from redshank. This is the mouse-copy I use right now, and it seems to work pretty well.

As you might suspect there's more time-saving things you can do with the mouse. For example, in redshank M-S-mouse-1 generates a skeleton for a make-instance when you click on a defclass definition. Looking at TI Explorer ZWEI sources, Lisp Machines had an entire modifier-key-and-mouse-button-chord convention that really made s-exp manipulation easy and direct. It would be nice to have something like that for Emacs.

If you have tips on better ways of using Emacs for editing Lisp, consider sharing them on CLiki's Emacs tips page.

9 comments:

Anonymous said...

Are you aware of M-double-mouse-1 and M-mouse-2 for copying and pasting a balanced expression to the secondary selection without moving point?

uuh

Vladimir Sedach said...

M-mouse-2 does move the current point. It's not much more convenient than using regular selection. This selects and copies with a single click.

Anonymous said...

Oh, I forgot to mention that I always have mouse-yank-at-point set.

uuh

Vladimir Sedach said...

That's a good tip, I'm going to start using it from now on. But using secondary selection that way is still 3 clicks vs 1, and more importantly it doesn't insert spaces for you.

synchromesh said...

Hi, can you expand on the "but" in "but it depends on buffers being in Paredit mode"? By which I mean, surely everyone uses Paredit mode anyway, so how is this a problem?

Cheers,

John :^P

Vladimir Sedach said...

The code that determines what to select for copying uses paredit functions. I don't know how well that works with buffers that aren't in Paredit mode (for example could be handy for copying things from documentation or porting code from other languages).

Anonymous said...

Hmmm not sure what the difference between our installs is, but M-S-mouse-1 on a defclass for me simply brings up the defclass-generator. Not nearly as useful.

Chris2048 said...

added a link to you on emacswiki (MouseCopy).

Vladimir Sedach said...

That's probably because I only read the source. I never actually tried running redshank.