I'd like my emacs v25.3.1 running on Mac OS X to have a mouse middle button functionality that copies what you mouse middle on to the insertion point in your buffer. This is great when writing code and you want to quickly grab a section of code already in your file by pointing with your mouse. This is the way the old Lisp Machines worked with Zmacs and the ZWEI editor. You click a point and it copies an sexp you point to or you click drag to specify an exact range of characters to copy, or you click at end of line to copy a whole line.

I've had doing this on my own, but it always breaks going to a new version of emacs, so it would be nice if there was built-in code to do this or an add-on that is supported.

I found Mouse Copy but that project appears untouched since 2012.

2 Answers 2


Set option mouse-yank-at-point to non-nil. Then clicking mouse-2 yanks at point instead of at the mouse-pointer (click) position. See also:

  • (emacs) Mouse Commands:

    If you change the variable mouse-yank-at-point to a non-nil value, mouse-2 does not move point; it inserts the text at point, regardless of where you clicked or even which of the frame’s windows you clicked on. This variable affects both mouse-yank-primary and mouse-yank-at-click.

  • (emacs) Secondary Selection: mouse-yank-at-point non-nil means M-mouse-2 yanks at point.

  • Sounds like you have to first fill yank buffer with the text to yank, the Zwei approach does this in one click to copy what you point at and yank it at insertion point.
    – WilliamKF
    Jan 30, 2018 at 0:32
  • You would need to write a command that combines that with what mouse-yank-at-click does. AFAIK, nothing in vanilla Emacs defines "what you point at", but you could certainly do so. Perhaps someone here will do that for you, if you define "what you point at". (It could so something like what thing-at-point does, but using the mouse-pointer position rather than point.)
    – Drew
    Jan 30, 2018 at 1:47
  • By point, I meant, what you click on is copied to insertion point.
    – WilliamKF
    Jan 30, 2018 at 16:08

Does anyone remember C-mouse-middle in Lisp Machine Emacs (Zmacs/ZWEI)? Once I'd used it, I really wanted it, and a generous Emacs wizard helped me create the following back in the day.

;;; Remember C-mouse-middle in Lisp Machine Emacs (ZWEI)?

(require 'mouse-copy)

(defun mouse-copy-sexp (event)
  "Copy expression after clicked point to current point."
  (interactive "e")
  (mouse-minibuffer-check event)
  (let* ((posn (event-end event))
     (source-buffer (window-buffer (posn-window posn)))
      (set-buffer source-buffer)
      (goto-char (posn-point posn))
      (let ((end (point)))
    (setq sexp (buffer-substring (point) end))))
    (let ((after (following-char))
      (before (preceding-char)))
      (if (not (or (bolp)
           (char-equal (char-syntax before) ?\ )
           (char-equal (char-syntax before) ?\()
           (char-equal (char-syntax before) ?\:)
           (char-equal (char-syntax before) ?\')))
      (insert " "))
      (insert sexp)  
      (if (not (or (eolp)
           (char-equal (char-syntax after) ?\ )
           (char-equal (char-syntax after) ?\))))
      (insert " ")))))

(global-set-key [C-S-mouse-1]   'mouse-copy-sexp)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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