home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / docs.lha / latexinfo / elisp / latexnfo-upd.el (.txt) < prev    next >
Encoding:
LaTeX Document  |  1992-02-20  |  67.0 KB  |  1,514 lines

  1. ;;;; latexnfo-upd.el
  2. ;;; Latexinfo mode utilities for updating nodes and menus in Latexinfo files.
  3. ;;; Version 2.07    10 September 1991
  4. ;;; Robert J. Chassell      
  5. ;;; Converted to Latexinfo by Mike Clarkson
  6. ;;; Please send bug reports to:  mike@apl.ists.ca
  7. ;;; Copyright 1989, 1990, 1991 Free Software Foundation
  8. ;;; Copyleft  (C) 1988, 1989, 1990, 1991 Michael E. Clarkson
  9. ;;; Known bug: update commands fail to ignore \begin{ignore}.
  10. ;;; This file is not part of GNU Emacs.
  11. ;; GNU Emacs is free software; you can redistribute it and/or modify
  12. ;; it under the terms of the GNU General Public License as published by
  13. ;; the Free Software Foundation; either version 1, or (at your option)
  14. ;; any later version.
  15. ;; GNU Emacs is distributed in the hope that it will be useful,
  16. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18. ;; GNU General Public License for more details.
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with GNU Emacs; see the file COPYING.  If not, write to
  21. ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22. ;;; Summary: how to use the updating commands
  23. ; The node and menu updating functions automatically
  24. ;   * insert missing `\node' lines,
  25. ;   * insert the `Next', `Previous' and `Up' pointers of a node,
  26. ;   * insert or update the menu for a section, 
  27. ;   * create a master menu for a Latexinfo source file.
  28. ; Passed an argument, the `latexinfo-update-node' and
  29. ; `latexinfo-make-menu' functions do their jobs in the region.
  30. ; In brief, the functions for creating or updating nodes and menus, are:
  31. ;     latexinfo-update-node (&optional region-p)            
  32. ;     latexinfo-every-node-update ()                        
  33. ;     latexinfo-sequential-node-update (&optional region-p)
  34. ;     latexinfo-make-menu (&optional region-p)              
  35. ;     latexinfo-all-menus-update ()                         
  36. ;     latexinfo-master-menu ()
  37. ;     latexinfo-insert-node-lines  (&optional title-p)
  38. ;     latexinfo-indent-menu-description (column &optional region-p)
  39. ; The `latexinfo-column-for-description' variable specifies the column to
  40. ; which menu descriptions are indented. 
  41. ; Latexinfo file structure
  42. ; ----------------------
  43. ; To use the updating commands, you must structure your Latexinfo file
  44. ; hierarchically.  Each `\node' line, with the exception of the top
  45. ; node, must be accompanied by some kind of section line, such as an
  46. ; `\chapter' or `\section' line.  Each node-line/section-line
  47. ; combination must look like this:
  48. ;      \node    Lists and Tables, Cross References, Structuring, Top
  49. ;      \comment node-name,        next,             previous,    up
  50. ;      \chapter{Making Lists and Tables}
  51. ; or like this (without the `\comment' line):
  52. ;      \node    Lists and Tables, Cross References, Structuring, Top
  53. ;      \chapter{Making Lists and Tables}
  54. ; If the file has a `top' node, it must be called `top' or `Top' and
  55. ; be the first node in the file.
  56. ;;; The update node functions described in detail
  57. ; The `latexinfo-update-node' function without an argument inserts
  58. ; the correct next, previous and up pointers for the node in which
  59. ; point is located (i.e., for the node preceding point).
  60. ; With an argument, the `latexinfo-update-node' function inserts the
  61. ; correct next, previous and up pointers for the nodes inside the
  62. ; region.
  63. ; It does not matter whether the  `\node' line has pre-existing
  64. ; `Next', `Previous', or `Up' pointers in it.  They are removed.
  65. ; The `latexinfo-every-node-update' function runs `latexinfo-update-node'
  66. ; on the whole buffer.
  67. ; The `latexinfo-update-node' function inserts the immediately following
  68. ; and preceding node into the `Next' or `Previous' pointers regardless
  69. ; of their hierarchical level.  This is only useful for certain kinds
  70. ; of text, like a novel, which you go through sequentially.  
  71. ;;; The menu making functions described in detail
  72. ; The `latexinfo-make-menu' function without an argument creates or
  73. ; updates a menu for the section encompassing the node that follows
  74. ; point.  With an argument, it makes or updates menus for the nodes
  75. ; within or part of the marked region.
  76. ; Whenever an existing menu is updated, the descriptions from
  77. ; that menu are incorporated into the new menu.  This is done by copying
  78. ; descriptions from the existing menu to the entries in the new menu
  79. ; that have the same node names.  If the node names are different, the
  80. ; descriptions are not copied to the new menu.
  81. ; Menu entries that refer to other Info files are removed since they
  82. ; are not a node within current buffer.  This is a deficiency.
  83. ; The `latexinfo-all-menus-update' function runs `latexinfo-make-menu'
  84. ; on the whole buffer.
  85. ; The `latexinfo-master-menu' function creates an extended menu located
  86. ; after the top node.  (The file must have a top node.)  The function
  87. ; first updates all the regular menus in the buffer (incorporating the
  88. ; descriptions from pre-existing menus), and then constructs a master
  89. ; menu that includes every entry from every other menu.  (However, the
  90. ; function cannot update an already existing master menu; if one
  91. ; exists, it must be removed before calling the function.)
  92. ; The `latexinfo-indent-menu-description' function indents every
  93. ; description in the menu following point, to the specified column.
  94. ; Non-nil argument (prefix, if interactive) means indent every
  95. ; description in every menu in the region.  This function does not
  96. ; indent second and subsequent lines of a multi-line description.
  97. ; The `latexinfo-insert-node-lines' function inserts `\node' before the
  98. ; `\chapter', `\section', and such like lines of a region in a Latexinfo
  99. ; file where the `\node' lines are missing.
  100. ; With a non-nil argument (prefix, if interactive), the function not
  101. ; only inserts `\node' lines but also inserts the chapter or section
  102. ; titles as the names of the corresponding nodes; and inserts titles
  103. ; as node names in pre-existing `\node' lines that lack names.
  104. ; Since node names should be more concise than section or chapter
  105. ; titles, node names so inserted will need to be edited manually.
  106. ;;; The menu making functions
  107. (defun latexinfo-make-menu (&optional region-p)
  108.   "Without any prefix argument, make or update a menu.
  109. Make the menu for the section enclosing the node found following point.
  110. Non-nil argument (prefix, if interactive) means make or update menus
  111. for nodes within or part of the marked region.
  112. Whenever a menu exists, and is being updated, the descriptions that
  113. are associated with node names in the pre-existing menu are
  114. incorporated into the new menu.  Otherwise, the nodes' section titles
  115. are inserted as descriptions."
  116.   (interactive "P")
  117.   (if (not region-p)
  118.       (let ((level (latexinfo-hierarchic-level)))
  119.         (latexinfo-make-one-menu level)
  120.         (message "Done...updated the menu.  You may save the buffer."))
  121.     ;; else
  122.     (message "Making or updating menus in %s... " (buffer-name))
  123.     (let ((beginning (region-beginning))
  124.       (region-end (region-end))
  125.           (level (progn         ; find section type following point
  126.                    (goto-char (region-beginning))
  127.                    (latexinfo-hierarchic-level))))
  128.       (if (= region-end beginning)
  129.           (error "Please mark a region!"))
  130.       (save-excursion
  131.         (save-restriction
  132.           (widen)
  133.           
  134.           (while  (latexinfo-find-lower-level-node level region-end)
  135.             (setq level (latexinfo-hierarchic-level)) ; new, lower level
  136.             (latexinfo-make-one-menu level))
  137.           
  138.           (while (and (< (point) region-end)
  139.                       (latexinfo-find-higher-level-node level region-end))
  140.             (setq level (latexinfo-hierarchic-level))
  141.             (while (latexinfo-find-lower-level-node level region-end)
  142.               (setq level (latexinfo-hierarchic-level)) ; new, lower level
  143.               (latexinfo-make-one-menu level))))))
  144.     (message "Done...updated menus.  You may save the buffer.")))
  145. (defun latexinfo-make-one-menu (level)
  146.   "Make a menu of all the appropriate nodes in this section.
  147. `Appropriate nodes' are those associated with sections that are 
  148. at the level specified by LEVEL.  Point is left at the end of menu."
  149.   (let*
  150.       ((case-fold-search t)
  151.        (beginning
  152.     (save-excursion
  153.       (goto-char (latexinfo-update-menu-region-beginning level))
  154.       (end-of-line)
  155.       (point)))
  156.        (end (latexinfo-update-menu-region-end level))
  157.        (first (latexinfo-menu-first-node beginning end))
  158.        (node-name (progn
  159.                     (goto-char beginning)
  160.                     (beginning-of-line)
  161.                     (latexinfo-copy-node-name)))
  162.        (new-menu-list (latexinfo-make-menu-list beginning end level)))
  163.     (if (latexinfo-old-menu-p beginning first)
  164.         (progn
  165.           (latexinfo-incorporate-descriptions new-menu-list)
  166.           (latexinfo-delete-old-menu beginning first)))
  167.     (latexinfo-insert-menu new-menu-list node-name)))
  168. (defun latexinfo-all-menus-update (&optional update-all-nodes-p)
  169.   "Update every regular menu in a Latexinfo file.
  170. Update pre-existing master menu, if there is one.
  171. If called with a non-nil argument, this function first updates all the
  172. nodes in the buffer before updating the menus.
  173. If called with a non-nil argument of 'sequential, this function first 
  174. sequentially updates all the nodes in the buffer before updating the menus.
  175.   (interactive "P")
  176.   (let (master-menu-p)
  177.     (save-excursion
  178.       (mark-whole-buffer)
  179.       (message "Checking for a master menu in %s ... "(buffer-name))
  180.       (save-excursion
  181.         (if (re-search-forward latexinfo-master-menu-header nil t)
  182.             ;; Remove detailed master menu listing
  183.             (progn
  184.               (setq master-menu-p t)
  185.               (goto-char (match-beginning 0))
  186.               (let ((end-of-detailed-menu-descriptions
  187.                      (save-excursion    ; beginning of end menu line
  188.                        (goto-char (latexinfo-menu-end))
  189.                        (beginning-of-line) (forward-char -1)
  190.                        (point))))
  191.                 (delete-region (point) end-of-detailed-menu-descriptions)))))
  192.       
  193.       (if update-all-nodes-p
  194.           (progn
  195.             (message "Updating all nodes in %s ... " (buffer-name))
  196.             (sleep-for 2)
  197.             (mark-whole-buffer)
  198.         (if (equal update-all-nodes-p 'sequential)
  199.         (latexinfo-sequential-node-update t)
  200.           (latexinfo-update-node t))))
  201.       
  202.       (message "Updating all menus in %s ... " (buffer-name))        
  203.       (sleep-for 2)
  204.       (mark-whole-buffer)
  205.       (latexinfo-make-menu t)
  206.       
  207.       (if master-menu-p
  208.           (progn
  209.             (message "Updating the master menu in %s... " (buffer-name))
  210.             (sleep-for 2)
  211.             (latexinfo-master-menu nil))))
  212.     (message "Done...updated all the menus.  You may save the buffer.")))
  213. (defun latexinfo-find-lower-level-node (level region-end)
  214.   "Search forward from point for node at any level lower than LEVEL.
  215. Search is limited to the end of the marked region, REGION-END, 
  216. and to the end of the menu region for the level.
  217. Return t if the node is found, else nil.  Leave point at the beginning
  218. of the node if one is found; else do not move point."
  219.   (if (and (< (point) region-end)
  220.            (re-search-forward
  221.             (concat
  222.              "\\(^\\\\node\\).*\n"         ; match node line
  223.              "\\(\\(\\(^\\\\c\\).*\n\\)"   ; match comment line, if any
  224.              "\\|"                      ; or
  225.              "\\(^\\\\begin{ifinfo}[ ]*\n\\)\\)?" ; ifinfo line, if any
  226.              (eval (cdr (assoc level latexinfo-update-menu-lower-regexps))))
  227.             ;; the next higher level node marks the end of this
  228.             ;; section, and no lower level node will be found beyond
  229.             ;; this position even if region-end is farther off
  230.             (latexinfo-update-menu-region-end level) 
  231.             t))
  232.       (goto-char (match-beginning 1))))
  233. (defun latexinfo-find-higher-level-node (level region-end)
  234.   "Search forward from point for node at any higher level than argument LEVEL.
  235. Search is limited to the end of the marked region, REGION-END.
  236. Return t if the node is found, else nil.  Leave point at the beginning
  237. of the node if one is found; else do not move point."
  238.   (cond
  239.    ((or (string-equal "top" level) (string-equal "chapter" level))
  240.     (if (re-search-forward "^\\\\node [ \t]*top[ \t]*\\(,\\|$\\)" region-end t)
  241.         (progn (beginning-of-line) t)))
  242.    (t
  243.     (if (re-search-forward
  244.          (concat
  245.           "\\(^\\\\node\\).*\n"              ; match node line
  246.           "\\(\\(\\(^\\\\c\\).*\n\\)"        ; match comment line, if any
  247.           "\\|"                           ; or
  248.           "\\(^\\\\begin{ifinfo}[ ]*\n\\)\\)?"      ; ifinfo line, if any
  249.           (eval (cdr (assoc level latexinfo-update-menu-higher-regexps))))
  250.          region-end t)
  251.         (progn (beginning-of-line) t)))))
  252. ;;; Making the list of new menu entries
  253. (defun latexinfo-make-menu-list (beginning end level)
  254.   "Make a list of node names and their descriptions.
  255. Point is left at the end of the menu region, but the menu is not inserted.
  256. First argument is position from which to start making menu list; 
  257. second argument is end of region in which to try to locate entries;
  258. third argument is the level of the nodes that are the entries.
  259. Node names and descriptions are dotted pairs of strings.  Each pair is
  260. an element of the list.  If the description does not exist, the
  261. element consists only of the node name."
  262.   (goto-char beginning)
  263.   (let (new-menu-list)
  264.     (while (latexinfo-menu-locate-entry-p level end)
  265.       (setq new-menu-list 
  266.             (cons (cons 
  267.                    (latexinfo-copy-node-name)
  268.                    (latexinfo-copy-section-title))
  269.                   new-menu-list)))
  270.     (reverse new-menu-list)))
  271. (defun latexinfo-menu-locate-entry-p (level search-end)
  272.   "Find a node that will be part of menu for this section.
  273. First argument is a string such as \"section\" specifying the general
  274. hierarchical level of the menu; second argument is a postion
  275. specifying the end of the search.
  276. The function returns t if the node is found, else nil.  It searches
  277. forward from point, and leaves point at the beginning of the node.
  278. The function finds entries of the same type.  Thus `subsections' and
  279. `unnumberedsubsecs' will appear in the same menu."
  280.   (if (re-search-forward
  281.        (concat
  282.         "\\(^\\\\node\\).*\n"              ; match node line
  283.         "\\(\\(\\(^\\\\c\\).*\n\\)"        ; match comment line, if any
  284.         "\\|"                           ; or
  285.         "\\(^\\\\begin{ifinfo}[ ]*\n\\)\\)?"      ; ifinfo line, if any
  286.         (eval
  287.          (cdr (assoc level latexinfo-update-menu-same-level-regexps))))
  288.        search-end
  289.        t)
  290.       (goto-char (match-beginning 1))))
  291. (defun latexinfo-copy-node-name ()
  292.   "Return the node name as a string.
  293. Start with point at the beginning of the node line; copy the text
  294. after the node command up to the first comma on the line, if any, and
  295. return the text as a string.  Leaves point at the beginning of the
  296. line.  If there is no node name, returns an empty string."
  297.   (save-excursion
  298.     (buffer-substring            
  299.      (progn (forward-word 1)        
  300.         (skip-chars-forward " \t")    
  301.         (point))
  302.      (if (search-forward        ; mike
  303.       ","
  304.       (save-excursion (end-of-line) (point)) t) ; bound search
  305.      (1- (point))
  306.        (end-of-line) (point)))
  307.     ))
  308. (defun latexinfo-copy-section-title ()
  309.   "Return the title of the section as a string.
  310. The title is used as a description line in the menu when one does not
  311. already exist.
  312. Move point to the beginning of the appropriate section line by going
  313. to the start of the text matched by last regexp searched for, which
  314. must have been done by `latexinfo-menu-locate-entry-p'."
  315.   ;; could use the same re-search as in `latexinfo-menu-locate-entry-p'
  316.   ;; instead of using `match-beginning'; such a variation would be
  317.   ;; more general, but would waste information already collected
  318.   (goto-char (match-beginning 7))       ; match section name 
  319.   (forward-word 1)                      
  320.   (skip-chars-forward " \t")            
  321.   (buffer-substring            ; look for braces - mike
  322.    (1+ (point))
  323.    (progn 
  324.      (forward-sexp 1) (1- (point)))))
  325. ;;; Handling the old menu
  326. (defun latexinfo-old-menu-p (beginning first)
  327.   "Move point to the beginning of the menu for this section, if any.
  328. Otherwise move point to the end of the first node of this section.
  329. Return t if a menu is found, nil otherwise.
  330. First argument is the position of the beginning of the section in which
  331. the menu will be located; second argument is the position of the first
  332. node within the section.
  333. If no menu is found, the function inserts two newlines just before the
  334. end of the section, and leaves point there where a menu ought to be."
  335.   (goto-char beginning)
  336.   (if (not (re-search-forward "^\\\\begin{menu}" first 'goto-end))
  337.       (progn (insert "\n\n") (forward-line -2) nil)
  338.     t))
  339. (defun latexinfo-incorporate-descriptions (new-menu-list)
  340.   "Copy the old menu line descriptions that exist to the new menu.
  341. Point must be at beginning of old menu.
  342. If the node-name of the new menu entry cannot be found in the old
  343. menu, use the new section title for the description, but if the
  344. node-name of the new menu is found in the old menu, replace the
  345. section title with the old description, whatever it may be.
  346. For this function, the new menu is a list made up of lists of dotted
  347. pairs in which the first element of the pair is the node name and the
  348. second element the description. The new menu is changed destructively.
  349. The old menu is the menu as it appears in the latexinfo file."
  350.   (let ((new-menu-list-pointer new-menu-list)
  351.         (end-of-menu (latexinfo-menu-end)))
  352.     (while new-menu-list
  353.       (save-excursion                   ; keep point at beginning of menu 
  354.         (if (search-forward
  355.              (concat "\* "              ; so only menu entries are found
  356.                      (car (car new-menu-list))
  357.                      ":")               ; so only complete entries are found
  358.              end-of-menu
  359.              t) 
  360.             (setcdr (car new-menu-list) 
  361.                     (latexinfo-menu-copy-old-description end-of-menu))))
  362.       (setq new-menu-list (cdr new-menu-list))) 
  363.     (setq new-menu-list new-menu-list-pointer)))
  364. (defun latexinfo-menu-copy-old-description (end-of-menu)
  365.   "Return description field of old menu line as string.
  366. Point must be located just after the node name.  Point left before description.
  367. Single argument, END-OF-MENU, is position limiting search."
  368.   (skip-chars-forward "[:.,\t\n ]+")
  369.   ;; don't copy a carriage return at line beginning with asterisk!
  370.   ;; do copy a description that begins with an `\'!
  371.   (if (and (looking-at "\\(\\w+\\|\\\\\\)")    
  372.            (not (looking-at "\\(^\\* \\|^\\\\end{menu}\\)")))  
  373.       (buffer-substring
  374.        (point)
  375.        (save-excursion
  376.          (re-search-forward "\\(^\\* \\|^\\\\end{menu}\\)" end-of-menu t)
  377.          (forward-line -1)
  378.          (end-of-line)                  ; go to end of last description line
  379.          (point)))
  380.     ""))
  381. (defun latexinfo-menu-end ()
  382.   "Return position of end of menu. Does not change location of point.
  383. Signal an error if not end of menu."
  384.   (save-excursion
  385.     (if (re-search-forward "^\\\\end{menu}" nil t)
  386.         (point)
  387.       (error "Menu does not have an end."))))
  388. (defun latexinfo-delete-old-menu (beginning first)
  389.   "Delete the old menu.  Point must be in or after menu.
  390. First argument is position of the beginning of the section in which
  391. the menu will be located; second argument is the position of the first
  392. node within the section."
  393.   ;; No third arg to search, so error if search fails.
  394.   (re-search-backward "^\\\\begin{menu}" beginning)
  395.   (delete-region (point)
  396.                  (save-excursion
  397.                    (re-search-forward "^\\\\end{menu}" first)
  398.                    (point))))
  399. ;;; Inserting new menu
  400. ;; try 32, but perhaps 24 is better
  401. (defvar latexinfo-column-for-description 32
  402.   "*Column at which descriptions start in a Latexinfo menu.")
  403. (defun latexinfo-insert-menu (menu-list node-name)
  404.   "Insert formatted menu at point.
  405. Indents the first line of the description, if any, to the value of
  406. latexinfo-column-for-description.
  407. MENU-LIST has form:
  408.     \(\(\"node-name1\" . \"description\"\) 
  409.     \(\"node-name\" . \"description\"\) ... \)
  410. However, there does not need to be a description field."
  411.   (insert "\\begin{menu}\n")
  412.   (while menu-list
  413.     (if (and (cdr (car menu-list))       ; menu-list has description entry
  414.          (not (string-equal (cdr (car menu-list)) (car (car menu-list)))))
  415.         (progn                ; if its not a duplicate - mike
  416.           (insert 
  417.            (format "* %s::" (car (car menu-list)))) ; node-name entry
  418.           (indent-to latexinfo-column-for-description 2)
  419.           (insert 
  420.            (format "%s\n" (cdr (car menu-list)))))  ; description entry
  421.         ;; else menu-list lacks description entry
  422.       (insert
  423.        (format "* %s::\n" (car (car menu-list)))))  ; node-name entry
  424.     (setq menu-list (cdr menu-list)))
  425.   (insert "\\end{menu}")
  426.   (message
  427.    "Updated \"%s\" level menu following node: %s ... "
  428.    level node-name))
  429. ;;; Handling description indentation
  430. ; Since the make-menu functions indent descriptions, these functions
  431. ; are useful primarily for indenting a single menu specially.
  432. (defun latexinfo-indent-menu-description (column &optional region-p)
  433.   "Indent every description in menu following point to COLUMN.  
  434. Non-nil argument (prefix, if interactive) means indent every
  435. description in every menu in the region.  Does not indent second and
  436. subsequent lines of a multi-line description."
  437.   (interactive
  438.    "nIndent menu descriptions to (column number): \nP")
  439.   (save-excursion
  440.     (save-restriction
  441.       (widen)
  442.       (if (not region-p)
  443.           (progn
  444.             (re-search-forward "^\\\\begin{menu}")
  445.             (latexinfo-menu-indent-description column)
  446.             (message
  447.              "Indented descriptions in menu.  You may save the buffer."))
  448.         ;;else
  449.         (message "Indenting every menu description in region... ")
  450.         (goto-char (region-beginning))
  451.         (while (and (< (point) (region-end))
  452.                     (latexinfo-locate-menu-p))
  453.           (forward-line 1)
  454.           (latexinfo-menu-indent-description column))
  455.         (message "Indenting done.  You may save the buffer.")))))
  456. (defun latexinfo-menu-indent-description (to-column-number)
  457.   "Indent the Latexinfo file menu description to TO-COLUMN-NUMBER.
  458. Start with point just after the word `menu' in the `\\menu' line and
  459. leave point on the line before the `\\end{menu}' line.  Does not indent
  460. second and subsequent lines of a multi-line description."
  461.   (let* ((beginning-of-next-line (point)))
  462.     (while (< beginning-of-next-line
  463.               (save-excursion     ; beginning of end menu line
  464.                 (goto-char (latexinfo-menu-end))
  465.                 (beginning-of-line)
  466.                 (point)))
  467.       (if (search-forward "::" (latexinfo-menu-end) t)
  468.           (progn
  469.             (let ((beginning-white-space (point)))
  470.               (skip-chars-forward " \t")  ; skip over spaces
  471.               (if (looking-at "\\(\\\\\\|\\w\\)+") ; if there is text
  472.                   (progn
  473.                     ;; remove pre-existing indentation
  474.                     (delete-region beginning-white-space (point))
  475.                     (indent-to-column to-column-number))))))
  476.       ;; position point at beginning of next line
  477.       (forward-line 1)                  
  478.       (setq beginning-of-next-line (point)))))
  479. ;;; Making the master menu
  480. (defun latexinfo-master-menu (update-all-nodes-menus-p)
  481.   "Make a master menu for a whole Latexinfo file.
  482. Non-nil argument (prefix, if interactive) means first update all
  483. existing nodes and menus.  Remove pre-existing master menu, if there is one.
  484. This function creates a master menu that follows the top node.  The
  485. master menu includes every entry from all the other menus.  It
  486. replaces any existing ordinary menu that follows the top node.
  487. If called with a non-nil argument, this function first updates all the
  488. menus in the buffer (incorporating descriptions from pre-existing
  489. menus) before it constructs the master menu.
  490. The function removes the detailed part of an already existing master
  491. menu.  This action depends on the pre-exisitng master menu using the
  492. standard `latexinfo-master-menu-header'.
  493. The master menu has the following format, which is adapted from the
  494. recommendation in the Latexinfo Manual:
  495.    * The first part contains the major nodes in the Latexinfo file: the
  496.      nodes for the chapters, chapter-like sections, and the major
  497.      appendices.  This includes the indices, so long as they are in
  498.      chapter-like sections, such as unnumbered sections.
  499.    * The second and subsequent parts contain a listing of the other,
  500.      lower level menus, in order.  This way, an inquirer can go
  501.      directly to a particular node if he or she is searching for
  502.      specific information.
  503. Each of the menus in the detailed node listing is introduced by the
  504. title of the section containing the menu."
  505.   (interactive "P")
  506.   (widen)
  507.   (goto-char (point-min))
  508.   ;; Move point to location after `top'.
  509.   (if (not (re-search-forward "^\\\\node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
  510.       (error "This buffer needs a Top node!"))
  511.   (let ((first-chapter                  
  512.          (save-excursion (re-search-forward "^\\\\node") (point))))
  513.     (if (re-search-forward latexinfo-master-menu-header first-chapter t)
  514.         ;; Remove detailed master menu listing
  515.         (progn
  516.            (goto-char (match-beginning 0))
  517.           (let ((end-of-detailed-menu-descriptions
  518.                  (save-excursion     ; beginning of end menu line
  519.                    (goto-char (latexinfo-menu-end))
  520.                    (beginning-of-line) (forward-char -1)
  521.                    (point))))
  522.             (delete-region (point) end-of-detailed-menu-descriptions)))))
  523.   (if update-all-nodes-menus-p
  524.       (progn
  525.         (message "Making a master menu in %s ...first updating all nodes... "
  526.                  (buffer-name))
  527.         (sleep-for 2)
  528.         (mark-whole-buffer)
  529.         (latexinfo-update-node t)
  530.         (message "Updating all menus in %s ... " (buffer-name))        
  531.         (sleep-for 2)
  532.         (mark-whole-buffer)
  533.         (latexinfo-make-menu t)))
  534.   (message "Now making the master menu in %s... " (buffer-name))
  535.   (sleep-for 2)
  536.   (goto-char (point-min))
  537.   (latexinfo-insert-master-menu-list
  538.    (latexinfo-master-menu-list))
  539.   ;; Remove extra newlines that latexinfo-insert-master-menu-list
  540.   ;; may have inserted.
  541.   (save-excursion
  542.     (goto-char (point-min))
  543.     (re-search-forward latexinfo-master-menu-header)
  544.     (goto-char (match-beginning 0))
  545.     (insert "\n")
  546.     (delete-blank-lines)
  547.     (re-search-backward "^\\\\begin{menu}")
  548.     (forward-line -1)
  549.     (delete-blank-lines)
  550.     (re-search-forward "^\\\\end{menu}")
  551.     (forward-line 1)
  552.     (delete-blank-lines))
  553.   (message "Done...completed making master menu.  You may save the buffer."))
  554. (defun latexinfo-master-menu-list ()
  555.   "Return a list of menu entries and header lines for the master menu.
  556. Start with the menu for chapters and indices and then find each
  557. following menu and the title of the node preceding that menu.
  558. The master menu list has this form:
  559.     \(\(\(... \"entry-1-2\"  \"entry-1\"\) \"title-1\"\)
  560.       \(\(... \"entry-2-2\"  \"entry-2-1\"\) \"title-2\"\)
  561.       ...\)
  562. However, there does not need to be a title field."
  563.   (let (master-menu-list)
  564.     (while (latexinfo-locate-menu-p)
  565.       (setq master-menu-list 
  566.             (cons (list
  567.                    (latexinfo-copy-menu)
  568.                    (latexinfo-copy-menu-title))
  569.                   master-menu-list)))
  570.     (reverse master-menu-list)))
  571. (defun latexinfo-insert-master-menu-list (master-menu-list)
  572.   "Format and insert the master menu in the current buffer."
  573.   (goto-char (point-min))
  574.   (re-search-forward "^\\\\begin{menu}")
  575.   (beginning-of-line)
  576.   (delete-region (point)        ; buffer must have ordinary top menu
  577.                  (save-excursion
  578.                    (re-search-forward "^\\\\end{menu}")
  579.                    (point)))
  580.   (save-excursion                       ; leave point at beginning of menu
  581.   ;; Handle top of menu
  582.   (insert "\n\\begin{menu}\n")
  583.   ;; Insert chapter menu entries
  584.   (setq this-very-menu-list (reverse (car (car master-menu-list))))
  585.   ;;; Tell user what is going on.
  586.   (message "Inserting chapter menu entry: %s ... " this-very-menu-list)
  587.   (while this-very-menu-list
  588.     (insert "* " (car this-very-menu-list) "\n")
  589.     (setq this-very-menu-list (cdr this-very-menu-list)))
  590.   (setq master-menu-list (cdr master-menu-list))
  591.   (insert latexinfo-master-menu-header)
  592.   ;; Now, insert all the other menus
  593.   ;; The menu master-menu-list has a form like this:
  594.   ;; ((("beta"  "alpha") "title-A")
  595.   ;;  (("delta" "gamma") "title-B"))
  596.   (while master-menu-list
  597.     (message
  598.      "Inserting menu for %s .... " (car (cdr (car master-menu-list))))
  599.     ;; insert title of menu section
  600.     (insert "\n" (car (cdr (car master-menu-list))) "\n\n")
  601.     ;; insert each menu entry
  602.     (setq this-very-menu-list (reverse (car (car master-menu-list))))
  603.     (while this-very-menu-list
  604.       (insert "* " (car this-very-menu-list) "\n")
  605.       (setq this-very-menu-list (cdr this-very-menu-list)))
  606.     (setq master-menu-list (cdr master-menu-list)))
  607.   ;; Finish menu
  608.   (insert "\\end{menu}\n\n")))
  609. (defvar latexinfo-master-menu-header
  610.   "\n --- The Detailed Node Listing ---\n"
  611.   "String inserted before lower level entries in Latexinfo master menu.
  612. It comes after the chapter-level menu entries.")
  613. (defun latexinfo-locate-menu-p ()
  614.   "Find the next menu in the latexinfo file.
  615. If found, leave point after word `menu' on the `\\begin{menu}' line, and 
  616. return t. If a menu is not found, do not move point and return nil."
  617.   (re-search-forward "\\(^\\\\begin{menu}\\)" nil t))
  618. (defun latexinfo-copy-menu-title  ()
  619.   "Return the title of the section preceding the menu as a string.
  620. If such a title cannot be found, return an empty string.  Do not move
  621. point."
  622.   (save-excursion
  623.     (if (re-search-backward
  624.          (concat
  625.           "\\(^\\\\top"
  626.           "\\|"                         ; or
  627.           latexinfo-section-types-regexp ; all other section types
  628.           "\\)")
  629.          nil
  630.          t)
  631.         (progn
  632.           (beginning-of-line)
  633.           (forward-word 1)              ; skip over section type
  634.           (skip-chars-forward " \t")    ; and over spaces
  635.       (buffer-substring        ; look for braces - mike
  636.        (1+ (point))
  637.        (progn 
  638.          (forward-sexp 1) (1- (point)))))
  639.       "")))
  640. (defun latexinfo-copy-menu ()
  641.   "Return the entries of an existing menu as a list.
  642. Start with point just after the word `menu' in the `\\menu' line
  643. and leave point on the line before the `\\end{menu}' line."
  644.   (let* (this-menu-list
  645.          (end-of-menu (latexinfo-menu-end)) ; position of end of `\\end{menu}'
  646.          (last-entry (save-excursion      ; position of beginning of
  647.                                           ; last `* ' entry
  648.                       (goto-char end-of-menu)
  649.                       (re-search-backward "^\* ") ; handle multi-line desc.
  650.                       (point))))
  651.     (while (< (point) last-entry)
  652.       (if (re-search-forward  "^\* " end-of-menu t)
  653.           (progn
  654.             (setq this-menu-list
  655.                   (cons
  656.                    (buffer-substring 
  657.                     (point)
  658.                     ;; copy multi-line descriptions
  659.                     (save-excursion
  660.                       (re-search-forward "\\(^\* \\|^\\\\e\\)" nil t)
  661.                       (- (point) 3)))
  662.                    this-menu-list)))))
  663.     this-menu-list))
  664. ;;; Determining the hierarchical level in the latexinfo file
  665. (defun latexinfo-specific-section-type () 
  666.   "Return the specific type of next section, as a string.
  667. For example, \"unnumberedsubsec\".  Return \"top\" for top node.
  668. Searches forward for a section.  Hence, point must be before the
  669. section whose type will be found.  Does not move point.  Signal an
  670. error if the node is not the top node and a section is not found."
  671.   (save-excursion
  672.     (cond
  673.      ((re-search-forward "^\\\\node [ \t]*top[ \t]*\\(,\\|$\\)"
  674. ;;; Following search limit by cph but causes a bug
  675. ;;;             (save-excursion
  676. ;;;               (end-of-line)
  677. ;;;               (point))
  678.                          nil
  679.              t)
  680.       "top")
  681.      ((re-search-forward latexinfo-section-types-regexp nil t)
  682.       (buffer-substring (progn (beginning-of-line) ; copy its name
  683.                                (1+ (point)))
  684.                         (progn (forward-word 1)
  685.                                (point))))
  686.      (t
  687.       (error
  688.        "latexinfo-specific-section-type: Chapter or section not found.")))))
  689. (defun latexinfo-hierarchic-level ()
  690.   "Return the general hierarchal level of the next node in a latexinfo file.
  691. Thus, a subsection* is of type subsection."
  692.   (or
  693.    (cdr (assoc
  694.      (latexinfo-specific-section-type)
  695.      latexinfo-section-to-generic-alist))
  696.    (error "Unknown section type!"))
  697. ;;; Locating the major positions
  698. (defun latexinfo-update-menu-region-beginning (level)  
  699.   "Locate beginning of higher level section this section is within.
  700. Return position of the beginning of the node line; do not move point.
  701. Thus, if this level is subsection, searches backwards for section node.
  702. Only argument is a string of the general type of section."
  703.   (cond
  704.    ((or (string-equal "top" level)
  705.     (string-equal "chapter" level))
  706.     (save-excursion
  707.       (goto-char (point-min))
  708.       (re-search-forward "^\\\\node [ \t]*top[ \t]*\\(,\\|$\\)" nil t)
  709.       (beginning-of-line)
  710.       (point)))
  711.    (t
  712.     (save-excursion
  713.       (re-search-backward
  714.        (concat
  715.         "\\(^\\\\node\\).*\n"              ; match node line
  716.         "\\(\\(\\(^\\\\c\\).*\n\\)"        ; match comment line, if any
  717.         "\\|"                           ; or
  718.         "\\(^\\\\begin{ifinfo}[ ]*\n\\)\\)?"      ; ifinfo line, if any
  719.         (eval
  720.          (cdr (assoc level latexinfo-update-menu-higher-regexps))))
  721.        nil
  722.        'goto-beginning)
  723.       (point)))))
  724. (defun latexinfo-update-menu-region-end (level)  
  725.   "Locate end of higher level section this section is within.
  726. Return position; do not move point.  Thus, if this level is a
  727. subsection, find the node for the section this subsection is within.
  728. If level is top or chapter, returns end of file.  Only argument is a
  729. string of the general type of section."
  730.   (save-excursion
  731.     (if (re-search-forward
  732.          (concat
  733.           "\\(^\\\\node\\).*\n"            ; match node line
  734.           "\\(\\(\\(^\\\\c\\).*\n\\)"      ; match comment line, if any
  735.           "\\|"                         ; or
  736.           "\\(^\\\\begin{ifinfo}[ ]*\n\\)\\)?"    ; ifinfo line, if any
  737.           (eval
  738.            ;; Never finds end of level above chapter so goes to end.
  739.            (cdr (assoc level latexinfo-update-menu-higher-regexps))))
  740.          nil
  741.          'goto-end)
  742.         (match-beginning 1)
  743.       (point-max))))
  744. (defun latexinfo-menu-first-node (beginning end)
  745.   "Locate first node of the section the menu will be placed in.  
  746. Return position; do not move point.
  747. The menu will be located just before this position.  
  748. First argument is the position of the beginning of the section in
  749. which the menu will be located; second argument is the position of the
  750. end of that region; it limits the search."
  751.   (save-excursion
  752.     (goto-char beginning)
  753.     (forward-line 1)
  754.     (re-search-forward "^\\\\node" end t)
  755.     (beginning-of-line)
  756.     (point)))
  757. ;;; Alists and regular expressions for defining hierarchical levels
  758. (defvar latexinfo-section-to-generic-alist
  759.   '(("top" . "top")
  760.     ("chapter" . "chapter")
  761.     ("chapter*" . "chapter")
  762.     ("unnumbered" . "chapter")
  763.     ("section" . "section")
  764.     ("section*" . "section")
  765.     ("unnumberedsec" . "section")
  766.     ("subsection" . "subsection")
  767.     ("subsection*" . "subsection")
  768.     ("unnumberedsubsec" . "subsection")
  769.     ("subsubsection" . "subsubsection")
  770.     ("subsubsection*" . "subsubsection")
  771.     ("unnumberedsubsubsec" . "subsubsection"))
  772.   "*An alist of specific and corresponding generic Latexinfo section types.
  773. The keys are strings specifying specific types of section; the values
  774. are strings of their corresponding general types.")
  775. (defvar latexinfo-section-types-regexp
  776.   "^\\\\\\(chapter\\|section\\|subsection\\|subsubsection\\|unnumbered\\|unnumberedsec\\|unnumberedsubsec\\|unnumberedsubsubsec\\)"
  777.   "Regexp matching chapter, section, other headings (but not the top node).")
  778. (defvar latexinfo-chapter-level-regexp 
  779.   "chapter\\|chapter\\*\\|unnumbered"
  780.   "Regular expression matching just the Latexinfo chapter level headings.")
  781. (defvar latexinfo-section-level-regexp 
  782.   "section\\|section\\*\\|unnumberedsec"
  783.   "Regular expression matching just the Latexinfo section level headings.")
  784. (defvar latexinfo-subsection-level-regexp 
  785.   "subsection\\|subsection\\*\\|unnumberedsubsec"
  786.   "Regular expression matching just the Latexinfo subsection level headings.")
  787. (defvar latexinfo-subsubsection-level-regexp
  788.   "subsubsection\\|subsubsection\\*\\|unnumberedsubsubsec"
  789.   "Regular expression matching just the Latexinfo subsubsection level headings.")
  790. (defvar latexinfo-update-menu-same-level-regexps
  791.   '(("top" . "top[ \t{]+")
  792.     ("chapter" . 
  793.      (concat "\\(^\\\\\\)\\(" latexinfo-chapter-level-regexp "\\)[ \t{]*"))
  794.     ("section" . 
  795.      (concat "\\(^\\\\\\)\\(" latexinfo-section-level-regexp "\\)[ \t{]*"))
  796.     ("subsection" .  
  797.      (concat "\\(^\\\\\\)\\(" latexinfo-subsection-level-regexp "\\)[ \t{]*"))
  798.     ("subsubsection" . 
  799.      (concat "\\(^\\\\\\)\\(" latexinfo-subsubsection-level-regexp "\\)[ \t{]*")))
  800.   "*Regexps for searching for same level sections in a Latexinfo file.
  801. The keys are strings specifying the general hierarchical level in the
  802. document; the values are regular expressions.")
  803. (defvar latexinfo-update-menu-higher-regexps
  804.   '(("top" . "^\\\\node [ \t]*DIR") 
  805.     ("chapter" . "^\\\\node [ \t]*top[ \t]*\\(,\\|$\\)")
  806.     ("section" .
  807.      (concat 
  808.       "\\(^\\\\\\("
  809.       latexinfo-chapter-level-regexp
  810.       "\\)[ \t{]*\\)"))
  811.     ("subsection" .
  812.      (concat 
  813.       "\\(^\\\\\\("
  814.       latexinfo-section-level-regexp
  815.       "\\|"
  816.       latexinfo-chapter-level-regexp
  817.       "\\)[ \t{]*\\)"))
  818.     ("subsubsection" .
  819.      (concat 
  820.       "\\(^\\\\\\("
  821.       latexinfo-subsection-level-regexp
  822.       "\\|"
  823.       latexinfo-section-level-regexp
  824.       "\\|"
  825.       latexinfo-chapter-level-regexp
  826.       "\\)[ \t{]*\\)")))
  827.   "*Regexps for searching for higher level sections in a Latexinfo file.
  828. The keys are strings specifying the general hierarchical level in the
  829. document; the values are regular expressions.")
  830. (defvar latexinfo-update-menu-lower-regexps
  831.   '(("top" . 
  832.      (concat 
  833.       "\\(^\\\\\\("
  834.       latexinfo-chapter-level-regexp
  835.       "\\|"
  836.       latexinfo-section-level-regexp
  837.       "\\|"
  838.       latexinfo-subsection-level-regexp
  839.       "\\|"
  840.       latexinfo-subsubsection-level-regexp
  841.       "\\)[ \t{]*\\)"))
  842.     ("chapter" . 
  843.      (concat 
  844.       "\\(^\\\\\\("
  845.       latexinfo-section-level-regexp
  846.       "\\|"
  847.       latexinfo-subsection-level-regexp
  848.       "\\|"
  849.       latexinfo-subsubsection-level-regexp
  850.       "\\)[ \t{]*\\)"))
  851.     ("section" .
  852.      (concat 
  853.       "\\(^\\\\\\("
  854.       latexinfo-subsection-level-regexp
  855.       "\\|"
  856.       latexinfo-subsubsection-level-regexp
  857.       "\\)[ \t{]*\\)"))
  858.     ("subsection" .
  859.      (concat 
  860.       "\\(^\\\\\\("
  861.       latexinfo-subsubsection-level-regexp
  862.       "\\)[ \t{]*\\)"))
  863.     ("subsubsection" . "nothing lower"))
  864.   "*Regexps for searching for lower level sections in a Latexinfo file.
  865. The keys are strings specifying the general hierarchical level in the
  866. document; the values are regular expressions.")
  867. ;;; Updating a node
  868. (defun latexinfo-update-node (&optional region-p)
  869.   "Without any prefix argument, update the node in which point is located.
  870. Non-nil argument (prefix, if interactive) means update the nodes in the
  871. marked region.
  872. The functions for creating or updating nodes and menus, and their
  873. keybindings, are:
  874.     latexinfo-update-node (&optional region-p)    \\[latexinfo-update-node]
  875.     latexinfo-every-node-update ()                \\[latexinfo-every-node-update]
  876.     latexinfo-sequential-node-update (&optional region-p)
  877.     latexinfo-make-menu (&optional region-p)      \\[latexinfo-make-menu]
  878.     latexinfo-all-menus-update ()                 \\[latexinfo-all-menus-update]
  879.     latexinfo-master-menu ()
  880.     latexinfo-indent-menu-description (column &optional region-p)
  881. The `latexinfo-column-for-description' variable specifies the column to
  882. which menu descriptions are indented. Its default value is 32."
  883.   (interactive "P")
  884.   (if (not region-p)
  885.       (let ((auto-fill-hook nil)) ; update a single node
  886.         (if (not (re-search-backward "^\\\\node" (point-min) t))
  887.             (error "Node line not found before this position."))
  888.         (latexinfo-update-the-node)
  889.         (message "Done...updated the node.  You may save the buffer."))
  890.     ;; else
  891.     (let ((auto-fill-hook nil)
  892.           (beginning (region-beginning))
  893.       (end (region-end)))
  894.       (if (= end beginning)
  895.           (error "Please mark a region!"))
  896.       (save-restriction
  897.     (narrow-to-region beginning end)
  898.     (goto-char beginning)
  899.         (push-mark)
  900.     (while     (re-search-forward "^\\\\node" (point-max) t)
  901.           (beginning-of-line)            
  902.           (latexinfo-update-the-node))
  903.         (message "Done...updated nodes in region.  You may save the buffer.")))))
  904. (defun latexinfo-every-node-update ()
  905.   "Update every node in a Latexinfo file."
  906.   (interactive)
  907.   (save-excursion
  908.     (mark-whole-buffer)
  909.     (latexinfo-update-node t)
  910.     (message "Done...updated every node.       You may save the buffer.")))
  911. (defun latexinfo-update-the-node ()
  912.   "Update one node.  Point must be at the beginning of node line.  
  913. Leave point at the end of the node line."
  914.   (latexinfo-check-for-node-name)
  915.   (latexinfo-delete-existing-pointers)
  916.   (message "Updating node: %s ... " (latexinfo-copy-node-name))
  917.   (save-restriction
  918.     (widen)
  919.     (let*
  920.         ((case-fold-search t)
  921.          (level (latexinfo-hierarchic-level))
  922.          (beginning (latexinfo-update-menu-region-beginning level))
  923.          (end (latexinfo-update-menu-region-end level)))
  924.       (if (string-equal level "top")
  925.           (latexinfo-top-pointer-case)
  926.         ;; else
  927.         (latexinfo-insert-pointer beginning end level 'next)
  928.         (latexinfo-insert-pointer beginning end level 'previous)
  929.         (latexinfo-insert-pointer beginning end level 'up)
  930.         (latexinfo-clean-up-node-line)))))
  931. (defun latexinfo-top-pointer-case ()
  932.   "Insert pointers in the Top node.  This is a special case.
  933. The `Next' pointer is a pointer to a chapter or section at a lower
  934. hierarchical level in the file.  The `Previous' and `Up' pointers are
  935. to `(dir)'.  Point must be at the beginning of the node line, and is
  936. left at the end of the node line."
  937.   (latexinfo-clean-up-node-line)
  938.   (insert ", " 
  939.           (save-excursion
  940.             ;; There may be an \chapter or other such command between
  941.             ;; the top node line and the next node line, as a title
  942.             ;; for an `ifinfo' section. This \chapter command must
  943.             ;; must be skipped.  So the procedure is to search for
  944.             ;; the next `\node' line, and then copy its name.
  945.             (if     (re-search-forward "^\\\\node" nil t)
  946.                 (progn
  947.                   (beginning-of-line)
  948.                   (latexinfo-copy-node-name))
  949.               " "))
  950.           ", (dir), (dir)"))
  951. (defun latexinfo-check-for-node-name ()
  952.   "Determine whether the node has a node name.  Prompt for one if not.
  953. Point must be at beginning of node line.  Does not move point."
  954.   (save-excursion
  955.     (forward-word 1)                    ; skip over node command
  956.     (skip-chars-forward " \t")          ; and over spaces
  957.     (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what info looks for
  958.                                         ; alternatively, use "[a-zA-Z]+"
  959.         (let ((node-name (read-from-minibuffer "Node name: ")))
  960.           (insert " " node-name)))))
  961. (defun latexinfo-delete-existing-pointers ()
  962.   "Delete `Next', `Previous', and `Up' pointers.  
  963. Starts from the current position of the cursor, and searches forward
  964. on the line for a comma and if one is found, deletes the rest of the
  965. line, including the comma.  Leaves point at beginning of line."
  966.   (if (search-forward "," (save-excursion (end-of-line) (point)) t)
  967.       (progn
  968.         (goto-char (1- (point)))
  969.         (kill-line nil)))
  970.   (beginning-of-line))
  971. (defun latexinfo-find-pointer (beginning end level direction)
  972.   "Move point to section associated with next, previous, or up pointer.
  973. Return type of pointer (either 'normal or 'no-pointer).
  974. The first and second arguments bound the search for a pointer to the
  975. beginning and end, respectively, of the enclosing higher level
  976. section.  The third argument is a string specifying the general kind
  977. of section such as \"chapter\ or \"section\".  When looking for the
  978. `Next' pointer, the section found will be at the same hierarchical
  979. level in the Latexinfo file; when looking for the `Previous' pointer,
  980. the section found will be at the same or higher hierarchical level in
  981. the Latexinfo file; when looking for the `Up' pointer, the section found
  982. will be at some level higher in the Latexinfo file.  The fourth argument
  983. \(one of 'next, 'previous, or 'up\) specifies whether to find the
  984. `Next', `Previous', or `Up' pointer."
  985.   (cond ((eq direction 'next)
  986.          (forward-line 3)             ; skip over current node
  987.          (if (re-search-forward
  988.               (eval
  989.                (cdr (assoc level latexinfo-update-menu-same-level-regexps)))
  990.               end
  991.               t)
  992.              'normal
  993.            'no-pointer))
  994.         ((eq direction 'previous)
  995.          (if (re-search-backward
  996.               (concat
  997.                "\\("
  998.                (eval
  999.                 (cdr (assoc level latexinfo-update-menu-same-level-regexps)))
  1000.                "\\|"
  1001.                (eval
  1002.                 (cdr (assoc level latexinfo-update-menu-higher-regexps)))
  1003.                "\\)")
  1004.               beginning
  1005.               t)
  1006.              'normal
  1007.            'no-pointer))
  1008.         ((eq direction 'up)
  1009.          (if (re-search-backward
  1010.              (eval (cdr (assoc level latexinfo-update-menu-higher-regexps)))
  1011.               (save-excursion
  1012.                 (goto-char beginning)
  1013.                 (beginning-of-line)
  1014.                 (point))
  1015.               t)
  1016.              'normal
  1017.            'no-pointer))
  1018.         (t
  1019.          (error "latexinfo-find-pointer: lack proper arguments"))))
  1020. (defun latexinfo-pointer-name (kind)
  1021.   "Return the node name preceding the section command.
  1022. The argument is the kind of section, either normal or no-pointer."
  1023.   (let (name)
  1024.     (cond ((eq kind 'normal)
  1025.            (end-of-line)                ; this handles prev node top case
  1026.            (re-search-backward          ; when point is already 
  1027.             "^\\\\node"                 ; at the beginning of \node line
  1028.             (save-excursion (forward-line -3))
  1029.             t)
  1030.            (setq name (latexinfo-copy-node-name)))
  1031.       ((eq kind 'no-pointer)
  1032.        (setq name " ")))    ; put a blank in the pointer slot
  1033.     name))
  1034. (defun latexinfo-insert-pointer (beginning end level direction)
  1035.   "Insert the `Next', `Previous' or `Up' node name at point.
  1036. Move point forward.  
  1037. The first and second arguments bound the search for a pointer to the
  1038. beginning and end, respectively, of the enclosing higher level
  1039. section.  The third argument is the hierarchical level of the Latexinfo
  1040. file, a string such as \"section\".  The fourth argument is direction
  1041. towards which the pointer is directed, one of `next, `previous, or
  1042. 'up."
  1043.   (end-of-line)
  1044.   (insert
  1045.    ", "
  1046.    (save-excursion
  1047.      (latexinfo-pointer-name
  1048.       (latexinfo-find-pointer beginning end level direction)))))
  1049. (defun latexinfo-clean-up-node-line ()
  1050.   "Remove extra commas, if any, at end of node line."
  1051.   (end-of-line)
  1052.   (skip-chars-backward ", ")
  1053.   (delete-region (point) (save-excursion (end-of-line) (point))))
  1054. ;;; Updating nodes sequentially
  1055. ; These sequential update functions insert `Next' or `Previous'
  1056. ; pointers that point to the following or preceding nodes even if they
  1057. ; are at higher or lower hierarchical levels.  This means that if a
  1058. ; section contains one or more subsections, the section's `Next'
  1059. ; pointer will point to the subsection and not the following section.
  1060. ; (The subsection to which `Next' points will most likely be the first
  1061. ; item on the section's menu.)
  1062. (defun latexinfo-sequential-node-update (&optional region-p)
  1063.   "Update one node (or many) in a Latexinfo file with sequential pointers.
  1064. This function causes the `Next' or `Previous' pointer to point to the
  1065. immediately preceding or following node, even if it is at a higher or
  1066. lower hierarchical level in the document.  Continually pressing `n' or
  1067. `p' takes you straight through the file.
  1068. Without any prefix argument, update the node in which point is located.
  1069. Non-nil argument (prefix, if interactive) means update the nodes in the
  1070. marked region.
  1071. This command makes it awkward to navigate among sections and
  1072. subsections; it should be used only for those documents that are meant
  1073. to be read like a novel rather than a reference, and for which the
  1074. Info `g*' command is inadequate."
  1075.   (interactive "P")
  1076.   (if (not region-p)
  1077.       (let ((auto-fill-hook nil))   ; update a single node
  1078.         (if (not (re-search-backward "^\\\\node" (point-min) t))
  1079.             (error "Node line not found before this position."))
  1080.         (latexinfo-sequentially-update-the-node)
  1081.         (message 
  1082.          "Done...sequentially updated the node .  You may save the buffer."))
  1083.     ;; else
  1084.     (let ((auto-fill-hook nil)
  1085.           (beginning (region-beginning))
  1086.           (end (region-end)))
  1087.       (if (= end beginning)
  1088.           (error "Please mark a region!"))
  1089.       (save-restriction
  1090.         (narrow-to-region beginning end)
  1091.         (goto-char beginning)
  1092.         (push-mark)
  1093.         (while (re-search-forward "^\\\\node" (point-max) t)
  1094.           (beginning-of-line)            
  1095.           (latexinfo-sequentially-update-the-node))
  1096.         (message 
  1097.          "Done...updated the nodes in sequence.  You may save the buffer.")))))
  1098. (defun latexinfo-sequentially-update-the-node ()
  1099.   "Update one node such that the pointers are sequential. 
  1100. A `Next' or `Previous' pointer points to any preceding or following node,
  1101. regardless of its hierarchical level."
  1102.         (latexinfo-check-for-node-name)
  1103.         (latexinfo-delete-existing-pointers)
  1104.         (message 
  1105.          "Sequentially updating node: %s ... " (latexinfo-copy-node-name))
  1106.         (save-restriction
  1107.           (widen)
  1108.           (let*
  1109.               ((case-fold-search t)
  1110.                (level (latexinfo-hierarchic-level)))
  1111.             (if (string-equal level "top")
  1112.                 (latexinfo-top-pointer-case)
  1113.               ;; else
  1114.               (latexinfo-sequentially-insert-pointer level 'next)
  1115.               (latexinfo-sequentially-insert-pointer level 'previous)
  1116.               (latexinfo-sequentially-insert-pointer level 'up)
  1117.               (latexinfo-clean-up-node-line)))))
  1118. (defun latexinfo-sequentially-find-pointer (level direction)
  1119.   "Find next or previous pointer sequentially in Latexinfo file, or up pointer.
  1120. Move point to section associated with the pointer.  Find point even if
  1121. it is in a different section.
  1122. Return type of pointer (either 'normal or 'no-pointer).
  1123. The first argument is a string specifying the general kind of section
  1124. such as \"chapter\ or \"section\".  The section found will be at the
  1125. same hierarchical level in the Latexinfo file, or, in the case of the up
  1126. pointer, some level higher.  The second argument (one of 'next,
  1127. 'previous, or 'up) specifies whether to find the `Next', `Previous',
  1128. or `Up' pointer."
  1129.   (cond ((eq direction 'next)
  1130.          (forward-line 3)        ; skip over current node
  1131.          (if (re-search-forward 
  1132.               latexinfo-section-types-regexp
  1133.               (point-max)
  1134.               t)
  1135.              'normal
  1136.            'no-pointer))
  1137.         ((eq direction 'previous)
  1138.          (if (re-search-backward 
  1139.               latexinfo-section-types-regexp
  1140.               (point-min)
  1141.               t)
  1142.              'normal
  1143.            'no-pointer))
  1144.         ((eq direction 'up)
  1145.      (let ((up-level
  1146.         (eval (cdr (assoc level latexinfo-update-menu-higher-regexps)))))
  1147.        (if (null up-level)
  1148.            (message "latexinfo-sequential-find-pointer: null up-level" ))
  1149.        (if (and (stringp up-level) (re-search-backward
  1150.                   up-level
  1151.                   nil ;; beginning ;; -mike
  1152.                   t))
  1153.            'normal
  1154.          'no-pointer)))
  1155.         (t
  1156.          (error "latexinfo-sequential-find-pointer: lack proper arguments"))))
  1157. (defun latexinfo-sequentially-insert-pointer (level direction)
  1158.   "Insert the `Next', `Previous' or `Up' node name at point.
  1159. Move point forward.  
  1160. The first argument is the hierarchical level of the Latexinfo file, a
  1161. string such as \"section\".  The second argument is direction, one of
  1162. `next, `previous, or 'up."
  1163.   (end-of-line)
  1164.   (insert
  1165.    ", "
  1166.    (save-excursion
  1167.      (latexinfo-pointer-name
  1168.       (latexinfo-sequentially-find-pointer level direction)))))
  1169. ;;; Inserting `\node' lines
  1170. ; The `latexinfo-insert-node-lines' function inserts `\node' lines as needed
  1171. ; before the `\chapter', `\section', and such like lines of a region
  1172. ; in a Latexinfo file.
  1173. (defun latexinfo-insert-node-lines (beginning end &optional title-p)
  1174.   "Insert missing `\\node' lines in region of Latexinfo file.
  1175. Non-nil argument (prefix, if interactive) means also to insert the
  1176. section titles as node names; and also to insert the section titles as
  1177. node names in pre-existing \\node lines that lack names."
  1178.   (interactive "r\nP")
  1179.   ;; Use marker; after inserting node lines, leave point at end of
  1180.   ;; region and mark at beginning.
  1181.   (let (beginning-marker end-marker title last-section-position)
  1182.     ;; Save current position on mark ring and set mark to end.
  1183.     (push-mark end t)                   
  1184.     (setq end-marker (mark-marker))        
  1185.     (goto-char beginning)
  1186.     (while (re-search-forward
  1187.             latexinfo-section-types-regexp 
  1188.             end-marker
  1189.             'end)
  1190.       ;; Copy title if desired.
  1191.       (if title-p
  1192.       (setq title           
  1193.         (progn
  1194.           (beginning-of-line)
  1195.           (forward-word 1)                      
  1196.           (skip-chars-forward " \t")            
  1197.           (buffer-substring
  1198.            (1+ (point))
  1199.            (save-excursion 
  1200.              (search-forward "," (save-excursion 
  1201.                        (forward-sexp 1) 
  1202.                        (1- (point)))
  1203.                      'yes)
  1204.              (point))))
  1205.       ;; Insert node line if necessary.
  1206.       (if (re-search-backward
  1207.            "^\\\\node" 
  1208.            ;; Avoid finding previous node line if node lines are close.
  1209.            (or last-section-position    
  1210.                (save-excursion (forward-line -2) (point))) t)
  1211.           ;;  \node is present, and point at beginning of that line
  1212.           (forward-word 1)        ; Leave point just after \node.
  1213.         ;; Else \node missing; insert one.
  1214.         (beginning-of-line)        ; Beginning of `\section' line.
  1215.         (insert "\\node\n")
  1216.         (backward-char 1))        ; Leave point just after `\node'.
  1217.       ;; Insert title if desired.
  1218.       (if title-p
  1219.           (progn
  1220.             (skip-chars-forward " \t")
  1221.             ;; Use regexp based on what info looks for
  1222.             ;; (alternatively, use "[a-zA-Z]+");
  1223.             ;; this means we only insert a title if none exists.
  1224.             (if (not (looking-at "[^,\t\n ]+")) 
  1225.                 (progn
  1226.                   (beginning-of-line) 
  1227.                   (forward-word 1)
  1228.                   (insert " " title)
  1229.                   (message "Inserted title %s ... " title)))))
  1230.       ;; Go forward beyond current section title.
  1231.       (re-search-forward latexinfo-section-types-regexp 
  1232.                          (save-excursion (forward-line 3) (point)) t)
  1233.       (setq last-section-position (point))
  1234.       (forward-line 1))
  1235.     ;; Leave point at end of region, mark at beginning.
  1236.     (set-mark beginning)
  1237.     (if title-p
  1238.     (message
  1239.      "Done inserting node lines and titles.  You may save the buffer.")
  1240.       (message "Done inserting node lines.  You may save the buffer."))))
  1241. ;;; Update and create menus for multi-file Latexinfo sources
  1242. ;;  1. M-x latexinfo-multiple-files-update 
  1243. ;;     Read the include file list of an outer Latexinfo file and
  1244. ;;     update all highest level nodes in the files listed and insert a
  1245. ;;     main menu in the outer file after its top node.
  1246. ;;  2. C-u M-x latexinfo-multiple-files-update 
  1247. ;;     Same as 1, but insert a master menu.  (Saves reupdating lower
  1248. ;;     level menus and nodes.)  This command simply reads every menu,
  1249. ;;     so if the menus are wrong, the master menu will be wrong.
  1250. ;;     Similarly, if the lower level node pointers are wrong, they
  1251. ;;     will stay wrong.
  1252. ;;  3. C-u 2 M-x latexinfo-multiple-files-update 
  1253. ;;     Read the include file list of an outer Latexinfo file and
  1254. ;;     update all nodes and menus in the files listed and insert a
  1255. ;;     master menu in the outer file after its top node.
  1256. ;;; Note: these functions:
  1257. ;;;   * Do not save or delete any buffers.  You may fill up your memory.
  1258. ;;;   * Do not handle any pre-existing nodes in outer file.  
  1259. ;;;     Hence, you may need a file for indices.
  1260. ;;; Auxiliary functions for multiple file updating
  1261. (defun latexinfo-multi-file-included-list (outer-file)
  1262.   "Return a list of the included files in OUTER-FILE."
  1263.   (let ((included-file-list (list outer-file))
  1264.         start)
  1265.     (save-excursion
  1266.       (switch-to-buffer (find-file-noselect outer-file))
  1267.       (widen)
  1268.       (goto-char (point-min))
  1269.       (while (re-search-forward "^\\\\include" nil t)
  1270.         (skip-chars-forward " \t")
  1271.         (setq start (point))
  1272.         (end-of-line)
  1273.         (skip-chars-backward " \t")   
  1274.         (setq included-file-list
  1275.               (cons (buffer-substring start (point))
  1276.                     included-file-list)))
  1277.       (nreverse included-file-list))))
  1278. (defun latexinfo-copy-next-section-title ()
  1279.   "Return the name of the immediately following section as a string.
  1280. Start with point at the beginning of the node line.  Leave point at the
  1281. same place.  If there is no title, returns an empty string."
  1282.   (save-excursion
  1283.     (end-of-line)
  1284.     (let ((section-end (or 
  1285.                         (save-excursion
  1286.                           (if (re-search-forward "\\(^\\\\node\\)" nil t)
  1287.                               (match-beginning 0)))
  1288.                         (point-max))))
  1289.       (if (re-search-forward latexinfo-section-types-regexp section-end t)
  1290.           (beginning-of-line)
  1291.           ;; copy title
  1292.           (let ((title
  1293.                  (buffer-substring
  1294.                   (progn (forward-word 1)           ; skip over section type
  1295.                          (skip-chars-forward " \t") ; and over spaces
  1296.                          (point))
  1297.                   (progn (end-of-line) (point)))))
  1298.             title)
  1299.         ""))))
  1300. (defun latexinfo-multi-file-update (files &optional update-everything)
  1301.   "Update first node pointers in each file in FILES.
  1302. Return a list of the node names and the title immediate following them.
  1303. The first file in the list is an outer file; the remaining are
  1304. files included in the outer file with `\\include' commands.
  1305. If optional arg UPDATE-EVERYTHING non-nil, update every menu and
  1306. pointer in each of the included files.
  1307. Also update the `Top' level node pointers of the outer file.
  1308. Requirements:
  1309.   * the first file in the FILES list must be the outer file,
  1310.   * each of the included files must contain exactly one highest
  1311.     hierarchical level node, 
  1312.   * this node must be the first node in the included file,
  1313.   * each highest hierarchical level node must be of the same type.
  1314. Thus, normally, each included file contains one, and only one,
  1315. chapter.
  1316. The menu-list has the form:
  1317.     \(\(\"node-name1\" . \"title1\"\) 
  1318.       \(\"node-name2\" . \"title2\"\) ... \)
  1319. However, there does not need to be a title field."
  1320.   (let (menu-list)
  1321.     ;; Find the name of the first node of the first included file.
  1322.     (switch-to-buffer (find-file-noselect (car (cdr files))))
  1323.     (widen)
  1324.     (goto-char (point-min))
  1325.     (if (not (re-search-forward "^\\\\node" nil t))
  1326.         (error "No `\\node' line found in %s !" (buffer-name)))
  1327.     (beginning-of-line)
  1328.     (latexinfo-check-for-node-name)
  1329.     (setq next-node-name (latexinfo-copy-node-name))
  1330.     (setq menu-list
  1331.           (cons (cons 
  1332.                  next-node-name
  1333.                  (latexinfo-copy-next-section-title))
  1334.                 menu-list))
  1335.     ;; Go to outer file
  1336.     (switch-to-buffer (find-file-noselect (car files)))
  1337.     (goto-char (point-min))
  1338.     (if (not (re-search-forward "^\\\\node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
  1339.         (error "This buffer needs a Top node!"))
  1340.     (beginning-of-line)
  1341.     (latexinfo-delete-existing-pointers)
  1342.     (end-of-line)
  1343.     (insert ", " next-node-name ", (dir), (dir)")
  1344.     (beginning-of-line)
  1345.     (setq previous-node-name "Top")
  1346.     (setq files (cdr files))
  1347.     (while files
  1348.       
  1349.       (if (not (cdr files))
  1350.           ;; No next file
  1351.           (setq next-node-name "")
  1352.         ;; Else,
  1353.         ;; find the name of the first node in the next file.
  1354.         (switch-to-buffer (find-file-noselect (car (cdr files))))
  1355.         (widen)
  1356.         (goto-char (point-min))
  1357.         (if (not (re-search-forward "^\\\\node" nil t))
  1358.             (error "No `\\node' line found in %s !" (buffer-name)))
  1359.         (beginning-of-line)
  1360.         (latexinfo-check-for-node-name)
  1361.         (setq next-node-name (latexinfo-copy-node-name))
  1362.         (setq menu-list
  1363.               (cons (cons 
  1364.                      next-node-name
  1365.                      (latexinfo-copy-next-section-title))
  1366.                     menu-list)))
  1367.       ;; Go to node to be updated.
  1368.       (switch-to-buffer (find-file-noselect (car files)))
  1369.       (goto-char (point-min))
  1370.       (if (not (re-search-forward "^\\\\node" nil t))
  1371.           (error "No `\\node' line found in %s !" (buffer-name)))
  1372.       (beginning-of-line)
  1373.       
  1374.       ;; Update other menus and nodes if requested.
  1375.       (if update-everything (latexinfo-all-menus-update t))
  1376.       (beginning-of-line)
  1377.       (latexinfo-delete-existing-pointers)
  1378.       (end-of-line)
  1379.       (insert ", " next-node-name ", " previous-node-name ", " up-node-name)
  1380.       
  1381.       (beginning-of-line)
  1382.       (setq previous-node-name (latexinfo-copy-node-name))
  1383.       
  1384.       (setq files (cdr files)))
  1385.     (nreverse menu-list)))
  1386. (defun latexinfo-multi-files-insert-main-menu (menu-list)
  1387.   "Insert formatted main menu at point.
  1388. Indents the first line of the description, if any, to the value of
  1389. latexinfo-column-for-description."
  1390.   (insert "\\begin{menu}\n")
  1391.   (while menu-list
  1392.     (if (cdr (car menu-list))       ; menu-list has description entry
  1393.         (progn
  1394.           (insert 
  1395.            (format "* %s::" (car (car menu-list)))) ; node-name entry
  1396.           (indent-to latexinfo-column-for-description 2)
  1397.           (insert 
  1398.            (format "%s\n" (cdr (car menu-list)))))  ; description entry
  1399.         ;; else menu-list lacks description entry
  1400.       (insert
  1401.        (format "* %s::\n" (car (car menu-list)))))  ; node-name entry
  1402.     (setq menu-list (cdr menu-list)))
  1403.   (insert "\\end{menu}"))
  1404. (defun latexinfo-multi-file-master-menu-list (files-list)
  1405.   "Return master menu list from files in FILES-LIST.
  1406. Menu entries in each file collected using `latexinfo-master-menu-list'.
  1407. The first file in FILES-LIST must be the outer file; the others must
  1408. be the files included within it.  A main menu must already exist."
  1409.   (save-excursion
  1410.     (let (master-menu-list)
  1411.       (while files-list
  1412.         (switch-to-buffer (find-file-noselect (car files-list)))
  1413.         (message "Working on: %s " (current-buffer))
  1414.         (goto-char (point-min))
  1415.         (setq master-menu-list
  1416.               (append master-menu-list (latexinfo-master-menu-list)))
  1417.         (setq files-list (cdr files-list)))
  1418.       master-menu-list)))
  1419. ;;; The multiple-file update function
  1420. (defun latexinfo-multiple-files-update
  1421.   (outer-file &optional update-everything make-master-menu)
  1422.   "Update first node pointers in each file included in OUTER-FILE;
  1423. create or update the `Top' level node pointers and the main menu in
  1424. the outer file that refers to such nodes.  This does not create or
  1425. update menus or pointers within the included files.
  1426. With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
  1427. insert a master menu in OUTER-FILE in addition to creating or updating
  1428. pointers in the first \\node line in each included file and creating or
  1429. updating the `Top' level node pointers of the outer file.  This does
  1430. not create or update other menus and pointers within the included
  1431. files.
  1432. With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
  1433. interactive), update all the menus and all the `Next', `Previous', and
  1434. `Up' pointers of all the files included in OUTER-FILE before inserting
  1435. a master menu in OUTER-FILE.  Also, update the `Top' level node
  1436. pointers of OUTER-FILE.
  1437. Notes: 
  1438.   * this command does NOT save any files--you must save the
  1439.     outer file and any modified, included files.
  1440.   * except for the `Top' node, this command does NOT handle any
  1441.     pre-existing nodes in the outer file; hence, indices must be
  1442.     enclosed in an included file.
  1443. Requirements:
  1444.   * each of the included files must contain exactly one highest
  1445.     hierarchical level node, 
  1446.   * this highest node must be the first node in the included file,
  1447.   * each highest hierarchical level node must be of the same type.
  1448. Thus, normally, each included file contains one, and only one,
  1449. chapter."
  1450.   (interactive (cons
  1451.                 (read-string
  1452.                  "Name of outer `include' file: "
  1453.                  (buffer-file-name))
  1454.                 (cond ((not current-prefix-arg)
  1455.                        '(nil nil))
  1456.                       ((listp current-prefix-arg)
  1457.                        '(t nil))   ; make-master-menu 
  1458.                       ((numberp current-prefix-arg)
  1459.                        '(t t))     ; update-everything
  1460.                       )))
  1461.   (let* ((included-file-list (latexinfo-multi-file-included-list outer-file))
  1462.          (files included-file-list)
  1463.          main-menu-list
  1464.          next-node-name
  1465.          previous-node-name
  1466.          (up-node-name "Top"))
  1467. ;;; Update the pointers 
  1468. ;;; and collect the names of the nodes and titles
  1469.     (setq main-menu-list (latexinfo-multi-file-update files update-everything))
  1470. ;;; Insert main menu
  1471.   ;; Go to outer file
  1472.   (switch-to-buffer (find-file-noselect (car included-file-list)))
  1473.   (if (latexinfo-old-menu-p
  1474.        (point-min)
  1475.        (save-excursion
  1476.          (re-search-forward "^\\include")
  1477.          (beginning-of-line)
  1478.          (point)))
  1479.       ;; If found, leave point after word `menu' on the `\\menu' line.
  1480.       (progn
  1481.         (latexinfo-incorporate-descriptions main-menu-list)
  1482.         ;; Delete existing menu.
  1483.         (beginning-of-line)
  1484.         (delete-region
  1485.          (point)
  1486.          (save-excursion (re-search-forward "^\\\\end{menu}") (point)))
  1487.         ;; Insert main menu
  1488.         (latexinfo-multi-files-insert-main-menu main-menu-list))
  1489.     ;; Else no current menu; insert it before `\include'
  1490.     (latexinfo-multi-files-insert-main-menu main-menu-list))
  1491. ;;; Insert master menu
  1492.   (if make-master-menu
  1493.       (progn
  1494.         ;; First, removing detailed part of any pre-existing master menu
  1495.         (goto-char (point-min))
  1496.         (if (re-search-forward latexinfo-master-menu-header nil t)
  1497.             ;; Remove detailed master menu listing
  1498.             (progn
  1499.               (goto-char (match-beginning 0))
  1500.               (let ((end-of-detailed-menu-descriptions
  1501.                      (save-excursion     ; beginning of end menu line
  1502.                        (goto-char (latexinfo-menu-end))
  1503.                        (beginning-of-line) (forward-char -1)
  1504.                        (point))))
  1505.                 (delete-region (point) end-of-detailed-menu-descriptions))))
  1506.         ;; Create a master menu and insert it
  1507.         (latexinfo-insert-master-menu-list 
  1508.          (latexinfo-multi-file-master-menu-list 
  1509.           included-file-list)))))
  1510.   (message "Multiple files updated."))
  1511. ;;; Place `provide' at end of file.
  1512. (provide 'latexnfo-upd)
  1513. ;;;;;;;;;;;;;;;; end texnfo-upd.el ;;;;;;;;;;;;;;;;
  1514.