("Czech"): Fix the documentation.
[bpt/emacs.git] / lisp / info.el
index 6fbe187..9ce5bb7 100644 (file)
@@ -61,9 +61,9 @@ The Lisp code is executed when the node is selected.")
   :group 'info)
 
 (defface info-node
-  '((((class color) (background light)) (:foreground "brown" :bold t :italic t))
-    (((class color) (background dark)) (:foreground "white" :bold t :italic t))
-    (t (:bold t :italic t)))
+  '((((class color) (background light)) (:foreground "brown" :weight bold :slant italic))
+    (((class color) (background dark)) (:foreground "white" :weight bold :slant italic))
+    (t (:weight bold :slant italic)))
   "Face for Info node names."
   :group 'info)
 
@@ -74,9 +74,9 @@ The Lisp code is executed when the node is selected.")
   :group 'info)
 
 (defface info-xref
-  '((((class color) (background light)) (:foreground "magenta4" :bold t))
-    (((class color) (background dark)) (:foreground "cyan" :bold t))
-    (t (:bold t)))
+  '((((class color) (background light)) (:foreground "magenta4" :weight bold))
+    (((class color) (background dark)) (:foreground "cyan" :weight bold))
+    (t (:weight bold)))
   "Face for Info cross-references."
   :group 'info)
 
@@ -508,12 +508,12 @@ it says do not attempt further (recursive) error recovery."
 (defun Info-on-current-buffer (&optional nodename)
   "Use the `Info-mode' to browse the current info buffer.
 If a prefix arg is provided, it queries for the NODENAME which
-else defaults to `Top'."
+else defaults to \"Top\"."
   (interactive
    (list (if current-prefix-arg
             (completing-read "Node name: " (Info-build-node-completions)
-                             nil t "Top")
-          "Top")))
+                             nil t "Top"))))
+  (unless nodename (setq nodename "Top"))
   (info-initialize)
   (Info-mode)
   (set (make-local-variable 'Info-current-file) t)
@@ -609,7 +609,7 @@ a case-insensitive match is tried."
               (erase-buffer)
               (if (eq filename t)
                   (Info-insert-dir)
-                (info-insert-file-contents filename t)
+                (info-insert-file-contents filename nil)
                 (setq default-directory (file-name-directory filename)))
               (set-buffer-modified-p nil)
               ;; See whether file has a tag table.  Record the location if yes.
@@ -901,7 +901,6 @@ a case-insensitive match is tried."
       (while buffers
        (kill-buffer (car buffers))
        (setq buffers (cdr buffers)))
-      (if Info-fontify (Info-fontify-menu-headers))
       (goto-char (point-min))
       (if problems
          (message "Composing main Info directory...problems encountered, see `*Messages*'")
@@ -1000,7 +999,8 @@ Bind this in case the user sets it to nil."
        (if Info-fontify (Info-fontify-node))
        (if Info-use-header-line
            (Info-setup-header-line)
-         (setq Info-header-line nil))
+         (setq Info-header-line nil)
+         (setq header-line-format nil)) ; so the header line isn't displayed
        (run-hooks 'Info-selection-hook)))))
 
 (defun Info-set-mode-line ()
@@ -1353,8 +1353,9 @@ FOOTNOTENAME may be an abbreviation of the reference name."
          (setq default (car (car completions))))
      (if completions
         (let ((input (completing-read (if default
-                                          (concat "Follow reference named: ("
-                                                  default ") ")
+                                          (concat
+                                           "Follow reference named: (default "
+                                           default ") ")
                                         "Follow reference named: ")
                                       completions nil t)))
           (list (if (equal input "")
@@ -1393,12 +1394,7 @@ FOOTNOTENAME may be an abbreviation of the reference name."
              (buffer-substring-no-properties beg (1- (point)))
            (skip-chars-forward " \t\n")
            (Info-following-node-name (if multi-line "^.,\t" "^.,\t\n"))))
-    (while (setq i (string-match "\n" str i))
-      (aset str i ?\ ))
-    ;; Collapse multiple spaces.
-    (while (string-match "  +" str)
-      (setq str (replace-match " " t t str)))
-    str))
+    (replace-regexp-in-string "[ \n]+" " " str)))
 
 ;; No one calls this.
 ;;(defun Info-menu-item-sequence (list)
@@ -1407,49 +1403,63 @@ FOOTNOTENAME may be an abbreviation of the reference name."
 ;;    (setq list (cdr list))))
 
 (defvar Info-complete-menu-buffer)
