bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cut and Paste


From: David
Subject: Cut and Paste
Date: Wed, 19 Sep 2001 15:31:59 -0600

We had the following posting on the Boulder Linux Users Group list:

> I'm no lisp guru- so silly emacs question. How can I get emacs to NOT 
> automatically copy a selection when I select something with the mouse? I 
> hate that!
> See:
> http://archive.lug.boulder.co.us/bymonth/2001.08/threads.html (silly emacs)

It turned out that this MS Windows questioner missed the ability to copy a
region, highlight another region, and replace the second with the first.

We came up with two solutions for him; the first does not prevent the copy,
but does handle the replace part; the second prevents the copy; and
information on these is below.

The user really likes the change (I just checked with him again):

> Thank you. You don't know how long I've hated that. Since 1997 when I 
> started using linux!! and I've never bothered to pursue fixing it.
> 
> And as a plus, if I select something by left clicking on the beginning, and 
> right clicking on the end, it will 'auto copy' it, as before, so when I 
> want to, I won't entirely lose that 'auto copy'  feature. But double 
> clicking, or mouse dragging selection acts like I want it to - no 
> kill-ring, or whatever emacs calls it. Even better than I expected, best of 
> both worlds!!

So the current suggestion is to provide something in emacs functionally
similar to what has been done; or, if it exists already, make that fact more
clear in the documentation.

This function works, this is the first solution.

(defun  xxxx-replace-region  (start  stop)    

   "Replaces the current region with the top item from the kill-ring.
invoke with: \\[xxxx-replace-region]"
  
  (interactive  "r")
  
  ;; Grab a copy of the region and delete the region from the buffer.
  (let  ((region  (buffer-substring  start  stop)))  
    (delete-region  start  stop)
    
    (if  (equal  region  (car  kill-ring))
        
        ;; Remove the current region from the kill-ring.  The mouse puts it
        ;; there when it selects a region; conversely, identifying a region
        ;; with point and mark does not put it in the kill-ring.
        (setq  kill-ring  (cdr  kill-ring)))
    ;; end if
    
    ;; Insert the top of the kill-ring, leave the kill-ring undisturbed
    ;; for future use.
    (insert  (format  (bas-format-simple) (car  kill-ring))) ))

This is a solution (this is the one that the user is using); the copy code in
mouse.el is deleted.

There are three places in the file to change, you can search for them.

    (let (this-command last-command deactivate-mark)
      (copy-region-as-kill (mark) (point)))

    (let (deactivate-mark)
      (copy-region-as-kill (point) (mark t)))

    (let (deactivate-mark)
      (copy-region-as-kill (overlay-start mouse-secondary-overlay)
                           (overlay-end mouse-secondary-overlay)))))

Comment out the first two entirely, modify the third:

;;;    (let (this-command last-command deactivate-mark)
;;;      (copy-region-as-kill (mark) (point)))

;;;    (let (deactivate-mark)
;;;      (copy-region-as-kill (point) (mark t)))

;;;    (let (deactivate-mark)
;;;      (copy-region-as-kill (overlay-start mouse-secondary-overlay)
;;;                           (overlay-end mouse-secondary-overlay)))))
))  ; these terminate other code

dajo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]