annotate lisp/prim/buffer.el @ 0:376386a54a3c r19-14

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