aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/replace.el
diff options
context:
space:
mode:
authorJuri Linkov2013-02-25 22:57:44 +0200
committerJuri Linkov2013-02-25 22:57:44 +0200
commitcd27a76dad3fa9ede47a9034031131872f65f07c (patch)
treec364d7f90bd2de10f9bb8f1391b25a8a9bef9ed9 /lisp/replace.el
parent343a2aefb528ce3c978ba2145705b9e37bfbe02a (diff)
downloademacs-cd27a76dad3fa9ede47a9034031131872f65f07c.tar.gz
emacs-cd27a76dad3fa9ede47a9034031131872f65f07c.zip
* lisp/replace.el (read-regexp): Let-bind `default' to the first
element of `defaults' if it's a list, otherwise it should be a string or nil. Let-bind `suggestions' to `defaults' if it's a list, otherwise make a list with the string value. Doc fix. Fixes: debbugs:13805
Diffstat (limited to 'lisp/replace.el')
-rw-r--r--lisp/replace.el59
1 files changed, 33 insertions, 26 deletions
diff --git a/lisp/replace.el b/lisp/replace.el
index 7f9ea869333..86b1aa27069 100644
--- a/lisp/replace.el
+++ b/lisp/replace.el
@@ -583,34 +583,39 @@ of `history-length', which see.")
583(defun read-regexp (prompt &optional defaults history) 583(defun read-regexp (prompt &optional defaults history)
584 "Read and return a regular expression as a string. 584 "Read and return a regular expression as a string.
585When PROMPT doesn't end with a colon and space, it adds a final \": \". 585When PROMPT doesn't end with a colon and space, it adds a final \": \".
586If DEFAULTS is non-nil, it displays the first default in the prompt. 586If the first element of DEFAULTS is non-nil, it's added to the prompt.
587 587
588Optional arg DEFAULTS is a string or a list of strings that are 588Optional arg DEFAULTS has the form (DEFAULT . SUGGESTIONS)
589prepended to a list of standard default values, which include the 589or simply DEFAULT where DEFAULT, if non-nil, should be a string that
590tag at point, the last isearch regexp, the last isearch string, 590is returned as the default value when the user enters empty input.
591SUGGESTIONS is a list of strings that can be inserted into
592the minibuffer using \\<minibuffer-local-map>\\[next-history-element]. \
593The values supplied in SUGGESTIONS
594are prepended to the list of standard suggestions that include
595the tag at point, the last isearch regexp, the last isearch string,
591and the last replacement regexp. 596and the last replacement regexp.
592 597
593Non-nil HISTORY is a symbol to use for the history list. 598Optional arg HISTORY is a symbol to use for the history list.
594If HISTORY is nil, `regexp-history' is used." 599If HISTORY is nil, `regexp-history' is used."
595 (let* ((defaults 600 (let* ((default (if (consp defaults) (car defaults) defaults))
596 (append 601 (suggestions (if (listp defaults) defaults (list defaults)))
597 (if (listp defaults) defaults (list defaults)) 602 (suggestions
598 (list 603 (append
599 ;; Regexp for tag at point. 604 suggestions
600 (let* ((tagf (or find-tag-default-function 605 (list
601 (get major-mode 'find-tag-default-function) 606 ;; Regexp for tag at point.
602 'find-tag-default)) 607 (let* ((tagf (or find-tag-default-function
603 (tag (funcall tagf))) 608 (get major-mode 'find-tag-default-function)
604 (cond ((not tag) "") 609 'find-tag-default))
605 ((eq tagf 'find-tag-default) 610 (tag (funcall tagf)))
606 (format "\\_<%s\\_>" (regexp-quote tag))) 611 (cond ((not tag) "")
607 (t (regexp-quote tag)))) 612 ((eq tagf 'find-tag-default)
608 (car regexp-search-ring) 613 (format "\\_<%s\\_>" (regexp-quote tag)))
609 (regexp-quote (or (car search-ring) "")) 614 (t (regexp-quote tag))))
610 (car (symbol-value 615 (car regexp-search-ring)
611 query-replace-from-history-variable))))) 616 (regexp-quote (or (car search-ring) ""))
612 (defaults (delete-dups (delq nil (delete "" defaults)))) 617 (car (symbol-value query-replace-from-history-variable)))))
613 (default (car defaults)) 618 (suggestions (delete-dups (delq nil (delete "" suggestions))))
614 ;; Do not automatically add default to the history for empty input. 619 ;; Do not automatically add default to the history for empty input.
615 (history-add-new-input nil) 620 (history-add-new-input nil)
616 (input (read-from-minibuffer 621 (input (read-from-minibuffer
@@ -621,9 +626,11 @@ If HISTORY is nil, `regexp-history' is used."
621 (query-replace-descr default))) 626 (query-replace-descr default)))
622 (t 627 (t
623 (format "%s: " prompt))) 628 (format "%s: " prompt)))
624 nil nil nil (or history 'regexp-history) defaults t))) 629 nil nil nil (or history 'regexp-history) suggestions t)))
625 (if (equal input "") 630 (if (equal input "")
631 ;; Return the default value when the user enters empty input.
626 (or default input) 632 (or default input)
633 ;; Otherwise, add non-empty input to the history and return input.
627 (prog1 input 634 (prog1 input
628 (add-to-history (or history 'regexp-history) input))))) 635 (add-to-history (or history 'regexp-history) input)))))
629 636