]> code.delx.au - gnu-emacs/blobdiff - lisp/calc/calc-help.el
Merge from emacs--rel--22
[gnu-emacs] / lisp / calc / calc-help.el
index 32f86d6f750fca1b308b0319951add2ece4b3e82..49d1fd937ba1319b5833bc0b7a0c70ee42483ce8 100644 (file)
@@ -1,38 +1,40 @@
 ;;; calc-help.el --- help display functions for Calc,
 
-;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002 Free Software Foundation, Inc.
+;; Copyright (C) 1990, 1991, 1992, 1993, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007  Free Software Foundation, Inc.
 
 ;; Author: David Gillespie <daveg@synaptics.com>
-;; Maintainers: D. Goel <deego@gnufans.org>
-;;              Colin Walters <walters@debian.org>
+;; Maintainer: Jay Belanger <jay.p.belanger@gmail.com>
 
 ;; This file is part of GNU Emacs.
 
+;; GNU Emacs 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 3, or (at your option)
+;; any later version.
+
 ;; GNU Emacs is distributed in the hope that it will be useful,
-;; but WITHOUT ANY WARRANTY.  No author or distributor
-;; accepts responsibility to anyone for the consequences of using it
-;; or for whether it serves any particular purpose or works at all,
-;; unless he says so in writing.  Refer to the GNU Emacs General Public
-;; License for full details.
-
-;; Everyone is granted permission to copy, modify and redistribute
-;; GNU Emacs, but only under the conditions described in the
-;; GNU Emacs General Public License.   A copy of this license is
-;; supposed to have been given to you along with GNU Emacs so you
-;; can know your rights and responsibilities.  It should be in a
-;; file named COPYING.  Among other things, the copyright notice
-;; and this notice must be preserved on all copies.
+;; 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 GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 ;;; Code:
 
 ;; This file is autoloaded from calc-ext.el.
