Annotation of 43BSDReno/contrib/emacs-18.55/lisp/helper.el, revision 1.1.1.1

1.1       root        1: ;; helper - utility help package for modes which want to provide help
                      2: ;; without relinquishing control, e.g. `electric' modes.
                      3: 
                      4: ;; Copyright (C) 1985 Free Software Foundation, Inc.
                      5: ;; Principal author K. Shane Hartman
                      6: 
                      7: ;; This file is part of GNU Emacs.
                      8: 
                      9: ;; GNU Emacs is distributed in the hope that it will be useful,
                     10: ;; but WITHOUT ANY WARRANTY.  No author or distributor
                     11: ;; accepts responsibility to anyone for the consequences of using it
                     12: ;; or for whether it serves any particular purpose or works at all,
                     13: ;; unless he says so in writing.  Refer to the GNU Emacs General Public
                     14: ;; License for full details.
                     15: 
                     16: ;; Everyone is granted permission to copy, modify and redistribute
                     17: ;; GNU Emacs, but only under the conditions described in the
                     18: ;; GNU Emacs General Public License.   A copy of this license is
                     19: ;; supposed to have been given to you along with GNU Emacs so you
                     20: ;; can know your rights and responsibilities.  It should be in a
                     21: ;; file named COPYING.  Among other things, the copyright notice
                     22: ;; and this notice must be preserved on all copies.
                     23: 
                     24: 
                     25: (provide 'helper)                      ; hey, here's a helping hand.
                     26: 
                     27: ;; Bind this to a string for <blank> in "... Other keys <blank>".
                     28: ;; Helper-help uses this to construct help string when scrolling.
                     29: ;; Defaults to "return"
                     30: (defvar Helper-return-blurb nil)
                     31: 
                     32: ;; Keymap implementation doesn't work too well for non-standard loops.
                     33: ;; But define it anyway for those who can use it.  Non-standard loops
                     34: ;; will probably have to use Helper-help.  You can't autoload the
                     35: ;; keymap either.
                     36: 
                     37: 
                     38: (defvar Helper-help-map nil)
                     39: (if Helper-help-map
                     40:     nil
                     41:   (setq Helper-help-map (make-keymap))
                     42:   ;(fillarray Helper-help-map 'undefined)
                     43:   (define-key Helper-help-map "m" 'Helper-describe-mode)
                     44:   (define-key Helper-help-map "b" 'Helper-describe-bindings)
                     45:   (define-key Helper-help-map "c" 'Helper-describe-key-briefly)
                     46:   (define-key Helper-help-map "k" 'Helper-describe-key)
                     47:   ;(define-key Helper-help-map "f" 'Helper-describe-function)
                     48:   ;(define-key Helper-help-map "v" 'Helper-describe-variable)
                     49:   (define-key Helper-help-map "?" 'Helper-help-options)
                     50:   (define-key Helper-help-map (char-to-string help-char) 'Helper-help-options)
                     51:   (fset 'Helper-help-map Helper-help-map))
                     52: 
                     53: (defun Helper-help-scroller ()
                     54:   (let ((blurb (or (and (boundp 'Helper-return-blurb)
                     55:                        Helper-return-blurb)
                     56:                   "return")))
                     57:     (save-window-excursion
                     58:       (goto-char (window-start (selected-window)))
                     59:       (if (get-buffer-window "*Help*")
                     60:          (pop-to-buffer "*Help*")
                     61:        (switch-to-buffer "*Help*"))
                     62:       (goto-char (point-min))
                     63:       (let ((continue t) state)
                     64:        (while continue
                     65:          (setq state (+ (* 2 (if (pos-visible-in-window-p (point-max)) 1 0))
                     66:                         (if (pos-visible-in-window-p (point-min)) 1 0)))
                     67:          (message
                     68:            (nth state
                     69:                 '("Space forward, Delete back. Other keys %s"
                     70:                   "Space scrolls forward. Other keys %s"
                     71:                   "Delete scrolls back. Other keys %s"
                     72:                   "Type anything to %s"))
                     73:            blurb)
                     74:          (setq continue (read-char))
                     75:          (cond ((and (memq continue '(?\ ?\C-v)) (< state 2))
                     76:                 (scroll-up))
                     77:                ((= continue ?\C-l)
                     78:                 (recenter))
                     79:                ((and (= continue ?\177) (zerop (% state 2)))
                     80:                 (scroll-down))
                     81:                (t (setq continue nil))))))))
                     82: 
                     83: (defun Helper-help-options ()
                     84:   "Describe help options."
                     85:   (interactive)
                     86:   (message "c (key briefly), m (mode), k (key), b (bindings)")
                     87:   ;(message "c (key briefly), m (mode), k (key), v (variable), f (function)")
                     88:   (sit-for 4))
                     89: 
                     90: (defun Helper-describe-key-briefly (key)
                     91:   "Briefly describe binding of KEYS."
                     92:   (interactive "kDescribe key briefly: ")
                     93:   (describe-key-briefly key)
                     94:   (sit-for 4))
                     95: 
                     96: (defun Helper-describe-key (key)
                     97:   "Describe binding of KEYS."
                     98:   (interactive "kDescribe key: ")
                     99:   (save-window-excursion (describe-key key))
                    100:   (Helper-help-scroller))
                    101: 
                    102: (defun Helper-describe-function ()
                    103:   "Describe a function.  Name read interactively."
                    104:   (interactive)
                    105:   (save-window-excursion (call-interactively 'describe-function))
                    106:   (Helper-help-scroller))
                    107: 
                    108: (defun Helper-describe-variable ()
                    109:   "Describe a variable.  Name read interactively."
                    110:   (interactive)
                    111:   (save-window-excursion (call-interactively 'describe-variable))
                    112:   (Helper-help-scroller))
                    113: 
                    114: (defun Helper-describe-mode ()
                    115:   "Describe the current mode."
                    116:   (interactive)
                    117:   (let ((name mode-name)
                    118:        (documentation (documentation major-mode)))
                    119:     (save-excursion
                    120:       (set-buffer (get-buffer-create "*Help*"))
                    121:       (erase-buffer)
                    122:       (insert name " Mode\n" documentation)))
                    123:   (Helper-help-scroller))
                    124: 
                    125: (defun Helper-describe-bindings ()
                    126:   "Describe local key bindings of current mode."
                    127:   (interactive)
                    128:   (message "Making binding list...")
                    129:   (save-window-excursion (describe-bindings))
                    130:   (Helper-help-scroller))
                    131: 
                    132: (defun Helper-help ()
                    133:   "Provide help for current mode."
                    134:   (interactive)
                    135:   (let ((continue t) c)
                    136:     (while continue
                    137:       (message "Help (Type ? for further options)")
                    138:       (setq c (char-to-string (downcase (read-char))))
                    139:       (setq c (lookup-key Helper-help-map c))
                    140:       (cond ((eq c 'Helper-help-options)
                    141:             (Helper-help-options))
                    142:            ((commandp c)
                    143:             (call-interactively c)
                    144:             (setq continue nil))
                    145:            (t
                    146:             (ding)
                    147:             (setq continue nil))))))
                    148: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.