From: "Drew Adams" <drew.adams@oracle.com>
To: 12321@debbugs.gnu.org
Subject: bug#12321: 24.2.50; `read-regexp' parameter DEFAULT-VALUE and the calculated defaults
Date: Fri, 31 Aug 2012 15:38:45 -0700 [thread overview]
Message-ID: <C9602E347A804423B8D678C77401C44E@us.oracle.com> (raw)
A couple of things seem odd to me about `read-regexp' as currently
defined.
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
one).
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
defaults
(list (regexp-quote
(or (funcall
(or find-tag-default-function
(get major-mode 'find-tag-default-function)
'find-tag-default))
""))
(car regexp-search-ring)
(regexp-quote (or (car search-ring) ""))
(car (symbol-value
query-replace-from-history-variable)))))
(deflts (delete-dups (delq nil (delete "" deflts))))
;; Do not automatically add INPUT to the history, in case it is "".
(history-add-new-input nil)
(input (read-from-minibuffer
(if defaults
(format "%s (default `%s'): " prompt
(mapconcat 'isearch-text-char-description
(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 24.2.50.1 (i386-mingw-nt5.1.2600)
of 2012-08-26 on MARVIN
Bzr revision: 109788 dmantipov@yandex.ru-20120827041533-3cy7pdjdqz14o90c
Windowing system distributor `Microsoft Corp.', version 5.1.2600
Configured using:
`configure --with-gcc (4.6) --no-opt --enable-checking --cflags
-ID:/devel/emacs/libs/libXpm-3.5.8/include
-ID:/devel/emacs/libs/libXpm-3.5.8/src
-ID:/devel/emacs/libs/libpng-dev_1.4.3-1/include
-ID:/devel/emacs/libs/zlib-dev_1.2.5-2/include
-ID:/devel/emacs/libs/giflib-4.1.4-1/include
-ID:/devel/emacs/libs/jpeg-6b-4/include
-ID:/devel/emacs/libs/tiff-3.8.2-1/include
-ID:/devel/emacs/libs/gnutls-3.0.9/include
-ID:/devel/emacs/libs/libiconv-1.13.1-1-dev/include
-ID:/devel/emacs/libs/libxml2-2.7.8/include/libxml2'
next reply other threads:[~2012-08-31 22:38 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-31 22:38 Drew Adams [this message]
2012-09-01 12:04 ` bug#12321: 24.2.50; `read-regexp' parameter DEFAULT-VALUE and the calculated defaults Juri Linkov
2012-09-01 16:52 ` Drew Adams
2012-09-20 8:18 ` bug#12321: 24.2.50; `read-regexp' parameter PROMPT Juri Linkov
2012-09-20 12:46 ` Stefan Monnier
2012-09-20 21:59 ` Juri Linkov
2012-09-20 8:43 ` bug#12321: 24.2.50; `read-regexp' parameter DEFAULT-VALUE and the calculated defaults Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=C9602E347A804423B8D678C77401C44E@us.oracle.com \
--to=drew.adams@oracle.com \
--cc=12321@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.