unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Manoj Srivastava <srivasta@ieee.org>
To: emacs-devel@gnu.org
Subject: yanking a killed or saved region with a single mouse gesture
Date: Tue, 15 Apr 2008 00:21:28 -0500	[thread overview]
Message-ID: <87wsmzu207.fsf@anzu.internal.golden-gryphon.com> (raw)

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





             reply	other threads:[~2008-04-15  5:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-15  5:21 Manoj Srivastava [this message]
2008-04-15  5:50 ` yanking a killed or saved region with a single mouse gesture Romain Francoise
2008-04-15  6:01   ` Manoj Srivastava
2008-04-15 15:25 ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wsmzu207.fsf@anzu.internal.golden-gryphon.com \
    --to=srivasta@ieee.org \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).