Tweaks.
[official-gcc.git] / texinfo / emacs / texnfo-upd.el
blob4827fe5f81900b06f37e50915c04d23aba21239d
1 ;;; texnfo-upd.el --- utilities for updating nodes and menus in Texinfo files
3 ;; Copyright 1989, 1990, 1991, 1992, 1996 Free Software Foundation, Inc.
5 ;; Author: Robert J. Chassell
6 ;; Date: 12 Sep 1996
7 ;; Maintainer: Robert J. Chassell <bug-texinfo@prep.ai.mit.edu>
8 ;; Keywords: maint, tex, docs
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 ;; Boston, MA 02111-1307, USA.
27 ;;; Commentary:
29 ;; Known bug: update commands fail to ignore @ignore.
31 ;; Summary: how to use the updating commands
33 ;; The node and menu updating functions automatically
35 ;; * insert missing `@node' lines,
36 ;; * insert the `Next', `Previous' and `Up' pointers of a node,
37 ;; * insert or update the menu for a section,
38 ;; * create a master menu for a Texinfo source file.
40 ;; Passed an argument, the `texinfo-update-node' and
41 ;; `texinfo-make-menu' functions do their jobs in the region.
43 ;; In brief, the functions for creating or updating nodes and menus, are:
44 ;;
45 ;; texinfo-update-node (&optional region-p)
46 ;; texinfo-every-node-update ()
47 ;; texinfo-sequential-node-update (&optional region-p)
48 ;;
49 ;; texinfo-make-menu (&optional region-p)
50 ;; texinfo-all-menus-update ()
51 ;; texinfo-master-menu ()
53 ;; texinfo-insert-node-lines (&optional title-p)
54 ;;
55 ;; texinfo-indent-menu-description (column &optional region-p)
57 ;; The `texinfo-column-for-description' variable specifies the column to
58 ;; which menu descriptions are indented.
60 ;; Texinfo file structure
61 ;; ----------------------
63 ;; To use the updating commands, you must structure your Texinfo file
64 ;; hierarchically. Each `@node' line, with the exception of the top
65 ;; node, must be accompanied by some kind of section line, such as an
66 ;; `@chapter' or `@section' line. Each node-line/section-line
67 ;; combination must look like this:
69 ;; @node Lists and Tables, Cross References, Structuring, Top
70 ;; @comment node-name, next, previous, up
71 ;; @chapter Making Lists and Tables
73 ;; or like this (without the `@comment' line):
75 ;; @node Lists and Tables, Cross References, Structuring, Top
76 ;; @chapter Making Lists and Tables
78 ;; If the file has a `top' node, it must be called `top' or `Top' and
79 ;; be the first node in the file.
82 ;;; The update node functions described in detail
84 ;; The `texinfo-update-node' function without an argument inserts
85 ;; the correct next, previous and up pointers for the node in which
86 ;; point is located (i.e., for the node preceding point).
88 ;; With an argument, the `texinfo-update-node' function inserts the
89 ;; correct next, previous and up pointers for the nodes inside the
90 ;; region.
92 ;; It does not matter whether the `@node' line has pre-existing
93 ;; `Next', `Previous', or `Up' pointers in it. They are removed.
95 ;; The `texinfo-every-node-update' function runs `texinfo-update-node'
96 ;; on the whole buffer.
98 ;; The `texinfo-sequential-node-update' function inserts the
99 ;; immediately following and preceding node into the `Next' or
100 ;; `Previous' pointers regardless of their hierarchical level. This is
101 ;; only useful for certain kinds of text, like a novel, which you go
102 ;; through sequentially.
105 ;;; The menu making functions described in detail
107 ;; The `texinfo-make-menu' function without an argument creates or
108 ;; updates a menu for the section encompassing the node that follows
109 ;; point. With an argument, it makes or updates menus for the nodes
110 ;; within or part of the marked region.
112 ;; Whenever an existing menu is updated, the descriptions from
113 ;; that menu are incorporated into the new menu. This is done by copying
114 ;; descriptions from the existing menu to the entries in the new menu
115 ;; that have the same node names. If the node names are different, the
116 ;; descriptions are not copied to the new menu.
118 ;; Menu entries that refer to other Info files are removed since they
119 ;; are not a node within current buffer. This is a deficiency.
121 ;; The `texinfo-all-menus-update' function runs `texinfo-make-menu'
122 ;; on the whole buffer.
124 ;; The `texinfo-master-menu' function creates an extended menu located
125 ;; after the top node. (The file must have a top node.) The function
126 ;; first updates all the regular menus in the buffer (incorporating the
127 ;; descriptions from pre-existing menus), and then constructs a master
128 ;; menu that includes every entry from every other menu. (However, the
129 ;; function cannot update an already existing master menu; if one
130 ;; exists, it must be removed before calling the function.)
132 ;; The `texinfo-indent-menu-description' function indents every
133 ;; description in the menu following point, to the specified column.
134 ;; Non-nil argument (prefix, if interactive) means indent every
135 ;; description in every menu in the region. This function does not
136 ;; indent second and subsequent lines of a multi-line description.
138 ;; The `texinfo-insert-node-lines' function inserts `@node' before the
139 ;; `@chapter', `@section', and such like lines of a region in a Texinfo
140 ;; file where the `@node' lines are missing.
142 ;; With a non-nil argument (prefix, if interactive), the function not
143 ;; only inserts `@node' lines but also inserts the chapter or section
144 ;; titles as the names of the corresponding nodes; and inserts titles
145 ;; as node names in pre-existing `@node' lines that lack names.
147 ;; Since node names should be more concise than section or chapter
148 ;; titles, node names so inserted will need to be edited manually.
151 ;;; Code:
153 ;;; The menu making functions
155 (defun texinfo-make-menu (&optional region-p)
156 "Without any prefix argument, make or update a menu.
157 Make the menu for the section enclosing the node found following point.
159 Non-nil argument (prefix, if interactive) means make or update menus
160 for nodes within or part of the marked region.
162 Whenever a menu exists, and is being updated, the descriptions that
163 are associated with node names in the pre-existing menu are
164 incorporated into the new menu. Otherwise, the nodes' section titles
165 are inserted as descriptions."
167 (interactive "P")
168 (if (not region-p)
169 (let ((level (texinfo-hierarchic-level)))
170 (texinfo-make-one-menu level)
171 (message "Done...updated the menu. You may save the buffer."))
172 ;; else
173 (message "Making or updating menus in %s... " (buffer-name))
174 (let ((beginning (region-beginning))
175 (region-end (region-end))
176 (level (progn ; find section type following point
177 (goto-char (region-beginning))
178 (texinfo-hierarchic-level))))
179 (if (= region-end beginning)
180 (error "Please mark a region!"))
181 (save-excursion
182 (save-restriction
183 (widen)
185 (while (texinfo-find-lower-level-node level region-end)
186 (setq level (texinfo-hierarchic-level)) ; new, lower level
187 (texinfo-make-one-menu level))
189 (while (and (< (point) region-end)
190 (texinfo-find-higher-level-node level region-end))
191 (setq level (texinfo-hierarchic-level))
192 (while (texinfo-find-lower-level-node level region-end)
193 (setq level (texinfo-hierarchic-level)) ; new, lower level
194 (texinfo-make-one-menu level))))))
195 (message "Done...updated menus. You may save the buffer.")))
197 (defun texinfo-make-one-menu (level)
198 "Make a menu of all the appropriate nodes in this section.
199 `Appropriate nodes' are those associated with sections that are
200 at the level specified by LEVEL. Point is left at the end of menu."
201 (let*
202 ((case-fold-search t)
203 (beginning
204 (save-excursion
205 (goto-char (texinfo-update-menu-region-beginning level))
206 (end-of-line)
207 (point)))
208 (end (texinfo-update-menu-region-end level))
209 (first (texinfo-menu-first-node beginning end))
210 (node-name (progn
211 (goto-char beginning)
212 (beginning-of-line)
213 (texinfo-copy-node-name)))
214 (new-menu-list (texinfo-make-menu-list beginning end level)))
215 (if (texinfo-old-menu-p beginning first)
216 (progn
217 (texinfo-incorporate-descriptions new-menu-list)
218 (texinfo-incorporate-menu-entry-names new-menu-list)
219 (texinfo-delete-old-menu beginning first)))
220 (texinfo-insert-menu new-menu-list node-name)))
222 (defun texinfo-all-menus-update (&optional update-all-nodes-p)
223 "Update every regular menu in a Texinfo file.
224 Update pre-existing master menu, if there is one.
226 If called with a non-nil argument, this function first updates all the
227 nodes in the buffer before updating the menus."
228 (interactive "P")
229 (let ((case-fold-search t)
230 master-menu-p)
231 (save-excursion
232 (push-mark (point-max) t)
233 (goto-char (point-min))
234 (message "Checking for a master menu in %s ... "(buffer-name))
235 (save-excursion
236 (if (re-search-forward texinfo-master-menu-header nil t)
237 ;; Remove detailed master menu listing
238 (progn
239 (setq master-menu-p t)
240 (goto-char (match-beginning 0))
241 (let ((end-of-detailed-menu-descriptions
242 (save-excursion ; beginning of end menu line
243 (goto-char (texinfo-menu-end))
244 (beginning-of-line) (forward-char -1)
245 (point))))
246 (delete-region (point) end-of-detailed-menu-descriptions)))))
248 (if update-all-nodes-p
249 (progn
250 (message "Updating all nodes in %s ... " (buffer-name))
251 (sleep-for 2)
252 (push-mark (point-max) t)
253 (goto-char (point-min))
254 ;; Using the mark to pass bounds this way
255 ;; is kludgy, but it's not worth fixing. -- rms.
256 (let ((mark-active t))
257 (texinfo-update-node t))))
259 (message "Updating all menus in %s ... " (buffer-name))
260 (sleep-for 2)
261 (push-mark (point-max) t)
262 (goto-char (point-min))
263 ;; Using the mark to pass bounds this way
264 ;; is kludgy, but it's not worth fixing. -- rms.
265 (let ((mark-active t))
266 (texinfo-make-menu t))
268 (if master-menu-p
269 (progn
270 (message "Updating the master menu in %s... " (buffer-name))
271 (sleep-for 2)
272 (texinfo-master-menu nil))))
274 (message "Done...updated all the menus. You may save the buffer.")))
276 (defun texinfo-find-lower-level-node (level region-end)
277 "Search forward from point for node at any level lower than LEVEL.
278 Search is limited to the end of the marked region, REGION-END,
279 and to the end of the menu region for the level.
281 Return t if the node is found, else nil. Leave point at the beginning
282 of the node if one is found; else do not move point."
283 (let ((case-fold-search t))
284 (if (and (< (point) region-end)
285 (re-search-forward
286 (concat
287 "\\(^@node\\).*\n" ; match node line
288 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
289 "\\|" ; or
290 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
291 (eval (cdr (assoc level texinfo-update-menu-lower-regexps))))
292 ;; the next higher level node marks the end of this
293 ;; section, and no lower level node will be found beyond
294 ;; this position even if region-end is farther off
295 (texinfo-update-menu-region-end level)
297 (goto-char (match-beginning 1)))))
299 (defun texinfo-find-higher-level-node (level region-end)
300 "Search forward from point for node at any higher level than argument LEVEL.
301 Search is limited to the end of the marked region, REGION-END.
303 Return t if the node is found, else nil. Leave point at the beginning
304 of the node if one is found; else do not move point."
305 (let ((case-fold-search t))
306 (cond
307 ((or (string-equal "top" level) (string-equal "chapter" level))
308 (if (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" region-end t)
309 (progn (beginning-of-line) t)))
311 (if (re-search-forward
312 (concat
313 "\\(^@node\\).*\n" ; match node line
314 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
315 "\\|" ; or
316 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
317 (eval (cdr (assoc level texinfo-update-menu-higher-regexps))))
318 region-end t)
319 (progn (beginning-of-line) t))))))
322 ;;; Making the list of new menu entries
324 (defun texinfo-make-menu-list (beginning end level)
325 "Make a list of node names and their descriptions.
326 Point is left at the end of the menu region, but the menu is not inserted.
328 First argument is position from which to start making menu list;
329 second argument is end of region in which to try to locate entries;
330 third argument is the level of the nodes that are the entries.
332 Node names and descriptions are dotted pairs of strings. Each pair is
333 an element of the list. If the description does not exist, the
334 element consists only of the node name."
335 (goto-char beginning)
336 (let (new-menu-list)
337 (while (texinfo-menu-locate-entry-p level end)
338 (setq new-menu-list
339 (cons (cons
340 (texinfo-copy-node-name)
341 (prog1 "" (forward-line 1)))
342 ;; Use following to insert section titles automatically.
343 ;; (texinfo-copy-section-title))
344 new-menu-list)))
345 (reverse new-menu-list)))
347 (defun texinfo-menu-locate-entry-p (level search-end)
348 "Find a node that will be part of menu for this section.
349 First argument is a string such as \"section\" specifying the general
350 hierarchical level of the menu; second argument is a position
351 specifying the end of the search.
353 The function returns t if the node is found, else nil. It searches
354 forward from point, and leaves point at the beginning of the node.
356 The function finds entries of the same type. Thus `subsections' and
357 `unnumberedsubsecs' will appear in the same menu."
358 (let ((case-fold-search t))
359 (if (re-search-forward
360 (concat
361 "\\(^@node\\).*\n" ; match node line
362 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
363 "\\|" ; or
364 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
365 (eval
366 (cdr (assoc level texinfo-update-menu-same-level-regexps))))
367 search-end
369 (goto-char (match-beginning 1)))))
371 (defun texinfo-copy-node-name ()
372 "Return the node name as a string.
374 Start with point at the beginning of the node line; copy the text
375 after the node command up to the first comma on the line, if any, and
376 return the text as a string. Leaves point at the beginning of the
377 line. If there is no node name, returns an empty string."
379 (save-excursion
380 (buffer-substring
381 (progn (forward-word 1) ; skip over node command
382 (skip-chars-forward " \t") ; and over spaces
383 (point))
384 (if (search-forward
386 (save-excursion (end-of-line) (point)) t) ; bound search
387 (1- (point))
388 (end-of-line) (point)))))
390 (defun texinfo-copy-section-title ()
391 "Return the title of the section as a string.
392 The title is used as a description line in the menu when one does not
393 already exist.
395 Move point to the beginning of the appropriate section line by going
396 to the start of the text matched by last regexp searched for, which
397 must have been done by `texinfo-menu-locate-entry-p'."
399 ;; could use the same re-search as in `texinfo-menu-locate-entry-p'
400 ;; instead of using `match-beginning'; such a variation would be
401 ;; more general, but would waste information already collected
403 (goto-char (match-beginning 7)) ; match section name
405 (buffer-substring
406 (progn (forward-word 1) ; skip over section type
407 (skip-chars-forward " \t") ; and over spaces
408 (point))
409 (progn (end-of-line) (point))))
412 ;;; Handling the old menu
414 (defun texinfo-old-menu-p (beginning first)
415 "Move point to the beginning of the menu for this section, if any.
416 Otherwise move point to the end of the first node of this section.
417 Return t if a menu is found, nil otherwise.
419 First argument is the position of the beginning of the section in which
420 the menu will be located; second argument is the position of the first
421 node within the section.
423 If no menu is found, the function inserts two newlines just before the
424 end of the section, and leaves point there where a menu ought to be."
425 (goto-char beginning)
426 (if (not (re-search-forward "^@menu" first 'goto-end))
427 (progn (insert "\n\n") (forward-line -2) nil)
430 (defun texinfo-incorporate-descriptions (new-menu-list)
431 "Copy the old menu line descriptions that exist to the new menu.
433 Point must be at beginning of old menu.
435 If the node-name of the new menu is found in the old menu, insert the
436 old description into the new entry.
438 For this function, the new menu is a list made up of lists of dotted
439 pairs in which the first element of the pair is the node name and the
440 second element the description. The new menu is changed destructively.
441 The old menu is the menu as it appears in the texinfo file."
443 (let ((new-menu-list-pointer new-menu-list)
444 (end-of-menu (texinfo-menu-end)))
445 (while new-menu-list
446 (save-excursion ; keep point at beginning of menu
447 (if (re-search-forward
448 ;; Existing nodes can have the form
449 ;; * NODE NAME:: DESCRIPTION
450 ;; or
451 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
453 ;; Recognize both when looking for the description.
454 (concat "\\* \\(" ; so only menu entries are found
455 (car (car new-menu-list)) "::"
456 "\\|"
457 ".*: " (car (car new-menu-list)) "[.,\t\n]"
458 "\\)"
459 ) ; so only complete entries are found
460 end-of-menu
462 (setcdr (car new-menu-list)
463 (texinfo-menu-copy-old-description end-of-menu))))
464 (setq new-menu-list (cdr new-menu-list)))
465 (setq new-menu-list new-menu-list-pointer)))
467 (defun texinfo-incorporate-menu-entry-names (new-menu-list)
468 "Copy any old menu entry names to the new menu.
470 Point must be at beginning of old menu.
472 If the node-name of the new menu entry cannot be found in the old
473 menu, do nothing.
475 For this function, the new menu is a list made up of lists of dotted
476 pairs in which the first element of the pair is the node name and the
477 second element is the description (or nil).
479 If we find an existing menu entry name, we change the first element of
480 the pair to be another dotted pair in which the car is the menu entry
481 name and the cdr is the node name.
483 NEW-MENU-LIST is changed destructively. The old menu is the menu as it
484 appears in the texinfo file."
486 (let ((new-menu-list-pointer new-menu-list)
487 (end-of-menu (texinfo-menu-end)))
488 (while new-menu-list
489 (save-excursion ; keep point at beginning of menu
490 (if (re-search-forward
491 ;; Existing nodes can have the form
492 ;; * NODE NAME:: DESCRIPTION
493 ;; or
494 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
496 ;; We're interested in the second case.
497 (concat "\\* " ; so only menu entries are found
498 "\\(.*\\): " (car (car new-menu-list)) "[.,\t\n]")
499 end-of-menu
501 (setcar
502 (car new-menu-list) ; replace the node name
503 (cons (buffer-substring (match-beginning 1) (match-end 1))
504 (car (car new-menu-list)))))
505 (setq new-menu-list (cdr new-menu-list))))
506 (setq new-menu-list new-menu-list-pointer)))
508 (defun texinfo-menu-copy-old-description (end-of-menu)
509 "Return description field of old menu line as string.
510 Point must be located just after the node name. Point left before description.
511 Single argument, END-OF-MENU, is position limiting search."
512 (skip-chars-forward "[:.,\t\n ]+")
513 ;; don't copy a carriage return at line beginning with asterisk!
514 ;; do copy a description that begins with an `@'!
515 ;; !! Known bug: does not copy descriptions starting with ^|\{?* etc.
516 (if (and (looking-at "\\(\\w+\\|@\\)")
517 (not (looking-at "\\(^\\* \\|^@end menu\\)")))
518 (buffer-substring
519 (point)
520 (save-excursion
521 (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t)
522 (forward-line -1)
523 (end-of-line) ; go to end of last description line
524 (point)))
525 ""))
527 (defun texinfo-menu-end ()
528 "Return position of end of menu. Does not change location of point.
529 Signal an error if not end of menu."
530 (save-excursion
531 (if (re-search-forward "^@end menu" nil t)
532 (point)
533 (error "Menu does not have an end."))))
535 (defun texinfo-delete-old-menu (beginning first)
536 "Delete the old menu. Point must be in or after menu.
537 First argument is position of the beginning of the section in which
538 the menu will be located; second argument is the position of the first
539 node within the section."
540 ;; No third arg to search, so error if search fails.
541 (re-search-backward "^@menu" beginning)
542 (delete-region (point)
543 (save-excursion
544 (re-search-forward "^@end menu" first)
545 (point))))
548 ;;; Inserting new menu
550 ;; try 32, but perhaps 24 is better
551 (defvar texinfo-column-for-description 32
552 "*Column at which descriptions start in a Texinfo menu.")
554 (defun texinfo-insert-menu (menu-list node-name)
555 "Insert formatted menu at point.
556 Indents the first line of the description, if any, to the value of
557 texinfo-column-for-description.
559 MENU-LIST has form:
561 \(\(\"node-name1\" . \"description\"\)
562 \(\"node-name2\" . \"description\"\) ... \)
564 However, the description field might be nil.
566 Also, the node-name field might itself be a dotted pair (call it P) of
567 strings instead of just a string. In that case, the car of P
568 is the menu entry name, and the cdr of P is the node name."
570 (insert "@menu\n")
571 (while menu-list
572 ;; Every menu entry starts with a star and a space.
573 (insert "* ")
575 ;; Insert the node name (and menu entry name, if present).
576 (let ((node-part (car (car menu-list))))
577 (if (stringp node-part)
578 ;; "Double colon" entry line; menu entry and node name are the same,
579 (insert (format "%s::" node-part))
580 ;; "Single colon" entry line; menu entry and node name are different.
581 (insert (format "%s: %s." (car node-part) (cdr node-part)))))
583 ;; Insert the description, if present.
584 (if (cdr (car menu-list))
585 (progn
586 ;; Move to right place.
587 (indent-to texinfo-column-for-description 2)
588 ;; Insert description.
589 (insert (format "%s" (cdr (car menu-list))))))
591 (insert "\n") ; end this menu entry
592 (setq menu-list (cdr menu-list)))
593 (insert "@end menu")
594 (message
595 "Updated \"%s\" level menu following node: %s ... " level node-name))
598 ;;; Starting menu descriptions by inserting titles
600 (defun texinfo-start-menu-description ()
601 "In this menu entry, insert the node's section title as a description.
602 Position point at beginning of description ready for editing.
603 Do not insert a title if the line contains an existing description.
605 You will need to edit the inserted text since a useful description
606 complements the node name rather than repeats it as a title does."
608 (interactive)
609 (let (beginning end node-name title)
610 (save-excursion
611 (beginning-of-line)
612 (if (search-forward "* " (save-excursion (end-of-line) (point)) t)
613 (progn (skip-chars-forward " \t")
614 (setq beginning (point)))
615 (error "This is not a line in a menu!"))
617 (cond
618 ;; "Double colon" entry line; menu entry and node name are the same,
619 ((search-forward "::" (save-excursion (end-of-line) (point)) t)
620 (if (looking-at "[ \t]*[^ \t\n]+")
621 (error "Descriptive text already exists."))
622 (skip-chars-backward ": \t")
623 (setq node-name (buffer-substring beginning (point))))
625 ;; "Single colon" entry line; menu entry and node name are different.
626 ((search-forward ":" (save-excursion (end-of-line) (point)) t)
627 (skip-chars-forward " \t")
628 (setq beginning (point))
629 ;; Menu entry line ends in a period, comma, or tab.
630 (if (re-search-forward "[.,\t]"
631 (save-excursion (forward-line 1) (point)) t)
632 (progn
633 (if (looking-at "[ \t]*[^ \t\n]+")
634 (error "Descriptive text already exists."))
635 (skip-chars-backward "., \t")
636 (setq node-name (buffer-substring beginning (point))))
637 ;; Menu entry line ends in a return.
638 (re-search-forward ".*\n"
639 (save-excursion (forward-line 1) (point)) t)
640 (skip-chars-backward " \t\n")
641 (setq node-name (buffer-substring beginning (point)))
642 (if (= 0 (length node-name))
643 (error "No node name on this line.")
644 (insert "."))))
645 (t (error "No node name on this line.")))
646 ;; Search for node that matches node name, and copy the section title.
647 (if (re-search-forward
648 (concat
649 "^@node[ \t]+"
650 node-name
651 ".*\n" ; match node line
652 "\\("
653 "\\(\\(^@c \\|^@comment\\).*\n\\)" ; match comment line, if any
654 "\\|" ; or
655 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
656 "\\)?")
657 nil t)
658 (progn
659 (setq title
660 (buffer-substring
661 ;; skip over section type
662 (progn (forward-word 1)
663 ;; and over spaces
664 (skip-chars-forward " \t")
665 (point))
666 (progn (end-of-line)
667 (skip-chars-backward " \t")
668 (point)))))
669 (error "Cannot find node to match node name in menu entry.")))
670 ;; Return point to the menu and insert the title.
671 (end-of-line)
672 (delete-region
673 (point)
674 (save-excursion (skip-chars-backward " \t") (point)))
675 (indent-to texinfo-column-for-description 2)
676 (save-excursion (insert title))))
679 ;;; Handling description indentation
681 ;; Since the make-menu functions indent descriptions, these functions
682 ;; are useful primarily for indenting a single menu specially.
684 (defun texinfo-indent-menu-description (column &optional region-p)
685 "Indent every description in menu following point to COLUMN.
686 Non-nil argument (prefix, if interactive) means indent every
687 description in every menu in the region. Does not indent second and
688 subsequent lines of a multi-line description."
690 (interactive
691 "nIndent menu descriptions to (column number): \nP")
692 (save-excursion
693 (save-restriction
694 (widen)
695 (if (not region-p)
696 (progn
697 (re-search-forward "^@menu")
698 (texinfo-menu-indent-description column)
699 (message
700 "Indented descriptions in menu. You may save the buffer."))
701 ;;else
702 (message "Indenting every menu description in region... ")
703 (goto-char (region-beginning))
704 (while (and (< (point) (region-end))
705 (texinfo-locate-menu-p))
706 (forward-line 1)
707 (texinfo-menu-indent-description column))
708 (message "Indenting done. You may save the buffer.")))))
710 (defun texinfo-menu-indent-description (to-column-number)
711 "Indent the Texinfo file menu description to TO-COLUMN-NUMBER.
712 Start with point just after the word `menu' in the `@menu' line and
713 leave point on the line before the `@end menu' line. Does not indent
714 second and subsequent lines of a multi-line description."
715 (let* ((beginning-of-next-line (point)))
716 (while (< beginning-of-next-line
717 (save-excursion ; beginning of end menu line
718 (goto-char (texinfo-menu-end))
719 (beginning-of-line)
720 (point)))
722 (if (re-search-forward "\\* \\(.*::\\|.*: [^.,\t\n]+[.,\t]\\)"
723 (texinfo-menu-end)
725 (progn
726 (let ((beginning-white-space (point)))
727 (skip-chars-forward " \t") ; skip over spaces
728 (if (looking-at "\\(@\\|\\w\\)+") ; if there is text
729 (progn
730 ;; remove pre-existing indentation
731 (delete-region beginning-white-space (point))
732 (indent-to-column to-column-number))))))
733 ;; position point at beginning of next line
734 (forward-line 1)
735 (setq beginning-of-next-line (point)))))
738 ;;; Making the master menu
740 (defun texinfo-master-menu (update-all-nodes-menus-p)
741 "Make a master menu for a whole Texinfo file.
742 Non-nil argument (prefix, if interactive) means first update all
743 existing nodes and menus. Remove pre-existing master menu, if there is one.
745 This function creates a master menu that follows the top node. The
746 master menu includes every entry from all the other menus. It
747 replaces any existing ordinary menu that follows the top node.
749 If called with a non-nil argument, this function first updates all the
750 menus in the buffer (incorporating descriptions from pre-existing
751 menus) before it constructs the master menu.
753 The function removes the detailed part of an already existing master
754 menu. This action depends on the pre-existing master menu using the
755 standard `texinfo-master-menu-header'.
757 The master menu has the following format, which is adapted from the
758 recommendation in the Texinfo Manual:
760 * The first part contains the major nodes in the Texinfo file: the
761 nodes for the chapters, chapter-like sections, and the major
762 appendices. This includes the indices, so long as they are in
763 chapter-like sections, such as unnumbered sections.
765 * The second and subsequent parts contain a listing of the other,
766 lower level menus, in order. This way, an inquirer can go
767 directly to a particular node if he or she is searching for
768 specific information.
770 Each of the menus in the detailed node listing is introduced by the
771 title of the section containing the menu."
773 (interactive "P")
774 (let ((case-fold-search t))
775 (widen)
776 (goto-char (point-min))
778 ;; Move point to location after `top'.
779 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
780 (error "This buffer needs a Top node!"))
782 (let ((first-chapter
783 (save-excursion
784 (or (re-search-forward "^@node" nil t)
785 (error "Too few nodes for a master menu!"))
786 (point))))
787 (if (re-search-forward texinfo-master-menu-header first-chapter t)
788 ;; Remove detailed master menu listing
789 (progn
790 (goto-char (match-beginning 0))
791 (let ((end-of-detailed-menu-descriptions
792 (save-excursion ; beginning of end menu line
793 (goto-char (texinfo-menu-end))
794 (beginning-of-line) (forward-char -1)
795 (point))))
796 (delete-region (point) end-of-detailed-menu-descriptions)))))
798 (if update-all-nodes-menus-p
799 (progn
800 (message "Making a master menu in %s ...first updating all nodes... "
801 (buffer-name))
802 (sleep-for 2)
803 (push-mark (point-max) t)
804 (goto-char (point-min))
805 (texinfo-update-node t)
807 (message "Updating all menus in %s ... " (buffer-name))
808 (sleep-for 2)
809 (push-mark (point-max) t)
810 (goto-char (point-min))
811 (texinfo-make-menu t)))
813 (message "Now making the master menu in %s... " (buffer-name))
814 (sleep-for 2)
815 (goto-char (point-min))
816 (texinfo-insert-master-menu-list
817 (texinfo-master-menu-list))
819 ;; Remove extra newlines that texinfo-insert-master-menu-list
820 ;; may have inserted.
822 (save-excursion
823 (goto-char (point-min))
825 (if (re-search-forward texinfo-master-menu-header nil t)
826 (progn
827 (goto-char (match-beginning 0))
828 (insert "\n")
829 (delete-blank-lines)
830 (goto-char (point-min))))
832 (re-search-forward "^@menu")
833 (forward-line -1)
834 (delete-blank-lines)
836 (re-search-forward "^@end menu")
837 (forward-line 1)
838 (delete-blank-lines))
840 (message
841 "Done...completed making master menu. You may save the buffer.")))
843 (defun texinfo-master-menu-list ()
844 "Return a list of menu entries and header lines for the master menu.
846 Start with the menu for chapters and indices and then find each
847 following menu and the title of the node preceding that menu.
849 The master menu list has this form:
851 \(\(\(... \"entry-1-2\" \"entry-1\"\) \"title-1\"\)
852 \(\(... \"entry-2-2\" \"entry-2-1\"\) \"title-2\"\)
853 ...\)
855 However, there does not need to be a title field."
857 (let (master-menu-list)
858 (while (texinfo-locate-menu-p)
859 (setq master-menu-list
860 (cons (list
861 (texinfo-copy-menu)
862 (texinfo-copy-menu-title))
863 master-menu-list)))
864 (reverse master-menu-list)))
866 (defun texinfo-insert-master-menu-list (master-menu-list)
867 "Format and insert the master menu in the current buffer."
868 (goto-char (point-min))
869 ;; Insert a master menu only after `Top' node and before next node
870 ;; \(or include file if there is no next node\).
871 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
872 (error "This buffer needs a Top node!"))
873 (let ((first-chapter
874 (save-excursion (re-search-forward "^@node\\|^@include") (point))))
875 (if (not (re-search-forward "^@menu" first-chapter t))
876 (error
877 "Buffer lacks ordinary `Top' menu in which to insert master.")))
878 (beginning-of-line)
879 (delete-region ; buffer must have ordinary top menu
880 (point)
881 (save-excursion (re-search-forward "^@end menu") (point)))
883 (save-excursion ; leave point at beginning of menu
884 ;; Handle top of menu
885 (insert "\n@menu\n")
886 ;; Insert chapter menu entries
887 (setq this-very-menu-list (reverse (car (car master-menu-list))))
888 ;; Tell user what is going on.
889 (message "Inserting chapter menu entry: %s ... " this-very-menu-list)
890 (while this-very-menu-list
891 (insert "* " (car this-very-menu-list) "\n")
892 (setq this-very-menu-list (cdr this-very-menu-list)))
894 (setq master-menu-list (cdr master-menu-list))
896 ;; Only insert detailed master menu if there is one....
897 (if (car (car master-menu-list))
898 ;; @detailmenu added 5 Sept 1996 at Karl Berry's request to avert a
899 ;; bug in `makeinfo'; all agree this is a bad kluge and should
900 ;; eventually be removed. @detailmenu ... @end detailmenu is a noop
901 ;; in `texinfmt.el' See @end detailmenu below
902 ;; also see `texinfo-all-menus-update' above, `texinfo-master-menu',
903 ;; `texinfo-multiple-files-update'
904 (insert texinfo-master-menu-header))
906 ;; Now, insert all the other menus
908 ;; The menu master-menu-list has a form like this:
909 ;; ((("beta" "alpha") "title-A")
910 ;; (("delta" "gamma") "title-B"))
912 (while master-menu-list
914 (message
915 "Inserting menu for %s .... " (car (cdr (car master-menu-list))))
916 ;; insert title of menu section
917 (insert "\n" (car (cdr (car master-menu-list))) "\n\n")
919 ;; insert each menu entry
920 (setq this-very-menu-list (reverse (car (car master-menu-list))))
921 (while this-very-menu-list
922 (insert "* " (car this-very-menu-list) "\n")
923 (setq this-very-menu-list (cdr this-very-menu-list)))
925 (setq master-menu-list (cdr master-menu-list)))
927 ;; Finish menu
928 ;; @detailmenu (see note above)
929 (insert "\n@end detailmenu")
930 (insert "\n@end menu\n\n")))
932 (defvar texinfo-master-menu-header
933 "\n@detailmenu\n --- The Detailed Node Listing ---\n"
934 "String inserted before lower level entries in Texinfo master menu.
935 It comes after the chapter-level menu entries.")
937 (defun texinfo-locate-menu-p ()
938 "Find the next menu in the texinfo file.
939 If found, leave point after word `menu' on the `@menu' line, and return t.
940 If a menu is not found, do not move point and return nil."
941 (re-search-forward "\\(^@menu\\)" nil t))
943 (defun texinfo-copy-menu-title ()
944 "Return the title of the section preceding the menu as a string.
945 If such a title cannot be found, return an empty string. Do not move
946 point."
947 (let ((case-fold-search t))
948 (save-excursion
949 (if (re-search-backward
950 (concat
951 "\\(^@top"
952 "\\|" ; or
953 texinfo-section-types-regexp ; all other section types
954 "\\)")
957 (progn
958 (beginning-of-line)
959 (forward-word 1) ; skip over section type
960 (skip-chars-forward " \t") ; and over spaces
961 (buffer-substring
962 (point)
963 (progn (end-of-line) (point))))
964 ""))))
966 (defun texinfo-copy-menu ()
967 "Return the entries of an existing menu as a list.
968 Start with point just after the word `menu' in the `@menu' line
969 and leave point on the line before the `@end menu' line."
970 (let* (this-menu-list
971 (end-of-menu (texinfo-menu-end)) ; position of end of `@end menu'
972 (last-entry (save-excursion ; position of beginning of
973 ; last `* ' entry
974 (goto-char end-of-menu)
975 ;; handle multi-line description
976 (if (not (re-search-backward "^\\* " nil t))
977 (error "No entries in menu."))
978 (point))))
979 (while (< (point) last-entry)
980 (if (re-search-forward "^\\* " end-of-menu t)
981 (progn
982 (setq this-menu-list
983 (cons
984 (buffer-substring
985 (point)
986 ;; copy multi-line descriptions
987 (save-excursion
988 (re-search-forward "\\(^\\* \\|^@e\\)" nil t)
989 (- (point) 3)))
990 this-menu-list)))))
991 this-menu-list))
994 ;;; Determining the hierarchical level in the texinfo file
996 (defun texinfo-specific-section-type ()
997 "Return the specific type of next section, as a string.
998 For example, \"unnumberedsubsec\". Return \"top\" for top node.
1000 Searches forward for a section. Hence, point must be before the
1001 section whose type will be found. Does not move point. Signal an
1002 error if the node is not the top node and a section is not found."
1003 (let ((case-fold-search t))
1004 (save-excursion
1005 (cond
1006 ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1007 ;;; Following search limit by cph but causes a bug
1008 ;;; (save-excursion
1009 ;;; (end-of-line)
1010 ;;; (point))
1013 "top")
1014 ((re-search-forward texinfo-section-types-regexp nil t)
1015 (buffer-substring-no-properties
1016 (progn (beginning-of-line) ; copy its name
1017 (1+ (point)))
1018 (progn (forward-word 1)
1019 (point))))
1021 (error
1022 "texinfo-specific-section-type: Chapter or section not found."))))))
1024 (defun texinfo-hierarchic-level ()
1025 "Return the general hierarchal level of the next node in a texinfo file.
1026 Thus, a subheading or appendixsubsec is of type subsection."
1027 (let ((case-fold-search t))
1028 (cdr (assoc
1029 (texinfo-specific-section-type)
1030 texinfo-section-to-generic-alist))))
1033 ;;; Locating the major positions
1035 (defun texinfo-update-menu-region-beginning (level)
1036 "Locate beginning of higher level section this section is within.
1037 Return position of the beginning of the node line; do not move point.
1038 Thus, if this level is subsection, searches backwards for section node.
1039 Only argument is a string of the general type of section."
1040 (let ((case-fold-search t))
1041 ;; !! Known bug: if section immediately follows top node, this
1042 ;; returns the beginning of the buffer as the beginning of the
1043 ;; higher level section.
1044 (cond
1045 ((or (string-equal "top" level)
1046 (string-equal "chapter" level))
1047 (save-excursion
1048 (goto-char (point-min))
1049 (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t)
1050 (beginning-of-line)
1051 (point)))
1053 (save-excursion
1054 (re-search-backward
1055 (concat
1056 "\\(^@node\\).*\n" ; match node line
1057 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1058 "\\|" ; or
1059 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
1060 (eval
1061 (cdr (assoc level texinfo-update-menu-higher-regexps))))
1063 'goto-beginning)
1064 (point))))))
1066 (defun texinfo-update-menu-region-end (level)
1067 "Locate end of higher level section this section is within.
1068 Return position; do not move point. Thus, if this level is a
1069 subsection, find the node for the section this subsection is within.
1070 If level is top or chapter, returns end of file. Only argument is a
1071 string of the general type of section."
1072 (let ((case-fold-search t))
1073 (save-excursion
1074 (if (re-search-forward
1075 (concat
1076 "\\(^@node\\).*\n" ; match node line
1077 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1078 "\\|" ; or
1079 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
1080 (eval
1081 ;; Never finds end of level above chapter so goes to end.
1082 (cdr (assoc level texinfo-update-menu-higher-regexps))))
1084 'goto-end)
1085 (match-beginning 1)
1086 (point-max)))))
1088 (defun texinfo-menu-first-node (beginning end)
1089 "Locate first node of the section the menu will be placed in.
1090 Return position; do not move point.
1091 The menu will be located just before this position.
1093 First argument is the position of the beginning of the section in
1094 which the menu will be located; second argument is the position of the
1095 end of that region; it limits the search."
1097 (save-excursion
1098 (goto-char beginning)
1099 (forward-line 1)
1100 (re-search-forward "^@node" end t)
1101 (beginning-of-line)
1102 (point)))
1105 ;;; Alists and regular expressions for defining hierarchical levels
1107 (defvar texinfo-section-to-generic-alist
1108 '(("top" . "top")
1110 ("chapter" . "chapter")
1111 ("unnumbered" . "chapter")
1112 ("majorheading" . "chapter")
1113 ("chapheading" . "chapter")
1114 ("appendix" . "chapter")
1116 ("section" . "section")
1117 ("unnumberedsec" . "section")
1118 ("heading" . "section")
1119 ("appendixsec" . "section")
1121 ("subsection" . "subsection")
1122 ("unnumberedsubsec" . "subsection")
1123 ("subheading" . "subsection")
1124 ("appendixsubsec" . "subsection")
1126 ("subsubsection" . "subsubsection")
1127 ("unnumberedsubsubsec" . "subsubsection")
1128 ("subsubheading" . "subsubsection")
1129 ("appendixsubsubsec" . "subsubsection"))
1130 "*An alist of specific and corresponding generic Texinfo section types.
1131 The keys are strings specifying specific types of section; the values
1132 are strings of their corresponding general types.")
1134 ;; We used to look for just sub, but that found @subtitle.
1135 (defvar texinfo-section-types-regexp
1136 "^@\\(chapter \\|sect\\|subs\\|subh\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
1137 "Regexp matching chapter, section, other headings (but not the top node).")
1139 (defvar texinfo-chapter-level-regexp
1140 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
1141 "Regular expression matching just the Texinfo chapter level headings.")
1143 (defvar texinfo-section-level-regexp
1144 "section\\|unnumberedsec\\|heading \\|appendixsec"
1145 "Regular expression matching just the Texinfo section level headings.")
1147 (defvar texinfo-subsection-level-regexp
1148 "subsection\\|unnumberedsubsec\\|subheading\\|appendixsubsec"
1149 "Regular expression matching just the Texinfo subsection level headings.")
1151 (defvar texinfo-subsubsection-level-regexp
1152 "subsubsection\\|unnumberedsubsubsec\\|subsubheading\\|appendixsubsubsec"
1153 "Regular expression matching just the Texinfo subsubsection level headings.")
1155 (defvar texinfo-update-menu-same-level-regexps
1156 '(("top" . "top[ \t]+")
1157 ("chapter" .
1158 (concat "\\(^@\\)\\(" texinfo-chapter-level-regexp "\\)[ \t]*"))
1159 ("section" .
1160 (concat "\\(^@\\)\\(" texinfo-section-level-regexp "\\)[ \t]*"))
1161 ("subsection" .
1162 (concat "\\(^@\\)\\(" texinfo-subsection-level-regexp "\\)[ \t]+"))
1163 ("subsubsection" .
1164 (concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp "\\)[ \t]+")))
1165 "*Regexps for searching for same level sections in a Texinfo file.
1166 The keys are strings specifying the general hierarchical level in the
1167 document; the values are regular expressions.")
1169 (defvar texinfo-update-menu-higher-regexps
1170 '(("top" . "^@node [ \t]*DIR")
1171 ("chapter" . "^@node [ \t]*top[ \t]*\\(,\\|$\\)")
1172 ("section" .
1173 (concat
1174 "\\(^@\\("
1175 texinfo-chapter-level-regexp
1176 "\\)[ \t]*\\)"))
1177 ("subsection" .
1178 (concat
1179 "\\(^@\\("
1180 texinfo-section-level-regexp
1181 "\\|"
1182 texinfo-chapter-level-regexp
1183 "\\)[ \t]*\\)"))
1184 ("subsubsection" .
1185 (concat
1186 "\\(^@\\("
1187 texinfo-subsection-level-regexp
1188 "\\|"
1189 texinfo-section-level-regexp
1190 "\\|"
1191 texinfo-chapter-level-regexp
1192 "\\)[ \t]*\\)")))
1193 "*Regexps for searching for higher level sections in a Texinfo file.
1194 The keys are strings specifying the general hierarchical level in the
1195 document; the values are regular expressions.")
1197 (defvar texinfo-update-menu-lower-regexps
1198 '(("top" .
1199 (concat
1200 "\\(^@\\("
1201 texinfo-chapter-level-regexp
1202 "\\|"
1203 texinfo-section-level-regexp
1204 "\\|"
1205 texinfo-subsection-level-regexp
1206 "\\|"
1207 texinfo-subsubsection-level-regexp
1208 "\\)[ \t]*\\)"))
1209 ("chapter" .
1210 (concat
1211 "\\(^@\\("
1212 texinfo-section-level-regexp
1213 "\\|"
1214 texinfo-subsection-level-regexp
1215 "\\|"
1216 texinfo-subsubsection-level-regexp
1217 "\\)[ \t]*\\)"))
1218 ("section" .
1219 (concat
1220 "\\(^@\\("
1221 texinfo-subsection-level-regexp
1222 "\\|"
1223 texinfo-subsubsection-level-regexp
1224 "\\)[ \t]+\\)"))
1225 ("subsection" .
1226 (concat
1227 "\\(^@\\("
1228 texinfo-subsubsection-level-regexp
1229 "\\)[ \t]+\\)"))
1230 ("subsubsection" . "nothing lower"))
1231 "*Regexps for searching for lower level sections in a Texinfo file.
1232 The keys are strings specifying the general hierarchical level in the
1233 document; the values are regular expressions.")
1236 ;;; Updating a node
1238 ;;;###autoload
1239 (defun texinfo-update-node (&optional region-p)
1240 "Without any prefix argument, update the node in which point is located.
1241 Non-nil argument (prefix, if interactive) means update the nodes in the
1242 marked region.
1244 The functions for creating or updating nodes and menus, and their
1245 keybindings, are:
1247 texinfo-update-node (&optional region-p) \\[texinfo-update-node]
1248 texinfo-every-node-update () \\[texinfo-every-node-update]
1249 texinfo-sequential-node-update (&optional region-p)
1251 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
1252 texinfo-all-menus-update () \\[texinfo-all-menus-update]
1253 texinfo-master-menu ()
1255 texinfo-indent-menu-description (column &optional region-p)
1257 The `texinfo-column-for-description' variable specifies the column to
1258 which menu descriptions are indented. Its default value is 32."
1260 (interactive "P")
1261 (if (not region-p)
1262 ;; update a single node
1263 (let ((auto-fill-function nil) (auto-fill-hook nil))
1264 (if (not (re-search-backward "^@node" (point-min) t))
1265 (error "Node line not found before this position."))
1266 (texinfo-update-the-node)
1267 (message "Done...updated the node. You may save the buffer."))
1268 ;; else
1269 (let ((auto-fill-function nil)
1270 (auto-fill-hook nil)
1271 (beginning (region-beginning))
1272 (end (region-end)))
1273 (if (= end beginning)
1274 (error "Please mark a region!"))
1275 (save-restriction
1276 (narrow-to-region beginning end)
1277 (goto-char beginning)
1278 (push-mark (point) t)
1279 (while (re-search-forward "^@node" (point-max) t)
1280 (beginning-of-line)
1281 (texinfo-update-the-node))
1282 (message "Done...updated nodes in region. You may save the buffer.")))))
1284 ;;;###autoload
1285 (defun texinfo-every-node-update ()
1286 "Update every node in a Texinfo file."
1287 (interactive)
1288 (save-excursion
1289 (push-mark (point-max) t)
1290 (goto-char (point-min))
1291 ;; Using the mark to pass bounds this way
1292 ;; is kludgy, but it's not worth fixing. -- rms.
1293 (let ((mark-active t))
1294 (texinfo-update-node t))
1295 (message "Done...updated every node. You may save the buffer.")))
1297 (defun texinfo-update-the-node ()
1298 "Update one node. Point must be at the beginning of node line.
1299 Leave point at the end of the node line."
1300 (texinfo-check-for-node-name)
1301 (texinfo-delete-existing-pointers)
1302 (message "Updating node: %s ... " (texinfo-copy-node-name))
1303 (save-restriction
1304 (widen)
1305 (let*
1306 ((case-fold-search t)
1307 (level (texinfo-hierarchic-level))
1308 (beginning (texinfo-update-menu-region-beginning level))
1309 (end (texinfo-update-menu-region-end level)))
1310 (if (string-equal level "top")
1311 (texinfo-top-pointer-case)
1312 ;; else
1313 (texinfo-insert-pointer beginning end level 'next)
1314 (texinfo-insert-pointer beginning end level 'previous)
1315 (texinfo-insert-pointer beginning end level 'up)
1316 (texinfo-clean-up-node-line)))))
1318 (defun texinfo-top-pointer-case ()
1319 "Insert pointers in the Top node. This is a special case.
1321 The `Next' pointer is a pointer to a chapter or section at a lower
1322 hierarchical level in the file. The `Previous' and `Up' pointers are
1323 to `(dir)'. Point must be at the beginning of the node line, and is
1324 left at the end of the node line."
1326 (texinfo-clean-up-node-line)
1327 (insert ", "
1328 (save-excursion
1329 ;; There may be an @chapter or other such command between
1330 ;; the top node line and the next node line, as a title
1331 ;; for an `ifinfo' section. This @chapter command must
1332 ;; must be skipped. So the procedure is to search for
1333 ;; the next `@node' line, and then copy its name.
1334 (if (re-search-forward "^@node" nil t)
1335 (progn
1336 (beginning-of-line)
1337 (texinfo-copy-node-name))
1338 " "))
1339 ", (dir), (dir)"))
1341 (defun texinfo-check-for-node-name ()
1342 "Determine whether the node has a node name. Prompt for one if not.
1343 Point must be at beginning of node line. Does not move point."
1344 (save-excursion
1345 (let ((initial (texinfo-copy-next-section-title)))
1346 ;; This is not clean. Use `interactive' to read the arg.
1347 (forward-word 1) ; skip over node command
1348 (skip-chars-forward " \t") ; and over spaces
1349 (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what Info looks for
1350 ; alternatively, use "[a-zA-Z]+"
1351 (let ((node-name
1352 (read-from-minibuffer
1353 "Node name (use no @, commas, colons, or apostrophes): "
1354 initial)))
1355 (insert " " node-name))))))
1357 (defun texinfo-delete-existing-pointers ()
1358 "Delete `Next', `Previous', and `Up' pointers.
1359 Starts from the current position of the cursor, and searches forward
1360 on the line for a comma and if one is found, deletes the rest of the
1361 line, including the comma. Leaves point at beginning of line."
1362 (let ((eol-point (save-excursion (end-of-line) (point))))
1363 (if (search-forward "," eol-point t)
1364 (delete-region (1- (point)) eol-point)))
1365 (beginning-of-line))
1367 (defun texinfo-find-pointer (beginning end level direction)
1368 "Move point to section associated with next, previous, or up pointer.
1369 Return type of pointer (either 'normal or 'no-pointer).
1371 The first and second arguments bound the search for a pointer to the
1372 beginning and end, respectively, of the enclosing higher level
1373 section. The third argument is a string specifying the general kind
1374 of section such as \"chapter\" or \"section\". When looking for the
1375 `Next' pointer, the section found will be at the same hierarchical
1376 level in the Texinfo file; when looking for the `Previous' pointer,
1377 the section found will be at the same or higher hierarchical level in
1378 the Texinfo file; when looking for the `Up' pointer, the section found
1379 will be at some level higher in the Texinfo file. The fourth argument
1380 \(one of 'next, 'previous, or 'up\) specifies whether to find the
1381 `Next', `Previous', or `Up' pointer."
1382 (let ((case-fold-search t))
1383 (cond ((eq direction 'next)
1384 (forward-line 3) ; skip over current node
1385 ;; Search for section commands accompanied by node lines;
1386 ;; ignore section commands in the middle of nodes.
1387 (if (re-search-forward
1388 ;; A `Top' node is never a next pointer, so won't find it.
1389 (concat
1390 ;; Match node line.
1391 "\\(^@node\\).*\n"
1392 ;; Match comment or ifinfo line, if any
1393 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1394 (eval
1395 (cdr (assoc level texinfo-update-menu-same-level-regexps))))
1398 'normal
1399 'no-pointer))
1400 ((eq direction 'previous)
1401 (if (re-search-backward
1402 (concat
1403 "\\("
1404 ;; Match node line.
1405 "\\(^@node\\).*\n"
1406 ;; Match comment or ifinfo line, if any
1407 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1408 (eval
1409 (cdr (assoc level texinfo-update-menu-same-level-regexps)))
1410 "\\|"
1411 ;; Match node line.
1412 "\\(^@node\\).*\n"
1413 ;; Match comment or ifinfo line, if any
1414 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1415 (eval
1416 (cdr (assoc level texinfo-update-menu-higher-regexps)))
1417 "\\|"
1418 ;; Handle `Top' node specially.
1419 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1420 "\\)")
1421 beginning
1423 'normal
1424 'no-pointer))
1425 ((eq direction 'up)
1426 (if (re-search-backward
1427 (concat
1428 "\\("
1429 ;; Match node line.
1430 "\\(^@node\\).*\n"
1431 ;; Match comment or ifinfo line, if any
1432 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1433 (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
1434 "\\|"
1435 ;; Handle `Top' node specially.
1436 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1437 "\\)")
1438 (save-excursion
1439 (goto-char beginning)
1440 (beginning-of-line)
1441 (point))
1443 'normal
1444 'no-pointer))
1446 (error "texinfo-find-pointer: lack proper arguments")))))
1448 (defun texinfo-pointer-name (kind)
1449 "Return the node name preceding the section command.
1450 The argument is the kind of section, either normal or no-pointer."
1451 (let (name)
1452 (cond ((eq kind 'normal)
1453 (end-of-line) ; this handles prev node top case
1454 (re-search-backward ; when point is already
1455 "^@node" ; at the beginning of @node line
1456 (save-excursion (forward-line -3))
1458 (setq name (texinfo-copy-node-name)))
1459 ((eq kind 'no-pointer)
1460 (setq name " "))) ; put a blank in the pointer slot
1461 name))
1463 (defun texinfo-insert-pointer (beginning end level direction)
1464 "Insert the `Next', `Previous' or `Up' node name at point.
1465 Move point forward.
1467 The first and second arguments bound the search for a pointer to the
1468 beginning and end, respectively, of the enclosing higher level
1469 section. The third argument is the hierarchical level of the Texinfo
1470 file, a string such as \"section\". The fourth argument is direction
1471 towards which the pointer is directed, one of `next, `previous, or
1472 'up."
1474 (end-of-line)
1475 (insert
1476 ", "
1477 (save-excursion
1478 (texinfo-pointer-name
1479 (texinfo-find-pointer beginning end level direction)))))
1481 (defun texinfo-clean-up-node-line ()
1482 "Remove extra commas, if any, at end of node line."
1483 (end-of-line)
1484 (skip-chars-backward ", ")
1485 (delete-region (point) (save-excursion (end-of-line) (point))))
1488 ;;; Updating nodes sequentially
1489 ;; These sequential update functions insert `Next' or `Previous'
1490 ;; pointers that point to the following or preceding nodes even if they
1491 ;; are at higher or lower hierarchical levels. This means that if a
1492 ;; section contains one or more subsections, the section's `Next'
1493 ;; pointer will point to the subsection and not the following section.
1494 ;; (The subsection to which `Next' points will most likely be the first
1495 ;; item on the section's menu.)
1497 ;;;###autoload
1498 (defun texinfo-sequential-node-update (&optional region-p)
1499 "Update one node (or many) in a Texinfo file with sequential pointers.
1501 This function causes the `Next' or `Previous' pointer to point to the
1502 immediately preceding or following node, even if it is at a higher or
1503 lower hierarchical level in the document. Continually pressing `n' or
1504 `p' takes you straight through the file.
1506 Without any prefix argument, update the node in which point is located.
1507 Non-nil argument (prefix, if interactive) means update the nodes in the
1508 marked region.
1510 This command makes it awkward to navigate among sections and
1511 subsections; it should be used only for those documents that are meant
1512 to be read like a novel rather than a reference, and for which the
1513 Info `g*' command is inadequate."
1515 (interactive "P")
1516 (if (not region-p)
1517 ;; update a single node
1518 (let ((auto-fill-function nil) (auto-fill-hook nil))
1519 (if (not (re-search-backward "^@node" (point-min) t))
1520 (error "Node line not found before this position."))
1521 (texinfo-sequentially-update-the-node)
1522 (message
1523 "Done...sequentially updated the node . You may save the buffer."))
1524 ;; else
1525 (let ((auto-fill-function nil)
1526 (auto-fill-hook nil)
1527 (beginning (region-beginning))
1528 (end (region-end)))
1529 (if (= end beginning)
1530 (error "Please mark a region!"))
1531 (save-restriction
1532 (narrow-to-region beginning end)
1533 (goto-char beginning)
1534 (push-mark (point) t)
1535 (while (re-search-forward "^@node" (point-max) t)
1536 (beginning-of-line)
1537 (texinfo-sequentially-update-the-node))
1538 (message
1539 "Done...updated the nodes in sequence. You may save the buffer.")))))
1541 (defun texinfo-sequentially-update-the-node ()
1542 "Update one node such that the pointers are sequential.
1543 A `Next' or `Previous' pointer points to any preceding or following node,
1544 regardless of its hierarchical level."
1546 (texinfo-check-for-node-name)
1547 (texinfo-delete-existing-pointers)
1548 (message
1549 "Sequentially updating node: %s ... " (texinfo-copy-node-name))
1550 (save-restriction
1551 (widen)
1552 (let*
1553 ((case-fold-search t)
1554 (level (texinfo-hierarchic-level)))
1555 (if (string-equal level "top")
1556 (texinfo-top-pointer-case)
1557 ;; else
1558 (texinfo-sequentially-insert-pointer level 'next)
1559 (texinfo-sequentially-insert-pointer level 'previous)
1560 (texinfo-sequentially-insert-pointer level 'up)
1561 (texinfo-clean-up-node-line)))))
1563 (defun texinfo-sequentially-find-pointer (level direction)
1564 "Find next or previous pointer sequentially in Texinfo file, or up pointer.
1565 Move point to section associated with the pointer. Find point even if
1566 it is in a different section.
1568 Return type of pointer (either 'normal or 'no-pointer).
1570 The first argument is a string specifying the general kind of section
1571 such as \"chapter\" or \"section\". The section found will be at the
1572 same hierarchical level in the Texinfo file, or, in the case of the up
1573 pointer, some level higher. The second argument (one of 'next,
1574 'previous, or 'up) specifies whether to find the `Next', `Previous',
1575 or `Up' pointer."
1576 (let ((case-fold-search t))
1577 (cond ((eq direction 'next)
1578 (forward-line 3) ; skip over current node
1579 (if (re-search-forward
1580 texinfo-section-types-regexp
1581 (point-max)
1583 'normal
1584 'no-pointer))
1585 ((eq direction 'previous)
1586 (if (re-search-backward
1587 texinfo-section-types-regexp
1588 (point-min)
1590 'normal
1591 'no-pointer))
1592 ((eq direction 'up)
1593 (if (re-search-backward
1594 (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
1595 beginning
1597 'normal
1598 'no-pointer))
1600 (error "texinfo-sequential-find-pointer: lack proper arguments")))))
1602 (defun texinfo-sequentially-insert-pointer (level direction)
1603 "Insert the `Next', `Previous' or `Up' node name at point.
1604 Move point forward.
1606 The first argument is the hierarchical level of the Texinfo file, a
1607 string such as \"section\". The second argument is direction, one of
1608 `next, `previous, or 'up."
1610 (end-of-line)
1611 (insert
1612 ", "
1613 (save-excursion
1614 (texinfo-pointer-name
1615 (texinfo-sequentially-find-pointer level direction)))))
1618 ;;; Inserting `@node' lines
1619 ;; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
1620 ;; before the `@chapter', `@section', and such like lines of a region
1621 ;; in a Texinfo file.
1623 (defun texinfo-insert-node-lines (beginning end &optional title-p)
1624 "Insert missing `@node' lines in region of Texinfo file.
1625 Non-nil argument (prefix, if interactive) means also to insert the
1626 section titles as node names; and also to insert the section titles as
1627 node names in pre-existing @node lines that lack names."
1628 (interactive "r\nP")
1630 ;; Use marker; after inserting node lines, leave point at end of
1631 ;; region and mark at beginning.
1633 (let (beginning-marker end-marker title last-section-position)
1635 ;; Save current position on mark ring and set mark to end.
1636 (push-mark end t)
1637 (setq end-marker (mark-marker))
1639 (goto-char beginning)
1640 (while (re-search-forward
1641 texinfo-section-types-regexp
1642 end-marker
1643 'end)
1644 ;; Copy title if desired.
1645 (if title-p
1646 (progn
1647 (beginning-of-line)
1648 (forward-word 1)
1649 (skip-chars-forward " \t")
1650 (setq title (buffer-substring
1651 (point)
1652 (save-excursion (end-of-line) (point))))))
1653 ;; Insert node line if necessary.
1654 (if (re-search-backward
1655 "^@node"
1656 ;; Avoid finding previous node line if node lines are close.
1657 (or last-section-position
1658 (save-excursion (forward-line -2) (point))) t)
1659 ;; @node is present, and point at beginning of that line
1660 (forward-word 1) ; Leave point just after @node.
1661 ;; Else @node missing; insert one.
1662 (beginning-of-line) ; Beginning of `@section' line.
1663 (insert "@node\n")
1664 (backward-char 1)) ; Leave point just after `@node'.
1665 ;; Insert title if desired.
1666 (if title-p
1667 (progn
1668 (skip-chars-forward " \t")
1669 ;; Use regexp based on what info looks for
1670 ;; (alternatively, use "[a-zA-Z]+");
1671 ;; this means we only insert a title if none exists.
1672 (if (not (looking-at "[^,\t\n ]+"))
1673 (progn
1674 (beginning-of-line)
1675 (forward-word 1)
1676 (insert " " title)
1677 (message "Inserted title %s ... " title)))))
1678 ;; Go forward beyond current section title.
1679 (re-search-forward texinfo-section-types-regexp
1680 (save-excursion (forward-line 3) (point)) t)
1681 (setq last-section-position (point))
1682 (forward-line 1))
1684 ;; Leave point at end of region, mark at beginning.
1685 (set-mark beginning)
1687 (if title-p
1688 (message
1689 "Done inserting node lines and titles. You may save the buffer.")
1690 (message "Done inserting node lines. You may save the buffer."))))
1693 ;;; Update and create menus for multi-file Texinfo sources
1695 ;; 1. M-x texinfo-multiple-files-update
1697 ;; Read the include file list of an outer Texinfo file and
1698 ;; update all highest level nodes in the files listed and insert a
1699 ;; main menu in the outer file after its top node.
1701 ;; 2. C-u M-x texinfo-multiple-files-update
1703 ;; Same as 1, but insert a master menu. (Saves reupdating lower
1704 ;; level menus and nodes.) This command simply reads every menu,
1705 ;; so if the menus are wrong, the master menu will be wrong.
1706 ;; Similarly, if the lower level node pointers are wrong, they
1707 ;; will stay wrong.
1709 ;; 3. C-u 2 M-x texinfo-multiple-files-update
1711 ;; Read the include file list of an outer Texinfo file and
1712 ;; update all nodes and menus in the files listed and insert a
1713 ;; master menu in the outer file after its top node.
1715 ;;; Note: these functions:
1717 ;;; * Do not save or delete any buffers. You may fill up your memory.
1718 ;;; * Do not handle any pre-existing nodes in outer file.
1719 ;;; Hence, you may need a file for indices.
1722 ;;; Auxiliary functions for multiple file updating
1724 (defun texinfo-multi-file-included-list (outer-file)
1725 "Return a list of the included files in OUTER-FILE."
1726 (let ((included-file-list (list outer-file))
1727 start)
1728 (save-excursion
1729 (switch-to-buffer (find-file-noselect outer-file))
1730 (widen)
1731 (goto-char (point-min))
1732 (while (re-search-forward "^@include" nil t)
1733 (skip-chars-forward " \t")
1734 (setq start (point))
1735 (end-of-line)
1736 (skip-chars-backward " \t")
1737 (setq included-file-list
1738 (cons (buffer-substring start (point))
1739 included-file-list)))
1740 (nreverse included-file-list))))
1742 (defun texinfo-copy-next-section-title ()
1743 "Return the name of the immediately following section as a string.
1745 Start with point at the beginning of the node line. Leave point at the
1746 same place. If there is no title, returns an empty string."
1748 (save-excursion
1749 (end-of-line)
1750 (let ((node-end (or
1751 (save-excursion
1752 (if (re-search-forward "\\(^@node\\)" nil t)
1753 (match-beginning 0)))
1754 (point-max))))
1755 (if (re-search-forward texinfo-section-types-regexp node-end t)
1756 (progn
1757 (beginning-of-line)
1758 ;; copy title
1759 (let ((title
1760 (buffer-substring
1761 (progn (forward-word 1) ; skip over section type
1762 (skip-chars-forward " \t") ; and over spaces
1763 (point))
1764 (progn (end-of-line) (point)))))
1765 title))
1766 ""))))
1768 (defun texinfo-multi-file-update (files &optional update-everything)
1769 "Update first node pointers in each file in FILES.
1770 Return a list of the node names.
1772 The first file in the list is an outer file; the remaining are
1773 files included in the outer file with `@include' commands.
1775 If optional arg UPDATE-EVERYTHING non-nil, update every menu and
1776 pointer in each of the included files.
1778 Also update the `Top' level node pointers of the outer file.
1780 Requirements:
1782 * the first file in the FILES list must be the outer file,
1783 * each of the included files must contain exactly one highest
1784 hierarchical level node,
1785 * this node must be the first node in the included file,
1786 * each highest hierarchical level node must be of the same type.
1788 Thus, normally, each included file contains one, and only one,
1789 chapter."
1791 ;; The menu-list has the form:
1793 ;; \(\(\"node-name1\" . \"title1\"\)
1794 ;; \(\"node-name2\" . \"title2\"\) ... \)
1796 ;; However, there does not need to be a title field and this function
1797 ;; does not fill it; however a comment tells you how to do so.
1798 ;; You would use the title field if you wanted to insert titles in the
1799 ;; description slot of a menu as a description.
1801 (let ((case-fold-search t)
1802 menu-list)
1804 ;; Find the name of the first node of the first included file.
1805 (switch-to-buffer (find-file-noselect (car (cdr files))))
1806 (widen)
1807 (goto-char (point-min))
1808 (if (not (re-search-forward "^@node" nil t))
1809 (error "No `@node' line found in %s !" (buffer-name)))
1810 (beginning-of-line)
1811 (texinfo-check-for-node-name)
1812 (setq next-node-name (texinfo-copy-node-name))
1814 (setq menu-list
1815 (cons (cons
1816 next-node-name
1817 (prog1 "" (forward-line 1)))
1818 ;; Use following to insert section titles automatically.
1819 ;; (texinfo-copy-next-section-title)
1820 menu-list))
1822 ;; Go to outer file
1823 (switch-to-buffer (find-file-noselect (car files)))
1824 (goto-char (point-min))
1825 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
1826 (error "This buffer needs a Top node!"))
1827 (beginning-of-line)
1828 (texinfo-delete-existing-pointers)
1829 (end-of-line)
1830 (insert ", " next-node-name ", (dir), (dir)")
1831 (beginning-of-line)
1832 (setq previous-node-name "Top")
1833 (setq files (cdr files))
1835 (while files
1837 (if (not (cdr files))
1838 ;; No next file
1839 (setq next-node-name "")
1840 ;; Else,
1841 ;; find the name of the first node in the next file.
1842 (switch-to-buffer (find-file-noselect (car (cdr files))))
1843 (widen)
1844 (goto-char (point-min))
1845 (if (not (re-search-forward "^@node" nil t))
1846 (error "No `@node' line found in %s !" (buffer-name)))
1847 (beginning-of-line)
1848 (texinfo-check-for-node-name)
1849 (setq next-node-name (texinfo-copy-node-name))
1850 (setq menu-list
1851 (cons (cons
1852 next-node-name
1853 (prog1 "" (forward-line 1)))
1854 ;; Use following to insert section titles automatically.
1855 ;; (texinfo-copy-next-section-title)
1856 menu-list)))
1858 ;; Go to node to be updated.
1859 (switch-to-buffer (find-file-noselect (car files)))
1860 (goto-char (point-min))
1861 (if (not (re-search-forward "^@node" nil t))
1862 (error "No `@node' line found in %s !" (buffer-name)))
1863 (beginning-of-line)
1865 ;; Update other menus and nodes if requested.
1866 (if update-everything (texinfo-all-menus-update t))
1868 (beginning-of-line)
1869 (texinfo-delete-existing-pointers)
1870 (end-of-line)
1871 (insert ", " next-node-name ", " previous-node-name ", " up-node-name)
1873 (beginning-of-line)
1874 (setq previous-node-name (texinfo-copy-node-name))
1876 (setq files (cdr files)))
1877 (nreverse menu-list)))
1879 (defun texinfo-multi-files-insert-main-menu (menu-list)
1880 "Insert formatted main menu at point.
1881 Indents the first line of the description, if any, to the value of
1882 texinfo-column-for-description."
1884 (insert "@menu\n")
1885 (while menu-list
1886 ;; Every menu entry starts with a star and a space.
1887 (insert "* ")
1889 ;; Insert the node name (and menu entry name, if present).
1890 (let ((node-part (car (car menu-list))))
1891 (if (stringp node-part)
1892 ;; "Double colon" entry line; menu entry and node name are the same,
1893 (insert (format "%s::" node-part))
1894 ;; "Single colon" entry line; menu entry and node name are different.
1895 (insert (format "%s: %s." (car node-part) (cdr node-part)))))
1897 ;; Insert the description, if present.
1898 (if (cdr (car menu-list))
1899 (progn
1900 ;; Move to right place.
1901 (indent-to texinfo-column-for-description 2)
1902 ;; Insert description.
1903 (insert (format "%s" (cdr (car menu-list))))))
1905 (insert "\n") ; end this menu entry
1906 (setq menu-list (cdr menu-list)))
1907 (insert "@end menu"))
1909 (defun texinfo-multi-file-master-menu-list (files-list)
1910 "Return master menu list from files in FILES-LIST.
1911 Menu entries in each file collected using `texinfo-master-menu-list'.
1913 The first file in FILES-LIST must be the outer file; the others must
1914 be the files included within it. A main menu must already exist."
1915 (save-excursion
1916 (let (master-menu-list)
1917 (while files-list
1918 (switch-to-buffer (find-file-noselect (car files-list)))
1919 (message "Working on: %s " (current-buffer))
1920 (goto-char (point-min))
1921 (setq master-menu-list
1922 (append master-menu-list (texinfo-master-menu-list)))
1923 (setq files-list (cdr files-list)))
1924 master-menu-list)))
1927 ;;; The multiple-file update function
1929 (defun texinfo-multiple-files-update
1930 (outer-file &optional update-everything make-master-menu)
1931 "Update first node pointers in each file included in OUTER-FILE;
1932 create or update the `Top' level node pointers and the main menu in
1933 the outer file that refers to such nodes. This does not create or
1934 update menus or pointers within the included files.
1936 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
1937 insert a master menu in OUTER-FILE in addition to creating or updating
1938 pointers in the first @node line in each included file and creating or
1939 updating the `Top' level node pointers of the outer file. This does
1940 not create or update other menus and pointers within the included
1941 files.
1943 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
1944 interactive), update all the menus and all the `Next', `Previous', and
1945 `Up' pointers of all the files included in OUTER-FILE before inserting
1946 a master menu in OUTER-FILE. Also, update the `Top' level node
1947 pointers of OUTER-FILE.
1949 Notes:
1951 * this command does NOT save any files--you must save the
1952 outer file and any modified, included files.
1954 * except for the `Top' node, this command does NOT handle any
1955 pre-existing nodes in the outer file; hence, indices must be
1956 enclosed in an included file.
1958 Requirements:
1960 * each of the included files must contain exactly one highest
1961 hierarchical level node,
1962 * this highest node must be the first node in the included file,
1963 * each highest hierarchical level node must be of the same type.
1965 Thus, normally, each included file contains one, and only one,
1966 chapter."
1968 (interactive (cons
1969 (read-string
1970 "Name of outer `include' file: "
1971 (buffer-file-name))
1972 (cond ((not current-prefix-arg)
1973 '(nil nil))
1974 ((listp current-prefix-arg)
1975 '(t nil)) ; make-master-menu
1976 ((numberp current-prefix-arg)
1977 '(t t)) ; update-everything
1980 (let* ((included-file-list (texinfo-multi-file-included-list outer-file))
1981 (files included-file-list)
1982 main-menu-list
1983 next-node-name
1984 previous-node-name
1985 (up-node-name "Top"))
1987 ;;; Update the pointers
1988 ;;; and collect the names of the nodes and titles
1989 (setq main-menu-list (texinfo-multi-file-update files update-everything))
1991 ;;; Insert main menu
1993 ;; Go to outer file
1994 (switch-to-buffer (find-file-noselect (car included-file-list)))
1995 (if (texinfo-old-menu-p
1996 (point-min)
1997 (save-excursion
1998 (re-search-forward "^@include")
1999 (beginning-of-line)
2000 (point)))
2002 ;; If found, leave point after word `menu' on the `@menu' line.
2003 (progn
2004 (texinfo-incorporate-descriptions main-menu-list)
2005 ;; Delete existing menu.
2006 (beginning-of-line)
2007 (delete-region
2008 (point)
2009 (save-excursion (re-search-forward "^@end menu") (point)))
2010 ;; Insert main menu
2011 (texinfo-multi-files-insert-main-menu main-menu-list))
2013 ;; Else no current menu; insert it before `@include'
2014 (texinfo-multi-files-insert-main-menu main-menu-list))
2016 ;;; Insert master menu
2018 (if make-master-menu
2019 (progn
2020 ;; First, removing detailed part of any pre-existing master menu
2021 (goto-char (point-min))
2022 (if (re-search-forward texinfo-master-menu-header nil t)
2023 ;; Remove detailed master menu listing
2024 (progn
2025 (goto-char (match-beginning 0))
2026 (let ((end-of-detailed-menu-descriptions
2027 (save-excursion ; beginning of end menu line
2028 (goto-char (texinfo-menu-end))
2029 (beginning-of-line) (forward-char -1)
2030 (point))))
2031 (delete-region (point) end-of-detailed-menu-descriptions))))
2033 ;; Create a master menu and insert it
2034 (texinfo-insert-master-menu-list
2035 (texinfo-multi-file-master-menu-list
2036 included-file-list)))))
2038 ;; Remove unwanted extra lines.
2039 (save-excursion
2040 (goto-char (point-min))
2042 (re-search-forward "^@menu")
2043 (forward-line -1)
2044 (insert "\n") ; Ensure at least one blank line.
2045 (delete-blank-lines)
2047 (re-search-forward "^@end menu")
2048 (forward-line 1)
2049 (insert "\n") ; Ensure at least one blank line.
2050 (delete-blank-lines))
2052 (message "Multiple files updated."))
2055 ;;; Place `provide' at end of file.
2056 (provide 'texnfo-upd)
2058 ;;; texnfo-upd.el ends here