+(defvar Info-complete-next-re nil)
+(defvar Info-complete-cache nil)
 
 (defun Info-complete-menu-item (string predicate action)
-  (let ((completion-ignore-case t)
-       (case-fold-search t))
-    (cond ((eq action nil)
-          (let (completions
-                (pattern (concat "\n\\* +\\("
-                                 (regexp-quote string)
-                                 "[^:\t\n]*\\):")))
-            (save-excursion
-              (set-buffer Info-complete-menu-buffer)
-              (goto-char (point-min))
-              (search-forward "\n* Menu:")
-              (while (re-search-forward pattern nil t)
-                (setq completions
-                      (cons (cons (match-string-no-properties 1)
-                                  (match-beginning 1))
-                            completions))))
-            (try-completion string completions predicate)))
-         ((eq action t)
-          (let (completions
-                (pattern (concat "\n\\* +\\("
-                                 (regexp-quote string)
-                                 "[^:\t\n]*\\):")))
-            (save-excursion
-              (set-buffer Info-complete-menu-buffer)
-              (goto-char (point-min))
-              (search-forward "\n* Menu:")
-              (while (re-search-forward pattern nil t)
-                (setq completions (cons (cons
-                                         (match-string-no-properties 1)
-                                         (match-beginning 1))
-                                        completions))))
-            (all-completions string completions predicate)))
-         (t
-          (save-excursion
-            (set-buffer Info-complete-menu-buffer)
-            (goto-char (point-min))
-            (search-forward "\n* Menu:")
-            (re-search-forward (concat "\n\\* +"
-                                       (regexp-quote string)
-                                       ":")
-                               nil t))))))
+  ;; This uses two dynamically bound variables:
+  ;; - `Info-complete-menu-buffer' which contains the buffer in which
+  ;; is the menu of items we're trying to complete.
+  ;; - `Info-complete-next-re' which, if non-nil, indicates that we should
+  ;; also look for menu items in subsequent nodes as long as those
+  ;; nodes' names match `Info-complete-next-re'.  This feature is currently
+  ;; only used for completion in Info-index.
+  (save-excursion
+    (set-buffer Info-complete-menu-buffer)
+    (let ((completion-ignore-case t)
+         (case-fold-search t)
+         (orignode Info-current-node)
+         nextnode)
+      (goto-char (point-min))
+      (search-forward "\n* Menu:")
+      (if (not (memq action '(nil t)))
+         (re-search-forward
+          (concat "\n\\* +" (regexp-quote string) ":") nil t)
+       (let ((pattern (concat "\n\\* +\\("
+                              (regexp-quote string)
+                              "[^:\t\n]*\\):"))
+             completions)
+         ;; Check the cache.
+         (if (and (equal (nth 0 Info-complete-cache) Info-current-file)
+                  (equal (nth 1 Info-complete-cache) Info-current-node)
+                  (equal (nth 2 Info-complete-cache) Info-complete-next-re)
+                  (let ((prev (nth 3 Info-complete-cache)))
+                    (eq t (compare-strings string 0 (length prev)
+                                           prev 0 nil t))))
+             ;; We can reuse the previous list.
+             (setq completions (nth 4 Info-complete-cache))
+           ;; The cache can't be used.
+           (while
+               (progn
+                 (while (re-search-forward pattern nil t)
+                   (push (cons (match-string-no-properties 1)
+                               (match-beginning 1))
+                         completions))
+                 ;; Check subsequent nodes if applicable.
+                 (and Info-complete-next-re
+                      (setq nextnode (Info-extract-pointer "next" t))
+                      (string-match Info-complete-next-re nextnode)))
+             (Info-goto-node nextnode))
+           ;; Go back to the start node (for the next completion).
+           (unless (equal Info-current-node orignode)
+             (Info-goto-node orignode))
+           ;; Update the cache.
+           (setq Info-complete-cache
+                 (list Info-current-file Info-current-node
+                       Info-complete-next-re string completions)))
+         (if action
+             (all-completions string completions predicate)
+           (try-completion string completions predicate)))))))
 
 
 (defun Info-menu (menu-item &optional fork)
@@ -1817,38 +1827,49 @@ parent node."
            (error "No cross references in this node")
          (Info-prev-reference t)))))
 
