[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#12321: 24.2.50; `read-regexp' parameter DEFAULT-VALUE and the calcul
bug#12321: 24.2.50; `read-regexp' parameter DEFAULT-VALUE and the calculated defaults
Fri, 31 Aug 2012 15:38:45 -0700
A couple of things seem odd to me about `read-regexp' as currently
First, there is the business of automatically handling `: ' for the
PROMPT. I thought we had finally gotten away from this kind of thing.
It just gives callers less control. And it has sometimes resulted in
confusion and extra work. I don't see this as a win. But whatever.
More importantly -
It seems odd that optional parameter DEFAULT-VALUE is not simply
included among the `M-n' choices (hence the prompt fiddling and the
after-read fiddling if empty input). And it seems odd that you cannot
pass a list of defaults as the optional parameter. Why is the argument
handled separately from the calculated list of "standard" defaults?
The current version provides a list of defaults, but they are all
hard-coded. A given calling context might well have its own set of
defaults that it would like to provide. But it cannot do so (except for
Here is a version I am using, which lets the arg be a list of defaults.
That gives callers more control. Perhaps you might consider it.
(I have not changed the prompt behavior here.)
(defun read-regexp (prompt &optional defaults)
"Read and return a regular expression as a string.
Prompt with PROMPT, which should not include a final `: '.
Non-nil optional arg DEFAULTS is a string or a list of strings that
are prepended to a list of standard default values, which include the
string at point, the last isearch regexp, the last isearch string, and
the last replacement regexp."
(when (and defaults (atom defaults)) (setq defaults (list defaults)))
(let* ((deflts (append
(get major-mode 'find-tag-default-function)
(regexp-quote (or (car search-ring) ""))
(deflts (delete-dups (delq nil (delete "" deflts))))
;; Do not automatically add INPUT to the history, in case it is "".
(format "%s (default `%s'): " prompt
(car deflts) ""))
(format "%s: " prompt))
nil nil nil 'regexp-history deflts t)))
(if (equal input "")
(or (car defaults) input)
(prog1 input (add-to-history 'regexp-history input)))))
Finally, I wonder if it is really appropriate to be filtering out empty
input ("") here. Perhaps we should let `read-regexp' return "" under
some conditions? For example, if DEFAULTS contains "", indicating an
explicit intention that the user be allowed to choose an empty regexp?
Seems like something like whether to allow "" should be up to the
caller, not to `read-regexp'.
It used to be the case, for instance, that you could enter empty input
for the `occur' regexp, and thus get all of the buffer lines in Occur
mode. Whether or not that is something useful for `occur', you can
imagine that some caller of `read-regexp' might well want to allow for
reading an empty string as the user input.
In GNU Emacs 18.104.22.168 (i386-mingw-nt5.1.2600)
of 2012-08-26 on MARVIN
Bzr revision: 109788 address@hidden
Windowing system distributor `Microsoft Corp.', version 5.1.2600
`configure --with-gcc (4.6) --no-opt --enable-checking --cflags
|[Prev in Thread]
||[Next in Thread]|
- bug#12321: 24.2.50; `read-regexp' parameter DEFAULT-VALUE and the calculated defaults,
Drew Adams <=