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

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

Re: looking for: query-replace with a yank-word binding ala isearch


From: Ehud Karni
Subject: Re: looking for: query-replace with a yank-word binding ala isearch
Date: Mon, 11 Nov 2002 18:36:14 +0200

On Thr, 7 Nov 2002 20:24:37 -0800, bigfaceworm <bigfaceworm@hotmail.com> wrote:
> 
> I tried defining my own, but because the control switches to the 
> minibuffer, I'm not sure how to find the buffer in which to do:
  
I use the following to insert the current word (defined as ANY non
white space string) into the mini buffer:

(defun insert-word-or-file-name ()
  "copy word cursor is on or file name to minibuff input"
       (interactive)
       (let* ((bfl (current-buffer))
              (str ""))
           (set-buffer (buffer-name-not-mini))
           (cond
               ((eq major-mode 'dired-mode)
                       (setq str (dired-get-filename t t)))
       ;;  audit-mode is a privetly defined mode for MVS
       ;;      ((eq major-mode 'audit-mode)                        
       ;;              (setq str (audit-get-filename t t)))
               (t
                       (let (bch ech)
                           (forward-char 1)
                           (backward-to-non-blank)
                           (setq bch (point))
                           (re-search-forward "[^ \t\n][ \t\n]" (point-max) t)
                           (setq ech (1- (point)))
                           (setq str (buffer-substring-no-properties bch 
ech)))))
           (set-buffer bfl)
           (insert str)))

(defun backward-to-non-blank () "go to 1st non blank (after blank) to left"
 (interactive)
       (if (re-search-backward "[ \t\n][^ \t\n]" (point-min) t)
           (forward-char 1)
           (if (string-match "[^ \t\n]" (buffer-substring 1 2))
               (goto-char (point-min)))))

(defun buffer-name-not-mini ()
  "Return the name of current buffer, as a string.
If current buffer is the *mini-buffer* return name of previous-window."
       (buffer-name (if (window-minibuffer-p)
                           (if (eq (get-lru-window) (next-window))
                               (window-buffer (previous-window))
                               (window-buffer (next-window)))
                           nil)))

;; to add it to mini buffer key maps:
(defun keymap-test (var)           ; internal function for keymap checking
       (and (boundp var)
            (keymapp (symbol-value var))))

(let ((minimaps (apropos-internal "mini" 'keymap-test))
      map op)
       (while minimaps
           (setq map (symbol-value (car minimaps)))
           (setq minimaps (cdr minimaps))
           (define-key map "\C-w" 'insert-word-or-file-name)))

You don't need to change the `query-replace-map' because when you edit
the replacement string you are using the minibuffer maps.

Ehud.


-- 
 Ehud Karni           Tel: +972-3-7966-561  /"\
 Mivtach - Simon      Fax: +972-3-7966-667  \ /  ASCII Ribbon Campaign
 Insurance agencies   (USA) voice mail and   X   Against   HTML   Mail
 http://www.mvs.co.il  FAX:  1-815-5509341  / \
 mailto:ehud@unix.mvs.co.il                  Better  Safe  Than  Sorry




reply via email to

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