home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / help-macro.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  3.4 KB  |  89 lines

  1. ;From utkcs2!emory!swrinde!zaphod.mps.ohio-state.edu!usc!ucsd!ucbvax!indetech.COM!lrs Wed Jun  6 08:05:14 EDT 1990
  2. ;Article 4365 of comp.emacs:
  3. ;Path: utkcs2!emory!swrinde!zaphod.mps.ohio-state.edu!usc!ucsd!ucbvax!indetech.COM!lrs
  4. ;>From: lrs@indetech.COM (Lynn Slater)
  5. ;Newsgroups: comp.emacs
  6. ;Subject: Macro to make keymap help screens like that of help-for-help
  7. ;Message-ID: <m0hci5x-0000FAC@fire.indetech.com>
  8. ;Date: 5 Jun 90 17:53:00 GMT
  9. ;Sender: daemon@ucbvax.BERKELEY.EDU
  10. ;Lines: 75
  11. ;
  12. ;The macro below makes help for keymaps such as that used by help-for-help. i.e.
  13. ;  nothing is displayed at first
  14. ;  if a help character is hit, a single line is displayed
  15. ;  if a help character is hit again, a screen is displayed
  16. ;    the screen is scrolled as needed
  17. ;  if a character from the map is hit, the corresponding command is executed.
  18. ;
  19. ;This implimentation supports standard emacs as well as those who move their
  20. ;help key off of C-h using the Baushke/Berlin/Slater mods.
  21. ;
  22. ;I suggest that this be added to help.el
  23.  
  24. (require 'backquote)
  25.  
  26. (defvar help-character "\C-h")                   ;current command string
  27. (defvar help-ch (string-to-char help-character)) ;1-byte, used in help-help lines
  28.  
  29. (defmacro make-help-screen (fname help-line help-text helped-map)
  30.   "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.
  31.    To install the generaded fcn, bind the FNAME function to the help characters
  32. in the HELPED-MAP.
  33.  
  34.   This operation is the same as used by help-for-help.
  35.   This fcn supports the extended help character choices advocated by 
  36.   Mark Baushke, Rich Berlin, and Lynn Slater"
  37.   (` (defun (, fname) ()
  38.        (, help-text)
  39.        (interactive)
  40.        (let ((line-prompt
  41.           (substitute-command-keys (, help-line))))
  42.          (message line-prompt)
  43.          (let ((char (read-char)))
  44.            (if (or (= char ??) (= char help-ch))
  45.            (save-window-excursion
  46.              (switch-to-buffer-other-window "*Help*")
  47.              (erase-buffer)
  48.              (insert (documentation (quote (, fname))))
  49.              (goto-char (point-min))
  50.              (while (memq char (cons help-ch '(?? ?\C-v ?\ ?\177 ?\M-v)))
  51.                (if (memq char '(?\C-v ?\ ))
  52.                (scroll-up))
  53.                (if (memq char '(?\177 ?\M-v))
  54.                (scroll-down))
  55.                (message "%s%s: "
  56.                 line-prompt
  57.                 (if (pos-visible-in-window-p (point-max))
  58.                     "" " or Space to scroll"))
  59.                (let ((cursor-in-echo-area t))
  60.              (setq char (read-char))))))
  61.            (let ((defn (cdr (assq (downcase char) (, helped-map)))))
  62.          (if defn (call-interactively defn) (ding))))))
  63.      ))
  64.  
  65.  
  66. ;Example use:
  67. ;
  68. ;(make-help-screen help-for-empire-redistribute-map
  69. ;          "f m p ?"
  70. ;          "You have discovered the empire tool redistribution commands
  71. ;   From here, you can use the following options:
  72. ;
  73. ;f, C-d    Redistribute food according to min and max desired levels
  74. ;m, C-m    Redistribute military using levels given by ideal-mil fcn
  75. ;p, C-p    Redistribute excess population to highways
  76. ;
  77. ;Please use \\[describe-key] to find out more about any of these keys."
  78. ;          empire-shell-redistribute-map)
  79. ;
  80. ;(define-key empire-shell-redistribute-map help-character 'help-for-empire-redistribute-map)
  81. ;
  82. ;===============================================================
  83. ;Lynn Slater -- lrs@indetech.com or {sun, ames, pacbell}!indetech!lrs
  84. ;42075 Lawrence Place, Fremont Ca 94538
  85. ;Office (415) 438-2048; Home (415) 793-1864; Fax (415) 438-2034
  86. ;===============================================================
  87.  
  88.  
  89.