Move the (require 'cl) to the front of the
[emacs.git] / lisp / textmodes / texnfo-upd.el
blob0c59eadfcc75c9f7216523fa236befe771a112c7
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@gnu.org
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:
44 ;; texinfo-update-node (&optional beginning end)
45 ;; texinfo-every-node-update ()
46 ;; texinfo-sequential-node-update (&optional region-p)
48 ;; texinfo-make-menu (&optional beginning end)
49 ;; texinfo-all-menus-update ()
50 ;; texinfo-master-menu ()
52 ;; texinfo-insert-node-lines (&optional title-p)
54 ;; texinfo-indent-menu-description (column &optional region-p)
56 ;; The `texinfo-column-for-description' variable specifies the column to
57 ;; which menu descriptions are indented.
59 ;; Texinfo file structure
60 ;; ----------------------
62 ;; To use the updating commands, you must structure your Texinfo file
63 ;; hierarchically. Each `@node' line, with the exception of the top
64 ;; node, must be accompanied by some kind of section line, such as an
65 ;; `@chapter' or `@section' line. Each node-line/section-line
66 ;; combination must look like this:
68 ;; @node Lists and Tables, Cross References, Structuring, Top
69 ;; @comment node-name, next, previous, up
70 ;; @chapter Making Lists and Tables
72 ;; or like this (without the `@comment' line):
74 ;; @node Lists and Tables, Cross References, Structuring, Top
75 ;; @chapter Making Lists and Tables
77 ;; If the file has a `top' node, it must be called `top' or `Top' and
78 ;; be the first node in the file.
81 ;;; The 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 (require 'texinfo)
155 (defvar texinfo-master-menu-header
156 " --- The Detailed Node Listing ---\n"
157 "String inserted before lower level entries in Texinfo master menu.
158 It comes after the chapter-level menu entries.")
160 (defun texinfo-make-menu (&optional beginning end)
161 "Without any prefix argument, make or update a menu.
162 Make the menu for the section enclosing the node found following point.
164 A prefix argument means make or update menus
165 for nodes within or part of the marked region.
167 Whenever a menu exists, and is being updated, the descriptions that
168 are associated with node names in the pre-existing menu are
169 incorporated into the new menu. Otherwise, the nodes' section titles
170 are inserted as descriptions."
172 (interactive
173 (if prefix-arg
174 (list (point) (mark))))
175 (if (null beginning)
176 (let ((level (texinfo-hierarchic-level)))
177 (texinfo-make-one-menu level)
178 (message "Menu updated"))
179 ;; else
180 (message "Making or updating menus in %s... " (buffer-name))
181 (save-excursion
182 (goto-char (min beginning end))
183 ;; find section type following point
184 (let ((level (texinfo-hierarchic-level))
185 (region-end-marker (make-marker)))
186 (set-marker region-end-marker (max beginning end))
187 (save-restriction
188 (widen)
190 (while (texinfo-find-lower-level-node
191 level (marker-position region-end-marker))
192 (setq level (texinfo-hierarchic-level)) ; new, lower level
193 (texinfo-make-one-menu level))
195 (while (and (< (point) (marker-position region-end-marker))
196 (texinfo-find-higher-level-node
197 level (marker-position region-end-marker)))
198 (setq level (texinfo-hierarchic-level))
199 ;; Don't allow texinfo-find-higher-level-node
200 ;; to find the same node again.
201 (forward-line 1)
202 (while (texinfo-find-lower-level-node
203 level (marker-position region-end-marker))
204 (setq level (texinfo-hierarchic-level)) ; new, lower level
205 (texinfo-make-one-menu level))))))
206 (message "Making or updating menus in %s...done" (buffer-name))))
208 (defun texinfo-make-one-menu (level)
209 "Make a menu of all the appropriate nodes in this section.
210 `Appropriate nodes' are those associated with sections that are
211 at the level specified by LEVEL. Point is left at the end of menu."
212 (let*
213 ((case-fold-search t)
214 (beginning
215 (save-excursion
216 (goto-char (texinfo-update-menu-region-beginning level))
217 (end-of-line)
218 (point)))
219 (end (texinfo-update-menu-region-end level))
220 (first (texinfo-menu-first-node beginning end))
221 (node-name (progn
222 (goto-char beginning)
223 (beginning-of-line)
224 (texinfo-copy-node-name)))
225 (new-menu-list (texinfo-make-menu-list beginning end level)))
226 (if (texinfo-old-menu-p beginning first)
227 (progn
228 (texinfo-incorporate-descriptions new-menu-list)
229 (texinfo-incorporate-menu-entry-names new-menu-list)
230 (texinfo-delete-old-menu beginning first)))
231 (texinfo-insert-menu new-menu-list node-name)))
233 (defun texinfo-all-menus-update (&optional update-all-nodes-p)
234 "Update every regular menu in a Texinfo file.
235 Update pre-existing master menu, if there is one.
237 If called with a non-nil argument, this function first updates all the
238 nodes in the buffer before updating the menus."
239 (interactive "P")
240 (let ((case-fold-search t)
241 master-menu-p)
242 (save-excursion
243 (push-mark (point-max) t)
244 (goto-char (point-min))
245 (message "Checking for a master menu in %s ... "(buffer-name))
246 (save-excursion
247 (if (search-forward texinfo-master-menu-header nil t)
248 (progn
249 ;; Check if @detailmenu kludge is used;
250 ;; if so, leave point before @detailmenu.
251 (search-backward "\n@detailmenu"
252 (save-excursion (forward-line -3) (point))
254 ;; Remove detailed master menu listing
255 (setq master-menu-p t)
256 (goto-char (match-beginning 0))
257 (let ((end-of-detailed-menu-descriptions
258 (save-excursion ; beginning of end menu line
259 (goto-char (texinfo-menu-end))
260 (beginning-of-line) (forward-char -1)
261 (point))))
262 (delete-region (point) end-of-detailed-menu-descriptions)))))
264 (if update-all-nodes-p
265 (progn
266 (message "Updating all nodes in %s ... " (buffer-name))
267 (texinfo-update-node (point-min) (point-max))))
269 (message "Updating all menus in %s ... " (buffer-name))
270 (texinfo-make-menu (point-max) (point-min))
272 (if master-menu-p
273 (progn
274 (message "Updating the master menu in %s... " (buffer-name))
275 (texinfo-master-menu nil))))
277 (message "Done...updated all the menus. You may save the buffer.")))
279 (defun texinfo-find-lower-level-node (level region-end)
280 "Search forward from point for node at any level lower than LEVEL.
281 Search is limited to the end of the marked region, REGION-END,
282 and to the end of the menu region for the level.
284 Return t if the node is found, else nil. Leave point at the beginning
285 of the node if one is found; else do not move point."
286 (let ((case-fold-search t))
287 (if (and (< (point) region-end)
288 (re-search-forward
289 (concat
290 "\\(^@node\\).*\n" ; match node line
291 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
292 "\\|" ; or
293 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
294 (eval (cdr (assoc level texinfo-update-menu-lower-regexps))))
295 ;; the next higher level node marks the end of this
296 ;; section, and no lower level node will be found beyond
297 ;; this position even if region-end is farther off
298 (texinfo-update-menu-region-end level)
300 (goto-char (match-beginning 1)))))
302 (defun texinfo-find-higher-level-node (level region-end)
303 "Search forward from point for node at any higher level than argument LEVEL.
304 Search is limited to the end of the marked region, REGION-END.
306 Return t if the node is found, else nil. Leave point at the beginning
307 of the node if one is found; else do not move point.
309 A `@node' line starting at point does count as a match;
310 if the match is found there, the value is t and point does not move."
312 (let ((case-fold-search t))
313 (cond
314 ((< level 3)
315 (if (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" region-end t)
316 (progn (beginning-of-line) t)))
318 (if (re-search-forward
319 (concat
320 "\\(^@node\\).*\n" ; match node line
321 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
322 "\\|" ; or
323 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
324 (eval (cdr (assoc level texinfo-update-menu-higher-regexps))))
325 region-end t)
326 (progn (beginning-of-line) t))))))
329 ;;; Making the list of new menu entries
331 (defun texinfo-make-menu-list (beginning end level)
332 "Make a list of node names and their descriptions.
333 Point is left at the end of the menu region, but the menu is not inserted.
335 First argument is position from which to start making menu list;
336 second argument is end of region in which to try to locate entries;
337 third argument is the level of the nodes that are the entries.
339 Node names and descriptions are dotted pairs of strings. Each pair is
340 an element of the list. If the description does not exist, the
341 element consists only of the node name."
342 (goto-char beginning)
343 (let (new-menu-list)
344 (while (texinfo-menu-locate-entry-p level end)
345 (setq new-menu-list
346 (cons (cons
347 (texinfo-copy-node-name)
348 (prog1 "" (forward-line 1)))
349 ;; Use following to insert section titles automatically.
350 ;; (texinfo-copy-section-title))
351 new-menu-list)))
352 (reverse new-menu-list)))
354 (defun texinfo-menu-locate-entry-p (level search-end)
355 "Find a node that will be part of menu for this section.
356 First argument is a string such as \"section\" specifying the general
357 hierarchical level of the menu; second argument is a position
358 specifying the end of the search.
360 The function returns t if the node is found, else nil. It searches
361 forward from point, and leaves point at the beginning of the node.
363 The function finds entries of the same type. Thus `subsections' and
364 `unnumberedsubsecs' will appear in the same menu."
365 (let ((case-fold-search t))
366 (if (re-search-forward
367 (concat
368 "\\(^@node\\).*\n" ; match node line
369 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
370 "\\|" ; or
371 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
372 (eval
373 (cdr (assoc level texinfo-update-menu-same-level-regexps))))
374 search-end
376 (goto-char (match-beginning 1)))))
378 (defun texinfo-copy-node-name ()
379 "Return the node name as a string.
381 Start with point at the beginning of the node line; copy the text
382 after the node command up to the first comma on the line, if any, and
383 return the text as a string. Leaves point at the beginning of the
384 line. If there is no node name, returns an empty string."
386 (save-excursion
387 (buffer-substring
388 (progn (forward-word 1) ; skip over node command
389 (skip-chars-forward " \t") ; and over spaces
390 (point))
391 (if (search-forward
393 (save-excursion (end-of-line) (point)) t) ; bound search
394 (1- (point))
395 (end-of-line) (point)))))
397 (defun texinfo-copy-section-title ()
398 "Return the title of the section as a string.
399 The title is used as a description line in the menu when one does not
400 already exist.
402 Move point to the beginning of the appropriate section line by going
403 to the start of the text matched by last regexp searched for, which
404 must have been done by `texinfo-menu-locate-entry-p'."
406 ;; could use the same re-search as in `texinfo-menu-locate-entry-p'
407 ;; instead of using `match-beginning'; such a variation would be
408 ;; more general, but would waste information already collected
410 (goto-char (match-beginning 7)) ; match section name
412 (buffer-substring
413 (progn (forward-word 1) ; skip over section type
414 (skip-chars-forward " \t") ; and over spaces
415 (point))
416 (progn (end-of-line) (point))))
419 ;;; Handling the old menu
421 (defun texinfo-old-menu-p (beginning first)
422 "Move point to the beginning of the menu for this section, if any.
423 Otherwise move point to the end of the first node of this section.
424 Return t if a menu is found, nil otherwise.
426 First argument is the position of the beginning of the section in which
427 the menu will be located; second argument is the position of the first
428 node within the section.
430 If no menu is found, the function inserts two newlines just before the
431 end of the section, and leaves point there where a menu ought to be."
432 (goto-char beginning)
433 (if (not (re-search-forward "^@menu" first 'goto-end))
434 (progn (insert "\n\n") (forward-line -2) nil)
437 (defun texinfo-incorporate-descriptions (new-menu-list)
438 "Copy the old menu line descriptions that exist to the new menu.
440 Point must be at beginning of old menu.
442 If the node-name of the new menu is found in the old menu, insert the
443 old description into the new entry.
445 For this function, the new menu is a list made up of lists of dotted
446 pairs in which the first element of the pair is the node name and the
447 second element the description. The new menu is changed destructively.
448 The old menu is the menu as it appears in the Texinfo file."
450 (let ((new-menu-list-pointer new-menu-list)
451 (end-of-menu (texinfo-menu-end)))
452 (while new-menu-list
453 (save-excursion ; keep point at beginning of menu
454 (if (re-search-forward
455 ;; Existing nodes can have the form
456 ;; * NODE NAME:: DESCRIPTION
457 ;; or
458 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
460 ;; Recognize both when looking for the description.
461 (concat "\\* \\(" ; so only menu entries are found
462 (regexp-quote (car (car new-menu-list))) "::"
463 "\\|"
464 ".*: " (regexp-quote (car (car new-menu-list))) "[.,\t\n]"
465 "\\)"
466 ) ; so only complete entries are found
467 end-of-menu
469 (setcdr (car new-menu-list)
470 (texinfo-menu-copy-old-description end-of-menu))))
471 (setq new-menu-list (cdr new-menu-list)))
472 (setq new-menu-list new-menu-list-pointer)))
474 (defun texinfo-incorporate-menu-entry-names (new-menu-list)
475 "Copy any old menu entry names to the new menu.
477 Point must be at beginning of old menu.
479 If the node-name of the new menu entry cannot be found in the old
480 menu, do nothing.
482 For this function, the new menu is a list made up of lists of dotted
483 pairs in which the first element of the pair is the node name and the
484 second element is the description (or nil).
486 If we find an existing menu entry name, we change the first element of
487 the pair to be another dotted pair in which the car is the menu entry
488 name and the cdr is the node name.
490 NEW-MENU-LIST is changed destructively. The old menu is the menu as it
491 appears in the texinfo file."
493 (let ((new-menu-list-pointer new-menu-list)
494 (end-of-menu (texinfo-menu-end)))
495 (while new-menu-list
496 (save-excursion ; keep point at beginning of menu
497 (if (re-search-forward
498 ;; Existing nodes can have the form
499 ;; * NODE NAME:: DESCRIPTION
500 ;; or
501 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
503 ;; We're interested in the second case.
504 (concat "\\* " ; so only menu entries are found
505 "\\(.*\\): " (regexp-quote (car (car new-menu-list)))
506 "[.,\t\n]")
507 end-of-menu
509 (setcar
510 (car new-menu-list) ; replace the node name
511 (cons (buffer-substring (match-beginning 1) (match-end 1))
512 (car (car new-menu-list)))))
513 (setq new-menu-list (cdr new-menu-list))))
514 (setq new-menu-list new-menu-list-pointer)))
516 (defun texinfo-menu-copy-old-description (end-of-menu)
517 "Return description field of old menu line as string.
518 Point must be located just after the node name. Point left before description.
519 Single argument, END-OF-MENU, is position limiting search."
520 (skip-chars-forward "[:.,\t\n ]+")
521 ;; don't copy a carriage return at line beginning with asterisk!
522 ;; do copy a description that begins with an `@'!
523 ;; !! Known bug: does not copy descriptions starting with ^|\{?* etc.
524 (if (and (looking-at "\\(\\w+\\|@\\)")
525 (not (looking-at "\\(^\\* \\|^@end menu\\)")))
526 (buffer-substring
527 (point)
528 (save-excursion
529 (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t)
530 (forward-line -1)
531 (end-of-line) ; go to end of last description line
532 (point)))
533 ""))
535 (defun texinfo-menu-end ()
536 "Return position of end of menu, but don't move point.
537 Signal an error if not end of menu."
538 (save-excursion
539 (if (re-search-forward "^@end menu" nil t)
540 (point)
541 (error "Menu does not have an end."))))
543 (defun texinfo-delete-old-menu (beginning first)
544 "Delete the old menu. Point must be in or after menu.
545 First argument is position of the beginning of the section in which
546 the menu will be located; second argument is the position of the first
547 node within the section."
548 ;; No third arg to search, so error if search fails.
549 (re-search-backward "^@menu" beginning)
550 (delete-region (point)
551 (save-excursion
552 (re-search-forward "^@end menu" first)
553 (point))))
556 ;;; Inserting new menu
558 ;; try 32, but perhaps 24 is better
559 (defvar texinfo-column-for-description 32
560 "*Column at which descriptions start in a Texinfo menu.")
562 (defun texinfo-insert-menu (menu-list node-name)
563 "Insert formatted menu at point.
564 Indents the first line of the description, if any, to the value of
565 texinfo-column-for-description.
567 MENU-LIST has form:
569 \(\(\"node-name1\" . \"description\"\)
570 \(\"node-name2\" . \"description\"\) ... \)
572 However, the description field might be nil.
574 Also, the node-name field might itself be a dotted pair (call it P) of
575 strings instead of just a string. In that case, the car of P
576 is the menu entry name, and the cdr of P is the node name."
578 (insert "@menu\n")
579 (while menu-list
580 ;; Every menu entry starts with a star and a space.
581 (insert "* ")
583 ;; Insert the node name (and menu entry name, if present).
584 (let ((node-part (car (car menu-list))))
585 (if (stringp node-part)
586 ;; "Double colon" entry line; menu entry and node name are the same,
587 (insert (format "%s::" node-part))
588 ;; "Single colon" entry line; menu entry and node name are different.
589 (insert (format "%s: %s." (car node-part) (cdr node-part)))))
591 ;; Insert the description, if present.
592 (if (cdr (car menu-list))
593 (progn
594 ;; Move to right place.
595 (indent-to texinfo-column-for-description 2)
596 ;; Insert description.
597 (insert (format "%s" (cdr (car menu-list))))))
599 (insert "\n") ; end this menu entry
600 (setq menu-list (cdr menu-list)))
601 (insert "@end menu")
602 (message
603 "Updated \"%s\" level menu following node: %s ... " level node-name))
606 ;;; Starting menu descriptions by inserting titles
608 (defun texinfo-start-menu-description ()
609 "In this menu entry, insert the node's section title as a description.
610 Position point at beginning of description ready for editing.
611 Do not insert a title if the line contains an existing description.
613 You will need to edit the inserted text since a useful description
614 complements the node name rather than repeats it as a title does."
616 (interactive)
617 (let (beginning end node-name title)
618 (save-excursion
619 (beginning-of-line)
620 (if (search-forward "* " (save-excursion (end-of-line) (point)) t)
621 (progn (skip-chars-forward " \t")
622 (setq beginning (point)))
623 (error "This is not a line in a menu!"))
625 (cond
626 ;; "Double colon" entry line; menu entry and node name are the same,
627 ((search-forward "::" (save-excursion (end-of-line) (point)) t)
628 (if (looking-at "[ \t]*[^ \t\n]+")
629 (error "Descriptive text already exists."))
630 (skip-chars-backward ": \t")
631 (setq node-name (buffer-substring beginning (point))))
633 ;; "Single colon" entry line; menu entry and node name are different.
634 ((search-forward ":" (save-excursion (end-of-line) (point)) t)
635 (skip-chars-forward " \t")
636 (setq beginning (point))
637 ;; Menu entry line ends in a period, comma, or tab.
638 (if (re-search-forward "[.,\t]"
639 (save-excursion (forward-line 1) (point)) t)
640 (progn
641 (if (looking-at "[ \t]*[^ \t\n]+")
642 (error "Descriptive text already exists."))
643 (skip-chars-backward "., \t")
644 (setq node-name (buffer-substring beginning (point))))
645 ;; Menu entry line ends in a return.
646 (re-search-forward ".*\n"
647 (save-excursion (forward-line 1) (point)) t)
648 (skip-chars-backward " \t\n")
649 (setq node-name (buffer-substring beginning (point)))
650 (if (= 0 (length node-name))
651 (error "No node name on this line.")
652 (insert "."))))
653 (t (error "No node name on this line.")))
654 ;; Search for node that matches node name, and copy the section title.
655 (if (re-search-forward
656 (concat
657 "^@node[ \t]+"
658 (regexp-quote node-name)
659 ".*\n" ; match node line
660 "\\("
661 "\\(\\(^@c \\|^@comment\\).*\n\\)" ; match comment line, if any
662 "\\|" ; or
663 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
664 "\\)?")
665 nil t)
666 (progn
667 (setq title
668 (buffer-substring
669 ;; skip over section type
670 (progn (forward-word 1)
671 ;; and over spaces
672 (skip-chars-forward " \t")
673 (point))
674 (progn (end-of-line)
675 (skip-chars-backward " \t")
676 (point)))))
677 (error "Cannot find node to match node name in menu entry.")))
678 ;; Return point to the menu and insert the title.
679 (end-of-line)
680 (delete-region
681 (point)
682 (save-excursion (skip-chars-backward " \t") (point)))
683 (indent-to texinfo-column-for-description 2)
684 (save-excursion (insert title))))
687 ;;; Handling description indentation
689 ;; Since the make-menu functions indent descriptions, these functions
690 ;; are useful primarily for indenting a single menu specially.
692 (defun texinfo-indent-menu-description (column &optional region-p)
693 "Indent every description in menu following point to COLUMN.
694 Non-nil argument (prefix, if interactive) means indent every
695 description in every menu in the region. Does not indent second and
696 subsequent lines of a multi-line description."
698 (interactive
699 "nIndent menu descriptions to (column number): \nP")
700 (save-excursion
701 (save-restriction
702 (widen)
703 (if (not region-p)
704 (progn
705 (re-search-forward "^@menu")
706 (texinfo-menu-indent-description column)
707 (message
708 "Indented descriptions in menu. You may save the buffer."))
709 ;;else
710 (message "Indenting every menu description in region... ")
711 (goto-char (region-beginning))
712 (while (and (< (point) (region-end))
713 (texinfo-locate-menu-p))
714 (forward-line 1)
715 (texinfo-menu-indent-description column))
716 (message "Indenting done. You may save the buffer.")))))
718 (defun texinfo-menu-indent-description (to-column-number)
719 "Indent the Texinfo file menu description to TO-COLUMN-NUMBER.
720 Start with point just after the word `menu' in the `@menu' line and
721 leave point on the line before the `@end menu' line. Does not indent
722 second and subsequent lines of a multi-line description."
723 (let* ((beginning-of-next-line (point)))
724 (while (< beginning-of-next-line
725 (save-excursion ; beginning of end menu line
726 (goto-char (texinfo-menu-end))
727 (beginning-of-line)
728 (point)))
730 (if (re-search-forward "\\* \\(.*::\\|.*: [^.,\t\n]+[.,\t]\\)"
731 (texinfo-menu-end)
733 (progn
734 (let ((beginning-white-space (point)))
735 (skip-chars-forward " \t") ; skip over spaces
736 (if (looking-at "\\(@\\|\\w\\)+") ; if there is text
737 (progn
738 ;; remove pre-existing indentation
739 (delete-region beginning-white-space (point))
740 (indent-to-column to-column-number))))))
741 ;; position point at beginning of next line
742 (forward-line 1)
743 (setq beginning-of-next-line (point)))))
746 ;;; Making the master menu
748 (defun texinfo-master-menu (update-all-nodes-menus-p)
749 "Make a master menu for a whole Texinfo file.
750 Non-nil argument (prefix, if interactive) means first update all
751 existing nodes and menus. Remove pre-existing master menu, if there is one.
753 This function creates a master menu that follows the top node. The
754 master menu includes every entry from all the other menus. It
755 replaces any existing ordinary menu that follows the top node.
757 If called with a non-nil argument, this function first updates all the
758 menus in the buffer (incorporating descriptions from pre-existing
759 menus) before it constructs the master menu.
761 The function removes the detailed part of an already existing master
762 menu. This action depends on the pre-existing master menu using the
763 standard `texinfo-master-menu-header'.
765 The master menu has the following format, which is adapted from the
766 recommendation in the Texinfo Manual:
768 * The first part contains the major nodes in the Texinfo file: the
769 nodes for the chapters, chapter-like sections, and the major
770 appendices. This includes the indices, so long as they are in
771 chapter-like sections, such as unnumbered sections.
773 * The second and subsequent parts contain a listing of the other,
774 lower level menus, in order. This way, an inquirer can go
775 directly to a particular node if he or she is searching for
776 specific information.
778 Each of the menus in the detailed node listing is introduced by the
779 title of the section containing the menu."
781 (interactive "P")
782 (let ((case-fold-search t))
783 (widen)
784 (goto-char (point-min))
786 ;; Move point to location after `top'.
787 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
788 (error "This buffer needs a Top node!"))
790 (let ((first-chapter
791 (save-excursion
792 (or (re-search-forward "^@node" nil t)
793 (error "Too few nodes for a master menu!"))
794 (point))))
795 (if (search-forward texinfo-master-menu-header first-chapter t)
796 (progn
797 ;; Check if @detailmenu kludge is used;
798 ;; if so, leave point before @detailmenu.
799 (search-backward "\n@detailmenu"
800 (save-excursion (forward-line -3) (point))
802 ;; Remove detailed master menu listing
803 (goto-char (match-beginning 0))
804 (let ((end-of-detailed-menu-descriptions
805 (save-excursion ; beginning of end menu line
806 (goto-char (texinfo-menu-end))
807 (beginning-of-line) (forward-char -1)
808 (point))))
809 (delete-region (point) end-of-detailed-menu-descriptions)))))
811 (if update-all-nodes-menus-p
812 (progn
813 (message "Making a master menu in %s ...first updating all nodes... "
814 (buffer-name))
815 (texinfo-update-node (point-min) (point-max))
817 (message "Updating all menus in %s ... " (buffer-name))
818 (texinfo-make-menu (point-min) (point-max))))
820 (message "Now making the master menu in %s... " (buffer-name))
821 (goto-char (point-min))
822 (texinfo-insert-master-menu-list
823 (texinfo-master-menu-list))
825 ;; Remove extra newlines that texinfo-insert-master-menu-list
826 ;; may have inserted.
828 (save-excursion
829 (goto-char (point-min))
831 (if (search-forward texinfo-master-menu-header nil t)
832 (progn
833 (goto-char (match-beginning 0))
834 ;; Check if @detailmenu kludge is used;
835 ;; if so, leave point before @detailmenu.
836 (search-backward "\n@detailmenu"
837 (save-excursion (forward-line -3) (point))
839 (insert "\n")
840 (delete-blank-lines)
841 (goto-char (point-min))))
843 (re-search-forward "^@menu")
844 (forward-line -1)
845 (delete-blank-lines)
847 (re-search-forward "^@end menu")
848 (forward-line 1)
849 (delete-blank-lines))
851 (message
852 "Done...completed making master menu. You may save the buffer.")))
854 (defun texinfo-master-menu-list ()
855 "Return a list of menu entries and header lines for the master menu.
857 Start with the menu for chapters and indices and then find each
858 following menu and the title of the node preceding that menu.
860 The master menu list has this form:
862 \(\(\(... \"entry-1-2\" \"entry-1\"\) \"title-1\"\)
863 \(\(... \"entry-2-2\" \"entry-2-1\"\) \"title-2\"\)
864 ...\)
866 However, there does not need to be a title field."
868 (let (master-menu-list)
869 (while (texinfo-locate-menu-p)
870 (setq master-menu-list
871 (cons (list
872 (texinfo-copy-menu)
873 (texinfo-copy-menu-title))
874 master-menu-list)))
875 (reverse master-menu-list)))
877 (defun texinfo-insert-master-menu-list (master-menu-list)
878 "Format and insert the master menu in the current buffer."
879 (goto-char (point-min))
880 ;; Insert a master menu only after `Top' node and before next node
881 ;; \(or include file if there is no next node\).
882 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
883 (error "This buffer needs a Top node!"))
884 (let ((first-chapter
885 (save-excursion (re-search-forward "^@node\\|^@include") (point))))
886 (if (not (re-search-forward "^@menu" first-chapter t))
887 (error
888 "Buffer lacks ordinary `Top' menu in which to insert master.")))
889 (beginning-of-line)
890 (delete-region ; buffer must have ordinary top menu
891 (point)
892 (save-excursion (re-search-forward "^@end menu") (point)))
894 (save-excursion
895 ;; `master-menu-inserted-p' is a kludge to tell
896 ;; whether to insert @end detailmenu (see bleow)
897 (let (master-menu-inserted-p)
898 ;; Handle top of menu
899 (insert "\n@menu\n")
900 ;; Insert chapter menu entries
901 (setq this-very-menu-list (reverse (car (car master-menu-list))))
902 ;; Tell user what is going on.
903 (message "Inserting chapter menu entry: %s ... " this-very-menu-list)
904 (while this-very-menu-list
905 (insert "* " (car this-very-menu-list) "\n")
906 (setq this-very-menu-list (cdr this-very-menu-list)))
908 (setq master-menu-list (cdr master-menu-list))
910 ;; Only insert detailed master menu if there is one....
911 (if (car (car master-menu-list))
912 (progn (setq master-menu-inserted-p t)
913 (insert (concat "\n@detailmenu\n"
914 texinfo-master-menu-header))))
916 ;; @detailmenu added 5 Sept 1996 to `texinfo-master-menu-header'
917 ;; at Karl Berry's request to avert a bug in `makeinfo';
918 ;; all agree this is a bad kludge and should eventually be removed.
919 ;; @detailmenu ... @end detailmenu is a noop in `texinfmt.el'.
920 ;; See @end detailmenu below;
921 ;; also see `texinfo-all-menus-update' above, `texinfo-master-menu',
922 ;; `texinfo-multiple-files-update'.
924 ;; Now, insert all the other menus
926 ;; The menu master-menu-list has a form like this:
927 ;; ((("beta" "alpha") "title-A")
928 ;; (("delta" "gamma") "title-B"))
930 (while master-menu-list
932 (message
933 "Inserting menu for %s .... " (car (cdr (car master-menu-list))))
934 ;; insert title of menu section
935 (insert "\n" (car (cdr (car master-menu-list))) "\n\n")
937 ;; insert each menu entry
938 (setq this-very-menu-list (reverse (car (car master-menu-list))))
939 (while this-very-menu-list
940 (insert "* " (car this-very-menu-list) "\n")
941 (setq this-very-menu-list (cdr this-very-menu-list)))
943 (setq master-menu-list (cdr master-menu-list)))
945 ;; Finish menu
947 ;; @detailmenu (see note above)
948 ;; Only insert @end detailmenu if a master menu was inserted.
949 (if master-menu-inserted-p
950 (insert "\n@end detailmenu"))
951 (insert "\n@end menu\n\n"))))
953 (defun texinfo-locate-menu-p ()
954 "Find the next menu in the texinfo file.
955 If found, leave point after word `menu' on the `@menu' line, and return t.
956 If a menu is not found, do not move point and return nil."
957 (re-search-forward "\\(^@menu\\)" nil t))
959 (defun texinfo-copy-menu-title ()
960 "Return the title of the section preceding the menu as a string.
961 If such a title cannot be found, return an empty string. Do not move
962 point."
963 (let ((case-fold-search t))
964 (save-excursion
965 (if (re-search-backward
966 (concat
967 "\\(^@top"
968 "\\|" ; or
969 texinfo-section-types-regexp ; all other section types
970 "\\)")
973 (progn
974 (beginning-of-line)
975 (forward-word 1) ; skip over section type
976 (skip-chars-forward " \t") ; and over spaces
977 (buffer-substring
978 (point)
979 (progn (end-of-line) (point))))
980 ""))))
982 (defun texinfo-copy-menu ()
983 "Return the entries of an existing menu as a list.
984 Start with point just after the word `menu' in the `@menu' line
985 and leave point on the line before the `@end menu' line."
986 (let* (this-menu-list
987 (end-of-menu (texinfo-menu-end)) ; position of end of `@end menu'
988 (last-entry (save-excursion ; position of beginning of
989 ; last `* ' entry
990 (goto-char end-of-menu)
991 ;; handle multi-line description
992 (if (not (re-search-backward "^\\* " nil t))
993 (error "No entries in menu."))
994 (point))))
995 (while (< (point) last-entry)
996 (if (re-search-forward "^\\* " end-of-menu t)
997 (progn
998 (setq this-menu-list
999 (cons
1000 (buffer-substring
1001 (point)
1002 ;; copy multi-line descriptions
1003 (save-excursion
1004 (re-search-forward "\\(^\\* \\|^@e\\)" nil t)
1005 (- (point) 3)))
1006 this-menu-list)))))
1007 this-menu-list))
1010 ;;; Determining the hierarchical level in the texinfo file
1012 (defun texinfo-specific-section-type ()
1013 "Return the specific type of next section, as a string.
1014 For example, \"unnumberedsubsec\". Return \"top\" for top node.
1016 Searches forward for a section. Hence, point must be before the
1017 section whose type will be found. Does not move point. Signal an
1018 error if the node is not the top node and a section is not found."
1019 (let ((case-fold-search t))
1020 (save-excursion
1021 (cond
1022 ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1023 ;;; Following search limit by cph but causes a bug
1024 ;;; (save-excursion
1025 ;;; (end-of-line)
1026 ;;; (point))
1029 "top")
1030 ((re-search-forward texinfo-section-types-regexp nil t)
1031 (buffer-substring-no-properties
1032 (progn (beginning-of-line) ; copy its name
1033 (1+ (point)))
1034 (progn (forward-word 1)
1035 (point))))
1037 (error
1038 "texinfo-specific-section-type: Chapter or section not found."))))))
1040 (defun texinfo-hierarchic-level ()
1041 "Return the general hierarchal level of the next node in a texinfo file.
1042 Thus, a subheading or appendixsubsec is of type subsection."
1043 (let ((case-fold-search t))
1044 (cadr (assoc
1045 (texinfo-specific-section-type)
1046 texinfo-section-list))))
1049 ;;; Locating the major positions
1051 (defun texinfo-update-menu-region-beginning (level)
1052 "Locate beginning of higher level section this section is within.
1053 Return position of the beginning of the node line; do not move point.
1054 Thus, if this level is subsection, searches backwards for section node.
1055 Only argument is a string of the general type of section."
1056 (let ((case-fold-search t))
1057 ;; !! Known bug: if section immediately follows top node, this
1058 ;; returns the beginning of the buffer as the beginning of the
1059 ;; higher level section.
1060 (cond
1061 ((< level 3)
1062 (save-excursion
1063 (goto-char (point-min))
1064 (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t)
1065 (beginning-of-line)
1066 (point)))
1068 (save-excursion
1069 (re-search-backward
1070 (concat
1071 "\\(^@node\\).*\n" ; match node line
1072 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1073 "\\|" ; or
1074 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
1075 (eval
1076 (cdr (assoc level texinfo-update-menu-higher-regexps))))
1078 'goto-beginning)
1079 (point))))))
1081 (defun texinfo-update-menu-region-end (level)
1082 "Locate end of higher level section this section is within.
1083 Return position; do not move point. Thus, if this level is a
1084 subsection, find the node for the section this subsection is within.
1085 If level is top or chapter, returns end of file. Only argument is a
1086 string of the general type of section."
1087 (let ((case-fold-search t))
1088 (save-excursion
1089 (if (re-search-forward
1090 (concat
1091 "\\(^@node\\).*\n" ; match node line
1092 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1093 "\\|" ; or
1094 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
1095 (eval
1096 ;; Never finds end of level above chapter so goes to end.
1097 (cdr (assoc level texinfo-update-menu-higher-regexps))))
1099 'goto-end)
1100 (match-beginning 1)
1101 (point-max)))))
1103 (defun texinfo-menu-first-node (beginning end)
1104 "Locate first node of the section the menu will be placed in.
1105 Return position; do not move point.
1106 The menu will be located just before this position.
1108 First argument is the position of the beginning of the section in
1109 which the menu will be located; second argument is the position of the
1110 end of that region; it limits the search."
1112 (save-excursion
1113 (goto-char beginning)
1114 (forward-line 1)
1115 (re-search-forward "^@node" end t)
1116 (beginning-of-line)
1117 (point)))
1120 ;; We used to look for just sub, but that found @subtitle.
1121 (defvar texinfo-section-types-regexp
1122 "^@\\(chapter \\|sect\\|subs\\|subh\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
1123 "Regexp matching chapter, section, other headings (but not the top node).")
1125 (defun texinfo-filter (section list)
1126 (let (res)
1127 (dolist (x list) (if (eq section (cadr x)) (push (car x) res)))
1128 res))
1130 (defvar texinfo-chapter-level-regexp
1131 (regexp-opt (texinfo-filter 2 texinfo-section-list))
1132 "Regular expression matching just the Texinfo chapter level headings.")
1134 (defvar texinfo-section-level-regexp
1135 (regexp-opt (texinfo-filter 3 texinfo-section-list))
1136 "Regular expression matching just the Texinfo section level headings.")
1138 (defvar texinfo-subsection-level-regexp
1139 (regexp-opt (texinfo-filter 4 texinfo-section-list))
1140 "Regular expression matching just the Texinfo subsection level headings.")
1142 (defvar texinfo-subsubsection-level-regexp
1143 (regexp-opt (texinfo-filter 5 texinfo-section-list))
1144 "Regular expression matching just the Texinfo subsubsection level headings.")
1146 (defvar texinfo-update-menu-same-level-regexps
1147 '((1 . "top[ \t]+")
1148 (2 . (concat "\\(^@\\)\\(" texinfo-chapter-level-regexp "\\)\\>[ \t]*"))
1149 (3 . (concat "\\(^@\\)\\(" texinfo-section-level-regexp "\\)\\>[ \t]*"))
1150 (4 . (concat "\\(^@\\)\\(" texinfo-subsection-level-regexp "\\)\\>[ \t]+"))
1151 (5 . (concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp "\\)\\>[ \t]+")))
1152 "*Regexps for searching for same level sections in a Texinfo file.
1153 The keys are strings specifying the general hierarchical level in the
1154 document; the values are regular expressions.")
1156 (defvar texinfo-update-menu-higher-regexps
1157 '((1 . "^@node [ \t]*DIR")
1158 (2 . "^@node [ \t]*top[ \t]*\\(,\\|$\\)")
1159 (3 .
1160 (concat
1161 "\\(^@\\("
1162 texinfo-chapter-level-regexp
1163 "\\)\\>[ \t]*\\)"))
1164 (4 .
1165 (concat
1166 "\\(^@\\("
1167 texinfo-section-level-regexp
1168 "\\|"
1169 texinfo-chapter-level-regexp
1170 "\\)\\>[ \t]*\\)"))
1171 (5 .
1172 (concat
1173 "\\(^@\\("
1174 texinfo-subsection-level-regexp
1175 "\\|"
1176 texinfo-section-level-regexp
1177 "\\|"
1178 texinfo-chapter-level-regexp
1179 "\\)\\>[ \t]*\\)")))
1180 "*Regexps for searching for higher level sections in a Texinfo file.
1181 The keys are strings specifying the general hierarchical level in the
1182 document; the values are regular expressions.")
1184 (defvar texinfo-update-menu-lower-regexps
1185 '((1 .
1186 (concat
1187 "\\(^@\\("
1188 texinfo-chapter-level-regexp
1189 "\\|"
1190 texinfo-section-level-regexp
1191 "\\|"
1192 texinfo-subsection-level-regexp
1193 "\\|"
1194 texinfo-subsubsection-level-regexp
1195 "\\)\\>[ \t]*\\)"))
1196 (2 .
1197 (concat
1198 "\\(^@\\("
1199 texinfo-section-level-regexp
1200 "\\|"
1201 texinfo-subsection-level-regexp
1202 "\\|"
1203 texinfo-subsubsection-level-regexp
1204 "\\)\\>[ \t]*\\)"))
1205 (3 .
1206 (concat
1207 "\\(^@\\("
1208 texinfo-subsection-level-regexp
1209 "\\|"
1210 texinfo-subsubsection-level-regexp
1211 "\\)\\>[ \t]+\\)"))
1212 (4 .
1213 (concat
1214 "\\(^@\\("
1215 texinfo-subsubsection-level-regexp
1216 "\\)\\>[ \t]+\\)"))
1217 (subsubsection . "nothing lower"))
1218 "*Regexps for searching for lower level sections in a Texinfo file.
1219 The keys are strings specifying the general hierarchical level in the
1220 document; the values are regular expressions.")
1223 ;;; Updating a node
1225 (defun texinfo-update-node (&optional beginning end)
1226 "Without any prefix argument, update the node in which point is located.
1227 Interactively, a prefix argument means to operate on the region.
1229 The functions for creating or updating nodes and menus, and their
1230 keybindings, are:
1232 texinfo-update-node (&optional beginning end) \\[texinfo-update-node]
1233 texinfo-every-node-update () \\[texinfo-every-node-update]
1234 texinfo-sequential-node-update (&optional region-p)
1236 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
1237 texinfo-all-menus-update () \\[texinfo-all-menus-update]
1238 texinfo-master-menu ()
1240 texinfo-indent-menu-description (column &optional region-p)
1242 The `texinfo-column-for-description' variable specifies the column to
1243 which menu descriptions are indented. Its default value is 32."
1245 (interactive
1246 (if prefix-arg
1247 (list (point) (mark))))
1248 (if (null beginning)
1249 ;; Update a single node.
1250 (let ((auto-fill-function nil) (auto-fill-hook nil))
1251 (if (not (re-search-backward "^@node" (point-min) t))
1252 (error "Node line not found before this position"))
1253 (texinfo-update-the-node)
1254 (message "Done...updated the node. You may save the buffer."))
1255 ;; else
1256 (let ((auto-fill-function nil)
1257 (auto-fill-hook nil))
1258 (save-excursion
1259 (save-restriction
1260 (narrow-to-region beginning end)
1261 (goto-char (point-min))
1262 (while (re-search-forward "^@node" (point-max) t)
1263 (beginning-of-line)
1264 (texinfo-update-the-node))
1265 (goto-char (point-max))
1266 (message "Done...nodes updated in region. You may save the buffer."))))))
1268 (defun texinfo-every-node-update ()
1269 "Update every node in a Texinfo file."
1270 (interactive)
1271 (save-excursion
1272 (texinfo-update-node (point-min) (point-max))
1273 (message "Done...updated every node. You may save the buffer.")))
1275 (defun texinfo-update-the-node ()
1276 "Update one node. Point must be at the beginning of node line.
1277 Leave point at the end of the node line."
1278 (texinfo-check-for-node-name)
1279 (texinfo-delete-existing-pointers)
1280 (message "Updating node: %s ... " (texinfo-copy-node-name))
1281 (save-restriction
1282 (widen)
1283 (let*
1284 ((case-fold-search t)
1285 (level (texinfo-hierarchic-level))
1286 (beginning (texinfo-update-menu-region-beginning level))
1287 (end (texinfo-update-menu-region-end level)))
1288 (if (eq level 1)
1289 (texinfo-top-pointer-case)
1290 ;; else
1291 (texinfo-insert-pointer beginning end level 'next)
1292 (texinfo-insert-pointer beginning end level 'previous)
1293 (texinfo-insert-pointer beginning end level 'up)
1294 (texinfo-clean-up-node-line)))))
1296 (defun texinfo-top-pointer-case ()
1297 "Insert pointers in the Top node. This is a special case.
1299 The `Next' pointer is a pointer to a chapter or section at a lower
1300 hierarchical level in the file. The `Previous' and `Up' pointers are
1301 to `(dir)'. Point must be at the beginning of the node line, and is
1302 left at the end of the node line."
1304 (texinfo-clean-up-node-line)
1305 (insert ", "
1306 (save-excursion
1307 ;; There may be an @chapter or other such command between
1308 ;; the top node line and the next node line, as a title
1309 ;; for an `ifinfo' section. This @chapter command must
1310 ;; must be skipped. So the procedure is to search for
1311 ;; the next `@node' line, and then copy its name.
1312 (if (re-search-forward "^@node" nil t)
1313 (progn
1314 (beginning-of-line)
1315 (texinfo-copy-node-name))
1316 " "))
1317 ", (dir), (dir)"))
1319 (defun texinfo-check-for-node-name ()
1320 "Determine whether the node has a node name. Prompt for one if not.
1321 Point must be at beginning of node line. Does not move point."
1322 (save-excursion
1323 (let ((initial (texinfo-copy-next-section-title)))
1324 ;; This is not clean. Use `interactive' to read the arg.
1325 (forward-word 1) ; skip over node command
1326 (skip-chars-forward " \t") ; and over spaces
1327 (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what Info looks for
1328 ; alternatively, use "[a-zA-Z]+"
1329 (let ((node-name
1330 (read-from-minibuffer
1331 "Node name (use no @, commas, colons, or apostrophes): "
1332 initial)))
1333 (insert " " node-name))))))
1335 (defun texinfo-delete-existing-pointers ()
1336 "Delete `Next', `Previous', and `Up' pointers.
1337 Starts from the current position of the cursor, and searches forward
1338 on the line for a comma and if one is found, deletes the rest of the
1339 line, including the comma. Leaves point at beginning of line."
1340 (let ((eol-point (save-excursion (end-of-line) (point))))
1341 (if (search-forward "," eol-point t)
1342 (delete-region (1- (point)) eol-point)))
1343 (beginning-of-line))
1345 (defun texinfo-find-pointer (beginning end level direction)
1346 "Move point to section associated with next, previous, or up pointer.
1347 Return type of pointer (either `normal' or `no-pointer').
1349 The first and second arguments bound the search for a pointer to the
1350 beginning and end, respectively, of the enclosing higher level
1351 section. The third argument is a string specifying the general kind
1352 of section such as \"chapter\" or \"section\". When looking for the
1353 `Next' pointer, the section found will be at the same hierarchical
1354 level in the Texinfo file; when looking for the `Previous' pointer,
1355 the section found will be at the same or higher hierarchical level in
1356 the Texinfo file; when looking for the `Up' pointer, the section found
1357 will be at some level higher in the Texinfo file. The fourth argument
1358 \(one of 'next, 'previous, or 'up\) specifies whether to find the
1359 `Next', `Previous', or `Up' pointer."
1360 (let ((case-fold-search t))
1361 (cond ((eq direction 'next)
1362 (forward-line 3) ; skip over current node
1363 ;; Search for section commands accompanied by node lines;
1364 ;; ignore section commands in the middle of nodes.
1365 (if (re-search-forward
1366 ;; A `Top' node is never a next pointer, so won't find it.
1367 (concat
1368 ;; Match node line.
1369 "\\(^@node\\).*\n"
1370 ;; Match comment or ifinfo line, if any
1371 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1372 (eval
1373 (cdr (assoc level texinfo-update-menu-same-level-regexps))))
1376 'normal
1377 'no-pointer))
1378 ((eq direction 'previous)
1379 (if (re-search-backward
1380 (concat
1381 "\\("
1382 ;; Match node line.
1383 "\\(^@node\\).*\n"
1384 ;; Match comment or ifinfo line, if any
1385 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1386 (eval
1387 (cdr (assoc level texinfo-update-menu-same-level-regexps)))
1388 "\\|"
1389 ;; Match node line.
1390 "\\(^@node\\).*\n"
1391 ;; Match comment or ifinfo line, if any
1392 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1393 (eval
1394 (cdr (assoc level texinfo-update-menu-higher-regexps)))
1395 "\\|"
1396 ;; Handle `Top' node specially.
1397 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1398 "\\)")
1399 beginning
1401 'normal
1402 'no-pointer))
1403 ((eq direction 'up)
1404 (if (re-search-backward
1405 (concat
1406 "\\("
1407 ;; Match node line.
1408 "\\(^@node\\).*\n"
1409 ;; Match comment or ifinfo line, if any
1410 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1411 (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
1412 "\\|"
1413 ;; Handle `Top' node specially.
1414 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1415 "\\)")
1416 (save-excursion
1417 (goto-char beginning)
1418 (beginning-of-line)
1419 (point))
1421 'normal
1422 'no-pointer))
1424 (error "texinfo-find-pointer: lack proper arguments")))))
1426 (defun texinfo-pointer-name (kind)
1427 "Return the node name preceding the section command.
1428 The argument is the kind of section, either `normal' or `no-pointer'."
1429 (let (name)
1430 (cond ((eq kind 'normal)
1431 (end-of-line) ; this handles prev node top case
1432 (re-search-backward ; when point is already
1433 "^@node" ; at the beginning of @node line
1434 (save-excursion (forward-line -3))
1436 (setq name (texinfo-copy-node-name)))
1437 ((eq kind 'no-pointer)
1438 ;; Don't need to put a blank in the pointer slot,
1439 ;; since insert "' " always has a space
1440 (setq name " "))) ; put a blank in the pointer slot
1441 name))
1443 (defun texinfo-insert-pointer (beginning end level direction)
1444 "Insert the `Next', `Previous' or `Up' node name at point.
1445 Move point forward.
1447 The first and second arguments bound the search for a pointer to the
1448 beginning and end, respectively, of the enclosing higher level
1449 section. The third argument is the hierarchical level of the Texinfo
1450 file, a string such as \"section\". The fourth argument is direction
1451 towards which the pointer is directed, one of `next', `previous', or `up'."
1453 (end-of-line)
1454 (insert
1455 ", "
1456 (save-excursion
1457 (texinfo-pointer-name
1458 (texinfo-find-pointer beginning end level direction)))))
1460 (defun texinfo-clean-up-node-line ()
1461 "Remove extra commas, if any, at end of node line."
1462 (end-of-line)
1463 (skip-chars-backward ", ")
1464 (delete-region (point) (save-excursion (end-of-line) (point))))
1467 ;;; Updating nodes sequentially
1468 ;; These sequential update functions insert `Next' or `Previous'
1469 ;; pointers that point to the following or preceding nodes even if they
1470 ;; are at higher or lower hierarchical levels. This means that if a
1471 ;; section contains one or more subsections, the section's `Next'
1472 ;; pointer will point to the subsection and not the following section.
1473 ;; (The subsection to which `Next' points will most likely be the first
1474 ;; item on the section's menu.)
1476 (defun texinfo-sequential-node-update (&optional region-p)
1477 "Update one node (or many) in a Texinfo file with sequential pointers.
1479 This function causes the `Next' or `Previous' pointer to point to the
1480 immediately preceding or following node, even if it is at a higher or
1481 lower hierarchical level in the document. Continually pressing `n' or
1482 `p' takes you straight through the file.
1484 Without any prefix argument, update the node in which point is located.
1485 Non-nil argument (prefix, if interactive) means update the nodes in the
1486 marked region.
1488 This command makes it awkward to navigate among sections and
1489 subsections; it should be used only for those documents that are meant
1490 to be read like a novel rather than a reference, and for which the
1491 Info `g*' command is inadequate."
1493 (interactive "P")
1494 (if (not region-p)
1495 ;; update a single node
1496 (let ((auto-fill-function nil) (auto-fill-hook nil))
1497 (if (not (re-search-backward "^@node" (point-min) t))
1498 (error "Node line not found before this position."))
1499 (texinfo-sequentially-update-the-node)
1500 (message
1501 "Done...sequentially updated the node . You may save the buffer."))
1502 ;; else
1503 (let ((auto-fill-function nil)
1504 (auto-fill-hook nil)
1505 (beginning (region-beginning))
1506 (end (region-end)))
1507 (if (= end beginning)
1508 (error "Please mark a region!"))
1509 (save-restriction
1510 (narrow-to-region beginning end)
1511 (goto-char beginning)
1512 (push-mark (point) t)
1513 (while (re-search-forward "^@node" (point-max) t)
1514 (beginning-of-line)
1515 (texinfo-sequentially-update-the-node))
1516 (message
1517 "Done...updated the nodes in sequence. You may save the buffer.")))))
1519 (defun texinfo-sequentially-update-the-node ()
1520 "Update one node such that the pointers are sequential.
1521 A `Next' or `Previous' pointer points to any preceding or following node,
1522 regardless of its hierarchical level."
1524 (texinfo-check-for-node-name)
1525 (texinfo-delete-existing-pointers)
1526 (message
1527 "Sequentially updating node: %s ... " (texinfo-copy-node-name))
1528 (save-restriction
1529 (widen)
1530 (let* ((case-fold-search t)
1531 (level (texinfo-hierarchic-level)))
1532 (if (eq level 1)
1533 (texinfo-top-pointer-case)
1534 ;; else
1535 (texinfo-sequentially-insert-pointer level 'next)
1536 (texinfo-sequentially-insert-pointer level 'previous)
1537 (texinfo-sequentially-insert-pointer level 'up)
1538 (texinfo-clean-up-node-line)))))
1540 (defun texinfo-sequentially-find-pointer (level direction)
1541 "Find next or previous pointer sequentially in Texinfo file, or up pointer.
1542 Move point to section associated with the pointer. Find point even if
1543 it is in a different section.
1545 Return type of pointer (either `normal' or `no-pointer').
1547 The first argument is a string specifying the general kind of section
1548 such as \"chapter\" or \"section\". The section found will be at the
1549 same hierarchical level in the Texinfo file, or, in the case of the up
1550 pointer, some level higher. The second argument (one of `next',
1551 `previous', or `up') specifies whether to find the `Next', `Previous',
1552 or `Up' pointer."
1553 (let ((case-fold-search t))
1554 (cond ((eq direction 'next)
1555 (forward-line 3) ; skip over current node
1556 (if (re-search-forward
1557 texinfo-section-types-regexp
1558 (point-max)
1560 'normal
1561 'no-pointer))
1562 ((eq direction 'previous)
1563 (if (re-search-backward
1564 texinfo-section-types-regexp
1565 (point-min)
1567 'normal
1568 'no-pointer))
1569 ((eq direction 'up)
1570 (if (re-search-backward
1571 (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
1572 beginning
1574 'normal
1575 'no-pointer))
1577 (error "texinfo-sequential-find-pointer: lack proper arguments")))))
1579 (defun texinfo-sequentially-insert-pointer (level direction)
1580 "Insert the `Next', `Previous' or `Up' node name at point.
1581 Move point forward.
1583 The first argument is the hierarchical level of the Texinfo file, a
1584 string such as \"section\". The second argument is direction, one of
1585 `next', `previous', or `up'."
1587 (end-of-line)
1588 (insert
1589 ", "
1590 (save-excursion
1591 (texinfo-pointer-name
1592 (texinfo-sequentially-find-pointer level direction)))))
1595 ;;; Inserting `@node' lines
1596 ;; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
1597 ;; before the `@chapter', `@section', and such like lines of a region
1598 ;; in a Texinfo file.
1600 (defun texinfo-insert-node-lines (beginning end &optional title-p)
1601 "Insert missing `@node' lines in region of Texinfo file.
1602 Non-nil argument (prefix, if interactive) means also to insert the
1603 section titles as node names; and also to insert the section titles as
1604 node names in pre-existing `@node' lines that lack names."
1605 (interactive "r\nP")
1607 ;; Use marker; after inserting node lines, leave point at end of
1608 ;; region and mark at beginning.
1610 (let (beginning-marker end-marker title last-section-position)
1612 ;; Save current position on mark ring and set mark to end.
1613 (push-mark end t)
1614 (setq end-marker (mark-marker))
1616 (goto-char beginning)
1617 (while (re-search-forward
1618 texinfo-section-types-regexp
1619 end-marker
1620 'end)
1621 ;; Copy title if desired.
1622 (if title-p
1623 (progn
1624 (beginning-of-line)
1625 (forward-word 1)
1626 (skip-chars-forward " \t")
1627 (setq title (buffer-substring
1628 (point)
1629 (save-excursion (end-of-line) (point))))))
1630 ;; Insert node line if necessary.
1631 (if (re-search-backward
1632 "^@node"
1633 ;; Avoid finding previous node line if node lines are close.
1634 (or last-section-position
1635 (save-excursion (forward-line -2) (point))) t)
1636 ;; @node is present, and point at beginning of that line
1637 (forward-word 1) ; Leave point just after @node.
1638 ;; Else @node missing; insert one.
1639 (beginning-of-line) ; Beginning of `@section' line.
1640 (insert "@node\n")
1641 (backward-char 1)) ; Leave point just after `@node'.
1642 ;; Insert title if desired.
1643 (if title-p
1644 (progn
1645 (skip-chars-forward " \t")
1646 ;; Use regexp based on what info looks for
1647 ;; (alternatively, use "[a-zA-Z]+");
1648 ;; this means we only insert a title if none exists.
1649 (if (not (looking-at "[^,\t\n ]+"))
1650 (progn
1651 (beginning-of-line)
1652 (forward-word 1)
1653 (insert " " title)
1654 (message "Inserted title %s ... " title)))))
1655 ;; Go forward beyond current section title.
1656 (re-search-forward texinfo-section-types-regexp
1657 (save-excursion (forward-line 3) (point)) t)
1658 (setq last-section-position (point))
1659 (forward-line 1))
1661 ;; Leave point at end of region, mark at beginning.
1662 (set-mark beginning)
1664 (if title-p
1665 (message
1666 "Done inserting node lines and titles. You may save the buffer.")
1667 (message "Done inserting node lines. You may save the buffer."))))
1670 ;;; Update and create menus for multi-file Texinfo sources
1672 ;; 1. M-x texinfo-multiple-files-update
1674 ;; Read the include file list of an outer Texinfo file and
1675 ;; update all highest level nodes in the files listed and insert a
1676 ;; main menu in the outer file after its top node.
1678 ;; 2. C-u M-x texinfo-multiple-files-update
1680 ;; Same as 1, but insert a master menu. (Saves reupdating lower
1681 ;; level menus and nodes.) This command simply reads every menu,
1682 ;; so if the menus are wrong, the master menu will be wrong.
1683 ;; Similarly, if the lower level node pointers are wrong, they
1684 ;; will stay wrong.
1686 ;; 3. C-u 2 M-x texinfo-multiple-files-update
1688 ;; Read the include file list of an outer Texinfo file and
1689 ;; update all nodes and menus in the files listed and insert a
1690 ;; master menu in the outer file after its top node.
1692 ;;; Note: these functions:
1694 ;;; * Do not save or delete any buffers. You may fill up your memory.
1695 ;;; * Do not handle any pre-existing nodes in outer file.
1696 ;;; Hence, you may need a file for indices.
1699 ;;; Auxiliary functions for multiple file updating
1701 (defun texinfo-multi-file-included-list (outer-file)
1702 "Return a list of the included files in OUTER-FILE."
1703 (let ((included-file-list (list outer-file))
1704 start)
1705 (save-excursion
1706 (switch-to-buffer (find-file-noselect outer-file))
1707 (widen)
1708 (goto-char (point-min))
1709 (while (re-search-forward "^@include" nil t)
1710 (skip-chars-forward " \t")
1711 (setq start (point))
1712 (end-of-line)
1713 (skip-chars-backward " \t")
1714 (setq included-file-list
1715 (cons (buffer-substring start (point))
1716 included-file-list)))
1717 (nreverse included-file-list))))
1719 (defun texinfo-copy-next-section-title ()
1720 "Return the name of the immediately following section as a string.
1722 Start with point at the beginning of the node line. Leave point at the
1723 same place. If there is no title, returns an empty string."
1725 (save-excursion
1726 (end-of-line)
1727 (let ((node-end (or
1728 (save-excursion
1729 (if (re-search-forward "\\(^@node\\)" nil t)
1730 (match-beginning 0)))
1731 (point-max))))
1732 (if (re-search-forward texinfo-section-types-regexp node-end t)
1733 (progn
1734 (beginning-of-line)
1735 ;; copy title
1736 (let ((title
1737 (buffer-substring
1738 (progn (forward-word 1) ; skip over section type
1739 (skip-chars-forward " \t") ; and over spaces
1740 (point))
1741 (progn (end-of-line) (point)))))
1742 title))
1743 ""))))
1745 (defun texinfo-multi-file-update (files &optional update-everything)
1746 "Update first node pointers in each file in FILES.
1747 Return a list of the node names.
1749 The first file in the list is an outer file; the remaining are
1750 files included in the outer file with `@include' commands.
1752 If optional arg UPDATE-EVERYTHING non-nil, update every menu and
1753 pointer in each of the included files.
1755 Also update the `Top' level node pointers of the outer file.
1757 Requirements:
1759 * the first file in the FILES list must be the outer file,
1760 * each of the included files must contain exactly one highest
1761 hierarchical level node,
1762 * this node must be the first node in the included file,
1763 * each highest hierarchical level node must be of the same type.
1765 Thus, normally, each included file contains one, and only one, chapter."
1767 ;; The menu-list has the form:
1769 ;; \(\(\"node-name1\" . \"title1\"\)
1770 ;; \(\"node-name2\" . \"title2\"\) ... \)
1772 ;; However, there does not need to be a title field and this function
1773 ;; does not fill it; however a comment tells you how to do so.
1774 ;; You would use the title field if you wanted to insert titles in the
1775 ;; description slot of a menu as a description.
1777 (let ((case-fold-search t)
1778 menu-list)
1780 ;; Find the name of the first node of the first included file.
1781 (switch-to-buffer (find-file-noselect (car (cdr files))))
1782 (widen)
1783 (goto-char (point-min))
1784 (if (not (re-search-forward "^@node" nil t))
1785 (error "No `@node' line found in %s !" (buffer-name)))
1786 (beginning-of-line)
1787 (texinfo-check-for-node-name)
1788 (setq next-node-name (texinfo-copy-node-name))
1790 (setq menu-list
1791 (cons (cons
1792 next-node-name
1793 (prog1 "" (forward-line 1)))
1794 ;; Use following to insert section titles automatically.
1795 ;; (texinfo-copy-next-section-title)
1796 menu-list))
1798 ;; Go to outer file
1799 (switch-to-buffer (find-file-noselect (car files)))
1800 (goto-char (point-min))
1801 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
1802 (error "This buffer needs a Top node!"))
1803 (beginning-of-line)
1804 (texinfo-delete-existing-pointers)
1805 (end-of-line)
1806 (insert ", " next-node-name ", (dir), (dir)")
1807 (beginning-of-line)
1808 (setq previous-node-name "Top")
1809 (setq files (cdr files))
1811 (while files
1813 (if (not (cdr files))
1814 ;; No next file
1815 (setq next-node-name "")
1816 ;; Else,
1817 ;; find the name of the first node in the next file.
1818 (switch-to-buffer (find-file-noselect (car (cdr files))))
1819 (widen)
1820 (goto-char (point-min))
1821 (if (not (re-search-forward "^@node" nil t))
1822 (error "No `@node' line found in %s !" (buffer-name)))
1823 (beginning-of-line)
1824 (texinfo-check-for-node-name)
1825 (setq next-node-name (texinfo-copy-node-name))
1826 (setq menu-list
1827 (cons (cons
1828 next-node-name
1829 (prog1 "" (forward-line 1)))
1830 ;; Use following to insert section titles automatically.
1831 ;; (texinfo-copy-next-section-title)
1832 menu-list)))
1834 ;; Go to node to be updated.
1835 (switch-to-buffer (find-file-noselect (car files)))
1836 (goto-char (point-min))
1837 (if (not (re-search-forward "^@node" nil t))
1838 (error "No `@node' line found in %s !" (buffer-name)))
1839 (beginning-of-line)
1841 ;; Update other menus and nodes if requested.
1842 (if update-everything (texinfo-all-menus-update t))
1844 (beginning-of-line)
1845 (texinfo-delete-existing-pointers)
1846 (end-of-line)
1847 (insert ", " next-node-name ", " previous-node-name ", " up-node-name)
1849 (beginning-of-line)
1850 (setq previous-node-name (texinfo-copy-node-name))
1852 (setq files (cdr files)))
1853 (nreverse menu-list)))
1855 (defun texinfo-multi-files-insert-main-menu (menu-list)
1856 "Insert formatted main menu at point.
1857 Indents the first line of the description, if any, to the value of
1858 `texinfo-column-for-description'."
1860 (insert "@menu\n")
1861 (while menu-list
1862 ;; Every menu entry starts with a star and a space.
1863 (insert "* ")
1865 ;; Insert the node name (and menu entry name, if present).
1866 (let ((node-part (car (car menu-list))))
1867 (if (stringp node-part)
1868 ;; "Double colon" entry line; menu entry and node name are the same,
1869 (insert (format "%s::" node-part))
1870 ;; "Single colon" entry line; menu entry and node name are different.
1871 (insert (format "%s: %s." (car node-part) (cdr node-part)))))
1873 ;; Insert the description, if present.
1874 (if (cdr (car menu-list))
1875 (progn
1876 ;; Move to right place.
1877 (indent-to texinfo-column-for-description 2)
1878 ;; Insert description.
1879 (insert (format "%s" (cdr (car menu-list))))))
1881 (insert "\n") ; end this menu entry
1882 (setq menu-list (cdr menu-list)))
1883 (insert "@end menu"))
1885 (defun texinfo-multi-file-master-menu-list (files-list)
1886 "Return master menu list from files in FILES-LIST.
1887 Menu entries in each file collected using `texinfo-master-menu-list'.
1889 The first file in FILES-LIST must be the outer file; the others must
1890 be the files included within it. A main menu must already exist."
1891 (save-excursion
1892 (let (master-menu-list)
1893 (while files-list
1894 (switch-to-buffer (find-file-noselect (car files-list)))
1895 (message "Working on: %s " (current-buffer))
1896 (goto-char (point-min))
1897 (setq master-menu-list
1898 (append master-menu-list (texinfo-master-menu-list)))
1899 (setq files-list (cdr files-list)))
1900 master-menu-list)))
1903 ;;; The multiple-file update function
1905 (defun texinfo-multiple-files-update
1906 (outer-file &optional update-everything make-master-menu)
1907 "Update first node pointers in each file included in OUTER-FILE;
1908 create or update the `Top' level node pointers and the main menu in
1909 the outer file that refers to such nodes. This does not create or
1910 update menus or pointers within the included files.
1912 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
1913 insert a master menu in OUTER-FILE in addition to creating or updating
1914 pointers in the first @node line in each included file and creating or
1915 updating the `Top' level node pointers of the outer file. This does
1916 not create or update other menus and pointers within the included
1917 files.
1919 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
1920 interactive), update all the menus and all the `Next', `Previous', and
1921 `Up' pointers of all the files included in OUTER-FILE before inserting
1922 a master menu in OUTER-FILE. Also, update the `Top' level node
1923 pointers of OUTER-FILE.
1925 Notes:
1927 * this command does NOT save any files--you must save the
1928 outer file and any modified, included files.
1930 * except for the `Top' node, this command does NOT handle any
1931 pre-existing nodes in the outer file; hence, indices must be
1932 enclosed in an included file.
1934 Requirements:
1936 * each of the included files must contain exactly one highest
1937 hierarchical level node,
1938 * this highest node must be the first node in the included file,
1939 * each highest hierarchical level node must be of the same type.
1941 Thus, normally, each included file contains one, and only one,
1942 chapter."
1944 (interactive (cons
1945 (read-string
1946 "Name of outer `include' file: "
1947 (buffer-file-name))
1948 (cond ((not current-prefix-arg)
1949 '(nil nil))
1950 ((listp current-prefix-arg)
1951 '(t nil)) ; make-master-menu
1952 ((numberp current-prefix-arg)
1953 '(t t)) ; update-everything
1956 (let* ((included-file-list (texinfo-multi-file-included-list outer-file))
1957 (files included-file-list)
1958 main-menu-list
1959 next-node-name
1960 previous-node-name
1961 (up-node-name "Top"))
1963 ;;; Update the pointers
1964 ;;; and collect the names of the nodes and titles
1965 (setq main-menu-list (texinfo-multi-file-update files update-everything))
1967 ;;; Insert main menu
1969 ;; Go to outer file
1970 (switch-to-buffer (find-file-noselect (car included-file-list)))
1971 (if (texinfo-old-menu-p
1972 (point-min)
1973 (save-excursion
1974 (re-search-forward "^@include")
1975 (beginning-of-line)
1976 (point)))
1978 ;; If found, leave point after word `menu' on the `@menu' line.
1979 (progn
1980 (texinfo-incorporate-descriptions main-menu-list)
1981 ;; Delete existing menu.
1982 (beginning-of-line)
1983 (delete-region
1984 (point)
1985 (save-excursion (re-search-forward "^@end menu") (point)))
1986 ;; Insert main menu
1987 (texinfo-multi-files-insert-main-menu main-menu-list))
1989 ;; Else no current menu; insert it before `@include'
1990 (texinfo-multi-files-insert-main-menu main-menu-list))
1992 ;;; Insert master menu
1994 (if make-master-menu
1995 (progn
1996 ;; First, removing detailed part of any pre-existing master menu
1997 (goto-char (point-min))
1998 (if (search-forward texinfo-master-menu-header nil t)
1999 (progn
2000 (goto-char (match-beginning 0))
2001 ;; Check if @detailmenu kludge is used;
2002 ;; if so, leave point before @detailmenu.
2003 (search-backward "\n@detailmenu"
2004 (save-excursion (forward-line -3) (point))
2006 ;; Remove detailed master menu listing
2007 (let ((end-of-detailed-menu-descriptions
2008 (save-excursion ; beginning of end menu line
2009 (goto-char (texinfo-menu-end))
2010 (beginning-of-line) (forward-char -1)
2011 (point))))
2012 (delete-region (point) end-of-detailed-menu-descriptions))))
2014 ;; Create a master menu and insert it
2015 (texinfo-insert-master-menu-list
2016 (texinfo-multi-file-master-menu-list
2017 included-file-list)))))
2019 ;; Remove unwanted extra lines.
2020 (save-excursion
2021 (goto-char (point-min))
2023 (re-search-forward "^@menu")
2024 (forward-line -1)
2025 (insert "\n") ; Ensure at least one blank line.
2026 (delete-blank-lines)
2028 (re-search-forward "^@end menu")
2029 (forward-line 1)
2030 (insert "\n") ; Ensure at least one blank line.
2031 (delete-blank-lines))
2033 (message "Multiple files updated."))
2036 ;;; Place `provide' at end of file.
2037 (provide 'texnfo-upd)
2039 ;;; texnfo-upd.el ends here