=== modified file 'lisp/replace.el' --- lisp/replace.el 2013-03-08 04:18:16 +0000 +++ lisp/replace.el 2013-03-09 08:23:57 +0000 @@ -580,6 +580,39 @@ of `history-length', which see.") (defvar occur-collect-regexp-history '("\\1") "History of regexp for occur's collect operation") +(defcustom read-regexp-user-defaults nil + "" + :type '(choice + (const :tag "Use system defaults" nil) + (repeat :tag "Per-command defaults" + (list (radio :tag "Command" + (function-item highlight-regexp) + (function-item highlight-phrase) + (function-item highlight-lines-matching-regexp) + (function :tag "Command")) + (choice :tag "Function to retrieve the regexp" + (const :tag "Use no defaults" nil) + (const :tag "Use system defaults" t) + (radio + (function-item find-tag-default-as-regexp) + (function-item find-tag-default) + (function-item :tag "Regexp history" + (lambda nil + "Use regexp history." + (car regexp-history))) + function))))) + :group 'matching + :version "24.4") + +(defun read-regexp-defaults () + (if (not read-regexp-user-defaults) t + (let ((user-default (assoc this-command read-regexp-user-defaults))) + (pcase user-default + (`(,cmd ,(and (pred functionp) getter)) + (funcall getter)) + (`nil nil) + (_ t))))) + (defun read-regexp (prompt &optional defaults history) "Read and return a regular expression as a string. When PROMPT doesn't end with a colon and space, it adds a final \": \". @@ -597,6 +630,11 @@ and the last replacement regexp. Optional arg HISTORY is a symbol to use for the history list. If HISTORY is nil, `regexp-history' is used." + (let ((user-defaults (read-regexp-defaults))) + (unless (eq user-defaults t) + (setq defaults user-defaults) + (message "cmd: %s defaults: %S" this-command defaults))) + (let* ((default (if (consp defaults) (car defaults) defaults)) (suggestions (if (listp defaults) defaults (list defaults))) (suggestions