[A] Switch to ANOTHER buffer

Adrian Aichner adrian at xemacs.org
Wed Oct 28 06:13:16 EDT 2009


Didier Verna <didier at xemacs.org> writes:

>        Hi,
>
> The function switch-to-buffer currently offers the current buffer as a
> completion. This is useless because you don't want to switch to where
> you are, and this can be very annoying, for instance when you have two
> buffers with similar names and want to switch from one to the other with
> a couple of keystrokes.
>
> The following patch fixes this by giving some programmatic control over
> read-buffer's completion list. I'll apply it in a couple of days if
> there is no objection.
>
> The next thing we could do is provide an interactive specification for
> this. I think it would be generally useful (not only in
> switch-to-buffer). Maybe g/G ?
>
>
>
> lisp/ChangeLog addition:
>
> 2009-10-27  Didier Verna  <didier at lrde.epita.fr>
>
> 	* minibuf.el (read-buffer): New optional argument 'exclude' for
> 	excluding buffers from the completion list.
> 	* buffer.el (switch-to-buffer): Don't offer the current buffer in
> 	the completion list.
>
>
> XEmacs 21.5 source patch:
> Diff command:   hg diff -wbB
> Files affected: lisp/minibuf.el lisp/buffer.el
>
> diff -r dfc9fe46c294 lisp/ChangeLog
> --- lisp/ChangeLog	Mon Oct 26 15:41:26 2009 -0600
           ^^^^^^^^^
> +++ lisp/buffer.el	Wed Oct 28 10:25:07 2009 +0100

Hi Didier!

You must be writing your patches by hand ? :-)

As for the proposed extension to interactive spec: Shouldn't that be
coordinated with the GNU project, or would that just be a waste of
effort?

Best regards!

Adrian

> @@ -41,7 +41,11 @@
>  WARNING: This is NOT the way to work on another buffer temporarily
>  within a Lisp program!  Use `set-buffer' instead.  That avoids messing with
>  the window-buffer correspondences."
> -  (interactive "BSwitch to buffer: ")
> +  (interactive
> +   (list (read-buffer "Switch to buffer: "
> +		      (other-buffer (current-buffer))
> +		      nil
> +		      (current-buffer))))
>    ;; #ifdef I18N3
>    ;; #### Doc string should indicate that the buffer name will get
>    ;; translated.
> diff -r dfc9fe46c294 lisp/minibuf.el
> --- lisp/minibuf.el	Mon Oct 26 15:41:26 2009 -0600
> +++ lisp/minibuf.el	Wed Oct 28 10:25:07 2009 +0100
> @@ -39,6 +39,8 @@
>  ;;  (following|preceding)-char. -slb
>  
>  ;;; Code:
> +
> +(require 'cl)
>  
>  (defgroup minibuffer nil
>    "Controling the behavior of the minibuffer."
> @@ -1467,20 +1469,24 @@
>  			       (symbol-name default-value)
>  			     default-value))))
>  
> -(defun read-buffer (prompt &optional default require-match)
> +(defun read-buffer (prompt &optional default require-match exclude)
>    "Read the name of a buffer and return as a string.
>  Prompts with PROMPT.  Optional second arg DEFAULT is value to return if user
>  enters an empty line.  If optional third arg REQUIRE-MATCH is non-nil,
> -only existing buffer names are allowed."
> +only existing buffer names are allowed.  Optional fourth argument EXCLUDE is
> +a buffer or a list of buffers to exclude from the completion list."
> +  (when (bufferp exclude)
> +    (setq exclude (list exclude)))
>    (let ((prompt (if default
>                      (format "%s(default %s) "
>                              (gettext prompt) (if (bufferp default)
>  						 (buffer-name default)
>  					       default))
> -                    prompt))
> -        (alist (mapcar #'(lambda (b) (cons (buffer-name b) b))
> -                       (buffer-list)))
> -        result)
> +		    prompt))
> +	(alist (mapcar #'(lambda (b) (cons (buffer-name b) b))
> +		       (remove-if (lambda (elt) (member elt exclude))
> +				  (buffer-list))))
> +	result)
>      (while (progn
>               (setq result (completing-read prompt alist nil require-match
>  					   nil 'buffer-history 

-- 
Adrian Aichner
 mailto:adrian at xemacs.org
 http://www.xemacs.org/



More information about the XEmacs-Patches mailing list