(defvar mouse-drag-overlay (make-overlay 1 1))
(overlay-put mouse-drag-overlay 'face 'region)
-(defvar mouse-selection-click-count nil)
+(defvar mouse-selection-click-count 0)
(defun mouse-drag-region (start-event)
"Set the region to the text that the mouse is dragged over.
(defvar mouse-save-then-kill-posn nil)
(defun mouse-save-then-kill-delete-region (beg end)
- ;; Delete just one char, so in case buffer is being modified
- ;; for the first time, the undo list records that fact.
- (delete-region beg
- (+ beg (if (> end beg) 1 -1)))
- (let ((buffer-undo-list buffer-undo-list))
- ;; Undo that deletion--but don't change the undo list!
- (primitive-undo 1 buffer-undo-list)
- ;; Now delete the rest of the specified region,
- ;; but don't record it.
- (setq buffer-undo-list t)
- (delete-region beg end))
- (if (not (eq buffer-undo-list t))
- (let ((tail buffer-undo-list))
- ;; Search back in buffer-undo-list for the string
- ;; that came from the first delete-region.
- (while (and tail (not (stringp (car (car tail)))))
- (setq tail (cdr tail)))
- ;; Replace it with an entry for the entire deleted text.
- (and tail
- (setcar tail (cons (car kill-ring) (min beg end)))))))
+ (if (or (= beg end) (eq buffer-undo-list t))
+ ;; If we have no undo list in this buffer,
+ ;; just delete.
+ (delete-region beg end)
+ ;; Delete, but make the undo-list entry share with the kill ring.
+ ;; First, delete just one char, so in case buffer is being modified
+ ;; for the first time, the undo list records that fact.
+ (delete-region beg
+ (+ beg (if (> end beg) 1 -1)))
+ (let ((buffer-undo-list buffer-undo-list))
+ ;; Undo that deletion--but don't change the undo list!
+ (primitive-undo 1 buffer-undo-list)
+ ;; Now delete the rest of the specified region,
+ ;; but don't record it.
+ (setq buffer-undo-list t)
+ (delete-region beg end))
+ (let ((tail buffer-undo-list))
+ ;; Search back in buffer-undo-list for the string
+ ;; that came from deleting one character.
+ (while (and tail (not (stringp (car (car tail)))))
+ (setq tail (cdr tail)))
+ ;; Replace it with an entry for the entire deleted text.
+ (and tail
+ (setcar tail (cons (car kill-ring) (min beg end)))))))
(defun mouse-save-then-kill (click)
"Save text to point in kill ring; the second time, kill the text.
(mouse-show-mark))
;; If we click this button again without moving it,
;; that time kill.
- (mouse-save-then-kill-delete-region (point) (mark)))
+ (mouse-save-then-kill-delete-region (point) (mark))
+ (setq mouse-selection-click-count 0)
+ (setq mouse-save-then-kill-posn nil))
(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.
- (mouse-save-then-kill-delete-region (point) (mark))
- (if (or (eq last-command 'mouse-save-then-kill)
+ (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))
+ (if (or (and (eq last-command 'mouse-save-then-kill)
+ mouse-save-then-kill-posn)
(and mark-active transient-mark-mode)
(and (eq last-command 'mouse-drag-region)
(or mark-even-if-inactive
(mouse-save-then-kill-delete-region
(overlay-start mouse-secondary-overlay)
(overlay-end mouse-secondary-overlay))
+ (setq mouse-save-then-kill-posn nil)
+ (setq mouse-selection-click-count 0)
(delete-overlay mouse-secondary-overlay)))
(if (and (eq last-command 'mouse-secondary-save-then-kill)
mouse-save-then-kill-posn
(mouse-save-then-kill-delete-region
(overlay-start mouse-secondary-overlay)
(overlay-end mouse-secondary-overlay))
+ (setq mouse-save-then-kill-posn nil)
(delete-overlay mouse-secondary-overlay))
(if (overlay-start mouse-secondary-overlay)
;; We have a selection, so adjust it.