1 ;;; texnfo-upd.el --- utilities for updating nodes and menus in Texinfo files
3 ;; Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
5 ;; Author: Robert J. Chassell
6 ;; Maintainer: bug-texinfo@prep.ai.mit.edu
7 ;; Keywords: maint, tex, docs
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
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.
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
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.
152 (defun texinfo-make-menu (&optional beginning end
)
153 "Without any prefix argument, make or update a menu.
154 Make the menu for the section enclosing the node found following point.
156 A prefix argument means make or update menus
157 for nodes within or part of the marked region.
159 Whenever a menu exists, and is being updated, the descriptions that
160 are associated with node names in the pre-existing menu are
161 incorporated into the new menu. Otherwise, the nodes' section titles
162 are inserted as descriptions."
166 (list (point) (mark))))
168 (let ((level (texinfo-hierarchic-level)))
169 (texinfo-make-one-menu level
)
170 (message "Menu updated"))
172 (message "Making or updating menus in %s... " (buffer-name))
174 (goto-char (min beginning end
))
175 ;; find section type following point
176 (let ((level (texinfo-hierarchic-level))
177 (region-end (max beginning end
)))
181 (while (texinfo-find-lower-level-node level region-end
)
182 (setq level
(texinfo-hierarchic-level)) ; new, lower level
183 (texinfo-make-one-menu level
))
185 (while (and (< (point) region-end
)
186 (texinfo-find-higher-level-node level region-end
))
187 (setq level
(texinfo-hierarchic-level))
188 (while (texinfo-find-lower-level-node level region-end
)
189 (setq level
(texinfo-hierarchic-level)) ; new, lower level
190 (texinfo-make-one-menu level
))))))
191 (message "Making or updating menus in %s...done" (buffer-name))))
193 (defun texinfo-make-one-menu (level)
194 "Make a menu of all the appropriate nodes in this section.
195 `Appropriate nodes' are those associated with sections that are
196 at the level specified by LEVEL. Point is left at the end of menu."
198 ((case-fold-search t
)
201 (goto-char (texinfo-update-menu-region-beginning level
))
204 (end (texinfo-update-menu-region-end level
))
205 (first (texinfo-menu-first-node beginning end
))
207 (goto-char beginning
)
209 (texinfo-copy-node-name)))
210 (new-menu-list (texinfo-make-menu-list beginning end level
)))
211 (if (texinfo-old-menu-p beginning first
)
213 (texinfo-incorporate-descriptions new-menu-list
)
214 (texinfo-incorporate-menu-entry-names new-menu-list
)
215 (texinfo-delete-old-menu beginning first
)))
216 (texinfo-insert-menu new-menu-list node-name
)))
218 (defun texinfo-all-menus-update (&optional update-all-nodes-p
)
219 "Update every regular menu in a Texinfo file.
220 Update pre-existing master menu, if there is one.
222 If called with a non-nil argument, this function first updates all the
223 nodes in the buffer before updating the menus."
225 (let ((case-fold-search t
)
228 (push-mark (point-max) t
)
229 (goto-char (point-min))
230 (message "Checking for a master menu in %s ... "(buffer-name))
232 (if (re-search-forward texinfo-master-menu-header nil t
)
233 ;; Remove detailed master menu listing
235 (setq master-menu-p t
)
236 (goto-char (match-beginning 0))
237 (let ((end-of-detailed-menu-descriptions
238 (save-excursion ; beginning of end menu line
239 (goto-char (texinfo-menu-end))
240 (beginning-of-line) (forward-char -
1)
242 (delete-region (point) end-of-detailed-menu-descriptions
)))))
244 (if update-all-nodes-p
246 (message "Updating all nodes in %s ... " (buffer-name))
248 (texinfo-update-node (point-min) (point-max))))
250 (message "Updating all menus in %s ... " (buffer-name))
252 (texinfo-make-menu (point-max) (point-min))
256 (message "Updating the master menu in %s... " (buffer-name))
258 (texinfo-master-menu nil
))))
260 (message "Done...updated all the menus. You may save the buffer.")))
262 (defun texinfo-find-lower-level-node (level region-end
)
263 "Search forward from point for node at any level lower than LEVEL.
264 Search is limited to the end of the marked region, REGION-END,
265 and to the end of the menu region for the level.
267 Return t if the node is found, else nil. Leave point at the beginning
268 of the node if one is found; else do not move point."
269 (let ((case-fold-search t
))
270 (if (and (< (point) region-end
)
273 "\\(^@node\\).*\n" ; match node line
274 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
276 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
277 (eval (cdr (assoc level texinfo-update-menu-lower-regexps
))))
278 ;; the next higher level node marks the end of this
279 ;; section, and no lower level node will be found beyond
280 ;; this position even if region-end is farther off
281 (texinfo-update-menu-region-end level
)
283 (goto-char (match-beginning 1)))))
285 (defun texinfo-find-higher-level-node (level region-end
)
286 "Search forward from point for node at any higher level than argument LEVEL.
287 Search is limited to the end of the marked region, REGION-END.
289 Return t if the node is found, else nil. Leave point at the beginning
290 of the node if one is found; else do not move point."
291 (let ((case-fold-search t
))
293 ((or (string-equal "top" level
) (string-equal "chapter" level
))
294 (if (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" region-end t
)
295 (progn (beginning-of-line) t
)))
297 (if (re-search-forward
299 "\\(^@node\\).*\n" ; match node line
300 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
302 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
303 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
))))
305 (progn (beginning-of-line) t
))))))
308 ;;; Making the list of new menu entries
310 (defun texinfo-make-menu-list (beginning end level
)
311 "Make a list of node names and their descriptions.
312 Point is left at the end of the menu region, but the menu is not inserted.
314 First argument is position from which to start making menu list;
315 second argument is end of region in which to try to locate entries;
316 third argument is the level of the nodes that are the entries.
318 Node names and descriptions are dotted pairs of strings. Each pair is
319 an element of the list. If the description does not exist, the
320 element consists only of the node name."
321 (goto-char beginning
)
323 (while (texinfo-menu-locate-entry-p level end
)
326 (texinfo-copy-node-name)
327 (prog1 "" (forward-line 1)))
328 ;; Use following to insert section titles automatically.
329 ;; (texinfo-copy-section-title))
331 (reverse new-menu-list
)))
333 (defun texinfo-menu-locate-entry-p (level search-end
)
334 "Find a node that will be part of menu for this section.
335 First argument is a string such as \"section\" specifying the general
336 hierarchical level of the menu; second argument is a position
337 specifying the end of the search.
339 The function returns t if the node is found, else nil. It searches
340 forward from point, and leaves point at the beginning of the node.
342 The function finds entries of the same type. Thus `subsections' and
343 `unnumberedsubsecs' will appear in the same menu."
344 (let ((case-fold-search t
))
345 (if (re-search-forward
347 "\\(^@node\\).*\n" ; match node line
348 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
350 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
352 (cdr (assoc level texinfo-update-menu-same-level-regexps
))))
355 (goto-char (match-beginning 1)))))
357 (defun texinfo-copy-node-name ()
358 "Return the node name as a string.
360 Start with point at the beginning of the node line; copy the text
361 after the node command up to the first comma on the line, if any, and
362 return the text as a string. Leaves point at the beginning of the
363 line. If there is no node name, returns an empty string."
367 (progn (forward-word 1) ; skip over node command
368 (skip-chars-forward " \t") ; and over spaces
372 (save-excursion (end-of-line) (point)) t
) ; bound search
374 (end-of-line) (point)))))
376 (defun texinfo-copy-section-title ()
377 "Return the title of the section as a string.
378 The title is used as a description line in the menu when one does not
381 Move point to the beginning of the appropriate section line by going
382 to the start of the text matched by last regexp searched for, which
383 must have been done by `texinfo-menu-locate-entry-p'."
385 ;; could use the same re-search as in `texinfo-menu-locate-entry-p'
386 ;; instead of using `match-beginning'; such a variation would be
387 ;; more general, but would waste information already collected
389 (goto-char (match-beginning 7)) ; match section name
392 (progn (forward-word 1) ; skip over section type
393 (skip-chars-forward " \t") ; and over spaces
395 (progn (end-of-line) (point))))
398 ;;; Handling the old menu
400 (defun texinfo-old-menu-p (beginning first
)
401 "Move point to the beginning of the menu for this section, if any.
402 Otherwise move point to the end of the first node of this section.
403 Return t if a menu is found, nil otherwise.
405 First argument is the position of the beginning of the section in which
406 the menu will be located; second argument is the position of the first
407 node within the section.
409 If no menu is found, the function inserts two newlines just before the
410 end of the section, and leaves point there where a menu ought to be."
411 (goto-char beginning
)
412 (if (not (re-search-forward "^@menu" first
'goto-end
))
413 (progn (insert "\n\n") (forward-line -
2) nil
)
416 (defun texinfo-incorporate-descriptions (new-menu-list)
417 "Copy the old menu line descriptions that exist to the new menu.
419 Point must be at beginning of old menu.
421 If the node-name of the new menu is found in the old menu, insert the
422 old description into the new entry.
424 For this function, the new menu is a list made up of lists of dotted
425 pairs in which the first element of the pair is the node name and the
426 second element the description. The new menu is changed destructively.
427 The old menu is the menu as it appears in the texinfo file."
429 (let ((new-menu-list-pointer new-menu-list
)
430 (end-of-menu (texinfo-menu-end)))
432 (save-excursion ; keep point at beginning of menu
433 (if (re-search-forward
434 ;; Existing nodes can have the form
435 ;; * NODE NAME:: DESCRIPTION
437 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
439 ;; Recognize both when looking for the description.
440 (concat "\\* \\(" ; so only menu entries are found
441 (regexp-quote (car (car new-menu-list
))) "::"
443 ".*: " (regexp-quote (car (car new-menu-list
))) "[.,\t\n]"
445 ) ; so only complete entries are found
448 (setcdr (car new-menu-list
)
449 (texinfo-menu-copy-old-description end-of-menu
))))
450 (setq new-menu-list
(cdr new-menu-list
)))
451 (setq new-menu-list new-menu-list-pointer
)))
453 (defun texinfo-incorporate-menu-entry-names (new-menu-list)
454 "Copy any old menu entry names to the new menu.
456 Point must be at beginning of old menu.
458 If the node-name of the new menu entry cannot be found in the old
461 For this function, the new menu is a list made up of lists of dotted
462 pairs in which the first element of the pair is the node name and the
463 second element is the description (or nil).
465 If we find an existing menu entry name, we change the first element of
466 the pair to be another dotted pair in which the car is the menu entry
467 name and the cdr is the node name.
469 NEW-MENU-LIST is changed destructively. The old menu is the menu as it
470 appears in the texinfo file."
472 (let ((new-menu-list-pointer new-menu-list
)
473 (end-of-menu (texinfo-menu-end)))
475 (save-excursion ; keep point at beginning of menu
476 (if (re-search-forward
477 ;; Existing nodes can have the form
478 ;; * NODE NAME:: DESCRIPTION
480 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
482 ;; We're interested in the second case.
483 (concat "\\* " ; so only menu entries are found
484 "\\(.*\\): " (car (car new-menu-list
)) "[.,\t\n]")
488 (car new-menu-list
) ; replace the node name
489 (cons (buffer-substring (match-beginning 1) (match-end 1))
490 (car (car new-menu-list
)))))
491 (setq new-menu-list
(cdr new-menu-list
))))
492 (setq new-menu-list new-menu-list-pointer
)))
494 (defun texinfo-menu-copy-old-description (end-of-menu)
495 "Return description field of old menu line as string.
496 Point must be located just after the node name. Point left before description.
497 Single argument, END-OF-MENU, is position limiting search."
498 (skip-chars-forward "[:.,\t\n ]+")
499 ;; don't copy a carriage return at line beginning with asterisk!
500 ;; do copy a description that begins with an `@'!
501 ;; !! Known bug: does not copy descriptions starting with ^|\{?* etc.
502 (if (and (looking-at "\\(\\w+\\|@\\)")
503 (not (looking-at "\\(^\\* \\|^@end menu\\)")))
507 (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t
)
509 (end-of-line) ; go to end of last description line
513 (defun texinfo-menu-end ()
514 "Return position of end of menu. Does not change location of point.
515 Signal an error if not end of menu."
517 (if (re-search-forward "^@end menu" nil t
)
519 (error "Menu does not have an end."))))
521 (defun texinfo-delete-old-menu (beginning first
)
522 "Delete the old menu. Point must be in or after menu.
523 First argument is position of the beginning of the section in which
524 the menu will be located; second argument is the position of the first
525 node within the section."
526 ;; No third arg to search, so error if search fails.
527 (re-search-backward "^@menu" beginning
)
528 (delete-region (point)
530 (re-search-forward "^@end menu" first
)
534 ;;; Inserting new menu
536 ;; try 32, but perhaps 24 is better
537 (defvar texinfo-column-for-description
32
538 "*Column at which descriptions start in a Texinfo menu.")
540 (defun texinfo-insert-menu (menu-list node-name
)
541 "Insert formatted menu at point.
542 Indents the first line of the description, if any, to the value of
543 texinfo-column-for-description.
547 \(\(\"node-name1\" . \"description\"\)
548 \(\"node-name2\" . \"description\"\) ... \)
550 However, the description field might be nil.
552 Also, the node-name field might itself be a dotted pair (call it P) of
553 strings instead of just a string. In that case, the car of P
554 is the menu entry name, and the cdr of P is the node name."
558 ;; Every menu entry starts with a star and a space.
561 ;; Insert the node name (and menu entry name, if present).
562 (let ((node-part (car (car menu-list
))))
563 (if (stringp node-part
)
564 ;; "Double colon" entry line; menu entry and node name are the same,
565 (insert (format "%s::" node-part
))
566 ;; "Single colon" entry line; menu entry and node name are different.
567 (insert (format "%s: %s." (car node-part
) (cdr node-part
)))))
569 ;; Insert the description, if present.
570 (if (cdr (car menu-list
))
572 ;; Move to right place.
573 (indent-to texinfo-column-for-description
2)
574 ;; Insert description.
575 (insert (format "%s" (cdr (car menu-list
))))))
577 (insert "\n") ; end this menu entry
578 (setq menu-list
(cdr menu-list
)))
581 "Updated \"%s\" level menu following node: %s ... " level node-name
))
584 ;;; Starting menu descriptions by inserting titles
586 (defun texinfo-start-menu-description ()
587 "In this menu entry, insert the node's section title as a description.
588 Position point at beginning of description ready for editing.
589 Do not insert a title if the line contains an existing description.
591 You will need to edit the inserted text since a useful description
592 complements the node name rather than repeats it as a title does."
595 (let (beginning end node-name title
)
598 (if (search-forward "* " (save-excursion (end-of-line) (point)) t
)
599 (progn (skip-chars-forward " \t")
600 (setq beginning
(point)))
601 (error "This is not a line in a menu!"))
604 ;; "Double colon" entry line; menu entry and node name are the same,
605 ((search-forward "::" (save-excursion (end-of-line) (point)) t
)
606 (if (looking-at "[ \t]*[^ \t\n]+")
607 (error "Descriptive text already exists."))
608 (skip-chars-backward ": \t")
609 (setq node-name
(buffer-substring beginning
(point))))
611 ;; "Single colon" entry line; menu entry and node name are different.
612 ((search-forward ":" (save-excursion (end-of-line) (point)) t
)
613 (skip-chars-forward " \t")
614 (setq beginning
(point))
615 ;; Menu entry line ends in a period, comma, or tab.
616 (if (re-search-forward "[.,\t]"
617 (save-excursion (forward-line 1) (point)) t
)
619 (if (looking-at "[ \t]*[^ \t\n]+")
620 (error "Descriptive text already exists."))
621 (skip-chars-backward "., \t")
622 (setq node-name
(buffer-substring beginning
(point))))
623 ;; Menu entry line ends in a return.
624 (re-search-forward ".*\n"
625 (save-excursion (forward-line 1) (point)) t
)
626 (skip-chars-backward " \t\n")
627 (setq node-name
(buffer-substring beginning
(point)))
628 (if (= 0 (length node-name
))
629 (error "No node name on this line.")
631 (t (error "No node name on this line.")))
632 ;; Search for node that matches node name, and copy the section title.
633 (if (re-search-forward
637 ".*\n" ; match node line
639 "\\(\\(^@c \\|^@comment\\).*\n\\)" ; match comment line, if any
641 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
647 ;; skip over section type
648 (progn (forward-word 1)
650 (skip-chars-forward " \t")
653 (skip-chars-backward " \t")
655 (error "Cannot find node to match node name in menu entry.")))
656 ;; Return point to the menu and insert the title.
660 (save-excursion (skip-chars-backward " \t") (point)))
661 (indent-to texinfo-column-for-description
2)
662 (save-excursion (insert title
))))
665 ;;; Handling description indentation
667 ; Since the make-menu functions indent descriptions, these functions
668 ; are useful primarily for indenting a single menu specially.
670 (defun texinfo-indent-menu-description (column &optional region-p
)
671 "Indent every description in menu following point to COLUMN.
672 Non-nil argument (prefix, if interactive) means indent every
673 description in every menu in the region. Does not indent second and
674 subsequent lines of a multi-line description."
677 "nIndent menu descriptions to (column number): \nP")
683 (re-search-forward "^@menu")
684 (texinfo-menu-indent-description column
)
686 "Indented descriptions in menu. You may save the buffer."))
688 (message "Indenting every menu description in region... ")
689 (goto-char (region-beginning))
690 (while (and (< (point) (region-end))
691 (texinfo-locate-menu-p))
693 (texinfo-menu-indent-description column
))
694 (message "Indenting done. You may save the buffer.")))))
696 (defun texinfo-menu-indent-description (to-column-number)
697 "Indent the Texinfo file menu description to TO-COLUMN-NUMBER.
698 Start with point just after the word `menu' in the `@menu' line and
699 leave point on the line before the `@end menu' line. Does not indent
700 second and subsequent lines of a multi-line description."
701 (let* ((beginning-of-next-line (point)))
702 (while (< beginning-of-next-line
703 (save-excursion ; beginning of end menu line
704 (goto-char (texinfo-menu-end))
708 (if (re-search-forward "\\* \\(.*::\\|.*: [^.,\t\n]+[.,\t]\\)"
712 (let ((beginning-white-space (point)))
713 (skip-chars-forward " \t") ; skip over spaces
714 (if (looking-at "\\(@\\|\\w\\)+") ; if there is text
716 ;; remove pre-existing indentation
717 (delete-region beginning-white-space
(point))
718 (indent-to-column to-column-number
))))))
719 ;; position point at beginning of next line
721 (setq beginning-of-next-line
(point)))))
724 ;;; Making the master menu
726 (defun texinfo-master-menu (update-all-nodes-menus-p)
727 "Make a master menu for a whole Texinfo file.
728 Non-nil argument (prefix, if interactive) means first update all
729 existing nodes and menus. Remove pre-existing master menu, if there is one.
731 This function creates a master menu that follows the top node. The
732 master menu includes every entry from all the other menus. It
733 replaces any existing ordinary menu that follows the top node.
735 If called with a non-nil argument, this function first updates all the
736 menus in the buffer (incorporating descriptions from pre-existing
737 menus) before it constructs the master menu.
739 The function removes the detailed part of an already existing master
740 menu. This action depends on the pre-existing master menu using the
741 standard `texinfo-master-menu-header'.
743 The master menu has the following format, which is adapted from the
744 recommendation in the Texinfo Manual:
746 * The first part contains the major nodes in the Texinfo file: the
747 nodes for the chapters, chapter-like sections, and the major
748 appendices. This includes the indices, so long as they are in
749 chapter-like sections, such as unnumbered sections.
751 * The second and subsequent parts contain a listing of the other,
752 lower level menus, in order. This way, an inquirer can go
753 directly to a particular node if he or she is searching for
754 specific information.
756 Each of the menus in the detailed node listing is introduced by the
757 title of the section containing the menu."
760 (let ((case-fold-search t
))
762 (goto-char (point-min))
764 ;; Move point to location after `top'.
765 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
766 (error "This buffer needs a Top node!"))
770 (or (re-search-forward "^@node" nil t
)
771 (error "Too few nodes for a master menu!"))
773 (if (re-search-forward texinfo-master-menu-header first-chapter t
)
774 ;; Remove detailed master menu listing
776 (goto-char (match-beginning 0))
777 (let ((end-of-detailed-menu-descriptions
778 (save-excursion ; beginning of end menu line
779 (goto-char (texinfo-menu-end))
780 (beginning-of-line) (forward-char -
1)
782 (delete-region (point) end-of-detailed-menu-descriptions
)))))
784 (if update-all-nodes-menus-p
786 (message "Making a master menu in %s ...first updating all nodes... "
789 (texinfo-update-node (point-min) (point-max))
791 (message "Updating all menus in %s ... " (buffer-name))
793 (texinfo-make-menu (point-min) (point-max))))
795 (message "Now making the master menu in %s... " (buffer-name))
797 (goto-char (point-min))
798 (texinfo-insert-master-menu-list
799 (texinfo-master-menu-list))
801 ;; Remove extra newlines that texinfo-insert-master-menu-list
802 ;; may have inserted.
805 (goto-char (point-min))
807 (if (re-search-forward texinfo-master-menu-header nil t
)
809 (goto-char (match-beginning 0))
812 (goto-char (point-min))))
814 (re-search-forward "^@menu")
818 (re-search-forward "^@end menu")
820 (delete-blank-lines))
823 "Done...completed making master menu. You may save the buffer.")))
825 (defun texinfo-master-menu-list ()
826 "Return a list of menu entries and header lines for the master menu.
828 Start with the menu for chapters and indices and then find each
829 following menu and the title of the node preceding that menu.
831 The master menu list has this form:
833 \(\(\(... \"entry-1-2\" \"entry-1\"\) \"title-1\"\)
834 \(\(... \"entry-2-2\" \"entry-2-1\"\) \"title-2\"\)
837 However, there does not need to be a title field."
839 (let (master-menu-list)
840 (while (texinfo-locate-menu-p)
841 (setq master-menu-list
844 (texinfo-copy-menu-title))
846 (reverse master-menu-list
)))
848 (defun texinfo-insert-master-menu-list (master-menu-list)
849 "Format and insert the master menu in the current buffer."
850 (goto-char (point-min))
851 ;; Insert a master menu only after `Top' node and before next node
852 ;; \(or include file if there is no next node\).
853 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
854 (error "This buffer needs a Top node!"))
856 (save-excursion (re-search-forward "^@node\\|^@include") (point))))
857 (if (not (re-search-forward "^@menu" first-chapter t
))
859 "Buffer lacks ordinary `Top' menu in which to insert master.")))
861 (delete-region ; buffer must have ordinary top menu
863 (save-excursion (re-search-forward "^@end menu") (point)))
865 (save-excursion ; leave point at beginning of menu
866 ;; Handle top of menu
868 ;; Insert chapter menu entries
869 (setq this-very-menu-list
(reverse (car (car master-menu-list
))))
870 ;; Tell user what is going on.
871 (message "Inserting chapter menu entry: %s ... " this-very-menu-list
)
872 (while this-very-menu-list
873 (insert "* " (car this-very-menu-list
) "\n")
874 (setq this-very-menu-list
(cdr this-very-menu-list
)))
876 (setq master-menu-list
(cdr master-menu-list
))
878 ;; Only insert detailed master menu if there is one....
879 (if (car (car master-menu-list
))
880 (insert texinfo-master-menu-header
))
882 ;; Now, insert all the other menus
884 ;; The menu master-menu-list has a form like this:
885 ;; ((("beta" "alpha") "title-A")
886 ;; (("delta" "gamma") "title-B"))
888 (while master-menu-list
891 "Inserting menu for %s .... " (car (cdr (car master-menu-list
))))
892 ;; insert title of menu section
893 (insert "\n" (car (cdr (car master-menu-list
))) "\n\n")
895 ;; insert each menu entry
896 (setq this-very-menu-list
(reverse (car (car master-menu-list
))))
897 (while this-very-menu-list
898 (insert "* " (car this-very-menu-list
) "\n")
899 (setq this-very-menu-list
(cdr this-very-menu-list
)))
901 (setq master-menu-list
(cdr master-menu-list
)))
904 (insert "@end menu\n\n")))
906 (defvar texinfo-master-menu-header
907 "\n --- The Detailed Node Listing ---\n"
908 "String inserted before lower level entries in Texinfo master menu.
909 It comes after the chapter-level menu entries.")
911 (defun texinfo-locate-menu-p ()
912 "Find the next menu in the texinfo file.
913 If found, leave point after word `menu' on the `@menu' line, and return t.
914 If a menu is not found, do not move point and return nil."
915 (re-search-forward "\\(^@menu\\)" nil t
))
917 (defun texinfo-copy-menu-title ()
918 "Return the title of the section preceding the menu as a string.
919 If such a title cannot be found, return an empty string. Do not move
921 (let ((case-fold-search t
))
923 (if (re-search-backward
927 texinfo-section-types-regexp
; all other section types
933 (forward-word 1) ; skip over section type
934 (skip-chars-forward " \t") ; and over spaces
937 (progn (end-of-line) (point))))
940 (defun texinfo-copy-menu ()
941 "Return the entries of an existing menu as a list.
942 Start with point just after the word `menu' in the `@menu' line
943 and leave point on the line before the `@end menu' line."
944 (let* (this-menu-list
945 (end-of-menu (texinfo-menu-end)) ; position of end of `@end menu'
946 (last-entry (save-excursion ; position of beginning of
948 (goto-char end-of-menu
)
949 ;; handle multi-line description
950 (if (not (re-search-backward "^\\* " nil t
))
951 (error "No entries in menu."))
953 (while (< (point) last-entry
)
954 (if (re-search-forward "^\\* " end-of-menu t
)
960 ;; copy multi-line descriptions
962 (re-search-forward "\\(^\\* \\|^@e\\)" nil t
)
968 ;;; Determining the hierarchical level in the texinfo file
970 (defun texinfo-specific-section-type ()
971 "Return the specific type of next section, as a string.
972 For example, \"unnumberedsubsec\". Return \"top\" for top node.
974 Searches forward for a section. Hence, point must be before the
975 section whose type will be found. Does not move point. Signal an
976 error if the node is not the top node and a section is not found."
977 (let ((case-fold-search t
))
980 ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
981 ;;; Following search limit by cph but causes a bug
988 ((re-search-forward texinfo-section-types-regexp nil t
)
989 (buffer-substring-no-properties
990 (progn (beginning-of-line) ; copy its name
992 (progn (forward-word 1)
996 "texinfo-specific-section-type: Chapter or section not found."))))))
998 (defun texinfo-hierarchic-level ()
999 "Return the general hierarchal level of the next node in a texinfo file.
1000 Thus, a subheading or appendixsubsec is of type subsection."
1001 (let ((case-fold-search t
))
1003 (texinfo-specific-section-type)
1004 texinfo-section-to-generic-alist
))))
1007 ;;; Locating the major positions
1009 (defun texinfo-update-menu-region-beginning (level)
1010 "Locate beginning of higher level section this section is within.
1011 Return position of the beginning of the node line; do not move point.
1012 Thus, if this level is subsection, searches backwards for section node.
1013 Only argument is a string of the general type of section."
1014 (let ((case-fold-search t
))
1015 ;; !! Known bug: if section immediately follows top node, this
1016 ;; returns the beginning of the buffer as the beginning of the
1017 ;; higher level section.
1019 ((or (string-equal "top" level
)
1020 (string-equal "chapter" level
))
1022 (goto-char (point-min))
1023 (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
)
1030 "\\(^@node\\).*\n" ; match node line
1031 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1033 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
1035 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
1040 (defun texinfo-update-menu-region-end (level)
1041 "Locate end of higher level section this section is within.
1042 Return position; do not move point. Thus, if this level is a
1043 subsection, find the node for the section this subsection is within.
1044 If level is top or chapter, returns end of file. Only argument is a
1045 string of the general type of section."
1046 (let ((case-fold-search t
))
1048 (if (re-search-forward
1050 "\\(^@node\\).*\n" ; match node line
1051 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1053 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
1055 ;; Never finds end of level above chapter so goes to end.
1056 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
1062 (defun texinfo-menu-first-node (beginning end
)
1063 "Locate first node of the section the menu will be placed in.
1064 Return position; do not move point.
1065 The menu will be located just before this position.
1067 First argument is the position of the beginning of the section in
1068 which the menu will be located; second argument is the position of the
1069 end of that region; it limits the search."
1072 (goto-char beginning
)
1074 (re-search-forward "^@node" end t
)
1079 ;;; Alists and regular expressions for defining hierarchical levels
1081 (defvar texinfo-section-to-generic-alist
1084 ("chapter" .
"chapter")
1085 ("unnumbered" .
"chapter")
1086 ("majorheading" .
"chapter")
1087 ("chapheading" .
"chapter")
1088 ("appendix" .
"chapter")
1090 ("section" .
"section")
1091 ("unnumberedsec" .
"section")
1092 ("heading" .
"section")
1093 ("appendixsec" .
"section")
1095 ("subsection" .
"subsection")
1096 ("unnumberedsubsec" .
"subsection")
1097 ("subheading" .
"subsection")
1098 ("appendixsubsec" .
"subsection")
1100 ("subsubsection" .
"subsubsection")
1101 ("unnumberedsubsubsec" .
"subsubsection")
1102 ("subsubheading" .
"subsubsection")
1103 ("appendixsubsubsec" .
"subsubsection"))
1104 "*An alist of specific and corresponding generic Texinfo section types.
1105 The keys are strings specifying specific types of section; the values
1106 are strings of their corresponding general types.")
1108 ;; We used to look for just sub, but that found @subtitle.
1109 (defvar texinfo-section-types-regexp
1110 "^@\\(chapter \\|sect\\|subs\\|subh\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
1111 "Regexp matching chapter, section, other headings (but not the top node).")
1113 (defvar texinfo-chapter-level-regexp
1114 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
1115 "Regular expression matching just the Texinfo chapter level headings.")
1117 (defvar texinfo-section-level-regexp
1118 "section\\|unnumberedsec\\|heading \\|appendixsec"
1119 "Regular expression matching just the Texinfo section level headings.")
1121 (defvar texinfo-subsection-level-regexp
1122 "subsection\\|unnumberedsubsec\\|subheading\\|appendixsubsec"
1123 "Regular expression matching just the Texinfo subsection level headings.")
1125 (defvar texinfo-subsubsection-level-regexp
1126 "subsubsection\\|unnumberedsubsubsec\\|subsubheading\\|appendixsubsubsec"
1127 "Regular expression matching just the Texinfo subsubsection level headings.")
1129 (defvar texinfo-update-menu-same-level-regexps
1130 '(("top" .
"top[ \t]+")
1132 (concat "\\(^@\\)\\(" texinfo-chapter-level-regexp
"\\)[ \t]*"))
1134 (concat "\\(^@\\)\\(" texinfo-section-level-regexp
"\\)[ \t]*"))
1136 (concat "\\(^@\\)\\(" texinfo-subsection-level-regexp
"\\)[ \t]+"))
1138 (concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp
"\\)[ \t]+")))
1139 "*Regexps for searching for same level sections in a Texinfo file.
1140 The keys are strings specifying the general hierarchical level in the
1141 document; the values are regular expressions.")
1143 (defvar texinfo-update-menu-higher-regexps
1144 '(("top" .
"^@node [ \t]*DIR")
1145 ("chapter" .
"^@node [ \t]*top[ \t]*\\(,\\|$\\)")
1149 texinfo-chapter-level-regexp
1154 texinfo-section-level-regexp
1156 texinfo-chapter-level-regexp
1161 texinfo-subsection-level-regexp
1163 texinfo-section-level-regexp
1165 texinfo-chapter-level-regexp
1167 "*Regexps for searching for higher level sections in a Texinfo file.
1168 The keys are strings specifying the general hierarchical level in the
1169 document; the values are regular expressions.")
1171 (defvar texinfo-update-menu-lower-regexps
1175 texinfo-chapter-level-regexp
1177 texinfo-section-level-regexp
1179 texinfo-subsection-level-regexp
1181 texinfo-subsubsection-level-regexp
1186 texinfo-section-level-regexp
1188 texinfo-subsection-level-regexp
1190 texinfo-subsubsection-level-regexp
1195 texinfo-subsection-level-regexp
1197 texinfo-subsubsection-level-regexp
1202 texinfo-subsubsection-level-regexp
1204 ("subsubsection" .
"nothing lower"))
1205 "*Regexps for searching for lower level sections in a Texinfo file.
1206 The keys are strings specifying the general hierarchical level in the
1207 document; the values are regular expressions.")
1213 (defun texinfo-update-node (&optional beginning end
)
1214 "Without any prefix argument, update the node in which point is located.
1215 Interactively, a prefix argument means to operate on the region.
1217 The functions for creating or updating nodes and menus, and their
1220 texinfo-update-node (&optional beginning end) \\[texinfo-update-node]
1221 texinfo-every-node-update () \\[texinfo-every-node-update]
1222 texinfo-sequential-node-update (&optional region-p)
1224 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
1225 texinfo-all-menus-update () \\[texinfo-all-menus-update]
1226 texinfo-master-menu ()
1228 texinfo-indent-menu-description (column &optional region-p)
1230 The `texinfo-column-for-description' variable specifies the column to
1231 which menu descriptions are indented. Its default value is 32."
1235 (list (point) (mark))))
1236 (if (null beginning
)
1237 ;; Update a single node.
1238 (let ((auto-fill-function nil
) (auto-fill-hook nil
))
1239 (if (not (re-search-backward "^@node" (point-min) t
))
1240 (error "Node line not found before this position"))
1241 (texinfo-update-the-node)
1242 (message "Done...updated the node. You may save the buffer."))
1244 (let ((auto-fill-function nil
)
1245 (auto-fill-hook nil
))
1248 (narrow-to-region beginning end
)
1249 (goto-char (point-min))
1250 (while (re-search-forward "^@node" (point-max) t
)
1252 (texinfo-update-the-node))
1253 (goto-char (point-max))
1254 (message "Done...nodes updated in region. You may save the buffer."))))))
1257 (defun texinfo-every-node-update ()
1258 "Update every node in a Texinfo file."
1261 (texinfo-update-node (point-min) (point-max))
1262 (message "Done...updated every node. You may save the buffer.")))
1264 (defun texinfo-update-the-node ()
1265 "Update one node. Point must be at the beginning of node line.
1266 Leave point at the end of the node line."
1267 (texinfo-check-for-node-name)
1268 (texinfo-delete-existing-pointers)
1269 (message "Updating node: %s ... " (texinfo-copy-node-name))
1273 ((case-fold-search t
)
1274 (level (texinfo-hierarchic-level))
1275 (beginning (texinfo-update-menu-region-beginning level
))
1276 (end (texinfo-update-menu-region-end level
)))
1277 (if (string-equal level
"top")
1278 (texinfo-top-pointer-case)
1280 (texinfo-insert-pointer beginning end level
'next
)
1281 (texinfo-insert-pointer beginning end level
'previous
)
1282 (texinfo-insert-pointer beginning end level
'up
)
1283 (texinfo-clean-up-node-line)))))
1285 (defun texinfo-top-pointer-case ()
1286 "Insert pointers in the Top node. This is a special case.
1288 The `Next' pointer is a pointer to a chapter or section at a lower
1289 hierarchical level in the file. The `Previous' and `Up' pointers are
1290 to `(dir)'. Point must be at the beginning of the node line, and is
1291 left at the end of the node line."
1293 (texinfo-clean-up-node-line)
1296 ;; There may be an @chapter or other such command between
1297 ;; the top node line and the next node line, as a title
1298 ;; for an `ifinfo' section. This @chapter command must
1299 ;; must be skipped. So the procedure is to search for
1300 ;; the next `@node' line, and then copy its name.
1301 (if (re-search-forward "^@node" nil t
)
1304 (texinfo-copy-node-name))
1308 (defun texinfo-check-for-node-name ()
1309 "Determine whether the node has a node name. Prompt for one if not.
1310 Point must be at beginning of node line. Does not move point."
1312 (let ((initial (texinfo-copy-next-section-title)))
1313 ;; This is not clean. Use `interactive' to read the arg.
1314 (forward-word 1) ; skip over node command
1315 (skip-chars-forward " \t") ; and over spaces
1316 (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what Info looks for
1317 ; alternatively, use "[a-zA-Z]+"
1319 (read-from-minibuffer
1320 "Node name (use no @, commas, colons, or apostrophes): "
1322 (insert " " node-name
))))))
1324 (defun texinfo-delete-existing-pointers ()
1325 "Delete `Next', `Previous', and `Up' pointers.
1326 Starts from the current position of the cursor, and searches forward
1327 on the line for a comma and if one is found, deletes the rest of the
1328 line, including the comma. Leaves point at beginning of line."
1329 (let ((eol-point (save-excursion (end-of-line) (point))))
1330 (if (search-forward "," eol-point t
)
1331 (delete-region (1- (point)) eol-point
)))
1332 (beginning-of-line))
1334 (defun texinfo-find-pointer (beginning end level direction
)
1335 "Move point to section associated with next, previous, or up pointer.
1336 Return type of pointer (either 'normal or 'no-pointer).
1338 The first and second arguments bound the search for a pointer to the
1339 beginning and end, respectively, of the enclosing higher level
1340 section. The third argument is a string specifying the general kind
1341 of section such as \"chapter\" or \"section\". When looking for the
1342 `Next' pointer, the section found will be at the same hierarchical
1343 level in the Texinfo file; when looking for the `Previous' pointer,
1344 the section found will be at the same or higher hierarchical level in
1345 the Texinfo file; when looking for the `Up' pointer, the section found
1346 will be at some level higher in the Texinfo file. The fourth argument
1347 \(one of 'next, 'previous, or 'up\) specifies whether to find the
1348 `Next', `Previous', or `Up' pointer."
1349 (let ((case-fold-search t
))
1350 (cond ((eq direction
'next
)
1351 (forward-line 3) ; skip over current node
1352 ;; Search for section commands accompanied by node lines;
1353 ;; ignore section commands in the middle of nodes.
1354 (if (re-search-forward
1355 ;; A `Top' node is never a next pointer, so won't find it.
1359 ;; Match comment or ifinfo line, if any
1360 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1362 (cdr (assoc level texinfo-update-menu-same-level-regexps
))))
1367 ((eq direction
'previous
)
1368 (if (re-search-backward
1373 ;; Match comment or ifinfo line, if any
1374 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1376 (cdr (assoc level texinfo-update-menu-same-level-regexps
)))
1380 ;; Match comment or ifinfo line, if any
1381 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1383 (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1385 ;; Handle `Top' node specially.
1386 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1393 (if (re-search-backward
1398 ;; Match comment or ifinfo line, if any
1399 "\\(\\(\\(^@c\\).*\n\\)\\|\\(^@ifinfo[ ]*\n\\)\\)?"
1400 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1402 ;; Handle `Top' node specially.
1403 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1406 (goto-char beginning
)
1413 (error "texinfo-find-pointer: lack proper arguments")))))
1415 (defun texinfo-pointer-name (kind)
1416 "Return the node name preceding the section command.
1417 The argument is the kind of section, either normal or no-pointer."
1419 (cond ((eq kind
'normal
)
1420 (end-of-line) ; this handles prev node top case
1421 (re-search-backward ; when point is already
1422 "^@node" ; at the beginning of @node line
1423 (save-excursion (forward-line -
3))
1425 (setq name
(texinfo-copy-node-name)))
1426 ((eq kind
'no-pointer
)
1427 (setq name
" "))) ; put a blank in the pointer slot
1430 (defun texinfo-insert-pointer (beginning end level direction
)
1431 "Insert the `Next', `Previous' or `Up' node name at point.
1434 The first and second arguments bound the search for a pointer to the
1435 beginning and end, respectively, of the enclosing higher level
1436 section. The third argument is the hierarchical level of the Texinfo
1437 file, a string such as \"section\". The fourth argument is direction
1438 towards which the pointer is directed, one of `next, `previous, or
1445 (texinfo-pointer-name
1446 (texinfo-find-pointer beginning end level direction
)))))
1448 (defun texinfo-clean-up-node-line ()
1449 "Remove extra commas, if any, at end of node line."
1451 (skip-chars-backward ", ")
1452 (delete-region (point) (save-excursion (end-of-line) (point))))
1455 ;;; Updating nodes sequentially
1456 ; These sequential update functions insert `Next' or `Previous'
1457 ; pointers that point to the following or preceding nodes even if they
1458 ; are at higher or lower hierarchical levels. This means that if a
1459 ; section contains one or more subsections, the section's `Next'
1460 ; pointer will point to the subsection and not the following section.
1461 ; (The subsection to which `Next' points will most likely be the first
1462 ; item on the section's menu.)
1465 (defun texinfo-sequential-node-update (&optional region-p
)
1466 "Update one node (or many) in a Texinfo file with sequential pointers.
1468 This function causes the `Next' or `Previous' pointer to point to the
1469 immediately preceding or following node, even if it is at a higher or
1470 lower hierarchical level in the document. Continually pressing `n' or
1471 `p' takes you straight through the file.
1473 Without any prefix argument, update the node in which point is located.
1474 Non-nil argument (prefix, if interactive) means update the nodes in the
1477 This command makes it awkward to navigate among sections and
1478 subsections; it should be used only for those documents that are meant
1479 to be read like a novel rather than a reference, and for which the
1480 Info `g*' command is inadequate."
1484 ;; update a single node
1485 (let ((auto-fill-function nil
) (auto-fill-hook nil
))
1486 (if (not (re-search-backward "^@node" (point-min) t
))
1487 (error "Node line not found before this position."))
1488 (texinfo-sequentially-update-the-node)
1490 "Done...sequentially updated the node . You may save the buffer."))
1492 (let ((auto-fill-function nil
)
1493 (auto-fill-hook nil
)
1494 (beginning (region-beginning))
1496 (if (= end beginning
)
1497 (error "Please mark a region!"))
1499 (narrow-to-region beginning end
)
1500 (goto-char beginning
)
1501 (push-mark (point) t
)
1502 (while (re-search-forward "^@node" (point-max) t
)
1504 (texinfo-sequentially-update-the-node))
1506 "Done...updated the nodes in sequence. You may save the buffer.")))))
1508 (defun texinfo-sequentially-update-the-node ()
1509 "Update one node such that the pointers are sequential.
1510 A `Next' or `Previous' pointer points to any preceding or following node,
1511 regardless of its hierarchical level."
1513 (texinfo-check-for-node-name)
1514 (texinfo-delete-existing-pointers)
1516 "Sequentially updating node: %s ... " (texinfo-copy-node-name))
1520 ((case-fold-search t
)
1521 (level (texinfo-hierarchic-level)))
1522 (if (string-equal level
"top")
1523 (texinfo-top-pointer-case)
1525 (texinfo-sequentially-insert-pointer level
'next
)
1526 (texinfo-sequentially-insert-pointer level
'previous
)
1527 (texinfo-sequentially-insert-pointer level
'up
)
1528 (texinfo-clean-up-node-line)))))
1530 (defun texinfo-sequentially-find-pointer (level direction
)
1531 "Find next or previous pointer sequentially in Texinfo file, or up pointer.
1532 Move point to section associated with the pointer. Find point even if
1533 it is in a different section.
1535 Return type of pointer (either 'normal or 'no-pointer).
1537 The first argument is a string specifying the general kind of section
1538 such as \"chapter\" or \"section\". The section found will be at the
1539 same hierarchical level in the Texinfo file, or, in the case of the up
1540 pointer, some level higher. The second argument (one of 'next,
1541 'previous, or 'up) specifies whether to find the `Next', `Previous',
1543 (let ((case-fold-search t
))
1544 (cond ((eq direction
'next
)
1545 (forward-line 3) ; skip over current node
1546 (if (re-search-forward
1547 texinfo-section-types-regexp
1552 ((eq direction
'previous
)
1553 (if (re-search-backward
1554 texinfo-section-types-regexp
1560 (if (re-search-backward
1561 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1567 (error "texinfo-sequential-find-pointer: lack proper arguments")))))
1569 (defun texinfo-sequentially-insert-pointer (level direction
)
1570 "Insert the `Next', `Previous' or `Up' node name at point.
1573 The first argument is the hierarchical level of the Texinfo file, a
1574 string such as \"section\". The second argument is direction, one of
1575 `next, `previous, or 'up."
1581 (texinfo-pointer-name
1582 (texinfo-sequentially-find-pointer level direction
)))))
1585 ;;; Inserting `@node' lines
1586 ; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
1587 ; before the `@chapter', `@section', and such like lines of a region
1588 ; in a Texinfo file.
1590 (defun texinfo-insert-node-lines (beginning end
&optional title-p
)
1591 "Insert missing `@node' lines in region of Texinfo file.
1592 Non-nil argument (prefix, if interactive) means also to insert the
1593 section titles as node names; and also to insert the section titles as
1594 node names in pre-existing @node lines that lack names."
1595 (interactive "r\nP")
1597 ;; Use marker; after inserting node lines, leave point at end of
1598 ;; region and mark at beginning.
1600 (let (beginning-marker end-marker title last-section-position
)
1602 ;; Save current position on mark ring and set mark to end.
1604 (setq end-marker
(mark-marker))
1606 (goto-char beginning
)
1607 (while (re-search-forward
1608 texinfo-section-types-regexp
1611 ;; Copy title if desired.
1616 (skip-chars-forward " \t")
1617 (setq title
(buffer-substring
1619 (save-excursion (end-of-line) (point))))))
1620 ;; Insert node line if necessary.
1621 (if (re-search-backward
1623 ;; Avoid finding previous node line if node lines are close.
1624 (or last-section-position
1625 (save-excursion (forward-line -
2) (point))) t
)
1626 ;; @node is present, and point at beginning of that line
1627 (forward-word 1) ; Leave point just after @node.
1628 ;; Else @node missing; insert one.
1629 (beginning-of-line) ; Beginning of `@section' line.
1631 (backward-char 1)) ; Leave point just after `@node'.
1632 ;; Insert title if desired.
1635 (skip-chars-forward " \t")
1636 ;; Use regexp based on what info looks for
1637 ;; (alternatively, use "[a-zA-Z]+");
1638 ;; this means we only insert a title if none exists.
1639 (if (not (looking-at "[^,\t\n ]+"))
1644 (message "Inserted title %s ... " title
)))))
1645 ;; Go forward beyond current section title.
1646 (re-search-forward texinfo-section-types-regexp
1647 (save-excursion (forward-line 3) (point)) t
)
1648 (setq last-section-position
(point))
1651 ;; Leave point at end of region, mark at beginning.
1652 (set-mark beginning
)
1656 "Done inserting node lines and titles. You may save the buffer.")
1657 (message "Done inserting node lines. You may save the buffer."))))
1660 ;;; Update and create menus for multi-file Texinfo sources
1662 ;; 1. M-x texinfo-multiple-files-update
1664 ;; Read the include file list of an outer Texinfo file and
1665 ;; update all highest level nodes in the files listed and insert a
1666 ;; main menu in the outer file after its top node.
1668 ;; 2. C-u M-x texinfo-multiple-files-update
1670 ;; Same as 1, but insert a master menu. (Saves reupdating lower
1671 ;; level menus and nodes.) This command simply reads every menu,
1672 ;; so if the menus are wrong, the master menu will be wrong.
1673 ;; Similarly, if the lower level node pointers are wrong, they
1676 ;; 3. C-u 2 M-x texinfo-multiple-files-update
1678 ;; Read the include file list of an outer Texinfo file and
1679 ;; update all nodes and menus in the files listed and insert a
1680 ;; master menu in the outer file after its top node.
1682 ;;; Note: these functions:
1684 ;;; * Do not save or delete any buffers. You may fill up your memory.
1685 ;;; * Do not handle any pre-existing nodes in outer file.
1686 ;;; Hence, you may need a file for indices.
1689 ;;; Auxiliary functions for multiple file updating
1691 (defun texinfo-multi-file-included-list (outer-file)
1692 "Return a list of the included files in OUTER-FILE."
1693 (let ((included-file-list (list outer-file
))
1696 (switch-to-buffer (find-file-noselect outer-file
))
1698 (goto-char (point-min))
1699 (while (re-search-forward "^@include" nil t
)
1700 (skip-chars-forward " \t")
1701 (setq start
(point))
1703 (skip-chars-backward " \t")
1704 (setq included-file-list
1705 (cons (buffer-substring start
(point))
1706 included-file-list
)))
1707 (nreverse included-file-list
))))
1709 (defun texinfo-copy-next-section-title ()
1710 "Return the name of the immediately following section as a string.
1712 Start with point at the beginning of the node line. Leave point at the
1713 same place. If there is no title, returns an empty string."
1719 (if (re-search-forward "\\(^@node\\)" nil t
)
1720 (match-beginning 0)))
1722 (if (re-search-forward texinfo-section-types-regexp node-end t
)
1728 (progn (forward-word 1) ; skip over section type
1729 (skip-chars-forward " \t") ; and over spaces
1731 (progn (end-of-line) (point)))))
1735 (defun texinfo-multi-file-update (files &optional update-everything
)
1736 "Update first node pointers in each file in FILES.
1737 Return a list of the node names.
1739 The first file in the list is an outer file; the remaining are
1740 files included in the outer file with `@include' commands.
1742 If optional arg UPDATE-EVERYTHING non-nil, update every menu and
1743 pointer in each of the included files.
1745 Also update the `Top' level node pointers of the outer file.
1749 * the first file in the FILES list must be the outer file,
1750 * each of the included files must contain exactly one highest
1751 hierarchical level node,
1752 * this node must be the first node in the included file,
1753 * each highest hierarchical level node must be of the same type.
1755 Thus, normally, each included file contains one, and only one,
1758 ; The menu-list has the form:
1760 ; \(\(\"node-name1\" . \"title1\"\)
1761 ; \(\"node-name2\" . \"title2\"\) ... \)
1763 ; However, there does not need to be a title field and this function
1764 ; does not fill it; however a comment tells you how to do so.
1765 ; You would use the title field if you wanted to insert titles in the
1766 ; description slot of a menu as a description.
1768 (let ((case-fold-search t
)
1771 ;; Find the name of the first node of the first included file.
1772 (switch-to-buffer (find-file-noselect (car (cdr files
))))
1774 (goto-char (point-min))
1775 (if (not (re-search-forward "^@node" nil t
))
1776 (error "No `@node' line found in %s !" (buffer-name)))
1778 (texinfo-check-for-node-name)
1779 (setq next-node-name
(texinfo-copy-node-name))
1784 (prog1 "" (forward-line 1)))
1785 ;; Use following to insert section titles automatically.
1786 ;; (texinfo-copy-next-section-title)
1790 (switch-to-buffer (find-file-noselect (car files
)))
1791 (goto-char (point-min))
1792 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
1793 (error "This buffer needs a Top node!"))
1795 (texinfo-delete-existing-pointers)
1797 (insert ", " next-node-name
", (dir), (dir)")
1799 (setq previous-node-name
"Top")
1800 (setq files
(cdr files
))
1804 (if (not (cdr files
))
1806 (setq next-node-name
"")
1808 ;; find the name of the first node in the next file.
1809 (switch-to-buffer (find-file-noselect (car (cdr files
))))
1811 (goto-char (point-min))
1812 (if (not (re-search-forward "^@node" nil t
))
1813 (error "No `@node' line found in %s !" (buffer-name)))
1815 (texinfo-check-for-node-name)
1816 (setq next-node-name
(texinfo-copy-node-name))
1820 (prog1 "" (forward-line 1)))
1821 ;; Use following to insert section titles automatically.
1822 ;; (texinfo-copy-next-section-title)
1825 ;; Go to node to be updated.
1826 (switch-to-buffer (find-file-noselect (car files
)))
1827 (goto-char (point-min))
1828 (if (not (re-search-forward "^@node" nil t
))
1829 (error "No `@node' line found in %s !" (buffer-name)))
1832 ;; Update other menus and nodes if requested.
1833 (if update-everything
(texinfo-all-menus-update t
))
1836 (texinfo-delete-existing-pointers)
1838 (insert ", " next-node-name
", " previous-node-name
", " up-node-name
)
1841 (setq previous-node-name
(texinfo-copy-node-name))
1843 (setq files
(cdr files
)))
1844 (nreverse menu-list
)))
1846 (defun texinfo-multi-files-insert-main-menu (menu-list)
1847 "Insert formatted main menu at point.
1848 Indents the first line of the description, if any, to the value of
1849 texinfo-column-for-description."
1853 ;; Every menu entry starts with a star and a space.
1856 ;; Insert the node name (and menu entry name, if present).
1857 (let ((node-part (car (car menu-list
))))
1858 (if (stringp node-part
)
1859 ;; "Double colon" entry line; menu entry and node name are the same,
1860 (insert (format "%s::" node-part
))
1861 ;; "Single colon" entry line; menu entry and node name are different.
1862 (insert (format "%s: %s." (car node-part
) (cdr node-part
)))))
1864 ;; Insert the description, if present.
1865 (if (cdr (car menu-list
))
1867 ;; Move to right place.
1868 (indent-to texinfo-column-for-description
2)
1869 ;; Insert description.
1870 (insert (format "%s" (cdr (car menu-list
))))))
1872 (insert "\n") ; end this menu entry
1873 (setq menu-list
(cdr menu-list
)))
1874 (insert "@end menu"))
1876 (defun texinfo-multi-file-master-menu-list (files-list)
1877 "Return master menu list from files in FILES-LIST.
1878 Menu entries in each file collected using `texinfo-master-menu-list'.
1880 The first file in FILES-LIST must be the outer file; the others must
1881 be the files included within it. A main menu must already exist."
1883 (let (master-menu-list)
1885 (switch-to-buffer (find-file-noselect (car files-list
)))
1886 (message "Working on: %s " (current-buffer))
1887 (goto-char (point-min))
1888 (setq master-menu-list
1889 (append master-menu-list
(texinfo-master-menu-list)))
1890 (setq files-list
(cdr files-list
)))
1894 ;;; The multiple-file update function
1896 (defun texinfo-multiple-files-update
1897 (outer-file &optional update-everything make-master-menu
)
1898 "Update first node pointers in each file included in OUTER-FILE;
1899 create or update the `Top' level node pointers and the main menu in
1900 the outer file that refers to such nodes. This does not create or
1901 update menus or pointers within the included files.
1903 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
1904 insert a master menu in OUTER-FILE in addition to creating or updating
1905 pointers in the first @node line in each included file and creating or
1906 updating the `Top' level node pointers of the outer file. This does
1907 not create or update other menus and pointers within the included
1910 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
1911 interactive), update all the menus and all the `Next', `Previous', and
1912 `Up' pointers of all the files included in OUTER-FILE before inserting
1913 a master menu in OUTER-FILE. Also, update the `Top' level node
1914 pointers of OUTER-FILE.
1918 * this command does NOT save any files--you must save the
1919 outer file and any modified, included files.
1921 * except for the `Top' node, this command does NOT handle any
1922 pre-existing nodes in the outer file; hence, indices must be
1923 enclosed in an included file.
1927 * each of the included files must contain exactly one highest
1928 hierarchical level node,
1929 * this highest node must be the first node in the included file,
1930 * each highest hierarchical level node must be of the same type.
1932 Thus, normally, each included file contains one, and only one,
1937 "Name of outer `include' file: "
1939 (cond ((not current-prefix-arg
)
1941 ((listp current-prefix-arg
)
1942 '(t nil
)) ; make-master-menu
1943 ((numberp current-prefix-arg
)
1944 '(t t
)) ; update-everything
1947 (let* ((included-file-list (texinfo-multi-file-included-list outer-file
))
1948 (files included-file-list
)
1952 (up-node-name "Top"))
1954 ;;; Update the pointers
1955 ;;; and collect the names of the nodes and titles
1956 (setq main-menu-list
(texinfo-multi-file-update files update-everything
))
1958 ;;; Insert main menu
1961 (switch-to-buffer (find-file-noselect (car included-file-list
)))
1962 (if (texinfo-old-menu-p
1965 (re-search-forward "^@include")
1969 ;; If found, leave point after word `menu' on the `@menu' line.
1971 (texinfo-incorporate-descriptions main-menu-list
)
1972 ;; Delete existing menu.
1976 (save-excursion (re-search-forward "^@end menu") (point)))
1978 (texinfo-multi-files-insert-main-menu main-menu-list
))
1980 ;; Else no current menu; insert it before `@include'
1981 (texinfo-multi-files-insert-main-menu main-menu-list
))
1983 ;;; Insert master menu
1985 (if make-master-menu
1987 ;; First, removing detailed part of any pre-existing master menu
1988 (goto-char (point-min))
1989 (if (re-search-forward texinfo-master-menu-header nil t
)
1990 ;; Remove detailed master menu listing
1992 (goto-char (match-beginning 0))
1993 (let ((end-of-detailed-menu-descriptions
1994 (save-excursion ; beginning of end menu line
1995 (goto-char (texinfo-menu-end))
1996 (beginning-of-line) (forward-char -
1)
1998 (delete-region (point) end-of-detailed-menu-descriptions
))))
2000 ;; Create a master menu and insert it
2001 (texinfo-insert-master-menu-list
2002 (texinfo-multi-file-master-menu-list
2003 included-file-list
)))))
2005 ;; Remove unwanted extra lines.
2007 (goto-char (point-min))
2009 (re-search-forward "^@menu")
2011 (insert "\n") ; Ensure at least one blank line.
2012 (delete-blank-lines)
2014 (re-search-forward "^@end menu")
2016 (insert "\n") ; Ensure at least one blank line.
2017 (delete-blank-lines))
2019 (message "Multiple files updated."))
2022 ;;; Place `provide' at end of file.
2023 (provide 'texnfo-upd
)
2025 ;;; texnfo-upd.el ends here