+(defun Info-goto-index ()
+  (Info-goto-node "Top")
+  (or (search-forward "\n* menu:" nil t)
+      (error "No index"))
+  (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
+      (error "No index"))
+  (goto-char (match-beginning 1))
+  ;; Protect Info-history so that the current node (Top) is not added to it.
+  (let ((Info-history nil))
+    (Info-goto-node (Info-extract-menu-node-name))))
+
 (defun Info-index (topic)
   "Look up a string TOPIC in the index for this file.
-The index is defined as the first node in the top-level menu whose
+The index is defined as the first node in the top level menu whose
 name contains the word \"Index\", plus any immediately following
 nodes whose names also contain the word \"Index\".
 If there are no exact matches to the specified topic, this chooses
 the first match which is a case-insensitive substring of a topic.
 Use the `,' command to see the other matches.
 Give a blank topic name to go to the Index node itself."
-  (interactive "sIndex topic: ")
+  (interactive
+   (list
+    (let ((Info-complete-menu-buffer (clone-buffer))
+         (Info-complete-next-re "\\<Index\\>"))
+      (unwind-protect
+         (with-current-buffer Info-complete-menu-buffer
+           (Info-goto-index)
+           (completing-read "Index topic: " 'Info-complete-menu-item))
+       (kill-buffer Info-complete-menu-buffer)))))
   (let ((orignode Info-current-node)
        (rnode nil)
        (pattern (format "\n\\* +\\([^\n:]*%s[^\n:]*\\):[ \t]*\\([^.\n]*\\)\\.[ \t]*\\([0-9]*\\)"
                         (regexp-quote topic)))
        node
        (case-fold-search t))
-    (Info-goto-node "Top")
-    (or (search-forward "\n* menu:" nil t)
-       (error "No index"))
-    (or (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t)
-       (error "No index"))
-    (goto-char (match-beginning 1))
-    ;; Here, and subsequently in this function,
-    ;; we bind Info-history to nil for internal node-switches
-    ;; so that we don't put junk in the history.
-    ;; In the first Info-goto-node call, above, we do update the history
-    ;; because that is what the user's previous node choice into it.
-    (let ((Info-history nil))
-      (Info-goto-node (Info-extract-menu-node-name)))
+    (Info-goto-index)
     (or (equal topic "")
        (let ((matches nil)
              (exact nil)
+             ;; We bind Info-history to nil for internal node-switches so
+             ;; that we don't put junk in the history.  In the first
+             ;; Info-goto-index call, above, we do update the history
+             ;; because that is what the user's previous node choice into it.
              (Info-history nil)
              found)
          (while
@@ -2156,8 +2177,7 @@ If no reference to follow, moves to the next node, or up if none."
        ;; Update menu menu.
        (let* ((Info-complete-menu-buffer (current-buffer))
               (items (nreverse (condition-case nil
-                                   (Info-complete-menu-item
-                                    "" (lambda (e) t) t)
+                                   (Info-complete-menu-item "" nil t)
                                  (error nil))))
               entries current
               (number 0))
@@ -2230,6 +2250,7 @@ The name of the info file is prepended to the node name in parentheses."
 \f
 ;; Info mode is suitable only for specially formatted data.
 (put 'Info-mode 'mode-class 'special)
+(put 'Info-mode 'no-clone-indirect t)
 
 (defun Info-mode ()
   "Info mode provides commands for browsing through the Info documentation tree.
@@ -2251,7 +2272,7 @@ Selecting other nodes:
 \\[Info-prev]  Move to the \"previous\" node of this node.
 \\[Info-up]    Move \"up\" from this node.
 \\[Info-menu]  Pick menu item specified by name (or abbreviation).
-       Picking a menu item causes another node to be selected.
+         Picking a menu item causes another node to be selected.
 \\[Info-directory]     Go to the Info directory node.
 \\[Info-follow-reference]      Follow a cross reference.  Reads name of reference.
 \\[Info-last]  Move to the last node you were at.
@@ -2264,12 +2285,13 @@ Selecting other nodes:
 
 Moving within a node:
 \\[Info-scroll-up]     Normally, scroll forward a full screen.
-Once you scroll far enough in a node that its menu appears on the screen
-but after point, the next scroll moves into its first subnode.
-When after all menu items (or if their is no menu), move up to
-the parent node.
+         Once you scroll far enough in a node that its menu appears on the
+         screen but after point, the next scroll moves into its first
+         subnode.  When after all menu items (or if there is no menu),
+         move up to the parent node.
 \\[Info-scroll-down]   Normally, scroll backward.  If the beginning of the buffer is
-already visible, try to go to the previous menu entry, or up if there is none.
+         already visible, try to go to the previous menu entry, or up
+         if there is none.
 \\[beginning-of-buffer]        Go to beginning of node.
 
 Advanced commands:
@@ -2278,10 +2300,10 @@ Advanced commands:
 1      Pick first item in node's menu.
 2, 3, 4, 5   Pick second ... fifth item in node's menu.
 \\[Info-goto-node]     Move to node specified by name.
-       You may include a filename as well, as (FILENAME)NODENAME.
+         You may include a filename as well, as (FILENAME)NODENAME.
 \\[universal-argument] \\[info]        Move to new Info file with completion.
 \\[Info-search]        Search through this Info file for specified regexp,
-       and select the node in which the next occurrence is found.
+         and select the node in which the next occurrence is found.
 \\[Info-next-reference]        Move cursor to next cross-reference or menu item.
 \\[Info-prev-reference]        Move cursor to previous cross-reference or menu item."
   (kill-all-local-variables)
@@ -2382,7 +2404,8 @@ Allowed only if variable `Info-enable-edit' is non-nil."
     ("copyright" . "autotype") ("executable" . "autotype")
     ("time-stamp" . "autotype") ("quickurl" . "autotype")
     ("tempo" . "autotype") ("hippie-expand" . "autotype")
-    ("cvs" . "pcl-cvs") ("ada" . "ada-mode")
+    ("cvs" . "pcl-cvs") ("ada" . "ada-mode") "calc"
+    ("calcAlg" . "calc") ("calcDigit" . "calc") ("calcVar" . "calc")
     "ebrowse" "eshell" "cl" "reftex" "speedbar" "widget" "woman"
     ("mail-header" . "emacs-mime") ("mail-content" . "emacs-mime")
     ("mail-encode" . "emacs-mime") ("mail-decode" . "emacs-mime")
@@ -2553,80 +2576,99 @@ the variable `Info-file-list-for-emacs'."
                           'face 'info-menu-header)))))
 
 (defun Info-fontify-node ()
-  (save-excursion
-    (let ((buffer-read-only nil)
-         (case-fold-search t))
-      (goto-char (point-min))
-      (when (looking-at "^File: [^,: \t]+,?[ \t]+")
-       (goto-char (match-end 0))
-       (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
+  ;; Only fontify the node if it hasn't already been done.  [We pass in
+  ;; LIMIT arg to `next-property-change' because it seems to search past
+  ;; (point-max).]
+  (unless (and (< (next-property-change (point-min) nil (point-max))
+                 (point-max))
+              ;; But do put the text properties if the local-map property
+              ;; is inconsistent with Info-use-header-line's value.
+              (eq
+               (= (next-single-property-change
+                   (point-min) 'local-map nil (point-max))
+                  (point-max))
+               (null Info-use-header-line)))
+    (save-excursion
+      (let ((buffer-read-only nil)
+           (case-fold-search t))
+       (goto-char (point-min))
+       (when (looking-at "^File: [^,: \t]+,?[ \t]+")
          (goto-char (match-end 0))
-         (let* ((nbeg (match-beginning 2))
-                (nend (match-end 2))
-                (tbeg (match-beginning 1))
-                (tag (buffer-substring tbeg (match-end 1))))
-           (if (string-equal tag "Node")
-               (put-text-property nbeg nend 'face 'info-header-node)
-             (put-text-property nbeg nend 'face 'info-header-xref)
-             (put-text-property nbeg nend 'mouse-face 'highlight)
-             (put-text-property tbeg nend
-                                'help-echo
-                                (concat "Go to node "
-                                        (buffer-substring nbeg nend)))
-             (let ((fun (cdr (assoc tag '(("Prev" . Info-prev)
-                                          ("Next" . Info-next)
-                                          ("Up" . Info-up))))))
-               (when fun
-                 (let ((keymap (make-sparse-keymap)))
-                   (define-key keymap [header-line mouse-1] fun)
-                   (define-key keymap [header-line mouse-2] fun)
-                   (put-text-property tbeg nend 'local-map keymap))))
-             ))))
-      (goto-char (point-min))
-      (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
-                               nil t)
-       (let ((c (preceding-char))
-             face)
-         (cond ((= c ?*) (setq face 'Info-title-1-face))
-               ((= c ?=) (setq face 'Info-title-2-face))
-               ((= c ?-) (setq face 'Info-title-3-face))
-               (t        (setq face 'Info-title-4-face)))
-         (put-text-property (match-beginning 1) (match-end 1)
-                            'face face))
-       ;; This is a serious problem for trying to handle multiple
-       ;; frame types at once.  We want this text to be invisible
-       ;; on frames that can display the font above.
-       (when (memq (framep (selected-frame)) '(x pc w32 mac))
-         (add-text-properties (match-end 1) (match-end 2)
-                              '(invisible t intangible t))
-         (add-text-properties (1- (match-end 1)) (match-end 2)
-                              '(intangible t))))
-      (goto-char (point-min))
-      (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
-       (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
-           nil
-         (add-text-properties (match-beginning 1) (match-end 1)
-                              '(face info-xref
-                                mouse-face highlight
-                                help-echo "mouse-2: go to this node"))))
-      (goto-char (point-min))
-      (if (and (search-forward "\n* Menu:" nil t)
-              (not (string-match "\\<Index\\>" Info-current-node))
-              ;; Don't take time to annotate huge menus
-              (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
-         (let ((n 0))
-           (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
-             (setq n (1+ n))
-             (if (memq n '(5 9))       ; visual aids to help with 1-9 keys
-                 (put-text-property (match-beginning 0)
-                                    (1+ (match-beginning 0))
-                                    'face 'info-menu-5))
-             (add-text-properties (match-beginning 1) (match-end 1)
-                                  '(face info-xref
-                                    mouse-face highlight
-                                    help-echo "mouse-2: go to this node")))))
-      (Info-fontify-menu-headers)
-      (set-buffer-modified-p nil))))
+         (while (looking-at "[ \t]*\\([^:, \t\n]+\\):[ \t]+\\([^:,\t\n]+\\),?")
+           (goto-char (match-end 0))
+           (let* ((nbeg (match-beginning 2))
+                  (nend (match-end 2))
+                  (tbeg (match-beginning 1))
+                  (tag (buffer-substring tbeg (match-end 1))))
+             (if (string-equal tag "Node")
+                 (put-text-property nbeg nend 'face 'info-header-node)
+               (put-text-property nbeg nend 'face 'info-header-xref)
+               (put-text-property nbeg nend 'mouse-face 'highlight)
+               (put-text-property tbeg nend
+                                  'help-echo
+                                  (concat "Go to node "
+                                          (buffer-substring nbeg nend)))
+               ;; Don't bind mouse events on the header line if we
+               ;; aren't going to display the header line.
+               (when Info-use-header-line
+                 (let ((fun (cdr (assoc tag '(("Prev" . Info-prev)
+                                              ("Next" . Info-next)
+                                              ("Up" . Info-up))))))
+                   (when fun
+                     (let ((keymap (make-sparse-keymap)))
+                       (define-key keymap [header-line down-mouse-1] fun)
+                       (define-key keymap [header-line down-mouse-2] fun)
+                       (put-text-property tbeg nend 'local-map keymap)))))
+               (if (not Info-use-header-line)
+                   ;; In case they switched Info-use-header-line off
+                   ;; in the middle of an Info session, some text
+                   ;; properties may have been left lying around from
+                   ;; past visits of this node.  Remove them.
+                   (remove-text-properties tbeg nend '(local-map nil)))
+                 ))))
+       (goto-char (point-min))
+       (while (re-search-forward "\n\\([^ \t\n].+\\)\n\\(\\*+\\|=+\\|-+\\|\\.+\\)$"
+                                 nil t)
+         (let ((c (preceding-char))
+               face)
+           (cond ((= c ?*) (setq face 'Info-title-1-face))
+                 ((= c ?=) (setq face 'Info-title-2-face))
+                 ((= c ?-) (setq face 'Info-title-3-face))
+                 (t        (setq face 'Info-title-4-face)))
+           (put-text-property (match-beginning 1) (match-end 1)
+                              'face face))
+         ;; This is a serious problem for trying to handle multiple
+         ;; frame types at once.  We want this text to be invisible
+         ;; on frames that can display the font above.
+         (when (memq (framep (selected-frame)) '(x pc w32 mac))
+           (add-text-properties (match-beginning 2) (1+ (match-end 2))
+                                '(invisible t intangible t))))
+       (goto-char (point-min))
+       (while (re-search-forward "\\*Note[ \n\t]+\\([^:]*\\):" nil t)
+         (if (= (char-after (1- (match-beginning 0))) ?\") ; hack
+             nil
+           (add-text-properties (match-beginning 1) (match-end 1)
+                                '(face info-xref
+                                  mouse-face highlight
+                                  help-echo "mouse-2: go to this node"))))
+       (goto-char (point-min))
+       (if (and (search-forward "\n* Menu:" nil t)
+                (not (string-match "\\<Index\\>" Info-current-node))
+                ;; Don't take time to annotate huge menus
+                (< (- (point-max) (point)) Info-fontify-maximum-menu-size))
+           (let ((n 0))
+             (while (re-search-forward "^\\* +\\([^:\t\n]*\\):" nil t)
+               (setq n (1+ n))
+               (if (zerop (% n 3)) ; visual aids to help with 1-9 keys
+                   (put-text-property (match-beginning 0)
+                                      (1+ (match-beginning 0))
+                                      'face 'info-menu-5))
+               (add-text-properties (match-beginning 1) (match-end 1)
+                                    '(face info-xref
+                                      mouse-face highlight
+                                      help-echo "mouse-2: go to this node")))))
+       (Info-fontify-menu-headers)
+       (set-buffer-modified-p nil)))))
 \f
 
 ;; When an Info buffer is killed, make sure the associated tags buffer