aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorJuri Linkov2008-06-29 16:10:11 +0000
committerJuri Linkov2008-06-29 16:10:11 +0000
commit96f606c5e6db0d93c89459478f6339ad22dd482e (patch)
tree3cf2caf65a7ad2b80950fdcab8b7539c76ea8186 /lisp/replace.el
parentc0cd125512587b9d0181496df163cec1ceaf34c9 (diff)
downloademacs-96f606c5e6db0d93c89459478f6339ad22dd482e.tar.gz
emacs-96f606c5e6db0d93c89459478f6339ad22dd482e.zip
(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.
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el93
1 files changed, 42 insertions, 51 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 9b42834d7cb..8a83ca62b31 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -522,6 +522,38 @@ which will run faster and will not set the mark or print anything."
522Maximum length of the history list is determined by the value 522Maximum length of the history list is determined by the value
523of `history-length', which see.") 523of `history-length', which see.")
524 524
525(defun read-regexp (prompt)
526 "Read regexp as a string using the regexp history and some useful defaults.
527Prompt for a regular expression with PROMPT in the minibuffer.
528Provide the last element of the regexp history as the basic default,
529and return it on typing RET. Additional defaults are the string
530at point, the last isearch regexp, the last isearch string, and the
531last replacement regexp. Return the regexp as a string."
532 (let* ((default (car regexp-history))
533 (defaults
534 (list (regexp-quote
535 (or (funcall (or find-tag-default-function
536 (get major-mode 'find-tag-default-function)
537 'find-tag-default))
538 ""))
539 (car regexp-search-ring)
540 (regexp-quote (or (car search-ring) ""))
541 (car (symbol-value
542 query-replace-from-history-variable))))
543 (defaults (delete-dups (delq nil (delete "" defaults))))
544 ;; Don't add automatically the car of defaults for empty input
545 (history-add-new-input nil)
546 (input
547 (read-from-minibuffer
548 (if default
549 (format "%s (default %s): " prompt (query-replace-descr default))
550 (format "%s: " prompt))
551 nil nil nil 'regexp-history defaults t)))
552 (if (equal input "")
553 default
554 (prog1 input
555 (add-to-history 'regexp-history input)))))
556
525 557
526(defalias 'delete-non-matching-lines 'keep-lines) 558(defalias 'delete-non-matching-lines 'keep-lines)
527(defalias 'delete-matching-lines 'flush-lines) 559(defalias 'delete-matching-lines 'flush-lines)
@@ -532,20 +564,7 @@ of `history-length', which see.")
532 "Read arguments for `keep-lines' and friends. 564 "Read arguments for `keep-lines' and friends.
533Prompt for a regexp with PROMPT. 565Prompt for a regexp with PROMPT.
534Value is a list, (REGEXP)." 566Value is a list, (REGEXP)."
535 (let* ((default (list 567 (list (read-regexp prompt) nil nil t))
536 (regexp-quote
537 (or (funcall (or find-tag-default-function
538 (get major-mode 'find-tag-default-function)
539 'find-tag-default))
540 ""))
541 (car regexp-search-ring)
542 (regexp-quote (or (car search-ring) ""))
543 (car (symbol-value
544 query-replace-from-history-variable))))
545 (default (delete-dups (delq nil (delete "" default)))))
546 (list (read-from-minibuffer prompt nil nil nil
547 'regexp-history default t)
548 nil nil t)))
549 568
550(defun keep-lines (regexp &optional rstart rend interactive) 569(defun keep-lines (regexp &optional rstart rend interactive)
551 "Delete all lines except those containing matches for REGEXP. 570 "Delete all lines except those containing matches for REGEXP.
@@ -574,7 +593,7 @@ a previously found match."
574 (interactive 593 (interactive
575 (progn 594 (progn
576 (barf-if-buffer-read-only) 595 (barf-if-buffer-read-only)
577 (keep-lines-read-args "Keep lines (containing match for regexp): "))) 596 (keep-lines-read-args "Keep lines containing match for regexp")))
578 (if rstart 597 (if rstart
579 (progn 598 (progn
580 (goto-char (min rstart rend)) 599 (goto-char (min rstart rend))
@@ -649,7 +668,7 @@ starting on the same line at which another match ended is ignored."
649 (interactive 668 (interactive
650 (progn 669 (progn
651 (barf-if-buffer-read-only) 670 (barf-if-buffer-read-only)
652 (keep-lines-read-args "Flush lines (containing match for regexp): "))) 671 (keep-lines-read-args "Flush lines containing match for regexp")))
653 (if rstart 672 (if rstart
654 (progn 673 (progn
655 (goto-char (min rstart rend)) 674 (goto-char (min rstart rend))
@@ -695,7 +714,7 @@ the previous match. Hence, it ignores matches that overlap
695a previously found match." 714a previously found match."
696 715
697 (interactive 716 (interactive
698 (keep-lines-read-args "How many matches for (regexp): ")) 717 (keep-lines-read-args "How many matches for regexp"))
699 (save-excursion 718 (save-excursion
700 (if rstart 719 (if rstart
701 (progn 720 (progn
@@ -1003,38 +1022,9 @@ which means to discard all text properties."
1003 (nreverse result)))) 1022 (nreverse result))))
1004 1023
1005(defun occur-read-primary-args () 1024(defun occur-read-primary-args ()
1006 (let* ((default (car regexp-history)) 1025 (list (read-regexp "List lines matching regexp")
1007 (defaults 1026 (when current-prefix-arg
1008 (list (and transient-mark-mode mark-active 1027 (prefix-numeric-value current-prefix-arg))))
1009 (regexp-quote
1010 (buffer-substring-no-properties
1011 (region-beginning) (region-end))))
1012 (regexp-quote
1013 (or (funcall
1014 (or find-tag-default-function
1015 (get major-mode 'find-tag-default-function)
1016 'find-tag-default))
1017 ""))
1018 (car regexp-search-ring)
1019 (regexp-quote (or (car search-ring) ""))
1020 (car (symbol-value
1021 query-replace-from-history-variable))))
1022 (defaults (delete-dups (delq nil (delete "" defaults))))
1023 ;; Don't add automatically the car of defaults for empty input
1024 (history-add-new-input nil)
1025 (input
1026 (read-from-minibuffer
1027 (if default
1028 (format "List lines matching regexp (default %s): "
1029 (query-replace-descr default))
1030 "List lines matching regexp: ")
1031 nil nil nil 'regexp-history defaults)))
1032 (list (if (equal input "")
1033 default
1034 (prog1 input
1035 (add-to-history 'regexp-history input)))
1036 (when current-prefix-arg
1037 (prefix-numeric-value current-prefix-arg)))))
1038 1028
1039(defun occur-rename-buffer (&optional unique-p interactive-p) 1029(defun occur-rename-buffer (&optional unique-p interactive-p)
1040 "Rename the current *Occur* buffer to *Occur: original-buffer-name*. 1030 "Rename the current *Occur* buffer to *Occur: original-buffer-name*.
@@ -1494,8 +1484,9 @@ with three arguments, as if it were `search-forward'.")
1494(defvar replace-re-search-function 're-search-forward 1484(defvar replace-re-search-function 're-search-forward
1495 "Function to use when searching for regexps to replace. 1485 "Function to use when searching for regexps to replace.
1496It is used by `query-replace-regexp', `replace-regexp', 1486It is used by `query-replace-regexp', `replace-regexp',
1497`query-replace-regexp-eval', and `map-query-replace-regexp'. It 1487`query-replace-regexp-eval', and `map-query-replace-regexp'.
1498is called with three arguments, as if it were `search-forward'.") 1488It is called with three arguments, as if it were
1489`re-search-forward'.")
1499 1490
1500(defun perform-replace (from-string replacements 1491(defun perform-replace (from-string replacements
1501 query-flag regexp-flag delimited-flag 1492 query-flag regexp-flag delimited-flag