unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* yanking a killed or saved region with a single mouse gesture
@ 2008-04-15  5:21 Manoj Srivastava
  2008-04-15  5:50 ` Romain Francoise
  2008-04-15 15:25 ` Stefan Monnier
  0 siblings, 2 replies; 4+ messages in thread
From: Manoj Srivastava @ 2008-04-15  5:21 UTC (permalink / raw)
  To: emacs-devel

Hi,

        I've the years, I have grown  fond of the ability to save  (or
 kill) a region, and optionally yank it, using a single mouse gesture.
 I think this used to be in Emacs a long time ago, and I have retained
 he feature for personal use.

--8<---------------cut here---------------start------------->8---
 (define-key global-map [drag-mouse-2]   'mouse-save-drag)
 (define-key global-map [drag-mouse-3]   'mouse-yank-drag)
 (define-key global-map [S-drag-mouse-2] 'mouse-kill-drag)
 (define-key global-map [S-drag-mouse-3] 'mouse-kill-and-yank-drag)
--8<---------------cut here---------------end--------------->8---

        So mouse 2 saves, mouse 3 yanks the saved region, and holding
 down the shift key kills instead of saves.

        Would this be something that could be added back into emacs? Or
 is this too esoteric?

        manoj

(defun mouse-yank-drag (click arg)
  "Yank the region the mouse was dragged at at point"
  (interactive "e\nP")
  (save-excursion
    (let* ((start-posn (posn-point (event-start click)))
           (end-posn (posn-point (event-end click)))
           (start-window (posn-window (event-start click)))
           )
      (save-window-excursion
       (select-window start-window)
       (kill-new (buffer-substring start-posn end-posn))
       )))
  (yank arg))


(defun mouse-save-drag (click)
  "kill the region the mouse was dragged at at point"
  (interactive "e")
  (save-excursion
    (let* ((start-posn (posn-point (event-start click)))
           (end-posn (posn-point (event-end click)))
           (start-window (posn-window (event-start click)))
           )
      (save-window-excursion
       (select-window start-window)
       (kill-new (buffer-substring start-posn end-posn))
       )))
  )

(defun mouse-kill-drag (click)
  "kill the region the mouse was dragged at at point"
  (interactive "e")
  (save-excursion
    (let* ((start-posn (posn-point (event-start click)))
           (end-posn (posn-point (event-end click)))
           (start-window (posn-window (event-start click)))
           )
      (save-window-excursion
        (select-window start-window)
        (kill-new (buffer-substring start-posn end-posn))
        (delete-region   start-posn end-posn)
        ))))

(defun mouse-kill-and-yank-drag (click arg)
  "kill the region the mouse was dragged at at point"
  (interactive "e\nP")
  (save-excursion
    (let* ((start-posn (posn-point (event-start click)))
           (end-posn (posn-point (event-end click)))
           (start-window (posn-window (event-start click)))
           )
      (save-window-excursion
       (select-window start-window)
       (kill-new (buffer-substring start-posn end-posn))
       (delete-region   start-posn end-posn)
       )))
  (yank arg))


-- 
Thus spake the master programmer: "Time for you to leave."  -- Geoffrey
James, "The Tao of Programming"
Manoj Srivastava <srivasta@acm.org> <http://www.golden-gryphon.com/>  
1024D/BF24424C print 4966 F272 D093 B493 410B  924B 21BA DABB BF24 424C





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-04-15 15:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-15  5:21 yanking a killed or saved region with a single mouse gesture Manoj Srivastava
2008-04-15  5:50 ` Romain Francoise
2008-04-15  6:01   ` Manoj Srivastava
2008-04-15 15:25 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).