unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: 16024@debbugs.gnu.org
Subject: bug#16024: 24.3.50; [PATCH] `switch-to-buffer*': prefix arg kills original buffer
Date: Sun, 1 Dec 2013 19:04:14 -0800 (PST)	[thread overview]
Message-ID: <76fd89bf-1c52-4fad-887c-55666f6392f2@default> (raw)

[-- Attachment #1: Type: text/plain, Size: 473 bytes --]

The attached patch makes `switch-to-buffer(-other-(window|frame))'
with a prefix arg act analogously to `find-alternate-file': the buffer
current before the switch is killed.

In GNU Emacs 24.3.50.2 (i686-pc-mingw32)
 of 2013-11-28 on LEG570
Bzr revision: 115271 rgm@gnu.org-20131128203155-qjc1xsp19z2k64b2
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --enable-checking 'CFLAGS=-O0 -g3' CPPFLAGS=-DGLYPH_DEBUG=1'

[-- Attachment #2: window-2013-12-01.patch --]
[-- Type: application/octet-stream, Size: 7936 bytes --]

diff -cw window.el window-patched-2013-12-01.el
*** window.el	Sun Dec  1 18:40:12 2013
--- window-patched-2013-12-01.el	Sun Dec  1 18:52:15 2013
***************
*** 6442,6448 ****
    :group 'windows
    :version "24.3")
  
! (defun switch-to-buffer (buffer-or-name &optional norecord force-same-window)
    "Display buffer BUFFER-OR-NAME in the selected window.
  
  WARNING: This is NOT the way to work on another buffer temporarily
--- 6442,6448 ----
    :group 'windows
    :version "24.3")
  
! (defun switch-to-buffer (buffer-or-name &optional norecord force-same-window replace)
    "Display buffer BUFFER-OR-NAME in the selected window.
  
  WARNING: This is NOT the way to work on another buffer temporarily
***************
*** 6459,6464 ****
--- 6459,6467 ----
  determines whether to request confirmation before creating a new
  buffer.
  
+ With a prefix argument, kill the buffer that was current before the
+ switch.
+ 
  BUFFER-OR-NAME may be a buffer, a string (a buffer name), or nil.
  If BUFFER-OR-NAME is a string that does not identify an existing
  buffer, create a buffer with that name.  If BUFFER-OR-NAME is
***************
*** 6472,6485 ****
  must be displayed in the selected window; if that is impossible,
  signal an error rather than calling `pop-to-buffer'.
  
  The option `switch-to-buffer-preserve-window-point' can be used
  to make the buffer appear at its last position in the selected
  window.
  
  Return the buffer switched to."
    (interactive
!    (list (read-buffer-to-switch "Switch to buffer: ") nil 'force-same-window))
!   (let ((buffer (window-normalize-buffer-to-switch-to buffer-or-name)))
      (cond
       ;; Don't call set-window-buffer if it's not needed since it
       ;; might signal an error (e.g. if the window is dedicated).
--- 6475,6497 ----
  must be displayed in the selected window; if that is impossible,
  signal an error rather than calling `pop-to-buffer'.
  
+ Optional argument REPLACE non-nil means kill the buffer that was
+ current before the switch.
+ 
  The option `switch-to-buffer-preserve-window-point' can be used
  to make the buffer appear at its last position in the selected
  window.
  
  Return the buffer switched to."
    (interactive
!    (list (read-buffer-to-switch (if current-prefix-arg
!                                     "Replace here with buffer: "
!                                   "Switch to buffer: "))
!          nil
!          'force-same-window
!          current-prefix-arg))
!   (let ((curr-buf (current-buffer))
!         (buffer (window-normalize-buffer-to-switch-to buffer-or-name)))
      (cond
        ;; Don't call set-window-buffer if it's not needed since it
        ;; might signal an error (e.g. if the window is dedicated).
***************
*** 6505,6516 ****
  	  ;; window (Bug#4041).
  	  (set-window-start (selected-window) (nth 1 entry) t)
  	  (set-window-point nil (nth 2 entry))))))
! 
      (unless norecord
        (select-window (selected-window)))
      (set-buffer buffer)))
  
! (defun switch-to-buffer-other-window (buffer-or-name &optional norecord)
    "Select the buffer specified by BUFFER-OR-NAME in another window.
  BUFFER-OR-NAME may be a buffer, a string (a buffer name), or
  nil.  Return the buffer switched to.
--- 6517,6528 ----
             ;; window (Bug#4041).
             (set-window-start (selected-window) (nth 1 entry) t)
             (set-window-point nil (nth 2 entry))))))
!     (when replace (kill-buffer curr-buf))
      (unless norecord
        (select-window (selected-window)))
      (set-buffer buffer)))
  