-(require 'calc-ext)
 
+(require 'calc-ext)
 (require 'calc-macs)
 
-(defun calc-Need-calc-help () nil)
+;; Declare functions which are defined elsewhere.
+(declare-function Info-goto-node "info" (nodename &optional fork))
+(declare-function Info-last "info" ())
 
 
 (defun calc-help-prefix (arg)
@@ -112,39 +114,34 @@ C-w  Describe how there is no warranty for Calc."
   (describe-bindings)
   (save-excursion
     (set-buffer "*Help*")
-    (goto-char (point-min))
-    (if (search-forward "Global bindings:" nil t)
-       (delete-region (match-beginning 0) (point-max)))
-    (goto-char (point-min))
-    (while (re-search-forward "\n[a-z] ESC" nil t)
-      (end-of-line)
-      (delete-region (match-beginning 0) (point)))
-    (goto-char (point-min))
-    (while (re-search-forward "\nESC m" nil t)
-      (end-of-line)
-      (delete-region (match-beginning 0) (point)))
-    (goto-char (point-min))
-    (while (search-forward "\n\n\n" nil t)
-      (backward-delete-char 1)
-      (backward-char 2))
-    (goto-char (point-min))
-    (while
-       (re-search-forward
-        "\n[a-z] [0-9]\\(\t\t.*\n\\)\\([a-z] [0-9]\\1\\)*[a-z] \\([0-9]\\)\\1"
-        nil t)
-      (let ((dig1 (char-after (1- (match-beginning 1))))
-           (dig2 (char-after (match-beginning 3))))
-       (delete-region (match-end 1) (match-end 0))
-       (goto-char (match-beginning 1))
-       (delete-backward-char 1)
-       (delete-char 1)
-       (insert (format "%c .. %c" (min dig1 dig2) (max dig1 dig2)))))
-    (goto-char (point-min))))
+    (let ((inhibit-read-only t))
+      (goto-char (point-min))
+      (when (search-forward "Major Mode Bindings:" nil t)
+        (delete-region (point-min) (point))
+        (insert "Calc Mode Bindings:"))
+      (when (search-forward "Global bindings:" nil t)
+        (forward-line -1)
+        (delete-region (point) (point-max)))
+      (goto-char (point-min))
+      (while
+          (re-search-forward
+           "\n[a-z] [0-9]\\( .*\n\\)\\([a-z] [0-9]\\1\\)*[a-z] \\([0-9]\\)\\1"
+           nil t)
+        (let ((dig1 (char-after (1- (match-beginning 1))))
+              (dig2 (char-after (match-beginning 3))))
+          (delete-region (match-end 1) (match-end 0))
+          (goto-char (match-beginning 1))
+          (delete-backward-char 1)
+          (delete-char 5)
+          (insert (format "%c .. %c" (min dig1 dig2) (max dig1 dig2)))))
+      (goto-char (point-min)))))
 
 (defun calc-describe-key-briefly (key)
   (interactive "kDescribe key briefly: ")
   (calc-describe-key key t))
 
+(defvar Info-history)
+
 (defun calc-describe-key (key &optional briefly)
   (interactive "kDescribe key: ")
   (let ((defn (if (eq (key-binding key) 'calc-dispatch)
@@ -163,7 +160,8 @@ C-w  Describe how there is no warranty for Calc."
                      (lookup-key calc-help-map key2))
                  (key-binding key))))
        (inv nil)
-       (hyp nil))
+       (hyp nil)
+        calc-summary-indentation)
     (while (or (equal key "I") (equal key "H"))
       (if (equal key "I")
          (setq inv (not inv))
@@ -185,19 +183,20 @@ C-w  Describe how there is no warranty for Calc."
                       (if (= (buffer-size) 0)
                           (progn
                             (message "Reading Calc summary from manual...")
-                            (save-window-excursion
-                              (save-excursion
-                                (calc-info-goto-node "Summary")
-                                (goto-char (point-min))
-                                (forward-line 1)
-                                (copy-to-buffer "*Calc Summary*"
-                                                (point) (point-max))
-                                 (if Info-history
-                                     (Info-last))))
-                            (setq case-fold-search nil)
-                            (re-search-forward "^\\(.*\\)\\[\\.\\. a b")
-                            (setq calc-summary-indentation
-                                  (- (match-end 1) (match-beginning 1)))))
+                             (require 'info nil t)
+                             (with-temp-buffer
+                               (Info-mode)
+                               (Info-goto-node "(Calc)Summary")
+                               (goto-char (point-min))
+                               (forward-line 1)
+                               (copy-to-buffer "*Calc Summary*"
+                                               (point) (point-max)))
+                             (setq buffer-read-only t)))
+                       (goto-char (point-min))
+                       (setq case-fold-search nil)
+                       (re-search-forward "^\\(.*\\)\\[\\.\\. a b")
+                       (setq calc-summary-indentation
+                             (- (match-end 1) (match-beginning 1)))
                       (goto-char (point-min))
                       (setq target (if (and (string-match "[0-9]\\'" desc)
                                             (not (string-match "[d#]" desc)))
@@ -296,29 +295,57 @@ C-w  Describe how there is no warranty for Calc."
        (calc-describe-thing desc "Key Index" nil
                             (string-match "[A-Z][A-Z][A-Z]" desc))))))
 
+(defvar calc-help-function-list nil
+  "List of functions provided by Calc.")
+
+(defvar calc-help-variable-list nil
+  "List of variables provided by Calc.")
+
+(defun calc-help-index-entries (&rest indices)
+  "Create a list of entries from the INDICES in the Calc info manual."
+  (let ((entrylist '())
+        entry)
+    (require 'info nil t)
+    (while indices
+      (condition-case nil
+          (with-temp-buffer
+            (Info-mode)
+            (Info-goto-node (concat "(Calc)" (car indices) " Index"))
+            (goto-char (point-min))
+            (while (re-search-forward "\n\\* \\(.*\\): " nil t)
+              (setq entry (match-string 1))
+              (if (and (not (string-match "<[1-9]+>" entry))
+                       (not (string-match "(.*)" entry))
+                       (not (string= entry "Menu")))
+                  (unless (assoc entry entrylist)
+                    (setq entrylist (cons entry entrylist))))))
+        (error nil))
+      (setq indices (cdr indices)))
+    entrylist))
+
 (defun calc-describe-function (&optional func)
   (interactive)
+  (unless calc-help-function-list
+    (setq calc-help-function-list
+          (calc-help-index-entries "Function" "Command")))
   (or func
-      (setq func (intern (completing-read "Describe function: "
-                                         obarray nil t "calcFunc-"))))
-  (setq func (symbol-name func))
+      (setq func (completing-read "Describe function: "
+                                  calc-help-function-list
+                                  nil t)))
   (if (string-match "\\`calc-." func)
       (calc-describe-thing func "Command Index")
-    (calc-describe-thing (if (string-match "\\`calcFunc-." func)
-                            (substring func 9)
-                          func)
-                        "Function Index")))
+    (calc-describe-thing func "Function Index")))
 
 (defun calc-describe-variable (&optional var)
   (interactive)
+  (unless calc-help-variable-list
+    (setq calc-help-variable-list
+          (calc-help-index-entries "Variable")))
   (or var
-      (setq var (intern (completing-read "Describe variable: "
-                                        obarray nil t "var-"))))
-  (setq var (symbol-name var))
-  (calc-describe-thing var "Variable Index"
-                      (if (string-match "\\`var-." var)
-                          (substring var 4)
-                        var)))
+      (setq var (completing-read "Describe variable: "
+                                 calc-help-variable-list
+                                 nil t)))
+  (calc-describe-thing var "Variable Index"))
 
 (defun calc-describe-thing (thing where &optional target not-quoted)
   (message "Looking for `%s' in %s..." thing where)
@@ -371,75 +398,77 @@ C-w  Describe how there is no warranty for Calc."
        (error "Can't locate Calc sources"))
     (calc-quit)
     (switch-to-buffer "*Help*")
