1 ;;; texnfo-upd.el --- a utility for updating nodes and menus in Texinfo files.
3 ;;;; Version 2.00 14 Dec 1990
5 ;;;; Copyright 1989, 1990, 1992 Free Software Foundation
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; 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.
26 ; (Much of the following commentary ought eventually be incorporated
27 ; into the Texinfo Manual.)
29 ; The node and menu updating functions automatically
31 ; * insert missing `@node' lines,
32 ; * insert the `Next', `Previous' and `Up' pointers of a node,
33 ; * insert or update the menu for a section,
34 ; * create a master menu for a Texinfo source file.
36 ; Passed an argument, the `texinfo-update-node' and
37 ; `texinfo-make-menu' functions do their jobs in the region.
39 ; These functions replace doing these jobs by hand.
40 ; You may find them helpful.
42 ; 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)
48 ; texinfo-make-menu (&optional region-p)
49 ; texinfo-all-menus-update ()
50 ; texinfo-master-menu ()
52 ; texinfo-insert-node-lines (&optional title-p)
54 ; texinfo-indent-menu-description (column &optional region-p)
56 ; The `texinfo-column-for-description' variable specifies the column to
57 ; which menu descriptions are indented.
59 ; Texinfo file structure
60 ; ----------------------
62 ; To use the updating commands, you must structure your Texinfo file
63 ; hierarchically. Each `@node' line, with the exception of the top
64 ; node, must be accompanied by some kind of section line, such as an
65 ; `@chapter' or `@section' line. Each node-line/section-line
66 ; combination must look like this:
68 ; @node Lists and Tables, Cross References, Structuring, Top
69 ; @comment node-name, next, previous, up
70 ; @chapter Making Lists and Tables
72 ; or like this (without the `@comment' line):
74 ; @node Lists and Tables, Cross References, Structuring, Top
75 ; @chapter Making Lists and Tables
77 ; If the file has a `top' node, it must be called `top' or `Top' and
78 ; be the first node in the file.
81 ;;;; The updating functions in detail
82 ; --------------------------------
84 ; The `texinfo-update-node' function without an argument inserts
85 ; the correct next, previous and up pointers for the node in which
86 ; point is located (i.e., for the node preceding point).
88 ; With an argument, the `texinfo-update-node' function inserts the
89 ; correct next, previous and up pointers for the nodes inside the
92 ; It does not matter whether the `@node' line has pre-existing
93 ; `Next', `Previous', or `Up' pointers in it. They are removed.
95 ; The `texinfo-every-node-update' function runs `texinfo-update-node'
96 ; on the whole buffer.
98 ; The `texinfo-update-node' function inserts the immediately following
99 ; and preceding node into the `Next' or `Previous' pointers regardless
100 ; of their hierarchical level. This is only useful for certain kinds
101 ; of text, like a novel, which you go through sequentially.
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.
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.
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.
117 ; The `texinfo-all-menus-update' function runs `texinfo-make-menu'
118 ; on the whole buffer.
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.)
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.
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.
138 ; With a non-nil argument (prefix, if interactive), the function not
139 ; only inserts `@node' lines but also inserts the chapter or section
140 ; titles as the names of the corresponding nodes; and inserts titles
141 ; as node names in pre-existing `@node' lines that lack names.
143 ; Since node names should be more concise than section or chapter
144 ; titles, node names so inserted will need to be edited manually.
147 ;;;; Menu Making Functions
149 (defun texinfo-make-menu (&optional region-p
)
150 "Without any prefix argument, make or update a menu.
151 Make the menu for the section enclosing the node found following point.
153 Non-nil argument (prefix, if interactive) means make or update menus
154 for nodes within or part of the marked region.
156 Whenever a menu exists, and is being updated, the descriptions that
157 are associated with node names in the pre-existing menu are
158 incorporated into the new menu. Otherwise, the nodes' section titles
159 are inserted as descriptions."
163 (let ((level (texinfo-hierarchic-level)))
164 (texinfo-make-one-menu level
)
165 (message "Done...updated the menu. You may save the buffer."))
167 (message "Making or updating menus... ")
168 (let ((beginning (region-beginning))
169 (region-end (region-end))
170 (level (progn ; find section type following point
171 (goto-char (region-beginning))
172 (texinfo-hierarchic-level))))
173 (if (= region-end beginning
)
174 (error "Please mark a region!"))
179 (while (texinfo-find-lower-level-node level region-end
)
180 (setq level
(texinfo-hierarchic-level)) ; new, lower level
181 (texinfo-make-one-menu level
))
183 (while (and (< (point) region-end
)
184 (texinfo-find-higher-level-node level region-end
))
185 (setq level
(texinfo-hierarchic-level))
186 (while (texinfo-find-lower-level-node level region-end
)
187 (setq level
(texinfo-hierarchic-level)) ; new, lower level
188 (texinfo-make-one-menu level
))))))
189 (message "Done...updated menus. You may save the buffer.")))
191 (defun texinfo-make-one-menu (level)
192 "Make a menu of all the appropriate nodes in this section.
193 `Appropriate nodes' are those associated with sections that are
194 at the level specified by LEVEL. Point is left at the end of menu."
196 ((case-fold-search t
)
199 (goto-char (texinfo-update-menu-region-beginning level
))
202 (end (texinfo-update-menu-region-end level
))
203 (first (texinfo-menu-first-node beginning end
))
205 (goto-char beginning
)
206 (texinfo-copy-node-name)))
207 (new-menu-list (texinfo-make-menu-list beginning end level
)))
208 (if (texinfo-old-menu-p beginning first
)
210 (texinfo-incorporate-descriptions new-menu-list
)
211 (texinfo-delete-old-menu beginning first
)))
212 (texinfo-insert-menu new-menu-list node-name
)))
214 (defun texinfo-all-menus-update (&optional update-all-nodes-p
)
215 "Update every regular menu in a Texinfo file.
216 You must remove the detailed part of a pre-existing master menu before
217 running this command, lest it be partly duplicated.
219 If called with a non-nil argument, this function first updates all the
220 nodes in the buffer before updating the menus."
224 (message "Checking for a master menu... ")
226 (if (re-search-forward texinfo-master-menu-header nil t
)
228 "Please remove existing master menu, lest it be partly duplicated!")))
230 (if update-all-nodes-p
232 (message "First updating all nodes... ")
235 (texinfo-update-node t
)))
237 (message "Updating all menus... ")
239 (texinfo-make-menu t
)
240 (message "Done...updated all the menus. You may save the buffer.")))
242 (defun texinfo-find-lower-level-node (level region-end
)
243 "Search forward from point for node at any level lower than LEVEL.
244 Search is limited to the end of the marked region, REGION-END,
245 and to the end of the menu region for the level.
247 Return t if the node is found, else nil. Leave point at the beginning
248 of the node if one is found; else do not move point."
250 (if (and (< (point) region-end
)
253 "\\(^@node\\).*\n" ; match node line
254 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
256 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
257 (eval (cdr (assoc level texinfo-update-menu-lower-regexps
))))
258 ;; the next higher level node marks the end of this
259 ;; section, and no lower level node will be found beyond
260 ;; this position even if region-end is farther off
261 (texinfo-update-menu-region-end level
)
263 (goto-char (match-beginning 1))))
265 (defun texinfo-find-higher-level-node (level region-end
)
266 "Search forward from point for node at any higher level than argument LEVEL.
267 Search is limited to the end of the marked region, REGION-END.
269 Return t if the node is found, else nil. Leave point at the beginning
270 of the node if one is found; else do not move point."
272 (if (and (< (point) region-end
)
275 "\\(^@node\\).*\n" ; match node line
276 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
278 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
279 (eval ; (won't ever find a `top' node)
280 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
283 (goto-char (match-beginning 1))))
286 ;;;; Making the list of new menu entries
288 (defun texinfo-make-menu-list (beginning end level
)
289 "Make a list of node names and their descriptions.
290 Point is left at the end of the menu region, but the menu is not inserted.
292 First argument is position from which to start making menu list;
293 second argument is end of region in which to try to locate entries;
294 third argument is the level of the nodes that are the entries.
296 Node names and descriptions are dotted pairs of strings. Each pair is
297 an element of the list. If the description does not exist, the
298 element consists only of the node name."
299 (goto-char beginning
)
301 (while (texinfo-menu-locate-entry-p level end
)
304 (texinfo-copy-node-name)
305 (texinfo-copy-section-title))
307 (reverse new-menu-list
)))
309 (defun texinfo-menu-locate-entry-p (level search-end
)
310 "Find a node that will be part of menu for this section.
311 First argument is a string such as \"section\" specifying the general
312 hierarchical level of the menu; second argument is a postion
313 specifying the end of the search.
315 The function returns t if the node is found, else nil. It searches
316 forward from point, and leaves point at the beginning of the node.
318 The function finds entries of the same type. Thus `subsections' and
319 `unnumberedsubsecs' will appear in the same menu."
320 (if (re-search-forward
322 "\\(^@node\\).*\n" ; match node line
323 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
325 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
327 (cdr (assoc level texinfo-update-menu-same-level-regexps
))))
330 (goto-char (match-beginning 1))))
332 (defun texinfo-copy-node-name ()
333 "Return the node name as a string.
335 Start with point at the beginning of the node line; copy the text
336 after the node command up to the first comma on the line, if any, and
337 return the text as a string. Leaves point at the beginning of the
338 line. If there is no node name, returns an empty string."
342 (progn (forward-word 1) ; skip over node command
343 (skip-chars-forward " \t") ; and over spaces
347 (save-excursion (end-of-line) (point)) t
) ; bound search
349 (end-of-line) (point)))))
351 (defun texinfo-copy-section-title ()
352 "Return the title of the section as a string.
353 The title is used as a description line in the menu when one does not
356 Move point to the beginning of the appropriate section line by going
357 to the start of the text matched by last regexp searched for, which
358 must have been done by `texinfo-menu-locate-entry-p'."
360 ;; could use the same re-search as in `texinfo-menu-locate-entry-p'
361 ;; instead of using `match-beginning'; such a variation would be
362 ;; more general, but would waste information already collected
364 (goto-char (match-beginning 7)) ; match section name
367 (progn (forward-word 1) ; skip over section type
368 (skip-chars-forward " \t") ; and over spaces
370 (progn (end-of-line) (point))))
373 ;;;; Handling the old menu
375 (defun texinfo-old-menu-p (beginning first
)
376 "Move point to the beginning of the menu for this section, if any.
377 Otherwise move point to the end of the first node of this section.
378 Return t if a menu is found, nil otherwise.
380 First argument is the position of the beginning of the section in which
381 the menu will be located; second argument is the position of the first
382 node within the section.
384 If no menu is found, the function inserts two newlines just before the
385 end of the section, and leaves point there where a menu ought to be."
386 (goto-char beginning
)
387 (if (not (re-search-forward "^@menu" first
'goto-end
))
388 (progn (insert "\n\n") (forward-line -
2) nil
)
391 (defun texinfo-incorporate-descriptions (new-menu-list)
392 "Copy the old menu line descriptions that exist to the new menu.
394 Point must be at beginning of old menu.
396 If the node-name of the new menu entry cannot be found in the old
397 menu, use the new section title for the description, but if the
398 node-name of the new menu is found in the old menu, replace the
399 section title with the old description, whatever it may be.
401 For this function, the new menu is a list made up of lists of dotted
402 pairs in which the first element of the pair is the node name and the
403 second element the description. The new menu is changed destructively.
404 The old menu is the menu as it appears in the texinfo file."
406 (let ((new-menu-list-pointer new-menu-list
)
407 (end-of-menu (texinfo-menu-end)))
409 (save-excursion ; keep point at beginning of menu
411 (concat "\* " ; so only menu entries are found
412 (car (car new-menu-list
))
413 ":") ; so only complete entries are found
416 (setcdr (car new-menu-list
)
417 (texinfo-menu-copy-old-description end-of-menu
))))
418 (setq new-menu-list
(cdr new-menu-list
)))
419 (setq new-menu-list new-menu-list-pointer
)))
421 (defun texinfo-menu-copy-old-description (end-of-menu)
422 "Return description field of old menu line as string.
423 Point must be located just after the node name. Point left before description.
424 Single argument, END-OF-MENU, is position limiting search."
425 (skip-chars-forward "[:.,\t\n ]+")
426 ;; don't copy a carriage return at line beginning with asterisk!
427 ;; do copy a description that begins with an `@'!
428 (if (and (looking-at "\\(\\w+\\|@\\)")
429 (not (looking-at "\\(^\\* \\|^@end menu\\)")))
433 (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t
)
435 (end-of-line) ; go to end of last description line
439 (defun texinfo-menu-end ()
440 "Return position of end of menu. Does not change location of point.
441 Signal an error if not end of menu."
443 (if (re-search-forward "^@end menu" nil t
)
445 (error "Menu does not have an end."))))
447 (defun texinfo-delete-old-menu (beginning first
)
448 "Delete the old menu. Point must be in or after menu.
449 First argument is position of the beginning of the section in which
450 the menu will be located; second argument is the position of the first
451 node within the section."
452 ;; No third arg to search, so error if search fails.
453 (re-search-backward "^@menu" beginning
)
454 (delete-region (point)
456 (re-search-forward "^@end menu" first
)
460 ;;;; Inserting new menu
462 ;; try 32, but perhaps 24 is better
463 (defvar texinfo-column-for-description
32
464 "*Column at which descriptions start in a Texinfo menu.")
466 (defun texinfo-insert-menu (menu-list node-name
)
467 "Insert formatted menu at point.
468 Indents the first line of the description, if any, to the value of
469 texinfo-column-for-description.
473 \(\(\"node-name1\" . \"description\"\)
474 \(\"node-name\" . \"description\"\) ... \)
476 However, there does not need to be a description field."
480 (if (cdr (car menu-list
)) ; menu-list has description entry
483 (format "* %s::" (car (car menu-list
)))) ; node-name entry
484 (indent-to texinfo-column-for-description
2)
486 (format "%s\n" (cdr (car menu-list
))))) ; description entry
487 ;; else menu-list lacks description entry
489 (format "* %s::\n" (car (car menu-list
))))) ; node-name entry
490 (setq menu-list
(cdr menu-list
)))
493 "Updated \"%s\" level menu following node: %s ... "
497 ;;;; Handling description indentation
499 ; Since the make-menu functions indent descriptions, these functions
500 ; are useful primarily for indenting a single menu specially.
502 (defun texinfo-indent-menu-description (column &optional region-p
)
503 "Indent every description in menu following point to COLUMN.
504 Non-nil argument (prefix, if interactive) means indent every
505 description in every menu in the region. Does not indent second and
506 subsequent lines of a multi-line description."
509 "nIndent menu descriptions to (column number): \nP")
515 (re-search-forward "^@menu")
516 (texinfo-menu-indent-description column
)
518 "Indented descriptions in menu. You may save the buffer."))
520 (message "Indenting every menu description in region... ")
521 (goto-char (region-beginning))
522 (while (and (< (point) (region-end))
523 (texinfo-locate-menu-p))
525 (texinfo-menu-indent-description column
))
526 (message "Indenting done. You may save the buffer.")))))
528 (defun texinfo-menu-indent-description (to-column-number)
529 "Indent the Texinfo file menu description to TO-COLUMN-NUMBER.
530 Start with point just after the word `menu' in the `@menu' line and
531 leave point on the line before the `@end menu' line. Does not indent
532 second and subsequent lines of a multi-line description."
533 (let* ((beginning-of-next-line (point)))
534 (while (< beginning-of-next-line
535 (save-excursion ; beginning of end menu line
536 (goto-char (texinfo-menu-end))
539 (if (search-forward "::" (texinfo-menu-end) t
)
541 (let ((beginning-white-space (point)))
542 (skip-chars-forward " \t") ; skip over spaces
543 (if (looking-at "\\(@\\|\\w\\)+") ; if there is text
545 ;; remove pre-existing indentation
546 (delete-region beginning-white-space
(point))
547 (indent-to-column to-column-number
))))))
548 ;; position point at beginning of next line
550 (setq beginning-of-next-line
(point)))))
553 ;;;; Making the master menu
555 (defun texinfo-master-menu (update-all-nodes-menus-p)
556 "Make a master menu for a whole Texinfo file.
557 Non-nil argument (prefix, if interactive) means first update all
558 existing nodes and menus. Remove pre-existing master menu, if there is one.
560 This function creates a master menu that follows the top node. The
561 master menu includes every entry from all the other menus. It
562 replaces any existing ordinary menu that follows the top node.
564 If called with a non-nil argument, this function first updates all the
565 menus in the buffer (incorporating descriptions from pre-existing
566 menus) before it constructs the master menu.
568 The function removes the detailed part of an already existing master
569 menu. This action depends on the pre-exisitng master menu using the
570 standard `texinfo-master-menu-header'.
572 The master menu has the following format, which is adapted from the
573 recommendation in the Texinfo Manual:
575 * The first part contains the major nodes in the Texinfo file: the
576 nodes for the chapters, chapter-like sections, and the major
577 appendices. This includes the indices, so long as they are in
578 chapter-like sections, such as unnumbered sections.
580 * The second and subsequent parts contain a listing of the other,
581 lower level menus, in order. This way, an inquirer can go
582 directly to a particular node if he or she is searching for
583 specific information.
585 Each of the menus in the detailed node listing is introduced by the
586 title of the section containing the menu."
590 (goto-char (point-min))
592 ;; Move point to location after `top'.
593 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
594 (error "This buffer needs a Top node!"))
597 (save-excursion (re-search-forward "^@node") (point))))
598 (if (re-search-forward texinfo-master-menu-header first-chapter t
)
599 ;; Remove detailed master menu listing
601 (goto-char (match-beginning 0))
602 (let ((end-of-detailed-menu-descriptions
603 (save-excursion ; beginning of end menu line
604 (goto-char (texinfo-menu-end))
605 (beginning-of-line) (forward-char -
1)
607 (delete-region (point) end-of-detailed-menu-descriptions
)))))
609 (if update-all-nodes-menus-p
611 (message "Making a master menu...first updating all nodes... ")
614 (texinfo-update-node t
)
616 (message "Updating all menus... ")
619 (texinfo-make-menu t
)))
621 (message "Now making the master menu... ")
623 (goto-char (point-min))
624 (texinfo-insert-master-menu-list
625 (texinfo-master-menu-list))
627 ;; Remove extra newlines that texinfo-insert-master-menu-list
628 ;; may have inserted.
631 (goto-char (point-min))
633 (re-search-forward texinfo-master-menu-header
)
634 (goto-char (match-beginning 0))
638 (re-search-backward "^@menu")
642 (re-search-forward "^@end menu")
644 (delete-blank-lines))
646 (message "Done...completed making master menu. You may save the buffer."))
648 (defun texinfo-master-menu-list ()
649 "Return a list of menu entries and header lines for the master menu.
651 Start with the menu for chapters and indices and then find each
652 following menu and the title of the node preceding that menu.
654 The master menu list has this form:
656 \(\(\(... \"entry-1-2\" \"entry-1\"\) \"title-1\"\)
657 \(\(... \"entry-2-2\" \"entry-2-1\"\) \"title-2\"\)
660 However, there does not need to be a title field."
662 (let (master-menu-list)
663 (while (texinfo-locate-menu-p)
664 (setq master-menu-list
667 (texinfo-copy-menu-title))
669 (reverse master-menu-list
)))
671 (defun texinfo-insert-master-menu-list (master-menu-list)
672 "Format and insert the master menu in the current buffer."
673 (goto-char (point-min))
674 (re-search-forward "^@menu")
676 (delete-region (point) ; buffer must have ordinary top menu
678 (re-search-forward "^@end menu")
681 (save-excursion ; leave point at beginning of menu
682 ;; Handle top of menu
684 ;; Insert chapter menu entries
685 (setq this-very-menu-list
(reverse (car (car master-menu-list
))))
686 ;;; Tell user what is going on.
687 (message "Inserting chapter menu entry: %s ... " this-very-menu-list
)
688 (while this-very-menu-list
689 (insert "* " (car this-very-menu-list
) "\n")
690 (setq this-very-menu-list
(cdr this-very-menu-list
)))
692 (setq master-menu-list
(cdr master-menu-list
))
694 (insert texinfo-master-menu-header
)
696 ;; Now, insert all the other menus
698 ;; The menu master-menu-list has a form like this:
699 ;; ((("beta" "alpha") "title-A")
700 ;; (("delta" "gamma") "title-B"))
702 (while master-menu-list
705 "Inserting menu for %s .... " (car (cdr (car master-menu-list
))))
706 ;; insert title of menu section
707 (insert "\n" (car (cdr (car master-menu-list
))) "\n\n")
709 ;; insert each menu entry
710 (setq this-very-menu-list
(reverse (car (car master-menu-list
))))
711 (while this-very-menu-list
712 (insert "* " (car this-very-menu-list
) "\n")
713 (setq this-very-menu-list
(cdr this-very-menu-list
)))
715 (setq master-menu-list
(cdr master-menu-list
)))
718 (insert "@end menu\n\n")))
720 (defvar texinfo-master-menu-header
721 "\n --- The Detailed Node Listing ---\n"
722 "String inserted before lower level entries in Texinfo master menu.
723 It comes after the chapter-level menu entries.")
725 (defun texinfo-locate-menu-p ()
726 "Find the next menu in the texinfo file.
727 If found, leave point after word `menu' on the `@menu' line, and return t.
728 If a menu is not found, do not move point and return nil."
729 (re-search-forward "\\(^@menu\\)" nil t
))
731 (defun texinfo-copy-menu-title ()
732 "Return the title of the section preceding the menu as a string.
733 If such a title cannot be found, return an empty string. Do not move
736 (if (re-search-backward
738 "\\(^@node\\).*\n" ; match node line
739 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
741 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
744 (assoc (texinfo-hierarchic-level)
745 texinfo-update-menu-higher-regexps
))))
748 (texinfo-copy-section-title)
751 (defun texinfo-copy-menu ()
752 "Return the entries of an existing menu as a list.
753 Start with point just after the word `menu' in the `@menu' line
754 and leave point on the line before the `@end menu' line."
755 (let* (this-menu-list
756 (end-of-menu (texinfo-menu-end)) ; position of end of `@end menu'
757 (last-entry (save-excursion ; position of beginning of
759 (goto-char end-of-menu
)
760 (re-search-backward "^\* ") ; handle multi-line desc.
762 (while (< (point) last-entry
)
763 (if (re-search-forward "^\* " end-of-menu t
)
769 ;; copy multi-line descriptions
771 (re-search-forward "\\(^\* \\|^@e\\)" nil t
)
777 ;;;; Determining the hierarchical level in the texinfo file
779 (defun texinfo-specific-section-type ()
780 "Return the specific type of next section, as a string.
781 For example, \"unnumberedsubsec\". Return \"top\" for top node.
783 Searches forward for a section. Hence, point must be before the
784 section whose type will be found. Does not move point. Signal an
785 error if the node is not the top node and a section is not found."
788 ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
794 ((re-search-forward texinfo-section-types-regexp nil t
)
795 (buffer-substring (progn (beginning-of-line) ; copy its name
797 (progn (forward-word 1)
801 "texinfo-specific-section-type: Chapter or section not found.")))))
803 (defun texinfo-hierarchic-level ()
804 "Return the general hierarchal level of the next node in a texinfo file.
805 Thus, a subheading or appendixsubsec is of type subsection."
807 (texinfo-specific-section-type)
808 texinfo-section-to-generic-alist
)))
811 ;;;; Locating the major positions
813 (defun texinfo-update-menu-region-beginning (level)
814 "Locate beginning of higher level section this section is within.
815 Return position of the beginning of the node line; do not move point.
816 Thus, if this level is subsection, searches backwards for section node.
817 Only argument is a string of the general type of section."
820 ((or (string-equal "top" level
)
821 (string-equal "chapter" level
))
823 (goto-char (point-min))
824 (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
)
831 "\\(^@node\\).*\n" ; match node line
832 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
834 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
836 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
841 (defun texinfo-update-menu-region-end (level)
842 "Locate end of higher level section this section is within.
843 Return position; do not move point. Thus, if this level is a
844 subsection, find the node for the section this subsection is within.
845 If level is top or chapter, returns end of file. Only argument is a
846 string of the general type of section."
849 (if (re-search-forward
851 "\\(^@node\\).*\n" ; match node line
852 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
854 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
856 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
862 (defun texinfo-menu-first-node (beginning end
)
863 "Locate first node of the section the menu will be placed in.
864 Return position; do not move point.
865 The menu will be located just before this position.
867 First argument is the position of the beginning of the section in
868 which the menu will be located; second argument is the position of the
869 end of that region; it limits the search."
872 (goto-char beginning
)
874 (re-search-forward "^@node" end t
)
879 ;;;; Alists and regular expressions for defining hierarchical levels
881 (defvar texinfo-section-to-generic-alist
884 ("chapter" .
"chapter")
885 ("unnumbered" .
"chapter")
886 ("majorheading" .
"chapter")
887 ("chapheading" .
"chapter")
888 ("appendix" .
"chapter")
890 ("section" .
"section")
891 ("unnumberedsec" .
"section")
892 ("heading" .
"section")
893 ("appendixsec" .
"section")
895 ("subsection" .
"subsection")
896 ("unnumberedsubsec" .
"subsection")
897 ("subheading" .
"subsection")
898 ("appendixsubsec" .
"subsection")
900 ("subsubsection" .
"subsubsection")
901 ("unnumberedsubsubsec" .
"subsubsection")
902 ("subsubheading" .
"subsubsection")
903 ("appendixsubsubsec" .
"subsubsection"))
904 "*An alist of specific and corresponding generic Texinfo section types.
905 The keys are strings specifying specific types of section; the values
906 are strings of their corresponding general types.")
908 (defvar texinfo-section-types-regexp
909 "^@\\(chapter \\|sect\\|sub\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
910 "Regexp matching chapter, section, other headings (but not the top node).")
912 (defvar texinfo-chapter-level-regexp
913 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
914 "Regular expression matching just the Texinfo chapter level headings.")
916 (defvar texinfo-section-level-regexp
917 "section\\|unnumberedsec\\|heading \\|appendixsec"
918 "Regular expression matching just the Texinfo section level headings.")
920 (defvar texinfo-subsection-level-regexp
921 "subsection\\|unnumberedsubsec\\|subheading\\|appendixsubsec"
922 "Regular expression matching just the Texinfo subsection level headings.")
924 (defvar texinfo-subsubsection-level-regexp
925 "subsubsection\\|unnumberedsubsubsec\\|subsubheading\\|appendixsubsubsec"
926 "Regular expression matching just the Texinfo subsubsection level headings.")
928 (defvar texinfo-update-menu-same-level-regexps
929 '(("top" .
"top[ \t]+")
931 (concat "\\(^@\\)\\(" texinfo-chapter-level-regexp
"\\)[ \t]*"))
933 (concat "\\(^@\\)\\(" texinfo-section-level-regexp
"\\)[ \t]*"))
935 (concat "\\(^@\\)\\(" texinfo-subsection-level-regexp
"\\)[ \t]+"))
937 (concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp
"\\)[ \t]+")))
938 "*Regexps for searching for same level sections in a Texinfo file.
939 The keys are strings specifying the general hierarchical level in the
940 document; the values are regular expressions.")
942 (defvar texinfo-update-menu-higher-regexps
943 '(("top" .
"^@node [ \t]*DIR")
944 ("chapter" .
"^@node [ \t]*top[ \t]*\\(,\\|$\\)")
948 texinfo-chapter-level-regexp
953 texinfo-section-level-regexp
955 texinfo-chapter-level-regexp
960 texinfo-subsection-level-regexp
962 texinfo-section-level-regexp
964 texinfo-chapter-level-regexp
966 "*Regexps for searching for higher level sections in a Texinfo file.
967 The keys are strings specifying the general hierarchical level in the
968 document; the values are regular expressions.")
970 (defvar texinfo-update-menu-lower-regexps
974 texinfo-chapter-level-regexp
976 texinfo-section-level-regexp
978 texinfo-subsection-level-regexp
980 texinfo-subsubsection-level-regexp
985 texinfo-section-level-regexp
987 texinfo-subsection-level-regexp
989 texinfo-subsubsection-level-regexp
994 texinfo-subsection-level-regexp
996 texinfo-subsubsection-level-regexp
1001 texinfo-subsubsection-level-regexp
1003 ("subsubsection" .
"nothing lower"))
1004 "*Regexps for searching for lower level sections in a Texinfo file.
1005 The keys are strings specifying the general hierarchical level in the
1006 document; the values are regular expressions.")
1009 ;;;; Updating a Node
1011 (defun texinfo-update-node (&optional region-p
)
1012 "Without any prefix argument, update the node in which point is located.
1013 Non-nil argument (prefix, if interactive) means update the nodes in the
1016 The functions for creating or updating nodes and menus, and their
1019 texinfo-update-node (&optional region-p) \\[texinfo-update-node]
1020 texinfo-every-node-update () \\[texinfo-every-node-update]
1021 texinfo-sequential-node-update (&optional region-p)
1023 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
1024 texinfo-all-menus-update () \\[texinfo-all-menus-update]
1025 texinfo-master-menu ()
1027 texinfo-indent-menu-description (column &optional region-p)
1029 The `texinfo-column-for-description' variable specifies the column to
1030 which menu descriptions are indented. Its default value is 24."
1034 (let ((auto-fill-function nil
)) ; update a single node
1035 (if (not (re-search-backward "^@node" (point-min) t
))
1036 (error "Node line not found before this position."))
1037 (texinfo-update-the-node)
1038 (message "Done...updated the node. You may save the buffer."))
1040 (let ((auto-fill-function nil
)
1041 (beginning (region-beginning))
1043 (if (= end beginning
)
1044 (error "Please mark a region!"))
1046 (narrow-to-region beginning end
)
1047 (goto-char beginning
)
1049 (while (re-search-forward "^@node" (point-max) t
)
1051 (texinfo-update-the-node))
1052 (message "Done...updated nodes in region. You may save the buffer.")))))
1054 (defun texinfo-every-node-update ()
1055 "Update every node in a Texinfo file."
1059 (texinfo-update-node t
)
1060 (message "Done...updated every node. You may save the buffer.")))
1062 (defun texinfo-update-the-node ()
1063 "Update one node. Point must be at the beginning of node line.
1064 Leave point at the end of the node line."
1065 (texinfo-check-for-node-name)
1066 (texinfo-delete-existing-pointers)
1067 (message "Updating node: %s ... " (texinfo-copy-node-name))
1071 ((case-fold-search t
)
1072 (level (texinfo-hierarchic-level))
1073 (beginning (texinfo-update-menu-region-beginning level
))
1074 (end (texinfo-update-menu-region-end level
)))
1075 (if (string-equal level
"top")
1076 (texinfo-top-pointer-case)
1078 (texinfo-insert-pointer beginning end level
'next
)
1079 (texinfo-insert-pointer beginning end level
'previous
)
1080 (texinfo-insert-pointer beginning end level
'up
)
1081 (texinfo-clean-up-node-line)))))
1083 (defun texinfo-top-pointer-case ()
1084 "Insert pointers in the Top node. This is a special case.
1086 The `Next' pointer is a pointer to a chapter or section at a lower
1087 hierarchical level in the file. The `Previous' and `Up' pointers are
1088 to `(dir)'. Point must be at the beginning of the node line, and is
1089 left at the end of the node line."
1091 (texinfo-clean-up-node-line)
1094 ;; There may be an @chapter or other such command between
1095 ;; the top node line and the next node line, as a title
1096 ;; for an `ifinfo' section. This @chapter command must
1097 ;; must be skipped. So the procedure is to search for
1098 ;; the next `@node' line, and then copy its name.
1099 (if (re-search-forward "^@node" nil t
)
1102 (texinfo-copy-node-name))
1106 (defun texinfo-check-for-node-name ()
1107 "Determine whether the node has a node name. Prompt for one if not.
1108 Point must be at beginning of node line. Does not move point."
1110 (forward-word 1) ; skip over node command
1111 (skip-chars-forward " \t") ; and over spaces
1112 (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what info looks for
1113 ; alternatively, use "[a-zA-Z]+"
1114 (let ((node-name (read-from-minibuffer "Node name: ")))
1115 (insert " " node-name
)))))
1117 (defun texinfo-delete-existing-pointers ()
1118 "Delete `Next', `Previous', and `Up' pointers.
1119 Starts from the current position of the cursor, and searches forward
1120 on the line for a comma and if one is found, deletes the rest of the
1121 line, including the comma. Leaves point at beginning of line."
1122 (if (search-forward "," (save-excursion (end-of-line) (point)) t
)
1124 (goto-char (1- (point)))
1126 (beginning-of-line))
1128 (defun texinfo-find-pointer (beginning end level direction
)
1129 "Move point to section associated with next, previous, or up pointer.
1130 Return type of pointer (either 'normal or 'no-pointer).
1132 The first and second arguments bound the search for a pointer to the
1133 beginning and end, respectively, of the enclosing higher level
1134 section. The third argument is a string specifying the general kind
1135 of section such as \"chapter\ or \"section\". When looking for the
1136 `Next' pointer, the section found will be at the same hierarchical
1137 level in the Texinfo file; when looking for the `Previous' pointer,
1138 the section found will be at the same or higher hierarchical level in
1139 the Texinfo file; when looking for the `Up' pointer, the section found
1140 will be at some level higher in the Texinfo file. The fourth argument
1141 \(one of 'next, 'previous, or 'up\) specifies whether to find the
1142 `Next', `Previous', or `Up' pointer."
1144 (cond ((eq direction
'next
)
1145 (forward-line 3) ; skip over current node
1146 (if (re-search-forward
1148 (cdr (assoc level texinfo-update-menu-same-level-regexps
)))
1153 ((eq direction
'previous
)
1154 (if (re-search-backward
1158 (cdr (assoc level texinfo-update-menu-same-level-regexps
)))
1161 (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1168 (if (re-search-backward
1169 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1171 (goto-char beginning
)
1178 (error "texinfo-find-pointer: lack proper arguments"))))
1180 (defun texinfo-pointer-name (kind)
1181 "Return the node name preceding the section command.
1182 The argument is the kind of section, either normal or no-pointer."
1184 (cond ((eq kind
'normal
)
1185 (end-of-line) ; this handles prev node top case
1186 (re-search-backward ; when point is already
1187 "^@node" ; at the beginning of @node line
1188 (save-excursion (forward-line -
3))
1190 (setq name
(texinfo-copy-node-name)))
1191 ((eq kind
'no-pointer
)
1192 (setq name
" "))) ; put a blank in the pointer slot
1195 (defun texinfo-insert-pointer (beginning end level direction
)
1196 "Insert the `Next', `Previous' or `Up' node name at point.
1199 The first and second arguments bound the search for a pointer to the
1200 beginning and end, respectively, of the enclosing higher level
1201 section. The third argument is the hierarchical level of the Texinfo
1202 file, a string such as \"section\". The fourth argument is direction
1203 towards which the pointer is directed, one of `next, `previous, or
1210 (texinfo-pointer-name
1211 (texinfo-find-pointer beginning end level direction
)))))
1213 (defun texinfo-clean-up-node-line ()
1214 "Remove extra commas, if any, at end of node line."
1216 (skip-chars-backward ", ")
1217 (delete-region (point) (save-excursion (end-of-line) (point))))
1220 ;;;; Updating nodes sequentially
1221 ; These sequential update functions insert `Next' or `Previous'
1222 ; pointers that point to the following or preceding nodes even if they
1223 ; are at higher or lower hierarchical levels. This means that if a
1224 ; section contains one or more subsections, the section's `Next'
1225 ; pointer will point to the subsection and not the following section.
1226 ; (The subsection to which `Next' points will most likely be the first
1227 ; item on the section's menu.)
1229 (defun texinfo-sequential-node-update (&optional region-p
)
1230 "Update one node (or many) in a Texinfo file with sequential pointers.
1232 This function causes the `Next' or `Previous' pointer to point to the
1233 immediately preceding or following node, even if it is at a higher or
1234 lower hierarchical level in the document. Continually pressing `n' or
1235 `p' takes you straight through the file.
1237 Without any prefix argument, update the node in which point is located.
1238 Non-nil argument (prefix, if interactive) means update the nodes in the
1241 This command makes it awkward to navigate among sections and
1242 subsections; it should be used only for those documents that are meant
1243 to be read like a novel rather than a reference, and for which the
1244 Info `g*' command is inadequate."
1248 (let ((auto-fill-function nil
)) ; update a single node
1249 (if (not (re-search-backward "^@node" (point-min) t
))
1250 (error "Node line not found before this position."))
1251 (texinfo-sequentially-update-the-node)
1253 "Done...sequentially updated the node . You may save the buffer."))
1255 (let ((auto-fill-function nil
)
1256 (beginning (region-beginning))
1258 (if (= end beginning
)
1259 (error "Please mark a region!"))
1261 (narrow-to-region beginning end
)
1262 (goto-char beginning
)
1264 (while (re-search-forward "^@node" (point-max) t
)
1266 (texinfo-sequentially-update-the-node))
1268 "Done...updated the nodes in sequence. You may save the buffer.")))))
1270 (defun texinfo-sequentially-update-the-node ()
1271 "Update one node such that the pointers are sequential.
1272 A `Next' or `Previous' pointer points to any preceding or following node,
1273 regardless of its hierarchical level."
1275 (texinfo-check-for-node-name)
1276 (texinfo-delete-existing-pointers)
1278 "Sequentially updating node: %s ... " (texinfo-copy-node-name))
1282 ((case-fold-search t
)
1283 (level (texinfo-hierarchic-level)))
1284 (if (string-equal level
"top")
1285 (texinfo-top-pointer-case)
1287 (texinfo-sequentially-insert-pointer level
'next
)
1288 (texinfo-sequentially-insert-pointer level
'previous
)
1289 (texinfo-sequentially-insert-pointer level
'up
)
1290 (texinfo-clean-up-node-line)))))
1292 (defun texinfo-sequentially-find-pointer (level direction
)
1293 "Find next or previous pointer sequentially in Texinfo file, or up pointer.
1294 Move point to section associated with the pointer. Find point even if
1295 it is in a different section.
1297 Return type of pointer (either 'normal or 'no-pointer).
1299 The first argument is a string specifying the general kind of section
1300 such as \"chapter\ or \"section\". The section found will be at the
1301 same hierarchical level in the Texinfo file, or, in the case of the up
1302 pointer, some level higher. The second argument (one of 'next,
1303 'previous, or 'up) specifies whether to find the `Next', `Previous',
1306 (cond ((eq direction
'next
)
1307 (forward-line 3) ; skip over current node
1308 (if (re-search-forward
1309 texinfo-section-types-regexp
1314 ((eq direction
'previous
)
1315 (if (re-search-backward
1316 texinfo-section-types-regexp
1322 (if (re-search-backward
1323 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1329 (error "texinfo-sequential-find-pointer: lack proper arguments"))))
1331 (defun texinfo-sequentially-insert-pointer (level direction
)
1332 "Insert the `Next', `Previous' or `Up' node name at point.
1335 The first argument is the hierarchical level of the Texinfo file, a
1336 string such as \"section\". The second argument is direction, one of
1337 `next, `previous, or 'up."
1343 (texinfo-pointer-name
1344 (texinfo-sequentially-find-pointer level direction
)))))
1347 ;;;; Inserting `@node' lines
1348 ; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
1349 ; before the `@chapter', `@section', and such like lines of a region
1350 ; in a Texinfo file.
1352 (defun texinfo-insert-node-lines (&optional title-p
)
1353 "Insert missing `@node' lines in region of Texinfo file.
1354 Non-nil argument (prefix, if interactive) means also to insert the
1355 section titles as node names; and also to insert the section titles as
1356 node names in pre-existing @node lines that lack names."
1359 (let ((begin-region (region-beginning))
1360 (end-region (region-end)))
1361 (goto-char begin-region
)
1362 (while (< (point) end-region
)
1363 (re-search-forward texinfo-section-types-regexp nil
'end
)
1364 ;; copy title, since most often, we will need it
1369 (skip-chars-forward " \t")
1372 (save-excursion (end-of-line) (point))))))
1373 ;; insert a node if necessary
1374 (if (re-search-backward
1380 ;; @node present, and point at beginning of that line
1382 ;; else @node missing, insert one
1384 (beginning-of-line) ; beginning of `@section' line
1386 (backward-char 1))) ; leave point just after `@node'
1387 ;; insert a title if warranted
1390 (skip-chars-forward " \t")
1391 ;; use regexp based on what info looks for
1392 ;; (alternatively, use "[a-zA-Z]+")
1393 (if (not (looking-at "[^,\t\n ]+"))
1398 (message "Inserted title %s ... " title
)))))
1399 ;; in any case, go forward beyond current section title
1400 (forward-line 3)))))
1403 "Done inserting node lines and titles. You may save the buffer.")
1404 (message "Done inserting node lines. You may save the buffer.")))
1407 ;;;; Update and create menus for multi-file Texinfo sources
1409 ;; 1. M-x texinfo-multiple-files-update
1411 ;; Read the include file list of an outer Texinfo file and
1412 ;; update all highest level nodes in the files listed and insert a
1413 ;; main menu in the outer file after its top node.
1415 ;; 2. C-u M-x texinfo-multiple-files-update
1417 ;; Same as 1, but insert a master menu. (Saves reupdating lower
1418 ;; level menus and nodes.) This command simply reads every menu,
1419 ;; so if the menus are wrong, the master menu will be wrong.
1420 ;; Similarly, if the lower level node pointers are wrong, they
1423 ;; 3. C-u 2 M-x texinfo-multiple-files-update
1425 ;; Read the include file list of an outer Texinfo file and
1426 ;; update all nodes and menus in the files listed and insert a
1427 ;; master menu in the outer file after its top node.
1429 ;;; Note: these functions:
1431 ;;; * Do not save or delete any buffers. You may fill up your memory.
1432 ;;; * Do not handle any pre-existing nodes in outer file.
1433 ;;; Hence, you may need a file for indices.
1436 ;;;; Auxiliary functions for multiple file updating
1438 (defun texinfo-multi-file-included-list (outer-file)
1439 "Return a list of the included files in OUTER-FILE."
1440 (let ((included-file-list (list outer-file
))
1443 (switch-to-buffer (find-file-noselect outer-file
))
1445 (goto-char (point-min))
1446 (while (re-search-forward "^@include" nil t
)
1447 (skip-chars-forward " \t")
1448 (setq start
(point))
1450 (skip-chars-backward " \t")
1451 (setq included-file-list
1452 (cons (buffer-substring start
(point))
1453 included-file-list
)))
1454 (nreverse included-file-list
))))
1456 (defun texinfo-copy-next-section-title ()
1457 "Return the name of the immediately following section as a string.
1459 Start with point at the beginning of the node line. Leave point at the
1460 same place. If there is no title, returns an empty string."
1464 (let ((section-end (or
1466 (re-search-forward "\\(^@node\\)" nil t
)
1467 (match-beginning 0))
1469 (if (re-search-forward texinfo-section-types-regexp section-end t
)
1473 (progn (forward-word 1) ; skip over section type
1474 (skip-chars-forward " \t") ; and over spaces
1476 (progn (end-of-line) (point)))))
1480 (defun texinfo-multi-file-update (files &optional update-everything
)
1481 "Update first node pointers in each file in FILES.
1482 Return a list of the node names and the title immediate following them.
1484 The first file in the list is an outer file; the remaining are
1485 files included in the outer file with `@include' commands.
1487 If optional arg UPDATE-EVERYTHING non-nil, update every menu and
1488 pointer in each of the included files.
1490 Also update the `Top' level node pointers of the outer file.
1494 * the first file in the FILES list must be the outer file,
1495 * each of the included files must contain exactly one highest
1496 hierarchical level node,
1497 * this node must be the first node in the included file,
1498 * each highest hierarchical level node must be of the same type.
1500 Thus, normally, each included file contains one, and only one,
1503 The menu-list has the form:
1505 \(\(\"node-name1\" . \"title1\"\)
1506 \(\"node-name2\" . \"title2\"\) ... \)
1508 However, there does not need to be a title field."
1512 ;; Find the name of the first node of the first included file.
1513 (switch-to-buffer (find-file-noselect (car (cdr files
))))
1515 (goto-char (point-min))
1516 (if (not (re-search-forward "^@node" nil t
))
1517 (error "No `@node' line found in %s !" (buffer-name)))
1519 (texinfo-check-for-node-name)
1520 (setq next-node-name
(texinfo-copy-node-name))
1525 (texinfo-copy-next-section-title))
1529 (switch-to-buffer (find-file-noselect (car files
)))
1530 (goto-char (point-min))
1531 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
1532 (error "This buffer needs a Top node!"))
1534 (texinfo-delete-existing-pointers)
1536 (insert ", " next-node-name
", (dir), (dir)")
1538 (setq previous-node-name
"Top")
1539 (setq files
(cdr files
))
1543 (if (not (cdr files
))
1545 (setq next-node-name
"")
1547 ;; find the name of the first node in the next file.
1548 (switch-to-buffer (find-file-noselect (car (cdr files
))))
1550 (goto-char (point-min))
1551 (if (not (re-search-forward "^@node" nil t
))
1552 (error "No `@node' line found in %s !" (buffer-name)))
1554 (texinfo-check-for-node-name)
1555 (setq next-node-name
(texinfo-copy-node-name))
1559 (texinfo-copy-next-section-title))
1562 ;; Go to node to be updated.
1563 (switch-to-buffer (find-file-noselect (car files
)))
1564 (goto-char (point-min))
1565 (if (not (re-search-forward "^@node" nil t
))
1566 (error "No `@node' line found in %s !" (buffer-name)))
1568 (texinfo-delete-existing-pointers)
1570 (insert ", " next-node-name
", " previous-node-name
", " up-node-name
)
1573 (setq previous-node-name
(texinfo-copy-node-name))
1575 ;; Update other menus and nodes if requested.
1576 (if update-everything
(texinfo-all-menus-update t
))
1578 (setq files
(cdr files
)))
1579 (nreverse menu-list
)))
1581 (defun texinfo-multi-files-insert-main-menu (menu-list)
1582 "Insert formatted main menu at point.
1583 Indents the first line of the description, if any, to the value of
1584 texinfo-column-for-description."
1588 (if (cdr (car menu-list
)) ; menu-list has description entry
1591 (format "* %s::" (car (car menu-list
)))) ; node-name entry
1592 (indent-to texinfo-column-for-description
2)
1594 (format "%s\n" (cdr (car menu-list
))))) ; description entry
1595 ;; else menu-list lacks description entry
1597 (format "* %s::\n" (car (car menu-list
))))) ; node-name entry
1598 (setq menu-list
(cdr menu-list
)))
1599 (insert "@end menu"))
1602 (defun texinfo-multi-file-master-menu-list (files-list)
1603 "Return master menu list from files in FILES-LIST.
1604 Menu entries in each file collected using `texinfo-master-menu-list'.
1606 The first file in FILES-LIST must be the outer file; the others must
1607 be the files included within it. A main menu must already exist."
1609 (let (master-menu-list)
1611 (switch-to-buffer (find-file-noselect (car files-list
)))
1612 (message "Working on: %s " (current-buffer))
1613 (goto-char (point-min))
1614 (setq master-menu-list
1615 (append master-menu-list
(texinfo-master-menu-list)))
1616 (setq files-list
(cdr files-list
)))
1620 ;;;; The multiple-file update function
1622 (defun texinfo-multiple-files-update
1623 (outer-file &optional update-everything make-master-menu
)
1624 "Update first node pointers in each file included in OUTER-FILE;
1625 create or update main menu in the outer file that refers to such nodes.
1626 This does not create or update menus or pointers within the included files.
1628 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
1629 insert a master menu in OUTER-FILE. This does not create or update
1630 menus or pointers within the included files.
1632 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
1633 interactive), update all the menus and all the `Next', `Previous', and
1634 `Up' pointers of all the files included in OUTER-FILE before inserting
1635 a master menu in OUTER-FILE.
1637 The command also updates the `Top' level node pointers of OUTER-FILE.
1641 * this command does NOT save any files--you must save the
1642 outer file and any modified, included files.
1644 * except for the `Top' node, this command does NOT handle any
1645 pre-existing nodes in the outer file; hence, indices must be
1646 enclosed in an included file.
1650 * each of the included files must contain exactly one highest
1651 hierarchical level node,
1652 * this highest node must be the first node in the included file,
1653 * each highest hierarchical level node must be of the same type.
1655 Thus, normally, each included file contains one, and only one,
1658 (interactive "fName of outer `include' file: ")
1660 (cond (current-prefix-arg
1661 (setq make-master-menu
(listp current-prefix-arg
))
1662 (setq update-everything
(numberp current-prefix-arg
))))
1664 (let* ((included-file-list (texinfo-multi-file-included-list outer-file
))
1665 (files included-file-list
)
1669 (up-node-name "Top"))
1671 ;;; Update the pointers
1672 ;;; and collect the names of the nodes and titles
1673 (setq main-menu-list
(texinfo-multi-file-update files update-everything
))
1675 ;;; Insert main menu
1678 (switch-to-buffer (find-file-noselect (car included-file-list
)))
1679 (if (texinfo-old-menu-p
1682 (re-search-forward "^@include")
1686 ;; If found, leave point after word `menu' on the `@menu' line.
1688 (texinfo-incorporate-descriptions main-menu-list
)
1689 ;; Delete existing menu.
1693 (save-excursion (re-search-forward "^@end menu") (point)))
1695 (texinfo-multi-files-insert-main-menu main-menu-list
))
1697 ;; Else no current menu; insert it before `@include'
1698 (texinfo-multi-files-insert-main-menu main-menu-list
))
1700 ;;; Insert master menu
1702 (if make-master-menu
1704 ;; First, removing detailed part of any pre-existing master menu
1705 (goto-char (point-min))
1706 (if (re-search-forward texinfo-master-menu-header nil t
)
1707 ;; Remove detailed master menu listing
1709 (goto-char (match-beginning 0))
1710 (let ((end-of-detailed-menu-descriptions
1711 (save-excursion ; beginning of end menu line
1712 (goto-char (texinfo-menu-end))
1713 (beginning-of-line) (forward-char -
1)
1715 (delete-region (point) end-of-detailed-menu-descriptions
))))
1717 ;; Create a master menu and insert it
1718 (texinfo-insert-master-menu-list
1719 (texinfo-multi-file-master-menu-list
1720 included-file-list
)))))
1721 (message "Multiple files updated."))
1723 (provide 'texnfo-upd
)
1725 ;;; texnfo-upd.el ends here