home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_xemacs.idb / usr / freeware / lib / xemacs-20.4 / lisp / prim / buffer.el.z / buffer.el
Encoding:
Text File  |  1998-05-21  |  3.9 KB  |  103 lines

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