From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jambunathan K Newsgroups: gmane.emacs.bugs Subject: bug#13687: /srv/bzr/emacs/trunk r111878: * lisp/replace.el(read-regexp): Let-bind `default' to the first Date: Sat, 09 Mar 2013 14:17:22 +0530 Message-ID: <87d2v9rmcl.fsf@gmail.com> References: <877glsyecw.fsf@gmail.com> <87621cfhff.fsf@mail.jurta.org> <87zjykygjk.fsf@mail.jurta.org> <87vc92gi37.fsf@gmail.com> <1751CEB23B214A3AADCCFD9F007425DE@us.oracle.com> <87li9xer9u.fsf@mail.jurta.org> <8738w5n3rg.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1362818915 27954 80.91.229.3 (9 Mar 2013 08:48:35 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 9 Mar 2013 08:48:35 +0000 (UTC) Cc: 13687@debbugs.gnu.org To: "Drew Adams" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Mar 09 09:48:59 2013 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 1UEFSa-0006wI-Os for geb-bug-gnu-emacs@m.gmane.org; Sat, 09 Mar 2013 09:48:56 +0100 Original-Received: from localhost ([::1]:56141 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEFSE-000481-RY for geb-bug-gnu-emacs@m.gmane.org; Sat, 09 Mar 2013 03:48:34 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:59144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEFS6-00047j-Kc for bug-gnu-emacs@gnu.org; Sat, 09 Mar 2013 03:48:32 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UEFS1-0008BZ-5u for bug-gnu-emacs@gnu.org; Sat, 09 Mar 2013 03:48:26 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:36709) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UEFS1-0008BV-1a for bug-gnu-emacs@gnu.org; Sat, 09 Mar 2013 03:48:21 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1UEFSg-0002KC-Gy for bug-gnu-emacs@gnu.org; Sat, 09 Mar 2013 03:49:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Jambunathan K Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 09 Mar 2013 08:49:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 13687 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 13687-submit@debbugs.gnu.org id=B13687.13628188928875 (code B ref 13687); Sat, 09 Mar 2013 08:49:02 +0000 Original-Received: (at 13687) by debbugs.gnu.org; 9 Mar 2013 08:48:12 +0000 Original-Received: from localhost ([127.0.0.1]:40818 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UEFRr-0002J6-Kr for submit@debbugs.gnu.org; Sat, 09 Mar 2013 03:48:12 -0500 Original-Received: from mail-pb0-f41.google.com ([209.85.160.41]:57477) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1UEFRp-0002It-9G for 13687@debbugs.gnu.org; Sat, 09 Mar 2013 03:48:10 -0500 Original-Received: by mail-pb0-f41.google.com with SMTP id um15so2060712pbc.28 for <13687@debbugs.gnu.org>; Sat, 09 Mar 2013 00:47:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version:content-type; bh=0lTLIhE7+1JtFsqNycNkNjU6BYDvyjWOWP2ZJRcRBg8=; b=oL0CElLCGHc/uxAmYgAOE5vEBkyso1bRBIYgK0TXtQrBInVhniC+10B3JmpnAyC5dQ D9oEiHO8f+0DIUsHL4fdH3IxymodUqzlRkDvmppkdSGpz62TDGcc8IsxBdOMEBzZxyOR l8Nt1iiIqDRPFmuDNTZBnU7Pg9VR55L9w+VFWmjGFO2TK6WX0sYTtiQiR3Ym7l86Y4aa aYSPWWKRPiQ3jRuXzLpuS6eIchOlMi6QWiqyV+95+AcsBD/SmVk/bSSkyqTMnR5db573 JkTZbSKU+8+ImIT+gICUohoWbbSNKLFQSy2Rev+LRoBugkbGiqAhIdGrOPKBibtYiRlw 0B1g== X-Received: by 10.68.179.1 with SMTP id dc1mr3090187pbc.128.1362818841124; Sat, 09 Mar 2013 00:47:21 -0800 (PST) Original-Received: from debian-6.05 ([115.242.225.97]) by mx.google.com with ESMTPS id vq9sm9226894pbc.36.2013.03.09.00.47.16 (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Sat, 09 Mar 2013 00:47:20 -0800 (PST) In-Reply-To: <8738w5n3rg.fsf@gmail.com> (Jambunathan K.'s message of "Sat, 09 Mar 2013 00:00:11 +0530") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) 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.x 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:72268 Archived-At: --=-=-= Content-Type: text/plain Jambunathan K writes: > "Drew Adams" writes: > >> E.g., in the code I cited, if a user does not want the same defaulting >> behavior for commands `occur', `how-many', etc., she can set option >> `search/replace-default-fn' to a function that distinguishes them >> (e.g., using `this-command', as Jambunathan suggested). > > Interesting suggestion there. > > This makes me think that there is no need for multiple > `hi-lock-read-regexp-defaults-function' and a separate > `occur-read-regexp-defaults-function' etc. But a single > `read-regexp-defaults-function' that cases on `this-command'. > > The function can return a symbol token like `t' for `this-command's > which it doesn't want to meddle with but return nil or a regexp or list > of regexps for commands it wants to insinuate. > > Is there any problem with this `read-regexp-defaults-function' > approach? EXPERIMENTAL and ABANDONED PATCH Use of `this-command' is very fragile and flaky. Consider `multi-occur-in-matching-buffers' which does multiple `read-regexp' - one for the buffers and one for the actual regexp. It is not possible to return a two different regexps for the same `this-command'. Interestingly, I am attaching a long from *Messages* buffer and it looks like `this-command' is not reliable (Do you see `exit-minibuffer' in the logs.) So `this-command' could work for simple commands like highlighting commands but will be flaky to be applied in general. Anyways good to experiment and see where an idea takes us... ---------------------------------------------------------------- Customization (custom-set-variables '(read-regexp-user-defaults (quote ((highlight-regexp find-tag-default-as-regexp) (highlight-phrase find-tag-default) (multi-occur-in-matching-buffers find-tag-default))))) ---------------------------------------------------------------- --=-=-= Content-Type: text/x-diff Content-Disposition: inline Content-Description: replace.el.patch === modified file 'lisp/replace.el' --- lisp/replace.el 2013-03-08 04:18:16 +0000 +++ lisp/replace.el 2013-03-09 08:23:57 +0000 @@ -580,6 +580,39 @@ of `history-length', which see.") (defvar occur-collect-regexp-history '("\\1") "History of regexp for occur's collect operation") +(defcustom read-regexp-user-defaults nil + "" + :type '(choice + (const :tag "Use system defaults" nil) + (repeat :tag "Per-command defaults" + (list (radio :tag "Command" + (function-item highlight-regexp) + (function-item highlight-phrase) + (function-item highlight-lines-matching-regexp) + (function :tag "Command")) + (choice :tag "Function to retrieve the regexp" + (const :tag "Use no defaults" nil) + (const :tag "Use system defaults" t) + (radio + (function-item find-tag-default-as-regexp) + (function-item find-tag-default) + (function-item :tag "Regexp history" + (lambda nil + "Use regexp history." + (car regexp-history))) + function))))) + :group 'matching + :version "24.4") + +(defun read-regexp-defaults () + (if (not read-regexp-user-defaults) t + (let ((user-default (assoc this-command read-regexp-user-defaults))) + (pcase user-default + (`(,cmd ,(and (pred functionp) getter)) + (funcall getter)) + (`nil nil) + (_ t))))) + (defun read-regexp (prompt &optional defaults history) "Read and return a regular expression as a string. When PROMPT doesn't end with a colon and space, it adds a final \": \". @@ -597,6 +630,11 @@ and the last replacement regexp. Optional arg HISTORY is a symbol to use for the history list. If HISTORY is nil, `regexp-history' is used." + (let ((user-defaults (read-regexp-defaults))) + (unless (eq user-defaults t) + (setq defaults user-defaults) + (message "cmd: %s defaults: %S" this-command defaults))) + (let* ((default (if (consp defaults) (car defaults) defaults)) (suggestions (if (listp defaults) defaults (list defaults))) (suggestions --=-=-= Content-Type: text/plain ---------------------------------------------------------------- *Messages* Global-Hi-Lock mode enabled Mark saved where search started cmd: highlight-regexp defaults: "\\_" cmd: highlight-regexp defaults: "\\_" cmd: highlight-phrase defaults: "min-colors" cmd: multi-occur-in-matching-buffers defaults: ":background" cmd: exit-minibuffer defaults: nil Searched 1 buffer; 10 matches for `yellow' --=-=-=--