[lug] silly emacs

David dajo at frii.com
Sat Aug 11 18:43:55 MDT 2001


I think that this command works, but I am not sure.  I have tried to
make it play nicely regardless of whether mouse or keyboard is used.
I may not have succeded.  Put this somewhere (in your .emacs?) so that
it is evaluated when you crank up Emacs.

  (defun  MinorTools-replace-region  (start  stop)
    
    "Replaces the current region with the top item from the kill-ring.

invoke with: \\[MinorTools-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  "%s" (car  kill-ring))) ))
  
  
This binds the command to C-v, note that this will overwrite the
standard binding of scroll-up.  You can bind this so that it becomes
part of a menu; I have left that to you; I do not know which map to
use. 

(define-key  global-map  [?\C-v]  'MinorTools-replace-region)  
  
dajo



More information about the LUG mailing list