annotate lisp/prim/buffer.el @ 26:441bb1e64a06 r19-15b96

Import from CVS: tag r19-15b96
author cvs
date Mon, 13 Aug 2007 08:51:32 +0200
parents 0293115a14e9
children 131b0175ea99
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
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 4
diff changeset
19 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 4
diff changeset
20 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 4
diff changeset
21 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;; Synched up with: FSF 19.30 buffer.c.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 (defun switch-to-buffer (bufname &optional norecord)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 "Select buffer BUFNAME in the current window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 BUFNAME may be a buffer or a buffer name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 Optional second arg NORECORD non-nil means
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 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
32
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 WARNING: This is NOT the way to work on another buffer temporarily
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 within a Lisp program! Use `set-buffer' instead. That avoids messing with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 the window-buffer correspondences."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (interactive "BSwitch to buffer: ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; #### Doc string should indicate that the buffer name will get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; translated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (if (eq (minibuffer-window) (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (error "Cannot switch buffers in minibuffer window"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (if (window-dedicated-p (selected-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (error "Cannot switch buffers in a dedicated window"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (let (buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (if (null bufname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (setq buf (other-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (setq buf (get-buffer bufname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (if (null buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (setq buf (get-buffer-create bufname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (set-buffer-major-mode buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (push-window-configuration)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (or norecord (record-buffer buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (set-window-buffer (if (eq (selected-window) (minibuffer-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (next-window (minibuffer-window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (selected-window))
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 buf))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defun pop-to-buffer (bufname &optional not-this-window-p on-frame)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "Select buffer BUFNAME in some window, preferably a different one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 If BUFNAME is nil, then some other buffer is chosen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 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
66 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
67 another window even if BUFNAME is already visible in the selected window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 If optional third arg is non-nil, it is the frame to pop to this
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
69 buffer on.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
70 If `focus-follows-mouse' is non-nil, keyboard focus is left unchanged."
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; #ifdef I18N3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; #### Doc string should indicate that the buffer name will get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; translated.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ;; #endif
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
75 ;; This is twisted. It is evil to throw the keyboard focus around
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
76 ;; willy-nilly if the user wants focus-follows-mouse.
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
77 (let ((oldbuf (current-buffer))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
78 buf window frame)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (if (null bufname)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (setq buf (other-buffer (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (setq buf (get-buffer bufname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (if (null buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (setq buf (get-buffer-create bufname))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (set-buffer-major-mode buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (push-window-configuration)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (set-buffer buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (setq window (display-buffer buf not-this-window-p on-frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (setq frame (window-frame window))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 ;; if the display-buffer hook decided to show this buffer in another
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
91 ;; frame, then select that frame, (unless obeying focus-follows-mouse -sb).
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
92 (if (and (not focus-follows-mouse)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
93 (not (eq frame (selected-frame))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (select-frame frame))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (record-buffer buf)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
96 (if (and focus-follows-mouse
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
97 on-frame
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
98 (not (eq on-frame (selected-frame))))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
99 (set-buffer oldbuf)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
100 ;; select-window will modify the internal keyboard focus of XEmacs
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
101 (select-window window))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 buf))