unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: "Drew Adams" <drew.adams@oracle.com>
Cc: 12321@debbugs.gnu.org
Subject: bug#12321: 24.2.50; `read-regexp' parameter DEFAULT-VALUE and the calculated defaults
Date: Thu, 20 Sep 2012 11:43:45 +0300	[thread overview]
Message-ID: <87k3vp2if2.fsf@mail.jurta.org> (raw)
In-Reply-To: <C9602E347A804423B8D678C77401C44E@us.oracle.com> (Drew Adams's message of "Fri, 31 Aug 2012 15:38:45 -0700")

> 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)))))
 





      parent reply	other threads:[~2012-09-20  8:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-31 22:38 bug#12321: 24.2.50; `read-regexp' parameter DEFAULT-VALUE and the calculated defaults Drew Adams
2012-09-01 12:04 ` 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 ` Juri Linkov [this message]

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k3vp2if2.fsf@mail.jurta.org \
    --to=juri@jurta.org \
    --cc=12321@debbugs.gnu.org \
    --cc=drew.adams@oracle.com \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).