From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#12321: 24.2.50; `read-regexp' parameter DEFAULT-VALUE and the calculated defaults Date: Thu, 20 Sep 2012 11:43:45 +0300 Organization: JURTA Message-ID: <87k3vp2if2.fsf@mail.jurta.org> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1348130739 13757 80.91.229.3 (20 Sep 2012 08:45:39 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Sep 2012 08:45:39 +0000 (UTC) Cc: 12321@debbugs.gnu.org To: "Drew Adams" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Sep 20 10:45:44 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 1TEcOD-0006h3-RK for geb-bug-gnu-emacs@m.gmane.org; Thu, 20 Sep 2012 10:45:42 +0200 Original-Received: from localhost ([::1]:33227 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEcO9-0007Wu-HP for geb-bug-gnu-emacs@m.gmane.org; Thu, 20 Sep 2012 04:45:37 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:49098) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEcO6-0007Wd-7O for bug-gnu-emacs@gnu.org; Thu, 20 Sep 2012 04:45:35 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TEcO5-0005aH-2B for bug-gnu-emacs@gnu.org; Thu, 20 Sep 2012 04:45:34 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:34972) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEcO4-0005Zm-Oz for bug-gnu-emacs@gnu.org; Thu, 20 Sep 2012 04:45:32 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1TEcPW-0002Hs-FA for bug-gnu-emacs@gnu.org; Thu, 20 Sep 2012 04:47:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 20 Sep 2012 08:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 12321 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 12321-submit@debbugs.gnu.org id=B12321.13481308168774 (code B ref 12321); Thu, 20 Sep 2012 08:47:02 +0000 Original-Received: (at 12321) by debbugs.gnu.org; 20 Sep 2012 08:46:56 +0000 Original-Received: from localhost ([127.0.0.1]:44518 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TEcPQ-0002HS-6X for submit@debbugs.gnu.org; Thu, 20 Sep 2012 04:46:56 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:46533 helo=ps18281.dreamhostps.com) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1TEcPO-0002HJ-2T for 12321@debbugs.gnu.org; Thu, 20 Sep 2012 04:46:54 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id B5FAE451CC5C; Thu, 20 Sep 2012 01:45:22 -0700 (PDT) In-Reply-To: (Drew Adams's message of "Fri, 31 Aug 2012 15:38:45 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (x86_64-pc-linux-gnu) 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:64638 Archived-At: > 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? This can be fixed by the following patch. It is based on two previously sent patches (one that fixes the PROMPT arg, and another that adds the HISTORY arg to `read-regexp' in bug#7567), so `read-regexp' has the `history' arg in this third patch. These three patches could be committed separately. No doc fix yet, just confirmed that it works predictably in all my tests. === modified file 'lisp/replace.el' --- lisp/replace.el 2012-09-09 22:15:24 +0000 +++ lisp/replace.el 2012-09-20 08:42:58 +0000 @@ -575,7 +575,7 @@ (defvar regexp-history nil (defvar occur-collect-regexp-history '("\\1") "History of regexp for occur's collect operation") -(defun read-regexp (prompt &optional default-value history) +(defun read-regexp (prompt &optional defaults history) "Read regexp as a string using the regexp history and some useful defaults. Prompt for a regular expression with PROMPT (without a colon and space) in the minibuffer. The optional argument DEFAULT-VALUE @@ -585,7 +585,10 @@ (defun read-regexp (prompt &optional def If HISTORY is nil, `regexp-history' is used. Values available via M-n are the string at point, the last isearch regexp, the last isearch string, and the last replacement regexp." - (let* ((defaults + (let* ((default (if (consp defaults) (car defaults) defaults)) + (defaults + (append + (if (listp defaults) defaults (list defaults)) (list (regexp-quote (or (funcall (or find-tag-default-function (get major-mode 'find-tag-default-function) @@ -594,7 +597,7 @@ (defun read-regexp (prompt &optional def (car regexp-search-ring) (regexp-quote (or (car search-ring) "")) (car (symbol-value - query-replace-from-history-variable)))) + query-replace-from-history-variable))))) (defaults (delete-dups (delq nil (delete "" defaults)))) ;; Don't add automatically the car of defaults for empty input (history-add-new-input nil) @@ -602,13 +605,13 @@ (defun read-regexp (prompt &optional def (read-from-minibuffer (if (string-match-p ":[ \t]*\\'" prompt) prompt - (if default-value + (if default (format "%s (default %s): " prompt - (query-replace-descr default-value)) + (query-replace-descr default)) (format "%s: " prompt))) nil nil nil (or history 'regexp-history) defaults t))) (if (equal input "") - (or default-value input) + (or default input) (prog1 input (add-to-history (or history 'regexp-history) input)))))