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

* Re: yanking a killed or saved region with a single mouse gesture
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Romain Francoise @ 2008-04-15  5:50 UTC (permalink / raw)
  To: emacs-devel

Manoj Srivastava <srivasta@ieee.org> writes:

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

In which way is this better than the default mouse commands (Mouse-1
at start of region, single or double Mouse-3 click at the end)?





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

* Re: yanking a killed or saved region with a single mouse gesture
  2008-04-15  5:50 ` Romain Francoise
@ 2008-04-15  6:01   ` Manoj Srivastava
  0 siblings, 0 replies; 4+ messages in thread
From: Manoj Srivastava @ 2008-04-15  6:01 UTC (permalink / raw)
  To: emacs-devel

On Tue, 15 Apr 2008 07:50:36 +0200, Romain Francoise <romain@orebokech.com> said: 

> Manoj Srivastava <srivasta@ieee.org> writes:
>> So mouse 2 saves, mouse 3 yanks the saved region, and holding down
>> the shift key kills instead of saves.

> In which way is this better than the default mouse commands (Mouse-1
> at start of region, single or double Mouse-3 click at the end)?

        Mouse 1 sets the point, or sets a region. The gestures do not
 reset point at all; they take a section of text at some other point,
 and optionally yank it in. Consider the following (I am showing the
 lines next to each other, but they can be in different buffers)

--8<---------------cut here---------------start------------->8---
 blah blah blah 1 XXXX XXXX XXXX XXXX 2 yadda yadda yadda
 some more text p and more yet.
--8<---------------cut here---------------end--------------->8---

        The point is at p; and I hold down shit, and drag mouse 3 from
 the character 1 over to the character 2. What I get is:
--8<---------------cut here---------------start------------->8---
 blah blah blah 12 yadda yadda yadda
 some more text p XXXX XXXX XXXX XXXX  and more yet.
--8<---------------cut here---------------end--------------->8---

        Without the shift, it copies: so I get:
--8<---------------cut here---------------start------------->8---
 blah blah blah 1 XXXX XXXX XXXX XXXX 2 yadda yadda yadda
 some more text p XXXX XXXX XXXX XXXX  and more yet.
--8<---------------cut here---------------end--------------->8---

        The point does not change, no mark was set. This single gesture
 with the mouse is faster than setting point with mouse 1, setting end
 point with mouse 3, optionally deleting with mouse 3, finding the spot
 where I need to yank the text to, and hitting mouse 2.

        I often use  this with different windows in the same frame.

        manoj
-- 
new, adj.: Different color from previous model.
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

* Re: yanking a killed or saved region with a single mouse gesture
  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 15:25 ` Stefan Monnier
  1 sibling, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2008-04-15 15:25 UTC (permalink / raw)
  To: emacs-devel

>         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.

Have you tried mouse-copy.el?


        Stefan




^ 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).