1 ;;; texnfo-upd.el --- a utility for updating nodes and menus in Texinfo files.
3 ;; Author: Bob Chassell <bob@gnu.ai.mit.edu>
5 ;; Last-Modified: 14 Dec 1990
7 ;;;; Copyright 1989, 1990, 1992 Free Software Foundation
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; 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.
151 ;;;; Menu Making Functions
153 (defun texinfo-make-menu (&optional region-p
)
154 "Without any prefix argument, make or update a menu.
155 Make the menu for the section enclosing the node found following point.
157 Non-nil argument (prefix, if interactive) means make or update menus
158 for nodes within or part of the marked region.
160 Whenever a menu exists, and is being updated, the descriptions that
161 are associated with node names in the pre-existing menu are
162 incorporated into the new menu. Otherwise, the nodes' section titles
163 are inserted as descriptions."
167 (let ((level (texinfo-hierarchic-level)))
168 (texinfo-make-one-menu level
)
169 (message "Done...updated the menu. You may save the buffer."))
171 (message "Making or updating menus... ")
172 (let ((beginning (region-beginning))
173 (region-end (region-end))
174 (level (progn ; find section type following point
175 (goto-char (region-beginning))
176 (texinfo-hierarchic-level))))
177 (if (= region-end beginning
)
178 (error "Please mark a region!"))
183 (while (texinfo-find-lower-level-node level region-end
)
184 (setq level
(texinfo-hierarchic-level)) ; new, lower level
185 (texinfo-make-one-menu level
))
187 (while (and (< (point) region-end
)
188 (texinfo-find-higher-level-node level region-end
))
189 (setq level
(texinfo-hierarchic-level))
190 (while (texinfo-find-lower-level-node level region-end
)
191 (setq level
(texinfo-hierarchic-level)) ; new, lower level
192 (texinfo-make-one-menu level
))))))
193 (message "Done...updated menus. You may save the buffer.")))
195 (defun texinfo-make-one-menu (level)
196 "Make a menu of all the appropriate nodes in this section.
197 `Appropriate nodes' are those associated with sections that are
198 at the level specified by LEVEL. Point is left at the end of menu."
200 ((case-fold-search t
)
203 (goto-char (texinfo-update-menu-region-beginning level
))
206 (end (texinfo-update-menu-region-end level
))
207 (first (texinfo-menu-first-node beginning end
))
209 (goto-char beginning
)
210 (texinfo-copy-node-name)))
211 (new-menu-list (texinfo-make-menu-list beginning end level
)))
212 (if (texinfo-old-menu-p beginning first
)
214 (texinfo-incorporate-descriptions new-menu-list
)
215 (texinfo-delete-old-menu beginning first
)))
216 (texinfo-insert-menu new-menu-list node-name
)))
218 (defun texinfo-all-menus-update (&optional update-all-nodes-p
)
219 "Update every regular menu in a Texinfo file.
220 You must remove the detailed part of a pre-existing master menu before
221 running this command, lest it be partly duplicated.
223 If called with a non-nil argument, this function first updates all the
224 nodes in the buffer before updating the menus."
228 (message "Checking for a master menu... ")
230 (if (re-search-forward texinfo-master-menu-header nil t
)
232 "Please remove existing master menu, lest it be partly duplicated!")))
234 (if update-all-nodes-p
236 (message "First updating all nodes... ")
239 (texinfo-update-node t
)))
241 (message "Updating all menus... ")
243 (texinfo-make-menu t
)
244 (message "Done...updated all the menus. You may save the buffer.")))
246 (defun texinfo-find-lower-level-node (level region-end
)
247 "Search forward from point for node at any level lower than LEVEL.
248 Search is limited to the end of the marked region, REGION-END,
249 and to the end of the menu region for the level.
251 Return t if the node is found, else nil. Leave point at the beginning
252 of the node if one is found; else do not move point."
254 (if (and (< (point) region-end
)
257 "\\(^@node\\).*\n" ; match node line
258 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
260 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
261 (eval (cdr (assoc level texinfo-update-menu-lower-regexps
))))
262 ;; the next higher level node marks the end of this
263 ;; section, and no lower level node will be found beyond
264 ;; this position even if region-end is farther off
265 (texinfo-update-menu-region-end level
)
267 (goto-char (match-beginning 1))))
269 (defun texinfo-find-higher-level-node (level region-end
)
270 "Search forward from point for node at any higher level than argument LEVEL.
271 Search is limited to the end of the marked region, REGION-END.
273 Return t if the node is found, else nil. Leave point at the beginning
274 of the node if one is found; else do not move point."
276 (if (and (< (point) region-end
)
279 "\\(^@node\\).*\n" ; match node line
280 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
282 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
283 (eval ; (won't ever find a `top' node)
284 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
287 (goto-char (match-beginning 1))))
290 ;;;; Making the list of new menu entries
292 (defun texinfo-make-menu-list (beginning end level
)
293 "Make a list of node names and their descriptions.
294 Point is left at the end of the menu region, but the menu is not inserted.
296 First argument is position from which to start making menu list;
297 second argument is end of region in which to try to locate entries;
298 third argument is the level of the nodes that are the entries.
300 Node names and descriptions are dotted pairs of strings. Each pair is
301 an element of the list. If the description does not exist, the
302 element consists only of the node name."
303 (goto-char beginning
)
305 (while (texinfo-menu-locate-entry-p level end
)
308 (texinfo-copy-node-name)
309 (texinfo-copy-section-title))
311 (reverse new-menu-list
)))
313 (defun texinfo-menu-locate-entry-p (level search-end
)
314 "Find a node that will be part of menu for this section.
315 First argument is a string such as \"section\" specifying the general
316 hierarchical level of the menu; second argument is a postion
317 specifying the end of the search.
319 The function returns t if the node is found, else nil. It searches
320 forward from point, and leaves point at the beginning of the node.
322 The function finds entries of the same type. Thus `subsections' and
323 `unnumberedsubsecs' will appear in the same menu."
324 (if (re-search-forward
326 "\\(^@node\\).*\n" ; match node line
327 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
329 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
331 (cdr (assoc level texinfo-update-menu-same-level-regexps
))))
334 (goto-char (match-beginning 1))))
336 (defun texinfo-copy-node-name ()
337 "Return the node name as a string.
339 Start with point at the beginning of the node line; copy the text
340 after the node command up to the first comma on the line, if any, and
341 return the text as a string. Leaves point at the beginning of the
342 line. If there is no node name, returns an empty string."
346 (progn (forward-word 1) ; skip over node command
347 (skip-chars-forward " \t") ; and over spaces
351 (save-excursion (end-of-line) (point)) t
) ; bound search
353 (end-of-line) (point)))))
355 (defun texinfo-copy-section-title ()
356 "Return the title of the section as a string.
357 The title is used as a description line in the menu when one does not
360 Move point to the beginning of the appropriate section line by going
361 to the start of the text matched by last regexp searched for, which
362 must have been done by `texinfo-menu-locate-entry-p'."
364 ;; could use the same re-search as in `texinfo-menu-locate-entry-p'
365 ;; instead of using `match-beginning'; such a variation would be
366 ;; more general, but would waste information already collected
368 (goto-char (match-beginning 7)) ; match section name
371 (progn (forward-word 1) ; skip over section type
372 (skip-chars-forward " \t") ; and over spaces
374 (progn (end-of-line) (point))))
377 ;;;; Handling the old menu
379 (defun texinfo-old-menu-p (beginning first
)
380 "Move point to the beginning of the menu for this section, if any.
381 Otherwise move point to the end of the first node of this section.
382 Return t if a menu is found, nil otherwise.
384 First argument is the position of the beginning of the section in which
385 the menu will be located; second argument is the position of the first
386 node within the section.
388 If no menu is found, the function inserts two newlines just before the
389 end of the section, and leaves point there where a menu ought to be."
390 (goto-char beginning
)
391 (if (not (re-search-forward "^@menu" first
'goto-end
))
392 (progn (insert "\n\n") (forward-line -
2) nil
)
395 (defun texinfo-incorporate-descriptions (new-menu-list)
396 "Copy the old menu line descriptions that exist to the new menu.
398 Point must be at beginning of old menu.
400 If the node-name of the new menu entry cannot be found in the old
401 menu, use the new section title for the description, but if the
402 node-name of the new menu is found in the old menu, replace the
403 section title with the old description, whatever it may be.
405 For this function, the new menu is a list made up of lists of dotted
406 pairs in which the first element of the pair is the node name and the
407 second element the description. The new menu is changed destructively.
408 The old menu is the menu as it appears in the texinfo file."
410 (let ((new-menu-list-pointer new-menu-list
)
411 (end-of-menu (texinfo-menu-end)))
413 (save-excursion ; keep point at beginning of menu
415 (concat "\* " ; so only menu entries are found
416 (car (car new-menu-list
))
417 ":") ; so only complete entries are found
420 (setcdr (car new-menu-list
)
421 (texinfo-menu-copy-old-description end-of-menu
))))
422 (setq new-menu-list
(cdr new-menu-list
)))
423 (setq new-menu-list new-menu-list-pointer
)))
425 (defun texinfo-menu-copy-old-description (end-of-menu)
426 "Return description field of old menu line as string.
427 Point must be located just after the node name. Point left before description.
428 Single argument, END-OF-MENU, is position limiting search."
429 (skip-chars-forward "[:.,\t\n ]+")
430 ;; don't copy a carriage return at line beginning with asterisk!
431 ;; do copy a description that begins with an `@'!
432 (if (and (looking-at "\\(\\w+\\|@\\)")
433 (not (looking-at "\\(^\\* \\|^@end menu\\)")))
437 (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t
)
439 (end-of-line) ; go to end of last description line
443 (defun texinfo-menu-end ()
444 "Return position of end of menu. Does not change location of point.
445 Signal an error if not end of menu."
447 (if (re-search-forward "^@end menu" nil t
)
449 (error "Menu does not have an end."))))
451 (defun texinfo-delete-old-menu (beginning first
)
452 "Delete the old menu. Point must be in or after menu.
453 First argument is position of the beginning of the section in which
454 the menu will be located; second argument is the position of the first
455 node within the section."
456 ;; No third arg to search, so error if search fails.
457 (re-search-backward "^@menu" beginning
)
458 (delete-region (point)
460 (re-search-forward "^@end menu" first
)
464 ;;;; Inserting new menu
466 ;; try 32, but perhaps 24 is better
467 (defvar texinfo-column-for-description
32
468 "*Column at which descriptions start in a Texinfo menu.")
470 (defun texinfo-insert-menu (menu-list node-name
)
471 "Insert formatted menu at point.
472 Indents the first line of the description, if any, to the value of
473 texinfo-column-for-description.
477 \(\(\"node-name1\" . \"description\"\)
478 \(\"node-name\" . \"description\"\) ... \)
480 However, there does not need to be a description field."
484 (if (cdr (car menu-list
)) ; menu-list has description entry
487 (format "* %s::" (car (car menu-list
)))) ; node-name entry
488 (indent-to texinfo-column-for-description
2)
490 (format "%s\n" (cdr (car menu-list
))))) ; description entry
491 ;; else menu-list lacks description entry
493 (format "* %s::\n" (car (car menu-list
))))) ; node-name entry
494 (setq menu-list
(cdr menu-list
)))
497 "Updated \"%s\" level menu following node: %s ... "
501 ;;;; Handling description indentation
503 ; Since the make-menu functions indent descriptions, these functions
504 ; are useful primarily for indenting a single menu specially.
506 (defun texinfo-indent-menu-description (column &optional region-p
)
507 "Indent every description in menu following point to COLUMN.
508 Non-nil argument (prefix, if interactive) means indent every
509 description in every menu in the region. Does not indent second and
510 subsequent lines of a multi-line description."
513 "nIndent menu descriptions to (column number): \nP")
519 (re-search-forward "^@menu")
520 (texinfo-menu-indent-description column
)
522 "Indented descriptions in menu. You may save the buffer."))
524 (message "Indenting every menu description in region... ")
525 (goto-char (region-beginning))
526 (while (and (< (point) (region-end))
527 (texinfo-locate-menu-p))
529 (texinfo-menu-indent-description column
))
530 (message "Indenting done. You may save the buffer.")))))
532 (defun texinfo-menu-indent-description (to-column-number)
533 "Indent the Texinfo file menu description to TO-COLUMN-NUMBER.
534 Start with point just after the word `menu' in the `@menu' line and
535 leave point on the line before the `@end menu' line. Does not indent
536 second and subsequent lines of a multi-line description."
537 (let* ((beginning-of-next-line (point)))
538 (while (< beginning-of-next-line
539 (save-excursion ; beginning of end menu line
540 (goto-char (texinfo-menu-end))
543 (if (search-forward "::" (texinfo-menu-end) t
)
545 (let ((beginning-white-space (point)))
546 (skip-chars-forward " \t") ; skip over spaces
547 (if (looking-at "\\(@\\|\\w\\)+") ; if there is text
549 ;; remove pre-existing indentation
550 (delete-region beginning-white-space
(point))
551 (indent-to-column to-column-number
))))))
552 ;; position point at beginning of next line
554 (setq beginning-of-next-line
(point)))))
557 ;;;; Making the master menu
559 (defun texinfo-master-menu (update-all-nodes-menus-p)
560 "Make a master menu for a whole Texinfo file.
561 Non-nil argument (prefix, if interactive) means first update all
562 existing nodes and menus. Remove pre-existing master menu, if there is one.
564 This function creates a master menu that follows the top node. The
565 master menu includes every entry from all the other menus. It
566 replaces any existing ordinary menu that follows the top node.
568 If called with a non-nil argument, this function first updates all the
569 menus in the buffer (incorporating descriptions from pre-existing
570 menus) before it constructs the master menu.
572 The function removes the detailed part of an already existing master
573 menu. This action depends on the pre-exisitng master menu using the
574 standard `texinfo-master-menu-header'.
576 The master menu has the following format, which is adapted from the
577 recommendation in the Texinfo Manual:
579 * The first part contains the major nodes in the Texinfo file: the
580 nodes for the chapters, chapter-like sections, and the major
581 appendices. This includes the indices, so long as they are in
582 chapter-like sections, such as unnumbered sections.
584 * The second and subsequent parts contain a listing of the other,
585 lower level menus, in order. This way, an inquirer can go
586 directly to a particular node if he or she is searching for
587 specific information.
589 Each of the menus in the detailed node listing is introduced by the
590 title of the section containing the menu."
594 (goto-char (point-min))
596 ;; Move point to location after `top'.
597 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
598 (error "This buffer needs a Top node!"))
601 (save-excursion (re-search-forward "^@node") (point))))
602 (if (re-search-forward texinfo-master-menu-header first-chapter t
)
603 ;; Remove detailed master menu listing
605 (goto-char (match-beginning 0))
606 (let ((end-of-detailed-menu-descriptions
607 (save-excursion ; beginning of end menu line
608 (goto-char (texinfo-menu-end))
609 (beginning-of-line) (forward-char -
1)
611 (delete-region (point) end-of-detailed-menu-descriptions
)))))
613 (if update-all-nodes-menus-p
615 (message "Making a master menu...first updating all nodes... ")
618 (texinfo-update-node t
)
620 (message "Updating all menus... ")
623 (texinfo-make-menu t
)))
625 (message "Now making the master menu... ")
627 (goto-char (point-min))
628 (texinfo-insert-master-menu-list
629 (texinfo-master-menu-list))
631 ;; Remove extra newlines that texinfo-insert-master-menu-list
632 ;; may have inserted.
635 (goto-char (point-min))
637 (re-search-forward texinfo-master-menu-header
)
638 (goto-char (match-beginning 0))
642 (re-search-backward "^@menu")
646 (re-search-forward "^@end menu")
648 (delete-blank-lines))
650 (message "Done...completed making master menu. You may save the buffer."))
652 (defun texinfo-master-menu-list ()
653 "Return a list of menu entries and header lines for the master menu.
655 Start with the menu for chapters and indices and then find each
656 following menu and the title of the node preceding that menu.
658 The master menu list has this form:
660 \(\(\(... \"entry-1-2\" \"entry-1\"\) \"title-1\"\)
661 \(\(... \"entry-2-2\" \"entry-2-1\"\) \"title-2\"\)
664 However, there does not need to be a title field."
666 (let (master-menu-list)
667 (while (texinfo-locate-menu-p)
668 (setq master-menu-list
671 (texinfo-copy-menu-title))
673 (reverse master-menu-list
)))
675 (defun texinfo-insert-master-menu-list (master-menu-list)
676 "Format and insert the master menu in the current buffer."
677 (goto-char (point-min))
678 (re-search-forward "^@menu")
680 (delete-region (point) ; buffer must have ordinary top menu
682 (re-search-forward "^@end menu")
685 (save-excursion ; leave point at beginning of menu
686 ;; Handle top of menu
688 ;; Insert chapter menu entries
689 (setq this-very-menu-list
(reverse (car (car master-menu-list
))))
690 ;;; Tell user what is going on.
691 (message "Inserting chapter menu entry: %s ... " this-very-menu-list
)
692 (while this-very-menu-list
693 (insert "* " (car this-very-menu-list
) "\n")
694 (setq this-very-menu-list
(cdr this-very-menu-list
)))
696 (setq master-menu-list
(cdr master-menu-list
))
698 (insert texinfo-master-menu-header
)
700 ;; Now, insert all the other menus
702 ;; The menu master-menu-list has a form like this:
703 ;; ((("beta" "alpha") "title-A")
704 ;; (("delta" "gamma") "title-B"))
706 (while master-menu-list
709 "Inserting menu for %s .... " (car (cdr (car master-menu-list
))))
710 ;; insert title of menu section
711 (insert "\n" (car (cdr (car master-menu-list
))) "\n\n")
713 ;; insert each menu entry
714 (setq this-very-menu-list
(reverse (car (car master-menu-list
))))
715 (while this-very-menu-list
716 (insert "* " (car this-very-menu-list
) "\n")
717 (setq this-very-menu-list
(cdr this-very-menu-list
)))
719 (setq master-menu-list
(cdr master-menu-list
)))
722 (insert "@end menu\n\n")))
724 (defvar texinfo-master-menu-header
725 "\n --- The Detailed Node Listing ---\n"
726 "String inserted before lower level entries in Texinfo master menu.
727 It comes after the chapter-level menu entries.")
729 (defun texinfo-locate-menu-p ()
730 "Find the next menu in the texinfo file.
731 If found, leave point after word `menu' on the `@menu' line, and return t.
732 If a menu is not found, do not move point and return nil."
733 (re-search-forward "\\(^@menu\\)" nil t
))
735 (defun texinfo-copy-menu-title ()
736 "Return the title of the section preceding the menu as a string.
737 If such a title cannot be found, return an empty string. Do not move
740 (if (re-search-backward
742 "\\(^@node\\).*\n" ; match node line
743 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
745 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
748 (assoc (texinfo-hierarchic-level)
749 texinfo-update-menu-higher-regexps
))))
752 (texinfo-copy-section-title)
755 (defun texinfo-copy-menu ()
756 "Return the entries of an existing menu as a list.
757 Start with point just after the word `menu' in the `@menu' line
758 and leave point on the line before the `@end menu' line."
759 (let* (this-menu-list
760 (end-of-menu (texinfo-menu-end)) ; position of end of `@end menu'
761 (last-entry (save-excursion ; position of beginning of
763 (goto-char end-of-menu
)
764 (re-search-backward "^\* ") ; handle multi-line desc.
766 (while (< (point) last-entry
)
767 (if (re-search-forward "^\* " end-of-menu t
)
773 ;; copy multi-line descriptions
775 (re-search-forward "\\(^\* \\|^@e\\)" nil t
)
781 ;;;; Determining the hierarchical level in the texinfo file
783 (defun texinfo-specific-section-type ()
784 "Return the specific type of next section, as a string.
785 For example, \"unnumberedsubsec\". Return \"top\" for top node.
787 Searches forward for a section. Hence, point must be before the
788 section whose type will be found. Does not move point. Signal an
789 error if the node is not the top node and a section is not found."
792 ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
798 ((re-search-forward texinfo-section-types-regexp nil t
)
799 (buffer-substring (progn (beginning-of-line) ; copy its name
801 (progn (forward-word 1)
805 "texinfo-specific-section-type: Chapter or section not found.")))))
807 (defun texinfo-hierarchic-level ()
808 "Return the general hierarchal level of the next node in a texinfo file.
809 Thus, a subheading or appendixsubsec is of type subsection."
811 (texinfo-specific-section-type)
812 texinfo-section-to-generic-alist
)))
815 ;;;; Locating the major positions
817 (defun texinfo-update-menu-region-beginning (level)
818 "Locate beginning of higher level section this section is within.
819 Return position of the beginning of the node line; do not move point.
820 Thus, if this level is subsection, searches backwards for section node.
821 Only argument is a string of the general type of section."
824 ((or (string-equal "top" level
)
825 (string-equal "chapter" level
))
827 (goto-char (point-min))
828 (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
)
835 "\\(^@node\\).*\n" ; match node line
836 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
838 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
840 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
845 (defun texinfo-update-menu-region-end (level)
846 "Locate end of higher level section this section is within.
847 Return position; do not move point. Thus, if this level is a
848 subsection, find the node for the section this subsection is within.
849 If level is top or chapter, returns end of file. Only argument is a
850 string of the general type of section."
853 (if (re-search-forward
855 "\\(^@node\\).*\n" ; match node line
856 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
858 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
860 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
866 (defun texinfo-menu-first-node (beginning end
)
867 "Locate first node of the section the menu will be placed in.
868 Return position; do not move point.
869 The menu will be located just before this position.
871 First argument is the position of the beginning of the section in
872 which the menu will be located; second argument is the position of the
873 end of that region; it limits the search."
876 (goto-char beginning
)
878 (re-search-forward "^@node" end t
)
883 ;;;; Alists and regular expressions for defining hierarchical levels
885 (defvar texinfo-section-to-generic-alist
888 ("chapter" .
"chapter")
889 ("unnumbered" .
"chapter")
890 ("majorheading" .
"chapter")
891 ("chapheading" .
"chapter")
892 ("appendix" .
"chapter")
894 ("section" .
"section")
895 ("unnumberedsec" .
"section")
896 ("heading" .
"section")
897 ("appendixsec" .
"section")
899 ("subsection" .
"subsection")
900 ("unnumberedsubsec" .
"subsection")
901 ("subheading" .
"subsection")
902 ("appendixsubsec" .
"subsection")
904 ("subsubsection" .
"subsubsection")
905 ("unnumberedsubsubsec" .
"subsubsection")
906 ("subsubheading" .
"subsubsection")
907 ("appendixsubsubsec" .
"subsubsection"))
908 "*An alist of specific and corresponding generic Texinfo section types.
909 The keys are strings specifying specific types of section; the values
910 are strings of their corresponding general types.")
912 (defvar texinfo-section-types-regexp
913 "^@\\(chapter \\|sect\\|sub\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
914 "Regexp matching chapter, section, other headings (but not the top node).")
916 (defvar texinfo-chapter-level-regexp
917 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
918 "Regular expression matching just the Texinfo chapter level headings.")
920 (defvar texinfo-section-level-regexp
921 "section\\|unnumberedsec\\|heading \\|appendixsec"
922 "Regular expression matching just the Texinfo section level headings.")
924 (defvar texinfo-subsection-level-regexp
925 "subsection\\|unnumberedsubsec\\|subheading\\|appendixsubsec"
926 "Regular expression matching just the Texinfo subsection level headings.")
928 (defvar texinfo-subsubsection-level-regexp
929 "subsubsection\\|unnumberedsubsubsec\\|subsubheading\\|appendixsubsubsec"
930 "Regular expression matching just the Texinfo subsubsection level headings.")
932 (defvar texinfo-update-menu-same-level-regexps
933 '(("top" .
"top[ \t]+")
935 (concat "\\(^@\\)\\(" texinfo-chapter-level-regexp
"\\)[ \t]*"))
937 (concat "\\(^@\\)\\(" texinfo-section-level-regexp
"\\)[ \t]*"))
939 (concat "\\(^@\\)\\(" texinfo-subsection-level-regexp
"\\)[ \t]+"))
941 (concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp
"\\)[ \t]+")))
942 "*Regexps for searching for same level sections in a Texinfo file.
943 The keys are strings specifying the general hierarchical level in the
944 document; the values are regular expressions.")
946 (defvar texinfo-update-menu-higher-regexps
947 '(("top" .
"^@node [ \t]*DIR")
948 ("chapter" .
"^@node [ \t]*top[ \t]*\\(,\\|$\\)")
952 texinfo-chapter-level-regexp
957 texinfo-section-level-regexp
959 texinfo-chapter-level-regexp
964 texinfo-subsection-level-regexp
966 texinfo-section-level-regexp
968 texinfo-chapter-level-regexp
970 "*Regexps for searching for higher level sections in a Texinfo file.
971 The keys are strings specifying the general hierarchical level in the
972 document; the values are regular expressions.")
974 (defvar texinfo-update-menu-lower-regexps
978 texinfo-chapter-level-regexp
980 texinfo-section-level-regexp
982 texinfo-subsection-level-regexp
984 texinfo-subsubsection-level-regexp
989 texinfo-section-level-regexp
991 texinfo-subsection-level-regexp
993 texinfo-subsubsection-level-regexp
998 texinfo-subsection-level-regexp
1000 texinfo-subsubsection-level-regexp
1005 texinfo-subsubsection-level-regexp
1007 ("subsubsection" .
"nothing lower"))
1008 "*Regexps for searching for lower level sections in a Texinfo file.
1009 The keys are strings specifying the general hierarchical level in the
1010 document; the values are regular expressions.")
1013 ;;;; Updating a Node
1015 (defun texinfo-update-node (&optional region-p
)
1016 "Without any prefix argument, update the node in which point is located.
1017 Non-nil argument (prefix, if interactive) means update the nodes in the
1020 The functions for creating or updating nodes and menus, and their
1023 texinfo-update-node (&optional region-p) \\[texinfo-update-node]
1024 texinfo-every-node-update () \\[texinfo-every-node-update]
1025 texinfo-sequential-node-update (&optional region-p)
1027 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
1028 texinfo-all-menus-update () \\[texinfo-all-menus-update]
1029 texinfo-master-menu ()
1031 texinfo-indent-menu-description (column &optional region-p)
1033 The `texinfo-column-for-description' variable specifies the column to
1034 which menu descriptions are indented. Its default value is 24."
1038 (let ((auto-fill-function nil
)) ; update a single node
1039 (if (not (re-search-backward "^@node" (point-min) t
))
1040 (error "Node line not found before this position."))
1041 (texinfo-update-the-node)
1042 (message "Done...updated the node. You may save the buffer."))
1044 (let ((auto-fill-function nil
)
1045 (beginning (region-beginning))
1047 (if (= end beginning
)
1048 (error "Please mark a region!"))
1050 (narrow-to-region beginning end
)
1051 (goto-char beginning
)
1053 (while (re-search-forward "^@node" (point-max) t
)
1055 (texinfo-update-the-node))
1056 (message "Done...updated nodes in region. You may save the buffer.")))))
1058 (defun texinfo-every-node-update ()
1059 "Update every node in a Texinfo file."
1063 (texinfo-update-node t
)
1064 (message "Done...updated every node. You may save the buffer.")))
1066 (defun texinfo-update-the-node ()
1067 "Update one node. Point must be at the beginning of node line.
1068 Leave point at the end of the node line."
1069 (texinfo-check-for-node-name)
1070 (texinfo-delete-existing-pointers)
1071 (message "Updating node: %s ... " (texinfo-copy-node-name))
1075 ((case-fold-search t
)
1076 (level (texinfo-hierarchic-level))
1077 (beginning (texinfo-update-menu-region-beginning level
))
1078 (end (texinfo-update-menu-region-end level
)))
1079 (if (string-equal level
"top")
1080 (texinfo-top-pointer-case)
1082 (texinfo-insert-pointer beginning end level
'next
)
1083 (texinfo-insert-pointer beginning end level
'previous
)
1084 (texinfo-insert-pointer beginning end level
'up
)
1085 (texinfo-clean-up-node-line)))))
1087 (defun texinfo-top-pointer-case ()
1088 "Insert pointers in the Top node. This is a special case.
1090 The `Next' pointer is a pointer to a chapter or section at a lower
1091 hierarchical level in the file. The `Previous' and `Up' pointers are
1092 to `(dir)'. Point must be at the beginning of the node line, and is
1093 left at the end of the node line."
1095 (texinfo-clean-up-node-line)
1098 ;; There may be an @chapter or other such command between
1099 ;; the top node line and the next node line, as a title
1100 ;; for an `ifinfo' section. This @chapter command must
1101 ;; must be skipped. So the procedure is to search for
1102 ;; the next `@node' line, and then copy its name.
1103 (if (re-search-forward "^@node" nil t
)
1106 (texinfo-copy-node-name))
1110 (defun texinfo-check-for-node-name ()
1111 "Determine whether the node has a node name. Prompt for one if not.
1112 Point must be at beginning of node line. Does not move point."
1114 (forward-word 1) ; skip over node command
1115 (skip-chars-forward " \t") ; and over spaces
1116 (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what info looks for
1117 ; alternatively, use "[a-zA-Z]+"
1118 (let ((node-name (read-from-minibuffer "Node name: ")))
1119 (insert " " node-name
)))))
1121 (defun texinfo-delete-existing-pointers ()
1122 "Delete `Next', `Previous', and `Up' pointers.
1123 Starts from the current position of the cursor, and searches forward
1124 on the line for a comma and if one is found, deletes the rest of the
1125 line, including the comma. Leaves point at beginning of line."
1126 (if (search-forward "," (save-excursion (end-of-line) (point)) t
)
1128 (goto-char (1- (point)))
1130 (beginning-of-line))
1132 (defun texinfo-find-pointer (beginning end level direction
)
1133 "Move point to section associated with next, previous, or up pointer.
1134 Return type of pointer (either 'normal or 'no-pointer).
1136 The first and second arguments bound the search for a pointer to the
1137 beginning and end, respectively, of the enclosing higher level
1138 section. The third argument is a string specifying the general kind
1139 of section such as \"chapter\ or \"section\". When looking for the
1140 `Next' pointer, the section found will be at the same hierarchical
1141 level in the Texinfo file; when looking for the `Previous' pointer,
1142 the section found will be at the same or higher hierarchical level in
1143 the Texinfo file; when looking for the `Up' pointer, the section found
1144 will be at some level higher in the Texinfo file. The fourth argument
1145 \(one of 'next, 'previous, or 'up\) specifies whether to find the
1146 `Next', `Previous', or `Up' pointer."
1148 (cond ((eq direction
'next
)
1149 (forward-line 3) ; skip over current node
1150 (if (re-search-forward
1152 (cdr (assoc level texinfo-update-menu-same-level-regexps
)))
1157 ((eq direction
'previous
)
1158 (if (re-search-backward
1162 (cdr (assoc level texinfo-update-menu-same-level-regexps
)))
1165 (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1172 (if (re-search-backward
1173 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1175 (goto-char beginning
)
1182 (error "texinfo-find-pointer: lack proper arguments"))))
1184 (defun texinfo-pointer-name (kind)
1185 "Return the node name preceding the section command.
1186 The argument is the kind of section, either normal or no-pointer."
1188 (cond ((eq kind
'normal
)
1189 (end-of-line) ; this handles prev node top case
1190 (re-search-backward ; when point is already
1191 "^@node" ; at the beginning of @node line
1192 (save-excursion (forward-line -
3))
1194 (setq name
(texinfo-copy-node-name)))
1195 ((eq kind
'no-pointer
)
1196 (setq name
" "))) ; put a blank in the pointer slot
1199 (defun texinfo-insert-pointer (beginning end level direction
)
1200 "Insert the `Next', `Previous' or `Up' node name at point.
1203 The first and second arguments bound the search for a pointer to the
1204 beginning and end, respectively, of the enclosing higher level
1205 section. The third argument is the hierarchical level of the Texinfo
1206 file, a string such as \"section\". The fourth argument is direction
1207 towards which the pointer is directed, one of `next, `previous, or
1214 (texinfo-pointer-name
1215 (texinfo-find-pointer beginning end level direction
)))))
1217 (defun texinfo-clean-up-node-line ()
1218 "Remove extra commas, if any, at end of node line."
1220 (skip-chars-backward ", ")
1221 (delete-region (point) (save-excursion (end-of-line) (point))))
1224 ;;;; Updating nodes sequentially
1225 ; These sequential update functions insert `Next' or `Previous'
1226 ; pointers that point to the following or preceding nodes even if they
1227 ; are at higher or lower hierarchical levels. This means that if a
1228 ; section contains one or more subsections, the section's `Next'
1229 ; pointer will point to the subsection and not the following section.
1230 ; (The subsection to which `Next' points will most likely be the first
1231 ; item on the section's menu.)
1233 (defun texinfo-sequential-node-update (&optional region-p
)
1234 "Update one node (or many) in a Texinfo file with sequential pointers.
1236 This function causes the `Next' or `Previous' pointer to point to the
1237 immediately preceding or following node, even if it is at a higher or
1238 lower hierarchical level in the document. Continually pressing `n' or
1239 `p' takes you straight through the file.
1241 Without any prefix argument, update the node in which point is located.
1242 Non-nil argument (prefix, if interactive) means update the nodes in the
1245 This command makes it awkward to navigate among sections and
1246 subsections; it should be used only for those documents that are meant
1247 to be read like a novel rather than a reference, and for which the
1248 Info `g*' command is inadequate."
1252 (let ((auto-fill-function nil
)) ; update a single node
1253 (if (not (re-search-backward "^@node" (point-min) t
))
1254 (error "Node line not found before this position."))
1255 (texinfo-sequentially-update-the-node)
1257 "Done...sequentially updated the node . You may save the buffer."))
1259 (let ((auto-fill-function nil
)
1260 (beginning (region-beginning))
1262 (if (= end beginning
)
1263 (error "Please mark a region!"))
1265 (narrow-to-region beginning end
)
1266 (goto-char beginning
)
1268 (while (re-search-forward "^@node" (point-max) t
)
1270 (texinfo-sequentially-update-the-node))
1272 "Done...updated the nodes in sequence. You may save the buffer.")))))
1274 (defun texinfo-sequentially-update-the-node ()
1275 "Update one node such that the pointers are sequential.
1276 A `Next' or `Previous' pointer points to any preceding or following node,
1277 regardless of its hierarchical level."
1279 (texinfo-check-for-node-name)
1280 (texinfo-delete-existing-pointers)
1282 "Sequentially updating node: %s ... " (texinfo-copy-node-name))
1286 ((case-fold-search t
)
1287 (level (texinfo-hierarchic-level)))
1288 (if (string-equal level
"top")
1289 (texinfo-top-pointer-case)
1291 (texinfo-sequentially-insert-pointer level
'next
)
1292 (texinfo-sequentially-insert-pointer level
'previous
)
1293 (texinfo-sequentially-insert-pointer level
'up
)
1294 (texinfo-clean-up-node-line)))))
1296 (defun texinfo-sequentially-find-pointer (level direction
)
1297 "Find next or previous pointer sequentially in Texinfo file, or up pointer.
1298 Move point to section associated with the pointer. Find point even if
1299 it is in a different section.
1301 Return type of pointer (either 'normal or 'no-pointer).
1303 The first argument is a string specifying the general kind of section
1304 such as \"chapter\ or \"section\". The section found will be at the
1305 same hierarchical level in the Texinfo file, or, in the case of the up
1306 pointer, some level higher. The second argument (one of 'next,
1307 'previous, or 'up) specifies whether to find the `Next', `Previous',
1310 (cond ((eq direction
'next
)
1311 (forward-line 3) ; skip over current node
1312 (if (re-search-forward
1313 texinfo-section-types-regexp
1318 ((eq direction
'previous
)
1319 (if (re-search-backward
1320 texinfo-section-types-regexp
1326 (if (re-search-backward
1327 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1333 (error "texinfo-sequential-find-pointer: lack proper arguments"))))
1335 (defun texinfo-sequentially-insert-pointer (level direction
)
1336 "Insert the `Next', `Previous' or `Up' node name at point.
1339 The first argument is the hierarchical level of the Texinfo file, a
1340 string such as \"section\". The second argument is direction, one of
1341 `next, `previous, or 'up."
1347 (texinfo-pointer-name
1348 (texinfo-sequentially-find-pointer level direction
)))))
1351 ;;;; Inserting `@node' lines
1352 ; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
1353 ; before the `@chapter', `@section', and such like lines of a region
1354 ; in a Texinfo file.
1356 (defun texinfo-insert-node-lines (&optional title-p
)
1357 "Insert missing `@node' lines in region of Texinfo file.
1358 Non-nil argument (prefix, if interactive) means also to insert the
1359 section titles as node names; and also to insert the section titles as
1360 node names in pre-existing @node lines that lack names."
1363 (let ((begin-region (region-beginning))
1364 (end-region (region-end)))
1365 (goto-char begin-region
)
1366 (while (< (point) end-region
)
1367 (re-search-forward texinfo-section-types-regexp nil
'end
)
1368 ;; copy title, since most often, we will need it
1373 (skip-chars-forward " \t")
1376 (save-excursion (end-of-line) (point))))))
1377 ;; insert a node if necessary
1378 (if (re-search-backward
1384 ;; @node present, and point at beginning of that line
1386 ;; else @node missing, insert one
1388 (beginning-of-line) ; beginning of `@section' line
1390 (backward-char 1))) ; leave point just after `@node'
1391 ;; insert a title if warranted
1394 (skip-chars-forward " \t")
1395 ;; use regexp based on what info looks for
1396 ;; (alternatively, use "[a-zA-Z]+")
1397 (if (not (looking-at "[^,\t\n ]+"))
1402 (message "Inserted title %s ... " title
)))))
1403 ;; in any case, go forward beyond current section title
1404 (forward-line 3)))))
1407 "Done inserting node lines and titles. You may save the buffer.")
1408 (message "Done inserting node lines. You may save the buffer.")))
1411 ;;;; Update and create menus for multi-file Texinfo sources
1413 ;; 1. M-x texinfo-multiple-files-update
1415 ;; Read the include file list of an outer Texinfo file and
1416 ;; update all highest level nodes in the files listed and insert a
1417 ;; main menu in the outer file after its top node.
1419 ;; 2. C-u M-x texinfo-multiple-files-update
1421 ;; Same as 1, but insert a master menu. (Saves reupdating lower
1422 ;; level menus and nodes.) This command simply reads every menu,
1423 ;; so if the menus are wrong, the master menu will be wrong.
1424 ;; Similarly, if the lower level node pointers are wrong, they
1427 ;; 3. C-u 2 M-x texinfo-multiple-files-update
1429 ;; Read the include file list of an outer Texinfo file and
1430 ;; update all nodes and menus in the files listed and insert a
1431 ;; master menu in the outer file after its top node.
1433 ;;; Note: these functions:
1435 ;;; * Do not save or delete any buffers. You may fill up your memory.
1436 ;;; * Do not handle any pre-existing nodes in outer file.
1437 ;;; Hence, you may need a file for indices.
1440 ;;;; Auxiliary functions for multiple file updating
1442 (defun texinfo-multi-file-included-list (outer-file)
1443 "Return a list of the included files in OUTER-FILE."
1444 (let ((included-file-list (list outer-file
))
1447 (switch-to-buffer (find-file-noselect outer-file
))
1449 (goto-char (point-min))
1450 (while (re-search-forward "^@include" nil t
)
1451 (skip-chars-forward " \t")
1452 (setq start
(point))
1454 (skip-chars-backward " \t")
1455 (setq included-file-list
1456 (cons (buffer-substring start
(point))
1457 included-file-list
)))
1458 (nreverse included-file-list
))))
1460 (defun texinfo-copy-next-section-title ()
1461 "Return the name of the immediately following section as a string.
1463 Start with point at the beginning of the node line. Leave point at the
1464 same place. If there is no title, returns an empty string."
1468 (let ((section-end (or
1470 (re-search-forward "\\(^@node\\)" nil t
)
1471 (match-beginning 0))
1473 (if (re-search-forward texinfo-section-types-regexp section-end t
)
1477 (progn (forward-word 1) ; skip over section type
1478 (skip-chars-forward " \t") ; and over spaces
1480 (progn (end-of-line) (point)))))
1484 (defun texinfo-multi-file-update (files &optional update-everything
)
1485 "Update first node pointers in each file in FILES.
1486 Return a list of the node names and the title immediate following them.
1488 The first file in the list is an outer file; the remaining are
1489 files included in the outer file with `@include' commands.
1491 If optional arg UPDATE-EVERYTHING non-nil, update every menu and
1492 pointer in each of the included files.
1494 Also update the `Top' level node pointers of the outer file.
1498 * the first file in the FILES list must be the outer file,
1499 * each of the included files must contain exactly one highest
1500 hierarchical level node,
1501 * this node must be the first node in the included file,
1502 * each highest hierarchical level node must be of the same type.
1504 Thus, normally, each included file contains one, and only one,
1507 The menu-list has the form:
1509 \(\(\"node-name1\" . \"title1\"\)
1510 \(\"node-name2\" . \"title2\"\) ... \)
1512 However, there does not need to be a title field."
1516 ;; Find the name of the first node of the first included file.
1517 (switch-to-buffer (find-file-noselect (car (cdr files
))))
1519 (goto-char (point-min))
1520 (if (not (re-search-forward "^@node" nil t
))
1521 (error "No `@node' line found in %s !" (buffer-name)))
1523 (texinfo-check-for-node-name)
1524 (setq next-node-name
(texinfo-copy-node-name))
1529 (texinfo-copy-next-section-title))
1533 (switch-to-buffer (find-file-noselect (car files
)))
1534 (goto-char (point-min))
1535 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
1536 (error "This buffer needs a Top node!"))
1538 (texinfo-delete-existing-pointers)
1540 (insert ", " next-node-name
", (dir), (dir)")
1542 (setq previous-node-name
"Top")
1543 (setq files
(cdr files
))
1547 (if (not (cdr files
))
1549 (setq next-node-name
"")
1551 ;; find the name of the first node in the next file.
1552 (switch-to-buffer (find-file-noselect (car (cdr files
))))
1554 (goto-char (point-min))
1555 (if (not (re-search-forward "^@node" nil t
))
1556 (error "No `@node' line found in %s !" (buffer-name)))
1558 (texinfo-check-for-node-name)
1559 (setq next-node-name
(texinfo-copy-node-name))
1563 (texinfo-copy-next-section-title))
1566 ;; Go to node to be updated.
1567 (switch-to-buffer (find-file-noselect (car files
)))
1568 (goto-char (point-min))
1569 (if (not (re-search-forward "^@node" nil t
))
1570 (error "No `@node' line found in %s !" (buffer-name)))
1572 (texinfo-delete-existing-pointers)
1574 (insert ", " next-node-name
", " previous-node-name
", " up-node-name
)
1577 (setq previous-node-name
(texinfo-copy-node-name))
1579 ;; Update other menus and nodes if requested.
1580 (if update-everything
(texinfo-all-menus-update t
))
1582 (setq files
(cdr files
)))
1583 (nreverse menu-list
)))
1585 (defun texinfo-multi-files-insert-main-menu (menu-list)
1586 "Insert formatted main menu at point.
1587 Indents the first line of the description, if any, to the value of
1588 texinfo-column-for-description."
1592 (if (cdr (car menu-list
)) ; menu-list has description entry
1595 (format "* %s::" (car (car menu-list
)))) ; node-name entry
1596 (indent-to texinfo-column-for-description
2)
1598 (format "%s\n" (cdr (car menu-list
))))) ; description entry
1599 ;; else menu-list lacks description entry
1601 (format "* %s::\n" (car (car menu-list
))))) ; node-name entry
1602 (setq menu-list
(cdr menu-list
)))
1603 (insert "@end menu"))
1606 (defun texinfo-multi-file-master-menu-list (files-list)
1607 "Return master menu list from files in FILES-LIST.
1608 Menu entries in each file collected using `texinfo-master-menu-list'.
1610 The first file in FILES-LIST must be the outer file; the others must
1611 be the files included within it. A main menu must already exist."
1613 (let (master-menu-list)
1615 (switch-to-buffer (find-file-noselect (car files-list
)))
1616 (message "Working on: %s " (current-buffer))
1617 (goto-char (point-min))
1618 (setq master-menu-list
1619 (append master-menu-list
(texinfo-master-menu-list)))
1620 (setq files-list
(cdr files-list
)))
1624 ;;;; The multiple-file update function
1626 (defun texinfo-multiple-files-update
1627 (outer-file &optional update-everything make-master-menu
)
1628 "Update first node pointers in each file included in OUTER-FILE;
1629 create or update main menu in the outer file that refers to such nodes.
1630 This does not create or update menus or pointers within the included files.
1632 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
1633 insert a master menu in OUTER-FILE. This does not create or update
1634 menus or pointers within the included files.
1636 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
1637 interactive), update all the menus and all the `Next', `Previous', and
1638 `Up' pointers of all the files included in OUTER-FILE before inserting
1639 a master menu in OUTER-FILE.
1641 The command also updates the `Top' level node pointers of OUTER-FILE.
1645 * this command does NOT save any files--you must save the
1646 outer file and any modified, included files.
1648 * except for the `Top' node, this command does NOT handle any
1649 pre-existing nodes in the outer file; hence, indices must be
1650 enclosed in an included file.
1654 * each of the included files must contain exactly one highest
1655 hierarchical level node,
1656 * this highest node must be the first node in the included file,
1657 * each highest hierarchical level node must be of the same type.
1659 Thus, normally, each included file contains one, and only one,
1662 (interactive "fName of outer `include' file: ")
1664 (cond (current-prefix-arg
1665 (setq make-master-menu
(listp current-prefix-arg
))
1666 (setq update-everything
(numberp current-prefix-arg
))))
1668 (let* ((included-file-list (texinfo-multi-file-included-list outer-file
))
1669 (files included-file-list
)
1673 (up-node-name "Top"))
1675 ;;; Update the pointers
1676 ;;; and collect the names of the nodes and titles
1677 (setq main-menu-list
(texinfo-multi-file-update files update-everything
))
1679 ;;; Insert main menu
1682 (switch-to-buffer (find-file-noselect (car included-file-list
)))
1683 (if (texinfo-old-menu-p
1686 (re-search-forward "^@include")
1690 ;; If found, leave point after word `menu' on the `@menu' line.
1692 (texinfo-incorporate-descriptions main-menu-list
)
1693 ;; Delete existing menu.
1697 (save-excursion (re-search-forward "^@end menu") (point)))
1699 (texinfo-multi-files-insert-main-menu main-menu-list
))
1701 ;; Else no current menu; insert it before `@include'
1702 (texinfo-multi-files-insert-main-menu main-menu-list
))
1704 ;;; Insert master menu
1706 (if make-master-menu
1708 ;; First, removing detailed part of any pre-existing master menu
1709 (goto-char (point-min))
1710 (if (re-search-forward texinfo-master-menu-header nil t
)
1711 ;; Remove detailed master menu listing
1713 (goto-char (match-beginning 0))
1714 (let ((end-of-detailed-menu-descriptions
1715 (save-excursion ; beginning of end menu line
1716 (goto-char (texinfo-menu-end))
1717 (beginning-of-line) (forward-char -
1)
1719 (delete-region (point) end-of-detailed-menu-descriptions
))))
1721 ;; Create a master menu and insert it
1722 (texinfo-insert-master-menu-list
1723 (texinfo-multi-file-master-menu-list
1724 included-file-list
)))))
1725 (message "Multiple files updated."))
1727 (provide 'texnfo-upd
)
1729 ;;; texnfo-upd.el ends here