1 ;; Calculator for GNU Emacs, part II [calc-help.el]
2 ;; Copyright (C) 1990, 1991, 1992, 1993, 2001 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)
48 (defun calc-help-for-help (arg)
49 "You have typed `h', the Calc help character. Type a Help option:
51 B calc-describe-bindings. Display a table of all key bindings.
52 H calc-full-help. Display all `?' key messages at once.
54 I calc-info. Read the Calc manual using the Info system.
55 T calc-tutorial. Read the Calc tutorial using the Info system.
56 S calc-info-summary. Read the Calc summary using the Info system.
58 C calc-describe-key-briefly. Look up the command name for a given key.
59 K calc-describe-key. Look up a key's documentation in the manual.
60 F calc-describe-function. Look up a function's documentation in the manual.
61 V calc-describe-variable. Look up a variable's documentation in the manual.
63 N calc-view-news. Display Calc history of changes.
65 C-c Describe conditions for copying Calc.
66 C-d Describe how you can get a new copy of Calc or report a bug.
67 C-w Describe how there is no warranty for Calc."
69 (if calc-dispatch-help
71 (save-window-excursion
72 (describe-function 'calc-help-for-help)
73 (select-window (get-buffer-window "*Help*"))
75 (message "Calc Help options: Help, Info, ... press SPC, DEL to scroll, C-g to cancel")
76 (memq (car (setq key (calc-read-key t)))
77 '(? ?\C-h ?\C-? ?\C-v ?\M-v)))
79 (if (memq (car key) '(? ?\C-v))
83 (calc-unread-command (cdr key))
84 (calc-help-prefix nil))
85 (let ((calc-dispatch-help t))
86 (calc-help-prefix arg))))
88 (defun calc-describe-copying ()
91 (Info-goto-node "Copying"))
93 (defun calc-describe-distribution ()
96 (Info-goto-node "Reporting Bugs"))
98 (defun calc-describe-no-warranty ()
101 (Info-goto-node "Copying")
102 (let ((case-fold-search nil))
103 (search-forward " NO WARRANTY"))
107 (defun calc-describe-bindings ()
111 (set-buffer "*Help*")
112 (goto-char (point-min))
113 (if (search-forward "Global bindings:" nil t)
114 (delete-region (match-beginning 0) (point-max)))
115 (goto-char (point-min))
116 (while (re-search-forward "\n[a-z] ESC" nil t)
118 (delete-region (match-beginning 0) (point)))
119 (goto-char (point-min))
120 (while (re-search-forward "\nESC m" nil t)
122 (delete-region (match-beginning 0) (point)))
123 (goto-char (point-min))
124 (while (search-forward "\n\n\n" nil t)
125 (backward-delete-char 1)
127 (goto-char (point-min))
130 "\n[a-z] [0-9]\\(\t\t.*\n\\)\\([a-z] [0-9]\\1\\)*[a-z] \\([0-9]\\)\\1"
132 (let ((dig1 (char-after (1- (match-beginning 1))))
133 (dig2 (char-after (match-beginning 3))))
134 (delete-region (match-end 1) (match-end 0))
135 (goto-char (match-beginning 1))
136 (delete-backward-char 1)
138 (insert (format "%c .. %c" (min dig1 dig2) (max dig1 dig2)))))
139 (goto-char (point-min))))
141 (defun calc-describe-key-briefly (key)
142 (interactive "kDescribe key briefly: ")
143 (calc-describe-key key t))
145 (defun calc-describe-key (key &optional briefly)
146 (interactive "kDescribe key: ")
147 (let ((defn (if (eq (key-binding key) 'calc-dispatch)
148 (let ((key2 (calc-read-key-sequence
149 (format "Describe key briefly: %s-"
150 (key-description key))
152 (setq key (concat key key2))
153 (lookup-key calc-dispatch-map key2))
154 (if (eq (key-binding key) 'calc-help-prefix)
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-help-map key2))
164 (while (or (equal key "I") (equal key "H"))
167 (setq hyp (not hyp)))
168 (setq key (read-key-sequence (format "Describe key%s:%s%s "
169 (if briefly " briefly" "")
172 defn (key-binding key)))
173 (let ((desc (key-description key))
175 (if (string-match "^ESC " desc)
176 (setq desc (concat "M-" (substring desc 4))))
177 (while (string-match "^M-# \\(ESC \\|C-\\)" desc)
178 (setq desc (concat "M-# " (substring desc (match-end 0)))))
180 (let ((msg (save-excursion
181 (set-buffer (get-buffer-create "*Calc Summary*"))
182 (if (= (buffer-size) 0)
184 (message "Reading Calc summary from manual...")
185 (save-window-excursion
188 (Info-goto-node "Summary")
189 (goto-char (point-min))
191 (copy-to-buffer "*Calc Summary*"
194 (setq case-fold-search nil)
195 (re-search-forward "^\\(.*\\)\\[\\.\\. a b")
196 (setq calc-summary-indentation
197 (- (match-end 1) (match-beginning 1)))))
198 (goto-char (point-min))
199 (setq target (if (and (string-match "[0-9]\\'" desc)
200 (not (string-match "[d#]" desc)))
201 (concat (substring desc 0 -1) "0-9")
203 (if (re-search-forward
204 (format "\n%s%s%s%s[ a-zA-Z]"
205 (make-string (+ calc-summary-indentation 9)
207 (if (string-match "M-#" desc) " "
209 (if hyp "I H " " I ")
211 (regexp-quote target)
212 (make-string (max (- 6 (length target)) 0)
217 (forward-char calc-summary-indentation)
220 (buffer-substring pt (point)))))))
222 (let ((args (substring msg 0 9))
223 (keys (substring msg 9 19))
224 (prompts (substring msg 19 38))
226 (cmd (substring msg 40))
228 (if (string-match "\\` +" args)
229 (setq args (substring args (match-end 0))))
230 (if (string-match " +\\'" args)
231 (setq args (substring args 0 (match-beginning 0))))
232 (if (string-match "\\` +" keys)
233 (setq keys (substring keys (match-end 0))))
234 (if (string-match " +\\'" keys)
235 (setq keys (substring keys 0 (match-beginning 0))))
236 (if (string-match " [0-9,]+\\'" prompts)
237 (setq notes (substring prompts (1+ (match-beginning 0)))
238 prompts (substring prompts 0 (match-beginning 0))))
239 (if (string-match " +\\'" prompts)
240 (setq prompts (substring prompts 0 (match-beginning 0))))
241 (if (string-match "\\` +" prompts)
242 (setq prompts (substring prompts (match-end 0))))
244 "%s: %s%s`%s'%s%s %s%s"
246 "\\`\\(calc-[-a-zA-Z0-9]+\\) *\\(.*\\)\\'"
248 (prog1 (math-match-substring cmd 1)
249 (setq cmd (math-match-substring cmd 2)))
251 args (if (equal args "") "" " ")
253 (if (equal prompts "") "" " ") prompts
254 (if (equal cmd "") "" " => ") cmd))
255 (message "%s%s%s runs %s%s"
256 (if inv "I " "") (if hyp "H " "") desc
258 (if (equal notes "") ""
259 (format " (?=notes %s)" notes)))
260 (let ((key (calc-read-key t)))
261 (if (eq (car key) ??)
263 (message "No notes for this command")
264 (while (string-match "," notes)
265 (aset notes (match-beginning 0) ? ))
266 (setq notes (sort (car (read-from-string
267 (format "(%s)" notes)))
269 (with-output-to-temp-buffer "*Help*"
270 (princ (format "%s\n\n" msg))
271 (set-buffer "*Calc Summary*")
272 (re-search-forward "^ *NOTES")
275 (format "^ *%d\\. " (car notes)))
279 (or (re-search-forward "^ ? ?[0-9]+\\. " nil t)
280 (goto-char (point-max)))
282 (princ (buffer-substring pt (point))))
283 (setq notes (cdr notes)))
284 (print-help-return-message)))
285 (calc-unread-command (cdr key)))))
286 (if (or (null defn) (integerp defn))
287 (message "%s is undefined" desc)
288 (message "%s runs the command %s"
290 (if (symbolp defn) defn (prin1-to-string defn))))))
291 (if inv (setq desc (concat "I " desc)))
292 (if hyp (setq desc (concat "H " desc)))
293 (calc-describe-thing desc "Key Index" nil
294 (string-match "[A-Z][A-Z][A-Z]" desc))))))
296 (defun calc-describe-function (&optional func)
299 (setq func (intern (completing-read "Describe function: "
300 obarray nil t "calcFunc-"))))
301 (setq func (symbol-name func))
302 (if (string-match "\\`calc-." func)
303 (calc-describe-thing func "Command Index")
304 (calc-describe-thing (if (string-match "\\`calcFunc-." func)
309 (defun calc-describe-variable (&optional var)
312 (setq var (intern (completing-read "Describe variable: "
313 obarray nil t "var-"))))
314 (setq var (symbol-name var))
315 (calc-describe-thing var "Variable Index"
316 (if (string-match "\\`var-." var)
320 (defun calc-describe-thing (thing where &optional target not-quoted)
321 (message "Looking for `%s' in %s..." thing where)
322 (let ((savewin (current-window-configuration)))
324 (Info-goto-node where)
325 (or (let ((case-fold-search nil))
326 (re-search-forward (format "\n\\* +%s: \\(.*\\)\\."
327 (regexp-quote thing))
329 (and (string-match "\\`\\([a-z ]*\\)[0-9]\\'" thing)
330 (re-search-forward (format "\n\\* +%s[01]-9: \\(.*\\)\\."
331 (substring thing 0 -1))
333 (setq thing (format "%s9" (substring thing 0 -1))))
336 (set-window-configuration savewin)
337 (error "Can't find `%s' in %s" thing where)))
339 (Info-goto-node (buffer-substring (match-beginning 1) (match-end 1))))
340 (or (let ((case-fold-search nil))
341 (or (search-forward (format "\\[`%s'\\]\\|(`%s')\\|\\<The[ \n]`%s'"
344 (or target thing)) nil t)
346 (let ((case-fold-search t))
347 (search-forward (or target thing) nil t)))
348 (search-forward (format "`%s'" (or target thing)) nil t)
349 (search-forward (or target thing) nil t)))
350 (let ((case-fold-search t))
351 (or (search-forward (format "\\[`%s'\\]\\|(`%s')\\|\\<The[ \n]`%s'"
354 (or target thing)) nil t)
355 (search-forward (format "`%s'" (or target thing)) nil t)
356 (search-forward (or target thing) nil t))))
358 (message "Found `%s' in %s" thing where)))
360 (defun calc-view-news ()
362 (let ((path load-path))
364 (not (file-exists-p (expand-file-name "calc.el" (car path)))))
365 (setq path (cdr path)))
367 (file-exists-p (expand-file-name "README" (car path))))
368 (error "Can't locate Calc sources"))
370 (switch-to-buffer "*Help*")
372 (insert-file-contents (expand-file-name "README" (car path)))
373 (search-forward "Summary of changes")
375 (delete-region (point-min) (point))
376 (goto-char (point-min))))
378 (defun calc-full-help ()
380 (with-output-to-temp-buffer "*Help*"
381 (princ (format "GNU Emacs Calculator version %s of %s.\n"
382 calc-version calc-version-date))
383 (princ " By Dave Gillespie, daveg@synaptics.com.\n")
384 (princ (format " Installed %s.\n" calc-installed-date))
385 (princ " Copyright (C) 1990, 1993 Free Software Foundation, Inc.\n\n")
386 (princ "Type `h s' for a more detailed summary.\n")
387 (princ "Or type `h i' to read the full Calc manual on-line.\n\n")
388 (princ "Basic keys:\n")
389 (let* ((calc-full-help-flag t))
390 (mapcar (function (lambda (x) (princ (format " %s\n" x))))
391 (nreverse (cdr (reverse (cdr (calc-help))))))
392 (mapcar (function (lambda (prefix)
393 (let ((msgs (condition-case err
398 (if (eq (nth 2 msgs) ?v)
399 "\n`v' or `V' prefix (vector/matrix) keys: \n"
402 "\n`%c' prefix (%s) keys:\n"
404 (or (cdr (assq (nth 2 msgs)
405 calc-help-long-names))
407 (format "\n%s-modified keys:\n"
408 (capitalize (nth 1 msgs)))))))
409 (mapcar (function (lambda (x)
410 (princ (format " %s\n" x))))
412 '(calc-inverse-prefix-help
413 calc-hyperbolic-prefix-help
414 calc-inv-hyp-prefix-help
430 calc-shift-Y-prefix-help
431 calc-shift-Z-prefix-help
432 calc-z-prefix-help)))
433 (print-help-return-message)))
435 (defvar calc-help-long-names '((?b . "binary/business")
438 (?k . "combinatorics/statistics")
439 (?u . "units/statistics")))
441 (defun calc-h-prefix-help ()
444 '("Help; Bindings; Info, Tutorial, Summary; News"
445 "describe: Key, C (briefly), Function, Variable")
448 (defun calc-inverse-prefix-help ()
451 '("I + S (arcsin), C (arccos), T (arctan); Q (square)"
452 "I + E (ln), L (exp), B (alog: B^X); f E (lnp1), f L (expm1)"
453 "I + F (ceiling), R (truncate); a S (invert func)"
454 "I + a m (match-not); c h (from-hms); k n (prev prime)"
455 "I + f G (gamma-Q); f e (erfc); k B (etc., lower-tail dists)"
456 "I + V S (reverse sort); V G (reverse grade)"
457 "I + v s (remove subvec); v h (tail)"
458 "I + t + (alt sum), t M (mean with error)"
459 "I + t S (pop std dev), t C (pop covar)")
462 (defun calc-hyperbolic-prefix-help ()
465 '("H + S (sinh), C (cosh), T (tanh); E (exp10), L (log10)"
466 "H + F (float floor), R (float round); P (constant \"e\")"
467 "H + a d (total derivative); k c (permutations)"
468 "H + k b (bern-poly), k e (euler-poly); k s (stirling-2)"
469 "H + f G (gamma-g), f B (beta-B); v h (rhead), v k (rcons)"
470 "H + v e (expand w/filler); V H (weighted histogram)"
471 "H + a S (general solve eqn), j I (general isolate)"
472 "H + a R (widen/root), a N (widen/min), a X (widen/max)"
473 "H + t M (median), t S (variance), t C (correlation coef)"
474 "H + c f/F/c (pervasive float/frac/clean)")
477 (defun calc-inv-hyp-prefix-help ()
480 '("I H + S (arcsinh), C (arccosh), T (arctanh)"
481 "I H + E (log10), L (exp10); f G (gamma-G)"
482 "I H + F (float ceiling), R (float truncate)"
483 "I H + t S (pop variance)"
484 "I H + a S (general invert func); v h (rtail)")
485 "inverse-hyperbolic" nil))
488 (defun calc-f-prefix-help ()
491 '("miN, maX; Hypot; Im, Re; Sign; [, ] (incr/decr)"
492 "Gamma, Beta, Erf, besselJ, besselY"
493 "SHIFT + int-sQrt; Int-log, Exp(x)-1, Ln(x+1); arcTan2"
494 "SHIFT + Abssqr; Mantissa, eXponent, Scale"
495 "SHIFT + incomplete: Gamma-P, Beta-I")
499 (defun calc-s-prefix-help ()
502 '("Store, inTo, Xchg, Unstore; Recall, 0-9; : (:=); = (=>)"
503 "Let; Copy; Declare; Insert, Perm; Edit"
504 "Negate, +, -, *, /, ^, &, |, [, ]; Map"
505 "SHIFT + Decls, GenCount, TimeZone, Holidays; IntegLimit"
506 "SHIFT + LineStyles, PointStyles, plotRejects; Units"
507 "SHIFT + Eval-, AlgSimp-, ExtSimp-, FitRules")
510 (defun calc-r-prefix-help ()
513 '("digits 0-9: recall, same as `s r 0-9'")
517 (defun calc-j-prefix-help ()
520 '("Select, Additional, Once; eVal, Formula; Rewrite"
521 "More, Less, 1-9, Next, Previous"
522 "Unselect, Clear; Display; Enable; Breakable"
523 "' (replace), ` (edit), +, -, *, /, RET (grab), DEL"
524 "SHIFT + swap: Left, Right; maybe: Select, Once"
525 "SHIFT + Commute, Merge, Distrib, jump-Eqn, Isolate"
526 "SHIFT + Negate, & (invert); Unpack")
530 (defun calc-a-prefix-help ()
533 '("Simplify, Extended-simplify, eVal; \" (exp-formula)"
534 "eXpand, Collect, Factor, Apart, Norm-rat"
535 "GCD, /, \\, % (polys); Polint"
536 "Derivative, Integral, Taylor; _ (subscr)"
537 "suBstitute; Rewrite, Match"
538 "SHIFT + Solve; Root, miN, maX; Poly-roots; Fit"
539 "SHIFT + Map; Tabulate, + (sum), * (prod); num-Integ"
540 "relations: =, # (not =), <, >, [ (< or =), ] (> or =)"
541 "logical: & (and), | (or), ! (not); : (if)"
542 "misc: { (in-set); . (rmeq)")
546 (defun calc-b-prefix-help ()
549 '("And, Or, Xor, Diff, Not; Wordsize, Clip"
550 "Lshift, Rshift, roTate; SHIFT + signed Lshift, Rshift"
551 "SHIFT + business: Pv, Npv, Fv, pMt, #pmts, raTe, Irr"
552 "SHIFT + business: Sln, sYd, Ddb; %ch")
556 (defun calc-c-prefix-help ()
559 '("Deg, Rad, HMS; Float; Polar/rect; Clean, 0-9; %"
564 (defun calc-d-prefix-help ()
567 '("Group, \",\"; Normal, Fix, Sci, Eng, \".\"; Over"
568 "Radix, Zeros, 2, 8, 0, 6; Hms; Date; Complex, I, J"
569 "Why; Line-nums, line-Breaks; <, =, > (justify); Plain"
570 "\" (strings); Truncate, [, ]; SPC (refresh), RET"
571 "SHIFT + language: Normal, One-line, Big, Unformatted"
572 "SHIFT + language: C, Pascal, Fortran; TeX, Eqn"
573 "SHIFT + language: Mathematica, W=Maple")
577 (defun calc-g-prefix-help ()
580 '("Fast; Add, Delete, Juggle; Plot, Clear; Quit"
581 "Header, Name, Grid, Border, Key; View-commands, X-display"
582 "x-axis: Range, Title, Log, Zero; lineStyle"
583 "SHIFT + y-axis: Range, Title, Log, Zero; pointStyle"
584 "SHIFT + Print; Device, Output-file; X-geometry"
585 "SHIFT + Num-pts; Command, Kill, View-trail"
586 "SHIFT + 3d: Fast, Add; CTRL + z-axis: Range, Title, Log")
590 (defun calc-k-prefix-help ()
593 '("GCD, LCM; Choose (binomial), Double-factorial"
594 "Random, random-Again, sHuffle"
595 "Factors, Prime-test, Next-prime, Totient, Moebius"
596 "Bernoulli, Euler, Stirling"
597 "SHIFT + Extended-gcd"
598 "SHIFT + dists: Binomial, Chi-square, F, Normal"
599 "SHIFT + dists: Poisson, student's-T")
603 (defun calc-m-prefix-help ()
606 '("Deg, Rad, HMS; Frac; Polar; Inf; Alg, Total; Symb; Vec/mat"
607 "Working; Xtensions; Mode-save"
608 "SHIFT + Shifted-prefixes, mode-Filename; Record; reCompute"
609 "SHIFT + simplify: Off, Num, Default, Bin, Alg, Ext, Units")
613 (defun calc-t-prefix-help ()
616 '("Display; Fwd, Back; Next, Prev, Here, [, ]; Yank"
617 "Search, Rev; In, Out; <, >; Kill; Marker; . (abbrev)"
618 "SHIFT + time: Now; Part; Date, Julian, Unix, Czone"
619 "SHIFT + time: newWeek, newMonth, newYear; Incmonth"
620 "SHIFT + time: +, - (business days)"
621 "digits 0-9: store-to, same as `s t 0-9'")
625 (defun calc-u-prefix-help ()
628 '("Simplify, Convert, Temperature-convert, Base-units"
629 "Autorange; Remove, eXtract; Explain; View-table; 0-9"
630 "Define, Undefine, Get-defn, Permanent"
631 "SHIFT + View-table-other-window"
632 "SHIFT + stat: Mean, G-mean, Std-dev, Covar, maX, miN"
633 "SHIFT + stat: + (sum), - (asum), * (prod), # (count)")
637 (defun calc-v-prefix-help ()
640 '("Pack, Unpack, Identity, Diagonal, indeX, Build"
641 "Row, Column, Subvector; Length; Find; Mask, Expand"
642 "Tranpose, Arrange, reVerse; Head, Kons; rNorm"
643 "SHIFT + Det, & (inverse), LUD, Trace, conJtrn, Cross"
644 "SHIFT + Sort, Grade, Histogram; cNorm"
645 "SHIFT + Apply, Map, Reduce, accUm, Inner-, Outer-prod"
646 "SHIFT + sets: V (union), ^ (intersection), - (diff)"
647 "SHIFT + sets: Xor, ~ (complement), Floor, Enum"
648 "SHIFT + sets: : (span), # (card), + (rdup)"
649 "<, =, > (justification); , (commas); [, {, ( (brackets)"
650 "} (matrix brackets); . (abbreviate); / (multi-lines)")
653 ;;; calc-help.el ends here