1 ;;; calc-help.el --- help display functions for Calc,
3 ;; Copyright (C) 1990-1993, 2001-2016 Free Software Foundation, Inc.
5 ;; Author: David Gillespie <daveg@synaptics.com>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software: you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation, either version 3 of the License, or
12 ;; (at your option) any later version.
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; This file is autoloaded from calc-ext.el.
31 ;; Declare functions which are defined elsewhere.
32 (declare-function Info-goto-node
"info" (nodename &optional fork strict-case
))
33 (declare-function Info-last
"info" ())
36 (defun calc-help-prefix (arg)
37 "This key is the prefix for Calc help functions. See calc-help-for-help."
39 (or calc-dispatch-help
(sit-for echo-keystrokes
))
40 (let ((key (calc-read-key-sequence
41 (if calc-dispatch-help
42 "Calc Help options: Help, Info, Tutorial, Summary; Key, Function; ?=more"
43 (format "%s (Type ? for a list of Calc Help options)"
44 (key-description (this-command-keys))))
46 (setq key
(lookup-key calc-help-map key
))
49 (call-interactively key
)
52 (defun calc-help-for-help (arg)
53 "You have typed `h', the Calc help character. Type a Help option:
55 B calc-describe-bindings. Display a table of all key bindings.
56 H calc-full-help. Display all `?' key messages at once.
58 I calc-info. Read the Calc manual using the Info system.
59 T calc-tutorial. Read the Calc tutorial using the Info system.
60 S calc-info-summary. Read the Calc summary using the Info system.
62 C calc-describe-key-briefly. Look up the command name for a given key.
63 K calc-describe-key. Look up a key's documentation in the manual.
64 F calc-describe-function. Look up a function's documentation in the manual.
65 V calc-describe-variable. Look up a variable's documentation in the manual.
67 N calc-view-news. Display Calc history of changes.
69 C-c Describe conditions for copying Calc.
70 C-d Describe how you can get a new copy of Calc or report a bug.
71 C-w Describe how there is no warranty for Calc."
73 (if calc-dispatch-help
75 (save-window-excursion
76 (describe-function 'calc-help-for-help
)
77 (select-window (get-buffer-window "*Help*"))
79 (message "Calc Help options: Help, Info, ... press SPC, DEL to scroll, C-g to cancel")
80 (memq (car (setq key
(calc-read-key t
)))
81 '(? ?\C-h ?\C-? ?\C-v ?\M-v
)))
83 (if (memq (car key
) '(? ?\C-v
))
87 (calc-unread-command (cdr key
))
88 (calc-help-prefix nil
))
89 (let ((calc-dispatch-help t
))
90 (calc-help-prefix arg
))))
92 (defun calc-describe-copying ()
94 (calc-info-goto-node "Copying"))
96 (defun calc-describe-distribution ()
98 (calc-info-goto-node "Reporting Bugs"))
100 (defun calc-describe-no-warranty ()
102 (calc-info-goto-node "Copying")
103 (let ((case-fold-search nil
))
104 (search-forward " NO WARRANTY"))
108 (defun calc-describe-bindings ()
111 (with-current-buffer "*Help*"
112 (let ((inhibit-read-only t
))
113 (goto-char (point-min))
114 (when (search-forward "Major Mode Bindings:" nil t
)
115 (delete-region (point-min) (point))
116 (insert "Calc Mode Bindings:"))
117 (when (search-forward "Global bindings:" nil t
)
119 (delete-region (point) (point-max)))
120 (goto-char (point-min))
123 "\n[a-z] [0-9]\\( .*\n\\)\\([a-z] [0-9]\\1\\)*[a-z] \\([0-9]\\)\\1"
125 (let ((dig1 (char-after (1- (match-beginning 1))))
126 (dig2 (char-after (match-beginning 3))))
127 (delete-region (match-end 1) (match-end 0))
128 (goto-char (match-beginning 1))
131 (insert (format "%c .. %c" (min dig1 dig2
) (max dig1 dig2
)))))
132 (goto-char (point-min)))))
134 (defun calc-describe-key-briefly (key)
135 (interactive "kDescribe key briefly: ")
136 (calc-describe-key key t
))
138 (defvar Info-history
)
140 (defun calc-describe-key (key &optional briefly
)
141 (interactive "kDescribe key: ")
142 (let ((defn (if (eq (key-binding key
) 'calc-dispatch
)
143 (let ((key2 (calc-read-key-sequence
144 (format "Describe key briefly: %s-"
145 (key-description key
))
147 (setq key
(concat key key2
))
148 (lookup-key calc-dispatch-map key2
))
149 (if (eq (key-binding key
) 'calc-help-prefix
)
150 (let ((key2 (calc-read-key-sequence
151 (format "Describe key briefly: %s-"
152 (key-description key
))
154 (setq key
(concat key key2
))
155 (lookup-key calc-help-map key2
))
159 calc-summary-indentation
)
160 (while (or (equal key
"I") (equal key
"H"))
163 (setq hyp
(not hyp
)))
164 (setq key
(read-key-sequence (format "Describe key%s:%s%s "
165 (if briefly
" briefly" "")
168 defn
(key-binding key
)))
169 (let ((desc (key-description key
))
171 (if (string-match "^ESC " desc
)
172 (setq desc
(concat "M-" (substring desc
4))))
173 (while (string-match "^M-# \\(ESC \\|C-\\)" desc
)
174 (setq desc
(concat "M-# " (substring desc
(match-end 0)))))
175 (if (string-match "\\(DEL\\|\\LFD\\|RET\\|SPC\\|TAB\\)" desc
)
176 (setq desc
(replace-match "<\\&>" nil nil desc
)))
178 (let ((msg (with-current-buffer (get-buffer-create "*Calc Summary*")
179 (if (= (buffer-size) 0)
181 (message "Reading Calc summary from manual...")
182 (require 'info nil t
)
185 (Info-goto-node "(Calc)Summary")
186 (goto-char (point-min))
188 (copy-to-buffer "*Calc Summary*"
189 (point) (point-max)))
190 (setq buffer-read-only t
)))
191 (goto-char (point-min))
192 (setq case-fold-search nil
)
193 (re-search-forward "^\\(.*\\)\\[\\.\\. a b")
194 (setq calc-summary-indentation
195 (- (match-end 1) (match-beginning 1)))
196 (goto-char (point-min))
197 (setq target
(if (and (string-match "[0-9]\\'" desc
)
198 (not (string-match "[d#]" desc
)))
199 (concat (substring desc
0 -
1) "0-9")
201 (if (re-search-forward
202 (format "\n%s%s%s%s[ a-zA-Z]"
203 (make-string (+ calc-summary-indentation
9)
205 (if (string-match "M-#" desc
) " "
207 (if hyp
"I H " " I ")
209 (regexp-quote target
)
210 (make-string (max (- 6 (length target
)) 0)
215 (forward-char calc-summary-indentation
)
218 (buffer-substring pt
(point)))))))
220 (let ((args (substring msg
0 9))
221 (keys (substring msg
9 19))
222 (prompts (substring msg
19 38))
224 (cmd (substring msg
40))
226 (if (string-match "\\` +" args
)
227 (setq args
(substring args
(match-end 0))))
228 (if (string-match " +\\'" args
)
229 (setq args
(substring args
0 (match-beginning 0))))
230 (if (string-match "\\` +" keys
)
231 (setq keys
(substring keys
(match-end 0))))
232 (if (string-match " +\\'" keys
)
233 (setq keys
(substring keys
0 (match-beginning 0))))
234 (if (string-match " [0-9,]+\\'" prompts
)
235 (setq notes
(substring prompts
(1+ (match-beginning 0)))
236 prompts
(substring prompts
0 (match-beginning 0))))
237 (if (string-match " +\\'" prompts
)
238 (setq prompts
(substring prompts
0 (match-beginning 0))))
239 (if (string-match "\\` +" prompts
)
240 (setq prompts
(substring prompts
(match-end 0))))
241 (setq msg
(format-message
242 "%s: %s%s`%s'%s%s %s%s"
244 "\\`\\(calc-[-a-zA-Z0-9]+\\) *\\(.*\\)\\'"
246 (prog1 (math-match-substring cmd
1)
247 (setq cmd
(math-match-substring cmd
2)))
249 args
(if (equal args
"") "" " ")
251 (if (equal prompts
"") "" " ") prompts
252 (if (equal cmd
"") "" " => ") cmd
))
253 (message "%s%s%s runs %s%s"
254 (if inv
"I " "") (if hyp
"H " "") desc
256 (if (equal notes
"") ""
257 (format " (?=notes %s)" notes
)))
258 (let ((key (calc-read-key t
)))
259 (if (eq (car key
) ??
)
261 (message "No notes for this command")
262 (while (string-match "," notes
)
263 (aset notes
(match-beginning 0) ?
))
264 (setq notes
(sort (car (read-from-string
265 (format "(%s)" notes
)))
267 (with-output-to-temp-buffer "*Help*"
268 (princ (format "%s\n\n" msg
))
269 (set-buffer "*Calc Summary*")
270 (re-search-forward "^ *NOTES")
273 (format "^ *%d\\. " (car notes
)))
277 (or (re-search-forward "^ ? ?[0-9]+\\. " nil t
)
278 (goto-char (point-max)))
280 (princ (buffer-substring pt
(point))))
281 (setq notes
(cdr notes
)))
282 (help-print-return-message)))
283 (calc-unread-command (cdr key
)))))
284 (if (or (null defn
) (integerp defn
))
285 (message "%s is undefined" desc
)
286 (message "%s runs the command %s"
288 (if (symbolp defn
) defn
(prin1-to-string defn
))))))
289 (if inv
(setq desc
(concat "I " desc
)))
290 (if hyp
(setq desc
(concat "H " desc
)))
291 (calc-describe-thing desc
"Key Index" nil
292 (string-match "[A-Z][A-Z][A-Z]" desc
))))))
294 (defvar calc-help-function-list nil
295 "List of functions provided by Calc.")
297 (defvar calc-help-variable-list nil
298 "List of variables provided by Calc.")
300 (defun calc-help-index-entries (&rest indices
)
301 "Create a list of entries from the INDICES in the Calc info manual."
302 (let ((entrylist '())
304 (require 'info nil t
)
309 (Info-goto-node (concat "(Calc)" (car indices
) " Index"))
310 (goto-char (point-min))
311 (while (re-search-forward "\n\\* \\(.*\\): " nil t
)
312 (setq entry
(match-string 1))
313 (if (and (not (string-match "<[1-9]+>" entry
))
314 (not (string-match "(.*)" entry
))
315 (not (string= entry
"Menu")))
316 (unless (assoc entry entrylist
)
317 (setq entrylist
(cons entry entrylist
))))))
319 (setq indices
(cdr indices
)))
322 (defun calc-describe-function (&optional func
)
324 (unless calc-help-function-list
325 (setq calc-help-function-list
326 (calc-help-index-entries "Function" "Command")))
328 (setq func
(completing-read "Describe function: "
329 calc-help-function-list
331 (if (string-match "\\`calc-." func
)
332 (calc-describe-thing func
"Command Index")
333 (calc-describe-thing func
"Function Index")))
335 (defun calc-describe-variable (&optional var
)
337 (unless calc-help-variable-list
338 (setq calc-help-variable-list
339 (calc-help-index-entries "Variable")))
341 (setq var
(completing-read "Describe variable: "
342 calc-help-variable-list
344 (calc-describe-thing var
"Variable Index"))
346 (defun calc-describe-thing (thing where
&optional target not-quoted
)
347 (message "Looking for `%s' in %s..." thing where
)
348 (let ((savewin (current-window-configuration)))
349 (calc-info-goto-node where
)
350 (or (let ((case-fold-search nil
))
351 (re-search-forward (format "\n\\* +%s: \\(.*\\)\\."
352 (regexp-quote thing
))
354 (and (string-match "\\`\\([a-z ]*\\)[0-9]\\'" thing
)
355 (re-search-forward (format "\n\\* +%s[01]-9: \\(.*\\)\\."
356 (substring thing
0 -
1))
358 (setq thing
(format "%s9" (substring thing
0 -
1))))
362 (set-window-configuration savewin
)
363 (error "Can't find `%s' in %s" thing where
)))
365 (Info-goto-node (buffer-substring (match-beginning 1) (match-end 1))))
366 (let* ((string-target (or target thing
))
367 (quoted (format "['`‘]%s['’]" (regexp-quote string-target
)))
368 (bracketed (format "\\[%s\\]\\|(%s)\\|\\<The[ \n]%s"
369 quoted quoted quoted
)))
370 (or (let ((case-fold-search nil
))
371 (or (re-search-forward bracketed nil t
)
373 (let ((case-fold-search t
))
374 (search-forward string-target nil t
)))
375 (re-search-forward quoted nil t
)
376 (search-forward string-target nil t
)))
377 (let ((case-fold-search t
))
378 (or (re-search-forward bracketed nil t
)
379 (re-search-forward quoted nil t
)
380 (search-forward string-target nil t
)))))
382 (message "Found `%s' in %s" thing where
)))
384 (defun calc-view-news ()
388 (re-search-forward "^\\*+ .*\\<Calc\\>" nil t
))
390 (defvar calc-help-long-names
'((?b .
"binary/business")
393 (?k .
"combinatorics/statistics")
394 (?u .
"units/statistics")))
396 (defun calc-full-help ()
398 (with-output-to-temp-buffer "*Help*"
399 (princ "GNU Emacs Calculator.\n")
400 (princ " By Dave Gillespie.\n")
401 (princ (format " %s\n\n" emacs-copyright
))
402 (princ (format-message "Type `h s' for a more detailed summary.\n"))
403 (princ (format-message
404 "Or type `h i' to read the full Calc manual on-line.\n\n"))
405 (princ "Basic keys:\n")
406 (let* ((calc-full-help-flag t
))
407 (mapc (function (lambda (x) (princ (format
409 (substitute-command-keys x
)))))
410 (nreverse (cdr (reverse (cdr (calc-help))))))
411 (mapc (function (lambda (prefix)
412 (let ((msgs (condition-case err
417 (if (eq (nth 2 msgs
) ?v
)
419 "\n`v' or `V' prefix (vector/matrix) keys: \n")
422 "\n`%c' prefix (%s) keys:\n"
424 (or (cdr (assq (nth 2 msgs
)
425 calc-help-long-names
))
427 (format "\n%s-modified keys:\n"
428 (capitalize (nth 1 msgs
)))))))
433 (substitute-command-keys x
)))))
435 '(calc-inverse-prefix-help
436 calc-hyperbolic-prefix-help
437 calc-inv-hyp-prefix-help
438 calc-option-prefix-help
455 calc-shift-Y-prefix-help
456 calc-shift-Z-prefix-help
457 calc-z-prefix-help
)))
458 (help-print-return-message)))
460 (defun calc-h-prefix-help ()
463 '("Help; Bindings; Info, Tutorial, Summary; News"
464 "describe: Key, C (briefly), Function, Variable")
467 (defun calc-inverse-prefix-help ()
470 '("I + S (arcsin), C (arccos), T (arctan); Q (square)"
471 "I + E (ln), L (exp), B (alog: B^X); f E (lnp1), f L (expm1)"
472 "I + F (ceiling), R (truncate); a S (invert func)"
473 "I + a m (match-not); c h (from-hms); k n (prev prime)"
474 "I + f G (gamma-Q); f e (erfc); k B (etc., lower-tail dists)"
475 "I + V S (reverse sort); V G (reverse grade)"
476 "I + v s (remove subvec); v h (tail)"
477 "I + t + (alt sum), t M (mean with error)"
478 "I + t S (pop std dev), t C (pop covar)")
481 (defun calc-hyperbolic-prefix-help ()
484 '("H + S (sinh), C (cosh), T (tanh); E (exp10), L (log10)"
485 "H + F (float floor), R (float round); P (constant \"e\")"
486 "H + a d (total derivative); k c (permutations)"
487 "H + k b (bern-poly), k e (euler-poly); k s (stirling-2)"
488 "H + f G (gamma-g), f B (beta-B); v h (rhead), v k (rcons)"
489 "H + v e (expand w/filler); V H (weighted histogram)"
490 "H + a S (general solve eqn), j I (general isolate)"
491 "H + a R (widen/root), a N (widen/min), a X (widen/max)"
492 "H + t M (median), t S (variance), t C (correlation coef)"
493 "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
))
506 (defun calc-option-prefix-help ()
512 (defun calc-f-prefix-help ()
515 '("miN, maX; Hypot; Im, Re; Sign; [, ] (incr/decr)"
516 "Gamma, Beta, Erf, besselJ, besselY"
517 "SHIFT + int-sQrt; Int-log, Exp(x)-1, Ln(x+1); arcTan2"
518 "SHIFT + Abssqr; Mantissa, eXponent, Scale"
519 "SHIFT + incomplete: Gamma-P, Beta-I")
523 (defun calc-s-prefix-help ()
526 '("Store, inTo, Xchg, Unstore; Recall, 0-9; : (:=); = (=>)"
527 "Let; Copy, K=copy constant; Declare; Insert, Perm; Edit"
528 "Negate, +, -, *, /, ^, &, |, [, ]; Map"
529 "SHIFT + Decls, GenCount, TimeZone, Holidays; IntegLimit"
530 "SHIFT + LineStyles, PointStyles, plotRejects; Units"
531 "SHIFT + Eval-, AlgSimp-, ExtSimp-, FitRules")
534 (defun calc-r-prefix-help ()
537 '("digits 0-9: recall, same as `s r 0-9'"
538 "Save to register, Insert from register")
539 "recall/register" ?r
))
542 (defun calc-j-prefix-help ()
545 '("Select, Additional, Once; eVal, Formula; Rewrite"
546 "More, Less, 1-9, Next, Previous"
547 "Unselect, Clear; Display; Enable; Breakable"
548 "\\=' (replace), \\=` (edit), +, -, *, /, RET (grab), DEL"
549 "SHIFT + swap: Left, Right; maybe: Select, Once"
550 "SHIFT + Commute, Merge, Distrib, jump-Eqn, Isolate"
551 "SHIFT + Negate, & (invert); Unpack")
555 (defun calc-a-prefix-help ()
558 '("Simplify, Extended-simplify, eVal; \" (exp-formula)"
559 "eXpand, Collect, Factor, Apart, Norm-rat"
560 "GCD, /, \\, % (polys); Polint"
561 "Derivative, Integral, Taylor; _ (subscr)"
562 "suBstitute; Rewrite, Match"
563 "SHIFT + Solve; Root, miN, maX; Poly-roots; Fit"
564 "SHIFT + Map; Tabulate, + (sum), * (prod); num-Integ"
565 "relations: =, # (not =), <, >, [ (< or =), ] (> or =)"
566 "logical: & (and), | (or), ! (not); : (if)"
567 "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")
581 (defun calc-c-prefix-help ()
584 '("Deg, Rad, HMS; Float; Polar/rect; Clean, 0-9; %"
589 (defun calc-d-prefix-help ()
592 '("Group, \",\"; Normal, Fix, Sci, Eng, \".\"; Over"
593 "Radix, Zeros, 2, 8, 0, 6; Hms; Date; Complex, I, J"
594 "Why; Line-nums, line-Breaks; <, =, > (justify); Plain"
595 "\" (strings); Truncate, [, ]; SPC (refresh), RET, @"
596 "SHIFT + language: Normal, One-line, Big, Unformatted"
597 "SHIFT + language: C, Pascal, Fortran; TeX, LaTeX, Eqn"
598 "SHIFT + language: Yacas, X=Maxima, A=Giac"
599 "SHIFT + language: Mathematica, W=Maple")
603 (defun calc-g-prefix-help ()
606 '("Fast; Add, Delete, Juggle; Plot, Clear; Quit"
607 "Header, Name, Grid, Border, Key; View-commands, X-display"
608 "x-axis: Range, Title, Log, Zero; lineStyle"
609 "SHIFT + y-axis: Range, Title, Log, Zero; pointStyle"
610 "SHIFT + Print; Device, Output-file; X-geometry"
611 "SHIFT + Num-pts; Command, Kill, View-trail"
612 "SHIFT + 3d: Fast, Add; CTRL + z-axis: Range, Title, Log")
616 (defun calc-k-prefix-help ()
619 '("GCD, LCM; Choose (binomial), Double-factorial"
620 "Random, random-Again, sHuffle"
621 "Factors, Prime-test, Next-prime, Totient, Moebius"
622 "Bernoulli, Euler, Stirling"
623 "SHIFT + Extended-gcd"
624 "SHIFT + dists: Binomial, Chi-square, F, Normal"
625 "SHIFT + dists: Poisson, student's-T")
629 (defun calc-m-prefix-help ()
632 '("Deg, Rad, HMS; Frac; Polar; Inf; Alg, Total; Symb; Vec/mat"
633 "Working; Xtensions; Mode-save; preserve Embedded modes"
634 "SHIFT + Shifted-prefixes, mode-Filename; Record; reCompute"
635 "SHIFT + simplify: Off, Num, basIc, Algebraic, Bin, Ext, Units")
639 (defun calc-t-prefix-help ()
642 '("Display; Fwd, Back; Next, Prev, Here, [, ]; Yank"
643 "Search, Rev; In, Out; <, >; Kill; Marker; . (abbrev)"
644 "SHIFT + time: Now; Part; Date, Julian, Unix, Czone"
645 "SHIFT + time: newWeek, newMonth, newYear; Incmonth"
646 "SHIFT + time: +, - (business days)"
647 "digits 0-9: store-to, same as `s t 0-9'")
651 (defun calc-u-prefix-help ()
654 '("Simplify, Convert, coNvert exact, Temperature-convert, Base-units"
655 "Autorange; Remove, eXtract; Explain; View-table; 0-9"
656 "Define, Undefine, Get-defn, Permanent"
657 "SHIFT + View-table-other-window"
658 "SHIFT + stat: Mean, G-mean, Std-dev, Covar, maX, miN"
659 "SHIFT + stat: + (sum), - (asum), * (prod), # (count)")
662 (defun calc-l-prefix-help ()
665 '("Quantity, DB level, Np level"
667 "Scientific pitch notation, Midi number, Frequency"
671 (defun calc-v-prefix-help ()
674 '("Pack, Unpack, Identity, Diagonal, indeX, Build"
675 "Row, Column, Subvector; Length; Find; Mask, Expand"
676 "Transpose, Arrange, reVerse; Head, Kons; rNorm"
677 "SHIFT + Det, & (inverse), LUD, Trace, conJtrn, Cross"
678 "SHIFT + Sort, Grade, Histogram; cNorm"
679 "SHIFT + Apply, Map, Reduce, accUm, Inner-, Outer-prod"
680 "SHIFT + sets: V (union), ^ (intersection), - (diff)"
681 "SHIFT + sets: Xor, ~ (complement), Floor, Enum"
682 "SHIFT + sets: : (span), # (card), + (rdup)"
683 "<, =, > (justification); , (commas); [, {, ( (brackets)"
684 "} (matrix brackets); . (abbreviate); / (multi-lines)")
689 ;;; calc-help.el ends here