1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
|
;;;;; -*-coding: iso-8859-1;-*-
;;;;;
;;;;; Copyright (C) 1991-2002 Lysator Academic Computer Association.
;;;;;
;;;;; This file is part of the LysKOM Emacs LISP client.
;;;;;
;;;;; LysKOM is free software; you can redistribute it and/or modify it
;;;;; under the terms of the GNU General Public License as published by
;;;;; the Free Software Foundation; either version 2, or (at your option)
;;;;; any later version.
;;;;;
;;;;; LysKOM is distributed in the hope that it will be useful, but WITHOUT
;;;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;;;;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
;;;;; for more details.
;;;;;
;;;;; You should have received a copy of the GNU General Public License
;;;;; along with LysKOM; see the file COPYING. If not, write to
;;;;; Lysator, c/o ISY, Linkoping University, S-581 83 Linkoping, SWEDEN,
;;;;; or the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
;;;;; MA 02139, USA.
;;;;;
;;;;; Please mail bug reports to bug-lyskom@lysator.liu.se.
;;;;;
;;;; ================================================================
;;;; ================================================================
;;;;
;;;; File: help.el
;;;;
;;;; Functions for formatting help strings in the client
;;;;
(defgroup lyskom-faces nil
"Faces for use in the LysKOM elisp client."
:group 'lyskom)
(defgroup lyskom nil
"Faces for use in the LysKOM elisp client."
:group 'default)
(defface lyskom-help-h1-face '((t (:weight bold :underline t :height 2.0 :family "helvetica")))
"First level header in LysKOM help."
:group 'lyskom-faces)
(defface lyskom-help-h2-face '((t (:weight bold :underline t :height 1.5 :family "helvetica")))
"Second level header in LysKOM help."
:group 'lyskom-faces)
(defface lyskom-help-h3-face '((t (:weight bold :family "helvetica")))
"Third level header in LysKOM help."
:group 'lyskom-faces)
;;; Note that these are duplicated in help-compile.el. Change one and change both!
;;UNUSED: lyskom-help-create-data
(defsubst lyskom-help-create-data (tag attr data)
(list tag attr data))
(defsubst lyskom-help-data-get-tag (data)
(elt data 0))
(defsubst lyskom-help-data-get-attr (attr data)
(cdr (assq attr (elt data 1))))
;;UNUSED: lyskom-help-data-get-attrs
(defsubst lyskom-help-data-get-attrs (data)
(elt data 1))
(defsubst lyskom-help-data-get-data (data)
(elt data 2))
(defvar lyskom-help-format-handlers
'((h1 . lyskom-help-format-h1)
(h2 . lyskom-help-format-h2)
(h3 . lyskom-help-format-h3)
(p . lyskom-help-format-p)
(b . lyskom-help-format-b)
(i . lyskom-help-format-i)
(list . lyskom-help-format-list)
(item . lyskom-help-format-item)
(keymap . lyskom-help-format-keymap)
(inline . lyskom-help-format-inline)
(refer . lyskom-help-format-refer)
(cref . lyskom-help-format-cref)
(section . lyskom-help-format-section)
(call . lyskom-help-call-function)
(TEXT . lyskom-help-format-TEXT))
)
(defun lyskom-help-get-section (section)
(elt (assq section lyskom-help-data) 2))
(defun lyskom-help-show-section (section)
"Format and insert section SECTION."
(lyskom-do-help-format (lyskom-help-get-section section)))
(defun lyskom-do-help-format (data)
"Format ant insert help data DATA."
(let ((inhibit-read-only t))
(cond ((symbolp (car data))
(funcall (cdr (assq (car data) lyskom-help-format-handlers)) data))
(t (lyskom-traverse el
data
(let ((tag (lyskom-help-data-get-tag el)))
(funcall (cdr (assq tag lyskom-help-format-handlers))
el)))))))
(defun lyskom-help-format-text-properties (data props)
(let ((start (point-max-marker)))
(set-marker-insertion-type start nil)
(lyskom-traverse el (lyskom-help-data-get-data data)
(lyskom-do-help-format el))
(add-text-properties start (point-max) props)
(set-marker start nil)))
(defun lyskom-help-format-section (section)
"Format and insert section SECTION."
(lyskom-do-help-format (lyskom-help-data-get-data section)))
(defun lyskom-help-format-h1 (data)
(lyskom-insert "\n\n")
(lyskom-help-format-text-properties data '(face lyskom-help-h1-face))
(lyskom-insert "\n\n"))
(defun lyskom-help-format-h2 (data)
(lyskom-insert "\n")
(lyskom-help-format-text-properties data '(face lyskom-help-h2-face))
(lyskom-insert "\n\n"))
(defun lyskom-help-format-h3 (data)
(lyskom-help-format-text-properties data '(face lyskom-help-h3-face))
(lyskom-insert "\n"))
(defun lyskom-help-format-i (data)
(lyskom-help-format-text-properties data '(face italic)))
(defun lyskom-help-format-b (data)
(lyskom-help-format-text-properties data '(face bold)))
(defun lyskom-help-format-TEXT (data)
(lyskom-insert (cdr data)))
(defun lyskom-help-format-list (data)
(lyskom-insert "\n")
(when (lyskom-help-data-get-attr 'header data)
(lyskom-insert (lyskom-help-data-get-attr 'header data))
(lyskom-insert "\n"))
(lyskom-do-help-format (lyskom-help-data-get-data data))
(lyskom-insert "\n"))
(defun lyskom-help-format-item (data)
(lyskom-insert " * ")
(lyskom-do-help-format (lyskom-help-data-get-data data))
(lyskom-insert "\n"))
(defun lyskom-help-format-keymap (data)
(let ((this-command-keys nil))
(lyskom-insert (lyskom-help t))))
(defun lyskom-help-call-function (data)
(let ((fn (lyskom-help-data-get-attr 'function data)))
(funcall (intern fn))))
(defun lyskom-help-format-refer (data)
(let* ((id (intern (lyskom-help-data-get-attr 'id data)))
(section (lyskom-help-get-section id))
(string (or (lyskom-help-data-get-attr 'prompt section)
(format "%s" id))))
(lyskom-format-insert
"%#2@%#1s"
string
`(face underline
mouse-face highlight
lyskom-button t
lyskom-button-text ""
lyskom-button-type func
lyskom-buffer ,(current-buffer)
lyskom-button-arg (kom-help (,string . ,id)))))
)
(defun lyskom-help-format-cref (data)
(let* ((command (intern (lyskom-help-data-get-attr 'id data)))
(command-name (lyskom-get-string command 'lyskom-command))
(keys (delq nil
(mapcar (lambda (x)
(if (and (arrayp x)
(eq (elt x 0) 'menu-bar))
nil
x))
(where-is-internal command))))
(heading (lyskom-format "%#1@%[%#2s%]%#3?b%[ (%#3s)%]%[%]"
'(face italic)
command-name
(and keys
(mapconcat 'key-description
keys
"; ")))))
(lyskom-insert heading)))
(defun lyskom-help-format-inline (data)
(let* ((id (intern (lyskom-help-data-get-attr 'id data)))
(section (lyskom-help-get-section id)))
(cond (section (lyskom-do-help-format section))
(t (lyskom-insert (format "[%S]" id))))))
(defun lyskom-help-format-p (data)
(let ((start (point-max-marker)))
(set-marker-insertion-type start nil)
(lyskom-traverse el (lyskom-help-data-get-data data)
(lyskom-do-help-format el))
(save-excursion
(save-restriction
(narrow-to-region start (point-max))
(goto-char (point-min))
(while (re-search-forward "^\\s-+" nil t)
(replace-match "" nil nil))
(lyskom-fill-region (point-min) (point-max))))
(lyskom-insert "\n\n")
(set-marker start nil)))
(defvar lyskom-swedish-bindings-reverse)
(defun lyskom-help-on-command (&rest args)
(let* ((cmd (lyskom-read-extended-command))
(specials (lyskom-menu-guess-shortcuts (current-local-map)))
(shortcut nil))
(when cmd
(if (assq cmd specials)
(unless (lyskom-traverse key (cdr (assq cmd specials))
(unless (condition-case nil
(eq (lookup-key (current-local-map) key) cmd)
(error nil))
(lyskom-traverse-break t)))
(setq shortcut
(mapconcat
(lambda (key)
(if (assq key lyskom-swedish-bindings-reverse)
(symbol-name
(cdr (assq key lyskom-swedish-bindings-reverse)))
(single-key-description key)))
(car (cdr (assq cmd specials)))
" ")))
(setq shortcut (delq nil (mapcar (lambda (kd) (unless (symbolp (elt kd 0)) kd))
(where-is-internal cmd)))))
(lyskom-format-insert "\n%#1C%#2?b%[ [%#2s]%]%[%]\n\n%#3s\n\n"
cmd
(if (stringp shortcut)
shortcut
(mapconcat
(lambda (x)
(format "`%s'" (key-description x)))
shortcut ", "))
(documentation cmd)))))
|