1 ;;; texnfo-upd.el --- utilities for updating nodes and menus in Texinfo files
3 ;; Copyright (C) 1989, 1990, 1991, 1992, 2001 Free Software Foundation, Inc.
5 ;; Author: Robert J. Chassell
6 ;; Maintainer: bug-texinfo@gnu.org
7 ;; Keywords: maint, tex, docs
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
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.
155 (defvar texinfo-master-menu-header
156 " --- The Detailed Node Listing ---\n"
157 "String inserted before lower level entries in Texinfo master menu.
158 It comes after the chapter-level menu entries.")
160 (defun texinfo-make-menu (&optional beginning end
)
161 "Without any prefix argument, make or update a menu.
162 Make the menu for the section enclosing the node found following point.
164 A prefix argument means make or update menus
165 for nodes within or part of the marked region.
167 Whenever a menu exists, and is being updated, the descriptions that
168 are associated with node names in the pre-existing menu are
169 incorporated into the new menu. Otherwise, the nodes' section titles
170 are inserted as descriptions."
174 (list (point) (mark))))
176 (let ((level (texinfo-hierarchic-level)))
177 (texinfo-make-one-menu level
)
178 (message "Menu updated"))
180 (message "Making or updating menus in %s... " (buffer-name))
182 (goto-char (min beginning end
))
183 ;; find section type following point
184 (let ((level (texinfo-hierarchic-level))
185 (region-end-marker (make-marker)))
186 (set-marker region-end-marker
(max beginning end
))
190 (while (texinfo-find-lower-level-node
191 level
(marker-position region-end-marker
))
192 (setq level
(texinfo-hierarchic-level)) ; new, lower level
193 (texinfo-make-one-menu level
))
195 (while (and (< (point) (marker-position region-end-marker
))
196 (texinfo-find-higher-level-node
197 level
(marker-position region-end-marker
)))
198 (setq level
(texinfo-hierarchic-level))
199 ;; Don't allow texinfo-find-higher-level-node
200 ;; to find the same node again.
202 (while (texinfo-find-lower-level-node
203 level
(marker-position region-end-marker
))
204 (setq level
(texinfo-hierarchic-level)) ; new, lower level
205 (texinfo-make-one-menu level
))))))
206 (message "Making or updating menus in %s...done" (buffer-name))))
208 (defun texinfo-make-one-menu (level)
209 "Make a menu of all the appropriate nodes in this section.
210 `Appropriate nodes' are those associated with sections that are
211 at the level specified by LEVEL. Point is left at the end of menu."
213 ((case-fold-search t
)
216 (goto-char (texinfo-update-menu-region-beginning level
))
219 (end (texinfo-update-menu-region-end level
))
220 (first (texinfo-menu-first-node beginning end
))
222 (goto-char beginning
)
224 (texinfo-copy-node-name)))
225 (new-menu-list (texinfo-make-menu-list beginning end level
)))
226 (if (texinfo-old-menu-p beginning first
)
228 (texinfo-incorporate-descriptions new-menu-list
)
229 (texinfo-incorporate-menu-entry-names new-menu-list
)
230 (texinfo-delete-old-menu beginning first
)))
231 (texinfo-insert-menu new-menu-list node-name
)))
233 (defun texinfo-all-menus-update (&optional update-all-nodes-p
)
234 "Update every regular menu in a Texinfo file.
235 Update pre-existing master menu, if there is one.
237 If called with a non-nil argument, this function first updates all the
238 nodes in the buffer before updating the menus."
240 (let ((case-fold-search t
)
243 (push-mark (point-max) t
)
244 (goto-char (point-min))
245 (message "Checking for a master menu in %s ... "(buffer-name))
247 (if (search-forward texinfo-master-menu-header nil t
)
249 ;; Check if @detailmenu kludge is used;
250 ;; if so, leave point before @detailmenu.
251 (search-backward "\n@detailmenu"
252 (save-excursion (forward-line -
3) (point))
254 ;; Remove detailed master menu listing
255 (setq master-menu-p t
)
256 (goto-char (match-beginning 0))
257 (let ((end-of-detailed-menu-descriptions
258 (save-excursion ; beginning of end menu line
259 (goto-char (texinfo-menu-end))
260 (beginning-of-line) (forward-char -
1)
262 (delete-region (point) end-of-detailed-menu-descriptions
)))))
264 (if update-all-nodes-p
266 (message "Updating all nodes in %s ... " (buffer-name))
267 (texinfo-update-node (point-min) (point-max))))
269 (message "Updating all menus in %s ... " (buffer-name))
270 (texinfo-make-menu (point-max) (point-min))
274 (message "Updating the master menu in %s... " (buffer-name))
275 (texinfo-master-menu nil
))))
277 (message "Done...updated all the menus. You may save the buffer.")))
279 (defun texinfo-find-lower-level-node (level region-end
)
280 "Search forward from point for node at any level lower than LEVEL.
281 Search is limited to the end of the marked region, REGION-END,
282 and to the end of the menu region for the level.
284 Return t if the node is found, else nil. Leave point at the beginning
285 of the node if one is found; else do not move point."
286 (let ((case-fold-search t
))
287 (if (and (< (point) region-end
)
290 "\\(^@node\\).*\n" ; match node line
291 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
293 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
295 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
296 "\\)?" ; end of expression
297 (eval (cdr (assoc level texinfo-update-menu-lower-regexps
))))
298 ;; the next higher level node marks the end of this
299 ;; section, and no lower level node will be found beyond
300 ;; this position even if region-end is farther off
301 (texinfo-update-menu-region-end level
)
303 (goto-char (match-beginning 1)))))
305 (defun texinfo-find-higher-level-node (level region-end
)
306 "Search forward from point for node at any higher level than argument LEVEL.
307 Search is limited to the end of the marked region, REGION-END.
309 Return t if the node is found, else nil. Leave point at the beginning
310 of the node if one is found; else do not move point.
312 A `@node' line starting at point does count as a match;
313 if the match is found there, the value is t and point does not move."
315 (let ((case-fold-search t
))
318 (if (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" region-end t
)
319 (progn (beginning-of-line) t
)))
321 (if (re-search-forward
323 "\\(^@node\\).*\n" ; match node line
324 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
326 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
328 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
329 "\\)?" ; end of expression
330 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
))))
332 (progn (beginning-of-line) t
))))))
335 ;;; Making the list of new menu entries
337 (defun texinfo-make-menu-list (beginning end level
)
338 "Make a list of node names and their descriptions.
339 Point is left at the end of the menu region, but the menu is not inserted.
341 First argument is position from which to start making menu list;
342 second argument is end of region in which to try to locate entries;
343 third argument is the level of the nodes that are the entries.
345 Node names and descriptions are dotted pairs of strings. Each pair is
346 an element of the list. If the description does not exist, the
347 element consists only of the node name."
348 (goto-char beginning
)
350 (while (texinfo-menu-locate-entry-p level end
)
353 (texinfo-copy-node-name)
354 (prog1 "" (forward-line 1)))
355 ;; Use following to insert section titles automatically.
356 ;; (texinfo-copy-section-title))
358 (reverse new-menu-list
)))
360 (defun texinfo-menu-locate-entry-p (level search-end
)
361 "Find a node that will be part of menu for this section.
362 First argument is a string such as \"section\" specifying the general
363 hierarchical level of the menu; second argument is a position
364 specifying the end of the search.
366 The function returns t if the node is found, else nil. It searches
367 forward from point, and leaves point at the beginning of the node.
369 The function finds entries of the same type. Thus `subsections' and
370 `unnumberedsubsecs' will appear in the same menu."
371 (let ((case-fold-search t
))
372 (if (re-search-forward
374 "\\(^@node\\).*\n" ; match node line
375 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
377 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
379 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
380 "\\)?" ; end of expression
382 (cdr (assoc level texinfo-update-menu-same-level-regexps
))))
385 (goto-char (match-beginning 1)))))
387 (defun texinfo-copy-node-name ()
388 "Return the node name as a string.
390 Start with point at the beginning of the node line; copy the text
391 after the node command up to the first comma on the line, if any, and
392 return the text as a string. Leaves point at the beginning of the
393 line. If there is no node name, returns an empty string."
397 (progn (forward-word 1) ; skip over node command
398 (skip-chars-forward " \t") ; and over spaces
402 (save-excursion (end-of-line) (point)) t
) ; bound search
404 (end-of-line) (point)))))
406 (defun texinfo-copy-section-title ()
407 "Return the title of the section as a string.
408 The title is used as a description line in the menu when one does not
411 Move point to the beginning of the appropriate section line by going
412 to the start of the text matched by last regexp searched for, which
413 must have been done by `texinfo-menu-locate-entry-p'."
415 ;; could use the same re-search as in `texinfo-menu-locate-entry-p'
416 ;; instead of using `match-beginning'; such a variation would be
417 ;; more general, but would waste information already collected
419 (goto-char (match-beginning 7)) ; match section name
422 (progn (forward-word 1) ; skip over section type
423 (skip-chars-forward " \t") ; and over spaces
425 (progn (end-of-line) (point))))
428 ;;; Handling the old menu
430 (defun texinfo-old-menu-p (beginning first
)
431 "Move point to the beginning of the menu for this section, if any.
432 Otherwise move point to the end of the first node of this section.
433 Return t if a menu is found, nil otherwise.
435 First argument is the position of the beginning of the section in which
436 the menu will be located; second argument is the position of the first
437 node within the section.
439 If no menu is found, the function inserts two newlines just before the
440 end of the section, and leaves point there where a menu ought to be."
441 (goto-char beginning
)
442 (if (not (re-search-forward "^@menu" first
'goto-end
))
443 (progn (insert "\n\n") (forward-line -
2) nil
)
446 (defun texinfo-incorporate-descriptions (new-menu-list)
447 "Copy the old menu line descriptions that exist to the new menu.
449 Point must be at beginning of old menu.
451 If the node-name of the new menu is found in the old menu, insert the
452 old description into the new entry.
454 For this function, the new menu is a list made up of lists of dotted
455 pairs in which the first element of the pair is the node name and the
456 second element the description. The new menu is changed destructively.
457 The old menu is the menu as it appears in the Texinfo file."
459 (let ((new-menu-list-pointer new-menu-list
)
460 (end-of-menu (texinfo-menu-end)))
462 (save-excursion ; keep point at beginning of menu
463 (if (re-search-forward
464 ;; Existing nodes can have the form
465 ;; * NODE NAME:: DESCRIPTION
467 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
469 ;; Recognize both when looking for the description.
470 (concat "\\* \\(" ; so only menu entries are found
471 (regexp-quote (car (car new-menu-list
))) "::"
473 ".*: " (regexp-quote (car (car new-menu-list
))) "[.,\t\n]"
475 ) ; so only complete entries are found
478 (setcdr (car new-menu-list
)
479 (texinfo-menu-copy-old-description end-of-menu
))))
480 (setq new-menu-list
(cdr new-menu-list
)))
481 (setq new-menu-list new-menu-list-pointer
)))
483 (defun texinfo-incorporate-menu-entry-names (new-menu-list)
484 "Copy any old menu entry names to the new menu.
486 Point must be at beginning of old menu.
488 If the node-name of the new menu entry cannot be found in the old
491 For this function, the new menu is a list made up of lists of dotted
492 pairs in which the first element of the pair is the node name and the
493 second element is the description (or nil).
495 If we find an existing menu entry name, we change the first element of
496 the pair to be another dotted pair in which the car is the menu entry
497 name and the cdr is the node name.
499 NEW-MENU-LIST is changed destructively. The old menu is the menu as it
500 appears in the texinfo file."
502 (let ((new-menu-list-pointer new-menu-list
)
503 (end-of-menu (texinfo-menu-end)))
505 (save-excursion ; keep point at beginning of menu
506 (if (re-search-forward
507 ;; Existing nodes can have the form
508 ;; * NODE NAME:: DESCRIPTION
510 ;; * MENU ITEM: NODE NAME. DESCRIPTION.
512 ;; We're interested in the second case.
513 (concat "\\* " ; so only menu entries are found
514 "\\(.*\\): " (regexp-quote (car (car new-menu-list
)))
519 (car new-menu-list
) ; replace the node name
520 (cons (buffer-substring (match-beginning 1) (match-end 1))
521 (car (car new-menu-list
)))))
522 (setq new-menu-list
(cdr new-menu-list
))))
523 (setq new-menu-list new-menu-list-pointer
)))
525 (defun texinfo-menu-copy-old-description (end-of-menu)
526 "Return description field of old menu line as string.
527 Point must be located just after the node name. Point left before description.
528 Single argument, END-OF-MENU, is position limiting search."
529 (skip-chars-forward "[:.,\t\n ]+")
530 ;; don't copy a carriage return at line beginning with asterisk!
531 ;; do copy a description that begins with an `@'!
532 ;; !! Known bug: does not copy descriptions starting with ^|\{?* etc.
533 (if (and (looking-at "\\(\\w+\\|@\\)")
534 (not (looking-at "\\(^\\* \\|^@end menu\\)")))
538 (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t
)
540 (end-of-line) ; go to end of last description line
544 (defun texinfo-menu-end ()
545 "Return position of end of menu, but don't move point.
546 Signal an error if not end of menu."
548 (if (re-search-forward "^@end menu" nil t
)
550 (error "Menu does not have an end."))))
552 (defun texinfo-delete-old-menu (beginning first
)
553 "Delete the old menu. Point must be in or after menu.
554 First argument is position of the beginning of the section in which
555 the menu will be located; second argument is the position of the first
556 node within the section."
557 ;; No third arg to search, so error if search fails.
558 (re-search-backward "^@menu" beginning
)
559 (delete-region (point)
561 (re-search-forward "^@end menu" first
)
565 ;;; Inserting new menu
567 ;; try 32, but perhaps 24 is better
568 (defvar texinfo-column-for-description
32
569 "*Column at which descriptions start in a Texinfo menu.")
571 (defun texinfo-insert-menu (menu-list node-name
)
572 "Insert formatted menu at point.
573 Indents the first line of the description, if any, to the value of
574 texinfo-column-for-description.
578 \(\(\"node-name1\" . \"description\"\)
579 \(\"node-name2\" . \"description\"\) ... \)
581 However, the description field might be nil.
583 Also, the node-name field might itself be a dotted pair (call it P) of
584 strings instead of just a string. In that case, the car of P
585 is the menu entry name, and the cdr of P is the node name."
589 ;; Every menu entry starts with a star and a space.
592 ;; Insert the node name (and menu entry name, if present).
593 (let ((node-part (car (car menu-list
))))
594 (if (stringp node-part
)
595 ;; "Double colon" entry line; menu entry and node name are the same,
596 (insert (format "%s::" node-part
))
597 ;; "Single colon" entry line; menu entry and node name are different.
598 (insert (format "%s: %s." (car node-part
) (cdr node-part
)))))
600 ;; Insert the description, if present.
601 (if (cdr (car menu-list
))
603 ;; Move to right place.
604 (indent-to texinfo-column-for-description
2)
605 ;; Insert description.
606 (insert (format "%s" (cdr (car menu-list
))))))
608 (insert "\n") ; end this menu entry
609 (setq menu-list
(cdr menu-list
)))
612 "Updated \"%s\" level menu following node: %s ... " level node-name
))
615 ;;; Starting menu descriptions by inserting titles
617 (defun texinfo-start-menu-description ()
618 "In this menu entry, insert the node's section title as a description.
619 Position point at beginning of description ready for editing.
620 Do not insert a title if the line contains an existing description.
622 You will need to edit the inserted text since a useful description
623 complements the node name rather than repeats it as a title does."
626 (let (beginning end node-name title
)
629 (if (search-forward "* " (save-excursion (end-of-line) (point)) t
)
630 (progn (skip-chars-forward " \t")
631 (setq beginning
(point)))
632 (error "This is not a line in a menu!"))
635 ;; "Double colon" entry line; menu entry and node name are the same,
636 ((search-forward "::" (save-excursion (end-of-line) (point)) t
)
637 (if (looking-at "[ \t]*[^ \t\n]+")
638 (error "Descriptive text already exists."))
639 (skip-chars-backward ": \t")
640 (setq node-name
(buffer-substring beginning
(point))))
642 ;; "Single colon" entry line; menu entry and node name are different.
643 ((search-forward ":" (save-excursion (end-of-line) (point)) t
)
644 (skip-chars-forward " \t")
645 (setq beginning
(point))
646 ;; Menu entry line ends in a period, comma, or tab.
647 (if (re-search-forward "[.,\t]"
648 (save-excursion (forward-line 1) (point)) t
)
650 (if (looking-at "[ \t]*[^ \t\n]+")
651 (error "Descriptive text already exists."))
652 (skip-chars-backward "., \t")
653 (setq node-name
(buffer-substring beginning
(point))))
654 ;; Menu entry line ends in a return.
655 (re-search-forward ".*\n"
656 (save-excursion (forward-line 1) (point)) t
)
657 (skip-chars-backward " \t\n")
658 (setq node-name
(buffer-substring beginning
(point)))
659 (if (= 0 (length node-name
))
660 (error "No node name on this line.")
662 (t (error "No node name on this line.")))
663 ;; Search for node that matches node name, and copy the section title.
664 (if (re-search-forward
667 (regexp-quote node-name
)
668 ".*\n" ; match node line
670 "\\(\\(^@c \\|^@comment\\).*\n\\)" ; match comment line, if any
672 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
674 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
675 "\\)?" ; end of expression
681 ;; skip over section type
682 (progn (forward-word 1)
684 (skip-chars-forward " \t")
687 (skip-chars-backward " \t")
689 (error "Cannot find node to match node name in menu entry.")))
690 ;; Return point to the menu and insert the title.
694 (save-excursion (skip-chars-backward " \t") (point)))
695 (indent-to texinfo-column-for-description
2)
696 (save-excursion (insert title
))))
699 ;;; Handling description indentation
701 ;; Since the make-menu functions indent descriptions, these functions
702 ;; are useful primarily for indenting a single menu specially.
704 (defun texinfo-indent-menu-description (column &optional region-p
)
705 "Indent every description in menu following point to COLUMN.
706 Non-nil argument (prefix, if interactive) means indent every
707 description in every menu in the region. Does not indent second and
708 subsequent lines of a multi-line description."
711 "nIndent menu descriptions to (column number): \nP")
717 (re-search-forward "^@menu")
718 (texinfo-menu-indent-description column
)
720 "Indented descriptions in menu. You may save the buffer."))
722 (message "Indenting every menu description in region... ")
723 (goto-char (region-beginning))
724 (while (and (< (point) (region-end))
725 (texinfo-locate-menu-p))
727 (texinfo-menu-indent-description column
))
728 (message "Indenting done. You may save the buffer.")))))
730 (defun texinfo-menu-indent-description (to-column-number)
731 "Indent the Texinfo file menu description to TO-COLUMN-NUMBER.
732 Start with point just after the word `menu' in the `@menu' line and
733 leave point on the line before the `@end menu' line. Does not indent
734 second and subsequent lines of a multi-line description."
735 (let* ((beginning-of-next-line (point)))
736 (while (< beginning-of-next-line
737 (save-excursion ; beginning of end menu line
738 (goto-char (texinfo-menu-end))
742 (if (re-search-forward "\\* \\(.*::\\|.*: [^.,\t\n]+[.,\t]\\)"
746 (let ((beginning-white-space (point)))
747 (skip-chars-forward " \t") ; skip over spaces
748 (if (looking-at "\\(@\\|\\w\\)+") ; if there is text
750 ;; remove pre-existing indentation
751 (delete-region beginning-white-space
(point))
752 (indent-to-column to-column-number
))))))
753 ;; position point at beginning of next line
755 (setq beginning-of-next-line
(point)))))
758 ;;; Making the master menu
760 (defun texinfo-master-menu (update-all-nodes-menus-p)
761 "Make a master menu for a whole Texinfo file.
762 Non-nil argument (prefix, if interactive) means first update all
763 existing nodes and menus. Remove pre-existing master menu, if there is one.
765 This function creates a master menu that follows the top node. The
766 master menu includes every entry from all the other menus. It
767 replaces any existing ordinary menu that follows the top node.
769 If called with a non-nil argument, this function first updates all the
770 menus in the buffer (incorporating descriptions from pre-existing
771 menus) before it constructs the master menu.
773 The function removes the detailed part of an already existing master
774 menu. This action depends on the pre-existing master menu using the
775 standard `texinfo-master-menu-header'.
777 The master menu has the following format, which is adapted from the
778 recommendation in the Texinfo Manual:
780 * The first part contains the major nodes in the Texinfo file: the
781 nodes for the chapters, chapter-like sections, and the major
782 appendices. This includes the indices, so long as they are in
783 chapter-like sections, such as unnumbered sections.
785 * The second and subsequent parts contain a listing of the other,
786 lower level menus, in order. This way, an inquirer can go
787 directly to a particular node if he or she is searching for
788 specific information.
790 Each of the menus in the detailed node listing is introduced by the
791 title of the section containing the menu."
794 (let ((case-fold-search t
))
796 (goto-char (point-min))
798 ;; Move point to location after `top'.
799 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
800 (error "This buffer needs a Top node!"))
804 (or (re-search-forward "^@node" nil t
)
805 (error "Too few nodes for a master menu!"))
807 (if (search-forward texinfo-master-menu-header first-chapter t
)
809 ;; Check if @detailmenu kludge is used;
810 ;; if so, leave point before @detailmenu.
811 (search-backward "\n@detailmenu"
812 (save-excursion (forward-line -
3) (point))
814 ;; Remove detailed master menu listing
815 (goto-char (match-beginning 0))
816 (let ((end-of-detailed-menu-descriptions
817 (save-excursion ; beginning of end menu line
818 (goto-char (texinfo-menu-end))
819 (beginning-of-line) (forward-char -
1)
821 (delete-region (point) end-of-detailed-menu-descriptions
)))))
823 (if update-all-nodes-menus-p
825 (message "Making a master menu in %s ...first updating all nodes... "
827 (texinfo-update-node (point-min) (point-max))
829 (message "Updating all menus in %s ... " (buffer-name))
830 (texinfo-make-menu (point-min) (point-max))))
832 (message "Now making the master menu in %s... " (buffer-name))
833 (goto-char (point-min))
834 (texinfo-insert-master-menu-list
835 (texinfo-master-menu-list))
837 ;; Remove extra newlines that texinfo-insert-master-menu-list
838 ;; may have inserted.
841 (goto-char (point-min))
843 (if (search-forward texinfo-master-menu-header nil t
)
845 (goto-char (match-beginning 0))
846 ;; Check if @detailmenu kludge is used;
847 ;; if so, leave point before @detailmenu.
848 (search-backward "\n@detailmenu"
849 (save-excursion (forward-line -
3) (point))
853 (goto-char (point-min))))
855 (re-search-forward "^@menu")
859 (re-search-forward "^@end menu")
861 (delete-blank-lines))
864 "Done...completed making master menu. You may save the buffer.")))
866 (defun texinfo-master-menu-list ()
867 "Return a list of menu entries and header lines for the master menu.
869 Start with the menu for chapters and indices and then find each
870 following menu and the title of the node preceding that menu.
872 The master menu list has this form:
874 \(\(\(... \"entry-1-2\" \"entry-1\"\) \"title-1\"\)
875 \(\(... \"entry-2-2\" \"entry-2-1\"\) \"title-2\"\)
878 However, there does not need to be a title field."
880 (let (master-menu-list)
881 (while (texinfo-locate-menu-p)
882 (setq master-menu-list
885 (texinfo-copy-menu-title))
887 (reverse master-menu-list
)))
889 (defun texinfo-insert-master-menu-list (master-menu-list)
890 "Format and insert the master menu in the current buffer."
891 (goto-char (point-min))
892 ;; Insert a master menu only after `Top' node and before next node
893 ;; \(or include file if there is no next node\).
894 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
895 (error "This buffer needs a Top node!"))
897 (save-excursion (re-search-forward "^@node\\|^@include") (point))))
898 (if (not (re-search-forward "^@menu" first-chapter t
))
900 "Buffer lacks ordinary `Top' menu in which to insert master.")))
902 (delete-region ; buffer must have ordinary top menu
904 (save-excursion (re-search-forward "^@end menu") (point)))
907 ;; `master-menu-inserted-p' is a kludge to tell
908 ;; whether to insert @end detailmenu (see bleow)
909 (let (master-menu-inserted-p)
910 ;; Handle top of menu
912 ;; Insert chapter menu entries
913 (setq this-very-menu-list
(reverse (car (car master-menu-list
))))
914 ;; Tell user what is going on.
915 (message "Inserting chapter menu entry: %s ... " this-very-menu-list
)
916 (while this-very-menu-list
917 (insert "* " (car this-very-menu-list
) "\n")
918 (setq this-very-menu-list
(cdr this-very-menu-list
)))
920 (setq master-menu-list
(cdr master-menu-list
))
922 ;; Only insert detailed master menu if there is one....
923 (if (car (car master-menu-list
))
924 (progn (setq master-menu-inserted-p t
)
925 (insert (concat "\n@detailmenu\n"
926 texinfo-master-menu-header
))))
928 ;; @detailmenu added 5 Sept 1996 to `texinfo-master-menu-header'
929 ;; at Karl Berry's request to avert a bug in `makeinfo';
930 ;; all agree this is a bad kludge and should eventually be removed.
931 ;; @detailmenu ... @end detailmenu is a noop in `texinfmt.el'.
932 ;; See @end detailmenu below;
933 ;; also see `texinfo-all-menus-update' above, `texinfo-master-menu',
934 ;; `texinfo-multiple-files-update'.
936 ;; Now, insert all the other menus
938 ;; The menu master-menu-list has a form like this:
939 ;; ((("beta" "alpha") "title-A")
940 ;; (("delta" "gamma") "title-B"))
942 (while master-menu-list
945 "Inserting menu for %s .... " (car (cdr (car master-menu-list
))))
946 ;; insert title of menu section
947 (insert "\n" (car (cdr (car master-menu-list
))) "\n\n")
949 ;; insert each menu entry
950 (setq this-very-menu-list
(reverse (car (car master-menu-list
))))
951 (while this-very-menu-list
952 (insert "* " (car this-very-menu-list
) "\n")
953 (setq this-very-menu-list
(cdr this-very-menu-list
)))
955 (setq master-menu-list
(cdr master-menu-list
)))
959 ;; @detailmenu (see note above)
960 ;; Only insert @end detailmenu if a master menu was inserted.
961 (if master-menu-inserted-p
962 (insert "\n@end detailmenu"))
963 (insert "\n@end menu\n\n"))))
965 (defun texinfo-locate-menu-p ()
966 "Find the next menu in the texinfo file.
967 If found, leave point after word `menu' on the `@menu' line, and return t.
968 If a menu is not found, do not move point and return nil."
969 (re-search-forward "\\(^@menu\\)" nil t
))
971 (defun texinfo-copy-menu-title ()
972 "Return the title of the section preceding the menu as a string.
973 If such a title cannot be found, return an empty string. Do not move
975 (let ((case-fold-search t
))
977 (if (re-search-backward
981 texinfo-section-types-regexp
; all other section types
987 (forward-word 1) ; skip over section type
988 (skip-chars-forward " \t") ; and over spaces
991 (progn (end-of-line) (point))))
994 (defun texinfo-copy-menu ()
995 "Return the entries of an existing menu as a list.
996 Start with point just after the word `menu' in the `@menu' line
997 and leave point on the line before the `@end menu' line."
998 (let* (this-menu-list
999 (end-of-menu (texinfo-menu-end)) ; position of end of `@end menu'
1000 (last-entry (save-excursion ; position of beginning of
1002 (goto-char end-of-menu
)
1003 ;; handle multi-line description
1004 (if (not (re-search-backward "^\\* " nil t
))
1005 (error "No entries in menu."))
1007 (while (< (point) last-entry
)
1008 (if (re-search-forward "^\\* " end-of-menu t
)
1010 (setq this-menu-list
1014 ;; copy multi-line descriptions
1016 (re-search-forward "\\(^\\* \\|^@e\\)" nil t
)
1022 ;;; Determining the hierarchical level in the texinfo file
1024 (defun texinfo-specific-section-type ()
1025 "Return the specific type of next section, as a string.
1026 For example, \"unnumberedsubsec\". Return \"top\" for top node.
1028 Searches forward for a section. Hence, point must be before the
1029 section whose type will be found. Does not move point. Signal an
1030 error if the node is not the top node and a section is not found."
1031 (let ((case-fold-search t
))
1034 ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1035 ;;; Following search limit by cph but causes a bug
1042 ((re-search-forward texinfo-section-types-regexp nil t
)
1043 (buffer-substring-no-properties
1044 (progn (beginning-of-line) ; copy its name
1046 (progn (forward-word 1)
1050 "texinfo-specific-section-type: Chapter or section not found."))))))
1052 (defun texinfo-hierarchic-level ()
1053 "Return the general hierarchal level of the next node in a texinfo file.
1054 Thus, a subheading or appendixsubsec is of type subsection."
1055 (let ((case-fold-search t
))
1057 (texinfo-specific-section-type)
1058 texinfo-section-list
))))
1061 ;;; Locating the major positions
1063 (defun texinfo-update-menu-region-beginning (level)
1064 "Locate beginning of higher level section this section is within.
1065 Return position of the beginning of the node line; do not move point.
1066 Thus, if this level is subsection, searches backwards for section node.
1067 Only argument is a string of the general type of section."
1068 (let ((case-fold-search t
))
1069 ;; !! Known bug: if section immediately follows top node, this
1070 ;; returns the beginning of the buffer as the beginning of the
1071 ;; higher level section.
1075 (goto-char (point-min))
1076 (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
)
1083 "\\(^@node\\).*\n" ; match node line
1084 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1086 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
1088 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
1089 "\\)?" ; end of expression
1091 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
1096 (defun texinfo-update-menu-region-end (level)
1097 "Locate end of higher level section this section is within.
1098 Return position; do not move point. Thus, if this level is a
1099 subsection, find the node for the section this subsection is within.
1100 If level is top or chapter, returns end of file. Only argument is a
1101 string of the general type of section."
1102 (let ((case-fold-search t
))
1104 (if (re-search-forward
1106 "\\(^@node\\).*\n" ; match node line
1107 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
1109 "\\(^@ifinfo[ ]*\n\\)" ; ifinfo line, if any
1111 "\\(^@ifnottex[ ]*\n\\)" ; ifnottex line, if any
1112 "\\)?" ; end of expression
1114 ;; Never finds end of level above chapter so goes to end.
1115 (cdr (assoc level texinfo-update-menu-higher-regexps
))))
1121 (defun texinfo-menu-first-node (beginning end
)
1122 "Locate first node of the section the menu will be placed in.
1123 Return position; do not move point.
1124 The menu will be located just before this position.
1126 First argument is the position of the beginning of the section in
1127 which the menu will be located; second argument is the position of the
1128 end of that region; it limits the search."
1131 (goto-char beginning
)
1133 (re-search-forward "^@node" end t
)
1138 ;; We used to look for just sub, but that found @subtitle.
1139 (defvar texinfo-section-types-regexp
1140 "^@\\(chapter \\|sect\\|subs\\|subh\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
1141 "Regexp matching chapter, section, other headings (but not the top node).")
1143 (defvar texinfo-section-level-regexp
1144 (regexp-opt (texinfo-filter 3 texinfo-section-list
))
1145 "Regular expression matching just the Texinfo section level headings.")
1147 (defvar texinfo-subsection-level-regexp
1148 (regexp-opt (texinfo-filter 4 texinfo-section-list
))
1149 "Regular expression matching just the Texinfo subsection level headings.")
1151 (defvar texinfo-subsubsection-level-regexp
1152 (regexp-opt (texinfo-filter 5 texinfo-section-list
))
1153 "Regular expression matching just the Texinfo subsubsection level headings.")
1155 (defvar texinfo-update-menu-same-level-regexps
1157 (2 .
(concat "\\(^@\\)\\(" texinfo-chapter-level-regexp
"\\)\\>[ \t]*"))
1158 (3 .
(concat "\\(^@\\)\\(" texinfo-section-level-regexp
"\\)\\>[ \t]*"))
1159 (4 .
(concat "\\(^@\\)\\(" texinfo-subsection-level-regexp
"\\)\\>[ \t]+"))
1160 (5 .
(concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp
"\\)\\>[ \t]+")))
1161 "*Regexps for searching for same level sections in a Texinfo file.
1162 The keys are strings specifying the general hierarchical level in the
1163 document; the values are regular expressions.")
1165 (defvar texinfo-update-menu-higher-regexps
1166 '((1 .
"^@node [ \t]*DIR")
1167 (2 .
"^@node [ \t]*top[ \t]*\\(,\\|$\\)")
1171 texinfo-chapter-level-regexp
1176 texinfo-section-level-regexp
1178 texinfo-chapter-level-regexp
1183 texinfo-subsection-level-regexp
1185 texinfo-section-level-regexp
1187 texinfo-chapter-level-regexp
1188 "\\)\\>[ \t]*\\)")))
1189 "*Regexps for searching for higher level sections in a Texinfo file.
1190 The keys are strings specifying the general hierarchical level in the
1191 document; the values are regular expressions.")
1193 (defvar texinfo-update-menu-lower-regexps
1197 texinfo-chapter-level-regexp
1199 texinfo-section-level-regexp
1201 texinfo-subsection-level-regexp
1203 texinfo-subsubsection-level-regexp
1208 texinfo-section-level-regexp
1210 texinfo-subsection-level-regexp
1212 texinfo-subsubsection-level-regexp
1217 texinfo-subsection-level-regexp
1219 texinfo-subsubsection-level-regexp
1224 texinfo-subsubsection-level-regexp
1226 ;; There's nothing below 5, use a bogus regexp that can't match.
1228 "*Regexps for searching for lower level sections in a Texinfo file.
1229 The keys are strings specifying the general hierarchical level in the
1230 document; the values are regular expressions.")
1235 (defun texinfo-update-node (&optional beginning end
)
1236 "Without any prefix argument, update the node in which point is located.
1237 Interactively, a prefix argument means to operate on the region.
1239 The functions for creating or updating nodes and menus, and their
1242 texinfo-update-node (&optional beginning end) \\[texinfo-update-node]
1243 texinfo-every-node-update () \\[texinfo-every-node-update]
1244 texinfo-sequential-node-update (&optional region-p)
1246 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
1247 texinfo-all-menus-update () \\[texinfo-all-menus-update]
1248 texinfo-master-menu ()
1250 texinfo-indent-menu-description (column &optional region-p)
1252 The `texinfo-column-for-description' variable specifies the column to
1253 which menu descriptions are indented. Its default value is 32."
1257 (list (point) (mark))))
1258 (if (null beginning
)
1259 ;; Update a single node.
1260 (let ((auto-fill-function nil
) (auto-fill-hook nil
))
1261 (if (not (re-search-backward "^@node" (point-min) t
))
1262 (error "Node line not found before this position"))
1263 (texinfo-update-the-node)
1264 (message "Done...updated the node. You may save the buffer."))
1266 (let ((auto-fill-function nil
)
1267 (auto-fill-hook nil
))
1270 (narrow-to-region beginning end
)
1271 (goto-char (point-min))
1272 (while (re-search-forward "^@node" (point-max) t
)
1274 (texinfo-update-the-node))
1275 (goto-char (point-max))
1276 (message "Done...nodes updated in region. You may save the buffer."))))))
1278 (defun texinfo-every-node-update ()
1279 "Update every node in a Texinfo file."
1282 (texinfo-update-node (point-min) (point-max))
1283 (message "Done...updated every node. You may save the buffer.")))
1285 (defun texinfo-update-the-node ()
1286 "Update one node. Point must be at the beginning of node line.
1287 Leave point at the end of the node line."
1288 (texinfo-check-for-node-name)
1289 (texinfo-delete-existing-pointers)
1290 (message "Updating node: %s ... " (texinfo-copy-node-name))
1294 ((case-fold-search t
)
1295 (level (texinfo-hierarchic-level))
1296 (beginning (texinfo-update-menu-region-beginning level
))
1297 (end (texinfo-update-menu-region-end level
)))
1299 (texinfo-top-pointer-case)
1301 (texinfo-insert-pointer beginning end level
'next
)
1302 (texinfo-insert-pointer beginning end level
'previous
)
1303 (texinfo-insert-pointer beginning end level
'up
)
1304 (texinfo-clean-up-node-line)))))
1306 (defun texinfo-top-pointer-case ()
1307 "Insert pointers in the Top node. This is a special case.
1309 The `Next' pointer is a pointer to a chapter or section at a lower
1310 hierarchical level in the file. The `Previous' and `Up' pointers are
1311 to `(dir)'. Point must be at the beginning of the node line, and is
1312 left at the end of the node line."
1314 (texinfo-clean-up-node-line)
1317 ;; There may be an @chapter or other such command between
1318 ;; the top node line and the next node line, as a title
1319 ;; for an `ifinfo' section. This @chapter command must
1320 ;; must be skipped. So the procedure is to search for
1321 ;; the next `@node' line, and then copy its name.
1322 (if (re-search-forward "^@node" nil t
)
1325 (texinfo-copy-node-name))
1329 (defun texinfo-check-for-node-name ()
1330 "Determine whether the node has a node name. Prompt for one if not.
1331 Point must be at beginning of node line. Does not move point."
1333 (let ((initial (texinfo-copy-next-section-title)))
1334 ;; This is not clean. Use `interactive' to read the arg.
1335 (forward-word 1) ; skip over node command
1336 (skip-chars-forward " \t") ; and over spaces
1337 (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what Info looks for
1338 ; alternatively, use "[a-zA-Z]+"
1340 (read-from-minibuffer
1341 "Node name (use no @, commas, colons, or apostrophes): "
1343 (insert " " node-name
))))))
1345 (defun texinfo-delete-existing-pointers ()
1346 "Delete `Next', `Previous', and `Up' pointers.
1347 Starts from the current position of the cursor, and searches forward
1348 on the line for a comma and if one is found, deletes the rest of the
1349 line, including the comma. Leaves point at beginning of line."
1350 (let ((eol-point (save-excursion (end-of-line) (point))))
1351 (if (search-forward "," eol-point t
)
1352 (delete-region (1- (point)) eol-point
)))
1353 (beginning-of-line))
1355 (defun texinfo-find-pointer (beginning end level direction
)
1356 "Move point to section associated with next, previous, or up pointer.
1357 Return type of pointer (either `normal' or `no-pointer').
1359 The first and second arguments bound the search for a pointer to the
1360 beginning and end, respectively, of the enclosing higher level
1361 section. The third argument is a string specifying the general kind
1362 of section such as \"chapter\" or \"section\". When looking for the
1363 `Next' pointer, the section found will be at the same hierarchical
1364 level in the Texinfo file; when looking for the `Previous' pointer,
1365 the section found will be at the same or higher hierarchical level in
1366 the Texinfo file; when looking for the `Up' pointer, the section found
1367 will be at some level higher in the Texinfo file. The fourth argument
1368 \(one of 'next, 'previous, or 'up\) specifies whether to find the
1369 `Next', `Previous', or `Up' pointer."
1370 (let ((case-fold-search t
))
1371 (cond ((eq direction
'next
)
1372 (forward-line 3) ; skip over current node
1373 ;; Search for section commands accompanied by node lines;
1374 ;; ignore section commands in the middle of nodes.
1375 (if (re-search-forward
1376 ;; A `Top' node is never a next pointer, so won't find it.
1380 ;; Match comment, ifinfo, ifnottex line, if any
1385 "\\(^@ifinfo[ ]*\n\\)"
1387 "\\(^@ifnottex[ ]*\n\\)"
1390 (cdr (assoc level texinfo-update-menu-same-level-regexps
))))
1395 ((eq direction
'previous
)
1396 (if (re-search-backward
1401 ;; Match comment, ifinfo, ifnottex line, if any
1406 "\\(^@ifinfo[ ]*\n\\)"
1408 "\\(^@ifnottex[ ]*\n\\)"
1411 (cdr (assoc level texinfo-update-menu-same-level-regexps
)))
1415 ;; Match comment, ifinfo, ifnottex line, if any
1420 "\\(^@ifinfo[ ]*\n\\)"
1422 "\\(^@ifnottex[ ]*\n\\)"
1425 (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1427 ;; Handle `Top' node specially.
1428 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1435 (if (re-search-backward
1440 ;; Match comment, ifinfo, ifnottex line, if any
1445 "\\(^@ifinfo[ ]*\n\\)"
1447 "\\(^@ifnottex[ ]*\n\\)"
1449 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1451 ;; Handle `Top' node specially.
1452 "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
1455 (goto-char beginning
)
1462 (error "texinfo-find-pointer: lack proper arguments")))))
1464 (defun texinfo-pointer-name (kind)
1465 "Return the node name preceding the section command.
1466 The argument is the kind of section, either `normal' or `no-pointer'."
1468 (cond ((eq kind
'normal
)
1469 (end-of-line) ; this handles prev node top case
1470 (re-search-backward ; when point is already
1471 "^@node" ; at the beginning of @node line
1472 (save-excursion (forward-line -
3))
1474 (setq name
(texinfo-copy-node-name)))
1475 ((eq kind
'no-pointer
)
1476 ;; Don't need to put a blank in the pointer slot,
1477 ;; since insert "' " always has a space
1478 (setq name
" "))) ; put a blank in the pointer slot
1481 (defun texinfo-insert-pointer (beginning end level direction
)
1482 "Insert the `Next', `Previous' or `Up' node name at point.
1485 The first and second arguments bound the search for a pointer to the
1486 beginning and end, respectively, of the enclosing higher level
1487 section. The third argument is the hierarchical level of the Texinfo
1488 file, a string such as \"section\". The fourth argument is direction
1489 towards which the pointer is directed, one of `next', `previous', or `up'."
1495 (texinfo-pointer-name
1496 (texinfo-find-pointer beginning end level direction
)))))
1498 (defun texinfo-clean-up-node-line ()
1499 "Remove extra commas, if any, at end of node line."
1501 (skip-chars-backward ", ")
1502 (delete-region (point) (save-excursion (end-of-line) (point))))
1505 ;;; Updating nodes sequentially
1506 ;; These sequential update functions insert `Next' or `Previous'
1507 ;; pointers that point to the following or preceding nodes even if they
1508 ;; are at higher or lower hierarchical levels. This means that if a
1509 ;; section contains one or more subsections, the section's `Next'
1510 ;; pointer will point to the subsection and not the following section.
1511 ;; (The subsection to which `Next' points will most likely be the first
1512 ;; item on the section's menu.)
1514 (defun texinfo-sequential-node-update (&optional region-p
)
1515 "Update one node (or many) in a Texinfo file with sequential pointers.
1517 This function causes the `Next' or `Previous' pointer to point to the
1518 immediately preceding or following node, even if it is at a higher or
1519 lower hierarchical level in the document. Continually pressing `n' or
1520 `p' takes you straight through the file.
1522 Without any prefix argument, update the node in which point is located.
1523 Non-nil argument (prefix, if interactive) means update the nodes in the
1526 This command makes it awkward to navigate among sections and
1527 subsections; it should be used only for those documents that are meant
1528 to be read like a novel rather than a reference, and for which the
1529 Info `g*' command is inadequate."
1533 ;; update a single node
1534 (let ((auto-fill-function nil
) (auto-fill-hook nil
))
1535 (if (not (re-search-backward "^@node" (point-min) t
))
1536 (error "Node line not found before this position."))
1537 (texinfo-sequentially-update-the-node)
1539 "Done...sequentially updated the node . You may save the buffer."))
1541 (let ((auto-fill-function nil
)
1542 (auto-fill-hook nil
)
1543 (beginning (region-beginning))
1545 (if (= end beginning
)
1546 (error "Please mark a region!"))
1548 (narrow-to-region beginning end
)
1549 (goto-char beginning
)
1550 (push-mark (point) t
)
1551 (while (re-search-forward "^@node" (point-max) t
)
1553 (texinfo-sequentially-update-the-node))
1555 "Done...updated the nodes in sequence. You may save the buffer.")))))
1557 (defun texinfo-sequentially-update-the-node ()
1558 "Update one node such that the pointers are sequential.
1559 A `Next' or `Previous' pointer points to any preceding or following node,
1560 regardless of its hierarchical level."
1562 (texinfo-check-for-node-name)
1563 (texinfo-delete-existing-pointers)
1565 "Sequentially updating node: %s ... " (texinfo-copy-node-name))
1568 (let* ((case-fold-search t
)
1569 (level (texinfo-hierarchic-level)))
1571 (texinfo-top-pointer-case)
1573 (texinfo-sequentially-insert-pointer level
'next
)
1574 (texinfo-sequentially-insert-pointer level
'previous
)
1575 (texinfo-sequentially-insert-pointer level
'up
)
1576 (texinfo-clean-up-node-line)))))
1578 (defun texinfo-sequentially-find-pointer (level direction
)
1579 "Find next or previous pointer sequentially in Texinfo file, or up pointer.
1580 Move point to section associated with the pointer. Find point even if
1581 it is in a different section.
1583 Return type of pointer (either `normal' or `no-pointer').
1585 The first argument is a string specifying the general kind of section
1586 such as \"chapter\" or \"section\". The section found will be at the
1587 same hierarchical level in the Texinfo file, or, in the case of the up
1588 pointer, some level higher. The second argument (one of `next',
1589 `previous', or `up') specifies whether to find the `Next', `Previous',
1591 (let ((case-fold-search t
))
1592 (cond ((eq direction
'next
)
1593 (forward-line 3) ; skip over current node
1594 (if (re-search-forward
1595 texinfo-section-types-regexp
1600 ((eq direction
'previous
)
1601 (if (re-search-backward
1602 texinfo-section-types-regexp
1608 (if (re-search-backward
1609 (eval (cdr (assoc level texinfo-update-menu-higher-regexps
)))
1615 (error "texinfo-sequential-find-pointer: lack proper arguments")))))
1617 (defun texinfo-sequentially-insert-pointer (level direction
)
1618 "Insert the `Next', `Previous' or `Up' node name at point.
1621 The first argument is the hierarchical level of the Texinfo file, a
1622 string such as \"section\". The second argument is direction, one of
1623 `next', `previous', or `up'."
1629 (texinfo-pointer-name
1630 (texinfo-sequentially-find-pointer level direction
)))))
1633 ;;; Inserting `@node' lines
1634 ;; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
1635 ;; before the `@chapter', `@section', and such like lines of a region
1636 ;; in a Texinfo file.
1638 (defun texinfo-insert-node-lines (beginning end
&optional title-p
)
1639 "Insert missing `@node' lines in region of Texinfo file.
1640 Non-nil argument (prefix, if interactive) means also to insert the
1641 section titles as node names; and also to insert the section titles as
1642 node names in pre-existing `@node' lines that lack names."
1643 (interactive "r\nP")
1645 ;; Use marker; after inserting node lines, leave point at end of
1646 ;; region and mark at beginning.
1648 (let (beginning-marker end-marker title last-section-position
)
1650 ;; Save current position on mark ring and set mark to end.
1652 (setq end-marker
(mark-marker))
1654 (goto-char beginning
)
1655 (while (re-search-forward
1656 texinfo-section-types-regexp
1659 ;; Copy title if desired.
1664 (skip-chars-forward " \t")
1665 (setq title
(buffer-substring
1667 (save-excursion (end-of-line) (point))))))
1668 ;; Insert node line if necessary.
1669 (if (re-search-backward
1671 ;; Avoid finding previous node line if node lines are close.
1672 (or last-section-position
1673 (save-excursion (forward-line -
2) (point))) t
)
1674 ;; @node is present, and point at beginning of that line
1675 (forward-word 1) ; Leave point just after @node.
1676 ;; Else @node missing; insert one.
1677 (beginning-of-line) ; Beginning of `@section' line.
1679 (backward-char 1)) ; Leave point just after `@node'.
1680 ;; Insert title if desired.
1683 (skip-chars-forward " \t")
1684 ;; Use regexp based on what info looks for
1685 ;; (alternatively, use "[a-zA-Z]+");
1686 ;; this means we only insert a title if none exists.
1687 (if (not (looking-at "[^,\t\n ]+"))
1692 (message "Inserted title %s ... " title
)))))
1693 ;; Go forward beyond current section title.
1694 (re-search-forward texinfo-section-types-regexp
1695 (save-excursion (forward-line 3) (point)) t
)
1696 (setq last-section-position
(point))
1699 ;; Leave point at end of region, mark at beginning.
1700 (set-mark beginning
)
1704 "Done inserting node lines and titles. You may save the buffer.")
1705 (message "Done inserting node lines. You may save the buffer."))))
1708 ;;; Update and create menus for multi-file Texinfo sources
1710 ;; 1. M-x texinfo-multiple-files-update
1712 ;; Read the include file list of an outer Texinfo file and
1713 ;; update all highest level nodes in the files listed and insert a
1714 ;; main menu in the outer file after its top node.
1716 ;; 2. C-u M-x texinfo-multiple-files-update
1718 ;; Same as 1, but insert a master menu. (Saves reupdating lower
1719 ;; level menus and nodes.) This command simply reads every menu,
1720 ;; so if the menus are wrong, the master menu will be wrong.
1721 ;; Similarly, if the lower level node pointers are wrong, they
1724 ;; 3. C-u 2 M-x texinfo-multiple-files-update
1726 ;; Read the include file list of an outer Texinfo file and
1727 ;; update all nodes and menus in the files listed and insert a
1728 ;; master menu in the outer file after its top node.
1730 ;;; Note: these functions:
1732 ;;; * Do not save or delete any buffers. You may fill up your memory.
1733 ;;; * Do not handle any pre-existing nodes in outer file.
1734 ;;; Hence, you may need a file for indices.
1737 ;;; Auxiliary functions for multiple file updating
1739 (defun texinfo-multi-file-included-list (outer-file)
1740 "Return a list of the included files in OUTER-FILE."
1741 (let ((included-file-list (list outer-file
))
1744 (switch-to-buffer (find-file-noselect outer-file
))
1746 (goto-char (point-min))
1747 (while (re-search-forward "^@include" nil t
)
1748 (skip-chars-forward " \t")
1749 (setq start
(point))
1751 (skip-chars-backward " \t")
1752 (setq included-file-list
1753 (cons (buffer-substring start
(point))
1754 included-file-list
)))
1755 (nreverse included-file-list
))))
1757 (defun texinfo-copy-next-section-title ()
1758 "Return the name of the immediately following section as a string.
1760 Start with point at the beginning of the node line. Leave point at the
1761 same place. If there is no title, returns an empty string."
1767 (if (re-search-forward "\\(^@node\\)" nil t
)
1768 (match-beginning 0)))
1770 (if (re-search-forward texinfo-section-types-regexp node-end t
)
1776 (progn (forward-word 1) ; skip over section type
1777 (skip-chars-forward " \t") ; and over spaces
1779 (progn (end-of-line) (point)))))
1783 (defun texinfo-multi-file-update (files &optional update-everything
)
1784 "Update first node pointers in each file in FILES.
1785 Return a list of the node names.
1787 The first file in the list is an outer file; the remaining are
1788 files included in the outer file with `@include' commands.
1790 If optional arg UPDATE-EVERYTHING non-nil, update every menu and
1791 pointer in each of the included files.
1793 Also update the `Top' level node pointers of the outer file.
1797 * the first file in the FILES list must be the outer file,
1798 * each of the included files must contain exactly one highest
1799 hierarchical level node,
1800 * this node must be the first node in the included file,
1801 * each highest hierarchical level node must be of the same type.
1803 Thus, normally, each included file contains one, and only one, chapter."
1805 ;; The menu-list has the form:
1807 ;; \(\(\"node-name1\" . \"title1\"\)
1808 ;; \(\"node-name2\" . \"title2\"\) ... \)
1810 ;; However, there does not need to be a title field and this function
1811 ;; does not fill it; however a comment tells you how to do so.
1812 ;; You would use the title field if you wanted to insert titles in the
1813 ;; description slot of a menu as a description.
1815 (let ((case-fold-search t
)
1818 ;; Find the name of the first node of the first included file.
1819 (switch-to-buffer (find-file-noselect (car (cdr files
))))
1821 (goto-char (point-min))
1822 (if (not (re-search-forward "^@node" nil t
))
1823 (error "No `@node' line found in %s !" (buffer-name)))
1825 (texinfo-check-for-node-name)
1826 (setq next-node-name
(texinfo-copy-node-name))
1831 (prog1 "" (forward-line 1)))
1832 ;; Use following to insert section titles automatically.
1833 ;; (texinfo-copy-next-section-title)
1837 (switch-to-buffer (find-file-noselect (car files
)))
1838 (goto-char (point-min))
1839 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t
))
1840 (error "This buffer needs a Top node!"))
1842 (texinfo-delete-existing-pointers)
1844 (insert ", " next-node-name
", (dir), (dir)")
1846 (setq previous-node-name
"Top")
1847 (setq files
(cdr files
))
1851 (if (not (cdr files
))
1853 (setq next-node-name
"")
1855 ;; find the name of the first node in the next file.
1856 (switch-to-buffer (find-file-noselect (car (cdr files
))))
1858 (goto-char (point-min))
1859 (if (not (re-search-forward "^@node" nil t
))
1860 (error "No `@node' line found in %s !" (buffer-name)))
1862 (texinfo-check-for-node-name)
1863 (setq next-node-name
(texinfo-copy-node-name))
1867 (prog1 "" (forward-line 1)))
1868 ;; Use following to insert section titles automatically.
1869 ;; (texinfo-copy-next-section-title)
1872 ;; Go to node to be updated.
1873 (switch-to-buffer (find-file-noselect (car files
)))
1874 (goto-char (point-min))
1875 (if (not (re-search-forward "^@node" nil t
))
1876 (error "No `@node' line found in %s !" (buffer-name)))
1879 ;; Update other menus and nodes if requested.
1880 (if update-everything
(texinfo-all-menus-update t
))
1883 (texinfo-delete-existing-pointers)
1885 (insert ", " next-node-name
", " previous-node-name
", " up-node-name
)
1888 (setq previous-node-name
(texinfo-copy-node-name))
1890 (setq files
(cdr files
)))
1891 (nreverse menu-list
)))
1893 (defun texinfo-multi-files-insert-main-menu (menu-list)
1894 "Insert formatted main menu at point.
1895 Indents the first line of the description, if any, to the value of
1896 `texinfo-column-for-description'."
1900 ;; Every menu entry starts with a star and a space.
1903 ;; Insert the node name (and menu entry name, if present).
1904 (let ((node-part (car (car menu-list
))))
1905 (if (stringp node-part
)
1906 ;; "Double colon" entry line; menu entry and node name are the same,
1907 (insert (format "%s::" node-part
))
1908 ;; "Single colon" entry line; menu entry and node name are different.
1909 (insert (format "%s: %s." (car node-part
) (cdr node-part
)))))
1911 ;; Insert the description, if present.
1912 (if (cdr (car menu-list
))
1914 ;; Move to right place.
1915 (indent-to texinfo-column-for-description
2)
1916 ;; Insert description.
1917 (insert (format "%s" (cdr (car menu-list
))))))
1919 (insert "\n") ; end this menu entry
1920 (setq menu-list
(cdr menu-list
)))
1921 (insert "@end menu"))
1923 (defun texinfo-multi-file-master-menu-list (files-list)
1924 "Return master menu list from files in FILES-LIST.
1925 Menu entries in each file collected using `texinfo-master-menu-list'.
1927 The first file in FILES-LIST must be the outer file; the others must
1928 be the files included within it. A main menu must already exist."
1930 (let (master-menu-list)
1932 (switch-to-buffer (find-file-noselect (car files-list
)))
1933 (message "Working on: %s " (current-buffer))
1934 (goto-char (point-min))
1935 (setq master-menu-list
1936 (append master-menu-list
(texinfo-master-menu-list)))
1937 (setq files-list
(cdr files-list
)))
1941 ;;; The multiple-file update function
1943 (defun texinfo-multiple-files-update
1944 (outer-file &optional update-everything make-master-menu
)
1945 "Update first node pointers in each file included in OUTER-FILE;
1946 create or update the `Top' level node pointers and the main menu in
1947 the outer file that refers to such nodes. This does not create or
1948 update menus or pointers within the included files.
1950 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
1951 insert a master menu in OUTER-FILE in addition to creating or updating
1952 pointers in the first @node line in each included file and creating or
1953 updating the `Top' level node pointers of the outer file. This does
1954 not create or update other menus and pointers within the included
1957 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
1958 interactive), update all the menus and all the `Next', `Previous', and
1959 `Up' pointers of all the files included in OUTER-FILE before inserting
1960 a master menu in OUTER-FILE. Also, update the `Top' level node
1961 pointers of OUTER-FILE.
1965 * this command does NOT save any files--you must save the
1966 outer file and any modified, included files.
1968 * except for the `Top' node, this command does NOT handle any
1969 pre-existing nodes in the outer file; hence, indices must be
1970 enclosed in an included file.
1974 * each of the included files must contain exactly one highest
1975 hierarchical level node,
1976 * this highest node must be the first node in the included file,
1977 * each highest hierarchical level node must be of the same type.
1979 Thus, normally, each included file contains one, and only one,
1984 "Name of outer `include' file: "
1986 (cond ((not current-prefix-arg
)
1988 ((listp current-prefix-arg
)
1989 '(t nil
)) ; make-master-menu
1990 ((numberp current-prefix-arg
)
1991 '(t t
)) ; update-everything
1994 (let* ((included-file-list (texinfo-multi-file-included-list outer-file
))
1995 (files included-file-list
)
1999 (up-node-name "Top"))
2001 ;;; Update the pointers
2002 ;;; and collect the names of the nodes and titles
2003 (setq main-menu-list
(texinfo-multi-file-update files update-everything
))
2005 ;;; Insert main menu
2008 (switch-to-buffer (find-file-noselect (car included-file-list
)))
2009 (if (texinfo-old-menu-p
2012 (re-search-forward "^@include")
2016 ;; If found, leave point after word `menu' on the `@menu' line.
2018 (texinfo-incorporate-descriptions main-menu-list
)
2019 ;; Delete existing menu.
2023 (save-excursion (re-search-forward "^@end menu") (point)))
2025 (texinfo-multi-files-insert-main-menu main-menu-list
))
2027 ;; Else no current menu; insert it before `@include'
2028 (texinfo-multi-files-insert-main-menu main-menu-list
))
2030 ;;; Insert master menu
2032 (if make-master-menu
2034 ;; First, removing detailed part of any pre-existing master menu
2035 (goto-char (point-min))
2036 (if (search-forward texinfo-master-menu-header nil t
)
2038 (goto-char (match-beginning 0))
2039 ;; Check if @detailmenu kludge is used;
2040 ;; if so, leave point before @detailmenu.
2041 (search-backward "\n@detailmenu"
2042 (save-excursion (forward-line -
3) (point))
2044 ;; Remove detailed master menu listing
2045 (let ((end-of-detailed-menu-descriptions
2046 (save-excursion ; beginning of end menu line
2047 (goto-char (texinfo-menu-end))
2048 (beginning-of-line) (forward-char -
1)
2050 (delete-region (point) end-of-detailed-menu-descriptions
))))
2052 ;; Create a master menu and insert it
2053 (texinfo-insert-master-menu-list
2054 (texinfo-multi-file-master-menu-list
2055 included-file-list
)))))
2057 ;; Remove unwanted extra lines.
2059 (goto-char (point-min))
2061 (re-search-forward "^@menu")
2063 (insert "\n") ; Ensure at least one blank line.
2064 (delete-blank-lines)
2066 (re-search-forward "^@end menu")
2068 (insert "\n") ; Ensure at least one blank line.
2069 (delete-blank-lines))
2071 (message "Multiple files updated."))
2074 ;;; Place `provide' at end of file.
2075 (provide 'texnfo-upd
)
2077 ;;; texnfo-upd.el ends here