0
|
1 ;;; buffer.el --- buffer routines taken from C
|
|
2 ;;; Copyright (C) 1985-1989, 1992-1995 Free Software Foundation, Inc.
|
|
3 ;;; Copyright (C) 1995 Sun Microsystems.
|
|
4 ;;; Copyright (C) 1995, 1996 Ben Wing.
|
|
5
|
|
6 ;; This file is part of XEmacs.
|
|
7
|
|
8 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
9 ;; under the terms of the GNU General Public License as published by
|
|
10 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
11 ;; any later version.
|
|
12
|
|
13 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
14 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16 ;; General Public License for more details.
|
|
17
|
|
18 ;; You should have received a copy of the GNU General Public License
|
|
19 ;; along with XEmacs; see the file COPYING. If not, write to the Free
|
|
20 ;; Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
21
|
|
22 ;;; Synched up with: FSF 19.30 buffer.c.
|
|
23
|
|
24 ;;; Code:
|
|
25
|
|
26 (defun switch-to-buffer (bufname &optional norecord)
|
|
27 "Select buffer BUFNAME in the current window.
|
|
28 BUFNAME may be a buffer or a buffer name.
|
|
29 Optional second arg NORECORD non-nil means
|
|
30 do not put this buffer at the front of the list of recently selected ones.
|
|
31
|
|
32 WARNING: This is NOT the way to work on another buffer temporarily
|
|
33 within a Lisp program! Use `set-buffer' instead. That avoids messing with
|
|
34 the window-buffer correspondences."
|
|
35 (interactive "BSwitch to buffer: ")
|
|
36 ;; #ifdef I18N3
|
|
37 ;; #### Doc string should indicate that the buffer name will get
|
|
38 ;; translated.
|
|
39 ;; #endif
|
|
40 (if (eq (minibuffer-window) (selected-window))
|
|
41 (error "Cannot switch buffers in minibuffer window"))
|
|
42 (if (window-dedicated-p (selected-window))
|
|
43 (error "Cannot switch buffers in a dedicated window"))
|
|
44 (let (buf)
|
|
45 (if (null bufname)
|
|
46 (setq buf (other-buffer (current-buffer)))
|
|
47 (setq buf (get-buffer bufname))
|
|
48 (if (null buf)
|
|
49 (progn
|
|
50 (setq buf (get-buffer-create bufname))
|
|
51 (set-buffer-major-mode buf))))
|
|
52 (push-window-configuration)
|
|
53 (set-buffer buf)
|
|
54 (or norecord (record-buffer buf))
|
|
55 (set-window-buffer (if (eq (selected-window) (minibuffer-window))
|
|
56 (next-window (minibuffer-window))
|
|
57 (selected-window))
|
|
58 buf)
|
|
59 buf))
|
|
60
|
|
61 (defun pop-to-buffer (bufname &optional not-this-window-p on-frame)
|
|
62 "Select buffer BUFNAME in some window, preferably a different one.
|
|
63 If BUFNAME is nil, then some other buffer is chosen.
|
|
64 If `pop-up-windows' is non-nil, windows can be split to do this.
|
|
65 If optional second arg NOT-THIS-WINDOW-P is non-nil, insist on finding
|
|
66 another window even if BUFNAME is already visible in the selected window.
|
|
67 If optional third arg is non-nil, it is the frame to pop to this
|
|
68 buffer on."
|
|
69 ;; #ifdef I18N3
|
|
70 ;; #### Doc string should indicate that the buffer name will get
|
|
71 ;; translated.
|
|
72 ;; #endif
|
|
73 (let (buf window frame)
|
|
74 (if (null bufname)
|
|
75 (setq buf (other-buffer (current-buffer)))
|
|
76 (setq buf (get-buffer bufname))
|
|
77 (if (null buf)
|
|
78 (progn
|
|
79 (setq buf (get-buffer-create bufname))
|
|
80 (set-buffer-major-mode buf))))
|
|
81 (push-window-configuration)
|
|
82 (set-buffer buf)
|
|
83 (setq window (display-buffer buf not-this-window-p on-frame))
|
|
84 (setq frame (window-frame window))
|
|
85 ;; if the display-buffer hook decided to show this buffer in another
|
|
86 ;; frame, then select that frame.
|
|
87 (if (not (eq frame (selected-frame)))
|
|
88 (select-frame frame))
|
|
89 (record-buffer buf)
|
|
90 (select-window window)
|
|
91 buf))
|