("Czech"): Fix the documentation.
[bpt/emacs.git] / lisp / info.el
index 58e1b0b..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)
 
@@ -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.
@@ -999,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 ()
@@ -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))
@@ -2252,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.
@@ -2265,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:
@@ -2279,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)
@@ -2558,8 +2579,15 @@ the variable `Info-file-list-for-emacs'."
   ;; 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 (< (next-property-change (point-min) nil (point-max))
-            (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))
@@ -2580,15 +2608,24 @@ the variable `Info-file-list-for-emacs'."
                                   '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 down-mouse-1] fun)
-                     (define-key keymap [header-line down-mouse-2] fun)
-                     (put-text-property tbeg nend 'local-map keymap))))
-               ))))
+               ;; 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)
@@ -2604,10 +2641,8 @@ the variable `Info-file-list-for-emacs'."
          ;; 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))))
+           (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