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

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