2 ;;;; A utility for updating nodes and menus in Texinfo files.
4 ;;;; Version 2.00 14 Dec 1990
6 ;;;; Copyright 1989, 1990 Free Software Foundation
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 1, or (at your option)
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
29 ; (Much of the following commentary ought eventually be incorporated
30 ; into the Texinfo Manual.)
32 ; The node and menu updating functions automatically
34 ; * insert missing `@node' lines,
35 ; * insert the `Next', `Previous' and `Up' pointers of a node,
36 ; * insert or update the menu for a section,
37 ; * create a master menu for a Texinfo source file.
39 ; Passed an argument, the `texinfo-update-node' and
40 ; `texinfo-make-menu' functions do their jobs in the region.
42 ; These functions replace doing these jobs by hand.
43 ; You may find them helpful.
45 ; In brief, the functions for creating or updating nodes and menus, are:
47 ; texinfo-update-node (&optional region-p)
48 ; texinfo-every-node-update ()
49 ; texinfo-sequential-node-update (&optional region-p)
51 ; texinfo-make-menu (&optional region-p)
52 ; texinfo-all-menus-update ()
53 ; texinfo-master-menu ()
55 ; texinfo-insert-node-lines (&optional title-p)
57 ; texinfo-indent-menu-description (column &optional region-p)
59 ; The `texinfo-column-for-description' variable specifies the column to
60 ; which menu descriptions are indented.
62 ; Texinfo file structure
63 ; ----------------------
65 ; To use the updating commands, you must structure your Texinfo file
66 ; hierarchically. Each `@node' line, with the exception of the top
67 ; node, must be accompanied by some kind of section line, such as an
68 ; `@chapter' or `@section' line. Each node-line/section-line
69 ; combination must look like this:
71 ; @node Lists and Tables, Cross References, Structuring, Top
72 ; @comment node-name, next, previous, up
73 ; @chapter Making Lists and Tables
75 ; or like this (without the `@comment' line):
77 ; @node Lists and Tables, Cross References, Structuring, Top
78 ; @chapter Making Lists and Tables
80 ; If the file has a `top' node, it must be called `top' or `Top' and
81 ; be the first node in the file.
84 ;;;; The updating functions in detail
85 ; --------------------------------
87 ; The `texinfo-update-node' function without an argument inserts
88 ; the correct next, previous and up pointers for the node in which
89 ; point is located (i.e., for the node preceding point).
91 ; With an argument, the `texinfo-update-node' function inserts the
92 ; correct next, previous and up pointers for the nodes inside the
95 ; It does not matter whether the `@node' line has pre-existing
96 ; `Next', `Previous', or `Up' pointers in it. They are removed.
98 ; The `texinfo-every-node-update' function runs `texinfo-update-node'
99 ; on the whole buffer.
101 ; The `texinfo-update-node' function inserts the immediately following
102 ; and preceding node into the `Next' or `Previous' pointers regardless
103 ; of their hierarchical level. This is only useful for certain kinds
104 ; of text, like a novel, which you go through sequentially.
106 ; The `texinfo-make-menu' function without an argument creates or
107 ; updates a menu for the section encompassing the node that follows
108 ; point. With an argument, it makes or updates menus for the nodes
109 ; within or part of the marked region.
111 ; Whenever an existing menu is updated, the descriptions from
112 ; that menu are incorporated into the new menu. This is done by copying
113 ; descriptions from the existing menu to the entries in the new menu
114 ; that have the same node names. If the node names are different, the
115 ; descriptions are not copied to the new menu.
117 ; Menu entries that refer to other Info files are removed since they
118 ; are not a node within current buffer. This is a deficiency.
120 ; The `texinfo-all-menus-update' function runs `texinfo-make-menu'
121 ; on the whole buffer.
123 ; The `texinfo-master-menu' function creates an extended menu located
124 ; after the top node. (The file must have a top node.) The function
125 ; first updates all the regular menus in the buffer (incorporating the
126 ; descriptions from pre-existing menus), and then constructs a master
127 ; menu that includes every entry from every other menu. (However, the
128 ; function cannot update an already existing master menu; if one
129 ; exists, it must be removed before calling the function.)
131 ; The `texinfo-indent-menu-description' function indents every
132 ; description in the menu following point, to the specified column.
133 ; Non-nil argument (prefix, if interactive) means indent every
134 ; description in every menu in the region. This function does not
135 ; indent second and subsequent lines of a multi-line description.
137 ; The `texinfo-insert-node-lines' function inserts `@node' before the
138 ; `@chapter', `@section', and such like lines of a region in a Texinfo
139 ; file where the `@node' lines are missing.
141 ; With a non-nil argument (prefix, if interactive), the function not
142 ; only inserts `@node' lines but also inserts the chapter or section
143 ; titles as the names of the corresponding nodes; and inserts titles
144 ; as node names in pre-existing `@node' lines that lack names.
146 ; Since node names should be more concise than section or chapter
147 ; titles, node names so inserted will need to be edited manually.
150 ;;;; Menu Making Functions
152 (defun texinfo-make-menu (&optional region-p
)
153 "Without any prefix argument, make or update a menu.
154 Make the menu for the section enclosing the node found following point.
156 Non-nil argument (prefix, if interactive) means make or update menus
157 for nodes within or part of the marked region.
159 Whenever a menu exists, and is being updated, the descriptions that
160 are associated with node names in the pre-existing menu are
161 incorporated into the new menu. Otherwise, the nodes' section titles
162 are inserted as descriptions."
166 (let ((level (texinfo-hierarchic-level)))
167 (texinfo-make-one-menu level
)
168 (message "Done...updated the menu. You may save the buffer."))
170 (message "Making or updating menus... ")
171 (let ((beginning (region-beginning))
172 (region-end (region-end))
173 (level (progn ; find section type following point
174 (goto-char (region-beginning))
175 (texinfo-hierarchic-level))))
176 (if (= region-end beginning
)
177 (error "Please mark a region!"))
182 (while (texinfo-find-lower-level-node level region-end
)
183 (setq level
(texinfo-hierarchic-level)) ; new, lower level
184 (texinfo-make-one-menu level
))
186 (while (and (< (point) region-end
)
187 (texinfo-find-higher-level-node level region-end
))
188 (setq level
(texinfo-hierarchic-level))
189 (while (texinfo-find-lower-level-node level region-end
)
190 (setq level
(texinfo-hierarchic-level)) ; new, lower level
191 (texinfo-make-one-menu level
))))))
192 (message "Done...updated menus. You may save the buffer.")))
194 (defun texinfo-make-one-menu (level)
195 "Make a menu of all the appropriate nodes in this section.
196 `Appropriate nodes' are those associated with sections that are
197 at the level specified by LEVEL. Point is left at the end of menu."
199 ((case-fold-search t
)
202 (goto-char (texinfo-update-menu-region-beginning level
))
205 (end (texinfo-update-menu-region-end level
))
206 (first (texinfo-menu-first-node beginning end
))
208 (goto-char beginning
)
209 (texinfo-copy-node-name)))
210 (new-menu-list (texinfo-make-menu-list beginning end level
)))
211 (if (texinfo-old-menu-p beginning first
)
213 (texinfo-incorporate-descriptions new-menu-list
)
214 (texinfo-delete-old-menu beginning first
)))
215 (texinfo-insert-menu new-menu-list node-name
)))
217 (defun texinfo-all-menus-update (&optional update-all-nodes-p
)
218 "Update every regular menu in a Texinfo file.
219 You must remove the detailed part of a pre-existing master menu before
220 running this command, lest it be partly duplicated.
222 If called with a non-nil argument, this function first updates all the
223 nodes in the buffer before updating the menus."
227 (message "Checking for a master menu... ")
229 (if (re-search-forward texinfo-master-menu-header nil t
)
231 "Please remove existing master menu, lest it be partly duplicated!")))
233 (if update-all-nodes-p
235 (message "First updating all nodes... ")
238 (texinfo-update-node t
)))
240 (message "Updating all menus... ")
242 (texinfo-make-menu t
)
243 (message "Done...updated all the menus. You may save the buffer.")))
245 (defun texinfo-find-lower-level-node (level region-end
)
246 "Search forward from point for node at any level lower than LEVEL.
247 Search is limited to the end of the marked region, REGION-END,
248 and to the end of the menu region for the level.
250 Return t if the node is found, else nil. Leave point at the beginning
251 of the node if one is found; else do not move point."
253 (if (and (< (point) region-end
)
256 "\\(^@node\\).*\n" ; match node line
257 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
259 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
260 (eval (cdr (assoc level texinfo-update-menu-lower-regexps
))))
261 ;; the next higher level node marks the end of this
262 ;; section, and no lower level node will be found beyond
263 ;; this position even if region-end is farther off
264 (texinfo-update-menu-region-end level
)
266 (goto-char (match-beginning 1))))
268 (defun texinfo-find-higher-level-node (level region-end
)
269 "Search forward from point for node at any higher level than argument LEVEL.
270 Search is limited to the end of the marked region, REGION-END.
272 Return t if the node is found, else nil. Leave point at the beginning
273 of the node if one is found; else do not move point."
275 (if (and (< (point) region-end
)
278 "\\(^@node\\).*\n" ; match node line
279 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
281 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
282 (eval ; (won't ever find a `top' node)
283 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
286 (goto-char (match-beginning 1))))
289 ;;;; Making the list of new menu entries
291 (defun texinfo-make-menu-list (beginning end level
)
292 "Make a list of node names and their descriptions.
293 Point is left at the end of the menu region, but the menu is not inserted.
295 First argument is position from which to start making menu list;
296 second argument is end of region in which to try to locate entries;
297 third argument is the level of the nodes that are the entries.
299 Node names and descriptions are dotted pairs of strings. Each pair is
300 an element of the list. If the description does not exist, the
301 element consists only of the node name."
302 (goto-char beginning
)
304 (while (texinfo-menu-locate-entry-p level end
)
307 (texinfo-copy-node-name)
308 (texinfo-copy-section-title))
310 (reverse new-menu-list
)))
312 (defun texinfo-menu-locate-entry-p (level search-end
)
313 "Find a node that will be part of menu for this section.
314 First argument is a string such as \"section\" specifying the general
315 hierarchical level of the menu; second argument is a postion
316 specifying the end of the search.
318 The function returns t if the node is found, else nil. It searches
319 forward from point, and leaves point at the beginning of the node.
321 The function finds entries of the same type. Thus `subsections' and
322 `unnumberedsubsecs' will appear in the same menu."
323 (if (re-search-forward
325 "\\(^@node\\).*\n" ; match node line
326 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
328 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
330 (cdr (assoc level texinfo-update-menu-same-level-regexps
))))
333 (goto-char (match-beginning 1))))
335 (defun texinfo-copy-node-name ()
336 "Return the node name as a string.
338 Start with point at the beginning of the node line; copy the text
339 after the node command up to the first comma on the line, if any, and
340 return the text as a string. Leaves point at the beginning of the
341 line. If there is no node name, returns an empty string."
345 (progn (forward-word 1) ; skip over node command
346 (skip-chars-forward " \t") ; and over spaces
350 (save-excursion (end-of-line) (point)) t
) ; bound search
352 (end-of-line) (point)))))
354 (defun texinfo-copy-section-title ()
355 "Return the title of the section as a string.
356 The title is used as a description line in the menu when one does not
359 Move point to the beginning of the appropriate section line by going
360 to the start of the text matched by last regexp searched for, which
361 must have been done by `texinfo-menu-locate-entry-p'."
363 ;; could use the same re-search as in `texinfo-menu-locate-entry-p'
364 ;; instead of using `match-beginning'; such a variation would be
365 ;; more general, but would waste information already collected
367 (goto-char (match-beginning 7)) ; match section name
370 (progn (forward-word 1) ; skip over section type
371 (skip-chars-forward " \t") ; and over spaces
373 (progn (end-of-line) (point))))
376 ;;;; Handling the old menu
378 (defun texinfo-old-menu-p (beginning first
)
379 "Move point to the beginning of the menu for this section, if any.
380 Otherwise move point to the end of the first node of this section.
381 Return t if a menu is found, nil otherwise.
383 First argument is the position of the beginning of the section in which
384 the menu will be located; second argument is the position of the first
385 node within the section.
387 If no menu is found, the function inserts two newlines just before the
388 end of the section, and leaves point there where a menu ought to be."
389 (goto-char beginning
)
390 (if (not (re-search-forward "^@menu" first
'goto-end
))
391 (progn (insert "\n\n") (forward-line -
2) nil
)
394 (defun texinfo-incorporate-descriptions (new-menu-list)
395 "Copy the old menu line descriptions that exist to the new menu.
397 Point must be at beginning of old menu.
399 If the node-name of the new menu entry cannot be found in the old
400 menu, use the new section title for the description, but if the
401 node-name of the new menu is found in the old menu, replace the
402 section title with the old description, whatever it may be.
404 For this function, the new menu is a list made up of lists of dotted
405 pairs in which the first element of the pair is the node name and the
406 second element the description. The new menu is changed destructively.
407 The old menu is the menu as it appears in the texinfo file."
409 (let ((new-menu-list-pointer new-menu-list
)
410 (end-of-menu (texinfo-menu-end)))
412 (save-excursion ; keep point at beginning of menu
414 (concat "\* " ; so only menu entries are found
415 (car (car new-menu-list
))
416 ":") ; so only complete entries are found
419 (setcdr (car new-menu-list
)
420 (texinfo-menu-copy-old-description end-of-menu
))))
421 (setq new-menu-list
(cdr new-menu-list
)))
422 (setq new-menu-list new-menu-list-pointer
)))
424 (defun texinfo-menu-copy-old-description (end-of-menu)
425 "Return description field of old menu line as string.
426 Point must be located just after the node name. Point left before description.
427 Single argument, END-OF-MENU, is position limiting search."
428 (skip-chars-forward "[:.,\t\n ]+")
429 ;; don't copy a carriage return at line beginning with asterisk!
430 ;; do copy a description that begins with an `@'!
431 (if (and (looking-at "\\(\\w+\\|@\\)")
432 (not (looking-at "\\(^\\* \\|^@end menu\\)")))
436 (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t
)
438 (end-of-line) ; go to end of last description line
442 (defun texinfo-menu-end ()
443 "Return position of end of menu. Does not change location of point.
444 Signal an error if not end of menu."
446 (if (re-search-forward "^@end menu" nil t
)
448 (error "Menu does not have an end."))))
450 (defun texinfo-delete-old-menu (beginning first
)
451 "Delete the old menu. Point must be in or after menu.
452 First argument is position of the beginning of the section in which
453 the menu will be located; second argument is the position of the first
454 node within the section."
455 ;; No third arg to search, so error if search fails.
456 (re-search-backward "^@menu" beginning
)
457 (delete-region (point)
459 (re-search-forward "^@end menu" first
)
463 ;;;; Inserting new menu
465 ;; try 32, but perhaps 24 is better
466 (defvar texinfo-column-for-description
32
467 "*Column at which descriptions start in a Texinfo menu.")
469 (defun texinfo-insert-menu (menu-list node-name
)
470 "Insert formatted menu at point.
471 Indents the first line of the description, if any, to the value of
472 texinfo-column-for-description.
476 \(\(\"node-name1\" . \"description\"\)
477 \(\"node-name\" . \"description\"\) ... \)
479 However, there does not need to be a description field."
483 (if (cdr (car menu-list
)) ; menu-list has description entry
486 (format "* %s::" (car (car menu-list
)))) ; node-name entry
487 (indent-to texinfo-column-for-description
2)
489 (format "%s\n" (cdr (car menu-list
))))) ; description entry
490 ;; else menu-list lacks description entry
492 (format "* %s::\n" (car (car menu-list
))))) ; node-name entry
493 (setq menu-list
(cdr menu-list
)))
496 "Updated \"%s\" level menu following node: %s ... "
500 ;;;; Handling description indentation
502 ; Since the make-menu functions indent descriptions, these functions
503 ; are useful primarily for indenting a single menu specially.
505 (defun texinfo-indent-menu-description (column &optional region-p
)
506 "Indent every description in menu following point to COLUMN.
507 Non-nil argument (prefix, if interactive) means indent every
508 description in every menu in the region. Does not indent second and
509 subsequent lines of a multi-line description."
512 "nIndent menu descriptions to (column number): \nP")
518 (re-search-forward "^@menu")
519 (texinfo-menu-indent-description column
)
521 "Indented descriptions in menu. You may save the buffer."))
523 (message "Indenting every menu description in region... ")
524 (goto-char (region-beginning))
525 (while (and (< (point) (region-end))
526 (texinfo-locate-menu-p))
528 (texinfo-menu-indent-description column
))
529 (message "Indenting done. You may save the buffer.")))))
531 (defun texinfo-menu-indent-description (to-column-number)
532 "Indent the Texinfo file menu description to TO-COLUMN-NUMBER.
533 Start with point just after the word `menu' in the `@menu' line and
534 leave point on the line before the `@end menu' line. Does not indent
535 second and subsequent lines of a multi-line description."
536 (let* ((beginning-of-next-line (point)))
537 (while (< beginning-of-next-line
538 (save-excursion ; beginning of end menu line
539 (goto-char (texinfo-menu-end))
542 (if (search-forward "::" (texinfo-menu-end) t
)
544 (let ((beginning-white-space (point)))
545 (skip-chars-forward " \t") ; skip over spaces
546 (if (looking-at "\\(@\\|\\w\\)+") ; if there is text
548 ;; remove pre-existing indentation
549 (delete-region beginning-white-space
(point))
550 (indent-to-column to-column-number
))))))
551 ;; position point at beginning of next line
553 (setq beginning-of-next-line
(point)))))
556 ;;;; Making the master menu
558 (defun texinfo-master-menu (update-all-nodes-menus-p)
559 "Make a master menu for a whole Texinfo file.
560 Non-nil argument (prefix, if interactive) means first update all
561 existing nodes and menus. Remove pre-existing master menu, if there is one.
563 This function creates a master menu that follows the top node. The
564 master menu includes every entry from all the other menus. It
565 replaces any existing ordinary menu that follows the top node.
567 If called with a non-nil argument, this function first updates all the
568 menus in the buffer (incorporating descriptions from pre-existing
569 menus) before it constructs the master menu.
571 The function removes the detailed part of an already existing master
572 menu. This action depends on the pre-exisitng master menu using the
573 standard `texinfo-master-menu-header'.
575 The master menu has the following format, which is adapted from the
576 recommendation in the Texinfo Manual:
578 * The first part contains the major nodes in the Texinfo file: the
579 nodes for the chapters, chapter-like sections, and the major
580 appendices. This includes the indices, so long as they are in
581 chapter-like sections, such as unnumbered sections.
583 * The second and subsequent parts contain a listing of the other,
584 lower level menus, in order. This way, an inquirer can go
585 directly to a particular node if he or she is searching for
586 specific information.
588 Each of the menus in the detailed node listing is introduced by the
589 title of the section containing the menu."
593 (goto-char (point-min))
595 ;; Move point to location after `top'.
596 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
597 (error "This buffer needs a Top node!"))
600 (save-excursion (re-search-forward "^@node") (point))))
601 (if (re-search-forward texinfo-master-menu-header first-chapter t
)
602 ;; Remove detailed master menu listing
604 (goto-char (match-beginning 0))
605 (let ((end-of-detailed-menu-descriptions
606 (save-excursion ; beginning of end menu line
607 (goto-char (texinfo-menu-end))
608 (beginning-of-line) (forward-char -
1)
610 (delete-region (point) end-of-detailed-menu-descriptions
)))))
612 (if update-all-nodes-menus-p
614 (message "Making a master menu...first updating all nodes... ")
617 (texinfo-update-node t
)
619 (message "Updating all menus... ")
622 (texinfo-make-menu t
)))
624 (message "Now making the master menu... ")
626 (goto-char (point-min))
627 (texinfo-insert-master-menu-list
628 (texinfo-master-menu-list))
630 ;; Remove extra newlines that texinfo-insert-master-menu-list
631 ;; may have inserted.
634 (goto-char (point-min))
636 (re-search-forward texinfo-master-menu-header
)
637 (goto-char (match-beginning 0))
641 (re-search-backward "^@menu")
645 (re-search-forward "^@end menu")
647 (delete-blank-lines))
649 (message "Done...completed making master menu. You may save the buffer."))
651 (defun texinfo-master-menu-list ()
652 "Return a list of menu entries and header lines for the master menu.
654 Start with the menu for chapters and indices and then find each
655 following menu and the title of the node preceding that menu.
657 The master menu list has this form:
659 \(\(\(... \"entry-1-2\" \"entry-1\"\) \"title-1\"\)
660 \(\(... \"entry-2-2\" \"entry-2-1\"\) \"title-2\"\)
663 However, there does not need to be a title field."
665 (let (master-menu-list)
666 (while (texinfo-locate-menu-p)
667 (setq master-menu-list
670 (texinfo-copy-menu-title))
672 (reverse master-menu-list
)))
674 (defun texinfo-insert-master-menu-list (master-menu-list)
675 "Format and insert the master menu in the current buffer."
676 (goto-char (point-min))
677 (re-search-forward "^@menu")
679 (delete-region (point) ; buffer must have ordinary top menu
681 (re-search-forward "^@end menu")
684 (save-excursion ; leave point at beginning of menu
685 ;; Handle top of menu
687 ;; Insert chapter menu entries
688 (setq this-very-menu-list
(reverse (car (car master-menu-list
))))
689 ;;; Tell user what is going on.
690 (message "Inserting chapter menu entry: %s ... " this-very-menu-list
)
691 (while this-very-menu-list
692 (insert "* " (car this-very-menu-list
) "\n")
693 (setq this-very-menu-list
(cdr this-very-menu-list
)))
695 (setq master-menu-list
(cdr master-menu-list
))
697 (insert texinfo-master-menu-header
)
699 ;; Now, insert all the other menus
701 ;; The menu master-menu-list has a form like this:
702 ;; ((("beta" "alpha") "title-A")
703 ;; (("delta" "gamma") "title-B"))
705 (while master-menu-list
708 "Inserting menu for %s .... " (car (cdr (car master-menu-list
))))
709 ;; insert title of menu section
710 (insert "\n" (car (cdr (car master-menu-list
))) "\n\n")
712 ;; insert each menu entry
713 (setq this-very-menu-list
(reverse (car (car master-menu-list
))))
714 (while this-very-menu-list
715 (insert "* " (car this-very-menu-list
) "\n")
716 (setq this-very-menu-list
(cdr this-very-menu-list
)))
718 (setq master-menu-list
(cdr master-menu-list
)))
721 (insert "@end menu\n\n")))
723 (defvar texinfo-master-menu-header
724 "\n --- The Detailed Node Listing ---\n"
725 "String inserted before lower level entries in Texinfo master menu.
726 It comes after the chapter-level menu entries.")
728 (defun texinfo-locate-menu-p ()
729 "Find the next menu in the texinfo file.
730 If found, leave point after word `menu' on the `@menu' line, and return t.
731 If a menu is not found, do not move point and return nil."
732 (re-search-forward "\\(^@menu\\)" nil t
))
734 (defun texinfo-copy-menu-title ()
735 "Return the title of the section preceding the menu as a string.
736 If such a title cannot be found, return an empty string. Do not move
739 (if (re-search-backward
741 "\\(^@node\\).*\n" ; match node line
742 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
744 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
747 (assoc (texinfo-hierarchic-level)
748 texinfo-update-menu-higher-regexps
))))
751 (texinfo-copy-section-title)
754 (defun texinfo-copy-menu ()
755 "Return the entries of an existing menu as a list.
756 Start with point just after the word `menu' in the `@menu' line
757 and leave point on the line before the `@end menu' line."
758 (let* (this-menu-list
759 (end-of-menu (texinfo-menu-end)) ; position of end of `@end menu'
760 (last-entry (save-excursion ; position of beginning of
762 (goto-char end-of-menu
)
763 (re-search-backward "^\* ") ; handle multi-line desc.
765 (while (< (point) last-entry
)
766 (if (re-search-forward "^\* " end-of-menu t
)
772 ;; copy multi-line descriptions
774 (re-search-forward "\\(^\* \\|^@e\\)" nil t
)
780 ;;;; Determining the hierarchical level in the texinfo file
782 (defun texinfo-specific-section-type ()
783 "Return the specific type of next section, as a string.
784 For example, \"unnumberedsubsec\". Return \"top\" for top node.
786 Searches forward for a section. Hence, point must be before the
787 section whose type will be found. Does not move point. Signal an
788 error if the node is not the top node and a section is not found."
791 ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
797 ((re-search-forward texinfo-section-types-regexp nil t
)
798 (buffer-substring (progn (beginning-of-line) ; copy its name
800 (progn (forward-word 1)
804 "texinfo-specific-section-type: Chapter or section not found.")))))
806 (defun texinfo-hierarchic-level ()
807 "Return the general hierarchal level of the next node in a texinfo file.
808 Thus, a subheading or appendixsubsec is of type subsection."
810 (texinfo-specific-section-type)
811 texinfo-section-to-generic-alist
)))
814 ;;;; Locating the major positions
816 (defun texinfo-update-menu-region-beginning (level)
817 "Locate beginning of higher level section this section is within.
818 Return position of the beginning of the node line; do not move point.
819 Thus, if this level is subsection, searches backwards for section node.
820 Only argument is a string of the general type of section."
823 ((or (string-equal "top" level
)
824 (string-equal "chapter" level
))
826 (goto-char (point-min))
827 (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
)
834 "\\(^@node\\).*\n" ; match node line
835 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
837 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
839 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
844 (defun texinfo-update-menu-region-end (level)
845 "Locate end of higher level section this section is within.
846 Return position; do not move point. Thus, if this level is a
847 subsection, find the node for the section this subsection is within.
848 If level is top or chapter, returns end of file. Only argument is a
849 string of the general type of section."
852 (if (re-search-forward
854 "\\(^@node\\).*\n" ; match node line
855 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
857 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
859 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
865 (defun texinfo-menu-first-node (beginning end
)
866 "Locate first node of the section the menu will be placed in.
867 Return position; do not move point.
868 The menu will be located just before this position.
870 First argument is the position of the beginning of the section in
871 which the menu will be located; second argument is the position of the
872 end of that region; it limits the search."
875 (goto-char beginning
)
877 (re-search-forward "^@node" end t
)
882 ;;;; Alists and regular expressions for defining hierarchical levels
884 (defvar texinfo-section-to-generic-alist
887 ("chapter" .
"chapter")
888 ("unnumbered" .
"chapter")
889 ("majorheading" .
"chapter")
890 ("chapheading" .
"chapter")
891 ("appendix" .
"chapter")
893 ("section" .
"section")
894 ("unnumberedsec" .
"section")
895 ("heading" .
"section")
896 ("appendixsec" .
"section")
898 ("subsection" .
"subsection")
899 ("unnumberedsubsec" .
"subsection")
900 ("subheading" .
"subsection")
901 ("appendixsubsec" .
"subsection")
903 ("subsubsection" .
"subsubsection")
904 ("unnumberedsubsubsec" .
"subsubsection")
905 ("subsubheading" .
"subsubsection")
906 ("appendixsubsubsec" .
"subsubsection"))
907 "*An alist of specific and corresponding generic Texinfo section types.
908 The keys are strings specifying specific types of section; the values
909 are strings of their corresponding general types.")
911 (defvar texinfo-section-types-regexp
912 "^@\\(chapter \\|sect\\|sub\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
913 "Regexp matching chapter, section, other headings (but not the top node).")
915 (defvar texinfo-chapter-level-regexp
916 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
917 "Regular expression matching just the Texinfo chapter level headings.")
919 (defvar texinfo-section-level-regexp
920 "section\\|unnumberedsec\\|heading \\|appendixsec"
921 "Regular expression matching just the Texinfo section level headings.")
923 (defvar texinfo-subsection-level-regexp
924 "subsection\\|unnumberedsubsec\\|subheading\\|appendixsubsec"
925 "Regular expression matching just the Texinfo subsection level headings.")
927 (defvar texinfo-subsubsection-level-regexp
928 "subsubsection\\|unnumberedsubsubsec\\|subsubheading\\|appendixsubsubsec"
929 "Regular expression matching just the Texinfo subsubsection level headings.")
931 (defvar texinfo-update-menu-same-level-regexps
932 '(("top" .
"top[ \t]+")
934 (concat "\\(^@\\)\\(" texinfo-chapter-level-regexp
"\\)[ \t]*"))
936 (concat "\\(^@\\)\\(" texinfo-section-level-regexp
"\\)[ \t]*"))
938 (concat "\\(^@\\)\\(" texinfo-subsection-level-regexp
"\\)[ \t]+"))
940 (concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp
"\\)[ \t]+")))
941 "*Regexps for searching for same level sections in a Texinfo file.
942 The keys are strings specifying the general hierarchical level in the
943 document; the values are regular expressions.")
945 (defvar texinfo-update-menu-higher-regexps
946 '(("top" .
"^@node [ \t]*DIR")
947 ("chapter" .
"^@node [ \t]*top[ \t]*\\(,\\|$\\)")
951 texinfo-chapter-level-regexp
956 texinfo-section-level-regexp
958 texinfo-chapter-level-regexp
963 texinfo-subsection-level-regexp
965 texinfo-section-level-regexp
967 texinfo-chapter-level-regexp
969 "*Regexps for searching for higher level sections in a Texinfo file.
970 The keys are strings specifying the general hierarchical level in the
971 document; the values are regular expressions.")
973 (defvar texinfo-update-menu-lower-regexps
977 texinfo-chapter-level-regexp
979 texinfo-section-level-regexp
981 texinfo-subsection-level-regexp
983 texinfo-subsubsection-level-regexp
988 texinfo-section-level-regexp
990 texinfo-subsection-level-regexp
992 texinfo-subsubsection-level-regexp
997 texinfo-subsection-level-regexp
999 texinfo-subsubsection-level-regexp
1004 texinfo-subsubsection-level-regexp
1006 ("subsubsection" .
"nothing lower"))
1007 "*Regexps for searching for lower level sections in a Texinfo file.
1008 The keys are strings specifying the general hierarchical level in the
1009 document; the values are regular expressions.")
1012 ;;;; Updating a Node
1014 (defun texinfo-update-node (&optional region-p
)
1015 "Without any prefix argument, update the node in which point is located.
1016 Non-nil argument (prefix, if interactive) means update the nodes in the
1019 The functions for creating or updating nodes and menus, and their
1022 texinfo-update-node (&optional region-p) \\[texinfo-update-node]
1023 texinfo-every-node-update () \\[texinfo-every-node-update]
1024 texinfo-sequential-node-update (&optional region-p)
1026 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
1027 texinfo-all-menus-update () \\[texinfo-all-menus-update]
1028 texinfo-master-menu ()
1030 texinfo-indent-menu-description (column &optional region-p)
1032 The `texinfo-column-for-description' variable specifies the column to
1033 which menu descriptions are indented. Its default value is 24."
1037 (let ((auto-fill-hook nil
)) ; update a single node
1038 (if (not (re-search-backward "^@node" (point-min) t
))
1039 (error "Node line not found before this position."))
1040 (texinfo-update-the-node)
1041 (message "Done...updated the node. You may save the buffer."))
1043 (let ((auto-fill-hook nil
)
1044 (beginning (region-beginning))
1046 (if (= end beginning
)
1047 (error "Please mark a region!"))
1049 (narrow-to-region beginning end
)
1050 (goto-char beginning
)
1052 (while (re-search-forward "^@node" (point-max) t
)
1054 (texinfo-update-the-node))
1055 (message "Done...updated nodes in region. You may save the buffer.")))))
1057 (defun texinfo-every-node-update ()
1058 "Update every node in a Texinfo file."
1062 (texinfo-update-node t
)
1063 (message "Done...updated every node. You may save the buffer.")))
1065 (defun texinfo-update-the-node ()
1066 "Update one node. Point must be at the beginning of node line.
1067 Leave point at the end of the node line."
1068 (texinfo-check-for-node-name)
1069 (texinfo-delete-existing-pointers)
1070 (message "Updating node: %s ... " (texinfo-copy-node-name))
1074 ((case-fold-search t
)
1075 (level (texinfo-hierarchic-level))
1076 (beginning (texinfo-update-menu-region-beginning level
))
1077 (end (texinfo-update-menu-region-end level
)))
1078 (if (string-equal level
"top")
1079 (texinfo-top-pointer-case)
1081 (texinfo-insert-pointer beginning end level
'next
)
1082 (texinfo-insert-pointer beginning end level
'previous
)
1083 (texinfo-insert-pointer beginning end level
'up
)
1084 (texinfo-clean-up-node-line)))))
1086 (defun texinfo-top-pointer-case ()
1087 "Insert pointers in the Top node. This is a special case.
1089 The `Next' pointer is a pointer to a chapter or section at a lower
1090 hierarchical level in the file. The `Previous' and `Up' pointers are
1091 to `(dir)'. Point must be at the beginning of the node line, and is
1092 left at the end of the node line."
1094 (texinfo-clean-up-node-line)
1097 ;; There may be an @chapter or other such command between
1098 ;; the top node line and the next node line, as a title
1099 ;; for an `ifinfo' section. This @chapter command must
1100 ;; must be skipped. So the procedure is to search for
1101 ;; the next `@node' line, and then copy its name.
1102 (if (re-search-forward "^@node" nil t
)
1105 (texinfo-copy-node-name))
1109 (defun texinfo-check-for-node-name ()
1110 "Determine whether the node has a node name. Prompt for one if not.
1111 Point must be at beginning of node line. Does not move point."
1113 (forward-word 1) ; skip over node command
1114 (skip-chars-forward " \t") ; and over spaces
1115 (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what info looks for
1116 ; alternatively, use "[a-zA-Z]+"
1117 (let ((node-name (read-from-minibuffer "Node name: ")))
1118 (insert " " node-name
)))))
1120 (defun texinfo-delete-existing-pointers ()
1121 "Delete `Next', `Previous', and `Up' pointers.
1122 Starts from the current position of the cursor, and searches forward
1123 on the line for a comma and if one is found, deletes the rest of the
1124 line, including the comma. Leaves point at beginning of line."
1125 (if (search-forward "," (save-excursion (end-of-line) (point)) t
)
1127 (goto-char (1- (point)))
1129 (beginning-of-line))
1131 (defun texinfo-find-pointer (beginning end level direction
)
1132 "Move point to section associated with next, previous, or up pointer.
1133 Return type of pointer (either 'normal or 'no-pointer).
1135 The first and second arguments bound the search for a pointer to the
1136 beginning and end, respectively, of the enclosing higher level
1137 section. The third argument is a string specifying the general kind
1138 of section such as \"chapter\ or \"section\". When looking for the
1139 `Next' pointer, the section found will be at the same hierarchical
1140 level in the Texinfo file; when looking for the `Previous' pointer,
1141 the section found will be at the same or higher hierarchical level in
1142 the Texinfo file; when looking for the `Up' pointer, the section found
1143 will be at some level higher in the Texinfo file. The fourth argument
1144 \(one of 'next, 'previous, or 'up\) specifies whether to find the
1145 `Next', `Previous', or `Up' pointer."
1147 (cond ((eq direction
'next
)
1148 (forward-line 3) ; skip over current node
1149 (if (re-search-forward
1151 (cdr (assoc level texinfo-update-menu-same-level-regexps
)))
1156 ((eq direction
'previous
)
1157 (if (re-search-backward
1161 (cdr (assoc level texinfo-update-menu-same-level-regexps
)))
1164 (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1171 (if (re-search-backward
1172 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1174 (goto-char beginning
)
1181 (error "texinfo-find-pointer: lack proper arguments"))))
1183 (defun texinfo-pointer-name (kind)
1184 "Return the node name preceding the section command.
1185 The argument is the kind of section, either normal or no-pointer."
1187 (cond ((eq kind
'normal
)
1188 (end-of-line) ; this handles prev node top case
1189 (re-search-backward ; when point is already
1190 "^@node" ; at the beginning of @node line
1191 (save-excursion (forward-line -
3))
1193 (setq name
(texinfo-copy-node-name)))
1194 ((eq kind
'no-pointer
)
1195 (setq name
" "))) ; put a blank in the pointer slot
1198 (defun texinfo-insert-pointer (beginning end level direction
)
1199 "Insert the `Next', `Previous' or `Up' node name at point.
1202 The first and second arguments bound the search for a pointer to the
1203 beginning and end, respectively, of the enclosing higher level
1204 section. The third argument is the hierarchical level of the Texinfo
1205 file, a string such as \"section\". The fourth argument is direction
1206 towards which the pointer is directed, one of `next, `previous, or
1213 (texinfo-pointer-name
1214 (texinfo-find-pointer beginning end level direction
)))))
1216 (defun texinfo-clean-up-node-line ()
1217 "Remove extra commas, if any, at end of node line."
1219 (skip-chars-backward ", ")
1220 (delete-region (point) (save-excursion (end-of-line) (point))))
1223 ;;;; Updating nodes sequentially
1224 ; These sequential update functions insert `Next' or `Previous'
1225 ; pointers that point to the following or preceding nodes even if they
1226 ; are at higher or lower hierarchical levels. This means that if a
1227 ; section contains one or more subsections, the section's `Next'
1228 ; pointer will point to the subsection and not the following section.
1229 ; (The subsection to which `Next' points will most likely be the first
1230 ; item on the section's menu.)
1232 (defun texinfo-sequential-node-update (&optional region-p
)
1233 "Update one node (or many) in a Texinfo file with sequential pointers.
1235 This function causes the `Next' or `Previous' pointer to point to the
1236 immediately preceding or following node, even if it is at a higher or
1237 lower hierarchical level in the document. Continually pressing `n' or
1238 `p' takes you straight through the file.
1240 Without any prefix argument, update the node in which point is located.
1241 Non-nil argument (prefix, if interactive) means update the nodes in the
1244 This command makes it awkward to navigate among sections and
1245 subsections; it should be used only for those documents that are meant
1246 to be read like a novel rather than a reference, and for which the
1247 Info `g*' command is inadequate."
1251 (let ((auto-fill-hook nil
)) ; update a single node
1252 (if (not (re-search-backward "^@node" (point-min) t
))
1253 (error "Node line not found before this position."))
1254 (texinfo-sequentially-update-the-node)
1256 "Done...sequentially updated the node . You may save the buffer."))
1258 (let ((auto-fill-hook nil
)
1259 (beginning (region-beginning))
1261 (if (= end beginning
)
1262 (error "Please mark a region!"))
1264 (narrow-to-region beginning end
)
1265 (goto-char beginning
)
1267 (while (re-search-forward "^@node" (point-max) t
)
1269 (texinfo-sequentially-update-the-node))
1271 "Done...updated the nodes in sequence. You may save the buffer.")))))
1273 (defun texinfo-sequentially-update-the-node ()
1274 "Update one node such that the pointers are sequential.
1275 A `Next' or `Previous' pointer points to any preceding or following node,
1276 regardless of its hierarchical level."
1278 (texinfo-check-for-node-name)
1279 (texinfo-delete-existing-pointers)
1281 "Sequentially updating node: %s ... " (texinfo-copy-node-name))
1285 ((case-fold-search t
)
1286 (level (texinfo-hierarchic-level)))
1287 (if (string-equal level
"top")
1288 (texinfo-top-pointer-case)
1290 (texinfo-sequentially-insert-pointer level
'next
)
1291 (texinfo-sequentially-insert-pointer level
'previous
)
1292 (texinfo-sequentially-insert-pointer level
'up
)
1293 (texinfo-clean-up-node-line)))))
1295 (defun texinfo-sequentially-find-pointer (level direction
)
1296 "Find next or previous pointer sequentially in Texinfo file, or up pointer.
1297 Move point to section associated with the pointer. Find point even if
1298 it is in a different section.
1300 Return type of pointer (either 'normal or 'no-pointer).
1302 The first argument is a string specifying the general kind of section
1303 such as \"chapter\ or \"section\". The section found will be at the
1304 same hierarchical level in the Texinfo file, or, in the case of the up
1305 pointer, some level higher. The second argument (one of 'next,
1306 'previous, or 'up) specifies whether to find the `Next', `Previous',
1309 (cond ((eq direction
'next
)
1310 (forward-line 3) ; skip over current node
1311 (if (re-search-forward
1312 texinfo-section-types-regexp
1317 ((eq direction
'previous
)
1318 (if (re-search-backward
1319 texinfo-section-types-regexp
1325 (if (re-search-backward
1326 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1332 (error "texinfo-sequential-find-pointer: lack proper arguments"))))
1334 (defun texinfo-sequentially-insert-pointer (level direction
)
1335 "Insert the `Next', `Previous' or `Up' node name at point.
1338 The first argument is the hierarchical level of the Texinfo file, a
1339 string such as \"section\". The second argument is direction, one of
1340 `next, `previous, or 'up."
1346 (texinfo-pointer-name
1347 (texinfo-sequentially-find-pointer level direction
)))))
1350 ;;;; Inserting `@node' lines
1351 ; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
1352 ; before the `@chapter', `@section', and such like lines of a region
1353 ; in a Texinfo file.
1355 (defun texinfo-insert-node-lines (&optional title-p
)
1356 "Insert missing `@node' lines in region of Texinfo file.
1357 Non-nil argument (prefix, if interactive) means also to insert the
1358 section titles as node names; and also to insert the section titles as
1359 node names in pre-existing @node lines that lack names."
1362 (let ((begin-region (region-beginning))
1363 (end-region (region-end)))
1364 (goto-char begin-region
)
1365 (while (< (point) end-region
)
1366 (re-search-forward texinfo-section-types-regexp nil
'end
)
1367 ;; copy title, since most often, we will need it
1372 (skip-chars-forward " \t")
1375 (save-excursion (end-of-line) (point))))))
1376 ;; insert a node if necessary
1377 (if (re-search-backward
1383 ;; @node present, and point at beginning of that line
1385 ;; else @node missing, insert one
1387 (beginning-of-line) ; beginning of `@section' line
1389 (backward-char 1))) ; leave point just after `@node'
1390 ;; insert a title if warranted
1393 (skip-chars-forward " \t")
1394 ;; use regexp based on what info looks for
1395 ;; (alternatively, use "[a-zA-Z]+")
1396 (if (not (looking-at "[^,\t\n ]+"))
1401 (message "Inserted title %s ... " title
)))))
1402 ;; in any case, go forward beyond current section title
1403 (forward-line 3)))))
1406 "Done inserting node lines and titles. You may save the buffer.")
1407 (message "Done inserting node lines. You may save the buffer.")))
1410 ;;;; Update and create menus for multi-file Texinfo sources
1412 ;; 1. M-x texinfo-multiple-files-update
1414 ;; Read the include file list of an outer Texinfo file and
1415 ;; update all highest level nodes in the files listed and insert a
1416 ;; main menu in the outer file after its top node.
1418 ;; 2. C-u M-x texinfo-multiple-files-update
1420 ;; Same as 1, but insert a master menu. (Saves reupdating lower
1421 ;; level menus and nodes.) This command simply reads every menu,
1422 ;; so if the menus are wrong, the master menu will be wrong.
1423 ;; Similarly, if the lower level node pointers are wrong, they
1426 ;; 3. C-u 2 M-x texinfo-multiple-files-update
1428 ;; Read the include file list of an outer Texinfo file and
1429 ;; update all nodes and menus in the files listed and insert a
1430 ;; master menu in the outer file after its top node.
1432 ;;; Note: these functions:
1434 ;;; * Do not save or delete any buffers. You may fill up your memory.
1435 ;;; * Do not handle any pre-existing nodes in outer file.
1436 ;;; Hence, you may need a file for indices.
1439 ;;;; Auxiliary functions for multiple file updating
1441 (defun texinfo-multi-file-included-list (outer-file)
1442 "Return a list of the included files in OUTER-FILE."
1443 (let ((included-file-list (list outer-file
))
1446 (switch-to-buffer (find-file-noselect outer-file
))
1448 (goto-char (point-min))
1449 (while (re-search-forward "^@include" nil t
)
1450 (skip-chars-forward " \t")
1451 (setq start
(point))
1453 (skip-chars-backward " \t")
1454 (setq included-file-list
1455 (cons (buffer-substring start
(point))
1456 included-file-list
)))
1457 (nreverse included-file-list
))))
1459 (defun texinfo-copy-next-section-title ()
1460 "Return the name of the immediately following section as a string.
1462 Start with point at the beginning of the node line. Leave point at the
1463 same place. If there is no title, returns an empty string."
1467 (let ((section-end (or
1469 (re-search-forward "\\(^@node\\)" nil t
)
1470 (match-beginning 0))
1472 (if (re-search-forward texinfo-section-types-regexp section-end t
)
1476 (progn (forward-word 1) ; skip over section type
1477 (skip-chars-forward " \t") ; and over spaces
1479 (progn (end-of-line) (point)))))
1483 (defun texinfo-multi-file-update (files &optional update-everything
)
1484 "Update first node pointers in each file in FILES.
1485 Return a list of the node names and the title immediate following them.
1487 The first file in the list is an outer file; the remaining are
1488 files included in the outer file with `@include' commands.
1490 If optional arg UPDATE-EVERYTHING non-nil, update every menu and
1491 pointer in each of the included files.
1493 Also update the `Top' level node pointers of the outer file.
1497 * the first file in the FILES list must be the outer file,
1498 * each of the included files must contain exactly one highest
1499 hierarchical level node,
1500 * this node must be the first node in the included file,
1501 * each highest hierarchical level node must be of the same type.
1503 Thus, normally, each included file contains one, and only one,
1506 The menu-list has the form:
1508 \(\(\"node-name1\" . \"title1\"\)
1509 \(\"node-name2\" . \"title2\"\) ... \)
1511 However, there does not need to be a title field."
1515 ;; Find the name of the first node of the first included file.
1516 (switch-to-buffer (find-file-noselect (car (cdr files
))))
1518 (goto-char (point-min))
1519 (if (not (re-search-forward "^@node" nil t
))
1520 (error "No `@node' line found in %s !" (buffer-name)))
1522 (texinfo-check-for-node-name)
1523 (setq next-node-name
(texinfo-copy-node-name))
1528 (texinfo-copy-next-section-title))
1532 (switch-to-buffer (find-file-noselect (car files
)))
1533 (goto-char (point-min))
1534 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
1535 (error "This buffer needs a Top node!"))
1537 (texinfo-delete-existing-pointers)
1539 (insert ", " next-node-name
", (dir), (dir)")
1541 (setq previous-node-name
"Top")
1542 (setq files
(cdr files
))
1546 (if (not (cdr files
))
1548 (setq next-node-name
"")
1550 ;; find the name of the first node in the next file.
1551 (switch-to-buffer (find-file-noselect (car (cdr files
))))
1553 (goto-char (point-min))
1554 (if (not (re-search-forward "^@node" nil t
))
1555 (error "No `@node' line found in %s !" (buffer-name)))
1557 (texinfo-check-for-node-name)
1558 (setq next-node-name
(texinfo-copy-node-name))
1562 (texinfo-copy-next-section-title))
1565 ;; Go to node to be updated.
1566 (switch-to-buffer (find-file-noselect (car files
)))
1567 (goto-char (point-min))
1568 (if (not (re-search-forward "^@node" nil t
))
1569 (error "No `@node' line found in %s !" (buffer-name)))
1571 (texinfo-delete-existing-pointers)
1573 (insert ", " next-node-name
", " previous-node-name
", " up-node-name
)
1576 (setq previous-node-name
(texinfo-copy-node-name))
1578 ;; Update other menus and nodes if requested.
1579 (if update-everything
(texinfo-all-menus-update t
))
1581 (setq files
(cdr files
)))
1582 (nreverse menu-list
)))
1584 (defun texinfo-multi-files-insert-main-menu (menu-list)
1585 "Insert formatted main menu at point.
1586 Indents the first line of the description, if any, to the value of
1587 texinfo-column-for-description."
1591 (if (cdr (car menu-list
)) ; menu-list has description entry
1594 (format "* %s::" (car (car menu-list
)))) ; node-name entry
1595 (indent-to texinfo-column-for-description
2)
1597 (format "%s\n" (cdr (car menu-list
))))) ; description entry
1598 ;; else menu-list lacks description entry
1600 (format "* %s::\n" (car (car menu-list
))))) ; node-name entry
1601 (setq menu-list
(cdr menu-list
)))
1602 (insert "@end menu"))
1605 (defun texinfo-multi-file-master-menu-list (files-list)
1606 "Return master menu list from files in FILES-LIST.
1607 Menu entries in each file collected using `texinfo-master-menu-list'.
1609 The first file in FILES-LIST must be the outer file; the others must
1610 be the files included within it. A main menu must already exist."
1612 (let (master-menu-list)
1614 (switch-to-buffer (find-file-noselect (car files-list
)))
1615 (message "Working on: %s " (current-buffer))
1616 (goto-char (point-min))
1617 (setq master-menu-list
1618 (append master-menu-list
(texinfo-master-menu-list)))
1619 (setq files-list
(cdr files-list
)))
1623 ;;;; The multiple-file update function
1625 (defun texinfo-multiple-files-update
1626 (outer-file &optional update-everything make-master-menu
)
1627 "Update first node pointers in each file included in OUTER-FILE;
1628 create or update main menu in the outer file that refers to such nodes.
1629 This does not create or update menus or pointers within the included files.
1631 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
1632 insert a master menu in OUTER-FILE. This does not create or update
1633 menus or pointers within the included files.
1635 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
1636 interactive), update all the menus and all the `Next', `Previous', and
1637 `Up' pointers of all the files included in OUTER-FILE before inserting
1638 a master menu in OUTER-FILE.
1640 The command also updates the `Top' level node pointers of OUTER-FILE.
1644 * this command does NOT save any files--you must save the
1645 outer file and any modified, included files.
1647 * except for the `Top' node, this command does NOT handle any
1648 pre-existing nodes in the outer file; hence, indices must be
1649 enclosed in an included file.
1653 * each of the included files must contain exactly one highest
1654 hierarchical level node,
1655 * this highest node must be the first node in the included file,
1656 * each highest hierarchical level node must be of the same type.
1658 Thus, normally, each included file contains one, and only one,
1661 (interactive "fName of outer `include' file: ")
1663 (cond (current-prefix-arg
1664 (setq make-master-menu
(listp current-prefix-arg
))
1665 (setq update-everything
(numberp current-prefix-arg
))))
1667 (let* ((included-file-list (texinfo-multi-file-included-list outer-file
))
1668 (files included-file-list
)
1672 (up-node-name "Top"))
1674 ;;; Update the pointers
1675 ;;; and collect the names of the nodes and titles
1676 (setq main-menu-list
(texinfo-multi-file-update files update-everything
))
1678 ;;; Insert main menu
1681 (switch-to-buffer (find-file-noselect (car included-file-list
)))
1682 (if (texinfo-old-menu-p
1685 (re-search-forward "^@include")
1689 ;; If found, leave point after word `menu' on the `@menu' line.
1691 (texinfo-incorporate-descriptions main-menu-list
)
1692 ;; Delete existing menu.
1696 (save-excursion (re-search-forward "^@end menu") (point)))
1698 (texinfo-multi-files-insert-main-menu main-menu-list
))
1700 ;; Else no current menu; insert it before `@include'
1701 (texinfo-multi-files-insert-main-menu main-menu-list
))
1703 ;;; Insert master menu
1705 (if make-master-menu
1707 ;; First, removing detailed part of any pre-existing master menu
1708 (goto-char (point-min))
1709 (if (re-search-forward texinfo-master-menu-header nil t
)
1710 ;; Remove detailed master menu listing
1712 (goto-char (match-beginning 0))
1713 (let ((end-of-detailed-menu-descriptions
1714 (save-excursion ; beginning of end menu line
1715 (goto-char (texinfo-menu-end))
1716 (beginning-of-line) (forward-char -
1)
1718 (delete-region (point) end-of-detailed-menu-descriptions
))))
1720 ;; Create a master menu and insert it
1721 (texinfo-insert-master-menu-list
1722 (texinfo-multi-file-master-menu-list
1723 included-file-list
)))))
1724 (message "Multiple files updated."))
1726 ;;;;;;;;;;;;;;;; end texnfo-upd.el ;;;;;;;;;;;;;;;;