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, 04 Apr 2008 01:59:19 +0300 Organization: JURTA Message-ID: <873aq2czp4.fsf@jurta.org> References: <87prtiik0l.fsf@jurta.org> <87iqz969fh.fsf@jurta.org> <87od9181m7.fsf@jurta.org> <87lk440z31.fsf@jurta.org> <87od8xccz6.fsf@jurta.org> <87hceouksk.fsf@jurta.org> <87y77zlqji.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 1207264217 7070 80.91.229.12 (3 Apr 2008 23:10:17 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 3 Apr 2008 23:10:17 +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 Apr 04 01:10:49 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 1JhYa0-0004Es-S8 for ged-emacs-devel@m.gmane.org; Fri, 04 Apr 2008 01:10:49 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JhYZO-0006OI-0l for ged-emacs-devel@m.gmane.org; Thu, 03 Apr 2008 19:10:10 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JhYY3-0005sV-Cu for emacs-devel@gnu.org; Thu, 03 Apr 2008 19:08:47 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JhYY1-0005rO-Hf for emacs-devel@gnu.org; Thu, 03 Apr 2008 19:08:46 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JhYY1-0005rL-9F for emacs-devel@gnu.org; Thu, 03 Apr 2008 19:08:45 -0400 Original-Received: from relay03.kiev.sovam.com ([62.64.120.201]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JhYY0-0003Qs-GA for emacs-devel@gnu.org; Thu, 03 Apr 2008 19:08:45 -0400 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by relay03.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1JhYXy-000DSu-JC; Fri, 04 Apr 2008 02:08:43 +0300 In-Reply-To: (Stefan Monnier's message of "Sun, 30 Mar 2008 22:11:24 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-Scanner-Signature: c94a7b229bbd1ed8a35d1eff8ed0aa98 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 2566 [Apr 04 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 6.x (1) 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:94297 Archived-At: > Actually, looking at the code some more, I'd suggest to add > a `predicate' arg to `read-buffer' and then use it in switch-to-buffer > (which would clearly need to be changed not to use a string-spec but > a lisp-spec for its interactive spec). Adding a new argument to `read-buffer' will cause the argument list mismatch between `read-buffer' and `read-buffer-function', and calling `read-buffer-function' with an additional argument will break existing code. But I now have an idea how to accomplish this task without adding a new argument to `read-buffer'. The patch below adds a new function `read-buffer-to-switch' that binds `minibuffer-default-add-function' to `minibuffer-default-add-buffers' that omits the current buffer from the list of defaults before calling `read-buffer': Index: src/buffer.c =================================================================== RCS file: /sources/emacs/emacs/src/buffer.c,v retrieving revision 1.557 diff -c -r1.557 buffer.c *** src/buffer.c 2 Apr 2008 20:15:11 -0000 1.557 --- src/buffer.c 3 Apr 2008 22:56:56 -0000 *************** *** 1767,1773 **** return buf; } ! DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ", doc: /* Select buffer BUFFER in the current window. If BUFFER does not identify an existing buffer, then this function creates a buffer with that name. --- 1767,1774 ---- return buf; } ! DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, ! "(list (read-buffer-to-switch \"Switch to buffer: \"))", doc: /* Select buffer BUFFER in the current window. If BUFFER does not identify an existing buffer, then this function creates a buffer with that name. Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.967 diff -c -r1.967 files.el *** lisp/files.el 3 Apr 2008 20:06:45 -0000 1.967 --- lisp/files.el 3 Apr 2008 22:57:00 -0000 *************** *** 1033,1038 **** --- 1033,1064 ---- (rename-file encoded new-encoded ok-if-already-exists) newname)) + (defun minibuffer-default-add-buffers () + "Return a list of all buffer completions without the current buffer. + This function is used to add all elements of the buffer name 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))) + ;; Remove the current buffer from the list of buffer completions + (setq all (cdr all)) + (if (listp def) + (append def all) + (cons def (delete def all))))) + + (defun read-buffer-to-switch (prompt) + "Read the name of a buffer to switch to and return as a string. + It is intended for `switch-to-buffer' family of commands since they + need to omit the name of current buffer from the list of defaults." + (minibuffer-with-setup-hook + (lambda () + (set (make-local-variable 'minibuffer-default-add-function) + 'minibuffer-default-add-buffers)) + (read-buffer prompt (other-buffer (current-buffer))))) + (defun switch-to-buffer-other-window (buffer &optional norecord) "Select buffer BUFFER in another window. If BUFFER does not identify an existing buffer, then this function *************** *** 1047,1053 **** This uses the function `display-buffer' as a subroutine; see its documentation for additional customization information." ! (interactive "BSwitch to buffer in other window: ") (let ((pop-up-windows t) ;; Don't let these interfere. same-window-buffer-names same-window-regexps) --- 1073,1080 ---- This uses the function `display-buffer' as a subroutine; see its documentation for additional customization information." ! (interactive ! (list (read-buffer-to-switch "Switch to buffer in other window: "))) (let ((pop-up-windows t) ;; Don't let these interfere. same-window-buffer-names same-window-regexps) *************** *** 1061,1067 **** This uses the function `display-buffer' as a subroutine; see its documentation for additional customization information." ! (interactive "BSwitch to buffer in other frame: ") (let ((pop-up-frames t) same-window-buffer-names same-window-regexps) (prog1 --- 1088,1095 ---- This uses the function `display-buffer' as a subroutine; see its documentation for additional customization information." ! (interactive ! (list (read-buffer-to-switch "Switch to buffer in other frame: "))) (let ((pop-up-frames t) same-window-buffer-names same-window-regexps) (prog1 -- Juri Linkov http://www.jurta.org/emacs/