;;; replace.el --- replace commands for Emacs
;; Copyright (C) 1985, 1986, 1987, 1992, 1994, 1996, 1997, 2000, 2001,
-;; 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+;; 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+;; Free Software Foundation, Inc.
;; Maintainer: FSF
(format "%s: " prompt))
nil nil nil 'regexp-history defaults t)))
(if (equal input "")
- default-value
+ (or default-value input)
(prog1 input
(add-to-history 'regexp-history input)))))
(define-key map "\C-c\C-f" 'next-error-follow-minor-mode)
(define-key map [menu-bar] (make-sparse-keymap))
(define-key map [menu-bar occur]
- (cons "Occur" map))
+ `(cons ,(purecopy "Occur") map))
(define-key map [next-error-follow-minor-mode]
(menu-bar-make-mm-toggle next-error-follow-minor-mode
"Auto Occurrence Display"
"Display another occurrence when moving the cursor"))
- (define-key map [separator-1] '("--"))
+ (define-key map [separator-1] menu-bar-separator)
(define-key map [kill-this-buffer]
- '(menu-item "Kill occur buffer" kill-this-buffer
- :help "Kill the current *Occur* buffer"))
+ `(menu-item ,(purecopy "Kill occur buffer") kill-this-buffer
+ :help ,(purecopy "Kill the current *Occur* buffer")))
(define-key map [quit-window]
- '(menu-item "Quit occur window" quit-window
- :help "Quit the current *Occur* buffer. Bury it, and maybe delete the selected frame"))
+ `(menu-item ,(purecopy "Quit occur window") quit-window
+ :help ,(purecopy "Quit the current *Occur* buffer. Bury it, and maybe delete the selected frame")))
(define-key map [revert-buffer]
- '(menu-item "Revert occur buffer" revert-buffer
- :help "Replace the text in the *Occur* buffer with the results of rerunning occur"))
+ `(menu-item ,(purecopy "Revert occur buffer") revert-buffer
+ :help ,(purecopy "Replace the text in the *Occur* buffer with the results of rerunning occur")))
(define-key map [clone-buffer]
- '(menu-item "Clone occur buffer" clone-buffer
- :help "Create and return a twin copy of the current *Occur* buffer"))
+ `(menu-item ,(purecopy "Clone occur buffer") clone-buffer
+ :help ,(purecopy "Create and return a twin copy of the current *Occur* buffer")))
(define-key map [occur-rename-buffer]
- '(menu-item "Rename occur buffer" occur-rename-buffer
- :help "Rename the current *Occur* buffer to *Occur: original-buffer-name*."))
- (define-key map [separator-2] '("--"))
+ `(menu-item ,(purecopy "Rename occur buffer") occur-rename-buffer
+ :help ,(purecopy "Rename the current *Occur* buffer to *Occur: original-buffer-name*.")))
+ (define-key map [separator-2] menu-bar-separator)
(define-key map [occur-mode-goto-occurrence-other-window]
- '(menu-item "Go To Occurrence Other Window" occur-mode-goto-occurrence-other-window
- :help "Go to the occurrence the current line describes, in another window"))
+ `(menu-item ,(purecopy "Go To Occurrence Other Window") occur-mode-goto-occurrence-other-window
+ :help ,(purecopy "Go to the occurrence the current line describes, in another window")))
(define-key map [occur-mode-goto-occurrence]
- '(menu-item "Go To Occurrence" occur-mode-goto-occurrence
- :help "Go to the occurrence the current line describes"))
+ `(menu-item ,(purecopy "Go To Occurrence") occur-mode-goto-occurrence
+ :help ,(purecopy "Go to the occurrence the current line describes")))
(define-key map [occur-mode-display-occurrence]
- '(menu-item "Display Occurrence" occur-mode-display-occurrence
- :help "Display in another window the occurrence the current line describes"))
+ `(menu-item ,(purecopy "Display Occurrence") occur-mode-display-occurrence
+ :help ,(purecopy "Display in another window the occurrence the current line describes")))
(define-key map [occur-next]
- '(menu-item "Move to next match" occur-next
- :help "Move to the Nth (default 1) next match in an Occur mode buffer"))
+ `(menu-item ,(purecopy "Move to next match") occur-next
+ :help ,(purecopy "Move to the Nth (default 1) next match in an Occur mode buffer")))
(define-key map [occur-prev]
- '(menu-item "Move to previous match" occur-prev
- :help "Move to the Nth (default 1) previous match in an Occur mode buffer"))
+ `(menu-item ,(purecopy "Move to previous match") occur-prev
+ :help ,(purecopy "Move to the Nth (default 1) previous match in an Occur mode buffer")))
map)
"Keymap for `occur-mode'.")
#& (string-to-number (match-string 0))
# replace-count
-Note that these symbols must be preceeded by a backslash in order to
+Note that these symbols must be preceded by a backslash in order to
type them using Lisp syntax."
(while (consp n)
(cond
(replace-count 0)
(nonempty-match nil)
(multi-buffer nil)
+ (recenter-last-op nil) ; Start cycling order with initial position.
;; If non-nil, it is marker saying where in the buffer to stop.
(limit nil)
;; If last typed key in previous call of multi-buffer perform-replace
;; was `automatic-all', don't ask more questions in next files
- (when (eq (lookup-key map (vector last-input-char)) 'automatic-all)
+ (when (eq (lookup-key map (vector last-input-event)) 'automatic-all)
(setq query-flag nil multi-buffer t))
;; REPLACEMENTS is either a string, a list of strings, or a cons cell
((eq def 'skip)
(setq done t))
((eq def 'recenter)
- (recenter nil))
+ ;; `this-command' has the value `query-replace',
+ ;; so we need to bind it to `recenter-top-bottom'
+ ;; to allow it to detect a sequence of `C-l'.
+ (let ((this-command 'recenter-top-bottom)
+ (last-command 'recenter-top-bottom))
+ (recenter-top-bottom)))
((eq def 'edit)
(let ((opos (point-marker)))
(setq real-match-data (replace-match-data
unread-command-events))
(setq done t)))
(when query-replace-lazy-highlight
- ;; Force lazy rehighlighting only after replacements
+ ;; Force lazy rehighlighting only after replacements.
(if (not (memq def '(skip backup)))
- (setq isearch-lazy-highlight-last-string nil))))
+ (setq isearch-lazy-highlight-last-string nil)))
+ (unless (eq def 'recenter)
+ ;; Reset recenter cycling order to initial position.
+ (setq recenter-last-op nil)))
;; Record previous position for ^ when we move on.
;; Change markers to numbers in the match data
;; since lots of markers slow down editing.
(let ((isearch-string string)
(isearch-regexp regexp)
(search-whitespace-regexp nil)
- (isearch-case-fold-search case-fold))
+ (isearch-case-fold-search case-fold)
+ (isearch-forward t)
+ (isearch-error nil))
(isearch-lazy-highlight-new-loop range-beg range-end))))
(defun replace-dehighlight ()