From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: C-r and C-s in minibuffer should search completion Date: Fri, 28 Mar 2008 01:43:32 +0200 Organization: JURTA Message-ID: <87lk440z31.fsf@jurta.org> References: <87prtiik0l.fsf@jurta.org> <87iqz969fh.fsf@jurta.org> <87od9181m7.fsf@jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1206662167 14887 80.91.229.12 (27 Mar 2008 23:56:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 27 Mar 2008 23:56:07 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Mar 28 00:56:38 2008 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Jf1xT-0006AY-Rv for ged-emacs-devel@m.gmane.org; Fri, 28 Mar 2008 00:56:36 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jf1ws-0003Ab-Ap for ged-emacs-devel@m.gmane.org; Thu, 27 Mar 2008 19:55:58 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Jf1wF-0002p1-Gc for emacs-devel@gnu.org; Thu, 27 Mar 2008 19:55:19 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Jf1wD-0002ng-N5 for emacs-devel@gnu.org; Thu, 27 Mar 2008 19:55:18 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jf1wD-0002nU-G0 for emacs-devel@gnu.org; Thu, 27 Mar 2008 19:55:17 -0400 Original-Received: from relay01.kiev.sovam.com ([62.64.120.200]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Jf1wC-0006GZ-TS for emacs-devel@gnu.org; Thu, 27 Mar 2008 19:55:17 -0400 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by relay01.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1Jf1w5-0009J7-DE; Fri, 28 Mar 2008 01:55:11 +0200 In-Reply-To: (Stefan Monnier's message of "Wed, 26 Mar 2008 22:43:14 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-Scanner-Signature: e3b942a55251a77f49093e43cd2f7d51 X-DrWeb-checked: yes X-SpamTest-Envelope-From: juri@jurta.org X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Not Detected X-SpamTest-Info: Profiles 2508 [Mar 27 2008] X-SpamTest-Info: helo_type=3 X-SpamTest-Info: {HEADERS: header Content-Type found without required header Content-Transfer-Encoding} X-SpamTest-Method: none X-SpamTest-Rate: 10 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.8-5.1 (or MacOS X 10.2-10.3) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:93674 Archived-At: >> Below is a new patch with a small improvement: it introduces a new >> variable `minibuffer-default-add-p' useful to add more elements to the >> list of defaults several times in chunks when needed (it can keep the >> current state of added elements to the list of defaults): > > OK, then please remove (make-variable-buffer-local > 'minibuffer-default-add-function). And I suggest to change > minibuffer-default-add-p into minibuffer-default-add-done (and to > reverse its default to nil). In the patch below I renamed minibuffer-default-add-p into minibuffer-default-add-done, changed its default to nil, and removed make-variable-buffer-local for minibuffer-default-add-function. Also I moved (setq minibuffer-default-add-done t) to goto-history-element just before the call to minibuffer-default-add-function, so there is no need to set this variable to t in minibuffer-default-add-function explicitly in normal cases. When necessary, minibuffer-default-add-function can nullify minibuffer-default-add-done to be able call this function more than once. > Also the docstring of minibuffer-default-add-function needs to mention > that the function should set minibuffer-default-add-done. minibuffer-default-add-function now doesn't need to set minibuffer-default-add-done any more, so I updated the docstrings accordingly. > This said, I'm wondering when the chunked computation makes sense. > Do you have an example in mind? I don't have a concrete example. When the chunked computation makes sense, a function defined by minibuffer-default-add-function can use a new specific global variable that will count the number of function calls. But this is not necessary now, and the main thing I added is the possibility to call this function more than once, when this functions sets minibuffer-default-add-done to nil. This patch also changes the error message "End of history; no next item" to "End of defaults; no next item" for the end of the list of defaults. Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.912 diff -c -r1.912 simple.el *** lisp/simple.el 26 Mar 2008 03:40:40 -0000 1.912 --- lisp/simple.el 27 Mar 2008 23:35:05 -0000 *************** *** 1304,1313 **** --- 1305,1353 ---- (defvar minibuffer-temporary-goal-position nil) + (defvar minibuffer-default-add-function 'minibuffer-default-add-completions + "Function run by `goto-history-element' before consuming `minibuffer-default'. + This is useful to dynamically add more elements to the list `minibuffer-default' + when `goto-history-element' reaches the end of this list. + Before calling this function `goto-history-element' sets the variable + `minibuffer-default-add-done' to t, so it will call this function only + once. In special cases, when this function needs to be called more + than once, it can set `minibuffer-default-add-done' to nil explicitly, + overriding the setting of this variable to t in `goto-history-element'.") + + (defvar minibuffer-default-add-done nil + "When nil, add more elements to the end of the list of default values. + The value nil causes `goto-history-element' to add more elements to + the list of defaults when it reaches the end of this list. It does + this by calling a function defined by `minibuffer-default-add-function'.") + + (make-variable-buffer-local 'minibuffer-default-add-done) + + (defun minibuffer-default-add-completions () + "Return a list of all completions without the default value. + This function is used to add all elements of the completion table to + the end of the list of defaults just after the default value." + (interactive) + (let ((def minibuffer-default) + (all (all-completions "" + minibuffer-completion-table + minibuffer-completion-predicate + t))) + (if (listp def) + (append def all) + (cons def (delete def all))))) + (defun goto-history-element (nabs) "Puts element of the minibuffer history in the minibuffer. The argument NABS specifies the absolute history position." (interactive "p") + (when (and (not minibuffer-default-add-done) + (functionp minibuffer-default-add-function) + (< nabs (- (if (listp minibuffer-default) + (length minibuffer-default) + 1)))) + (setq minibuffer-default-add-done t + minibuffer-default (funcall minibuffer-default-add-function))) (let ((minimum (if minibuffer-default (- (if (listp minibuffer-default) (length minibuffer-default) *************** *** 1320,1326 **** (minibuffer-contents-no-properties))) (if (< nabs minimum) (if minibuffer-default ! (error "End of history; no next item") (error "End of history; no default available"))) (if (> nabs (length (symbol-value minibuffer-history-variable))) (error "Beginning of history; no preceding item")) --- 1360,1366 ---- (minibuffer-contents-no-properties))) (if (< nabs minimum) (if minibuffer-default ! (error "End of defaults; no next item") (error "End of history; no default available"))) (if (> nabs (length (symbol-value minibuffer-history-variable))) (error "Beginning of history; no preceding item")) Index: lisp/bindings.el =================================================================== RCS file: /sources/emacs/emacs/lisp/bindings.el,v retrieving revision 1.202 diff -c -r1.202 bindings.el *** lisp/bindings.el 26 Mar 2008 03:32:46 -0000 1.202 --- lisp/bindings.el 27 Mar 2008 23:35:36 -0000 *************** *** 650,656 **** "^No later matching history item$" "^No earlier matching history item$" "^End of history; no default available$" ! "^End of history; no next item$" "^Beginning of history; no preceding item$" "^No recursive edit is in progress$" "^Changes to be undone are outside visible portion of buffer$" --- 650,656 ---- "^No later matching history item$" "^No earlier matching history item$" "^End of history; no default available$" ! "^End of defaults; no next item$" "^Beginning of history; no preceding item$" "^No recursive edit is in progress$" "^Changes to be undone are outside visible portion of buffer$" -- Juri Linkov http://www.jurta.org/emacs/