(access_keymap): Return the cdr of the binding of
[emacs.git] / lisp / textmodes / texnfo-upd.el
blob1aed3154d16e6338eb7bcd79098cdbdfacf7b1a8
1 ;;; texnfo-upd.el --- utilities for updating nodes and menus in Texinfo files
3 ;; Copyright (C) 1989, 1990, 1991, 1992, 2001 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 "\\|" ; or
295 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
296 "\\)?" ; end of expression
297 (eval (cdr (assoc level texinfo-update-menu-lower-regexps))))
298 ;; the next higher level node marks the end of this
299 ;; section, and no lower level node will be found beyond
300 ;; this position even if region-end is farther off
301 (texinfo-update-menu-region-end level)
303 (goto-char (match-beginning 1)))))
305 (defun texinfo-find-higher-level-node (level region-end)
306 "Search forward from point for node at any higher level than argument LEVEL.
307 Search is limited to the end of the marked region, REGION-END.
309 Return t if the node is found, else nil. Leave point at the beginning
310 of the node if one is found; else do not move point.
312 A `@node' line starting at point does count as a match;
313 if the match is found there, the value is t and point does not move."
315 (let ((case-fold-search t))
316 (cond
317 ((< level 3)
318 (if (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" region-end t)
319 (progn (beginning-of-line) t)))
321 (if (re-search-forward
322 (concat
323 "\\(^@node\\).*\n" ; match node line
324 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
325 "\\|" ; or
326 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
327 "\\|" ; or
328 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
329 "\\)?" ; end of expression
330 (eval (cdr (assoc level texinfo-update-menu-higher-regexps))))
331 region-end t)
332 (progn (beginning-of-line) t))))))
335 ;;; Making the list of new menu entries
337 (defun texinfo-make-menu-list (beginning end level)
338 "Make a list of node names and their descriptions.
339 Point is left at the end of the menu region, but the menu is not inserted.
341 First argument is position from which to start making menu list;
342 second argument is end of region in which to try to locate entries;
343 third argument is the level of the nodes that are the entries.
345 Node names and descriptions are dotted pairs of strings. Each pair is
346 an element of the list. If the description does not exist, the
347 element consists only of the node name."
348 (goto-char beginning)
349 (let (new-menu-list)
350 (while (texinfo-menu-locate-entry-p level end)
351 (setq new-menu-list
352 (cons (cons
353 (texinfo-copy-node-name)
354 (prog1 "" (forward-line 1)))
355 ;; Use following to insert section titles automatically.
356 ;; (texinfo-copy-section-title))
357 new-menu-list)))
358 (reverse new-menu-list)))
360 (defun texinfo-menu-locate-entry-p (level search-end)
361 "Find a node that will be part of menu for this section.
362 First argument is a string such as \"section\" specifying the general
363 hierarchical level of the menu; second argument is a position
364 specifying the end of the search.
366 The function returns t if the node is found, else nil. It searches
367 forward from point, and leaves point at the beginning of the node.
369 The function finds entries of the same type. Thus `subsections' and
370 `unnumberedsubsecs' will appear in the same menu."
371 (let ((case-fold-search t))
372 (if (re-search-forward
373 (concat
374 "\\(^@node\\).*\n" ; match node line
375 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
376 "\\|" ; or
377 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
378 "\\|" ; or
379 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
380 "\\)?" ; end of expression
381 (eval
382 (cdr (assoc level texinfo-update-menu-same-level-regexps))))
383 search-end
385 (goto-char (match-beginning 1)))))
387 (defun texinfo-copy-node-name ()
388 "Return the node name as a string.
390 Start with point at the beginning of the node line; copy the text
391 after the node command up to the first comma on the line, if any, and
392 return the text as a string. Leaves point at the beginning of the
393 line. If there is no node name, returns an empty string."
395 (save-excursion
396 (buffer-substring
397 (progn (forward-word 1) ; skip over node command
398 (skip-chars-forward " \t") ; and over spaces
399 (point))
400 (if (search-forward
402 (save-excursion (end-of-line) (point)) t) ; bound search
403 (1- (point))
404 (end-of-line) (point)))))
406 (defun texinfo-copy-section-title ()
407 "Return the title of the section as a string.
408 The title is used as a description line in the menu when one does not
409 already exist.
411 Move point to the beginning of the appropriate section line by going
412 to the start of the text matched by last regexp searched for, which
413 must have been done by `texinfo-menu-locate-entry-p'."
415 ;; could use the same re-search as in `texinfo-menu-locate-entry-p'
416 ;; instead of using `match-beginning'; such a variation would be
417 ;; more general, but would waste information already collected
419 (goto-char (match-beginning 7)) ; match section name
421 (buffer-substring
422 (progn (forward-word 1) ; skip over section type
423 (skip-chars-forward " \t") ; and over spaces
424 (point))
425 (progn (end-of-line) (point))))
428 ;;; Handling the old menu
430 (defun texinfo-old-menu-p (beginning first)
431 "Move point to the beginning of the menu for this section, if any.
432 Otherwise move point to the end of the first node of this section.
433 Return t if a menu is found, nil otherwise.
435 First argument is the position of the beginning of the section in which
436 the menu will be located; second argument is the position of the first
437 node within the section.
439 If no menu is found, the function inserts two newlines just before the
440 end of the section, and leaves point there where a menu ought to be."
441 (goto-char beginning)
442 (if (not (re-search-forward "^@menu" first 'goto-end))
443 (progn (insert "\n\n") (forward-line -2) nil)
446 (defun texinfo-incorporate-descriptions (new-menu-list)
447 "Copy the old menu line descriptions that exist to the new menu.
449 Point must be at beginning of old menu.
451 If the node-name of the new menu is found in the old menu, insert the
452 old description into the new entry.
454 For this function, the new menu is a list made up of lists of dotted
455 pairs in which the first element of the pair is the node name and the
456 second element the description. The new menu is changed destructively.
457 The old menu is the menu as it appears in the Texinfo file."
459 (let ((new-menu-list-pointer new-menu-list)
460 (end-of-menu (texinfo-menu-end)))
461 (while new-menu-list
462 (save-excursion ; keep point at beginning of menu
463 (if (re-search-forward
464 ;; Existing nodes can have the form
465 ;; * NODE NAME:: DESCRIPTION
466 ;; or
467 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
469 ;; Recognize both when looking for the description.
470 (concat "\\* \\(" ; so only menu entries are found
471 (regexp-quote (car (car new-menu-list))) "::"
472 "\\|"
473 ".*: " (regexp-quote (car (car new-menu-list))) "[.,\t\n]"
474 "\\)"
475 ) ; so only complete entries are found
476 end-of-menu
478 (setcdr (car new-menu-list)
479 (texinfo-menu-copy-old-description end-of-menu))))
480 (setq new-menu-list (cdr new-menu-list)))
481 (setq new-menu-list new-menu-list-pointer)))
483 (defun texinfo-incorporate-menu-entry-names (new-menu-list)
484 "Copy any old menu entry names to the new menu.
486 Point must be at beginning of old menu.
488 If the node-name of the new menu entry cannot be found in the old
489 menu, do nothing.
491 For this function, the new menu is a list made up of lists of dotted
492 pairs in which the first element of the pair is the node name and the
493 second element is the description (or nil).
495 If we find an existing menu entry name, we change the first element of
496 the pair to be another dotted pair in which the car is the menu entry
497 name and the cdr is the node name.
499 NEW-MENU-LIST is changed destructively. The old menu is the menu as it
500 appears in the texinfo file."
502 (let ((new-menu-list-pointer new-menu-list)
503 (end-of-menu (texinfo-menu-end)))
504 (while new-menu-list
505 (save-excursion ; keep point at beginning of menu
506 (if (re-search-forward
507 ;; Existing nodes can have the form
508 ;; * NODE NAME:: DESCRIPTION
509 ;; or
510 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
512 ;; We're interested in the second case.
513 (concat "\\* " ; so only menu entries are found
514 "\\(.*\\): " (regexp-quote (car (car new-menu-list)))
515 "[.,\t\n]")
516 end-of-menu
518 (setcar
519 (car new-menu-list) ; replace the node name
520 (cons (buffer-substring (match-beginning 1) (match-end 1))
521 (car (car new-menu-list)))))
522 (setq new-menu-list (cdr new-menu-list))))
523 (setq new-menu-list new-menu-list-pointer)))
525 (defun texinfo-menu-copy-old-description (end-of-menu)
526 "Return description field of old menu line as string.
527 Point must be located just after the node name. Point left before description.
528 Single argument, END-OF-MENU, is position limiting search."
529 (skip-chars-forward "[:.,\t\n ]+")
530 ;; don't copy a carriage return at line beginning with asterisk!
531 ;; do copy a description that begins with an `@'!
532 ;; !! Known bug: does not copy descriptions starting with ^|\{?* etc.
533 (if (and (looking-at "\\(\\w+\\|@\\)")
534 (not (looking-at "\\(^\\* \\|^@end menu\\)")))
535 (buffer-substring
536 (point)
537 (save-excursion
538 (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t)
539 (forward-line -1)
540 (end-of-line) ; go to end of last description line
541 (point)))
542 ""))
544 (defun texinfo-menu-end ()
545 "Return position of end of menu, but don't move point.
546 Signal an error if not end of menu."
547 (save-excursion
548 (if (re-search-forward "^@end menu" nil t)
549 (point)
550 (error "Menu does not have an end."))))
552 (defun texinfo-delete-old-menu (beginning first)
553 "Delete the old menu. Point must be in or after menu.
554 First argument is position of the beginning of the section in which
555 the menu will be located; second argument is the position of the first
556 node within the section."
557 ;; No third arg to search, so error if search fails.
558 (re-search-backward "^@menu" beginning)
559 (delete-region (point)
560 (save-excursion
561 (re-search-forward "^@end menu" first)
562 (point))))
565 ;;; Inserting new menu
567 ;; try 32, but perhaps 24 is better
568 (defvar texinfo-column-for-description 32
569 "*Column at which descriptions start in a Texinfo menu.")
571 (defun texinfo-insert-menu (menu-list node-name)
572 "Insert formatted menu at point.
573 Indents the first line of the description, if any, to the value of
574 texinfo-column-for-description.
576 MENU-LIST has form:
578 \(\(\"node-name1\" . \"description\"\)
579 \(\"node-name2\" . \"description\"\) ... \)
581 However, the description field might be nil.
583 Also, the node-name field might itself be a dotted pair (call it P) of
584 strings instead of just a string. In that case, the car of P
585 is the menu entry name, and the cdr of P is the node name."
587 (insert "@menu\n")
588 (while menu-list
589 ;; Every menu entry starts with a star and a space.
590 (insert "* ")
592 ;; Insert the node name (and menu entry name, if present).
593 (let ((node-part (car (car menu-list))))
594 (if (stringp node-part)
595 ;; "Double colon" entry line; menu entry and node name are the same,
596 (insert (format "%s::" node-part))
597 ;; "Single colon" entry line; menu entry and node name are different.
598 (insert (format "%s: %s." (car node-part) (cdr node-part)))))
600 ;; Insert the description, if present.
601 (if (cdr (car menu-list))
602 (progn
603 ;; Move to right place.
604 (indent-to texinfo-column-for-description 2)
605 ;; Insert description.
606 (insert (format "%s" (cdr (car menu-list))))))
608 (insert "\n") ; end this menu entry
609 (setq menu-list (cdr menu-list)))
610 (insert "@end menu")
611 (message
612 "Updated \"%s\" level menu following node: %s ... " level node-name))
615 ;;; Starting menu descriptions by inserting titles
617 (defun texinfo-start-menu-description ()
618 "In this menu entry, insert the node's section title as a description.
619 Position point at beginning of description ready for editing.
620 Do not insert a title if the line contains an existing description.
622 You will need to edit the inserted text since a useful description
623 complements the node name rather than repeats it as a title does."
625 (interactive)
626 (let (beginning end node-name title)
627 (save-excursion
628 (beginning-of-line)
629 (if (search-forward "* " (save-excursion (end-of-line) (point)) t)
630 (progn (skip-chars-forward " \t")
631 (setq beginning (point)))
632 (error "This is not a line in a menu!"))
634 (cond
635 ;; "Double colon" entry line; menu entry and node name are the same,
636 ((search-forward "::" (save-excursion (end-of-line) (point)) t)
637 (if (looking-at "[ \t]*[^ \t\n]+")
638 (error "Descriptive text already exists."))
639 (skip-chars-backward ": \t")
640 (setq node-name (buffer-substring beginning (point))))
642 ;; "Single colon" entry line; menu entry and node name are different.
643 ((search-forward ":" (save-excursion (end-of-line) (point)) t)
644 (skip-chars-forward " \t")
645 (setq beginning (point))
646 ;; Menu entry line ends in a period, comma, or tab.
647 (if (re-search-forward "[.,\t]"
648 (save-excursion (forward-line 1) (point)) t)
649 (progn
650 (if (looking-at "[ \t]*[^ \t\n]+")
651 (error "Descriptive text already exists."))
652 (skip-chars-backward "., \t")
653 (setq node-name (buffer-substring beginning (point))))
654 ;; Menu entry line ends in a return.
655 (re-search-forward ".*\n"
656 (save-excursion (forward-line 1) (point)) t)
657 (skip-chars-backward " \t\n")
658 (setq node-name (buffer-substring beginning (point)))
659 (if (= 0 (length node-name))
660 (error "No node name on this line.")
661 (insert "."))))
662 (t (error "No node name on this line.")))
663 ;; Search for node that matches node name, and copy the section title.
664 (if (re-search-forward
665 (concat
666 "^@node[ \t]+"
667 (regexp-quote node-name)
668 ".*\n" ; match node line
669 "\\("
670 "\\(\\(^@c \\|^@comment\\).*\n\\)" ; match comment line, if any
671 "\\|" ; or
672 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
673 "\\|" ; or
674 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
675 "\\)?" ; end of expression
676 "\\)?")
677 nil t)
678 (progn
679 (setq title
680 (buffer-substring
681 ;; skip over section type
682 (progn (forward-word 1)
683 ;; and over spaces
684 (skip-chars-forward " \t")
685 (point))
686 (progn (end-of-line)
687 (skip-chars-backward " \t")
688 (point)))))
689 (error "Cannot find node to match node name in menu entry.")))
690 ;; Return point to the menu and insert the title.
691 (end-of-line)
692 (delete-region
693 (point)
694 (save-excursion (skip-chars-backward " \t") (point)))
695 (indent-to texinfo-column-for-description 2)
696 (save-excursion (insert title))))
699 ;;; Handling description indentation
701 ;; Since the make-menu functions indent descriptions, these functions
702 ;; are useful primarily for indenting a single menu specially.
704 (defun texinfo-indent-menu-description (column &optional region-p)
705 "Indent every description in menu following point to COLUMN.
706 Non-nil argument (prefix, if interactive) means indent every
707 description in every menu in the region. Does not indent second and
708 subsequent lines of a multi-line description."
710 (interactive
711 "nIndent menu descriptions to (column number): \nP")
712 (save-excursion
713 (save-restriction
714 (widen)
715 (if (not region-p)
716 (progn
717 (re-search-forward "^@menu")
718 (texinfo-menu-indent-description column)
719 (message
720 "Indented descriptions in menu. You may save the buffer."))
721 ;;else
722 (message "Indenting every menu description in region... ")
723 (goto-char (region-beginning))
724 (while (and (< (point) (region-end))
725 (texinfo-locate-menu-p))
726 (forward-line 1)
727 (texinfo-menu-indent-description column))
728 (message "Indenting done. You may save the buffer.")))))
730 (defun texinfo-menu-indent-description (to-column-number)
731 "Indent the Texinfo file menu description to TO-COLUMN-NUMBER.
732 Start with point just after the word `menu' in the `@menu' line and
733 leave point on the line before the `@end menu' line. Does not indent
734 second and subsequent lines of a multi-line description."
735 (let* ((beginning-of-next-line (point)))
736 (while (< beginning-of-next-line
737 (save-excursion ; beginning of end menu line
738 (goto-char (texinfo-menu-end))
739 (beginning-of-line)
740 (point)))
742 (if (re-search-forward "\\* \\(.*::\\|.*: [^.,\t\n]+[.,\t]\\)"
743 (texinfo-menu-end)
745 (progn
746 (let ((beginning-white-space (point)))
747 (skip-chars-forward " \t") ; skip over spaces
748 (if (looking-at "\\(@\\|\\w\\)+") ; if there is text
749 (progn
750 ;; remove pre-existing indentation
751 (delete-region beginning-white-space (point))
752 (indent-to-column to-column-number))))))
753 ;; position point at beginning of next line
754 (forward-line 1)
755 (setq beginning-of-next-line (point)))))
758 ;;; Making the master menu
760 (defun texinfo-master-menu (update-all-nodes-menus-p)
761 "Make a master menu for a whole Texinfo file.
762 Non-nil argument (prefix, if interactive) means first update all
763 existing nodes and menus. Remove pre-existing master menu, if there is one.
765 This function creates a master menu that follows the top node. The
766 master menu includes every entry from all the other menus. It
767 replaces any existing ordinary menu that follows the top node.
769 If called with a non-nil argument, this function first updates all the
770 menus in the buffer (incorporating descriptions from pre-existing
771 menus) before it constructs the master menu.
773 The function removes the detailed part of an already existing master
774 menu. This action depends on the pre-existing master menu using the
775 standard `texinfo-master-menu-header'.
777 The master menu has the following format, which is adapted from the
778 recommendation in the Texinfo Manual:
780 * The first part contains the major nodes in the Texinfo file: the
781 nodes for the chapters, chapter-like sections, and the major
782 appendices. This includes the indices, so long as they are in
783 chapter-like sections, such as unnumbered sections.
785 * The second and subsequent parts contain a listing of the other,
786 lower level menus, in order. This way, an inquirer can go
787 directly to a particular node if he or she is searching for
788 specific information.
790 Each of the menus in the detailed node listing is introduced by the
791 title of the section containing the menu."
793 (interactive "P")
794 (let ((case-fold-search t))
795 (widen)
796 (goto-char (point-min))
798 ;; Move point to location after `top'.
799 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
800 (error "This buffer needs a Top node!"))
802 (let ((first-chapter
803 (save-excursion
804 (or (re-search-forward "^@node" nil t)
805 (error "Too few nodes for a master menu!"))
806 (point))))
807 (if (search-forward texinfo-master-menu-header first-chapter t)
808 (progn
809 ;; Check if @detailmenu kludge is used;
810 ;; if so, leave point before @detailmenu.
811 (search-backward "\n@detailmenu"
812 (save-excursion (forward-line -3) (point))
814 ;; Remove detailed master menu listing
815 (goto-char (match-beginning 0))
816 (let ((end-of-detailed-menu-descriptions
817 (save-excursion ; beginning of end menu line
818 (goto-char (texinfo-menu-end))
819 (beginning-of-line) (forward-char -1)
820 (point))))
821 (delete-region (point) end-of-detailed-menu-descriptions)))))
823 (if update-all-nodes-menus-p
824 (progn
825 (message "Making a master menu in %s ...first updating all nodes... "
826 (buffer-name))
827 (texinfo-update-node (point-min) (point-max))
829 (message "Updating all menus in %s ... " (buffer-name))
830 (texinfo-make-menu (point-min) (point-max))))
832 (message "Now making the master menu in %s... " (buffer-name))
833 (goto-char (point-min))
834 (texinfo-insert-master-menu-list
835 (texinfo-master-menu-list))
837 ;; Remove extra newlines that texinfo-insert-master-menu-list
838 ;; may have inserted.
840 (save-excursion
841 (goto-char (point-min))
843 (if (search-forward texinfo-master-menu-header nil t)
844 (progn
845 (goto-char (match-beginning 0))
846 ;; Check if @detailmenu kludge is used;
847 ;; if so, leave point before @detailmenu.
848 (search-backward "\n@detailmenu"
849 (save-excursion (forward-line -3) (point))
851 (insert "\n")
852 (delete-blank-lines)
853 (goto-char (point-min))))
855 (re-search-forward "^@menu")
856 (forward-line -1)
857 (delete-blank-lines)
859 (re-search-forward "^@end menu")
860 (forward-line 1)
861 (delete-blank-lines))
863 (message
864 "Done...completed making master menu. You may save the buffer.")))
866 (defun texinfo-master-menu-list ()
867 "Return a list of menu entries and header lines for the master menu.
869 Start with the menu for chapters and indices and then find each
870 following menu and the title of the node preceding that menu.
872 The master menu list has this form:
874 \(\(\(... \"entry-1-2\" \"entry-1\"\) \"title-1\"\)
875 \(\(... \"entry-2-2\" \"entry-2-1\"\) \"title-2\"\)
876 ...\)
878 However, there does not need to be a title field."
880 (let (master-menu-list)
881 (while (texinfo-locate-menu-p)
882 (setq master-menu-list
883 (cons (list
884 (texinfo-copy-menu)
885 (texinfo-copy-menu-title))
886 master-menu-list)))
887 (reverse master-menu-list)))
889 (defun texinfo-insert-master-menu-list (master-menu-list)
890 "Format and insert the master menu in the current buffer."
891 (goto-char (point-min))
892 ;; Insert a master menu only after `Top' node and before next node
893 ;; \(or include file if there is no next node\).
894 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
895 (error "This buffer needs a Top node!"))
896 (let ((first-chapter
897 (save-excursion (re-search-forward "^@node\\|^@include") (point))))
898 (if (not (re-search-forward "^@menu" first-chapter t))
899 (error
900 "Buffer lacks ordinary `Top' menu in which to insert master.")))
901 (beginning-of-line)
902 (delete-region ; buffer must have ordinary top menu
903 (point)
904 (save-excursion (re-search-forward "^@end menu") (point)))
906 (save-excursion
907 ;; `master-menu-inserted-p' is a kludge to tell
908 ;; whether to insert @end detailmenu (see bleow)
909 (let (master-menu-inserted-p)
910 ;; Handle top of menu
911 (insert "\n@menu\n")
912 ;; Insert chapter menu entries
913 (setq this-very-menu-list (reverse (car (car master-menu-list))))
914 ;; Tell user what is going on.
915 (message "Inserting chapter menu entry: %s ... " this-very-menu-list)
916 (while this-very-menu-list
917 (insert "* " (car this-very-menu-list) "\n")
918 (setq this-very-menu-list (cdr this-very-menu-list)))
920 (setq master-menu-list (cdr master-menu-list))
922 ;; Only insert detailed master menu if there is one....
923 (if (car (car master-menu-list))
924 (progn (setq master-menu-inserted-p t)
925 (insert (concat "\n@detailmenu\n"
926 texinfo-master-menu-header))))
928 ;; @detailmenu added 5 Sept 1996 to `texinfo-master-menu-header'
929 ;; at Karl Berry's request to avert a bug in `makeinfo';
930 ;; all agree this is a bad kludge and should eventually be removed.
931 ;; @detailmenu ... @end detailmenu is a noop in `texinfmt.el'.
932 ;; See @end detailmenu below;
933 ;; also see `texinfo-all-menus-update' above, `texinfo-master-menu',
934 ;; `texinfo-multiple-files-update'.
936 ;; Now, insert all the other menus
938 ;; The menu master-menu-list has a form like this:
939 ;; ((("beta" "alpha") "title-A")
940 ;; (("delta" "gamma") "title-B"))
942 (while master-menu-list
944 (message
945 "Inserting menu for %s .... " (car (cdr (car master-menu-list))))
946 ;; insert title of menu section
947 (insert "\n" (car (cdr (car master-menu-list))) "\n\n")
949 ;; insert each menu entry
950 (setq this-very-menu-list (reverse (car (car master-menu-list))))
951 (while this-very-menu-list
952 (insert "* " (car this-very-menu-list) "\n")
953 (setq this-very-menu-list (cdr this-very-menu-list)))
955 (setq master-menu-list (cdr master-menu-list)))
957 ;; Finish menu
959 ;; @detailmenu (see note above)
960 ;; Only insert @end detailmenu if a master menu was inserted.
961 (if master-menu-inserted-p
962 (insert "\n@end detailmenu"))
963 (insert "\n@end menu\n\n"))))
965 (defun texinfo-locate-menu-p ()
966 "Find the next menu in the texinfo file.
967 If found, leave point after word `menu' on the `@menu' line, and return t.
968 If a menu is not found, do not move point and return nil."
969 (re-search-forward "\\(^@menu\\)" nil t))
971 (defun texinfo-copy-menu-title ()
972 "Return the title of the section preceding the menu as a string.
973 If such a title cannot be found, return an empty string. Do not move
974 point."
975 (let ((case-fold-search t))
976 (save-excursion
977 (if (re-search-backward
978 (concat
979 "\\(^@top"
980 "\\|" ; or
981 texinfo-section-types-regexp ; all other section types
982 "\\)")
985 (progn
986 (beginning-of-line)
987 (forward-word 1) ; skip over section type
988 (skip-chars-forward " \t") ; and over spaces
989 (buffer-substring
990 (point)
991 (progn (end-of-line) (point))))
992 ""))))
994 (defun texinfo-copy-menu ()
995 "Return the entries of an existing menu as a list.
996 Start with point just after the word `menu' in the `@menu' line
997 and leave point on the line before the `@end menu' line."
998 (let* (this-menu-list
999 (end-of-menu (texinfo-menu-end)) ; position of end of `@end menu'
1000 (last-entry (save-excursion ; position of beginning of
1001 ; last `* ' entry
1002 (goto-char end-of-menu)
1003 ;; handle multi-line description
1004 (if (not (re-search-backward "^\\* " nil t))
1005 (error "No entries in menu."))
1006 (point))))
1007 (while (< (point) last-entry)
1008 (if (re-search-forward "^\\* " end-of-menu t)
1009 (progn
1010 (setq this-menu-list
1011 (cons
1012 (buffer-substring
1013 (point)
1014 ;; copy multi-line descriptions
1015 (save-excursion
1016 (re-search-forward "\\(^\\* \\|^@e\\)" nil t)
1017 (- (point) 3)))
1018 this-menu-list)))))
1019 this-menu-list))
1022 ;;; Determining the hierarchical level in the texinfo file
1024 (defun texinfo-specific-section-type ()
1025 "Return the specific type of next section, as a string.
1026 For example, \"unnumberedsubsec\". Return \"top\" for top node.
1028 Searches forward for a section. Hence, point must be before the
1029 section whose type will be found. Does not move point. Signal an
1030 error if the node is not the top node and a section is not found."
1031 (let ((case-fold-search t))
1032 (save-excursion
1033 (cond
1034 ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1035 ;;; Following search limit by cph but causes a bug
1036 ;;; (save-excursion
1037 ;;; (end-of-line)
1038 ;;; (point))
1041 "top")
1042 ((re-search-forward texinfo-section-types-regexp nil t)
1043 (buffer-substring-no-properties
1044 (progn (beginning-of-line) ; copy its name
1045 (1+ (point)))
1046 (progn (forward-word 1)
1047 (point))))
1049 (error
1050 "texinfo-specific-section-type: Chapter or section not found."))))))
1052 (defun texinfo-hierarchic-level ()
1053 "Return the general hierarchal level of the next node in a texinfo file.
1054 Thus, a subheading or appendixsubsec is of type subsection."
1055 (let ((case-fold-search t))
1056 (cadr (assoc
1057 (texinfo-specific-section-type)
1058 texinfo-section-list))))
1061 ;;; Locating the major positions
1063 (defun texinfo-update-menu-region-beginning (level)
1064 "Locate beginning of higher level section this section is within.
1065 Return position of the beginning of the node line; do not move point.
1066 Thus, if this level is subsection, searches backwards for section node.
1067 Only argument is a string of the general type of section."
1068 (let ((case-fold-search t))
1069 ;; !! Known bug: if section immediately follows top node, this
1070 ;; returns the beginning of the buffer as the beginning of the
1071 ;; higher level section.
1072 (cond
1073 ((< level 3)
1074 (save-excursion
1075 (goto-char (point-min))
1076 (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t)
1077 (beginning-of-line)
1078 (point)))
1080 (save-excursion
1081 (re-search-backward
1082 (concat
1083 "\\(^@node\\).*\n" ; match node line
1084 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1085 "\\|" ; or
1086 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
1087 "\\|" ; or
1088 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
1089 "\\)?" ; end of expression
1090 (eval
1091 (cdr (assoc level texinfo-update-menu-higher-regexps))))
1093 'goto-beginning)
1094 (point))))))
1096 (defun texinfo-update-menu-region-end (level)
1097 "Locate end of higher level section this section is within.
1098 Return position; do not move point. Thus, if this level is a
1099 subsection, find the node for the section this subsection is within.
1100 If level is top or chapter, returns end of file. Only argument is a
1101 string of the general type of section."
1102 (let ((case-fold-search t))
1103 (save-excursion
1104 (if (re-search-forward
1105 (concat
1106 "\\(^@node\\).*\n" ; match node line
1107 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1108 "\\|" ; or
1109 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
1110 "\\|" ; or
1111 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
1112 "\\)?" ; end of expression
1113 (eval
1114 ;; Never finds end of level above chapter so goes to end.
1115 (cdr (assoc level texinfo-update-menu-higher-regexps))))
1117 'goto-end)
1118 (match-beginning 1)
1119 (point-max)))))
1121 (defun texinfo-menu-first-node (beginning end)
1122 "Locate first node of the section the menu will be placed in.
1123 Return position; do not move point.
1124 The menu will be located just before this position.
1126 First argument is the position of the beginning of the section in
1127 which the menu will be located; second argument is the position of the
1128 end of that region; it limits the search."
1130 (save-excursion
1131 (goto-char beginning)
1132 (forward-line 1)
1133 (re-search-forward "^@node" end t)
1134 (beginning-of-line)
1135 (point)))
1138 ;; We used to look for just sub, but that found @subtitle.
1139 (defvar texinfo-section-types-regexp
1140 "^@\\(chapter \\|sect\\|subs\\|subh\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
1141 "Regexp matching chapter, section, other headings (but not the top node).")
1143 (defvar texinfo-section-level-regexp
1144 (regexp-opt (texinfo-filter 3 texinfo-section-list))
1145 "Regular expression matching just the Texinfo section level headings.")
1147 (defvar texinfo-subsection-level-regexp
1148 (regexp-opt (texinfo-filter 4 texinfo-section-list))
1149 "Regular expression matching just the Texinfo subsection level headings.")
1151 (defvar texinfo-subsubsection-level-regexp
1152 (regexp-opt (texinfo-filter 5 texinfo-section-list))
1153 "Regular expression matching just the Texinfo subsubsection level headings.")
1155 (defvar texinfo-update-menu-same-level-regexps
1156 '((1 . "top[ \t]+")
1157 (2 . (concat "\\(^@\\)\\(" texinfo-chapter-level-regexp "\\)\\>[ \t]*"))
1158 (3 . (concat "\\(^@\\)\\(" texinfo-section-level-regexp "\\)\\>[ \t]*"))
1159 (4 . (concat "\\(^@\\)\\(" texinfo-subsection-level-regexp "\\)\\>[ \t]+"))
1160 (5 . (concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp "\\)\\>[ \t]+")))
1161 "*Regexps for searching for same level sections in a Texinfo file.
1162 The keys are strings specifying the general hierarchical level in the
1163 document; the values are regular expressions.")
1165 (defvar texinfo-update-menu-higher-regexps
1166 '((1 . "^@node [ \t]*DIR")
1167 (2 . "^@node [ \t]*top[ \t]*\\(,\\|$\\)")
1168 (3 .
1169 (concat
1170 "\\(^@\\("
1171 texinfo-chapter-level-regexp
1172 "\\)\\>[ \t]*\\)"))
1173 (4 .
1174 (concat
1175 "\\(^@\\("
1176 texinfo-section-level-regexp
1177 "\\|"
1178 texinfo-chapter-level-regexp
1179 "\\)\\>[ \t]*\\)"))
1180 (5 .
1181 (concat
1182 "\\(^@\\("
1183 texinfo-subsection-level-regexp
1184 "\\|"
1185 texinfo-section-level-regexp
1186 "\\|"
1187 texinfo-chapter-level-regexp
1188 "\\)\\>[ \t]*\\)")))
1189 "*Regexps for searching for higher level sections in a Texinfo file.
1190 The keys are strings specifying the general hierarchical level in the
1191 document; the values are regular expressions.")
1193 (defvar texinfo-update-menu-lower-regexps
1194 '((1 .
1195 (concat
1196 "\\(^@\\("
1197 texinfo-chapter-level-regexp
1198 "\\|"
1199 texinfo-section-level-regexp
1200 "\\|"
1201 texinfo-subsection-level-regexp
1202 "\\|"
1203 texinfo-subsubsection-level-regexp
1204 "\\)\\>[ \t]*\\)"))
1205 (2 .
1206 (concat
1207 "\\(^@\\("
1208 texinfo-section-level-regexp
1209 "\\|"
1210 texinfo-subsection-level-regexp
1211 "\\|"
1212 texinfo-subsubsection-level-regexp
1213 "\\)\\>[ \t]*\\)"))
1214 (3 .
1215 (concat
1216 "\\(^@\\("
1217 texinfo-subsection-level-regexp
1218 "\\|"
1219 texinfo-subsubsection-level-regexp
1220 "\\)\\>[ \t]+\\)"))
1221 (4 .
1222 (concat
1223 "\\(^@\\("
1224 texinfo-subsubsection-level-regexp
1225 "\\)\\>[ \t]+\\)"))
1226 ;; There's nothing below 5, use a bogus regexp that can't match.
1227 (5 . "a\\(^\\)"))
1228 "*Regexps for searching for lower level sections in a Texinfo file.
1229 The keys are strings specifying the general hierarchical level in the
1230 document; the values are regular expressions.")
1233 ;;; Updating a node
1235 (defun texinfo-update-node (&optional beginning end)
1236 "Without any prefix argument, update the node in which point is located.
1237 Interactively, a prefix argument means to operate on the region.
1239 The functions for creating or updating nodes and menus, and their
1240 keybindings, are:
1242 texinfo-update-node (&optional beginning end) \\[texinfo-update-node]
1243 texinfo-every-node-update () \\[texinfo-every-node-update]
1244 texinfo-sequential-node-update (&optional region-p)
1246 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
1247 texinfo-all-menus-update () \\[texinfo-all-menus-update]
1248 texinfo-master-menu ()
1250 texinfo-indent-menu-description (column &optional region-p)
1252 The `texinfo-column-for-description' variable specifies the column to
1253 which menu descriptions are indented. Its default value is 32."
1255 (interactive
1256 (if prefix-arg
1257 (list (point) (mark))))
1258 (if (null beginning)
1259 ;; Update a single node.
1260 (let ((auto-fill-function nil) (auto-fill-hook nil))
1261 (if (not (re-search-backward "^@node" (point-min) t))
1262 (error "Node line not found before this position"))
1263 (texinfo-update-the-node)
1264 (message "Done...updated the node. You may save the buffer."))
1265 ;; else
1266 (let ((auto-fill-function nil)
1267 (auto-fill-hook nil))
1268 (save-excursion
1269 (save-restriction
1270 (narrow-to-region beginning end)
1271 (goto-char (point-min))
1272 (while (re-search-forward "^@node" (point-max) t)
1273 (beginning-of-line)
1274 (texinfo-update-the-node))
1275 (goto-char (point-max))
1276 (message "Done...nodes updated in region. You may save the buffer."))))))
1278 (defun texinfo-every-node-update ()
1279 "Update every node in a Texinfo file."
1280 (interactive)
1281 (save-excursion
1282 (texinfo-update-node (point-min) (point-max))
1283 (message "Done...updated every node. You may save the buffer.")))
1285 (defun texinfo-update-the-node ()
1286 "Update one node. Point must be at the beginning of node line.
1287 Leave point at the end of the node line."
1288 (texinfo-check-for-node-name)
1289 (texinfo-delete-existing-pointers)
1290 (message "Updating node: %s ... " (texinfo-copy-node-name))
1291 (save-restriction
1292 (widen)
1293 (let*
1294 ((case-fold-search t)
1295 (level (texinfo-hierarchic-level))
1296 (beginning (texinfo-update-menu-region-beginning level))
1297 (end (texinfo-update-menu-region-end level)))
1298 (if (eq level 1)
1299 (texinfo-top-pointer-case)
1300 ;; else
1301 (texinfo-insert-pointer beginning end level 'next)
1302 (texinfo-insert-pointer beginning end level 'previous)
1303 (texinfo-insert-pointer beginning end level 'up)
1304 (texinfo-clean-up-node-line)))))
1306 (defun texinfo-top-pointer-case ()
1307 "Insert pointers in the Top node. This is a special case.
1309 The `Next' pointer is a pointer to a chapter or section at a lower
1310 hierarchical level in the file. The `Previous' and `Up' pointers are
1311 to `(dir)'. Point must be at the beginning of the node line, and is
1312 left at the end of the node line."
1314 (texinfo-clean-up-node-line)
1315 (insert ", "
1316 (save-excursion
1317 ;; There may be an @chapter or other such command between
1318 ;; the top node line and the next node line, as a title
1319 ;; for an `ifinfo' section. This @chapter command must
1320 ;; must be skipped. So the procedure is to search for
1321 ;; the next `@node' line, and then copy its name.
1322 (if (re-search-forward "^@node" nil t)
1323 (progn
1324 (beginning-of-line)
1325 (texinfo-copy-node-name))
1326 " "))
1327 ", (dir), (dir)"))
1329 (defun texinfo-check-for-node-name ()
1330 "Determine whether the node has a node name. Prompt for one if not.
1331 Point must be at beginning of node line. Does not move point."
1332 (save-excursion
1333 (let ((initial (texinfo-copy-next-section-title)))
1334 ;; This is not clean. Use `interactive' to read the arg.
1335 (forward-word 1) ; skip over node command
1336 (skip-chars-forward " \t") ; and over spaces
1337 (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what Info looks for
1338 ; alternatively, use "[a-zA-Z]+"
1339 (let ((node-name
1340 (read-from-minibuffer
1341 "Node name (use no @, commas, colons, or apostrophes): "
1342 initial)))
1343 (insert " " node-name))))))
1345 (defun texinfo-delete-existing-pointers ()
1346 "Delete `Next', `Previous', and `Up' pointers.
1347 Starts from the current position of the cursor, and searches forward
1348 on the line for a comma and if one is found, deletes the rest of the
1349 line, including the comma. Leaves point at beginning of line."
1350 (let ((eol-point (save-excursion (end-of-line) (point))))
1351 (if (search-forward "," eol-point t)
1352 (delete-region (1- (point)) eol-point)))
1353 (beginning-of-line))
1355 (defun texinfo-find-pointer (beginning end level direction)
1356 "Move point to section associated with next, previous, or up pointer.
1357 Return type of pointer (either `normal' or `no-pointer').
1359 The first and second arguments bound the search for a pointer to the
1360 beginning and end, respectively, of the enclosing higher level
1361 section. The third argument is a string specifying the general kind
1362 of section such as \"chapter\" or \"section\". When looking for the
1363 `Next' pointer, the section found will be at the same hierarchical
1364 level in the Texinfo file; when looking for the `Previous' pointer,
1365 the section found will be at the same or higher hierarchical level in
1366 the Texinfo file; when looking for the `Up' pointer, the section found
1367 will be at some level higher in the Texinfo file. The fourth argument
1368 \(one of 'next, 'previous, or 'up\) specifies whether to find the
1369 `Next', `Previous', or `Up' pointer."
1370 (let ((case-fold-search t))
1371 (cond ((eq direction 'next)
1372 (forward-line 3) ; skip over current node
1373 ;; Search for section commands accompanied by node lines;
1374 ;; ignore section commands in the middle of nodes.
1375 (if (re-search-forward
1376 ;; A `Top' node is never a next pointer, so won't find it.
1377 (concat
1378 ;; Match node line.
1379 "\\(^@node\\).*\n"
1380 ;; Match comment, ifinfo, ifnottex line, if any
1381 (concat
1382 "\\(\\("
1383 "\\(^@c\\).*\n\\)"
1384 "\\|"
1385 "\\(^@ifinfo[ ]*\n\\)"
1386 "\\|"
1387 "\\(^@ifnottex[ ]*\n\\)"
1388 "\\)?")
1389 (eval
1390 (cdr (assoc level texinfo-update-menu-same-level-regexps))))
1393 'normal
1394 'no-pointer))
1395 ((eq direction 'previous)
1396 (if (re-search-backward
1397 (concat
1398 "\\("
1399 ;; Match node line.
1400 "\\(^@node\\).*\n"
1401 ;; Match comment, ifinfo, ifnottex line, if any
1402 (concat
1403 "\\(\\("
1404 "\\(^@c\\).*\n\\)"
1405 "\\|"
1406 "\\(^@ifinfo[ ]*\n\\)"
1407 "\\|"
1408 "\\(^@ifnottex[ ]*\n\\)"
1409 "\\)?")
1410 (eval
1411 (cdr (assoc level texinfo-update-menu-same-level-regexps)))
1412 "\\|"
1413 ;; Match node line.
1414 "\\(^@node\\).*\n"
1415 ;; Match comment, ifinfo, ifnottex line, if any
1416 (concat
1417 "\\(\\("
1418 "\\(^@c\\).*\n\\)"
1419 "\\|"
1420 "\\(^@ifinfo[ ]*\n\\)"
1421 "\\|"
1422 "\\(^@ifnottex[ ]*\n\\)"
1423 "\\)?")
1424 (eval
1425 (cdr (assoc level texinfo-update-menu-higher-regexps)))
1426 "\\|"
1427 ;; Handle `Top' node specially.
1428 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1429 "\\)")
1430 beginning
1432 'normal
1433 'no-pointer))
1434 ((eq direction 'up)
1435 (if (re-search-backward
1436 (concat
1437 "\\("
1438 ;; Match node line.
1439 "\\(^@node\\).*\n"
1440 ;; Match comment, ifinfo, ifnottex line, if any
1441 (concat
1442 "\\(\\("
1443 "\\(^@c\\).*\n\\)"
1444 "\\|"
1445 "\\(^@ifinfo[ ]*\n\\)"
1446 "\\|"
1447 "\\(^@ifnottex[ ]*\n\\)"
1448 "\\)?")
1449 (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
1450 "\\|"
1451 ;; Handle `Top' node specially.
1452 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1453 "\\)")
1454 (save-excursion
1455 (goto-char beginning)
1456 (beginning-of-line)
1457 (point))
1459 'normal
1460 'no-pointer))
1462 (error "texinfo-find-pointer: lack proper arguments")))))
1464 (defun texinfo-pointer-name (kind)
1465 "Return the node name preceding the section command.
1466 The argument is the kind of section, either `normal' or `no-pointer'."
1467 (let (name)
1468 (cond ((eq kind 'normal)
1469 (end-of-line) ; this handles prev node top case
1470 (re-search-backward ; when point is already
1471 "^@node" ; at the beginning of @node line
1472 (save-excursion (forward-line -3))
1474 (setq name (texinfo-copy-node-name)))
1475 ((eq kind 'no-pointer)
1476 ;; Don't need to put a blank in the pointer slot,
1477 ;; since insert "' " always has a space
1478 (setq name " "))) ; put a blank in the pointer slot
1479 name))
1481 (defun texinfo-insert-pointer (beginning end level direction)
1482 "Insert the `Next', `Previous' or `Up' node name at point.
1483 Move point forward.
1485 The first and second arguments bound the search for a pointer to the
1486 beginning and end, respectively, of the enclosing higher level
1487 section. The third argument is the hierarchical level of the Texinfo
1488 file, a string such as \"section\". The fourth argument is direction
1489 towards which the pointer is directed, one of `next', `previous', or `up'."
1491 (end-of-line)
1492 (insert
1493 ", "
1494 (save-excursion
1495 (texinfo-pointer-name
1496 (texinfo-find-pointer beginning end level direction)))))
1498 (defun texinfo-clean-up-node-line ()
1499 "Remove extra commas, if any, at end of node line."
1500 (end-of-line)
1501 (skip-chars-backward ", ")
1502 (delete-region (point) (save-excursion (end-of-line) (point))))
1505 ;;; Updating nodes sequentially
1506 ;; These sequential update functions insert `Next' or `Previous'
1507 ;; pointers that point to the following or preceding nodes even if they
1508 ;; are at higher or lower hierarchical levels. This means that if a
1509 ;; section contains one or more subsections, the section's `Next'
1510 ;; pointer will point to the subsection and not the following section.
1511 ;; (The subsection to which `Next' points will most likely be the first
1512 ;; item on the section's menu.)
1514 (defun texinfo-sequential-node-update (&optional region-p)
1515 "Update one node (or many) in a Texinfo file with sequential pointers.
1517 This function causes the `Next' or `Previous' pointer to point to the
1518 immediately preceding or following node, even if it is at a higher or
1519 lower hierarchical level in the document. Continually pressing `n' or
1520 `p' takes you straight through the file.
1522 Without any prefix argument, update the node in which point is located.
1523 Non-nil argument (prefix, if interactive) means update the nodes in the
1524 marked region.
1526 This command makes it awkward to navigate among sections and
1527 subsections; it should be used only for those documents that are meant
1528 to be read like a novel rather than a reference, and for which the
1529 Info `g*' command is inadequate."
1531 (interactive "P")
1532 (if (not region-p)
1533 ;; update a single node
1534 (let ((auto-fill-function nil) (auto-fill-hook nil))
1535 (if (not (re-search-backward "^@node" (point-min) t))
1536 (error "Node line not found before this position."))
1537 (texinfo-sequentially-update-the-node)
1538 (message
1539 "Done...sequentially updated the node . You may save the buffer."))
1540 ;; else
1541 (let ((auto-fill-function nil)
1542 (auto-fill-hook nil)
1543 (beginning (region-beginning))
1544 (end (region-end)))
1545 (if (= end beginning)
1546 (error "Please mark a region!"))
1547 (save-restriction
1548 (narrow-to-region beginning end)
1549 (goto-char beginning)
1550 (push-mark (point) t)
1551 (while (re-search-forward "^@node" (point-max) t)
1552 (beginning-of-line)
1553 (texinfo-sequentially-update-the-node))
1554 (message
1555 "Done...updated the nodes in sequence. You may save the buffer.")))))
1557 (defun texinfo-sequentially-update-the-node ()
1558 "Update one node such that the pointers are sequential.
1559 A `Next' or `Previous' pointer points to any preceding or following node,
1560 regardless of its hierarchical level."
1562 (texinfo-check-for-node-name)
1563 (texinfo-delete-existing-pointers)
1564 (message
1565 "Sequentially updating node: %s ... " (texinfo-copy-node-name))
1566 (save-restriction
1567 (widen)
1568 (let* ((case-fold-search t)
1569 (level (texinfo-hierarchic-level)))
1570 (if (eq level 1)
1571 (texinfo-top-pointer-case)
1572 ;; else
1573 (texinfo-sequentially-insert-pointer level 'next)
1574 (texinfo-sequentially-insert-pointer level 'previous)
1575 (texinfo-sequentially-insert-pointer level 'up)
1576 (texinfo-clean-up-node-line)))))
1578 (defun texinfo-sequentially-find-pointer (level direction)
1579 "Find next or previous pointer sequentially in Texinfo file, or up pointer.
1580 Move point to section associated with the pointer. Find point even if
1581 it is in a different section.
1583 Return type of pointer (either `normal' or `no-pointer').
1585 The first argument is a string specifying the general kind of section
1586 such as \"chapter\" or \"section\". The section found will be at the
1587 same hierarchical level in the Texinfo file, or, in the case of the up
1588 pointer, some level higher. The second argument (one of `next',
1589 `previous', or `up') specifies whether to find the `Next', `Previous',
1590 or `Up' pointer."
1591 (let ((case-fold-search t))
1592 (cond ((eq direction 'next)
1593 (forward-line 3) ; skip over current node
1594 (if (re-search-forward
1595 texinfo-section-types-regexp
1596 (point-max)
1598 'normal
1599 'no-pointer))
1600 ((eq direction 'previous)
1601 (if (re-search-backward
1602 texinfo-section-types-regexp
1603 (point-min)
1605 'normal
1606 'no-pointer))
1607 ((eq direction 'up)
1608 (if (re-search-backward
1609 (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
1610 beginning
1612 'normal
1613 'no-pointer))
1615 (error "texinfo-sequential-find-pointer: lack proper arguments")))))
1617 (defun texinfo-sequentially-insert-pointer (level direction)
1618 "Insert the `Next', `Previous' or `Up' node name at point.
1619 Move point forward.
1621 The first argument is the hierarchical level of the Texinfo file, a
1622 string such as \"section\". The second argument is direction, one of
1623 `next', `previous', or `up'."
1625 (end-of-line)
1626 (insert
1627 ", "
1628 (save-excursion
1629 (texinfo-pointer-name
1630 (texinfo-sequentially-find-pointer level direction)))))
1633 ;;; Inserting `@node' lines
1634 ;; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
1635 ;; before the `@chapter', `@section', and such like lines of a region
1636 ;; in a Texinfo file.
1638 (defun texinfo-insert-node-lines (beginning end &optional title-p)
1639 "Insert missing `@node' lines in region of Texinfo file.
1640 Non-nil argument (prefix, if interactive) means also to insert the
1641 section titles as node names; and also to insert the section titles as
1642 node names in pre-existing `@node' lines that lack names."
1643 (interactive "r\nP")
1645 ;; Use marker; after inserting node lines, leave point at end of
1646 ;; region and mark at beginning.
1648 (let (beginning-marker end-marker title last-section-position)
1650 ;; Save current position on mark ring and set mark to end.
1651 (push-mark end t)
1652 (setq end-marker (mark-marker))
1654 (goto-char beginning)
1655 (while (re-search-forward
1656 texinfo-section-types-regexp
1657 end-marker
1658 'end)
1659 ;; Copy title if desired.
1660 (if title-p
1661 (progn
1662 (beginning-of-line)
1663 (forward-word 1)
1664 (skip-chars-forward " \t")
1665 (setq title (buffer-substring
1666 (point)
1667 (save-excursion (end-of-line) (point))))))
1668 ;; Insert node line if necessary.
1669 (if (re-search-backward
1670 "^@node"
1671 ;; Avoid finding previous node line if node lines are close.
1672 (or last-section-position
1673 (save-excursion (forward-line -2) (point))) t)
1674 ;; @node is present, and point at beginning of that line
1675 (forward-word 1) ; Leave point just after @node.
1676 ;; Else @node missing; insert one.
1677 (beginning-of-line) ; Beginning of `@section' line.
1678 (insert "@node\n")
1679 (backward-char 1)) ; Leave point just after `@node'.
1680 ;; Insert title if desired.
1681 (if title-p
1682 (progn
1683 (skip-chars-forward " \t")
1684 ;; Use regexp based on what info looks for
1685 ;; (alternatively, use "[a-zA-Z]+");
1686 ;; this means we only insert a title if none exists.
1687 (if (not (looking-at "[^,\t\n ]+"))
1688 (progn
1689 (beginning-of-line)
1690 (forward-word 1)
1691 (insert " " title)
1692 (message "Inserted title %s ... " title)))))
1693 ;; Go forward beyond current section title.
1694 (re-search-forward texinfo-section-types-regexp
1695 (save-excursion (forward-line 3) (point)) t)
1696 (setq last-section-position (point))
1697 (forward-line 1))
1699 ;; Leave point at end of region, mark at beginning.
1700 (set-mark beginning)
1702 (if title-p
1703 (message
1704 "Done inserting node lines and titles. You may save the buffer.")
1705 (message "Done inserting node lines. You may save the buffer."))))
1708 ;;; Update and create menus for multi-file Texinfo sources
1710 ;; 1. M-x texinfo-multiple-files-update
1712 ;; Read the include file list of an outer Texinfo file and
1713 ;; update all highest level nodes in the files listed and insert a
1714 ;; main menu in the outer file after its top node.
1716 ;; 2. C-u M-x texinfo-multiple-files-update
1718 ;; Same as 1, but insert a master menu. (Saves reupdating lower
1719 ;; level menus and nodes.) This command simply reads every menu,
1720 ;; so if the menus are wrong, the master menu will be wrong.
1721 ;; Similarly, if the lower level node pointers are wrong, they
1722 ;; will stay wrong.
1724 ;; 3. C-u 2 M-x texinfo-multiple-files-update
1726 ;; Read the include file list of an outer Texinfo file and
1727 ;; update all nodes and menus in the files listed and insert a
1728 ;; master menu in the outer file after its top node.
1730 ;;; Note: these functions:
1732 ;;; * Do not save or delete any buffers. You may fill up your memory.
1733 ;;; * Do not handle any pre-existing nodes in outer file.
1734 ;;; Hence, you may need a file for indices.
1737 ;;; Auxiliary functions for multiple file updating
1739 (defun texinfo-multi-file-included-list (outer-file)
1740 "Return a list of the included files in OUTER-FILE."
1741 (let ((included-file-list (list outer-file))
1742 start)
1743 (save-excursion
1744 (switch-to-buffer (find-file-noselect outer-file))
1745 (widen)
1746 (goto-char (point-min))
1747 (while (re-search-forward "^@include" nil t)
1748 (skip-chars-forward " \t")
1749 (setq start (point))
1750 (end-of-line)
1751 (skip-chars-backward " \t")
1752 (setq included-file-list
1753 (cons (buffer-substring start (point))
1754 included-file-list)))
1755 (nreverse included-file-list))))
1757 (defun texinfo-copy-next-section-title ()
1758 "Return the name of the immediately following section as a string.
1760 Start with point at the beginning of the node line. Leave point at the
1761 same place. If there is no title, returns an empty string."
1763 (save-excursion
1764 (end-of-line)
1765 (let ((node-end (or
1766 (save-excursion
1767 (if (re-search-forward "\\(^@node\\)" nil t)
1768 (match-beginning 0)))
1769 (point-max))))
1770 (if (re-search-forward texinfo-section-types-regexp node-end t)
1771 (progn
1772 (beginning-of-line)
1773 ;; copy title
1774 (let ((title
1775 (buffer-substring
1776 (progn (forward-word 1) ; skip over section type
1777 (skip-chars-forward " \t") ; and over spaces
1778 (point))
1779 (progn (end-of-line) (point)))))
1780 title))
1781 ""))))
1783 (defun texinfo-multi-file-update (files &optional update-everything)
1784 "Update first node pointers in each file in FILES.
1785 Return a list of the node names.
1787 The first file in the list is an outer file; the remaining are
1788 files included in the outer file with `@include' commands.
1790 If optional arg UPDATE-EVERYTHING non-nil, update every menu and
1791 pointer in each of the included files.
1793 Also update the `Top' level node pointers of the outer file.
1795 Requirements:
1797 * the first file in the FILES list must be the outer file,
1798 * each of the included files must contain exactly one highest
1799 hierarchical level node,
1800 * this node must be the first node in the included file,
1801 * each highest hierarchical level node must be of the same type.
1803 Thus, normally, each included file contains one, and only one, chapter."
1805 ;; The menu-list has the form:
1807 ;; \(\(\"node-name1\" . \"title1\"\)
1808 ;; \(\"node-name2\" . \"title2\"\) ... \)
1810 ;; However, there does not need to be a title field and this function
1811 ;; does not fill it; however a comment tells you how to do so.
1812 ;; You would use the title field if you wanted to insert titles in the
1813 ;; description slot of a menu as a description.
1815 (let ((case-fold-search t)
1816 menu-list)
1818 ;; Find the name of the first node of the first included file.
1819 (switch-to-buffer (find-file-noselect (car (cdr files))))
1820 (widen)
1821 (goto-char (point-min))
1822 (if (not (re-search-forward "^@node" nil t))
1823 (error "No `@node' line found in %s !" (buffer-name)))
1824 (beginning-of-line)
1825 (texinfo-check-for-node-name)
1826 (setq next-node-name (texinfo-copy-node-name))
1828 (setq menu-list
1829 (cons (cons
1830 next-node-name
1831 (prog1 "" (forward-line 1)))
1832 ;; Use following to insert section titles automatically.
1833 ;; (texinfo-copy-next-section-title)
1834 menu-list))
1836 ;; Go to outer file
1837 (switch-to-buffer (find-file-noselect (car files)))
1838 (goto-char (point-min))
1839 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
1840 (error "This buffer needs a Top node!"))
1841 (beginning-of-line)
1842 (texinfo-delete-existing-pointers)
1843 (end-of-line)
1844 (insert ", " next-node-name ", (dir), (dir)")
1845 (beginning-of-line)
1846 (setq previous-node-name "Top")
1847 (setq files (cdr files))
1849 (while files
1851 (if (not (cdr files))
1852 ;; No next file
1853 (setq next-node-name "")
1854 ;; Else,
1855 ;; find the name of the first node in the next file.
1856 (switch-to-buffer (find-file-noselect (car (cdr files))))
1857 (widen)
1858 (goto-char (point-min))
1859 (if (not (re-search-forward "^@node" nil t))
1860 (error "No `@node' line found in %s !" (buffer-name)))
1861 (beginning-of-line)
1862 (texinfo-check-for-node-name)
1863 (setq next-node-name (texinfo-copy-node-name))
1864 (setq menu-list
1865 (cons (cons
1866 next-node-name
1867 (prog1 "" (forward-line 1)))
1868 ;; Use following to insert section titles automatically.
1869 ;; (texinfo-copy-next-section-title)
1870 menu-list)))
1872 ;; Go to node to be updated.
1873 (switch-to-buffer (find-file-noselect (car files)))
1874 (goto-char (point-min))
1875 (if (not (re-search-forward "^@node" nil t))
1876 (error "No `@node' line found in %s !" (buffer-name)))
1877 (beginning-of-line)
1879 ;; Update other menus and nodes if requested.
1880 (if update-everything (texinfo-all-menus-update t))
1882 (beginning-of-line)
1883 (texinfo-delete-existing-pointers)
1884 (end-of-line)
1885 (insert ", " next-node-name ", " previous-node-name ", " up-node-name)
1887 (beginning-of-line)
1888 (setq previous-node-name (texinfo-copy-node-name))
1890 (setq files (cdr files)))
1891 (nreverse menu-list)))
1893 (defun texinfo-multi-files-insert-main-menu (menu-list)
1894 "Insert formatted main menu at point.
1895 Indents the first line of the description, if any, to the value of
1896 `texinfo-column-for-description'."
1898 (insert "@menu\n")
1899 (while menu-list
1900 ;; Every menu entry starts with a star and a space.
1901 (insert "* ")
1903 ;; Insert the node name (and menu entry name, if present).
1904 (let ((node-part (car (car menu-list))))
1905 (if (stringp node-part)
1906 ;; "Double colon" entry line; menu entry and node name are the same,
1907 (insert (format "%s::" node-part))
1908 ;; "Single colon" entry line; menu entry and node name are different.
1909 (insert (format "%s: %s." (car node-part) (cdr node-part)))))
1911 ;; Insert the description, if present.
1912 (if (cdr (car menu-list))
1913 (progn
1914 ;; Move to right place.
1915 (indent-to texinfo-column-for-description 2)
1916 ;; Insert description.
1917 (insert (format "%s" (cdr (car menu-list))))))
1919 (insert "\n") ; end this menu entry
1920 (setq menu-list (cdr menu-list)))
1921 (insert "@end menu"))
1923 (defun texinfo-multi-file-master-menu-list (files-list)
1924 "Return master menu list from files in FILES-LIST.
1925 Menu entries in each file collected using `texinfo-master-menu-list'.
1927 The first file in FILES-LIST must be the outer file; the others must
1928 be the files included within it. A main menu must already exist."
1929 (save-excursion
1930 (let (master-menu-list)
1931 (while files-list
1932 (switch-to-buffer (find-file-noselect (car files-list)))
1933 (message "Working on: %s " (current-buffer))
1934 (goto-char (point-min))
1935 (setq master-menu-list
1936 (append master-menu-list (texinfo-master-menu-list)))
1937 (setq files-list (cdr files-list)))
1938 master-menu-list)))
1941 ;;; The multiple-file update function
1943 (defun texinfo-multiple-files-update
1944 (outer-file &optional update-everything make-master-menu)
1945 "Update first node pointers in each file included in OUTER-FILE;
1946 create or update the `Top' level node pointers and the main menu in
1947 the outer file that refers to such nodes. This does not create or
1948 update menus or pointers within the included files.
1950 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
1951 insert a master menu in OUTER-FILE in addition to creating or updating
1952 pointers in the first @node line in each included file and creating or
1953 updating the `Top' level node pointers of the outer file. This does
1954 not create or update other menus and pointers within the included
1955 files.
1957 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
1958 interactive), update all the menus and all the `Next', `Previous', and
1959 `Up' pointers of all the files included in OUTER-FILE before inserting
1960 a master menu in OUTER-FILE. Also, update the `Top' level node
1961 pointers of OUTER-FILE.
1963 Notes:
1965 * this command does NOT save any files--you must save the
1966 outer file and any modified, included files.
1968 * except for the `Top' node, this command does NOT handle any
1969 pre-existing nodes in the outer file; hence, indices must be
1970 enclosed in an included file.
1972 Requirements:
1974 * each of the included files must contain exactly one highest
1975 hierarchical level node,
1976 * this highest node must be the first node in the included file,
1977 * each highest hierarchical level node must be of the same type.
1979 Thus, normally, each included file contains one, and only one,
1980 chapter."
1982 (interactive (cons
1983 (read-string
1984 "Name of outer `include' file: "
1985 (buffer-file-name))
1986 (cond ((not current-prefix-arg)
1987 '(nil nil))
1988 ((listp current-prefix-arg)
1989 '(t nil)) ; make-master-menu
1990 ((numberp current-prefix-arg)
1991 '(t t)) ; update-everything
1994 (let* ((included-file-list (texinfo-multi-file-included-list outer-file))
1995 (files included-file-list)
1996 main-menu-list
1997 next-node-name
1998 previous-node-name
1999 (up-node-name "Top"))
2001 ;;; Update the pointers
2002 ;;; and collect the names of the nodes and titles
2003 (setq main-menu-list (texinfo-multi-file-update files update-everything))
2005 ;;; Insert main menu
2007 ;; Go to outer file
2008 (switch-to-buffer (find-file-noselect (car included-file-list)))
2009 (if (texinfo-old-menu-p
2010 (point-min)
2011 (save-excursion
2012 (re-search-forward "^@include")
2013 (beginning-of-line)
2014 (point)))
2016 ;; If found, leave point after word `menu' on the `@menu' line.
2017 (progn
2018 (texinfo-incorporate-descriptions main-menu-list)
2019 ;; Delete existing menu.
2020 (beginning-of-line)
2021 (delete-region
2022 (point)
2023 (save-excursion (re-search-forward "^@end menu") (point)))
2024 ;; Insert main menu
2025 (texinfo-multi-files-insert-main-menu main-menu-list))
2027 ;; Else no current menu; insert it before `@include'
2028 (texinfo-multi-files-insert-main-menu main-menu-list))
2030 ;;; Insert master menu
2032 (if make-master-menu
2033 (progn
2034 ;; First, removing detailed part of any pre-existing master menu
2035 (goto-char (point-min))
2036 (if (search-forward texinfo-master-menu-header nil t)
2037 (progn
2038 (goto-char (match-beginning 0))
2039 ;; Check if @detailmenu kludge is used;
2040 ;; if so, leave point before @detailmenu.
2041 (search-backward "\n@detailmenu"
2042 (save-excursion (forward-line -3) (point))
2044 ;; Remove detailed master menu listing
2045 (let ((end-of-detailed-menu-descriptions
2046 (save-excursion ; beginning of end menu line
2047 (goto-char (texinfo-menu-end))
2048 (beginning-of-line) (forward-char -1)
2049 (point))))
2050 (delete-region (point) end-of-detailed-menu-descriptions))))
2052 ;; Create a master menu and insert it
2053 (texinfo-insert-master-menu-list
2054 (texinfo-multi-file-master-menu-list
2055 included-file-list)))))
2057 ;; Remove unwanted extra lines.
2058 (save-excursion
2059 (goto-char (point-min))
2061 (re-search-forward "^@menu")
2062 (forward-line -1)
2063 (insert "\n") ; Ensure at least one blank line.
2064 (delete-blank-lines)
2066 (re-search-forward "^@end menu")
2067 (forward-line 1)
2068 (insert "\n") ; Ensure at least one blank line.
2069 (delete-blank-lines))
2071 (message "Multiple files updated."))
2074 ;;; Place `provide' at end of file.
2075 (provide 'texnfo-upd)
2077 ;;; texnfo-upd.el ends here