From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.bugs Subject: bug#12321: 24.2.50; `read-regexp' parameter DEFAULT-VALUE and the calculated defaults Date: Fri, 31 Aug 2012 15:38:45 -0700 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1346452795 20139 80.91.229.3 (31 Aug 2012 22:39:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 31 Aug 2012 22:39:55 +0000 (UTC) To: 12321@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Sep 01 00:39:56 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1T7ZsW-0006DM-Fb for geb-bug-gnu-emacs@m.gmane.org; Sat, 01 Sep 2012 00:39:52 +0200 Original-Received: from localhost ([::1]:36383 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7ZsU-0002Xj-3W for geb-bug-gnu-emacs@m.gmane.org; Fri, 31 Aug 2012 18:39:50 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7ZsQ-0002XS-Pu for bug-gnu-emacs@gnu.org; Fri, 31 Aug 2012 18:39:47 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T7ZsP-00012H-Bb for bug-gnu-emacs@gnu.org; Fri, 31 Aug 2012 18:39:46 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:50594) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7ZsP-00012D-8C for bug-gnu-emacs@gnu.org; Fri, 31 Aug 2012 18:39:45 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1T7Zte-0008DA-Iv for bug-gnu-emacs@gnu.org; Fri, 31 Aug 2012 18:41:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Drew Adams" Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 31 Aug 2012 22:41:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 12321 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: Original-Received: via spool by submit@debbugs.gnu.org id=B.134645282531520 (code B ref -1); Fri, 31 Aug 2012 22:41:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 31 Aug 2012 22:40:25 +0000 Original-Received: from localhost ([127.0.0.1]:60140 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T7Zt2-0008CK-2E for submit@debbugs.gnu.org; Fri, 31 Aug 2012 18:40:24 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36551) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1T7Zsw-0008CA-RZ for submit@debbugs.gnu.org; Fri, 31 Aug 2012 18:40:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T7Zrg-0000mY-0K for submit@debbugs.gnu.org; Fri, 31 Aug 2012 18:39:01 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:45956) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7Zrf-0000mT-T8 for submit@debbugs.gnu.org; Fri, 31 Aug 2012 18:38:59 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:36580) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7Zre-0002TF-PS for bug-gnu-emacs@gnu.org; Fri, 31 Aug 2012 18:38:59 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T7Zrd-0000ld-9N for bug-gnu-emacs@gnu.org; Fri, 31 Aug 2012 18:38:58 -0400 Original-Received: from rcsinet15.oracle.com ([148.87.113.117]:23429) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7Zrd-0000lD-2J for bug-gnu-emacs@gnu.org; Fri, 31 Aug 2012 18:38:57 -0400 Original-Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by rcsinet15.oracle.com (Sentrion-MTA-4.2.2/Sentrion-MTA-4.2.2) with ESMTP id q7VMcrlu001758 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 31 Aug 2012 22:38:54 GMT Original-Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id q7VMcqNR022374 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 31 Aug 2012 22:38:53 GMT Original-Received: from abhmt118.oracle.com (abhmt118.oracle.com [141.146.116.70]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id q7VMcqPN008503 for ; Fri, 31 Aug 2012 17:38:52 -0500 Original-Received: from dradamslap1 (/10.159.219.220) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 31 Aug 2012 15:38:52 -0700 X-Mailer: Microsoft Office Outlook 11 Thread-Index: Ac2HyWFPF22nAeFERWestqa+KAr6Kw== X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-Source-IP: acsinet21.oracle.com [141.146.126.237] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:63639 Archived-At: 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'