   (if (eq acme-mouse-state 'left)
       (progn
         (setq acme-mouse-state 'left-right)
-        (if (eq acme-cut nil)
-            (progn (setq acme-pasted t)
-                   (mouse-set-point click)
+        (if (eq acme-last-command nil)
+            (progn (mouse-set-point click)
                    (let ((range (mouse-start-end (mark) (point) mouse-selection-click-count)))
                      (set-mark (car range))
-                     (goto-char (nth 1 range))
-                     (delete-region (mark) (point)))
-                   (yank arg))
-          (undo))
+                     (goto-char (nth 1 range)))))
+        (delete-region (mark) (point))
+        (yank arg)
+        (setq acme-last-command 'paste)
         (setq deactivate-mark nil)
         (exchange-point-and-mark))))
 

  ;; which buttons are currently pressed?
  (setq acme-mouse-state 'left)
  (mouse-set-mark click)
  (setq acme-cut nil)
  (setq acme-pasted nil)
  ;; pass to regular click handler
  (mouse-drag-region click))


(defun acme-mouse-1 (click)
  (interactive "e")
  (setq acme-mouse-state 'none)
  (setq acme-last-command nil)
  (setq deactivate-mark nil)
  (if (eq acme-last-command nil)
      (mouse-set-point click)))

;; called if mouse moves between button down and up
(defun acme-drag-mouse-1 (click)
  (interactive "e")
  (if (eq acme-last-command nil)
      (mouse-set-region click)
    (setq deactivate-mark nil)
    (exchange-point-and-mark))
  (setq acme-last-command nil))

(defun acme-down-mouse-2 (click)
  (interactive "e")
  (if (eq acme-mouse-state 'left)
      (progn (setq acme-mouse-state 'left-middle)
             (if (eq acme-last-command 'paste)
                 (undo)
               (mouse-set-point click)
               (let ((range (mouse-start-end (mark) (point) mouse-selection-click-count)))
                 (set-mark (car range))
                 (goto-char (nth 1 range))
                 (kill-region (mark) (point))))
             (setq acme-last-command 'cut))))

(defun acme-mouse-2 ()
  (interactive)
