;;; replace.el --- replace commands for Emacs
;; Copyright (C) 1985, 1986, 1987, 1992, 1994, 1996, 1997, 2000, 2001,
-;; 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
+;; Free Software Foundation, Inc.
;; Maintainer: FSF
;;; Code:
(defcustom case-replace t
- "*Non-nil means `query-replace' should preserve case in replacements."
+ "Non-nil means `query-replace' should preserve case in replacements."
:type 'boolean
:group 'matching)
:version "20.3")
(defcustom query-replace-skip-read-only nil
- "*Non-nil means `query-replace' and friends ignore read-only matches."
+ "Non-nil means `query-replace' and friends ignore read-only matches."
:type 'boolean
:group 'matching
:version "22.1")
(defcustom query-replace-show-replacement t
- "*Non-nil means to show what actual replacement text will be."
+ "Non-nil means to show what actual replacement text will be."
:type 'boolean
:group 'matching
:version "23.1")
(defcustom query-replace-highlight t
- "*Non-nil means to highlight matches during query replacement."
+ "Non-nil means to highlight matches during query replacement."
:type 'boolean
:group 'matching)
(defcustom query-replace-lazy-highlight t
- "*Controls the lazy-highlighting during query replacements.
+ "Controls the lazy-highlighting during query replacements.
When non-nil, all text in the buffer matching the current match
is highlighted lazily using isearch lazy highlighting (see
`lazy-highlight-initial-delay' and `lazy-highlight-interval')."
Fourth and fifth arg START and END specify the region to operate on.
To customize possible responses, change the \"bindings\" in `query-replace-map'."
- (interactive (let ((common
- (query-replace-read-args
- (if (and transient-mark-mode mark-active)
- "Query replace in region"
- "Query replace")
- nil)))
- (list (nth 0 common) (nth 1 common) (nth 2 common)
- ;; These are done separately here
- ;; so that command-history will record these expressions
- ;; rather than the values they had this time.
- (if (and transient-mark-mode mark-active)
- (region-beginning))
- (if (and transient-mark-mode mark-active)
- (region-end)))))
+ (interactive
+ (let ((common
+ (query-replace-read-args
+ (concat "Query replace"
+ (if current-prefix-arg " word" "")
+ (if (and transient-mark-mode mark-active) " in region" ""))
+ nil)))
+ (list (nth 0 common) (nth 1 common) (nth 2 common)
+ ;; These are done separately here
+ ;; so that command-history will record these expressions
+ ;; rather than the values they had this time.
+ (if (and transient-mark-mode mark-active)
+ (region-beginning))
+ (if (and transient-mark-mode mark-active)
+ (region-end)))))
(perform-replace from-string to-string t nil delimited nil nil start end))
(define-key esc-map "%" 'query-replace)
(interactive
(let ((common
(query-replace-read-args
- (if (and transient-mark-mode mark-active)
- "Query replace regexp in region"
- "Query replace regexp")
+ (concat "Query replace"
+ (if current-prefix-arg " word" "")
+ " regexp"
+ (if (and transient-mark-mode mark-active) " in region" ""))
t)))
(list (nth 0 common) (nth 1 common) (nth 2 common)
;; These are done separately here
(interactive
(let ((common
(query-replace-read-args
- (if (and transient-mark-mode mark-active)
- "Replace string in region"
- "Replace string")
+ (concat "Replace"
+ (if current-prefix-arg " word" "")
+ " string"
+ (if (and transient-mark-mode mark-active) " in region" ""))
nil)))
(list (nth 0 common) (nth 1 common) (nth 2 common)
(if (and transient-mark-mode mark-active)
(interactive
(let ((common
(query-replace-read-args
- (if (and transient-mark-mode mark-active)
- "Replace regexp in region"
- "Replace regexp")
+ (concat "Replace"
+ (if current-prefix-arg " word" "")
+ " regexp"
+ (if (and transient-mark-mode mark-active) " in region" ""))
t)))
(list (nth 0 common) (nth 1 common) (nth 2 common)
(if (and transient-mark-mode mark-active)
Maximum length of the history list is determined by the value
of `history-length', which see.")
-(defun read-regexp (prompt &optional default)
+(defun read-regexp (prompt &optional default-value)
"Read regexp as a string using the regexp history and some useful defaults.
Prompt for a regular expression with PROMPT (without a colon and
-space) in the minibuffer. The optional string argument DEFAULT
-provides the basic default value, that is returned on typing RET.
-Additional defaults are the string at point, the last isearch regexp,
-the last isearch string, and the last replacement regexp."
+space) in the minibuffer. The optional argument DEFAULT-VALUE
+provides the value to display in the minibuffer prompt that is
+returned if the user just types RET.
+Values available via M-n are the string at point, the last isearch
+regexp, the last isearch string, and the last replacement regexp."
(let* ((defaults
(list (regexp-quote
(or (funcall (or find-tag-default-function
(history-add-new-input nil)
(input
(read-from-minibuffer
- (if default
- (format "%s (default %s): " prompt (query-replace-descr default))
+ (if default-value
+ (format "%s (default %s): " prompt
+ (query-replace-descr default-value))
(format "%s: " prompt))
nil nil nil 'regexp-history defaults t)))
(if (equal input "")
- default
+ (or default-value input)
(prog1 input
(add-to-history 'regexp-history input)))))
"Print and return number of matches for REGEXP following point.
When called from Lisp and INTERACTIVE is omitted or nil, just return
the number, do not print it; if INTERACTIVE is t, the function behaves
-in all respects has if it had been called interactively.
+in all respects as if it had been called interactively.
If REGEXP contains upper case characters (excluding those preceded by `\\')
and `search-upper-case' is non-nil, the matching is case-sensitive.
(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 [kill-this-buffer]
- '(menu-item "Kill occur buffer" kill-this-buffer
- :help "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"))
- (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"))
- (define-key map [clone-buffer]
- '(menu-item "Clone occur buffer" clone-buffer
- :help "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] '("--"))
+ (define-key map [separator-1] menu-bar-separator)
+ (define-key map [kill-this-buffer]
+ `(menu-item ,(purecopy "Kill occur buffer") kill-this-buffer
+ :help ,(purecopy "Kill the current *Occur* buffer")))
+ (define-key map [quit-window]
+ `(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 ,(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 ,(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 ,(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"))
- (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"))
- (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 "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 ,(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 ,(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'.")
:version "22.1")
(defcustom list-matching-lines-default-context-lines 0
- "*Default number of context lines included around `list-matching-lines' matches.
+ "Default number of context lines included around `list-matching-lines' matches.
A negative number means to include that many lines before the match.
A positive number means to include that many lines both before and after."
:type 'integer
(defalias 'list-matching-lines 'occur)
(defcustom list-matching-lines-face 'match
- "*Face used by \\[list-matching-lines] to show the text that matches.
+ "Face used by \\[list-matching-lines] to show the text that matches.
If the value is nil, don't highlight the matching portions specially."
:type 'face
:group 'matching)
(defcustom list-matching-lines-buffer-name-face 'underline
- "*Face used by \\[list-matching-lines] to show the names of buffers.
+ "Face used by \\[list-matching-lines] to show the names of buffers.
If the value is nil, don't highlight the buffer names specially."
:type 'face
:group 'matching)
(defcustom occur-excluded-properties
'(read-only invisible intangible field mouse-face help-echo local-map keymap
yank-handler follow-link)
- "*Text properties to discard when copying lines to the *Occur* buffer.
+ "Text properties to discard when copying lines to the *Occur* buffer.
The value should be a list of text properties to discard or t,
which means to discard all text properties."
:type '(choice (const :tag "All" t) (repeat symbol))
(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
(funcall (car replacements) (cdr replacements)
replace-count)))
(if (not query-flag)
- (let ((inhibit-read-only
- query-replace-skip-read-only))
+ (progn
(unless (or literal noedit)
(replace-highlight
(nth 0 real-match-data) (nth 1 real-match-data)
(with-output-to-temp-buffer "*Help*"
(princ
(concat "Query replacing "
+ (if delimited-flag "word " "")
(if regexp-flag "regexp " "")
from-string " with "
next-replacement ".\n\n"
((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.