unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Juri Linkov <juri@jurta.org>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: emacs-devel@gnu.org
Subject: Re: C-r and C-s in minibuffer should search completion
Date: Fri, 04 Apr 2008 01:59:19 +0300	[thread overview]
Message-ID: <873aq2czp4.fsf@jurta.org> (raw)
In-Reply-To: <jwvbq4vd4rb.fsf-monnier+emacs@gnu.org> (Stefan Monnier's message of "Sun, 30 Mar 2008 22:11:24 -0400")

> 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))
  \f
+ (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/




  reply	other threads:[~2008-04-03 22:59 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-20 19:13 C-r and C-s in minibuffer should search completion Stefan Monnier
2008-03-20 19:35 ` Juri Linkov
2008-03-20 20:07   ` Lennart Borgman (gmail)
2008-03-20 20:38     ` Juri Linkov
2008-03-20 20:54       ` Drew Adams
2008-03-20 23:07         ` Juri Linkov
2008-03-20 22:13   ` Stefan Monnier
2008-03-20 22:27     ` Drew Adams
2008-03-20 23:03     ` Juri Linkov
2008-03-21  1:26       ` Stefan Monnier
2008-03-22  1:17         ` Juri Linkov
2008-03-22 17:04           ` Stefan Monnier
2008-03-23  2:17             ` Juri Linkov
2008-03-23  3:24               ` Stefan Monnier
2008-03-29  1:00   ` Xavier Maillard
2008-03-29 12:30     ` Juri Linkov
2008-03-29 16:23       ` Drew Adams
2008-03-30  0:38         ` Juri Linkov
2008-03-30  2:38           ` Drew Adams
2008-03-20 20:44 ` Drew Adams
2008-03-25 21:44 ` Juri Linkov
2008-03-26  2:31   ` Stefan Monnier
2008-03-26  7:01     ` Drew Adams
2008-03-26 14:41       ` Stefan Monnier
2008-03-26 17:07         ` Drew Adams
2008-03-26 10:56     ` Juri Linkov
2008-03-26 14:47       ` Stefan Monnier
2008-03-27  0:44         ` Juri Linkov
2008-03-27  2:43           ` Stefan Monnier
2008-03-27 23:43             ` Juri Linkov
2008-03-29  4:03               ` Stefan Monnier
2008-03-30  0:44                 ` Juri Linkov
2008-03-30  4:01                   ` Stefan Monnier
2008-03-30 18:32                     ` Juri Linkov
2008-03-30 22:41                       ` Stefan Monnier
2008-03-30 23:50                         ` Juri Linkov
2008-03-31  2:11                           ` Stefan Monnier
2008-04-03 22:59                             ` Juri Linkov [this message]
2008-04-04  1:18                               ` Stefan Monnier
2008-04-06 20:45                                 ` Juri Linkov
2008-04-07 15:32                                   ` Stefan Monnier
2008-04-15 22:28                                     ` Juri Linkov
2008-04-16  2:08                                       ` Stefan Monnier
2008-04-16 23:16                                         ` Juri Linkov
2008-04-17  1:41                                           ` Stefan Monnier
2008-04-17  9:18                                             ` Juri Linkov
2008-04-18  1:07                                               ` Stefan Monnier
2008-04-19 20:11                                                 ` Juri Linkov
2008-04-19 21:10                                                   ` Stefan Monnier
2008-04-19 22:46                                                     ` Juri Linkov
2008-04-20  2:44                                                       ` Stefan Monnier
2008-04-21 21:51                                                         ` Juri Linkov
2008-04-22  3:11                                                           ` Stefan Monnier
2008-04-22 20:59                                                             ` Juri Linkov
2008-04-23  2:28                                                               ` Stefan Monnier
2008-04-21  3:07                                                       ` Richard Stallman
2008-04-21 22:54                                                         ` Juri Linkov
2008-04-22  3:10                                                           ` Stefan Monnier
2008-03-30  0:44                 ` minibuffer-default-add-shell-commands (was: C-r and C-s in minibuffer should search completion) Juri Linkov
2008-03-30  4:08                   ` minibuffer-default-add-shell-commands Stefan Monnier
2008-03-30 18:28                     ` minibuffer-default-add-shell-commands Juri Linkov
2008-03-30 11:30                   ` minibuffer-default-add-shell-commands Reiner Steib
2008-03-30 18:31                     ` minibuffer-default-add-shell-commands Juri Linkov
2008-03-30 20:25                       ` minibuffer-default-add-shell-commands Reiner Steib

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=873aq2czp4.fsf@jurta.org \
    --to=juri@jurta.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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).