]> code.delx.au - gnu-emacs/blobdiff - lisp/textmodes/texnfo-upd.el
Update copyright year to 2015
[gnu-emacs] / lisp / textmodes / texnfo-upd.el
index 83ef834257a2e8129dd564e882dc31a49101738d..df05b670095c887aa5324775d0e827b91240802d 100644 (file)
@@ -1,6 +1,6 @@
 ;;; texnfo-upd.el --- utilities for updating nodes and menus in Texinfo files
 
-;; Copyright (C) 1989-1992, 2001-201 Free Software Foundation, Inc.
+;; Copyright (C) 1989-1992, 2001-2015 Free Software Foundation, Inc.
 
 ;; Author: Robert J. Chassell
 ;; Maintainer: bug-texinfo@gnu.org
@@ -203,7 +203,7 @@ It comes after the chapter-level menu entries.")
     (3 . (concat "\\(^@\\)\\(" texinfo-section-level-regexp "\\)\\>[ \t]*"))
     (4 . (concat "\\(^@\\)\\(" texinfo-subsection-level-regexp "\\)\\>[ \t]+"))
     (5 . (concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp "\\)\\>[ \t]+")))
-  "*Regexps for searching for same level sections in a Texinfo file.
+  "Regexps for searching for same level sections in a Texinfo file.
 The keys are strings specifying the general hierarchical level in the
 document; the values are regular expressions.")
 
@@ -231,7 +231,7 @@ document; the values are regular expressions.")
       "\\|"
       texinfo-chapter-level-regexp
       "\\)\\>[ \t]*\\)")))
-  "*Regexps for searching for higher level sections in a Texinfo file.
+  "Regexps for searching for higher level sections in a Texinfo file.
 The keys are strings specifying the general hierarchical level in the
 document; the values are regular expressions.")
 
@@ -270,7 +270,7 @@ document; the values are regular expressions.")
       "\\)\\>[ \t]+\\)"))
     ;; There's nothing below 5, use a bogus regexp that can't match.
     (5 . "a\\(^\\)"))
-  "*Regexps for searching for lower level sections in a Texinfo file.
+  "Regexps for searching for lower level sections in a Texinfo file.
 The keys are strings specifying the general hierarchical level in the
 document; the values are regular expressions.")
 
@@ -682,7 +682,7 @@ node within the section."
 
 ;; try 32, but perhaps 24 is better
 (defvar texinfo-column-for-description 32
-  "*Column at which descriptions start in a Texinfo menu.")
+  "Column at which descriptions start in a Texinfo menu.")
 
 (defun texinfo-insert-menu (menu-list node-name)
   "Insert formatted menu at point.
@@ -1145,24 +1145,40 @@ For example, \"unnumberedsubsec\".  Return \"top\" for top node.
 Searches forward for a section.  Hence, point must be before the
 section whose type will be found.  Does not move point.  Signal an
 error if the node is not the top node and a section is not found."
-  (let ((case-fold-search t))
-    (save-excursion
-      (cond
-       ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
-                          ;; Following search limit by cph but causes a bug
-                          ;;(line-end-position)
-                          nil
-                          t)
-       "top")
-       ((re-search-forward texinfo-section-types-regexp nil t)
-       (buffer-substring-no-properties
-        (progn (beginning-of-line) ; copy its name
-               (1+ (point)))
-        (progn (forward-word 1)
-               (point))))
-       (t
-       (error
-        "texinfo-specific-section-type: Chapter or section not found"))))))
+  (let* ((case-fold-search t)
+        ;; The Texinfo manual has a second Top node inside @verbatim
+        ;; near the end, which dupes us into thinking we are at top
+        ;; level, no matter where we are when invoked.  We don't
+        ;; really grok @verbatim, so we cheat: only consider us to be
+        ;; at top level if the position of the Top node we found is
+        ;; before any other sectioning command.
+        (top-pos (save-excursion
+                   (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
+                                      ;; Following search limit causes a bug
+                                      ;;(line-end-position)
+                                      nil
+                                      t)))
+        (sec-pos (save-excursion
+                   (re-search-forward texinfo-section-types-regexp nil t)))
+        sec-name)
+    (if sec-pos
+       (save-excursion
+         (goto-char sec-pos)
+         (setq sec-name (buffer-substring-no-properties
+                         (progn (beginning-of-line) ; copy its name
+                                (1+ (point)))
+                         (progn (forward-word 1)
+                                (point))))))
+    (cond
+     ((or sec-pos top-pos)
+      (if (and top-pos sec-pos)
+         (if (< top-pos sec-pos)
+             "top"
+           sec-name)
+       (or sec-name "top")))
+     (t
+      (error
+       "texinfo-specific-section-type: Chapter or section not found")))))
 
 (defun texinfo-hierarchic-level ()
   "Return the general hierarchical level of the next node in a texinfo file.