(erc-input-message): Replace last-command-char with last-command-event.
[bpt/emacs.git] / lisp / replace.el
index 2572125..95bb680 100644 (file)
@@ -1,7 +1,7 @@
 ;;; 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
 
@@ -28,7 +28,7 @@
 ;;; 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)
 
@@ -62,24 +62,24 @@ strings or patterns."
   :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')."
@@ -223,20 +223,21 @@ only matches surrounded by word boundaries.
 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)
@@ -289,9 +290,10 @@ Use \\[repeat-complex-command] after this command for details."
   (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
@@ -447,9 +449,10 @@ and TO-STRING is also null.)"
   (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)
@@ -504,9 +507,10 @@ which will run faster and will not set the mark or print anything."
   (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)
@@ -522,15 +526,15 @@ which will run faster and will not set the mark or print anything."
 Maximum length of the history list is determined by the value
 of `history-length', which see.")
 
-(defun read-regexp (prompt)
+(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 in the minibuffer.
-Provide the last element of the regexp history as the basic default,
-and return it on typing RET.  Additional defaults are the string
-at point, the last isearch regexp, the last isearch string, and the
-last replacement regexp.  Return the regexp as a string."
-  (let* ((default (car regexp-history))
-        (defaults
+Prompt for a regular expression with PROMPT (without a colon and
+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
                                   (get major-mode 'find-tag-default-function)
@@ -545,12 +549,13 @@ last replacement regexp.  Return the regexp as a string."
         (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)))))
 
@@ -698,7 +703,7 @@ starting on the same line at which another match ended is ignored."
   "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.
@@ -768,19 +773,19 @@ a previously found match."
                               "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] '("--"))
@@ -793,10 +798,10 @@ a previously found match."
     (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)
@@ -965,7 +970,7 @@ Compatibility function for \\[next-error] invocations."
   :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
@@ -974,13 +979,13 @@ A positive number means to include that many lines both before and after."
 (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)
@@ -988,7 +993,7 @@ If the value is nil, don't highlight the buffer names specially."
 (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))
@@ -1022,7 +1027,8 @@ which means to discard all text properties."
       (nreverse result))))
 
 (defun occur-read-primary-args ()
-  (list (read-regexp "List lines matching regexp")
+  (list (read-regexp "List lines matching regexp"
+                    (car regexp-history))
        (when current-prefix-arg
          (prefix-numeric-value current-prefix-arg))))
 
@@ -1665,8 +1671,7 @@ make, or the user didn't cancel the call."
                    (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)
@@ -1715,6 +1720,7 @@ make, or the user didn't cancel the call."
                         (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"