(read-regexp-suggestions): New function.
(read-regexp): Use `read-regexp-defaults-function' to get default values.
Use `read-regexp-suggestions'. Add non-empty default to history
for empty input.
(occur-read-regexp-defaults-function): Remove function.
(occur-read-primary-args): Use `regexp-history-last' instead of
`occur-read-regexp-defaults-function'.
* lisp/hi-lock.el (hi-lock-read-regexp-defaults-function): Remove function.
(hi-lock-line-face-buffer, hi-lock-face-buffer)
(hi-lock-face-phrase-buffer): Use `regexp-history-last' instead of
`hi-lock-read-regexp-defaults-function'. Doc fix.
(hi-lock-face-symbol-at-point): Replace `find-tag-default-as-regexp'
with `find-tag-default-as-symbol-regexp'. Doc fix.
(hi-lock-read-regexp-defaults): Remove function.
(hi-lock-regexp-okay): Add check for null.
* lisp/progmodes/grep.el (grep-read-regexp): Use `grep-tag-default' for
the arg DEFAULTS. Move formatting of the prompt to `read-regexp'.
* lisp/subr.el (find-tag-default-as-symbol-regexp): New function.
(find-tag-default-as-regexp): Move symbol regexp formatting to
`find-tag-default-as-symbol-regexp'.
Fixes: debbugs:14405
** jit-lock-debug-mode lets you use the debuggers on code run via jit-lock.
-** completing-read-multiple's separator can now be a regexp.
+** Minibuffer
+
+*** completing-read-multiple's separator can now be a regexp.
The default separator is changed to allow surrounding spaces around the comma.
+*** New option `read-regexp-defaults-function' defines the function
+that provides the default value for commands that ask for a regexp:
+`rgrep', `lgrep' `occur', `multi-occur', `multi-occur-in-matching-buffers',
+`highlight-regexp', `highlight-lines-matching-regexp', `highlight-phrase'.
+This option can be customized to values that provide a default value
+from the regexp last history element or from the symbol found at point.
+
** The backtrace debugger and local variables:
*** The debugger's `e' command evaluates the code in the context at point.
This includes using the lexical environment at point, which means that
+2013-12-20 Juri Linkov <juri@jurta.org>
+
+ * replace.el (read-regexp-defaults-function): New defcustom (bug#14405).
+ (read-regexp-suggestions): New function.
+ (read-regexp): Use `read-regexp-defaults-function' to get default values.
+ Use `read-regexp-suggestions'. Add non-empty default to history
+ for empty input.
+ (occur-read-regexp-defaults-function): Remove function.
+ (occur-read-primary-args): Use `regexp-history-last' instead of
+ `occur-read-regexp-defaults-function'.
+
+ * hi-lock.el (hi-lock-read-regexp-defaults-function): Remove function.
+ (hi-lock-line-face-buffer, hi-lock-face-buffer)
+ (hi-lock-face-phrase-buffer): Use `regexp-history-last' instead of
+ `hi-lock-read-regexp-defaults-function'. Doc fix.
+ (hi-lock-face-symbol-at-point): Replace `find-tag-default-as-regexp'
+ with `find-tag-default-as-symbol-regexp'. Doc fix.
+ (hi-lock-read-regexp-defaults): Remove function.
+ (hi-lock-regexp-okay): Add check for null.
+
+ * progmodes/grep.el (grep-read-regexp): Use `grep-tag-default' for
+ the arg DEFAULTS. Move formatting of the prompt to `read-regexp'.
+
+ * subr.el (find-tag-default-as-symbol-regexp): New function.
+ (find-tag-default-as-regexp): Move symbol regexp formatting to
+ `find-tag-default-as-symbol-regexp'.
+
2013-12-20 E Sabof <esabof@gmail.com> (tiny change)
* hi-lock.el (hi-lock-set-pattern): Check for `font-lock-specified-p'.
map)
"Key map for hi-lock.")
-(defvar hi-lock-read-regexp-defaults-function
- 'hi-lock-read-regexp-defaults
- "Function that provides default regexp(s) for highlighting commands.
-This function should take no arguments and return one of nil, a
-regexp or a list of regexps for use with highlighting commands -
-`hi-lock-face-phrase-buffer', `hi-lock-line-face-buffer' and
-`hi-lock-face-buffer'. The return value of this function is used
-as DEFAULTS param of `read-regexp' while executing the
-highlighting command. This function is called only during
-interactive use.
-
-For example, to highlight at symbol at point use
-
- \(setq hi-lock-read-regexp-defaults-function
- 'find-tag-default-as-regexp\)
-
-If you need different defaults for different highlighting
-operations, use `this-command' to identify the command under
-execution.")
-
;; Visible Functions
;;;###autoload
(defun hi-lock-line-face-buffer (regexp &optional face)
"Set face of all lines containing a match of REGEXP to FACE.
Interactively, prompt for REGEXP then FACE. Use
-`hi-lock-read-regexp-defaults-function' to retrieve default
+`read-regexp-defaults-function' to customize default
value(s) of REGEXP. Use the global history list for FACE.
Use Font lock mode, if enabled, to highlight REGEXP. Otherwise,
(interactive
(list
(hi-lock-regexp-okay
- (read-regexp "Regexp to highlight line"
- (funcall hi-lock-read-regexp-defaults-function)))
+ (read-regexp "Regexp to highlight line" 'regexp-history-last))
(hi-lock-read-face-name)))
(or (facep face) (setq face 'hi-yellow))
(unless hi-lock-mode (hi-lock-mode 1))
(defun hi-lock-face-buffer (regexp &optional face)
"Set face of each match of REGEXP to FACE.
Interactively, prompt for REGEXP then FACE. Use
-`hi-lock-read-regexp-defaults-function' to retrieve default
-value(s) REGEXP. Use the global history list for FACE.
+`read-regexp-defaults-function' to customize default
+value(s) of REGEXP. Use the global history list for FACE.
Use Font lock mode, if enabled, to highlight REGEXP. Otherwise,
use overlays for highlighting. If overlays are used, the
(interactive
(list
(hi-lock-regexp-okay
- (read-regexp "Regexp to highlight"
- (funcall hi-lock-read-regexp-defaults-function)))
+ (read-regexp "Regexp to highlight" 'regexp-history-last))
(hi-lock-read-face-name)))
(or (facep face) (setq face 'hi-yellow))
(unless hi-lock-mode (hi-lock-mode 1))
(defun hi-lock-face-phrase-buffer (regexp &optional face)
"Set face of each match of phrase REGEXP to FACE.
Interactively, prompt for REGEXP then FACE. Use
-`hi-lock-read-regexp-defaults-function' to retrieve default
+`read-regexp-defaults-function' to customize default
value(s) of REGEXP. Use the global history list for FACE. When
called interactively, replace whitespace in user provided regexp
with arbitrary whitespace and make initial lower-case letters
(list
(hi-lock-regexp-okay
(hi-lock-process-phrase
- (read-regexp "Phrase to highlight"
- (funcall hi-lock-read-regexp-defaults-function))))
+ (read-regexp "Phrase to highlight" 'regexp-history-last)))
(hi-lock-read-face-name)))
(or (facep face) (setq face 'hi-yellow))
(unless hi-lock-mode (hi-lock-mode 1))
;;;###autoload
(defun hi-lock-face-symbol-at-point ()
"Set face of each match of the symbol at point.
-Use `find-tag-default-as-regexp' to retrieve the symbol at point.
+Use `find-tag-default-as-symbol-regexp' to retrieve the symbol at point.
Use non-nil `hi-lock-auto-select-face' to retrieve the next face
from `hi-lock-face-defaults' automatically.
the highlighting will not update as you type."
(interactive)
(let* ((regexp (hi-lock-regexp-okay
- (find-tag-default-as-regexp)))
+ (find-tag-default-as-symbol-regexp)))
(hi-lock-auto-select-face t)
(face (hi-lock-read-face-name)))
(or (facep face) (setq face 'hi-yellow))
Otherwise signal an error. A pattern that matches the null string is
not suitable."
- (if (string-match regexp "")
- (error "Regexp cannot match an empty string")
- regexp))
-
-(defun hi-lock-read-regexp-defaults ()
- "Return the latest regexp from `regexp-history'.
-See `hi-lock-read-regexp-defaults-function' for details."
- (car regexp-history))
+ (cond
+ ((null regexp)
+ (error "Regexp cannot match nil"))
+ ((string-match regexp "")
+ (error "Regexp cannot match an empty string"))
+ (t regexp)))
(defun hi-lock-read-face-name ()
"Return face for interactive highlighting.
(defun grep-read-regexp ()
"Read regexp arg for interactive grep."
- (let ((default (grep-tag-default)))
- (read-regexp
- (concat "Search for"
- (if (and default (> (length default) 0))
- (format " (default \"%s\"): " default) ": "))
- default 'grep-regexp-history)))
+ (read-regexp "Search for" 'grep-tag-default 'grep-regexp-history))
(defun grep-read-files (regexp)
"Read files arg for interactive grep."
(defvar occur-collect-regexp-history '("\\1")
"History of regexp for occur's collect operation")
+(defcustom read-regexp-defaults-function nil
+ "Function that provides default regexp(s) for regexp reading commands.
+This function should take no arguments and return one of nil, a
+regexp or a list of regexps. The return value of this function is used
+as DEFAULTS param of `read-regexp'. This function is called only during
+interactive use.
+
+If you need different defaults for different commands,
+use `this-command' to identify the command under execution.
+
+You can customize `read-regexp-defaults-function' to the value
+`find-tag-default-as-regexp' to highlight a symbol at point."
+ :type '(choice
+ (const :tag "No default regexp reading function" nil)
+ (const :tag "Latest regexp history" regexp-history-last)
+ (function-item :tag "Tag at point"
+ find-tag-default)
+ (function-item :tag "Tag at point as regexp"
+ find-tag-default-as-regexp)
+ (function-item :tag "Tag at point as symbol regexp"
+ find-tag-default-as-symbol-regexp)
+ (function :tag "Function to provide default for read-regexp"))
+ :group 'matching
+ :version "24.4")
+
+(defun read-regexp-suggestions ()
+ "Return a list of standard suggestions for `read-regexp'.
+By default, the list includes the tag at point, the last isearch regexp,
+the last isearch string, and the last replacement regexp. `read-regexp'
+appends the list returned by this function to the end of values available
+via \\<minibuffer-local-map>\\[next-history-element]."
+ (list
+ (find-tag-default-as-regexp)
+ (find-tag-default-as-symbol-regexp)
+ (car regexp-search-ring)
+ (regexp-quote (or (car search-ring) ""))
+ (car (symbol-value query-replace-from-history-variable))))
+
(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 \": \".
SUGGESTIONS is a list of strings that can be inserted into
the minibuffer using \\<minibuffer-local-map>\\[next-history-element]. \
The values supplied in SUGGESTIONS
-are prepended to the list of standard suggestions that include
-the tag at point, the last isearch regexp, the last isearch string,
-and the last replacement regexp.
+are prepended to the list of standard suggestions returned by
+`read-regexp-suggestions'. The default values can be customized
+by `read-regexp-defaults-function'.
Optional arg HISTORY is a symbol to use for the history list.
If HISTORY is nil, `regexp-history' is used."
- (let* ((default (if (consp defaults) (car defaults) defaults))
+ (let* ((defaults
+ (if (and defaults (symbolp defaults))
+ (cond
+ ((eq (or read-regexp-defaults-function defaults)
+ 'regexp-history-last)
+ (car (symbol-value (or history 'regexp-history))))
+ ((functionp (or read-regexp-defaults-function defaults))
+ (funcall (or read-regexp-defaults-function defaults))))
+ defaults))
+ (default (if (consp defaults) (car defaults) defaults))
(suggestions (if (listp defaults) defaults (list defaults)))
- (suggestions
- (append
- suggestions
- (list
- (find-tag-default-as-regexp)
- (car regexp-search-ring)
- (regexp-quote (or (car search-ring) ""))
- (car (symbol-value query-replace-from-history-variable)))))
+ (suggestions (append suggestions (read-regexp-suggestions)))
(suggestions (delete-dups (delq nil (delete "" suggestions))))
;; Do not automatically add default to the history for empty input.
(history-add-new-input nil)
(input (read-from-minibuffer
(cond ((string-match-p ":[ \t]*\\'" prompt)
prompt)
- (default
+ ((and default (> (length default) 0))
(format "%s (default %s): " prompt
(query-replace-descr default)))
(t
nil nil nil (or history 'regexp-history) suggestions t)))
(if (equal input "")
;; Return the default value when the user enters empty input.
- (or default input)
+ (prog1 (or default input)
+ (when default
+ (add-to-history (or history 'regexp-history) default)))
;; Otherwise, add non-empty input to the history and return input.
(prog1 input
(add-to-history (or history 'regexp-history) input)))))
:group 'matching
:version "22.1")
-(defvar occur-read-regexp-defaults-function
- 'occur-read-regexp-defaults
- "Function that provides default regexp(s) for occur commands.
-This function should take no arguments and return one of nil, a
-regexp or a list of regexps for use with occur commands -
-`occur', `multi-occur' and `multi-occur-in-matching-buffers'.
-The return value of this function is used as DEFAULTS param of
-`read-regexp' while executing the occur command. This function
-is called only during interactive use.
-
-For example, to check for occurrence of symbol at point use
-
- (setq occur-read-regexp-defaults-function
- 'find-tag-default-as-regexp).")
-
-(defun occur-read-regexp-defaults ()
- "Return the latest regexp from `regexp-history'.
-See `occur-read-regexp-defaults-function' for details."
- (car regexp-history))
-
(defun occur-read-primary-args ()
(let* ((perform-collect (consp current-prefix-arg))
(regexp (read-regexp (if perform-collect
"Collect strings matching regexp"
"List lines matching regexp")
- (funcall occur-read-regexp-defaults-function))))
+ 'regexp-history-last)))
(list regexp
(if perform-collect
;; Perform collect operation
When in a major mode that does not provide its own
`find-tag-default-function', return a regexp that matches the
symbol at point exactly."
- (let* ((tagf (or find-tag-default-function
- (get major-mode 'find-tag-default-function)
- 'find-tag-default))
- (tag (funcall tagf)))
- (cond ((null tag) nil)
- ((eq tagf 'find-tag-default)
- (format "\\_<%s\\_>" (regexp-quote tag)))
- (t (regexp-quote tag)))))
+ (let ((tag (funcall (or find-tag-default-function
+ (get major-mode 'find-tag-default-function)
+ 'find-tag-default))))
+ (if tag (regexp-quote tag))))
+
+(defun find-tag-default-as-symbol-regexp ()
+ "Return regexp that matches the default tag at point as symbol.
+If there is no tag at point, return nil.
+
+When in a major mode that does not provide its own
+`find-tag-default-function', return a regexp that matches the
+symbol at point exactly."
+ (let ((tag-regexp (find-tag-default-as-regexp)))
+ (if (and tag-regexp
+ (eq (or find-tag-default-function
+ (get major-mode 'find-tag-default-function)
+ 'find-tag-default)
+ 'find-tag-default))
+ (format "\\_<%s\\_>" tag-regexp)
+ tag-regexp)))
(defun play-sound (sound)
"SOUND is a list of the form `(sound KEYWORD VALUE...)'.