home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / gnu / emacs / help / 3887 < prev    next >
Encoding:
Text File  |  1992-08-30  |  3.8 KB  |  91 lines

  1. Newsgroups: gnu.emacs.help
  2. Path: sparky!uunet!ulowell!news.bbn.com!usc!cs.utexas.edu!hellgate.utah.edu!eeide
  3. From: eeide%asylum.cs.utah.edu@cs.utah.edu (Eric Eide)
  4. Subject: Re: switch-to-buffer : how to require an existing buffer ??
  5. Message-ID: <EEIDE.92Aug29190505@asylum.cs.utah.edu>
  6. In-reply-to: delacour@waxwing.parc.xerox.com's message of 26 Aug 92 11:50:23
  7. Organization: University of Utah Department of Computer Science
  8. References: <DELACOUR.92Aug26115023@waxwing.parc.xerox.com>
  9. Date: 29 Aug 92 19:05:05
  10. Lines: 79
  11.  
  12. >Does somebody know the right way to have switch-to-buffer and
  13. >switch-to-buffer-other-window require an existing buffer ?
  14.  
  15. Below are the functions that I use.  Have fun.
  16.  
  17. -------------------------------------------------------------------------------
  18.  
  19. (global-set-key "\C-xb" 'switch-to-existing-buffer)
  20. (global-set-key "\C-x4b" 'switch-to-existing-buffer-other-window)
  21.  
  22. ;;;
  23. ;;; Command switch-to-existing-buffer
  24. ;;;
  25. ;;; switch-to-existing-buffer is a replacement for switch-to-buffer.  Unlike
  26. ;;; switch-to-buffer, when used interactively this function does not allow the
  27. ;;; user to create a new buffer.
  28. ;;;
  29.  
  30. (defun switch-to-existing-buffer (buffer &optional norecord)
  31.   "Select buffer BUFFER in the current window.  BUFFER may be a buffer or a
  32. buffer name.  Optional second arg NORECORD non-nil means do not put this buffer
  33. at the front of the list of recently selected ones.
  34.  
  35. When called interactively, this function will not create a new buffer.
  36.  
  37. WARNING: This is NOT the way to work on another buffer temporarily within a
  38. Lisp program!  Use `set-buffer' instead.  That avoids messing with the
  39. window-buffer correspondences."
  40.   ;; NOTE that (interactive "bSwitch to buffer: ") would use the current buffer
  41.   ;; as the default -- not very useful here.
  42.   (interactive (list (read-buffer "Switch to buffer: "
  43.                   (buffer-name (other-buffer)) t)))
  44.   (switch-to-buffer buffer norecord))
  45.  
  46. ;;;
  47. ;;; Command switch-to-existing-buffer-other-window
  48. ;;;
  49. ;;; switch-to-existing-buffer-other-window is a replacement for switch-to-
  50. ;;; buffer-other-window.  Unlike switch-to-buffer-other-window, when used
  51. ;;; interactively this function does not allow the user to create a new buffer.
  52. ;;;
  53.  
  54. (defun switch-to-existing-buffer-other-window (buffer)
  55.   "Select buffer BUFFER in another window.  When called interactively, this
  56. function will not create a new buffer."
  57.   ;; NOTE that (interactive "bSwitch to buffer in other window: ") would use
  58.   ;; the current buffer as the default -- not very useful here.
  59.   (interactive (list (read-buffer "Switch to buffer in other window: "
  60.                   (buffer-name (other-buffer)) t)))
  61.   (let ((pop-up-windows t))
  62.     (pop-to-buffer buffer t)))
  63.  
  64. ;;;
  65. ;;; Function print-help-return-message
  66. ;;;
  67. ;;; This is a hacked version of print-help-return-messge from the GNU Emacs
  68. ;;; file help.el; it looks for my buffer-switching functions rather than the
  69. ;;; standard ones.
  70. ;;;
  71.  
  72. (defun print-help-return-message (&optional function)
  73.   "Display or return message saying how to restore windows after help command.
  74. Computes a message and applies the argument FUNCTION to it.
  75. If FUNCTION is nil, applies `message' to it, thus printing it."
  76.   (and (not (get-buffer-window standard-output))
  77.        (funcall    (or function 'message)
  78.         (substitute-command-keys
  79.          (if (one-window-p t)
  80.              (if pop-up-windows
  81.              "Type \\[delete-other-windows] to remove help window."
  82.                "Type \\[switch-to-existing-buffer] RET to remove help window.")
  83.            "Type \\[switch-to-existing-buffer-other-window] RET to restore old contents of help window.")))))
  84.  
  85. ;; End of functions.
  86.  
  87. --
  88. -------------------------------------------------------------------------------
  89. Eric Eide          |          University of Utah Department of Computer Science
  90. eeide@cs.utah.edu  | Buddhist to hot dog vendor: "Make me one with everything."
  91.