(Man-notify-when-ready): Don't use window-system. If
[bpt/emacs.git] / lisp / info.el
index 494570b..78c2193 100644 (file)
@@ -109,8 +109,8 @@ It doesn't contain directory names or file name extensions added by Info.
 Can also be t when using `Info-on-current-buffer'.")
 
 (defvar Info-current-subfile nil
-  "Info subfile that is actually in the *info* buffer now,
-or nil if current info file is not split into subfiles.")
+  "Info subfile that is actually in the *info* buffer now.
+nil if current info file is not split into subfiles.")
 
 (defvar Info-current-node nil
   "Name of node that Info is now looking at, or nil.")
@@ -126,7 +126,7 @@ Marker points nowhere if file has no tag table.")
   "Cached completion list for current Info file.")
 
 (defvar Info-index-alternatives nil
-  "List of possible matches for last Info-index command.")
+  "List of possible matches for last `Info-index' command.")
 
 (defvar Info-standalone nil
   "Non-nil if Emacs was started solely as an Info browser.")
@@ -250,8 +250,8 @@ Do the right thing if the file has been compressed or zipped."
            (call-process-region (point-min) (point-max) decoder t t)))
       (insert-file-contents fullname visit))))
 \f
-;; Initialize Info-directory-list, if that hasn't been done yet.
 (defun info-initialize ()
+  "Initialize `Info-directory-list', if that hasn't been done yet."
   (unless Info-directory-list
     (let ((path (getenv "INFOPATH"))
          (source (expand-file-name "info/" source-directory))
@@ -362,10 +362,10 @@ In standalone mode, \\<Info-mode-map>\\[Info-exit] exits Emacs itself."
         (forward-line 1)               ; does the line after delimiter match REGEXP?
         (re-search-backward regexp beg t))))
 
-;; Go to an info node specified as separate filename and nodename.
-;; no-going-back is non-nil if recovering from an error in this function;
-;; it says do not attempt further (recursive) error recovery.
 (defun Info-find-node (filename nodename &optional no-going-back)
+  "Go to an info node specified as separate FILENAME and NODENAME.
+NO-GOING-BACK is non-nil if recovering from an error in this function;
+it says do not attempt further (recursive) error recovery."
   (info-initialize)
   ;; Convert filename to lower case if not found as specified.
   ;; Expand it.
@@ -430,6 +430,76 @@ else defaults to `Top'."
   (set (make-local-variable 'Info-current-file) t)
   (Info-find-node-2 nil nodename))
 
+(defun Info-find-in-tag-table-1 (marker regexp case-fold)
+  "Find a node in a tag table.
+MARKER specifies the buffer and position to start searching at.
+REGEXP is a regular expression matching nodes or references.  Its first
+group should match `Node:' or `Ref:'.
+CASE-FOLD t means search for a case-insensitive match.
+If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
+FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
+where the match was found, and MODE is `major-mode' of the buffer in
+which the match was found."
+  (let ((case-fold-search case-fold)
+       found-mode guesspos found-anchor)
+    (save-excursion
+      (set-buffer (marker-buffer marker))
+      (goto-char marker)
+    
+      ;; Search tag table
+      (beginning-of-line)
+      (when (re-search-forward regexp nil t)
+       (list (string-equal "Ref:" (match-string 1))
+             (1+ (read (current-buffer)))
+             major-mode)))))
+
+(defun Info-find-in-tag-table (marker regexp)
+  "Find a node in a tag table.
+MARKER specifies the buffer and position to start searching at.
+REGEXP is a regular expression matching nodes or references.  Its first
+group should match `Node:' or `Ref:'.
+If a match was found, value is a list (FOUND-ANCHOR POS MODE), where
+FOUND-ANCHOR is non-nil if a `Ref:' was matched, POS is the position
+where the match was found, and MODE is `major-mode' of the buffer in
+which the match was found.
+This function tries to find a case-sensitive match first, then a
+case-insensitive match is tried."
+  (let ((result (Info-find-in-tag-table-1 marker regexp nil)))
+    (when (null (car result))
+      (setq result (Info-find-in-tag-table-1 marker regexp t)))
+    result))
+
+(defun Info-find-node-in-buffer-1 (regexp case-fold)
+  "Find a node or anchor in the current buffer.
+REGEXP is a regular expression matching nodes or references.  Its first
+group should match `Node:' or `Ref:'.
+CASE-FOLD t means search for a case-insensitive match.
+Value is the position at which a match was found, or nil if not found."
+  (let ((case-fold-search case-fold)
+       found)
+    (save-excursion
+      (when (Info-node-at-bob-matching regexp)
+       (setq found (point)))
+      (while (and (not found)
+                 (search-forward "\n\^_" nil t))
+       (forward-line 1)
+       (let ((beg (point)))
+         (forward-line 1)
+         (when (re-search-backward regexp beg t)
+           (beginning-of-line)
+           (setq found (point)))))
+      found)))
+                 
+(defun Info-find-node-in-buffer (regexp)
+  "Find a node or anchor in the current buffer.
+REGEXP is a regular expression matching nodes or references.  Its first
+group should match `Node:' or `Ref:'.
+Value is the position at which a match was found, or nil if not found.
+This function looks for a case-sensitive match first.  If none is found,
+a case-insensitive match is tried."
+  (or (Info-find-node-in-buffer-1 regexp nil)
+      (Info-find-node-in-buffer-1 regexp t)))
+  
 (defun Info-find-node-2 (filename nodename &optional no-going-back)
   (buffer-disable-undo (current-buffer))
   (or (eq major-mode 'Info-mode)
@@ -437,7 +507,6 @@ else defaults to `Top'."
   (widen)
   (setq Info-current-node nil)
   (unwind-protect
-      ;; Bind case-fold-search in case the user sets it to nil.
       (let ((case-fold-search t)
            anchorpos)
         ;; Switch files if necessary
@@ -505,73 +574,49 @@ else defaults to `Top'."
 
           ;; Search file for a suitable node.
          (let ((guesspos (point-min))
-               (regexp
-                (concat "\\(Node:\\|Ref:\\) *\\("
-                        (regexp-quote nodename)
-                        "\\) *[,\t\n\177]"))
+               (regexp (concat "\\(Node:\\|Ref:\\) *\\("
+                               (regexp-quote nodename)
+                               "\\) *[,\t\n\177]"))
                (nodepos nil))
 
            (catch 'foo
+             
              ;; First, search a tag table, if any
-             (if (marker-position Info-tag-table-marker)
-                 (let (found-in-tag-table
-                       found-anchor
-                       found-mode
-                       (m Info-tag-table-marker))
-                   (save-excursion
-                     (set-buffer (marker-buffer m))
-                     (goto-char m)
-                     (beginning-of-line) ; so re-search will work.
-
-                     ;; Search tag table
-                     (setq found-in-tag-table
-                           (re-search-forward regexp nil t)
-                           found-anchor
-                           (string-equal "Ref:" (match-string 1)))
-                     (if found-in-tag-table
-                         (setq guesspos (1+ (read (current-buffer)))))
-                     (setq found-mode major-mode))
-
-                   ;; Indirect file among split files
-                   (if found-in-tag-table
-                       (progn
-                         ;; If this is an indirect file, determine
-                         ;; which file really holds this node and
-                         ;; read it in.
-                         (if (not (eq found-mode 'Info-mode))
-                             ;; Note that the current buffer must be
-                             ;; the *info* buffer on entry to
-                             ;; Info-read-subfile.  Thus the hackery
-                             ;; above.
-                             (setq guesspos (Info-read-subfile guesspos)))))
+             (when (marker-position Info-tag-table-marker)
+               (let* ((m Info-tag-table-marker)
+                      (found (Info-find-in-tag-table m regexp)))
+                 
+                 (when found
+                   ;; FOUND is (ANCHOR POS MODE).
+                   (setq guesspos (nth 1 found))
+                   
+                   ;; If this is an indirect file, determine which
+                   ;; file really holds this node and read it in.
+                   (unless (eq (nth 2 found) 'Info-mode)
+                     ;; Note that the current buffer must be the
+                     ;; *info* buffer on entry to
+                     ;; Info-read-subfile.  Thus the hackery above.
+                     (setq guesspos (Info-read-subfile guesspos)))
 
                    ;; Handle anchor
-                   (if found-anchor
-                       (progn
-                         (goto-char (setq anchorpos guesspos))
-                         (throw 'foo t)))))
+                   (when (nth 0 found)
+                     (goto-char (setq anchorpos guesspos))
+                     (throw 'foo t)))))
 
              ;; Else we may have a node, which we search for:
              (goto-char (max (point-min)
                              (- (byte-to-position guesspos) 1000)))
-             ;; Now search from our advised position
-             ;; (or from beg of buffer)
-             ;; to find the actual node.
-             ;; First, check whether the node is right
-             ;; where we are, in case the buffer begins
-             ;; with a node.
-             (or (Info-node-at-bob-matching regexp)
-                 (while (search-forward "\n\^_" nil t)
-                   (forward-line 1)
-                   (let ((beg (point)))
-                     (forward-line 1)
-                     (if (re-search-backward regexp beg t)
-                         (progn
-                           (beginning-of-line)
-                           (throw 'foo t)))))
-                 (error
-                  "No such anchor in tag table or node in tag table or file: %s"
-                  nodename)))
+             
+             ;; Now search from our advised position (or from beg of
+             ;; buffer) to find the actual node.  First, check
+             ;; whether the node is right where we are, in case the
+             ;; buffer begins with a node.
+             (let ((pos (Info-find-node-in-buffer regexp)))
+               (when pos
+                 (goto-char pos)
+                 (throw 'foo t))
+               (error "No such anchor in tag table or node in tag table or file: %s"
+                      nodename)))
 
            (Info-select-node)
            (goto-char (or anchorpos (point-min))))))
@@ -606,15 +651,15 @@ else defaults to `Top'."
           ;; Verify that none of the files we used has changed
           ;; since we used it.
           (eval (cons 'and
-                      (mapcar '(lambda (elt)
-                                 (let ((curr (file-attributes
-                                              ;; Handle symlinks
-                                              (file-truename (car elt)))))
-
-                                   ;; Don't compare the access time.
-                                   (if curr (setcar (nthcdr 4 curr) 0))
-                                   (setcar (nthcdr 4 (cdr elt)) 0)
-                                   (equal (cdr elt) curr)))
+                      (mapcar (lambda (elt)
+                                (let ((curr (file-attributes
+                                             ;; Handle symlinks
+                                             (file-truename (car elt)))))
+
+                                  ;; Don't compare the access time.
+                                  (if curr (setcar (nthcdr 4 curr) 0))
+                                  (setcar (nthcdr 4 (cdr elt)) 0)
+                                  (equal (cdr elt) curr)))
                               Info-dir-file-attributes))))
       (progn
        (insert Info-dir-contents)
@@ -714,8 +759,8 @@ else defaults to `Top'."
              (setq problems t)
              (message "No `top' node in %s" Info-dir-file-name))))
        (setq others (cdr others)))
-      ;; Add to the main menu a menu item for each other node. 
-      (let ((case-fold-search t)     
+      ;; Add to the main menu a menu item for each other node.
+      (let ((case-fold-search t)
            (re-search-forward "^\\* Menu:")))
       (forward-line 1)
       (let ((menu-items '("top"))
@@ -816,9 +861,9 @@ else defaults to `Top'."
     (if (numberp nodepos)
        (+ (- nodepos lastfilepos) (point)))))
 
-;; Select the info node that point is in.
 (defun Info-select-node ()
-  ;; Bind this in case the user sets it to nil.
+"Select the info node that point is in.
+Bind this in case the user sets it to nil."
   (let ((case-fold-search t))
     (save-excursion
       ;; Find beginning of node.
@@ -855,13 +900,11 @@ else defaults to `Top'."
 (defun Info-set-mode-line ()
   (setq mode-line-buffer-identification
        (concat
-        "  Info:  ("
-        (if Info-current-file
-            (file-name-nondirectory (if (stringp Info-current-file)
-                                        Info-current-file
-                                      (or buffer-file-name "")))
-          "")
-        ")"
+        "  *Info* ("
+        (file-name-nondirectory (if (stringp Info-current-file)
+                                    Info-current-file
+                                  (or buffer-file-name "")))
+        ") "
         (or Info-current-node ""))))
 \f
 ;; Go to an info node specified with a filename-and-nodename string
@@ -933,9 +976,9 @@ If FORK is a string, it is the name to use for the new buffer."
                  (set-buffer (marker-buffer marker))
                  (widen)
                  (goto-char marker)
-                 (while (re-search-forward "\nNode: \\(.*\\)\177" nil t)
+                 (while (re-search-forward "\n\\(Node\\|Ref\\): \\(.*\\)\177" nil t)
                    (setq compl
-                         (cons (list (match-string-no-properties 1))
+                         (cons (list (match-string-no-properties 2))
                                compl))))
              (widen)
              (goto-char (point-min))
@@ -1038,11 +1081,11 @@ If FORK is a string, it is the name to use for the new buffer."
          (setq Info-history (cons (list ofile onode opoint)
                                   Info-history))))))
 \f
-;; Extract the value of the node-pointer named NAME.
-;; If there is none, use ERRORNAME in the error message;
-;; if ERRORNAME is nil, just return nil.
 (defun Info-extract-pointer (name &optional errorname)
-  ;; Bind this in case the user sets it to nil.
+  "Extract the value of the node-pointer named NAME.
+If there is none, use ERRORNAME in the error message;
+if ERRORNAME is nil, just return nil.
+Bind this in case the user sets it to nil."
   (let ((case-fold-search t))
     (save-excursion
       (goto-char (point-min))
@@ -1055,10 +1098,10 @@ If FORK is a string, it is the name to use for the new buffer."
            nil
          (error "Node has no %s" (capitalize (or errorname name))))))))
 
-;; Return the node name in the buffer following point.
-;; ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
-;; saying which chars may appear in the node name.
 (defun Info-following-node-name (&optional allowedchars)
+  "Return the node name in the buffer following point.
+ALLOWEDCHARS, if non-nil, goes within [...] to make a regexp
+saying which chars may appear in the node name."
   (skip-chars-forward " \t")
   (buffer-substring-no-properties
    (point)
@@ -1112,8 +1155,8 @@ If SAME-FILE is non-nil, do not move to a different Info file."
   (Info-find-node "dir" "top"))
 \f
 (defun Info-follow-reference (footnotename)
-  "Follow cross reference named NAME to the node it refers to.
-NAME may be an abbreviation of the reference name."
+  "Follow cross reference named FOOTNOTENAME to the node it refers to.
+FOOTNOTENAME may be an abbreviation of the reference name."
   (interactive
    (let ((completion-ignore-case t)
         (case-fold-search t)
@@ -1435,7 +1478,7 @@ N is the digit argument used to invoke this command."
 
 (defun Info-next-menu-item ()
   (interactive)
-  ;; Bind this in case the user sets it to nil.  
+  ;; Bind this in case the user sets it to nil.
   (let* ((case-fold-search t)
         (node
          (save-excursion
@@ -1450,7 +1493,7 @@ N is the digit argument used to invoke this command."
   (interactive)
   (save-excursion
     (forward-line 1)
-    ;; Bind this in case the user sets it to nil.      
+    ;; Bind this in case the user sets it to nil.
     (let* ((case-fold-search t)
           (beg (save-excursion
                  (and (search-backward "\n* menu:" nil t)
@@ -1599,7 +1642,7 @@ previous node or back up to the parent node."
          (Info-prev-reference t)))))
 
 (defun Info-index (topic)
-  "Look up a string in the index for this file.
+  "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
 name contains the word \"Index\", plus any immediately following
 nodes whose names also contain the word \"Index\".
@@ -1732,15 +1775,15 @@ Give a blank topic name to go to the Index node itself."
     (bury-buffer "*Help*")))
 \f
 (defun Info-get-token (pos start all &optional errorstring)
-  "Return the token around POS,
+  "Return the token around POS.
 POS must be somewhere inside the token
 START is a regular expression which will match the
     beginning of the tokens delimited string
 ALL is a regular expression with a single
     parenthesized subpattern which is the token to be
-    returned. E.g. '{\(.*\)}' would return any string
+    returned.  E.g. '{\(.*\)}' would return any string
     enclosed in braces around POS.
-SIG optional fourth argument, controls action on no match
+ERRORSTRING optional fourth argument, controls action on no match
     nil: return nil
     t: beep
     a string: signal an error, using that string."
@@ -1869,7 +1912,7 @@ If no reference to follow, moves to the next node, or up if none."
   )
 
 (defun Info-check-pointer (item)
-  ;; Non-nil if ITEM is present in this node.
+  "Non-nil if ITEM is present in this node."
   (condition-case nil
       (Info-extract-pointer item)
     (error nil)))
@@ -1911,7 +1954,7 @@ If no reference to follow, moves to the next node, or up if none."
 ;; Value is a list, (FILE-NAME NODE-NAME).
 
 (defun Info-menu-update ()
-  ;; Update the Info menu for the current node.
+  "Update the Info menu for the current node."
   (condition-case nil
       (if (or (not (eq major-mode 'Info-mode))
              (equal (list Info-current-file Info-current-node)
@@ -1980,12 +2023,12 @@ If no reference to follow, moves to the next node, or up if none."
 (put 'info-mode 'mode-class 'special)
 
 (defun Info-mode ()
-  "\\<Info-mode-map>
-Info mode provides commands for browsing through the Info documentation tree.
+  "Info mode provides commands for browsing through the Info documentation tree.
 Documentation in Info is divided into \"nodes\", each of which discusses
 one topic and contains references to other nodes which discuss related
 topics.  Info has commands to follow the references and show you other nodes.
 
+\\<Info-mode-map>\
 \\[Info-help]  Invoke the Info tutorial.
 \\[Info-exit]  Quit Info: reselect previously selected buffer.
 
@@ -2133,7 +2176,7 @@ If the element is just a file name, the file name also serves as the prefix.")
 The `info-file' property of COMMAND says which Info manual to search.
 If COMMAND has no property, the variable `Info-file-list-for-emacs'
 defines heuristics for which Info manual to try.
-The locations are of the format used in Info-history, i.e.
+The locations are of the format used in `Info-history', i.e.
 \(FILENAME NODENAME BUFFERPOS\)."
   (let ((where '())
        (cmd-desc (concat "^\\* +" (regexp-quote (symbol-name command))
@@ -2209,7 +2252,7 @@ the variable `Info-file-list-for-emacs'."
 ;;;###autoload
 (defun Info-goto-emacs-key-command-node (key)
   "Go to the Info node in the Emacs manual the command bound to KEY, a string.
-Interactively, if the binding is execute-extended-command, a command is read.
+Interactively, if the binding is `execute-extended-command', a command is read.
 The command is found by looking up in Emacs manual's Command Index
 or in another manual found via COMMAND's `info-file' property or
 the variable `Info-file-list-for-emacs'."