🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #98785

Macro to build dynamic help screens

#98785
From: Lynn Slater x2048
Date: Tue, 26 Feb 1991 17:09
97 lines
4688 bytes
;;;;;;;;;;;;;;;;;;;;;;;;;;; -*- Mode: Emacs-Lisp -*- ;;;;;;;;;;;;;;;;;;;;;;;;;;
;; help-screen.el -- Makes command line help such as help-for-help
;; AFSID           : $__Header$
;; Author          : Lynn Slater
;; Created On      : Mon Oct  1 11:42:39 1990
;; Last Modified By: Lynn Slater x2048
;; Last Modified On: Tue Feb 26 09:08:15 1991
;; Update Count    : 5
;; Status          : Unknown, Use with caution!
;; 
;; PURPOSE
;; 	This file supplies the macro make-help-screen which constructs
;; single character dispatching with browsable help such as that provided
;; by help-for-help. This can be used to make many modes easier to use; for
;; example, the Gnu Emacs Empire Tool uses this for every "nested" mode map
;; called from the main mode map.
;; TABLE OF CONTENTS
;; HISTORY
;; 22-Jan-1991		Lynn Slater x2048	
;;    Last Modified: Mon Oct  1 11:43:52 1990 #3 (Lynn Slater)
;;    documented better
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;(require 'help)
(provide 'help-screen)

(defvar help-character "\C-h")			; current command string
(defvar help-ch help-char)			; current command character
						; (an integer)

(defmacro make-help-screen (fname help-line help-text helped-map)
  "Constructs function FNAME that when invoked shows HELP-LINE and if a help
character is requested, shows HELP-TEXT. The user is prompted for a character
from the HELPED-MAP and the corresponding interactive function is executed.

This operation is the same as used by help-for-help.
This fcn supports the extended help character choices advocated by 
Mark Baushke, Rich Berlin, and Lynn Slater"
  (` (defun (, fname) ()
	   (, help-text)
	   (interactive)
	   (let ((line-prompt
		  (substitute-command-keys (, help-line))))
	     (message line-prompt)
	     (let ((char (read-char)))
	       (if (or (= char ??) (= char help-ch))
		   (save-window-excursion
		     (switch-to-buffer-other-window "*Help*")
		     (erase-buffer)
		     (insert (documentation (quote (, fname))))
		     (goto-char (point-min))
		     (while (memq char (cons help-ch '(?? ?\C-v ?\ ?\177 ?\M-v)))
		       (if (memq char '(?\C-v ?\ ))
			   (scroll-up))
		       (if (memq char '(?\177 ?\M-v))
			   (scroll-down))
		       (message "%s%s: "
				line-prompt
				(if (pos-visible-in-window-p (point-max))
				    "" " or Space to scroll"))
		       (let ((cursor-in-echo-area t))
			 (setq char (read-char))))))
	       (let ((defn (cdr (assq (downcase char) (, helped-map)))))
		 (if defn
		     (if (keymapp defn)
			 (error "sorry, this command cannot be run from the help screen. Start over.")
		       (call-interactively defn))
		   (ding))))))
     ))


;;-> ***********************  Example of use *********************************

;;->(make-help-screen help-for-empire-redistribute-map
;;->		  "c:civ m:mil p:population f:food ?"
;;->		  "You have discovered the GEET redistribution commands
;;->   From here, you can use the following options:
;;->
;;->c	Redistribute civs from overfull sectors into connected underfull ones
;;->	  The functions typically named by empire-ideal-civ-fcn control
;;->          based in part on empire-sector-civ-threshold  
;;->m	Redistribute military using levels given by empire-ideal-mil-fcn
;;->p	Redistribute excess population to highways for max pop growth
;;->	  Excess is any sector so full babies will not be born.
;;->f	Even out food on highways to highway min and leave levels
;;->	  This is good to pump max food to all warehouses/dist pts
;;->
;;->
;;->Use \\[help-for-empire-redistribute-map] for help on redistribution.
;;->Use \\[help-for-empire-extract-map] for help on data extraction.
;;->Please use \\[describe-key] to find out more about any of the other keys."
;;->		  empire-shell-redistribute-map)


;;->  (define-key c-mp "\C-h" 'help-for-empire-redistribute-map)
;;->  (define-key c-mp help-character 'help-for-empire-redistribute-map)
Technical Details
Message-ID: <m0jB8Af-0000ZpC@gira.indetech.com>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbage

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: fb2f1,9bab4e4b477f94be,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1991-02-27 02:32:30 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!elroy.jpl.nasa.gov!swrinde!zaphod.mps.ohio-state.edu!magnus.ircc.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbage
From: lrs@indetech.com (Lynn Slater x2048)
Newsgroups: gnu.emacs.bug
Subject: Macro to build dynamic help screens
Message-ID: <m0jB8Af-0000ZpC@gira.indetech.com>
Date: 26 Feb 91 17:09:00 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 97
Approved: bug-gnu-emacs@prep.ai.mit.edu