1 ;; Calculator for GNU Emacs, part II [calc-help.el]
2 ;; Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3 ;; Written by Dave Gillespie, daveg@synaptics.com.
5 ;; This file is part of GNU Emacs.
7 ;; GNU Emacs is distributed in the hope that it will be useful,
8 ;; but WITHOUT ANY WARRANTY. No author or distributor
9 ;; accepts responsibility to anyone for the consequences of using it
10 ;; or for whether it serves any particular purpose or works at all,
11 ;; unless he says so in writing. Refer to the GNU Emacs General Public
12 ;; License for full details.
14 ;; Everyone is granted permission to copy, modify and redistribute
15 ;; GNU Emacs, but only under the conditions described in the
16 ;; GNU Emacs General Public License. A copy of this license is
17 ;; supposed to have been given to you along with GNU Emacs so you
18 ;; can know your rights and responsibilities. It should be in a
19 ;; file named COPYING. Among other things, the copyright notice
20 ;; and this notice must be preserved on all copies.
24 ;; This file is autoloaded from calc-ext.el.
29 (defun calc-Need-calc-help () nil)
32 (defun calc-help-prefix (arg)
33 "This key is the prefix for Calc help functions. See calc-help-for-help."
35 (or calc-dispatch-help (sit-for echo-keystrokes))
36 (let ((key (calc-read-key-sequence
37 (if calc-dispatch-help
38 "Calc Help options: Help, Info, Tutorial, Summary; Key, Function; ?=more"
39 (format "%s (Type ? for a list of Calc Help options)"
40 (key-description (this-command-keys))))
42 (setq key (lookup-key calc-help-map key))
45 (call-interactively key)
49 (defun calc-help-for-help (arg)
50 "You have typed `h', the Calc help character. Type a Help option:
52 B calc-describe-bindings. Display a table of all key bindings.
53 H calc-full-help. Display all `?' key messages at once.
55 I calc-info. Read the Calc manual using the Info system.
56 T calc-tutorial. Read the Calc tutorial using the Info system.
57 S calc-info-summary. Read the Calc summary using the Info system.
59 C calc-describe-key-briefly. Look up the command name for a given key.
60 K calc-describe-key. Look up a key's documentation in the manual.
61 F calc-describe-function. Look up a function's documentation in the manual.
62 V calc-describe-variable. Look up a variable's documentation in the manual.
64 N calc-view-news. Display Calc history of changes.
66 C-c Describe conditions for copying Calc.
67 C-d Describe how you can get a new copy of Calc or report a bug.
68 C-w Describe how there is no warranty for Calc."
70 (if calc-dispatch-help
72 (save-window-excursion
73 (describe-function 'calc-help-for-help)
74 (select-window (get-buffer-window "*Help*"))
76 (message "Calc Help options: Help, Info, ... press SPC, DEL to scroll, C-g to cancel")
77 (memq (car (setq key (calc-read-key t)))
78 '(? ?\C-h ?\C-? ?\C-v ?\M-v)))
80 (if (memq (car key) '(? ?\C-v))
84 (calc-unread-command (cdr key))
85 (calc-help-prefix nil))
86 (let ((calc-dispatch-help t))
87 (calc-help-prefix arg)))
90 (defun calc-describe-copying ()
93 (Info-goto-node "Copying")
96 (defun calc-describe-distribution ()
99 (Info-goto-node "Reporting Bugs")
102 (defun calc-describe-no-warranty ()
105 (Info-goto-node "Copying")
106 (let ((case-fold-search nil))
107 (search-forward " NO WARRANTY"))
112 (defun calc-describe-bindings ()
116 (set-buffer "*Help*")
117 (goto-char (point-min))
118 (if (search-forward "Global bindings:" nil t)
119 (delete-region (match-beginning 0) (point-max)))
120 (goto-char (point-min))
121 (while (re-search-forward "\n[a-z] ESC" nil t)
123 (delete-region (match-beginning 0) (point)))
124 (goto-char (point-min))
125 (while (re-search-forward "\nESC m" nil t)
127 (delete-region (match-beginning 0) (point)))
128 (goto-char (point-min))
129 (while (search-forward "\n\n\n" nil t)
130 (backward-delete-char 1)
132 (goto-char (point-min))
135 "\n[a-z] [0-9]\\(\t\t.*\n\\)\\([a-z] [0-9]\\1\\)*[a-z] \\([0-9]\\)\\1"
137 (let ((dig1 (char-after (1- (match-beginning 1))))
138 (dig2 (char-after (match-beginning 3))))
139 (delete-region (match-end 1) (match-end 0))
140 (goto-char (match-beginning 1))
141 (delete-backward-char 1)
143 (insert (format "%c .. %c" (min dig1 dig2) (max dig1 dig2)))))
144 (goto-char (point-min)))
147 (defun calc-describe-key-briefly (key)
148 (interactive "kDescribe key briefly: ")
149 (calc-describe-key key t)
152 (defun calc-describe-key (key &optional briefly)
153 (interactive "kDescribe key: ")
154 (let ((defn (if (eq (key-binding key) 'calc-dispatch)
155 (let ((key2 (calc-read-key-sequence
156 (format "Describe key briefly: %s-"
157 (key-description key))
159 (setq key (concat key key2))
160 (lookup-key calc-dispatch-map key2))
161 (if (eq (key-binding key) 'calc-help-prefix)
162 (let ((key2 (calc-read-key-sequence
163 (format "Describe key briefly: %s-"
164 (key-description key))
166 (setq key (concat key key2))
167 (lookup-key calc-help-map key2))
171 (while (or (equal key "I") (equal key "H"))
174 (setq hyp (not hyp)))
175 (setq key (read-key-sequence (format "Describe key%s:%s%s "
176 (if briefly " briefly" "")
179 defn (key-binding key)))
180 (let ((desc (key-description key))
182 (if (string-match "^ESC " desc)
183 (setq desc (concat "M-" (substring desc 4))))
184 (while (string-match "^M-# \\(ESC \\|C-\\)" desc)
185 (setq desc (concat "M-# " (substring desc (match-end 0)))))
187 (let ((msg (save-excursion
188 (set-buffer (get-buffer-create "*Calc Summary*"))
189 (if (= (buffer-size) 0)
191 (message "Reading Calc summary from manual...")
192 (save-window-excursion
195 (Info-goto-node "Summary")
196 (goto-char (point-min))
198 (copy-to-buffer "*Calc Summary*"
201 (setq case-fold-search nil)
202 (re-search-forward "^\\(.*\\)\\[\\.\\. a b")
203 (setq calc-summary-indentation
204 (- (match-end 1) (match-beginning 1)))))
205 (goto-char (point-min))
206 (setq target (if (and (string-match "[0-9]\\'" desc)
207 (not (string-match "[d#]" desc)))
208 (concat (substring desc 0 -1) "0-9")
210 (if (re-search-forward
211 (format "\n%s%s%s%s[ a-zA-Z]"
212 (make-string (+ calc-summary-indentation 9)
214 (if (string-match "M-#" desc) " "
216 (if hyp "I H " " I ")
218 (regexp-quote target)
219 (make-string (max (- 6 (length target)) 0)
224 (forward-char calc-summary-indentation)
227 (buffer-substring pt (point)))))))
229 (let ((args (substring msg 0 9))
230 (keys (substring msg 9 19))
231 (prompts (substring msg 19 38))
233 (cmd (substring msg 40))
235 (if (string-match "\\` +" args)
236 (setq args (substring args (match-end 0))))
237 (if (string-match " +\\'" args)
238 (setq args (substring args 0 (match-beginning 0))))
239 (if (string-match "\\` +" keys)
240 (setq keys (substring keys (match-end 0))))
241 (if (string-match " +\\'" keys)
242 (setq keys (substring keys 0 (match-beginning 0))))
243 (if (string-match " [0-9,]+\\'" prompts)
244 (setq notes (substring prompts (1+ (match-beginning 0)))
245 prompts (substring prompts 0 (match-beginning 0))))
246 (if (string-match " +\\'" prompts)
247 (setq prompts (substring prompts 0 (match-beginning 0))))
248 (if (string-match "\\` +" prompts)
249 (setq prompts (substring prompts (match-end 0))))
251 "%s: %s%s`%s'%s%s %s%s"
253 "\\`\\(calc-[-a-zA-Z0-9]+\\) *\\(.*\\)\\'"
255 (prog1 (math-match-substring cmd 1)
256 (setq cmd (math-match-substring cmd 2)))
258 args (if (equal args "") "" " ")
260 (if (equal prompts "") "" " ") prompts
261 (if (equal cmd "") "" " => ") cmd))
262 (message "%s%s%s runs %s%s"
263 (if inv "I " "") (if hyp "H " "") desc
265 (if (equal notes "") ""
266 (format " (?=notes %s)" notes)))
267 (let ((key (calc-read-key t)))
268 (if (eq (car key) ??)
270 (message "No notes for this command")
271 (while (string-match "," notes)
272 (aset notes (match-beginning 0) ? ))
273 (setq notes (sort (car (read-from-string
274 (format "(%s)" notes)))
276 (with-output-to-temp-buffer "*Help*"
277 (princ (format "%s\n\n" msg))
278 (set-buffer "*Calc Summary*")
279 (re-search-forward "^ *NOTES")
282 (format "^ *%d\\. " (car notes)))
286 (or (re-search-forward "^ ? ?[0-9]+\\. " nil t)
287 (goto-char (point-max)))
289 (princ (buffer-substring pt (point))))
290 (setq notes (cdr notes)))
291 (print-help-return-message)))
292 (calc-unread-command (cdr key)))))
293 (if (or (null defn) (integerp defn))
294 (message "%s is undefined" desc)
295 (message "%s runs the command %s"
297 (if (symbolp defn) defn (prin1-to-string defn))))))
298 (if inv (setq desc (concat "I " desc)))
299 (if hyp (setq desc (concat "H " desc)))
300 (calc-describe-thing desc "Key Index" nil
301 (string-match "[A-Z][A-Z][A-Z]" desc)))))
304 (defun calc-describe-function (&optional func)
307 (setq func (intern (completing-read "Describe function: "
308 obarray nil t "calcFunc-"))))
309 (setq func (symbol-name func))
310 (if (string-match "\\`calc-." func)
311 (calc-describe-thing func "Command Index")
312 (calc-describe-thing (if (string-match "\\`calcFunc-." func)
318 (defun calc-describe-variable (&optional var)
321 (setq var (intern (completing-read "Describe variable: "
322 obarray nil t "var-"))))
323 (setq var (symbol-name var))
324 (calc-describe-thing var "Variable Index"
325 (if (string-match "\\`var-." var)
330 (defun calc-describe-thing (thing where &optional target not-quoted)
331 (message "Looking for `%s' in %s..." thing where)
332 (let ((savewin (current-window-configuration)))
334 (Info-goto-node where)
335 (or (let ((case-fold-search nil))
336 (re-search-forward (format "\n\\* +%s: \\(.*\\)\\."
337 (regexp-quote thing))
339 (and (string-match "\\`\\([a-z ]*\\)[0-9]\\'" thing)
340 (re-search-forward (format "\n\\* +%s[01]-9: \\(.*\\)\\."
341 (substring thing 0 -1))
343 (setq thing (format "%s9" (substring thing 0 -1))))
346 (set-window-configuration savewin)
347 (error "Can't find `%s' in %s" thing where)))
349 (Info-goto-node (buffer-substring (match-beginning 1) (match-end 1))))
350 (or (let ((case-fold-search nil))
351 (or (search-forward (format "\\[`%s'\\]\\|(`%s')\\|\\<The[ \n]`%s'"
354 (or target thing)) nil t)
356 (let ((case-fold-search t))
357 (search-forward (or target thing) nil t)))
358 (search-forward (format "`%s'" (or target thing)) nil t)
359 (search-forward (or target thing) nil t)))
360 (let ((case-fold-search t))
361 (or (search-forward (format "\\[`%s'\\]\\|(`%s')\\|\\<The[ \n]`%s'"
364 (or target thing)) nil t)
365 (search-forward (format "`%s'" (or target thing)) nil t)
366 (search-forward (or target thing) nil t))))
368 (message "Found `%s' in %s" thing where))
371 (defun calc-view-news ()
373 (let ((path load-path))
375 (not (file-exists-p (expand-file-name "calc.el" (car path)))))
376 (setq path (cdr path)))
378 (file-exists-p (expand-file-name "README" (car path))))
379 (error "Can't locate Calc sources"))
381 (switch-to-buffer "*Help*")
383 (insert-file-contents (expand-file-name "README" (car path)))
384 (search-forward "Summary of changes")
386 (delete-region (point-min) (point))
387 (goto-char (point-min)))
392 (defun calc-full-help ()
394 (with-output-to-temp-buffer "*Help*"
395 (princ (format "GNU Emacs Calculator version %s of %s.\n"
396 calc-version calc-version-date))
397 (princ " By Dave Gillespie, daveg@synaptics.com.\n")
398 (princ (format " Installed %s.\n" calc-installed-date))
399 (princ " Copyright (C) 1990, 1993 Free Software Foundation, Inc.\n\n")
400 (princ "Type `h s' for a more detailed summary.\n")
401 (princ "Or type `h i' to read the full Calc manual on-line.\n\n")
402 (princ "Basic keys:\n")
403 (let* ((calc-full-help-flag t))
404 (mapcar (function (lambda (x) (princ (format " %s\n" x))))
405 (nreverse (cdr (reverse (cdr (calc-help))))))
406 (mapcar (function (lambda (prefix)
407 (let ((msgs (condition-case err
412 (if (eq (nth 2 msgs) ?v)
413 "\n`v' or `V' prefix (vector/matrix) keys: \n"
416 "\n`%c' prefix (%s) keys:\n"
418 (or (cdr (assq (nth 2 msgs)
419 calc-help-long-names))
421 (format "\n%s-modified keys:\n"
422 (capitalize (nth 1 msgs)))))))
423 (mapcar (function (lambda (x)
424 (princ (format " %s\n" x))))
426 '(calc-inverse-prefix-help
427 calc-hyperbolic-prefix-help
428 calc-inv-hyp-prefix-help
444 calc-shift-Y-prefix-help
445 calc-shift-Z-prefix-help
446 calc-z-prefix-help)))
447 (print-help-return-message))
450 (defvar calc-help-long-names '( ( ?b . "binary/business" )
453 ( ?k . "combinatorics/statistics" )
454 ( ?u . "units/statistics" )
457 (defun calc-h-prefix-help ()
460 '("Help; Bindings; Info, Tutorial, Summary; News"
461 "describe: Key, C (briefly), Function, Variable")
465 (defun calc-inverse-prefix-help ()
468 '("I + S (arcsin), C (arccos), T (arctan); Q (square)"
469 "I + E (ln), L (exp), B (alog: B^X); f E (lnp1), f L (expm1)"
470 "I + F (ceiling), R (truncate); a S (invert func)"
471 "I + a m (match-not); c h (from-hms); k n (prev prime)"
472 "I + f G (gamma-Q); f e (erfc); k B (etc., lower-tail dists)"
473 "I + V S (reverse sort); V G (reverse grade)"
474 "I + v s (remove subvec); v h (tail)"
475 "I + t + (alt sum), t M (mean with error)"
476 "I + t S (pop std dev), t C (pop covar)")
480 (defun calc-hyperbolic-prefix-help ()
483 '("H + S (sinh), C (cosh), T (tanh); E (exp10), L (log10)"
484 "H + F (float floor), R (float round); P (constant \"e\")"
485 "H + a d (total derivative); k c (permutations)"
486 "H + k b (bern-poly), k e (euler-poly); k s (stirling-2)"
487 "H + f G (gamma-g), f B (beta-B); v h (rhead), v k (rcons)"
488 "H + v e (expand w/filler); V H (weighted histogram)"
489 "H + a S (general solve eqn), j I (general isolate)"
490 "H + a R (widen/root), a N (widen/min), a X (widen/max)"
491 "H + t M (median), t S (variance), t C (correlation coef)"
492 "H + c f/F/c (pervasive float/frac/clean)")
496 (defun calc-inv-hyp-prefix-help ()
499 '("I H + S (arcsinh), C (arccosh), T (arctanh)"
500 "I H + E (log10), L (exp10); f G (gamma-G)"
501 "I H + F (float ceiling), R (float truncate)"
502 "I H + t S (pop variance)"
503 "I H + a S (general invert func); v h (rtail)")
504 "inverse-hyperbolic" nil)
508 (defun calc-f-prefix-help ()
511 '("miN, maX; Hypot; Im, Re; Sign; [, ] (incr/decr)"
512 "Gamma, Beta, Erf, besselJ, besselY"
513 "SHIFT + int-sQrt; Int-log, Exp(x)-1, Ln(x+1); arcTan2"
514 "SHIFT + Abssqr; Mantissa, eXponent, Scale"
515 "SHIFT + incomplete: Gamma-P, Beta-I")
520 (defun calc-s-prefix-help ()
523 '("Store, inTo, Xchg, Unstore; Recall, 0-9; : (:=); = (=>)"
524 "Let; Copy; Declare; Insert, Perm; Edit"
525 "Negate, +, -, *, /, ^, &, |, [, ]; Map"
526 "SHIFT + Decls, GenCount, TimeZone, Holidays; IntegLimit"
527 "SHIFT + LineStyles, PointStyles, plotRejects; Units"
528 "SHIFT + Eval-, AlgSimp-, ExtSimp-, FitRules")
532 (defun calc-r-prefix-help ()
535 '("digits 0-9: recall, same as `s r 0-9'")
540 (defun calc-j-prefix-help ()
543 '("Select, Additional, Once; eVal, Formula; Rewrite"
544 "More, Less, 1-9, Next, Previous"
545 "Unselect, Clear; Display; Enable; Breakable"
546 "' (replace), ` (edit), +, -, *, /, RET (grab), DEL"
547 "SHIFT + swap: Left, Right; maybe: Select, Once"
548 "SHIFT + Commute, Merge, Distrib, jump-Eqn, Isolate"
549 "SHIFT + Negate, & (invert); Unpack")
554 (defun calc-a-prefix-help ()
557 '("Simplify, Extended-simplify, eVal; \" (exp-formula)"
558 "eXpand, Collect, Factor, Apart, Norm-rat"
559 "GCD, /, \\, % (polys); Polint"
560 "Derivative, Integral, Taylor; _ (subscr)"
561 "suBstitute; Rewrite, Match"
562 "SHIFT + Solve; Root, miN, maX; Poly-roots; Fit"
563 "SHIFT + Map; Tabulate, + (sum), * (prod); num-Integ"
564 "relations: =, # (not =), <, >, [ (< or =), ] (> or =)"
565 "logical: & (and), | (or), ! (not); : (if)"
566 "misc: { (in-set); . (rmeq)")
571 (defun calc-b-prefix-help ()
574 '("And, Or, Xor, Diff, Not; Wordsize, Clip"
575 "Lshift, Rshift, roTate; SHIFT + signed Lshift, Rshift"
576 "SHIFT + business: Pv, Npv, Fv, pMt, #pmts, raTe, Irr"
577 "SHIFT + business: Sln, sYd, Ddb; %ch")
582 (defun calc-c-prefix-help ()
585 '("Deg, Rad, HMS; Float; Polar/rect; Clean, 0-9; %"
591 (defun calc-d-prefix-help ()
594 '("Group, \",\"; Normal, Fix, Sci, Eng, \".\"; Over"
595 "Radix, Zeros, 2, 8, 0, 6; Hms; Date; Complex, I, J"
596 "Why; Line-nums, line-Breaks; <, =, > (justify); Plain"
597 "\" (strings); Truncate, [, ]; SPC (refresh), RET"
598 "SHIFT + language: Normal, One-line, Big, Unformatted"
599 "SHIFT + language: C, Pascal, Fortran; TeX, Eqn"
600 "SHIFT + language: Mathematica, W=Maple")
605 (defun calc-g-prefix-help ()
608 '("Fast; Add, Delete, Juggle; Plot, Clear; Quit"
609 "Header, Name, Grid, Border, Key; View-commands, X-display"
610 "x-axis: Range, Title, Log, Zero; lineStyle"
611 "SHIFT + y-axis: Range, Title, Log, Zero; pointStyle"
612 "SHIFT + Print; Device, Output-file; X-geometry"
613 "SHIFT + Num-pts; Command, Kill, View-trail"
614 "SHIFT + 3d: Fast, Add; CTRL + z-axis: Range, Title, Log")
619 (defun calc-k-prefix-help ()
622 '("GCD, LCM; Choose (binomial), Double-factorial"
623 "Random, random-Again, sHuffle"
624 "Factors, Prime-test, Next-prime, Totient, Moebius"
625 "Bernoulli, Euler, Stirling"
626 "SHIFT + Extended-gcd"
627 "SHIFT + dists: Binomial, Chi-square, F, Normal"
628 "SHIFT + dists: Poisson, student's-T")
633 (defun calc-m-prefix-help ()
636 '("Deg, Rad, HMS; Frac; Polar; Inf; Alg, Total; Symb; Vec/mat"
637 "Working; Xtensions; Mode-save"
638 "SHIFT + Shifted-prefixes, mode-Filename; Record; reCompute"
639 "SHIFT + simplify: Off, Num, Default, Bin, Alg, Ext, Units")
644 (defun calc-t-prefix-help ()
647 '("Display; Fwd, Back; Next, Prev, Here, [, ]; Yank"
648 "Search, Rev; In, Out; <, >; Kill; Marker; . (abbrev)"
649 "SHIFT + time: Now; Part; Date, Julian, Unix, Czone"
650 "SHIFT + time: newWeek, newMonth, newYear; Incmonth"
651 "SHIFT + time: +, - (business days)"
652 "digits 0-9: store-to, same as `s t 0-9'")
657 (defun calc-u-prefix-help ()
660 '("Simplify, Convert, Temperature-convert, Base-units"
661 "Autorange; Remove, eXtract; Explain; View-table; 0-9"
662 "Define, Undefine, Get-defn, Permanent"
663 "SHIFT + View-table-other-window"
664 "SHIFT + stat: Mean, G-mean, Std-dev, Covar, maX, miN"
665 "SHIFT + stat: + (sum), - (asum), * (prod), # (count)")
670 (defun calc-v-prefix-help ()
673 '("Pack, Unpack, Identity, Diagonal, indeX, Build"
674 "Row, Column, Subvector; Length; Find; Mask, Expand"
675 "Transpose, Arrange, reVerse; Head, Kons; rNorm"
676 "SHIFT + Det, & (inverse), LUD, Trace, conJtrn, Cross"
677 "SHIFT + Sort, Grade, Histogram; cNorm"
678 "SHIFT + Apply, Map, Reduce, accUm, Inner-, Outer-prod"
679 "SHIFT + sets: V (union), ^ (intersection), - (diff)"
680 "SHIFT + sets: Xor, ~ (complement), Floor, Enum"
681 "SHIFT + sets: : (span), # (card), + (rdup)"
682 "<, =, > (justification); , (commas); [, {, ( (brackets)"
683 "} (matrix brackets); . (abbreviate); / (multi-lines)")