# HG changeset patch # User Juri Linkov # Date 1214755748 0 # Node ID b5e89d359b84a6173478ac6b4b6e8e1f3cfc04f3 # Parent 3dff73218ec3bea7636ba850cac78fbf26fc2822 (read-regexp): New function. (keep-lines-read-args, occur-read-primary-args): Call `read-regexp' instead of code moved to new function. (keep-lines, flush-lines, how-many): Remove parenthesis and colon from the end of prompt. (replace-re-search-function): Doc fix. diff -r 3dff73218ec3 -r b5e89d359b84 lisp/replace.el --- a/lisp/replace.el Sun Jun 29 14:44:12 2008 +0000 +++ b/lisp/replace.el Sun Jun 29 16:09:08 2008 +0000 @@ -522,6 +522,38 @@ Maximum length of the history list is determined by the value of `history-length', which see.") +(defun read-regexp (prompt) + "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 + (list (regexp-quote + (or (funcall (or find-tag-default-function + (get major-mode 'find-tag-default-function) + 'find-tag-default)) + "")) + (car regexp-search-ring) + (regexp-quote (or (car search-ring) "")) + (car (symbol-value + query-replace-from-history-variable)))) + (defaults (delete-dups (delq nil (delete "" defaults)))) + ;; Don't add automatically the car of defaults for empty input + (history-add-new-input nil) + (input + (read-from-minibuffer + (if default + (format "%s (default %s): " prompt (query-replace-descr default)) + (format "%s: " prompt)) + nil nil nil 'regexp-history defaults t))) + (if (equal input "") + default + (prog1 input + (add-to-history 'regexp-history input))))) + (defalias 'delete-non-matching-lines 'keep-lines) (defalias 'delete-matching-lines 'flush-lines) @@ -532,20 +564,7 @@ "Read arguments for `keep-lines' and friends. Prompt for a regexp with PROMPT. Value is a list, (REGEXP)." - (let* ((default (list - (regexp-quote - (or (funcall (or find-tag-default-function - (get major-mode 'find-tag-default-function) - 'find-tag-default)) - "")) - (car regexp-search-ring) - (regexp-quote (or (car search-ring) "")) - (car (symbol-value - query-replace-from-history-variable)))) - (default (delete-dups (delq nil (delete "" default))))) - (list (read-from-minibuffer prompt nil nil nil - 'regexp-history default t) - nil nil t))) + (list (read-regexp prompt) nil nil t)) (defun keep-lines (regexp &optional rstart rend interactive) "Delete all lines except those containing matches for REGEXP. @@ -574,7 +593,7 @@ (interactive (progn (barf-if-buffer-read-only) - (keep-lines-read-args "Keep lines (containing match for regexp): "))) + (keep-lines-read-args "Keep lines containing match for regexp"))) (if rstart (progn (goto-char (min rstart rend)) @@ -649,7 +668,7 @@ (interactive (progn (barf-if-buffer-read-only) - (keep-lines-read-args "Flush lines (containing match for regexp): "))) + (keep-lines-read-args "Flush lines containing match for regexp"))) (if rstart (progn (goto-char (min rstart rend)) @@ -695,7 +714,7 @@ a previously found match." (interactive - (keep-lines-read-args "How many matches for (regexp): ")) + (keep-lines-read-args "How many matches for regexp")) (save-excursion (if rstart (progn @@ -1003,38 +1022,9 @@ (nreverse result)))) (defun occur-read-primary-args () - (let* ((default (car regexp-history)) - (defaults - (list (and transient-mark-mode mark-active - (regexp-quote - (buffer-substring-no-properties - (region-beginning) (region-end)))) - (regexp-quote - (or (funcall - (or find-tag-default-function - (get major-mode 'find-tag-default-function) - 'find-tag-default)) - "")) - (car regexp-search-ring) - (regexp-quote (or (car search-ring) "")) - (car (symbol-value - query-replace-from-history-variable)))) - (defaults (delete-dups (delq nil (delete "" defaults)))) - ;; Don't add automatically the car of defaults for empty input - (history-add-new-input nil) - (input - (read-from-minibuffer - (if default - (format "List lines matching regexp (default %s): " - (query-replace-descr default)) - "List lines matching regexp: ") - nil nil nil 'regexp-history defaults))) - (list (if (equal input "") - default - (prog1 input - (add-to-history 'regexp-history input))) - (when current-prefix-arg - (prefix-numeric-value current-prefix-arg))))) + (list (read-regexp "List lines matching regexp") + (when current-prefix-arg + (prefix-numeric-value current-prefix-arg)))) (defun occur-rename-buffer (&optional unique-p interactive-p) "Rename the current *Occur* buffer to *Occur: original-buffer-name*. @@ -1494,8 +1484,9 @@ (defvar replace-re-search-function 're-search-forward "Function to use when searching for regexps to replace. It is used by `query-replace-regexp', `replace-regexp', -`query-replace-regexp-eval', and `map-query-replace-regexp'. It -is called with three arguments, as if it were `search-forward'.") +`query-replace-regexp-eval', and `map-query-replace-regexp'. +It is called with three arguments, as if it were +`re-search-forward'.") (defun perform-replace (from-string replacements query-flag regexp-flag delimited-flag