help-emacs-windows
[Top][All Lists]
Advanced

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

Re: [h-e-w] query-replace takes highlighted section as first arg?


From: Galen Boyer
Subject: Re: [h-e-w] query-replace takes highlighted section as first arg?
Date: 10 Apr 2002 21:03:00 -0700
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1

On 08 Apr 2002, address@hidden wrote:
> On Monday, April 08, "Daniel Hegyi" <address@hidden> wrote:
>>Does anybody know how to have M-x query-replace take
>>automatically the highlighted (marked) section to be
>>the first argument, i.e., the string to be replaced?

Got this off google.  Am starting to love it.

(defun delete-region-and-yank (&optional arg)
  "Deletes region if mark is active and yanks the last kill.
Always replaces the region with the yank, whether the region was
selected via keyboard or mouse.  Also works for normal
yank even with ARGS (thus it can be mapped to \C-y)"
  (interactive "p")
  (if mark-active
      (let ((str (buffer-substring (point) (mark))))
        (delete-region (point) (mark))
        (if (string= str (current-kill 0 1))
            (let ((str2 (current-kill 1 1)))
              (kill-new str2 t)))))
  (if arg
      (yank arg)
    (yank)))

(global-set-key "\C-y" 'delete-region-and-yank)

-- 
Galen deForest Boyer
Sweet dreams and flying machines in pieces on the ground.




reply via email to

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