├── LICENSE ├── README └── mouse-copy.el /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, Vladimir Sedach , Stas Boukarev 2 | 3 | 4 | Permission to use, copy, modify, and/or distribute this software for 5 | any purpose with or without fee is hereby granted, provided that the 6 | above copyright notice and this permission notice appear in all 7 | copies. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 10 | WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 11 | WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 12 | AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 13 | DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 14 | PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 15 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 16 | PERFORMANCE OF THIS SOFTWARE. -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | mouse-copy is an Emacs minor mode that lets you copy/yank an s-exp 2 | under the mouse cursor to point by holding down a modifier key (C/C-M) 3 | and left-clicking. It works across windows and is frequently faster 4 | than re-positioning the pointer to select and copy a region. 5 | 6 | mouse-copy is inspired by similar functionality in the Lisp Machine 7 | ZWEI/Zmacs and the Macintosh Common Lisp editors. 8 | 9 | mouse-copy is licensed under the ISC (simplified BSD) license (see 10 | LICENSE file), and is developed by Vladimir Sedach 11 | and Stas Boukarev 12 | 13 | To use mouse-copy, add something like this to your .emacs: 14 | (load "~/.emacs.d/mouse-copy/mouse-copy.el") 15 | (add-hook 'lisp-mode-hook (lambda () (mouse-copy-mode t))) 16 | (add-hook 'slime-repl-mode-hook (lambda () (mouse-copy-mode t))) 17 | (setq mouse-yank-at-point t) ;; for secondary selection 18 | 19 | add-hook for whatever other modes you want to use with mouse-copy. 20 | 21 | -------------------------------------------------------------------------------- /mouse-copy.el: -------------------------------------------------------------------------------- 1 | ;;; mouse-copy.el --- easily copy/yank sexps under the mouse cursor 2 | 3 | ;; Copyright (c) 2011, Vladimir Sedach , Stas Boukarev 4 | ;; Keywords: lisp 5 | 6 | ;; Permission to use, copy, modify, and/or distribute this software for 7 | ;; any purpose with or without fee is hereby granted, provided that the 8 | ;; above copyright notice and this permission notice appear in all 9 | ;; copies. 10 | 11 | ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 12 | ;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 13 | ;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 14 | ;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 15 | ;; DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 16 | ;; PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 17 | ;; TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 18 | ;; PERFORMANCE OF THIS SOFTWARE. 19 | 20 | ;;; Commentary: 21 | 22 | ;; Adapted from http://www.mail-archive.com/gnu-emacs-sources@gnu.org/msg00393.html 23 | ;; and http://www.foldr.org/~michaelw/projects/redshank/redshank.el 24 | 25 | ;;; Code: 26 | 27 | (require 'thingatpt) 28 | 29 | (defvar mouse-mode-map (make-sparse-keymap)) 30 | 31 | (define-minor-mode mouse-copy-mode 32 | "Minor mode for copying and moving text using a mouse 33 | \\{mouse-mode-map}" 34 | :global t 35 | :keymap mouse-mode-map) 36 | 37 | (define-key mouse-mode-map [C-mouse-1] 'ignore) 38 | (define-key mouse-mode-map [C-drag-mouse-1] 'ignore) 39 | (define-key mouse-mode-map [C-down-mouse-1] 'mouse-insert-sexp-at-point) 40 | (define-key mouse-mode-map [C-M-mouse-1] 'ignore) 41 | (define-key mouse-mode-map [C-M-drag-mouse-1] 'ignore) 42 | (define-key mouse-mode-map [C-M-down-mouse-1] 'mouse-yank-sexp-to-point) 43 | 44 | (defun mouse-copy-sexp-at-mouse (event thunk) 45 | (let ((position (event-start event))) 46 | (with-selected-window (posn-window position) 47 | (save-excursion 48 | (goto-char (posn-point position)) 49 | (let ((sexp (thing-at-point 'sexp))) 50 | (funcall thunk sexp)))))) 51 | 52 | (defun mouse-copy-do-at-point (event thunk) 53 | (let ((sexp (mouse-copy-sexp-at-mouse event thunk))) 54 | (unless sexp 55 | (error "Mouse not at a sexp")) 56 | (when (and delete-selection-mode 57 | (use-region-p)) 58 | (delete-region (region-beginning) (region-end))) 59 | (unless (or (bolp) 60 | (and (minibufferp) 61 | (= (point) (minibuffer-prompt-end))) 62 | (save-excursion 63 | (backward-char) 64 | (looking-at "\\s-\\|\\s\("))) 65 | (insert " ")) 66 | (insert sexp) 67 | (unless (or (eolp) 68 | (and (minibufferp) 69 | (= (point) (minibuffer-prompt-end))) 70 | (looking-at "\\s-\\|\\s\)")) 71 | (insert " ")))) 72 | 73 | (defun mouse-insert-sexp-at-point (start-event) 74 | "Insert the sexp under the mouse cursor at point. 75 | This command must be bound to a mouse event." 76 | (interactive "*e") 77 | (mouse-copy-do-at-point start-event (lambda (sexp) sexp))) 78 | 79 | (defun mouse-copy-delete-sexp () 80 | (let ((point (point))) 81 | (forward-sexp) 82 | (delete-region point (point)))) 83 | 84 | (defun mouse-yank-sexp-to-point (start-event) 85 | "Yank the sexp under the mouse cursor to point. 86 | This command must be bound to a mouse event." 87 | (interactive "*e") 88 | (mouse-copy-do-at-point start-event 89 | (lambda (sexp) 90 | (beginning-of-thing 'sexp) 91 | (mouse-copy-delete-sexp) 92 | sexp))) 93 | 94 | (provide 'mouse-copy) 95 | ;;; mouse-copy.el ends here 96 | --------------------------------------------------------------------------------