-    (erase-buffer)
-    (insert-file-contents (expand-file-name "README" (car path)))
-    (search-forward "Summary of changes")
-    (forward-line -1)
-    (delete-region (point-min) (point))
-    (goto-char (point-min))))
+    (let ((inhibit-read-only t))
+      (erase-buffer)
+      (insert-file-contents (expand-file-name "README" (car path)))
+      (search-forward "Summary of changes")
+      (forward-line -1)
+      (delete-region (point-min) (point))
+      (goto-char (point-min)))
+    (help-mode)))
+
+(defvar calc-help-long-names '((?b . "binary/business")
+                              (?g . "graphics")
+                              (?j . "selection")
+                              (?k . "combinatorics/statistics")
+                              (?u . "units/statistics")))
 
 (defun calc-full-help ()
   (interactive)
   (with-output-to-temp-buffer "*Help*"
-    (princ (format "GNU Emacs Calculator version %s of %s.\n"
-                  calc-version calc-version-date))
-    (princ "  By Dave Gillespie, daveg@synaptics.com.\n")
-    (princ "  Copyright (C) 1990, 1993 Free Software Foundation, Inc.\n\n")
+    (princ (format "GNU Emacs Calculator version %s.\n"
+                  calc-version))
+    (princ "  By Dave Gillespie.\n")
+    (princ (format "  %s\n\n" emacs-copyright))
     (princ "Type `h s' for a more detailed summary.\n")
     (princ "Or type `h i' to read the full Calc manual on-line.\n\n")
     (princ "Basic keys:\n")
     (let* ((calc-full-help-flag t))
-      (mapcar (function (lambda (x) (princ (format "  %s\n" x))))
-             (nreverse (cdr (reverse (cdr (calc-help))))))
-      (mapcar (function (lambda (prefix)
-                         (let ((msgs (condition-case err
-                                         (funcall prefix)
-                                       (error nil))))
-                           (if (car msgs)
-                               (princ
-                                (if (eq (nth 2 msgs) ?v)
-                                    "\n`v' or `V' prefix (vector/matrix) keys: \n"
-                                  (if (nth 2 msgs)
-                                      (format
-                                       "\n`%c' prefix (%s) keys:\n"
-                                       (nth 2 msgs)
-                                       (or (cdr (assq (nth 2 msgs)
-                                                      calc-help-long-names))
-                                           (nth 1 msgs)))
-                                    (format "\n%s-modified keys:\n"
-                                            (capitalize (nth 1 msgs)))))))
-                           (mapcar (function (lambda (x)
-                                               (princ (format "  %s\n" x))))
-                                   (car msgs)))))
-             '(calc-inverse-prefix-help
-               calc-hyperbolic-prefix-help
-               calc-inv-hyp-prefix-help
-               calc-a-prefix-help
-               calc-b-prefix-help
-               calc-c-prefix-help
-               calc-d-prefix-help
-               calc-f-prefix-help
-               calc-g-prefix-help
-               calc-h-prefix-help
-               calc-j-prefix-help
-               calc-k-prefix-help
-               calc-m-prefix-help
-               calc-r-prefix-help
-               calc-s-prefix-help
-               calc-t-prefix-help
-               calc-u-prefix-help
-               calc-v-prefix-help
-               calc-shift-Y-prefix-help
-               calc-shift-Z-prefix-help
-               calc-z-prefix-help)))
+      (mapc (function (lambda (x) (princ (format "  %s\n" x))))
+           (nreverse (cdr (reverse (cdr (calc-help))))))
+      (mapc (function (lambda (prefix)
+                       (let ((msgs (condition-case err
+                                       (funcall prefix)
+                                     (error nil))))
+                         (if (car msgs)
+                             (princ
+                              (if (eq (nth 2 msgs) ?v)
+                                  "\n`v' or `V' prefix (vector/matrix) keys: \n"
+                                (if (nth 2 msgs)
+                                    (format
+                                     "\n`%c' prefix (%s) keys:\n"
+                                     (nth 2 msgs)
+                                     (or (cdr (assq (nth 2 msgs)
+                                                    calc-help-long-names))
+                                         (nth 1 msgs)))
+                                  (format "\n%s-modified keys:\n"
+                                          (capitalize (nth 1 msgs)))))))
+                         (mapcar (function (lambda (x)
+                                   (princ (format "  %s\n" x))))
+                                 (car msgs)))))
+           '(calc-inverse-prefix-help
+             calc-hyperbolic-prefix-help
+             calc-inv-hyp-prefix-help
+             calc-a-prefix-help
+             calc-b-prefix-help
+             calc-c-prefix-help
+             calc-d-prefix-help
+             calc-f-prefix-help
+             calc-g-prefix-help
+             calc-h-prefix-help
+             calc-j-prefix-help
+             calc-k-prefix-help
+             calc-m-prefix-help
+             calc-r-prefix-help
+             calc-s-prefix-help
+             calc-t-prefix-help
+             calc-u-prefix-help
+             calc-v-prefix-help
+             calc-shift-Y-prefix-help
+             calc-shift-Z-prefix-help
+             calc-z-prefix-help)))
     (print-help-return-message)))
 
