* allow mouse-save-then-kill customization like mouse-drag-copy-region?
@ 2008-02-13 2:09 David De La Harpe Golden
0 siblings, 0 replies; only message in thread
From: David De La Harpe Golden @ 2008-02-13 2:09 UTC (permalink / raw)
To: Emacs-Devel
[-- Attachment #1: Type: text/plain, Size: 1115 bytes --]
This is independent from anything else in "Improved X selections" so
I'm splitting it out - it just adds a customization
mouse-save-then-kill-copy-region that is pretty similar to
mouse-drag-copy-region, only for mouse-save-then-kill (mouse-3).
Attached patch implements desired feature.
mouse-save-then-kill is useful for (but not only for) its
region-adjusting features, since it allows the point and mark of an
active region to be moved separately with the mouse using its "who's
closest" algo, particularly handy when the point or mark is offscreen.
But, like mouse-1 dragging with mouse-drag-copy-region non-nil, it
insta-saves. It'd be nice if one could have mouse-1 and mouse-3
behaviour that fitted in together when mouse-drag-copy-region is nil.
The customization allows one to choose whether mouse-save-then-kill
has its original behaviour (adjusting the region and insta-saving, the
default), only region-adjusting, or a "double" option that "saves"
save-then-kill functionality, so you can double/triple click instead
of single/double click for save/kill, but single clicks just adjust
the region.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: cust-mouse-save-then-kill.diff --]
[-- Type: text/x-diff; name=cust-mouse-save-then-kill.diff, Size: 7921 bytes --]
Index: lisp/mouse.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/mouse.el,v
retrieving revision 1.327
diff -u -d -r1.327 mouse.el
--- lisp/mouse.el 7 Feb 2008 06:20:25 -0000 1.327
+++ lisp/mouse.el 13 Feb 2008 01:53:32 -0000
@@ -1394,6 +1394,19 @@
(kill-ring-save (point) (mark t)))
(mouse-show-mark))
+(defcustom mouse-save-then-kill-copy-region t
+ "Says how many clicks are needed for \\[mouse-save-then-kill] to save then kill.
+
+Never: only adjust region, never kill.
+Single: adjust region and save on single click, kill on second click.
+Double: adjust region on first click, save on second, kill on third."
+
+:type '(choice (const :tag "Never" nil)
+ (const :tag "Single" t)
+ (const :tag "Double" :double))
+:group 'mouse
+:version "23.1")
+
;;; This function used to delete the text between point and the mouse
;;; whenever it was equal to the front of the kill ring, but some
;;; people found that confusing.
@@ -1437,7 +1450,14 @@
(undo-boundary))
(defun mouse-save-then-kill (click)
- "Save text to point in kill ring; the second time, kill the text.
+ "Depending on click count, adjust region, save to kill ring, or kill.
+
+Behaviour customized by `mouse-save-then-kill-copy-region'. If that
+is nil, clicking merely adjusts the region. If :double, single
+clicking adjusts the region, double clicking saves text to kill
+ring, triple clicking kills the text. If t, single clicking saves
+text to kill ring, double clicking kills.
+
If the text between point and the mouse is the same as what's
at the front of the kill ring, this deletes the text.
Otherwise, it adds the text to the kill ring, like \\[kill-ring-save],
@@ -1446,7 +1466,7 @@
If you have selected words or lines, this command extends the
selection through the word or line clicked on. If you do this
again in a different position, it extends the selection again.
-If you do this twice in the same position, the selection is killed."
+"
(interactive "e")
(let ((before-scroll
(with-current-buffer (window-buffer (posn-window (event-start click)))
@@ -1462,6 +1482,7 @@
;; Don't be fooled by a recent click in some other buffer.
(eq mouse-selection-click-count-buffer
(current-buffer)))))
+ ;; moving by words/lines
(if (not (and (eq last-command 'mouse-save-then-kill)
(equal click-posn
(car (cdr-safe (cdr-safe mouse-save-then-kill-posn))))))
@@ -1475,30 +1496,58 @@
(abs (- click-posn (point))))
(set-mark (car range))
(goto-char (nth 1 range)))
- ;; We have already put the old region in the kill ring.
- ;; Replace it with the extended region.
- ;; (It would be annoying to make a separate entry.)
- (kill-new (buffer-substring (point) (mark t)) t)
+
+ (cond ((eq mouse-save-then-kill-copy-region t) ; save on first click
+ ;; We have already put the old region in the kill ring.
+ ;; Replace it with the extended region.
+ ;; (It would be annoying to make a separate entry.)
+ (kill-new (buffer-substring (point) (mark t)) t)
+ ;; Arrange for a repeated mouse-3 to kill this region.
+ (setq mouse-save-then-kill-posn
+ (list (car kill-ring) (point) click-posn)))
+ ((eq mouse-save-then-kill-copy-region :double) ; no save on first click
+ ;; no save on first click, but need to know region
+ ;; from first. nil for saved kill ring top used for
+ ;; limbo between second and third clicks
+ (setq mouse-save-then-kill-posn
+ (list nil (point) click-posn))))
(mouse-set-region-1)
- ;; Arrange for a repeated mouse-3 to kill this region.
- (setq mouse-save-then-kill-posn
- (list (car kill-ring) (point) click-posn))
(mouse-show-mark))
- ;; If we click this button again without moving it,
- ;; that time kill.
- (mouse-save-then-kill-delete-region (mark) (point))
- (setq mouse-selection-click-count 0)
- (setq mouse-save-then-kill-posn nil))
- (if (and (eq last-command 'mouse-save-then-kill)
+ (cond ((eq mouse-save-then-kill-copy-region t) ; kill on second click
+ ;; If we click this button again without moving it,
+ ;; that time kill.
+ (mouse-save-then-kill-delete-region (mark) (point))
+ (setq mouse-selection-click-count 0)
+ (setq mouse-save-then-kill-posn nil))
+ ((eq mouse-save-then-kill-copy-region :double) ;save on second/kill on third
+ (if (car-safe mouse-save-then-kill-posn) ; kill on third
+ (progn
+ (mouse-save-then-kill-delete-region (mark) (point))
+ (setq mouse-selection-click-count 0)
+ (setq mouse-save-then-kill-posn nil))
+ (progn ; save on second
+ (kill-new (buffer-substring (point) (mark t)) t)
+ (setq mouse-save-then-kill-posn
+ (list (car kill-ring) (point) click-posn)))))))
+ ;; moving by chars
+ (if (and (eq last-command 'mouse-save-then-kill)
mouse-save-then-kill-posn
- (eq (car mouse-save-then-kill-posn) (car kill-ring))
- (equal (cdr mouse-save-then-kill-posn) (list (point) click-posn)))
- ;; If this is the second time we've called
- ;; mouse-save-then-kill, delete the text from the buffer.
- (progn
- (mouse-save-then-kill-delete-region (point) (mark))
- ;; After we kill, another click counts as "the first time".
- (setq mouse-save-then-kill-posn nil))
+ (equal (cdr-safe mouse-save-then-kill-posn) (list (point) click-posn)))
+ (cond ((eq mouse-save-then-kill-copy-region t) ; kill on second click
+ ;; If this is the second time we've called
+ ;; mouse-save-then-kill, delete the text from the buffer.
+ (mouse-save-then-kill-delete-region (point) (mark))
+ ;; After we kill, another click counts as "the first time".
+ (setq mouse-save-then-kill-posn nil))
+ ((eq mouse-save-then-kill-copy-region :double) ; save on second / kill on third
+ (if (car-safe mouse-save-then-kill-posn) ; kill on third
+ (progn
+ (mouse-save-then-kill-delete-region (point) (mark))
+ (setq mouse-save-then-kill-posn nil))
+ (progn ; save on second
+ (kill-new (buffer-substring (point) (mark t)) t)
+ (setq mouse-save-then-kill-posn
+ (list (car kill-ring) (point) click-posn))))))
;; This is not a repetition.
;; We are adjusting an old selection or creating a new one.
(if (or (and (eq last-command 'mouse-save-then-kill)
@@ -1520,17 +1569,26 @@
(goto-char new)
(set-mark new))
(setq deactivate-mark nil)))
- (kill-new (buffer-substring (point) (mark t)) t))
+ (and (eq mouse-save-then-kill-copy-region t) ; save on first click
+ (kill-new (buffer-substring (point) (mark t)) t)))
;; Set the mark where point is, then move where clicked.
(mouse-set-mark-fast click)
(if before-scroll
(goto-char before-scroll))
(exchange-point-and-mark) ;Why??? --Stef
- (kill-new (buffer-substring (point) (mark t))))
- (mouse-show-mark)
+ (and (eq mouse-save-then-kill-copy-region t) ; save on first click
+ (kill-new (buffer-substring (point) (mark t)))))
+ (cond ((eq mouse-save-then-kill-copy-region t) ; save on first click
+ (setq mouse-save-then-kill-posn
+ (list (car kill-ring) (point) click-posn)))
+ ((eq mouse-save-then-kill-copy-region :double) ; no save on first click
+ ;; no save on first click, but need to know region from first
+ ;; nil for saved kill ring top used for limbo between
+ ;; second and third clicks
+ (setq mouse-save-then-kill-posn
+ (list nil (point) click-posn))))
(mouse-set-region-1)
- (setq mouse-save-then-kill-posn
- (list (car kill-ring) (point) click-posn)))))))
+ (mouse-show-mark))))))
\f
(global-set-key [M-mouse-1] 'mouse-start-secondary)
(global-set-key [M-drag-mouse-1] 'mouse-set-secondary)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-02-13 2:09 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-13 2:09 allow mouse-save-then-kill customization like mouse-drag-copy-region? David De La Harpe Golden
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.