Rainer Joswig
Hamburg, Germany
Email: joswig@lisp.de

Home > Lisp News > 18. November 2007

On Mouse Copy

Those who edit Lisp code might be interested in 'Mouse Copy'. I have used this functionality the first time in Zmacs on the Symbolics Lisp Machine. Macintosh Common Lisp has a nice version in its example directory (ccl:examples;mouse-copy.lisp). LispWorks has also a Mouse Copy facility - improved in LispWorks 5. Recently I thought about adding it to Clozure CL and wrote down what it should do. Then I had a conversation with Michael Weber (the author of the Redshank extension to GNU Emacs), who saw my post about adding Mouse Copy to Clozure CL. This brought some more thinking about the 'Mouse Copy' functionality. Here are some thoughts:

So, what is 'Mouse Copy'? 'Mouse Copy' allows you to click on Lisp expressions in the editor and have it inserted at the current 'point'. If there is a current selection, this selection will be replaced with the s-expression you have clicked on. If the s-expression is in another buffer, window or a dialog-item, then it will be copied from there without activating the buffer, window or dialog-item. The focus stays where you want to have the S-Expression entered. If you click on several symbols, these symbols will be added at the point and a space between them will be inserted. It also tries to be clever when to add an additional space and when not.

Mouse Copy allows you to reuse parts of your code and write code by clicking on existing code snippets. There is an assumption that, while writing a program, there is a high possibility that there are symbols, lists, numbers, strings, comments already on the screen that you want to reuse.

An example would be a class definitions:
(defclass foo () ((bar :initarg :bar)))
Now you want to write a MAKE-INSTANCE form. Type an open parentheses. Click on another MAKE-INSTANCE on the screen, type ', click on foo, click on :bar and so on.
You get the idea. Often you can click together some parts of your code with existing code that is already visible on the screen. It gets addictive after some time.

So, what should Mouse Copy do?

  • The command should be on Middle-Mouse-Click or something like Command-Mouse-Click.
  • Clicking on something should determine the surrounding s-expression where the click is.
  • Clicking on ", (, ), [, ], {, }, |, #(, #|, |#, or ' will copy the whole expression.
  • Clicking on ; will add the comment to the end of the line
  • Clicking on a number, a character, or a symbol will copy those.
  • Clicking on a Hyperlink (URL) should copy the Hyperlink.
  • The s-expression will be copied and inserted at the current point.
  • If there is a current selection, the selected text will be replaced.
  • If the cursor is behind a word character, then an additional space is inserted before inserting the s-expression.
  • If the cursor is before a word character, then an additional space is inserted after inserting the s-expression.
  • Clicking should not shift focus to another window, buffer or dialog item.
  • Dragging the mouse after pressing the mouse button should have no effect.
  • The s-expression that has been clicked on will be inserted, not the one where the button was released.

Possible advanced functionality:

  • After inserting the s-expression, reindent or reformat the code.
  • When a string is inserted in another string, the inserted string gets escaped.
  • When clicking on a registered symbol, a corresponding template gets inserted (defun, defclass, ...).

Implementation:

  • It should reuse a function that determines the s-expression at a certain point.
  • The object clicked on (window, buffer, dialog-item, ...) should have a method which determines if there is an s-expression at the point.
  • The object clicked on (window, buffer, dialog-item, ...) should have a method which returns the s-expression at the point as text.

Links:
Redshank, GNU Emacs extension for editing Lisp code

Keywords:
EMACS ZMACS

Feedback for this Lisp news item.
Please add to the Number 672 the Number 1 and put the result in the Number input field below.
Name:
Email:

Feedback:



Terms of use: no crawlers, no wget, no site copying, use of pictures and text only with permission. No excessive rss feed checking.

Website by Rainer Joswig, Copyright 2003-2010, feedback to joswig@lisp.de