emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Info index cookie support


From: Juri Linkov
Subject: Info index cookie support
Date: Sat, 29 Oct 2005 01:04:35 +0300
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/22.0.50 (gnu/linux)

Current support for Info index cookies is incomplete in info.el.
Non-index Info nodes that have the word `Index' in the node name are
recognized as index nodes.  This doesn't highlight their menus,
and their menu items interpreted as index entries which adds their
subnode names to the list created by `i', etc.

The problem is following: to determine if the node is an index node,
info.el first looks for the word `Index' in the node name, and after
that looks for the index cookie "address@hidden@^H]" in the node text.
So when info.el finds the word `Index' if reports the node as the
index node no matter if the node contains the index cookie or not.
This was implemented for backward compatibility with older Info formats
that don't have special index cookies.

To correctly recognize the index node info.el needs to know whether an
Info file it processes supports the cookie "address@hidden@^H]" or not.
One way is to scan the whole manual for the first index cookie, and if it
finds one, then this means that the Info file supports index cookies.
This solution has several drawbacks: it may be slow to scan several Info
subfiles over slow network connections before opening the first node,
and also if the Info file doesn't have an index node at all (but is
still in the new Info format that supports index cookies), then info.el
will incorrectly assume that this Info file is in the old format
without index cookies.

A better solution to know whether an Info file supports index cookies
is to read the first two lines of the Info file, and to check the version
of makeinfo that generated them.  If the version is greater than 4.7,
then this means that this Info format supports index cookies.  This
information will help to correctly recognize index nodes:

Index: lisp/info.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/info.el,v
retrieving revision 1.454
diff -c -w -b -r1.454 info.el
*** lisp/info.el        26 Oct 2005 16:38:36 -0000      1.454
--- lisp/info.el        28 Oct 2005 22:02:45 -0000
***************
*** 310,315 ****
--- 310,318 ----
  (defvar Info-current-file-completions nil
    "Cached completion list for current Info file.")
  
+ (defvar Info-file-supports-index-cookies nil
+   "Non-nil if current Info file supports index cookies.")
+ 
  (defvar Info-index-alternatives nil
    "List of possible matches for last `Info-index' command.")
  
***************
*** 842,847 ****
--- 845,860 ----
                  (info-insert-file-contents filename nil)
                  (setq default-directory (file-name-directory filename))))
                (set-buffer-modified-p nil)
+             ;; Check makeinfo version for index cookie support
+             (goto-char (point-min))
+             (condition-case ()
+                 (if (and (re-search-forward
+                           "makeinfo version \\([0-9]+.[0-9]+\\)"
+                           (line-beginning-position 3) t)
+                          (not (version< (match-string 1) "4.7")))
+                     (set (make-local-variable 
'Info-file-supports-index-cookies) t))
+               (error nil))
+ 
                ;; See whether file has a tag table.  Record the location if 
yes.
                (goto-char (point-max))
                (forward-line -8)
***************
*** 2649,2654 ****
--- 2670,2676 ----
        (and (member file '("dir" "history" "toc" "apropos"))
             (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
        (not (stringp file))
+       (if Info-file-supports-index-cookies
          ;; Find nodes with index cookie
          (let* ((default-directory (or (and (stringp file)
                                             (file-name-directory
***************
*** 2683,2689 ****
              (setq nodes (nreverse nodes)
                    Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
          nodes)
!       ;; Find nodes with the word "Index" in the node name
        (let ((case-fold-search t)
              Info-history Info-history-list Info-fontify-maximum-menu-size
              nodes node)
--- 2705,2711 ----
                (setq nodes (nreverse nodes)
                      Info-index-nodes (cons (cons file nodes) 
Info-index-nodes)))
            nodes)
!       ;; Else find nodes with the word "Index" in the node name
        (let ((case-fold-search t)
              Info-history Info-history-list Info-fontify-maximum-menu-size
              nodes node)
***************
*** 2704,2710 ****
          (if nodes
              (setq nodes (nreverse nodes)
                    Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
!         nodes)
        ;; If file has no index nodes, still add it to the cache
        (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
    (cdr (assoc file Info-index-nodes)))
--- 2726,2732 ----
          (if nodes
              (setq nodes (nreverse nodes)
                    Info-index-nodes (cons (cons file nodes) Info-index-nodes)))
!         nodes))
        ;; If file has no index nodes, still add it to the cache
        (setq Info-index-nodes (cons (cons file nil) Info-index-nodes)))
    (cdr (assoc file Info-index-nodes)))
***************
*** 2718,2726 ****
        (member (or node Info-current-node) (Info-index-nodes file))
      ;; Don't search all index nodes if request is only for the current node
      ;; and file is not in the cache of index nodes
!     (or
!      (save-match-data
!        (string-match "\\<Index\\>" (or node Info-current-node "")))
       (save-excursion
         (goto-char (+ (or (save-excursion
                             (search-backward "\n\^_" nil t))
--- 2740,2746 ----
        (member (or node Info-current-node) (Info-index-nodes file))
      ;; Don't search all index nodes if request is only for the current node
      ;; and file is not in the cache of index nodes
!     (if Info-file-supports-index-cookies
        (save-excursion
          (goto-char (+ (or (save-excursion
                              (search-backward "\n\^_" nil t))
***************
*** 2728,2734 ****
         (search-forward "\0\b[index\0\b]"
                         (or (save-excursion
                               (search-forward "\n\^_" nil t))
!                            (point-max)) t)))))
  
  (defun Info-goto-index ()
    "Go to the first index node."
--- 2748,2756 ----
          (search-forward "\0\b[index\0\b]"
                          (or (save-excursion
                                (search-forward "\n\^_" nil t))
!                             (point-max)) t))
!       (save-match-data
!       (string-match "\\<Index\\>" (or node Info-current-node ""))))))
  
  (defun Info-goto-index ()
    "Go to the first index node."
***************
*** 3504,3513 ****
                (setq info-file file file-list nil))
            (setq file-list (cdr file-list))))))
      (Info-find-node info-file "Top")
-     (or (and (search-forward "\n* menu:" nil t)
-            (re-search-forward "\n\\* \\(.*\\<Index\\>\\)" nil t))
-       (error "Info file `%s' appears to lack an index" info-file))
-     (goto-char (match-beginning 1))
      ;; Bind Info-history to nil, to prevent the index nodes from
      ;; getting into the node history.
      (let ((Info-history nil)
--- 3526,3531 ----

-- 
Juri Linkov
http://www.jurta.org/emacs/





reply via email to

[Prev in Thread] Current Thread [Next in Thread]