! (defun switch-to-buffer-other-window (buffer-or-name &optional norecord replace)
    "Select the buffer specified by BUFFER-OR-NAME in another window.
  BUFFER-OR-NAME may be a buffer, a string (a buffer name), or
  nil.  Return the buffer switched to.
***************
*** 6520,6525 ****
--- 6532,6540 ----
  determines whether to request confirmation before creating a new
  buffer.
  
+ With a prefix argument, kill the buffer that was current before the
+ switch.
+ 
  If BUFFER-OR-NAME is a string and does not identify an existing
  buffer, create a new buffer with that name.  If BUFFER-OR-NAME is
  nil, switch to the buffer returned by `other-buffer'.
***************
*** 6527,6540 ****
  Optional second argument NORECORD non-nil means do not put this
  buffer at the front of the list of recently selected ones.
  
  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))
      (pop-to-buffer buffer-or-name t norecord)))
  
! (defun switch-to-buffer-other-frame (buffer-or-name &optional norecord)
    "Switch to buffer BUFFER-OR-NAME in another frame.
  BUFFER-OR-NAME may be a buffer, a string (a buffer name), or
  nil.  Return the buffer switched to.
--- 6542,6564 ----
  Optional second argument NORECORD non-nil means do not put this
  buffer at the front of the list of recently selected ones.
  
+ Optional argument REPLACE non-nil means kill the buffer that was
+ current before the switch.
+ 
  This uses the function `display-buffer' as a subroutine; see its
  documentation for additional customization information."
    (interactive
!    (list (read-buffer-to-switch (if current-prefix-arg
!                                     "Replace with buffer (other window): "
!                                   "Switch to buffer in other window: "))
!          nil
!          current-prefix-arg))
!   (let ((curr-buf (current-buffer))
!         (pop-up-windows t))
!     (when replace (kill-buffer curr-buf))
      (pop-to-buffer buffer-or-name t norecord)))
  
! (defun switch-to-buffer-other-frame (buffer-or-name &optional norecord replace)
    "Switch to buffer BUFFER-OR-NAME in another frame.
  BUFFER-OR-NAME may be a buffer, a string (a buffer name), or
  nil.  Return the buffer switched to.
***************
*** 6544,6549 ****
--- 6568,6576 ----
  determines whether to request confirmation before creating a new
  buffer.
  
+ With a prefix argument, kill the buffer that was current before the
+ switch.
+ 
  If BUFFER-OR-NAME is a string and does not identify an existing
  buffer, create a new buffer with that name.  If BUFFER-OR-NAME is
  nil, switch to the buffer returned by `other-buffer'.
***************
*** 6551,6561 ****
  Optional second arg NORECORD non-nil means do not put this
  buffer at the front of the list of recently selected ones.
  
  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: ")))
!   (pop-to-buffer buffer-or-name display-buffer--other-frame-action norecord))
  \f
  (defun set-window-text-height (window height)
    "Set the height in lines of the text display area of WINDOW to HEIGHT.
--- 6578,6598 ----
  Optional second arg NORECORD non-nil means do not put this
  buffer at the front of the list of recently selected ones.
  
+ Optional argument REPLACE non-nil means kill the buffer that was
+ current before the switch.
+ 
  This uses the function `display-buffer' as a subroutine; see its
  documentation for additional customization information."
    (interactive
!    (list (read-buffer-to-switch (if current-prefix-arg
!                                     "Replace with buffer (other frame): "
!                                   "Switch to buffer in other frame: "))
!          nil
!          current-prefix-arg))
!   (let ((curr-buf (current-buffer))
!         (pop-up-windows t))
!     (when replace (kill-buffer curr-buf))
!     (pop-to-buffer buffer-or-name display-buffer--other-frame-action norecord)))
  \f
  (defun set-window-text-height (window height)
    "Set the height in lines of the text display area of WINDOW to HEIGHT.

             reply	other threads:[~2013-12-02  3:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-02  3:04 Drew Adams [this message]
2014-02-10  4:08 ` bug#16024: 24.3.50; [PATCH] `switch-to-buffer*': prefix arg kills original buffer Lars Ingebrigtsen
2014-02-10  5:20   ` Drew Adams
2014-02-11 11:56     ` Lars Ingebrigtsen

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=76fd89bf-1c52-4fad-887c-55666f6392f2@default \
    --to=drew.adams@oracle.com \
    --cc=16024@debbugs.gnu.org \
    /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).