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