From: carlton@scws8.harvard.edu (david carlton)
Newsgroups: gnu.epoch.misc
Subject: Re: looking for Epoch goodies, e.g. screens for completion & compilation
Date: 18 Nov 92 18:42:23 GMT
Article-I.D.: scws8.CARLTON.92Nov18104223
Organization: Citizens for Boysenberry Jam
In-reply-to: nelson@reed.edu's message of 17 Nov 92 23:08:47 GMT

In article <1992Nov17.230847.23183@reed.edu>, nelson@reed.edu (Nelson Minar) writes:

> What I really want is a bit of elisp so that help windows (ie when you
> type M-x apropos mail) come up in seperate screens.

Here's one of the first pieces of Epoch code I wrote.  It even tries
to get the window that it pops up not to overlap with your current
one, though admittedly it doesn't try all _that_ hard.  I require it
in my .emacs if I'm running Epoch, though I suppose that a better way
to do things would just to set the temp-buffer-show-hook in my .emacs
and autoload this when I call check-help-screen-buffer.  Type 'q' to
get out of the screen that it pops up.

david carlton
carlton@husc.harvard.edu

;; Help commands for Epoch.
;;
;; These commands cause help to create a new screen each time it is
;; run, rather than merely a new buffer.
;;
;; by david carlton, carlton@husc.harvard.edu

(provide 'epoch-help)

(defvar help-return-screen nil)		; used to return to the old screen
(defvar help-screen-mode-hooks nil)
(defvar help-screen-mode-map nil)
(defvar help-screen-cursor-glyph 92)	; question-arrow
(defvar help-screen-dimensions "80x24")
(defvar help-screen-xpos 10)
(defvar help-screen-ypos 100)

(defun check-help-screen-buffer (buffer)
  (if (string-equal (buffer-name buffer) "*Help*")
      (create-help-screen buffer)
    (display-buffer buffer)))

(defun create-help-screen (buffer)
  (set-buffer buffer)
  (help-screen-mode)
  (let
      ((help-screen
	(create-screen buffer (get-help-screen-alist))))
    (setq help-return-screen (current-screen))
    (map-screen help-screen)
    (select-screen help-screen)
    (cursor-to-screen (current-screen))))

(defun get-help-screen-alist ()
  (cons (cons 'geometry (get-help-screen-geometry))
	(list (cons 'cursor-glyph help-screen-cursor-glyph))))

(defun get-help-screen-geometry ()
  (let ((screen-dims (screen-information)))
    (concat help-screen-dimensions
	    (if (< (car screen-dims) (- (caddr screen-dims) help-screen-xpos))
		"-"
	      "+")
	    help-screen-xpos
	    "+"
	    help-screen-ypos)))

(defun help-screen-mode ()
  "Mode for help screen created by Epoch"
  (interactive)
  (kill-all-local-variables)
  (use-local-map help-screen-mode-map)
  (setq major-mode 'help-screen-mode)
  (setq mode-name "help-screen")
  (run-hooks 'help-screen-mode-hooks))

(defun create-help-screen-mode-map (keymap)
  (suppress-keymap keymap)
  (define-key keymap "q" 'exit-help-screen-mode)
  (define-key keymap " " 'scroll-up)
  (define-key keymap "\177" 'scroll-down)
  (define-key keymap "s" 'isearch-forward)
  keymap)

(defun exit-help-screen-mode ()
  "Deletes help screen, leaves help-screen-mode"
  (interactive)
  (delete-screen)
  (select-screen help-return-screen)
  (cursor-to-screen help-return-screen))


(defun print-help-return-message (&optional function)
  "Prints help-return-message for help-screen"
  (and (not (get-buffer-window standard-output))
       (funcall (or function 'message)
		"Type q to remove help screen."))) ; should be using
					           ; substitute-command-keys

(if (not help-screen-mode-map)
    (setq help-screen-mode-map
	  (create-help-screen-mode-map (make-keymap))))

(setq temp-buffer-show-hook 'check-help-screen-buffer)
Newsgroups: gnu.epoch.misc,gnu.emacs