-(defvar calc-help-long-names '((?b . "binary/business")
-                              (?g . "graphics")
-                              (?j . "selection")
-                              (?k . "combinatorics/statistics")
-                              (?u . "units/statistics")))
-
 (defun calc-h-prefix-help ()
   (interactive)
   (calc-do-prefix-help
@@ -502,7 +531,7 @@ C-w  Describe how there is no warranty for Calc."
   (interactive)
   (calc-do-prefix-help
    '("Store, inTo, Xchg, Unstore; Recall, 0-9; : (:=); = (=>)"
-     "Let; Copy; Declare; Insert, Perm; Edit"
+     "Let; Copy, K=copy constant; Declare; Insert, Perm; Edit"
      "Negate, +, -, *, /, ^, &, |, [, ]; Map"
      "SHIFT + Decls, GenCount, TimeZone, Holidays; IntegLimit"
      "SHIFT + LineStyles, PointStyles, plotRejects; Units"
@@ -571,7 +600,7 @@ C-w  Describe how there is no warranty for Calc."
      "Why; Line-nums, line-Breaks; <, =, > (justify); Plain"
      "\" (strings); Truncate, [, ]; SPC (refresh), RET, @"
      "SHIFT + language: Normal, One-line, Big, Unformatted"
-     "SHIFT + language: C, Pascal, Fortran; TeX, Eqn"
+     "SHIFT + language: C, Pascal, Fortran; TeX, LaTeX, Eqn"
      "SHIFT + language: Mathematica, W=Maple")
    "display" ?d))
 
@@ -606,7 +635,7 @@ C-w  Describe how there is no warranty for Calc."
   (interactive)
   (calc-do-prefix-help
    '("Deg, Rad, HMS; Frac; Polar; Inf; Alg, Total; Symb; Vec/mat"
-     "Working; Xtensions; Mode-save"
+     "Working; Xtensions; Mode-save; preserve Embedded modes"
      "SHIFT + Shifted-prefixes, mode-Filename; Record; reCompute"
      "SHIFT + simplify: Off, Num, Default, Bin, Alg, Ext, Units")
    "mode" ?m))
@@ -652,5 +681,7 @@ C-w  Describe how there is no warranty for Calc."
      "} (matrix brackets); . (abbreviate); / (multi-lines)")
    "vec/mat" ?v))
 
-;;; arch-tag: 2d347593-7591-449e-a64a-93dab5f2f686
+(provide 'calc-help)
+
+;; arch-tag: 2d347593-7591-449e-a64a-93dab5f2f686
 ;;; calc-help.el ends here