;;; 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 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
+ default-value
(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.
"Auto Occurrence Display"
"Display another occurrence when moving the cursor"))
(define-key map [separator-1] '("--"))
- (define-key map [kill-this-buffer]
+ (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]
+ (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]
+ (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]
+ (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]
+ (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 [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]
+ (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]
+ (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"))
map)
: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))
(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"