home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / tinfo210.lzh / TINFO210 / ELISP / TEXNFO-U.EL < prev   
Text File  |  1991-09-13  |  67KB  |  1,781 lines

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