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: Wed, 16 Apr 2008 01:28:45 +0300 Organization: JURTA Message-ID: <87r6d6vjg2.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> <873aq2czp4.fsf@jurta.org> <871w5j2ca1.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 1208300143 16540 80.91.229.12 (15 Apr 2008 22:55:43 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 15 Apr 2008 22:55:43 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Apr 16 00:56:11 2008 connect(): Connection refused 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 1Jlu3v-0002Eg-8O for ged-emacs-devel@m.gmane.org; Wed, 16 Apr 2008 00:55:42 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Jltz0-0004dV-PM for ged-emacs-devel@m.gmane.org; Tue, 15 Apr 2008 18:50:34 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1JltxN-0003mW-N0 for emacs-devel@gnu.org; Tue, 15 Apr 2008 18:48:53 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1JltxM-0003kQ-Fr for emacs-devel@gnu.org; Tue, 15 Apr 2008 18:48:52 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JltxM-0003kG-8x for emacs-devel@gnu.org; Tue, 15 Apr 2008 18:48:52 -0400 Original-Received: from relay02.kiev.sovam.com ([62.64.120.197]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1JltxL-0005R2-Hd for emacs-devel@gnu.org; Tue, 15 Apr 2008 18:48:52 -0400 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by relay02.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1JltxJ-000Mz9-0j; Wed, 16 Apr 2008 01:48:49 +0300 In-Reply-To: (Stefan Monnier's message of "Mon, 07 Apr 2008 11:32:23 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu) X-Scanner-Signature: ad39b63ab710533149c2a2019fd816be 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 2635 [Apr 15 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:95319 Archived-At: > Yes, that's an acceptable solution, but really if there are only > 2 buffers, C-x b TAB should select the only other buffer, so the better > solution is to fix the completion table. On a par with your efforts to move minibuffer stuff to minibuffer.el, I've ported the existing function `internal-complete-buffer' to Lisp and created a new function `internal-complete-buffer-sans-current' to remove the current buffer from the completion table for `C-x b' family of commands. I also considered using `complete-with-action' internally in `internal-complete-buffer' since it uses the same code pattern, but `complete-with-action' doesn't call `all-completions' with the non-nil arg `hide-spaces'. Below is a complete patch that causes `C-x b TAB' to omit the current buffer from the completion table: Index: src/minibuf.c =================================================================== RCS file: /sources/emacs/emacs/src/minibuf.c,v retrieving revision 1.345 diff -c -r1.345 minibuf.c *** src/minibuf.c 9 Apr 2008 19:33:51 -0000 1.345 --- src/minibuf.c 15 Apr 2008 22:27:45 -0000 *************** *** 1944,1967 **** return Qt; } - DEFUN ("internal-complete-buffer", Finternal_complete_buffer, Sinternal_complete_buffer, 3, 3, 0, - doc: /* Perform completion on buffer names. - If the argument FLAG is nil, invoke `try-completion', if it's t, invoke - `all-completions', otherwise invoke `test-completion'. - - The arguments STRING and PREDICATE are as in `try-completion', - `all-completions', and `test-completion'. */) - (string, predicate, flag) - Lisp_Object string, predicate, flag; - { - if (NILP (flag)) - return Ftry_completion (string, Vbuffer_alist, predicate); - else if (EQ (flag, Qt)) - return Fall_completions (string, Vbuffer_alist, predicate, Qt); - else /* assume `lambda' */ - return Ftest_completion (string, Vbuffer_alist, predicate); - } - /* Like assoc but assumes KEY is a string, and ignores case if appropriate. */ DEFUN ("assoc-string", Fassoc_string, Sassoc_string, 2, 3, 0, --- 1944,1949 ---- *************** *** 2220,2226 **** defsubr (&Sread_string); defsubr (&Sread_command); defsubr (&Sread_variable); - defsubr (&Sinternal_complete_buffer); defsubr (&Sread_buffer); defsubr (&Sread_no_blanks_input); defsubr (&Sminibuffer_depth); --- 2202,2207 ---- Index: lisp/minibuffer.el =================================================================== RCS file: /sources/emacs/emacs/lisp/minibuffer.el,v retrieving revision 1.13 diff -c -r1.13 minibuffer.el *** lisp/minibuffer.el 14 Apr 2008 22:04:38 -0000 1.13 --- lisp/minibuffer.el 15 Apr 2008 22:27:03 -0000 *************** *** 730,734 **** --- 730,758 ---- 'completion--file-name-table) "Internal subroutine for `read-file-name'. Do not call this.") + (defun internal-complete-buffer (string predicate flag) + "Perform completion on buffer names. + If the argument FLAG is nil, invoke `try-completion', if it's t, invoke + `all-completions', otherwise invoke `test-completion'. + + The arguments STRING and PREDICATE are as in `try-completion', + `all-completions', and `test-completion'." + (let ((table (mapcar 'buffer-name (buffer-list)))) + (cond + ((null flag) (try-completion string table predicate)) + ((eq flag t) (all-completions string table predicate t)) + (t (test-completion string table predicate))))) + + (defun internal-complete-buffer-sans-current (string predicate flag) + "Perform completion on buffer names excluding the current buffer. + Like `internal-complete-buffer', but removes the current buffer from + the completion list." + (let ((table (mapcar 'buffer-name (delq (other-buffer (current-buffer) t) + (buffer-list))))) + (cond + ((null flag) (try-completion string table predicate)) + ((eq flag t) (all-completions string table predicate t)) + (t (test-completion string table predicate))))) + (provide 'minibuffer) ;;; minibuffer.el ends here Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.970 diff -c -r1.970 files.el *** lisp/files.el 12 Apr 2008 03:14:56 -0000 1.970 --- lisp/files.el 15 Apr 2008 22:27:11 -0000 *************** *** 1033,1038 **** --- 1033,1048 ---- (rename-file encoded new-encoded ok-if-already-exists) newname)) + (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-completion-table) + 'internal-complete-buffer-sans-current)) + (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) --- 1057,1064 ---- 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 --- 1072,1079 ---- 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 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 15 Apr 2008 22:27:01 -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. -- Juri Linkov http://www.jurta.org/emacs/