Add defgroup; use defcustom for user vars.
[emacs.git] / lisp / textmodes / texnfo-upd.el
blob724d3617d13b9c60365c236bb1094578aafca7b4
1 ;;; texnfo-upd.el --- utilities for updating nodes and menus in Texinfo files
3 ;; Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
5 ;; Author: Robert J. Chassell
6 ;; Maintainer: bug-texinfo@prep.ai.mit.edu
7 ;; Keywords: maint, tex, docs
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)
14 ;; any later version.
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 the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
26 ;;; Commentary:
28 ;; Known bug: update commands fail to ignore @ignore.
30 ;; Summary: how to use the updating commands
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 ;; With a prefix argument, the `texinfo-update-node' and
40 ;; `texinfo-make-menu' functions do their jobs in the region.
42 ;; In brief, the functions for creating or updating nodes and menus, are:
43 ;;
44 ;; texinfo-update-node (&optional beginning end)
45 ;; texinfo-every-node-update ()
46 ;; texinfo-sequential-node-update (&optional region-p)
47 ;;
48 ;; texinfo-make-menu (&optional beginning end)
49 ;; texinfo-all-menus-update ()
50 ;; texinfo-master-menu ()
52 ;; texinfo-insert-node-lines (&optional title-p)
53 ;;
54 ;; texinfo-indent-menu-description (column &optional region-p)
56 ;; The `texinfo-column-for-description' variable specifies the column to
57 ;; which menu descriptions are indented.
59 ;; Texinfo file structure
60 ;; ----------------------
62 ;; To use the updating commands, you must structure your Texinfo file
63 ;; hierarchically. Each `@node' line, with the exception of the top
64 ;; node, must be accompanied by some kind of section line, such as an
65 ;; `@chapter' or `@section' line. Each node-line/section-line
66 ;; combination must look like this:
68 ;; @node Lists and Tables, Cross References, Structuring, Top
69 ;; @comment node-name, next, previous, up
70 ;; @chapter Making Lists and Tables
72 ;; or like this (without the `@comment' line):
74 ;; @node Lists and Tables, Cross References, Structuring, Top
75 ;; @chapter Making Lists and Tables
77 ;; If the file has a `top' node, it must be called `top' or `Top' and
78 ;; be the first node in the file.
81 ;;; The update node functions described in detail
83 ;; The `texinfo-update-node' command with no prefix argument inserts
84 ;; the correct next, previous and up pointers for the node in which
85 ;; point is located (i.e., for the node preceding point).
87 ;; With prefix argument, the `texinfo-update-node' function inserts the
88 ;; correct next, previous and up pointers for the nodes inside the
89 ;; region.
91 ;; It does not matter whether the `@node' line has pre-existing
92 ;; `Next', `Previous', or `Up' pointers in it. They are removed.
94 ;; The `texinfo-every-node-update' function runs `texinfo-update-node'
95 ;; on the whole buffer.
97 ;; The `texinfo-sequential-node-update' function inserts the
98 ;; immediately following and preceding node into the `Next' or
99 ;; `Previous' pointers regardless of their hierarchical level. This is
100 ;; only useful for certain kinds of text, like a novel, which you go
101 ;; through sequentially.
104 ;;; The menu making functions described in detail
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 ;;; Code:
152 (defun texinfo-make-menu (&optional beginning end)
153 "Without any prefix argument, make or update a menu.
154 Make the menu for the section enclosing the node found following point.
156 A prefix argument 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."
164 (interactive
165 (if prefix-arg
166 (list (point) (mark))))
167 (if (null beginning)
168 (let ((level (texinfo-hierarchic-level)))
169 (texinfo-make-one-menu level)
170 (message "Menu updated"))
171 ;; else
172 (message "Making or updating menus in %s... " (buffer-name))
173 (save-excursion
174 (goto-char (min beginning end))
175 ;; find section type following point
176 (let ((level (texinfo-hierarchic-level))
177 (region-end (max beginning end)))
178 (save-restriction
179 (widen)
181 (while (texinfo-find-lower-level-node level region-end)
182 (setq level (texinfo-hierarchic-level)) ; new, lower level
183 (texinfo-make-one-menu level))
185 (while (and (< (point) region-end)
186 (texinfo-find-higher-level-node level region-end))
187 (setq level (texinfo-hierarchic-level))
188 (while (texinfo-find-lower-level-node level region-end)
189 (setq level (texinfo-hierarchic-level)) ; new, lower level
190 (texinfo-make-one-menu level))))))
191 (message "Making or updating menus in %s...done" (buffer-name))))
193 (defun texinfo-make-one-menu (level)
194 "Make a menu of all the appropriate nodes in this section.
195 `Appropriate nodes' are those associated with sections that are
196 at the level specified by LEVEL. Point is left at the end of menu."
197 (let*
198 ((case-fold-search t)
199 (beginning
200 (save-excursion
201 (goto-char (texinfo-update-menu-region-beginning level))
202 (end-of-line)
203 (point)))
204 (end (texinfo-update-menu-region-end level))
205 (first (texinfo-menu-first-node beginning end))
206 (node-name (progn
207 (goto-char beginning)
208 (beginning-of-line)
209 (texinfo-copy-node-name)))
210 (new-menu-list (texinfo-make-menu-list beginning end level)))
211 (if (texinfo-old-menu-p beginning first)
212 (progn
213 (texinfo-incorporate-descriptions new-menu-list)
214 (texinfo-incorporate-menu-entry-names 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 Update pre-existing master menu, if there is one.
222 If called with a non-nil argument, this function first updates all the
223 nodes in the buffer before updating the menus."
224 (interactive "P")
225 (let ((case-fold-search t)
226 master-menu-p)
227 (save-excursion
228 (push-mark (point-max) t)
229 (goto-char (point-min))
230 (message "Checking for a master menu in %s ... "(buffer-name))
231 (save-excursion
232 (if (re-search-forward texinfo-master-menu-header nil t)
233 ;; Remove detailed master menu listing
234 (progn
235 (setq master-menu-p t)
236 (goto-char (match-beginning 0))
237 (let ((end-of-detailed-menu-descriptions
238 (save-excursion ; beginning of end menu line
239 (goto-char (texinfo-menu-end))
240 (beginning-of-line) (forward-char -1)
241 (point))))
242 (delete-region (point) end-of-detailed-menu-descriptions)))))
244 (if update-all-nodes-p
245 (progn
246 (message "Updating all nodes in %s ... " (buffer-name))
247 (sleep-for 2)
248 (texinfo-update-node (point-min) (point-max))))
250 (message "Updating all menus in %s ... " (buffer-name))
251 (sleep-for 2)
252 (texinfo-make-menu (point-max) (point-min))
254 (if master-menu-p
255 (progn
256 (message "Updating the master menu in %s... " (buffer-name))
257 (sleep-for 2)
258 (texinfo-master-menu nil))))
260 (message "Done...updated all the menus. You may save the buffer.")))
262 (defun texinfo-find-lower-level-node (level region-end)
263 "Search forward from point for node at any level lower than LEVEL.
264 Search is limited to the end of the marked region, REGION-END,
265 and to the end of the menu region for the level.
267 Return t if the node is found, else nil. Leave point at the beginning
268 of the node if one is found; else do not move point."
269 (let ((case-fold-search t))
270 (if (and (< (point) region-end)
271 (re-search-forward
272 (concat
273 "\\(^@node\\).*\n" ; match node line
274 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
275 "\\|" ; or
276 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
277 (eval (cdr (assoc level texinfo-update-menu-lower-regexps))))
278 ;; the next higher level node marks the end of this
279 ;; section, and no lower level node will be found beyond
280 ;; this position even if region-end is farther off
281 (texinfo-update-menu-region-end level)
283 (goto-char (match-beginning 1)))))
285 (defun texinfo-find-higher-level-node (level region-end)
286 "Search forward from point for node at any higher level than argument LEVEL.
287 Search is limited to the end of the marked region, REGION-END.
289 Return t if the node is found, else nil. Leave point at the beginning
290 of the node if one is found; else do not move point."
291 (let ((case-fold-search t))
292 (cond
293 ((or (string-equal "top" level) (string-equal "chapter" level))
294 (if (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" region-end t)
295 (progn (beginning-of-line) t)))
297 (if (re-search-forward
298 (concat
299 "\\(^@node\\).*\n" ; match node line
300 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
301 "\\|" ; or
302 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
303 (eval (cdr (assoc level texinfo-update-menu-higher-regexps))))
304 region-end t)
305 (progn (beginning-of-line) t))))))
308 ;;; Making the list of new menu entries
310 (defun texinfo-make-menu-list (beginning end level)
311 "Make a list of node names and their descriptions.
312 Point is left at the end of the menu region, but the menu is not inserted.
314 First argument is position from which to start making menu list;
315 second argument is end of region in which to try to locate entries;
316 third argument is the level of the nodes that are the entries.
318 Node names and descriptions are dotted pairs of strings. Each pair is
319 an element of the list. If the description does not exist, the
320 element consists only of the node name."
321 (goto-char beginning)
322 (let (new-menu-list)
323 (while (texinfo-menu-locate-entry-p level end)
324 (setq new-menu-list
325 (cons (cons
326 (texinfo-copy-node-name)
327 (prog1 "" (forward-line 1)))
328 ;; Use following to insert section titles automatically.
329 ;; (texinfo-copy-section-title))
330 new-menu-list)))
331 (reverse new-menu-list)))
333 (defun texinfo-menu-locate-entry-p (level search-end)
334 "Find a node that will be part of menu for this section.
335 First argument is a string such as \"section\" specifying the general
336 hierarchical level of the menu; second argument is a position
337 specifying the end of the search.
339 The function returns t if the node is found, else nil. It searches
340 forward from point, and leaves point at the beginning of the node.
342 The function finds entries of the same type. Thus `subsections' and
343 `unnumberedsubsecs' will appear in the same menu."
344 (let ((case-fold-search t))
345 (if (re-search-forward
346 (concat
347 "\\(^@node\\).*\n" ; match node line
348 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
349 "\\|" ; or
350 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
351 (eval
352 (cdr (assoc level texinfo-update-menu-same-level-regexps))))
353 search-end
355 (goto-char (match-beginning 1)))))
357 (defun texinfo-copy-node-name ()
358 "Return the node name as a string.
360 Start with point at the beginning of the node line; copy the text
361 after the node command up to the first comma on the line, if any, and
362 return the text as a string. Leaves point at the beginning of the
363 line. If there is no node name, returns an empty string."
365 (save-excursion
366 (buffer-substring
367 (progn (forward-word 1) ; skip over node command
368 (skip-chars-forward " \t") ; and over spaces
369 (point))
370 (if (search-forward
372 (save-excursion (end-of-line) (point)) t) ; bound search
373 (1- (point))
374 (end-of-line) (point)))))
376 (defun texinfo-copy-section-title ()
377 "Return the title of the section as a string.
378 The title is used as a description line in the menu when one does not
379 already exist.
381 Move point to the beginning of the appropriate section line by going
382 to the start of the text matched by last regexp searched for, which
383 must have been done by `texinfo-menu-locate-entry-p'."
385 ;; could use the same re-search as in `texinfo-menu-locate-entry-p'
386 ;; instead of using `match-beginning'; such a variation would be
387 ;; more general, but would waste information already collected
389 (goto-char (match-beginning 7)) ; match section name
391 (buffer-substring
392 (progn (forward-word 1) ; skip over section type
393 (skip-chars-forward " \t") ; and over spaces
394 (point))
395 (progn (end-of-line) (point))))
398 ;;; Handling the old menu
400 (defun texinfo-old-menu-p (beginning first)
401 "Move point to the beginning of the menu for this section, if any.
402 Otherwise move point to the end of the first node of this section.
403 Return t if a menu is found, nil otherwise.
405 First argument is the position of the beginning of the section in which
406 the menu will be located; second argument is the position of the first
407 node within the section.
409 If no menu is found, the function inserts two newlines just before the
410 end of the section, and leaves point there where a menu ought to be."
411 (goto-char beginning)
412 (if (not (re-search-forward "^@menu" first 'goto-end))
413 (progn (insert "\n\n") (forward-line -2) nil)
416 (defun texinfo-incorporate-descriptions (new-menu-list)
417 "Copy the old menu line descriptions that exist to the new menu.
419 Point must be at beginning of old menu.
421 If the node-name of the new menu is found in the old menu, insert the
422 old description into the new entry.
424 For this function, the new menu is a list made up of lists of dotted
425 pairs in which the first element of the pair is the node name and the
426 second element the description. The new menu is changed destructively.
427 The old menu is the menu as it appears in the texinfo file."
429 (let ((new-menu-list-pointer new-menu-list)
430 (end-of-menu (texinfo-menu-end)))
431 (while new-menu-list
432 (save-excursion ; keep point at beginning of menu
433 (if (re-search-forward
434 ;; Existing nodes can have the form
435 ;; * NODE NAME:: DESCRIPTION
436 ;; or
437 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
439 ;; Recognize both when looking for the description.
440 (concat "\\* \\(" ; so only menu entries are found
441 (regexp-quote (car (car new-menu-list))) "::"
442 "\\|"
443 ".*: " (regexp-quote (car (car new-menu-list))) "[.,\t\n]"
444 "\\)"
445 ) ; so only complete entries are found
446 end-of-menu
448 (setcdr (car new-menu-list)
449 (texinfo-menu-copy-old-description end-of-menu))))
450 (setq new-menu-list (cdr new-menu-list)))
451 (setq new-menu-list new-menu-list-pointer)))
453 (defun texinfo-incorporate-menu-entry-names (new-menu-list)
454 "Copy any old menu entry names to the new menu.
456 Point must be at beginning of old menu.
458 If the node-name of the new menu entry cannot be found in the old
459 menu, do nothing.
461 For this function, the new menu is a list made up of lists of dotted
462 pairs in which the first element of the pair is the node name and the
463 second element is the description (or nil).
465 If we find an existing menu entry name, we change the first element of
466 the pair to be another dotted pair in which the car is the menu entry
467 name and the cdr is the node name.
469 NEW-MENU-LIST is changed destructively. The old menu is the menu as it
470 appears in the texinfo file."
472 (let ((new-menu-list-pointer new-menu-list)
473 (end-of-menu (texinfo-menu-end)))
474 (while new-menu-list
475 (save-excursion ; keep point at beginning of menu
476 (if (re-search-forward
477 ;; Existing nodes can have the form
478 ;; * NODE NAME:: DESCRIPTION
479 ;; or
480 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
482 ;; We're interested in the second case.
483 (concat "\\* " ; so only menu entries are found
484 "\\(.*\\): " (car (car new-menu-list)) "[.,\t\n]")
485 end-of-menu
487 (setcar
488 (car new-menu-list) ; replace the node name
489 (cons (buffer-substring (match-beginning 1) (match-end 1))
490 (car (car new-menu-list)))))
491 (setq new-menu-list (cdr new-menu-list))))
492 (setq new-menu-list new-menu-list-pointer)))
494 (defun texinfo-menu-copy-old-description (end-of-menu)
495 "Return description field of old menu line as string.
496 Point must be located just after the node name. Point left before description.
497 Single argument, END-OF-MENU, is position limiting search."
498 (skip-chars-forward "[:.,\t\n ]+")
499 ;; don't copy a carriage return at line beginning with asterisk!
500 ;; do copy a description that begins with an `@'!
501 ;; !! Known bug: does not copy descriptions starting with ^|\{?* etc.
502 (if (and (looking-at "\\(\\w+\\|@\\)")
503 (not (looking-at "\\(^\\* \\|^@end menu\\)")))
504 (buffer-substring
505 (point)
506 (save-excursion
507 (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t)
508 (forward-line -1)
509 (end-of-line) ; go to end of last description line
510 (point)))
511 ""))
513 (defun texinfo-menu-end ()
514 "Return position of end of menu. Does not change location of point.
515 Signal an error if not end of menu."
516 (save-excursion
517 (if (re-search-forward "^@end menu" nil t)
518 (point)
519 (error "Menu does not have an end."))))
521 (defun texinfo-delete-old-menu (beginning first)
522 "Delete the old menu. Point must be in or after menu.
523 First argument is position of the beginning of the section in which
524 the menu will be located; second argument is the position of the first
525 node within the section."
526 ;; No third arg to search, so error if search fails.
527 (re-search-backward "^@menu" beginning)
528 (delete-region (point)
529 (save-excursion
530 (re-search-forward "^@end menu" first)
531 (point))))
534 ;;; Inserting new menu
536 ;; try 32, but perhaps 24 is better
537 (defvar texinfo-column-for-description 32
538 "*Column at which descriptions start in a Texinfo menu.")
540 (defun texinfo-insert-menu (menu-list node-name)
541 "Insert formatted menu at point.
542 Indents the first line of the description, if any, to the value of
543 texinfo-column-for-description.
545 MENU-LIST has form:
547 \(\(\"node-name1\" . \"description\"\)
548 \(\"node-name2\" . \"description\"\) ... \)
550 However, the description field might be nil.
552 Also, the node-name field might itself be a dotted pair (call it P) of
553 strings instead of just a string. In that case, the car of P
554 is the menu entry name, and the cdr of P is the node name."
556 (insert "@menu\n")
557 (while menu-list
558 ;; Every menu entry starts with a star and a space.
559 (insert "* ")
561 ;; Insert the node name (and menu entry name, if present).
562 (let ((node-part (car (car menu-list))))
563 (if (stringp node-part)
564 ;; "Double colon" entry line; menu entry and node name are the same,
565 (insert (format "%s::" node-part))
566 ;; "Single colon" entry line; menu entry and node name are different.
567 (insert (format "%s: %s." (car node-part) (cdr node-part)))))
569 ;; Insert the description, if present.
570 (if (cdr (car menu-list))
571 (progn
572 ;; Move to right place.
573 (indent-to texinfo-column-for-description 2)
574 ;; Insert description.
575 (insert (format "%s" (cdr (car menu-list))))))
577 (insert "\n") ; end this menu entry
578 (setq menu-list (cdr menu-list)))
579 (insert "@end menu")
580 (message
581 "Updated \"%s\" level menu following node: %s ... " level node-name))
584 ;;; Starting menu descriptions by inserting titles
586 (defun texinfo-start-menu-description ()
587 "In this menu entry, insert the node's section title as a description.
588 Position point at beginning of description ready for editing.
589 Do not insert a title if the line contains an existing description.
591 You will need to edit the inserted text since a useful description
592 complements the node name rather than repeats it as a title does."
594 (interactive)
595 (let (beginning end node-name title)
596 (save-excursion
597 (beginning-of-line)
598 (if (search-forward "* " (save-excursion (end-of-line) (point)) t)
599 (progn (skip-chars-forward " \t")
600 (setq beginning (point)))
601 (error "This is not a line in a menu!"))
603 (cond
604 ;; "Double colon" entry line; menu entry and node name are the same,
605 ((search-forward "::" (save-excursion (end-of-line) (point)) t)
606 (if (looking-at "[ \t]*[^ \t\n]+")
607 (error "Descriptive text already exists."))
608 (skip-chars-backward ": \t")
609 (setq node-name (buffer-substring beginning (point))))
611 ;; "Single colon" entry line; menu entry and node name are different.
612 ((search-forward ":" (save-excursion (end-of-line) (point)) t)
613 (skip-chars-forward " \t")
614 (setq beginning (point))
615 ;; Menu entry line ends in a period, comma, or tab.
616 (if (re-search-forward "[.,\t]"
617 (save-excursion (forward-line 1) (point)) t)
618 (progn
619 (if (looking-at "[ \t]*[^ \t\n]+")
620 (error "Descriptive text already exists."))
621 (skip-chars-backward "., \t")
622 (setq node-name (buffer-substring beginning (point))))
623 ;; Menu entry line ends in a return.
624 (re-search-forward ".*\n"
625 (save-excursion (forward-line 1) (point)) t)
626 (skip-chars-backward " \t\n")
627 (setq node-name (buffer-substring beginning (point)))
628 (if (= 0 (length node-name))
629 (error "No node name on this line.")
630 (insert "."))))
631 (t (error "No node name on this line.")))
632 ;; Search for node that matches node name, and copy the section title.
633 (if (re-search-forward
634 (concat
635 "^@node[ \t]+"
636 node-name
637 ".*\n" ; match node line
638 "\\("
639 "\\(\\(^@c \\|^@comment\\).*\n\\)" ; match comment line, if any
640 "\\|" ; or
641 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
642 "\\)?")
643 nil t)
644 (progn
645 (setq title
646 (buffer-substring
647 ;; skip over section type
648 (progn (forward-word 1)
649 ;; and over spaces
650 (skip-chars-forward " \t")
651 (point))
652 (progn (end-of-line)
653 (skip-chars-backward " \t")
654 (point)))))
655 (error "Cannot find node to match node name in menu entry.")))
656 ;; Return point to the menu and insert the title.
657 (end-of-line)
658 (delete-region
659 (point)
660 (save-excursion (skip-chars-backward " \t") (point)))
661 (indent-to texinfo-column-for-description 2)
662 (save-excursion (insert title))))
665 ;;; Handling description indentation
667 ; Since the make-menu functions indent descriptions, these functions
668 ; are useful primarily for indenting a single menu specially.
670 (defun texinfo-indent-menu-description (column &optional region-p)
671 "Indent every description in menu following point to COLUMN.
672 Non-nil argument (prefix, if interactive) means indent every
673 description in every menu in the region. Does not indent second and
674 subsequent lines of a multi-line description."
676 (interactive
677 "nIndent menu descriptions to (column number): \nP")
678 (save-excursion
679 (save-restriction
680 (widen)
681 (if (not region-p)
682 (progn
683 (re-search-forward "^@menu")
684 (texinfo-menu-indent-description column)
685 (message
686 "Indented descriptions in menu. You may save the buffer."))
687 ;;else
688 (message "Indenting every menu description in region... ")
689 (goto-char (region-beginning))
690 (while (and (< (point) (region-end))
691 (texinfo-locate-menu-p))
692 (forward-line 1)
693 (texinfo-menu-indent-description column))
694 (message "Indenting done. You may save the buffer.")))))
696 (defun texinfo-menu-indent-description (to-column-number)
697 "Indent the Texinfo file menu description to TO-COLUMN-NUMBER.
698 Start with point just after the word `menu' in the `@menu' line and
699 leave point on the line before the `@end menu' line. Does not indent
700 second and subsequent lines of a multi-line description."
701 (let* ((beginning-of-next-line (point)))
702 (while (< beginning-of-next-line
703 (save-excursion ; beginning of end menu line
704 (goto-char (texinfo-menu-end))
705 (beginning-of-line)
706 (point)))
708 (if (re-search-forward "\\* \\(.*::\\|.*: [^.,\t\n]+[.,\t]\\)"
709 (texinfo-menu-end)
711 (progn
712 (let ((beginning-white-space (point)))
713 (skip-chars-forward " \t") ; skip over spaces
714 (if (looking-at "\\(@\\|\\w\\)+") ; if there is text
715 (progn
716 ;; remove pre-existing indentation
717 (delete-region beginning-white-space (point))
718 (indent-to-column to-column-number))))))
719 ;; position point at beginning of next line
720 (forward-line 1)
721 (setq beginning-of-next-line (point)))))
724 ;;; Making the master menu
726 (defun texinfo-master-menu (update-all-nodes-menus-p)
727 "Make a master menu for a whole Texinfo file.
728 Non-nil argument (prefix, if interactive) means first update all
729 existing nodes and menus. Remove pre-existing master menu, if there is one.
731 This function creates a master menu that follows the top node. The
732 master menu includes every entry from all the other menus. It
733 replaces any existing ordinary menu that follows the top node.
735 If called with a non-nil argument, this function first updates all the
736 menus in the buffer (incorporating descriptions from pre-existing
737 menus) before it constructs the master menu.
739 The function removes the detailed part of an already existing master
740 menu. This action depends on the pre-existing master menu using the
741 standard `texinfo-master-menu-header'.
743 The master menu has the following format, which is adapted from the
744 recommendation in the Texinfo Manual:
746 * The first part contains the major nodes in the Texinfo file: the
747 nodes for the chapters, chapter-like sections, and the major
748 appendices. This includes the indices, so long as they are in
749 chapter-like sections, such as unnumbered sections.
751 * The second and subsequent parts contain a listing of the other,
752 lower level menus, in order. This way, an inquirer can go
753 directly to a particular node if he or she is searching for
754 specific information.
756 Each of the menus in the detailed node listing is introduced by the
757 title of the section containing the menu."
759 (interactive "P")
760 (let ((case-fold-search t))
761 (widen)
762 (goto-char (point-min))
764 ;; Move point to location after `top'.
765 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
766 (error "This buffer needs a Top node!"))
768 (let ((first-chapter
769 (save-excursion
770 (or (re-search-forward "^@node" nil t)
771 (error "Too few nodes for a master menu!"))
772 (point))))
773 (if (re-search-forward texinfo-master-menu-header first-chapter t)
774 ;; Remove detailed master menu listing
775 (progn
776 (goto-char (match-beginning 0))
777 (let ((end-of-detailed-menu-descriptions
778 (save-excursion ; beginning of end menu line
779 (goto-char (texinfo-menu-end))
780 (beginning-of-line) (forward-char -1)
781 (point))))
782 (delete-region (point) end-of-detailed-menu-descriptions)))))
784 (if update-all-nodes-menus-p
785 (progn
786 (message "Making a master menu in %s ...first updating all nodes... "
787 (buffer-name))
788 (sleep-for 2)
789 (texinfo-update-node (point-min) (point-max))
791 (message "Updating all menus in %s ... " (buffer-name))
792 (sleep-for 2)
793 (texinfo-make-menu (point-min) (point-max))))
795 (message "Now making the master menu in %s... " (buffer-name))
796 (sleep-for 2)
797 (goto-char (point-min))
798 (texinfo-insert-master-menu-list
799 (texinfo-master-menu-list))
801 ;; Remove extra newlines that texinfo-insert-master-menu-list
802 ;; may have inserted.
804 (save-excursion
805 (goto-char (point-min))
807 (if (re-search-forward texinfo-master-menu-header nil t)
808 (progn
809 (goto-char (match-beginning 0))
810 (insert "\n")
811 (delete-blank-lines)
812 (goto-char (point-min))))
814 (re-search-forward "^@menu")
815 (forward-line -1)
816 (delete-blank-lines)
818 (re-search-forward "^@end menu")
819 (forward-line 1)
820 (delete-blank-lines))
822 (message
823 "Done...completed making master menu. You may save the buffer.")))
825 (defun texinfo-master-menu-list ()
826 "Return a list of menu entries and header lines for the master menu.
828 Start with the menu for chapters and indices and then find each
829 following menu and the title of the node preceding that menu.
831 The master menu list has this form:
833 \(\(\(... \"entry-1-2\" \"entry-1\"\) \"title-1\"\)
834 \(\(... \"entry-2-2\" \"entry-2-1\"\) \"title-2\"\)
835 ...\)
837 However, there does not need to be a title field."
839 (let (master-menu-list)
840 (while (texinfo-locate-menu-p)
841 (setq master-menu-list
842 (cons (list
843 (texinfo-copy-menu)
844 (texinfo-copy-menu-title))
845 master-menu-list)))
846 (reverse master-menu-list)))
848 (defun texinfo-insert-master-menu-list (master-menu-list)
849 "Format and insert the master menu in the current buffer."
850 (goto-char (point-min))
851 ;; Insert a master menu only after `Top' node and before next node
852 ;; \(or include file if there is no next node\).
853 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
854 (error "This buffer needs a Top node!"))
855 (let ((first-chapter
856 (save-excursion (re-search-forward "^@node\\|^@include") (point))))
857 (if (not (re-search-forward "^@menu" first-chapter t))
858 (error
859 "Buffer lacks ordinary `Top' menu in which to insert master.")))
860 (beginning-of-line)
861 (delete-region ; buffer must have ordinary top menu
862 (point)
863 (save-excursion (re-search-forward "^@end menu") (point)))
865 (save-excursion ; leave point at beginning of menu
866 ;; Handle top of menu
867 (insert "\n@menu\n")
868 ;; Insert chapter menu entries
869 (setq this-very-menu-list (reverse (car (car master-menu-list))))
870 ;; Tell user what is going on.
871 (message "Inserting chapter menu entry: %s ... " this-very-menu-list)
872 (while this-very-menu-list
873 (insert "* " (car this-very-menu-list) "\n")
874 (setq this-very-menu-list (cdr this-very-menu-list)))
876 (setq master-menu-list (cdr master-menu-list))
878 ;; Only insert detailed master menu if there is one....
879 (if (car (car master-menu-list))
880 (insert texinfo-master-menu-header))
882 ;; Now, insert all the other menus
884 ;; The menu master-menu-list has a form like this:
885 ;; ((("beta" "alpha") "title-A")
886 ;; (("delta" "gamma") "title-B"))
888 (while master-menu-list
890 (message
891 "Inserting menu for %s .... " (car (cdr (car master-menu-list))))
892 ;; insert title of menu section
893 (insert "\n" (car (cdr (car master-menu-list))) "\n\n")
895 ;; insert each menu entry
896 (setq this-very-menu-list (reverse (car (car master-menu-list))))
897 (while this-very-menu-list
898 (insert "* " (car this-very-menu-list) "\n")
899 (setq this-very-menu-list (cdr this-very-menu-list)))
901 (setq master-menu-list (cdr master-menu-list)))
903 ;; Finish menu
904 (insert "@end menu\n\n")))
906 (defvar texinfo-master-menu-header
907 "\n --- The Detailed Node Listing ---\n"
908 "String inserted before lower level entries in Texinfo master menu.
909 It comes after the chapter-level menu entries.")
911 (defun texinfo-locate-menu-p ()
912 "Find the next menu in the texinfo file.
913 If found, leave point after word `menu' on the `@menu' line, and return t.
914 If a menu is not found, do not move point and return nil."
915 (re-search-forward "\\(^@menu\\)" nil t))
917 (defun texinfo-copy-menu-title ()
918 "Return the title of the section preceding the menu as a string.
919 If such a title cannot be found, return an empty string. Do not move
920 point."
921 (let ((case-fold-search t))
922 (save-excursion
923 (if (re-search-backward
924 (concat
925 "\\(^@top"
926 "\\|" ; or
927 texinfo-section-types-regexp ; all other section types
928 "\\)")
931 (progn
932 (beginning-of-line)
933 (forward-word 1) ; skip over section type
934 (skip-chars-forward " \t") ; and over spaces
935 (buffer-substring
936 (point)
937 (progn (end-of-line) (point))))
938 ""))))
940 (defun texinfo-copy-menu ()
941 "Return the entries of an existing menu as a list.
942 Start with point just after the word `menu' in the `@menu' line
943 and leave point on the line before the `@end menu' line."
944 (let* (this-menu-list
945 (end-of-menu (texinfo-menu-end)) ; position of end of `@end menu'
946 (last-entry (save-excursion ; position of beginning of
947 ; last `* ' entry
948 (goto-char end-of-menu)
949 ;; handle multi-line description
950 (if (not (re-search-backward "^\\* " nil t))
951 (error "No entries in menu."))
952 (point))))
953 (while (< (point) last-entry)
954 (if (re-search-forward "^\\* " end-of-menu t)
955 (progn
956 (setq this-menu-list
957 (cons
958 (buffer-substring
959 (point)
960 ;; copy multi-line descriptions
961 (save-excursion
962 (re-search-forward "\\(^\\* \\|^@e\\)" nil t)
963 (- (point) 3)))
964 this-menu-list)))))
965 this-menu-list))
968 ;;; Determining the hierarchical level in the texinfo file
970 (defun texinfo-specific-section-type ()
971 "Return the specific type of next section, as a string.
972 For example, \"unnumberedsubsec\". Return \"top\" for top node.
974 Searches forward for a section. Hence, point must be before the
975 section whose type will be found. Does not move point. Signal an
976 error if the node is not the top node and a section is not found."
977 (let ((case-fold-search t))
978 (save-excursion
979 (cond
980 ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
981 ;;; Following search limit by cph but causes a bug
982 ;;; (save-excursion
983 ;;; (end-of-line)
984 ;;; (point))
987 "top")
988 ((re-search-forward texinfo-section-types-regexp nil t)
989 (buffer-substring-no-properties
990 (progn (beginning-of-line) ; copy its name
991 (1+ (point)))
992 (progn (forward-word 1)
993 (point))))
995 (error
996 "texinfo-specific-section-type: Chapter or section not found."))))))
998 (defun texinfo-hierarchic-level ()
999 "Return the general hierarchal level of the next node in a texinfo file.
1000 Thus, a subheading or appendixsubsec is of type subsection."
1001 (let ((case-fold-search t))
1002 (cdr (assoc
1003 (texinfo-specific-section-type)
1004 texinfo-section-to-generic-alist))))
1007 ;;; Locating the major positions
1009 (defun texinfo-update-menu-region-beginning (level)
1010 "Locate beginning of higher level section this section is within.
1011 Return position of the beginning of the node line; do not move point.
1012 Thus, if this level is subsection, searches backwards for section node.
1013 Only argument is a string of the general type of section."
1014 (let ((case-fold-search t))
1015 ;; !! Known bug: if section immediately follows top node, this
1016 ;; returns the beginning of the buffer as the beginning of the
1017 ;; higher level section.
1018 (cond
1019 ((or (string-equal "top" level)
1020 (string-equal "chapter" level))
1021 (save-excursion
1022 (goto-char (point-min))
1023 (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t)
1024 (beginning-of-line)
1025 (point)))
1027 (save-excursion
1028 (re-search-backward
1029 (concat
1030 "\\(^@node\\).*\n" ; match node line
1031 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1032 "\\|" ; or
1033 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
1034 (eval
1035 (cdr (assoc level texinfo-update-menu-higher-regexps))))
1037 'goto-beginning)
1038 (point))))))
1040 (defun texinfo-update-menu-region-end (level)
1041 "Locate end of higher level section this section is within.
1042 Return position; do not move point. Thus, if this level is a
1043 subsection, find the node for the section this subsection is within.
1044 If level is top or chapter, returns end of file. Only argument is a
1045 string of the general type of section."
1046 (let ((case-fold-search t))
1047 (save-excursion
1048 (if (re-search-forward
1049 (concat
1050 "\\(^@node\\).*\n" ; match node line
1051 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1052 "\\|" ; or
1053 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
1054 (eval
1055 ;; Never finds end of level above chapter so goes to end.
1056 (cdr (assoc level texinfo-update-menu-higher-regexps))))
1058 'goto-end)
1059 (match-beginning 1)
1060 (point-max)))))
1062 (defun texinfo-menu-first-node (beginning end)
1063 "Locate first node of the section the menu will be placed in.
1064 Return position; do not move point.
1065 The menu will be located just before this position.
1067 First argument is the position of the beginning of the section in
1068 which the menu will be located; second argument is the position of the
1069 end of that region; it limits the search."
1071 (save-excursion
1072 (goto-char beginning)
1073 (forward-line 1)
1074 (re-search-forward "^@node" end t)
1075 (beginning-of-line)
1076 (point)))
1079 ;;; Alists and regular expressions for defining hierarchical levels
1081 (defvar texinfo-section-to-generic-alist
1082 '(("top" . "top")
1084 ("chapter" . "chapter")
1085 ("unnumbered" . "chapter")
1086 ("majorheading" . "chapter")
1087 ("chapheading" . "chapter")
1088 ("appendix" . "chapter")
1090 ("section" . "section")
1091 ("unnumberedsec" . "section")
1092 ("heading" . "section")
1093 ("appendixsec" . "section")
1095 ("subsection" . "subsection")
1096 ("unnumberedsubsec" . "subsection")
1097 ("subheading" . "subsection")
1098 ("appendixsubsec" . "subsection")
1100 ("subsubsection" . "subsubsection")
1101 ("unnumberedsubsubsec" . "subsubsection")
1102 ("subsubheading" . "subsubsection")
1103 ("appendixsubsubsec" . "subsubsection"))
1104 "*An alist of specific and corresponding generic Texinfo section types.
1105 The keys are strings specifying specific types of section; the values
1106 are strings of their corresponding general types.")
1108 ;; We used to look for just sub, but that found @subtitle.
1109 (defvar texinfo-section-types-regexp
1110 "^@\\(chapter \\|sect\\|subs\\|subh\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
1111 "Regexp matching chapter, section, other headings (but not the top node).")
1113 (defvar texinfo-chapter-level-regexp
1114 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
1115 "Regular expression matching just the Texinfo chapter level headings.")
1117 (defvar texinfo-section-level-regexp
1118 "section\\|unnumberedsec\\|heading \\|appendixsec"
1119 "Regular expression matching just the Texinfo section level headings.")
1121 (defvar texinfo-subsection-level-regexp
1122 "subsection\\|unnumberedsubsec\\|subheading\\|appendixsubsec"
1123 "Regular expression matching just the Texinfo subsection level headings.")
1125 (defvar texinfo-subsubsection-level-regexp
1126 "subsubsection\\|unnumberedsubsubsec\\|subsubheading\\|appendixsubsubsec"
1127 "Regular expression matching just the Texinfo subsubsection level headings.")
1129 (defvar texinfo-update-menu-same-level-regexps
1130 '(("top" . "top[ \t]+")
1131 ("chapter" .
1132 (concat "\\(^@\\)\\(" texinfo-chapter-level-regexp "\\)[ \t]*"))
1133 ("section" .
1134 (concat "\\(^@\\)\\(" texinfo-section-level-regexp "\\)[ \t]*"))
1135 ("subsection" .
1136 (concat "\\(^@\\)\\(" texinfo-subsection-level-regexp "\\)[ \t]+"))
1137 ("subsubsection" .
1138 (concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp "\\)[ \t]+")))
1139 "*Regexps for searching for same level sections in a Texinfo file.
1140 The keys are strings specifying the general hierarchical level in the
1141 document; the values are regular expressions.")
1143 (defvar texinfo-update-menu-higher-regexps
1144 '(("top" . "^@node [ \t]*DIR")
1145 ("chapter" . "^@node [ \t]*top[ \t]*\\(,\\|$\\)")
1146 ("section" .
1147 (concat
1148 "\\(^@\\("
1149 texinfo-chapter-level-regexp
1150 "\\)[ \t]*\\)"))
1151 ("subsection" .
1152 (concat
1153 "\\(^@\\("
1154 texinfo-section-level-regexp
1155 "\\|"
1156 texinfo-chapter-level-regexp
1157 "\\)[ \t]*\\)"))
1158 ("subsubsection" .
1159 (concat
1160 "\\(^@\\("
1161 texinfo-subsection-level-regexp
1162 "\\|"
1163 texinfo-section-level-regexp
1164 "\\|"
1165 texinfo-chapter-level-regexp
1166 "\\)[ \t]*\\)")))
1167 "*Regexps for searching for higher level sections in a Texinfo file.
1168 The keys are strings specifying the general hierarchical level in the
1169 document; the values are regular expressions.")
1171 (defvar texinfo-update-menu-lower-regexps
1172 '(("top" .
1173 (concat
1174 "\\(^@\\("
1175 texinfo-chapter-level-regexp
1176 "\\|"
1177 texinfo-section-level-regexp
1178 "\\|"
1179 texinfo-subsection-level-regexp
1180 "\\|"
1181 texinfo-subsubsection-level-regexp
1182 "\\)[ \t]*\\)"))
1183 ("chapter" .
1184 (concat
1185 "\\(^@\\("
1186 texinfo-section-level-regexp
1187 "\\|"
1188 texinfo-subsection-level-regexp
1189 "\\|"
1190 texinfo-subsubsection-level-regexp
1191 "\\)[ \t]*\\)"))
1192 ("section" .
1193 (concat
1194 "\\(^@\\("
1195 texinfo-subsection-level-regexp
1196 "\\|"
1197 texinfo-subsubsection-level-regexp
1198 "\\)[ \t]+\\)"))
1199 ("subsection" .
1200 (concat
1201 "\\(^@\\("
1202 texinfo-subsubsection-level-regexp
1203 "\\)[ \t]+\\)"))
1204 ("subsubsection" . "nothing lower"))
1205 "*Regexps for searching for lower level sections in a Texinfo file.
1206 The keys are strings specifying the general hierarchical level in the
1207 document; the values are regular expressions.")
1210 ;;; Updating a node
1212 ;;;###autoload
1213 (defun texinfo-update-node (&optional beginning end)
1214 "Without any prefix argument, update the node in which point is located.
1215 Interactively, a prefix argument means to operate on the region.
1217 The functions for creating or updating nodes and menus, and their
1218 keybindings, are:
1220 texinfo-update-node (&optional beginning end) \\[texinfo-update-node]
1221 texinfo-every-node-update () \\[texinfo-every-node-update]
1222 texinfo-sequential-node-update (&optional region-p)
1224 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
1225 texinfo-all-menus-update () \\[texinfo-all-menus-update]
1226 texinfo-master-menu ()
1228 texinfo-indent-menu-description (column &optional region-p)
1230 The `texinfo-column-for-description' variable specifies the column to
1231 which menu descriptions are indented. Its default value is 32."
1233 (interactive
1234 (if prefix-arg
1235 (list (point) (mark))))
1236 (if (null beginning)
1237 ;; Update a single node.
1238 (let ((auto-fill-function nil) (auto-fill-hook nil))
1239 (if (not (re-search-backward "^@node" (point-min) t))
1240 (error "Node line not found before this position"))
1241 (texinfo-update-the-node)
1242 (message "Done...updated the node. You may save the buffer."))
1243 ;; else
1244 (let ((auto-fill-function nil)
1245 (auto-fill-hook nil))
1246 (save-excursion
1247 (save-restriction
1248 (narrow-to-region beginning end)
1249 (goto-char (point-min))
1250 (while (re-search-forward "^@node" (point-max) t)
1251 (beginning-of-line)
1252 (texinfo-update-the-node))
1253 (goto-char (point-max))
1254 (message "Done...nodes updated in region. You may save the buffer."))))))
1256 ;;;###autoload
1257 (defun texinfo-every-node-update ()
1258 "Update every node in a Texinfo file."
1259 (interactive)
1260 (save-excursion
1261 (texinfo-update-node (point-min) (point-max))
1262 (message "Done...updated every node. You may save the buffer.")))
1264 (defun texinfo-update-the-node ()
1265 "Update one node. Point must be at the beginning of node line.
1266 Leave point at the end of the node line."
1267 (texinfo-check-for-node-name)
1268 (texinfo-delete-existing-pointers)
1269 (message "Updating node: %s ... " (texinfo-copy-node-name))
1270 (save-restriction
1271 (widen)
1272 (let*
1273 ((case-fold-search t)
1274 (level (texinfo-hierarchic-level))
1275 (beginning (texinfo-update-menu-region-beginning level))
1276 (end (texinfo-update-menu-region-end level)))
1277 (if (string-equal level "top")
1278 (texinfo-top-pointer-case)
1279 ;; else
1280 (texinfo-insert-pointer beginning end level 'next)
1281 (texinfo-insert-pointer beginning end level 'previous)
1282 (texinfo-insert-pointer beginning end level 'up)
1283 (texinfo-clean-up-node-line)))))
1285 (defun texinfo-top-pointer-case ()
1286 "Insert pointers in the Top node. This is a special case.
1288 The `Next' pointer is a pointer to a chapter or section at a lower
1289 hierarchical level in the file. The `Previous' and `Up' pointers are
1290 to `(dir)'. Point must be at the beginning of the node line, and is
1291 left at the end of the node line."
1293 (texinfo-clean-up-node-line)
1294 (insert ", "
1295 (save-excursion
1296 ;; There may be an @chapter or other such command between
1297 ;; the top node line and the next node line, as a title
1298 ;; for an `ifinfo' section. This @chapter command must
1299 ;; must be skipped. So the procedure is to search for
1300 ;; the next `@node' line, and then copy its name.
1301 (if (re-search-forward "^@node" nil t)
1302 (progn
1303 (beginning-of-line)
1304 (texinfo-copy-node-name))
1305 " "))
1306 ", (dir), (dir)"))
1308 (defun texinfo-check-for-node-name ()
1309 "Determine whether the node has a node name. Prompt for one if not.
1310 Point must be at beginning of node line. Does not move point."
1311 (save-excursion
1312 (let ((initial (texinfo-copy-next-section-title)))
1313 ;; This is not clean. Use `interactive' to read the arg.
1314 (forward-word 1) ; skip over node command
1315 (skip-chars-forward " \t") ; and over spaces
1316 (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what Info looks for
1317 ; alternatively, use "[a-zA-Z]+"
1318 (let ((node-name
1319 (read-from-minibuffer
1320 "Node name (use no @, commas, colons, or apostrophes): "
1321 initial)))
1322 (insert " " node-name))))))
1324 (defun texinfo-delete-existing-pointers ()
1325 "Delete `Next', `Previous', and `Up' pointers.
1326 Starts from the current position of the cursor, and searches forward
1327 on the line for a comma and if one is found, deletes the rest of the
1328 line, including the comma. Leaves point at beginning of line."
1329 (let ((eol-point (save-excursion (end-of-line) (point))))
1330 (if (search-forward "," eol-point t)
1331 (delete-region (1- (point)) eol-point)))
1332 (beginning-of-line))
1334 (defun texinfo-find-pointer (beginning end level direction)
1335 "Move point to section associated with next, previous, or up pointer.
1336 Return type of pointer (either 'normal or 'no-pointer).
1338 The first and second arguments bound the search for a pointer to the
1339 beginning and end, respectively, of the enclosing higher level
1340 section. The third argument is a string specifying the general kind
1341 of section such as \"chapter\" or \"section\". When looking for the
1342 `Next' pointer, the section found will be at the same hierarchical
1343 level in the Texinfo file; when looking for the `Previous' pointer,
1344 the section found will be at the same or higher hierarchical level in
1345 the Texinfo file; when looking for the `Up' pointer, the section found
1346 will be at some level higher in the Texinfo file. The fourth argument
1347 \(one of 'next, 'previous, or 'up\) specifies whether to find the
1348 `Next', `Previous', or `Up' pointer."
1349 (let ((case-fold-search t))
1350 (cond ((eq direction 'next)
1351 (forward-line 3) ; skip over current node
1352 ;; Search for section commands accompanied by node lines;
1353 ;; ignore section commands in the middle of nodes.
1354 (if (re-search-forward
1355 ;; A `Top' node is never a next pointer, so won't find it.
1356 (concat
1357 ;; Match node line.
1358 "\\(^@node\\).*\n"
1359 ;; Match comment or ifinfo line, if any
1360 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1361 (eval
1362 (cdr (assoc level texinfo-update-menu-same-level-regexps))))
1365 'normal
1366 'no-pointer))
1367 ((eq direction 'previous)
1368 (if (re-search-backward
1369 (concat
1370 "\\("
1371 ;; Match node line.
1372 "\\(^@node\\).*\n"
1373 ;; Match comment or ifinfo line, if any
1374 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1375 (eval
1376 (cdr (assoc level texinfo-update-menu-same-level-regexps)))
1377 "\\|"
1378 ;; Match node line.
1379 "\\(^@node\\).*\n"
1380 ;; Match comment or ifinfo line, if any
1381 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1382 (eval
1383 (cdr (assoc level texinfo-update-menu-higher-regexps)))
1384 "\\|"
1385 ;; Handle `Top' node specially.
1386 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1387 "\\)")
1388 beginning
1390 'normal
1391 'no-pointer))
1392 ((eq direction 'up)
1393 (if (re-search-backward
1394 (concat
1395 "\\("
1396 ;; Match node line.
1397 "\\(^@node\\).*\n"
1398 ;; Match comment or ifinfo line, if any
1399 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1400 (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
1401 "\\|"
1402 ;; Handle `Top' node specially.
1403 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1404 "\\)")
1405 (save-excursion
1406 (goto-char beginning)
1407 (beginning-of-line)
1408 (point))
1410 'normal
1411 'no-pointer))
1413 (error "texinfo-find-pointer: lack proper arguments")))))
1415 (defun texinfo-pointer-name (kind)
1416 "Return the node name preceding the section command.
1417 The argument is the kind of section, either normal or no-pointer."
1418 (let (name)
1419 (cond ((eq kind 'normal)
1420 (end-of-line) ; this handles prev node top case
1421 (re-search-backward ; when point is already
1422 "^@node" ; at the beginning of @node line
1423 (save-excursion (forward-line -3))
1425 (setq name (texinfo-copy-node-name)))
1426 ((eq kind 'no-pointer)
1427 (setq name " "))) ; put a blank in the pointer slot
1428 name))
1430 (defun texinfo-insert-pointer (beginning end level direction)
1431 "Insert the `Next', `Previous' or `Up' node name at point.
1432 Move point forward.
1434 The first and second arguments bound the search for a pointer to the
1435 beginning and end, respectively, of the enclosing higher level
1436 section. The third argument is the hierarchical level of the Texinfo
1437 file, a string such as \"section\". The fourth argument is direction
1438 towards which the pointer is directed, one of `next, `previous, or
1439 'up."
1441 (end-of-line)
1442 (insert
1443 ", "
1444 (save-excursion
1445 (texinfo-pointer-name
1446 (texinfo-find-pointer beginning end level direction)))))
1448 (defun texinfo-clean-up-node-line ()
1449 "Remove extra commas, if any, at end of node line."
1450 (end-of-line)
1451 (skip-chars-backward ", ")
1452 (delete-region (point) (save-excursion (end-of-line) (point))))
1455 ;;; Updating nodes sequentially
1456 ; These sequential update functions insert `Next' or `Previous'
1457 ; pointers that point to the following or preceding nodes even if they
1458 ; are at higher or lower hierarchical levels. This means that if a
1459 ; section contains one or more subsections, the section's `Next'
1460 ; pointer will point to the subsection and not the following section.
1461 ; (The subsection to which `Next' points will most likely be the first
1462 ; item on the section's menu.)
1464 ;;;###autoload
1465 (defun texinfo-sequential-node-update (&optional region-p)
1466 "Update one node (or many) in a Texinfo file with sequential pointers.
1468 This function causes the `Next' or `Previous' pointer to point to the
1469 immediately preceding or following node, even if it is at a higher or
1470 lower hierarchical level in the document. Continually pressing `n' or
1471 `p' takes you straight through the file.
1473 Without any prefix argument, update the node in which point is located.
1474 Non-nil argument (prefix, if interactive) means update the nodes in the
1475 marked region.
1477 This command makes it awkward to navigate among sections and
1478 subsections; it should be used only for those documents that are meant
1479 to be read like a novel rather than a reference, and for which the
1480 Info `g*' command is inadequate."
1482 (interactive "P")
1483 (if (not region-p)
1484 ;; update a single node
1485 (let ((auto-fill-function nil) (auto-fill-hook nil))
1486 (if (not (re-search-backward "^@node" (point-min) t))
1487 (error "Node line not found before this position."))
1488 (texinfo-sequentially-update-the-node)
1489 (message
1490 "Done...sequentially updated the node . You may save the buffer."))
1491 ;; else
1492 (let ((auto-fill-function nil)
1493 (auto-fill-hook nil)
1494 (beginning (region-beginning))
1495 (end (region-end)))
1496 (if (= end beginning)
1497 (error "Please mark a region!"))
1498 (save-restriction
1499 (narrow-to-region beginning end)
1500 (goto-char beginning)
1501 (push-mark (point) t)
1502 (while (re-search-forward "^@node" (point-max) t)
1503 (beginning-of-line)
1504 (texinfo-sequentially-update-the-node))
1505 (message
1506 "Done...updated the nodes in sequence. You may save the buffer.")))))
1508 (defun texinfo-sequentially-update-the-node ()
1509 "Update one node such that the pointers are sequential.
1510 A `Next' or `Previous' pointer points to any preceding or following node,
1511 regardless of its hierarchical level."
1513 (texinfo-check-for-node-name)
1514 (texinfo-delete-existing-pointers)
1515 (message
1516 "Sequentially updating node: %s ... " (texinfo-copy-node-name))
1517 (save-restriction
1518 (widen)
1519 (let*
1520 ((case-fold-search t)
1521 (level (texinfo-hierarchic-level)))
1522 (if (string-equal level "top")
1523 (texinfo-top-pointer-case)
1524 ;; else
1525 (texinfo-sequentially-insert-pointer level 'next)
1526 (texinfo-sequentially-insert-pointer level 'previous)
1527 (texinfo-sequentially-insert-pointer level 'up)
1528 (texinfo-clean-up-node-line)))))
1530 (defun texinfo-sequentially-find-pointer (level direction)
1531 "Find next or previous pointer sequentially in Texinfo file, or up pointer.
1532 Move point to section associated with the pointer. Find point even if
1533 it is in a different section.
1535 Return type of pointer (either 'normal or 'no-pointer).
1537 The first argument is a string specifying the general kind of section
1538 such as \"chapter\" or \"section\". The section found will be at the
1539 same hierarchical level in the Texinfo file, or, in the case of the up
1540 pointer, some level higher. The second argument (one of 'next,
1541 'previous, or 'up) specifies whether to find the `Next', `Previous',
1542 or `Up' pointer."
1543 (let ((case-fold-search t))
1544 (cond ((eq direction 'next)
1545 (forward-line 3) ; skip over current node
1546 (if (re-search-forward
1547 texinfo-section-types-regexp
1548 (point-max)
1550 'normal
1551 'no-pointer))
1552 ((eq direction 'previous)
1553 (if (re-search-backward
1554 texinfo-section-types-regexp
1555 (point-min)
1557 'normal
1558 'no-pointer))
1559 ((eq direction 'up)
1560 (if (re-search-backward
1561 (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
1562 beginning
1564 'normal
1565 'no-pointer))
1567 (error "texinfo-sequential-find-pointer: lack proper arguments")))))
1569 (defun texinfo-sequentially-insert-pointer (level direction)
1570 "Insert the `Next', `Previous' or `Up' node name at point.
1571 Move point forward.
1573 The first argument is the hierarchical level of the Texinfo file, a
1574 string such as \"section\". The second argument is direction, one of
1575 `next, `previous, or 'up."
1577 (end-of-line)
1578 (insert
1579 ", "
1580 (save-excursion
1581 (texinfo-pointer-name
1582 (texinfo-sequentially-find-pointer level direction)))))
1585 ;;; Inserting `@node' lines
1586 ; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
1587 ; before the `@chapter', `@section', and such like lines of a region
1588 ; in a Texinfo file.
1590 (defun texinfo-insert-node-lines (beginning end &optional title-p)
1591 "Insert missing `@node' lines in region of Texinfo file.
1592 Non-nil argument (prefix, if interactive) means also to insert the
1593 section titles as node names; and also to insert the section titles as
1594 node names in pre-existing @node lines that lack names."
1595 (interactive "r\nP")
1597 ;; Use marker; after inserting node lines, leave point at end of
1598 ;; region and mark at beginning.
1600 (let (beginning-marker end-marker title last-section-position)
1602 ;; Save current position on mark ring and set mark to end.
1603 (push-mark end t)
1604 (setq end-marker (mark-marker))
1606 (goto-char beginning)
1607 (while (re-search-forward
1608 texinfo-section-types-regexp
1609 end-marker
1610 'end)
1611 ;; Copy title if desired.
1612 (if title-p
1613 (progn
1614 (beginning-of-line)
1615 (forward-word 1)
1616 (skip-chars-forward " \t")
1617 (setq title (buffer-substring
1618 (point)
1619 (save-excursion (end-of-line) (point))))))
1620 ;; Insert node line if necessary.
1621 (if (re-search-backward
1622 "^@node"
1623 ;; Avoid finding previous node line if node lines are close.
1624 (or last-section-position
1625 (save-excursion (forward-line -2) (point))) t)
1626 ;; @node is present, and point at beginning of that line
1627 (forward-word 1) ; Leave point just after @node.
1628 ;; Else @node missing; insert one.
1629 (beginning-of-line) ; Beginning of `@section' line.
1630 (insert "@node\n")
1631 (backward-char 1)) ; Leave point just after `@node'.
1632 ;; Insert title if desired.
1633 (if title-p
1634 (progn
1635 (skip-chars-forward " \t")
1636 ;; Use regexp based on what info looks for
1637 ;; (alternatively, use "[a-zA-Z]+");
1638 ;; this means we only insert a title if none exists.
1639 (if (not (looking-at "[^,\t\n ]+"))
1640 (progn
1641 (beginning-of-line)
1642 (forward-word 1)
1643 (insert " " title)
1644 (message "Inserted title %s ... " title)))))
1645 ;; Go forward beyond current section title.
1646 (re-search-forward texinfo-section-types-regexp
1647 (save-excursion (forward-line 3) (point)) t)
1648 (setq last-section-position (point))
1649 (forward-line 1))
1651 ;; Leave point at end of region, mark at beginning.
1652 (set-mark beginning)
1654 (if title-p
1655 (message
1656 "Done inserting node lines and titles. You may save the buffer.")
1657 (message "Done inserting node lines. You may save the buffer."))))
1660 ;;; Update and create menus for multi-file Texinfo sources
1662 ;; 1. M-x texinfo-multiple-files-update
1664 ;; Read the include file list of an outer Texinfo file and
1665 ;; update all highest level nodes in the files listed and insert a
1666 ;; main menu in the outer file after its top node.
1668 ;; 2. C-u M-x texinfo-multiple-files-update
1670 ;; Same as 1, but insert a master menu. (Saves reupdating lower
1671 ;; level menus and nodes.) This command simply reads every menu,
1672 ;; so if the menus are wrong, the master menu will be wrong.
1673 ;; Similarly, if the lower level node pointers are wrong, they
1674 ;; will stay wrong.
1676 ;; 3. C-u 2 M-x texinfo-multiple-files-update
1678 ;; Read the include file list of an outer Texinfo file and
1679 ;; update all nodes and menus in the files listed and insert a
1680 ;; master menu in the outer file after its top node.
1682 ;;; Note: these functions:
1684 ;;; * Do not save or delete any buffers. You may fill up your memory.
1685 ;;; * Do not handle any pre-existing nodes in outer file.
1686 ;;; Hence, you may need a file for indices.
1689 ;;; Auxiliary functions for multiple file updating
1691 (defun texinfo-multi-file-included-list (outer-file)
1692 "Return a list of the included files in OUTER-FILE."
1693 (let ((included-file-list (list outer-file))
1694 start)
1695 (save-excursion
1696 (switch-to-buffer (find-file-noselect outer-file))
1697 (widen)
1698 (goto-char (point-min))
1699 (while (re-search-forward "^@include" nil t)
1700 (skip-chars-forward " \t")
1701 (setq start (point))
1702 (end-of-line)
1703 (skip-chars-backward " \t")
1704 (setq included-file-list
1705 (cons (buffer-substring start (point))
1706 included-file-list)))
1707 (nreverse included-file-list))))
1709 (defun texinfo-copy-next-section-title ()
1710 "Return the name of the immediately following section as a string.
1712 Start with point at the beginning of the node line. Leave point at the
1713 same place. If there is no title, returns an empty string."
1715 (save-excursion
1716 (end-of-line)
1717 (let ((node-end (or
1718 (save-excursion
1719 (if (re-search-forward "\\(^@node\\)" nil t)
1720 (match-beginning 0)))
1721 (point-max))))
1722 (if (re-search-forward texinfo-section-types-regexp node-end t)
1723 (progn
1724 (beginning-of-line)
1725 ;; copy title
1726 (let ((title
1727 (buffer-substring
1728 (progn (forward-word 1) ; skip over section type
1729 (skip-chars-forward " \t") ; and over spaces
1730 (point))
1731 (progn (end-of-line) (point)))))
1732 title))
1733 ""))))
1735 (defun texinfo-multi-file-update (files &optional update-everything)
1736 "Update first node pointers in each file in FILES.
1737 Return a list of the node names.
1739 The first file in the list is an outer file; the remaining are
1740 files included in the outer file with `@include' commands.
1742 If optional arg UPDATE-EVERYTHING non-nil, update every menu and
1743 pointer in each of the included files.
1745 Also update the `Top' level node pointers of the outer file.
1747 Requirements:
1749 * the first file in the FILES list must be the outer file,
1750 * each of the included files must contain exactly one highest
1751 hierarchical level node,
1752 * this node must be the first node in the included file,
1753 * each highest hierarchical level node must be of the same type.
1755 Thus, normally, each included file contains one, and only one,
1756 chapter."
1758 ; The menu-list has the form:
1760 ; \(\(\"node-name1\" . \"title1\"\)
1761 ; \(\"node-name2\" . \"title2\"\) ... \)
1763 ; However, there does not need to be a title field and this function
1764 ; does not fill it; however a comment tells you how to do so.
1765 ; You would use the title field if you wanted to insert titles in the
1766 ; description slot of a menu as a description.
1768 (let ((case-fold-search t)
1769 menu-list)
1771 ;; Find the name of the first node of the first included file.
1772 (switch-to-buffer (find-file-noselect (car (cdr files))))
1773 (widen)
1774 (goto-char (point-min))
1775 (if (not (re-search-forward "^@node" nil t))
1776 (error "No `@node' line found in %s !" (buffer-name)))
1777 (beginning-of-line)
1778 (texinfo-check-for-node-name)
1779 (setq next-node-name (texinfo-copy-node-name))
1781 (setq menu-list
1782 (cons (cons
1783 next-node-name
1784 (prog1 "" (forward-line 1)))
1785 ;; Use following to insert section titles automatically.
1786 ;; (texinfo-copy-next-section-title)
1787 menu-list))
1789 ;; Go to outer file
1790 (switch-to-buffer (find-file-noselect (car files)))
1791 (goto-char (point-min))
1792 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
1793 (error "This buffer needs a Top node!"))
1794 (beginning-of-line)
1795 (texinfo-delete-existing-pointers)
1796 (end-of-line)
1797 (insert ", " next-node-name ", (dir), (dir)")
1798 (beginning-of-line)
1799 (setq previous-node-name "Top")
1800 (setq files (cdr files))
1802 (while files
1804 (if (not (cdr files))
1805 ;; No next file
1806 (setq next-node-name "")
1807 ;; Else,
1808 ;; find the name of the first node in the next file.
1809 (switch-to-buffer (find-file-noselect (car (cdr files))))
1810 (widen)
1811 (goto-char (point-min))
1812 (if (not (re-search-forward "^@node" nil t))
1813 (error "No `@node' line found in %s !" (buffer-name)))
1814 (beginning-of-line)
1815 (texinfo-check-for-node-name)
1816 (setq next-node-name (texinfo-copy-node-name))
1817 (setq menu-list
1818 (cons (cons
1819 next-node-name
1820 (prog1 "" (forward-line 1)))
1821 ;; Use following to insert section titles automatically.
1822 ;; (texinfo-copy-next-section-title)
1823 menu-list)))
1825 ;; Go to node to be updated.
1826 (switch-to-buffer (find-file-noselect (car files)))
1827 (goto-char (point-min))
1828 (if (not (re-search-forward "^@node" nil t))
1829 (error "No `@node' line found in %s !" (buffer-name)))
1830 (beginning-of-line)
1832 ;; Update other menus and nodes if requested.
1833 (if update-everything (texinfo-all-menus-update t))
1835 (beginning-of-line)
1836 (texinfo-delete-existing-pointers)
1837 (end-of-line)
1838 (insert ", " next-node-name ", " previous-node-name ", " up-node-name)
1840 (beginning-of-line)
1841 (setq previous-node-name (texinfo-copy-node-name))
1843 (setq files (cdr files)))
1844 (nreverse menu-list)))
1846 (defun texinfo-multi-files-insert-main-menu (menu-list)
1847 "Insert formatted main menu at point.
1848 Indents the first line of the description, if any, to the value of
1849 texinfo-column-for-description."
1851 (insert "@menu\n")
1852 (while menu-list
1853 ;; Every menu entry starts with a star and a space.
1854 (insert "* ")
1856 ;; Insert the node name (and menu entry name, if present).
1857 (let ((node-part (car (car menu-list))))
1858 (if (stringp node-part)
1859 ;; "Double colon" entry line; menu entry and node name are the same,
1860 (insert (format "%s::" node-part))
1861 ;; "Single colon" entry line; menu entry and node name are different.
1862 (insert (format "%s: %s." (car node-part) (cdr node-part)))))
1864 ;; Insert the description, if present.
1865 (if (cdr (car menu-list))
1866 (progn
1867 ;; Move to right place.
1868 (indent-to texinfo-column-for-description 2)
1869 ;; Insert description.
1870 (insert (format "%s" (cdr (car menu-list))))))
1872 (insert "\n") ; end this menu entry
1873 (setq menu-list (cdr menu-list)))
1874 (insert "@end menu"))
1876 (defun texinfo-multi-file-master-menu-list (files-list)
1877 "Return master menu list from files in FILES-LIST.
1878 Menu entries in each file collected using `texinfo-master-menu-list'.
1880 The first file in FILES-LIST must be the outer file; the others must
1881 be the files included within it. A main menu must already exist."
1882 (save-excursion
1883 (let (master-menu-list)
1884 (while files-list
1885 (switch-to-buffer (find-file-noselect (car files-list)))
1886 (message "Working on: %s " (current-buffer))
1887 (goto-char (point-min))
1888 (setq master-menu-list
1889 (append master-menu-list (texinfo-master-menu-list)))
1890 (setq files-list (cdr files-list)))
1891 master-menu-list)))
1894 ;;; The multiple-file update function
1896 (defun texinfo-multiple-files-update
1897 (outer-file &optional update-everything make-master-menu)
1898 "Update first node pointers in each file included in OUTER-FILE;
1899 create or update the `Top' level node pointers and the main menu in
1900 the outer file that refers to such nodes. This does not create or
1901 update menus or pointers within the included files.
1903 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
1904 insert a master menu in OUTER-FILE in addition to creating or updating
1905 pointers in the first @node line in each included file and creating or
1906 updating the `Top' level node pointers of the outer file. This does
1907 not create or update other menus and pointers within the included
1908 files.
1910 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
1911 interactive), update all the menus and all the `Next', `Previous', and
1912 `Up' pointers of all the files included in OUTER-FILE before inserting
1913 a master menu in OUTER-FILE. Also, update the `Top' level node
1914 pointers of OUTER-FILE.
1916 Notes:
1918 * this command does NOT save any files--you must save the
1919 outer file and any modified, included files.
1921 * except for the `Top' node, this command does NOT handle any
1922 pre-existing nodes in the outer file; hence, indices must be
1923 enclosed in an included file.
1925 Requirements:
1927 * each of the included files must contain exactly one highest
1928 hierarchical level node,
1929 * this highest node must be the first node in the included file,
1930 * each highest hierarchical level node must be of the same type.
1932 Thus, normally, each included file contains one, and only one,
1933 chapter."
1935 (interactive (cons
1936 (read-string
1937 "Name of outer `include' file: "
1938 (buffer-file-name))
1939 (cond ((not current-prefix-arg)
1940 '(nil nil))
1941 ((listp current-prefix-arg)
1942 '(t nil)) ; make-master-menu
1943 ((numberp current-prefix-arg)
1944 '(t t)) ; update-everything
1947 (let* ((included-file-list (texinfo-multi-file-included-list outer-file))
1948 (files included-file-list)
1949 main-menu-list
1950 next-node-name
1951 previous-node-name
1952 (up-node-name "Top"))
1954 ;;; Update the pointers
1955 ;;; and collect the names of the nodes and titles
1956 (setq main-menu-list (texinfo-multi-file-update files update-everything))
1958 ;;; Insert main menu
1960 ;; Go to outer file
1961 (switch-to-buffer (find-file-noselect (car included-file-list)))
1962 (if (texinfo-old-menu-p
1963 (point-min)
1964 (save-excursion
1965 (re-search-forward "^@include")
1966 (beginning-of-line)
1967 (point)))
1969 ;; If found, leave point after word `menu' on the `@menu' line.
1970 (progn
1971 (texinfo-incorporate-descriptions main-menu-list)
1972 ;; Delete existing menu.
1973 (beginning-of-line)
1974 (delete-region
1975 (point)
1976 (save-excursion (re-search-forward "^@end menu") (point)))
1977 ;; Insert main menu
1978 (texinfo-multi-files-insert-main-menu main-menu-list))
1980 ;; Else no current menu; insert it before `@include'
1981 (texinfo-multi-files-insert-main-menu main-menu-list))
1983 ;;; Insert master menu
1985 (if make-master-menu
1986 (progn
1987 ;; First, removing detailed part of any pre-existing master menu
1988 (goto-char (point-min))
1989 (if (re-search-forward texinfo-master-menu-header nil t)
1990 ;; Remove detailed master menu listing
1991 (progn
1992 (goto-char (match-beginning 0))
1993 (let ((end-of-detailed-menu-descriptions
1994 (save-excursion ; beginning of end menu line
1995 (goto-char (texinfo-menu-end))
1996 (beginning-of-line) (forward-char -1)
1997 (point))))
1998 (delete-region (point) end-of-detailed-menu-descriptions))))
2000 ;; Create a master menu and insert it
2001 (texinfo-insert-master-menu-list
2002 (texinfo-multi-file-master-menu-list
2003 included-file-list)))))
2005 ;; Remove unwanted extra lines.
2006 (save-excursion
2007 (goto-char (point-min))
2009 (re-search-forward "^@menu")
2010 (forward-line -1)
2011 (insert "\n") ; Ensure at least one blank line.
2012 (delete-blank-lines)
2014 (re-search-forward "^@end menu")
2015 (forward-line 1)
2016 (insert "\n") ; Ensure at least one blank line.
2017 (delete-blank-lines))
2019 (message "Multiple files updated."))
2022 ;;; Place `provide' at end of file.
2023 (provide 'texnfo-upd)
2025 ;;; texnfo-upd.el ends here