107
|
1 ;;;; texnfo-upd.el
|
|
2 ;;;; A utility for updating nodes and menus in Texinfo files.
|
|
3
|
140
|
4 ;;;; Version 2.00 14 Dec 1990
|
107
|
5
|
|
6 ;;;; Copyright 1989, 1990 Free Software Foundation
|
|
7
|
|
8 ;; This file is part of GNU Emacs.
|
|
9
|
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
11 ;; it under the terms of the GNU General Public License as published by
|
|
12 ;; the Free Software Foundation; either version 1, or (at your option)
|
|
13 ;; any later version.
|
|
14
|
|
15 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18 ;; GNU General Public License for more details.
|
|
19
|
|
20 ;; You should have received a copy of the GNU General Public License
|
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
23
|
|
24
|
|
25 ;;;; Summary
|
|
26
|
|
27 ; (Much of the following commentary ought eventually be incorporated
|
|
28 ; into the Texinfo Manual.)
|
|
29
|
|
30 ; The node and menu updating functions automatically
|
|
31
|
|
32 ; * insert missing `@node' lines,
|
|
33 ; * insert the `Next', `Previous' and `Up' pointers of a node,
|
|
34 ; * insert or update the menu for a section,
|
|
35 ; * create a master menu for a Texinfo source file.
|
|
36
|
|
37 ; Passed an argument, the `texinfo-update-node' and
|
|
38 ; `texinfo-make-menu' functions do their jobs in the region.
|
|
39
|
|
40 ; These functions replace doing these jobs by hand.
|
|
41 ; You may find them helpful.
|
|
42
|
|
43 ; In brief, the functions for creating or updating nodes and menus, are:
|
|
44 ;
|
|
45 ; texinfo-update-node (&optional region-p)
|
|
46 ; texinfo-every-node-update ()
|
|
47 ; texinfo-sequential-node-update (&optional region-p)
|
|
48 ;
|
|
49 ; texinfo-make-menu (&optional region-p)
|
|
50 ; texinfo-all-menus-update ()
|
|
51 ; texinfo-master-menu ()
|
|
52 ;
|
|
53 ; texinfo-insert-node-lines (&optional title-p)
|
|
54 ;
|
|
55 ; texinfo-indent-menu-description (column &optional region-p)
|
|
56
|
|
57 ; The `texinfo-column-for-description' variable specifies the column to
|
|
58 ; which menu descriptions are indented.
|
|
59
|
|
60 ; Texinfo file structure
|
|
61 ; ----------------------
|
|
62
|
|
63 ; To use the updating commands, you must structure your Texinfo file
|
|
64 ; hierarchically. Each `@node' line, with the exception of the top
|
|
65 ; node, must be accompanied by some kind of section line, such as an
|
|
66 ; `@chapter' or `@section' line. Each node-line/section-line
|
|
67 ; combination must look like this:
|
|
68
|
|
69 ; @node Lists and Tables, Cross References, Structuring, Top
|
|
70 ; @comment node-name, next, previous, up
|
|
71 ; @chapter Making Lists and Tables
|
|
72
|
|
73 ; or like this (without the `@comment' line):
|
|
74
|
|
75 ; @node Lists and Tables, Cross References, Structuring, Top
|
|
76 ; @chapter Making Lists and Tables
|
|
77
|
|
78 ; If the file has a `top' node, it must be called `top' or `Top' and
|
|
79 ; be the first node in the file.
|
|
80
|
|
81
|
|
82 ;;;; The updating functions in detail
|
|
83 ; --------------------------------
|
|
84
|
|
85 ; The `texinfo-update-node' function without an argument inserts
|
|
86 ; the correct next, previous and up pointers for the node in which
|
|
87 ; point is located (i.e., for the node preceding point).
|
|
88
|
|
89 ; With an argument, the `texinfo-update-node' function inserts the
|
|
90 ; correct next, previous and up pointers for the nodes inside the
|
|
91 ; region.
|
|
92
|
|
93 ; It does not matter whether the `@node' line has pre-existing
|
|
94 ; `Next', `Previous', or `Up' pointers in it. They are removed.
|
|
95
|
|
96 ; The `texinfo-every-node-update' function runs `texinfo-update-node'
|
|
97 ; on the whole buffer.
|
|
98
|
|
99 ; The `texinfo-update-node' function inserts the immediately following
|
|
100 ; and preceding node into the `Next' or `Previous' pointers regardless
|
|
101 ; of their hierarchical level. This is only useful for certain kinds
|
|
102 ; of text, like a novel, which you go through sequentially.
|
|
103
|
|
104 ; The `texinfo-make-menu' function without an argument creates or
|
|
105 ; updates a menu for the section encompassing the node that follows
|
|
106 ; point. With an argument, it makes or updates menus for the nodes
|
|
107 ; within or part of the marked region.
|
|
108
|
|
109 ; Whenever an existing menu is updated, the descriptions from
|
|
110 ; that menu are incorporated into the new menu. This is done by copying
|
|
111 ; descriptions from the existing menu to the entries in the new menu
|
|
112 ; that have the same node names. If the node names are different, the
|
|
113 ; descriptions are not copied to the new menu.
|
|
114
|
|
115 ; Menu entries that refer to other Info files are removed since they
|
|
116 ; are not a node within current buffer. This is a deficiency.
|
|
117
|
|
118 ; The `texinfo-all-menus-update' function runs `texinfo-make-menu'
|
|
119 ; on the whole buffer.
|
|
120
|
|
121 ; The `texinfo-master-menu' function creates an extended menu located
|
|
122 ; after the top node. (The file must have a top node.) The function
|
|
123 ; first updates all the regular menus in the buffer (incorporating the
|
|
124 ; descriptions from pre-existing menus), and then constructs a master
|
|
125 ; menu that includes every entry from every other menu. (However, the
|
|
126 ; function cannot update an already existing master menu; if one
|
|
127 ; exists, it must be removed before calling the function.)
|
|
128
|
|
129 ; The `texinfo-indent-menu-description' function indents every
|
|
130 ; description in the menu following point, to the specified column.
|
|
131 ; Non-nil argument (prefix, if interactive) means indent every
|
|
132 ; description in every menu in the region. This function does not
|
|
133 ; indent second and subsequent lines of a multi-line description.
|
|
134
|
|
135 ; The `texinfo-insert-node-lines' function inserts `@node' before the
|
|
136 ; `@chapter', `@section', and such like lines of a region in a Texinfo
|
|
137 ; file where the `@node' lines are missing.
|
|
138 ;
|
|
139 ; With a non-nil argument (prefix, if interactive), the function not
|
|
140 ; only inserts `@node' lines but also inserts the chapter or section
|
|
141 ; titles as the names of the corresponding nodes; and inserts titles
|
|
142 ; as node names in pre-existing `@node' lines that lack names.
|
|
143 ;
|
|
144 ; Since node names should be more concise than section or chapter
|
|
145 ; titles, node names so inserted will need to be edited manually.
|
|
146
|
|
147
|
|
148 ;;;; Menu Making Functions
|
|
149
|
|
150 (defun texinfo-make-menu (&optional region-p)
|
|
151 "Without any prefix argument, make or update a menu.
|
|
152 Make the menu for the section enclosing the node found following point.
|
|
153
|
|
154 Non-nil argument (prefix, if interactive) means make or update menus
|
|
155 for nodes within or part of the marked region.
|
|
156
|
|
157 Whenever a menu exists, and is being updated, the descriptions that
|
|
158 are associated with node names in the pre-existing menu are
|
|
159 incorporated into the new menu. Otherwise, the nodes' section titles
|
|
160 are inserted as descriptions."
|
|
161
|
|
162 (interactive "P")
|
|
163 (if (not region-p)
|
|
164 (let ((level (texinfo-hierarchic-level)))
|
|
165 (texinfo-make-one-menu level)
|
|
166 (message "Done...updated the menu. You may save the buffer."))
|
|
167 ;; else
|
|
168 (message "Making or updating menus... ")
|
|
169 (let ((beginning (region-beginning))
|
|
170 (region-end (region-end))
|
|
171 (level (progn ; find section type following point
|
|
172 (goto-char (region-beginning))
|
|
173 (texinfo-hierarchic-level))))
|
|
174 (if (= region-end beginning)
|
|
175 (error "Please mark a region!"))
|
|
176 (save-excursion
|
|
177 (save-restriction
|
|
178 (widen)
|
|
179
|
|
180 (while (texinfo-find-lower-level-node level region-end)
|
|
181 (setq level (texinfo-hierarchic-level)) ; new, lower level
|
|
182 (texinfo-make-one-menu level))
|
|
183
|
|
184 (while (and (< (point) region-end)
|
|
185 (texinfo-find-higher-level-node level region-end))
|
|
186 (setq level (texinfo-hierarchic-level))
|
|
187 (while (texinfo-find-lower-level-node level region-end)
|
|
188 (setq level (texinfo-hierarchic-level)) ; new, lower level
|
|
189 (texinfo-make-one-menu level))))))
|
|
190 (message "Done...updated menus. You may save the buffer.")))
|
|
191
|
|
192 (defun texinfo-make-one-menu (level)
|
|
193 "Make a menu of all the appropriate nodes in this section.
|
|
194 `Appropriate nodes' are those associated with sections that are
|
|
195 at the level specified by LEVEL. Point is left at the end of menu."
|
|
196 (let*
|
|
197 ((case-fold-search t)
|
143
|
198 (beginning
|
|
199 (save-excursion
|
|
200 (goto-char (texinfo-update-menu-region-beginning level))
|
|
201 (end-of-line)
|
|
202 (point)))
|
107
|
203 (end (texinfo-update-menu-region-end level))
|
|
204 (first (texinfo-menu-first-node beginning end))
|
|
205 (node-name (progn
|
|
206 (goto-char beginning)
|
|
207 (texinfo-copy-node-name)))
|
|
208 (new-menu-list (texinfo-make-menu-list beginning end level)))
|
|
209 (if (texinfo-old-menu-p beginning first)
|
|
210 (progn
|
|
211 (texinfo-incorporate-descriptions new-menu-list)
|
|
212 (texinfo-delete-old-menu beginning first)))
|
|
213 (texinfo-insert-menu new-menu-list node-name)))
|
|
214
|
|
215 (defun texinfo-all-menus-update (&optional update-all-nodes-p)
|
|
216 "Update every regular menu in a Texinfo file.
|
|
217 You must remove the detailed part of a pre-existing master menu before
|
|
218 running this command, lest it be partly duplicated.
|
|
219
|
|
220 If called with a non-nil argument, this function first updates all the
|
|
221 nodes in the buffer before updating the menus."
|
|
222 (interactive "P")
|
|
223 (save-excursion
|
|
224 (mark-whole-buffer)
|
|
225 (message "Checking for a master menu... ")
|
|
226 (save-excursion
|
|
227 (if (re-search-forward texinfo-master-menu-header nil t)
|
|
228 (error
|
|
229 "Please remove existing master menu, lest it be partly duplicated!")))
|
|
230
|
|
231 (if update-all-nodes-p
|
|
232 (progn
|
|
233 (message "First updating all nodes... ")
|
|
234 (sleep-for 2)
|
|
235 (mark-whole-buffer)
|
|
236 (texinfo-update-node t)))
|
|
237
|
|
238 (message "Updating all menus... ")
|
|
239 (sleep-for 2)
|
|
240 (texinfo-make-menu t)
|
|
241 (message "Done...updated all the menus. You may save the buffer.")))
|
|
242
|
|
243 (defun texinfo-find-lower-level-node (level region-end)
|
|
244 "Search forward from point for node at any level lower than LEVEL.
|
|
245 Search is limited to the end of the marked region, REGION-END,
|
|
246 and to the end of the menu region for the level.
|
|
247
|
|
248 Return t if the node is found, else nil. Leave point at the beginning
|
|
249 of the node if one is found; else do not move point."
|
|
250
|
|
251 (if (and (< (point) region-end)
|
|
252 (re-search-forward
|
|
253 (concat
|
|
254 "\\(^@node\\).*\n" ; match node line
|
|
255 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
|
|
256 "\\|" ; or
|
|
257 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
|
|
258 (eval (cdr (assoc level texinfo-update-menu-lower-regexps))))
|
|
259 ;; the next higher level node marks the end of this
|
|
260 ;; section, and no lower level node will be found beyond
|
|
261 ;; this position even if region-end is farther off
|
|
262 (texinfo-update-menu-region-end level)
|
|
263 t))
|
|
264 (goto-char (match-beginning 1))))
|
|
265
|
|
266 (defun texinfo-find-higher-level-node (level region-end)
|
|
267 "Search forward from point for node at any higher level than argument LEVEL.
|
|
268 Search is limited to the end of the marked region, REGION-END.
|
|
269
|
|
270 Return t if the node is found, else nil. Leave point at the beginning
|
|
271 of the node if one is found; else do not move point."
|
|
272
|
|
273 (if (and (< (point) region-end)
|
|
274 (re-search-forward
|
|
275 (concat
|
|
276 "\\(^@node\\).*\n" ; match node line
|
|
277 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
|
|
278 "\\|" ; or
|
|
279 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
|
|
280 (eval ; (won't ever find a `top' node)
|
|
281 (cdr (assoc level texinfo-update-menu-higher-regexps))))
|
|
282 nil
|
|
283 t))
|
|
284 (goto-char (match-beginning 1))))
|
|
285
|
|
286
|
|
287 ;;;; Making the list of new menu entries
|
|
288
|
|
289 (defun texinfo-make-menu-list (beginning end level)
|
|
290 "Make a list of node names and their descriptions.
|
|
291 Point is left at the end of the menu region, but the menu is not inserted.
|
|
292
|
|
293 First argument is position from which to start making menu list;
|
|
294 second argument is end of region in which to try to locate entries;
|
|
295 third argument is the level of the nodes that are the entries.
|
|
296
|
|
297 Node names and descriptions are dotted pairs of strings. Each pair is
|
|
298 an element of the list. If the description does not exist, the
|
|
299 element consists only of the node name."
|
|
300 (goto-char beginning)
|
|
301 (let (new-menu-list)
|
|
302 (while (texinfo-menu-locate-entry-p level end)
|
|
303 (setq new-menu-list
|
|
304 (cons (cons
|
|
305 (texinfo-copy-node-name)
|
|
306 (texinfo-copy-section-title))
|
|
307 new-menu-list)))
|
|
308 (reverse new-menu-list)))
|
|
309
|
|
310 (defun texinfo-menu-locate-entry-p (level search-end)
|
|
311 "Find a node that will be part of menu for this section.
|
|
312 First argument is a string such as \"section\" specifying the general
|
|
313 hierarchical level of the menu; second argument is a postion
|
|
314 specifying the end of the search.
|
|
315
|
|
316 The function returns t if the node is found, else nil. It searches
|
|
317 forward from point, and leaves point at the beginning of the node.
|
|
318
|
|
319 The function finds entries of the same type. Thus `subsections' and
|
|
320 `unnumberedsubsecs' will appear in the same menu."
|
|
321 (if (re-search-forward
|
|
322 (concat
|
|
323 "\\(^@node\\).*\n" ; match node line
|
|
324 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
|
|
325 "\\|" ; or
|
|
326 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
|
|
327 (eval
|
|
328 (cdr (assoc level texinfo-update-menu-same-level-regexps))))
|
|
329 search-end
|
|
330 t)
|
|
331 (goto-char (match-beginning 1))))
|
|
332
|
|
333 (defun texinfo-copy-node-name ()
|
|
334 "Return the node name as a string.
|
|
335
|
|
336 Start with point at the beginning of the node line; copy the text
|
|
337 after the node command up to the first comma on the line, if any, and
|
|
338 return the text as a string. Leaves point at the beginning of the
|
|
339 line. If there is no node name, returns an empty string."
|
|
340
|
|
341 (save-excursion
|
|
342 (buffer-substring
|
|
343 (progn (forward-word 1) ; skip over node command
|
|
344 (skip-chars-forward " \t") ; and over spaces
|
|
345 (point))
|
|
346 (if (search-forward
|
|
347 ","
|
|
348 (save-excursion (end-of-line) (point)) t) ; bound search
|
|
349 (1- (point))
|
|
350 (end-of-line) (point)))))
|
|
351
|
|
352 (defun texinfo-copy-section-title ()
|
|
353 "Return the title of the section as a string.
|
|
354 The title is used as a description line in the menu when one does not
|
|
355 already exist.
|
|
356
|
|
357 Move point to the beginning of the appropriate section line by going
|
|
358 to the start of the text matched by last regexp searched for, which
|
|
359 must have been done by `texinfo-menu-locate-entry-p'."
|
|
360
|
|
361 ;; could use the same re-search as in `texinfo-menu-locate-entry-p'
|
|
362 ;; instead of using `match-beginning'; such a variation would be
|
|
363 ;; more general, but would waste information already collected
|
|
364
|
|
365 (goto-char (match-beginning 7)) ; match section name
|
|
366
|
|
367 (buffer-substring
|
|
368 (progn (forward-word 1) ; skip over section type
|
|
369 (skip-chars-forward " \t") ; and over spaces
|
|
370 (point))
|
|
371 (progn (end-of-line) (point))))
|
|
372
|
|
373
|
|
374 ;;;; Handling the old menu
|
|
375
|
|
376 (defun texinfo-old-menu-p (beginning first)
|
|
377 "Move point to the beginning of the menu for this section, if any.
|
|
378 Otherwise move point to the end of the first node of this section.
|
|
379 Return t if a menu is found, nil otherwise.
|
|
380
|
|
381 First argument is the position of the beginning of the section in which
|
|
382 the menu will be located; second argument is the position of the first
|
|
383 node within the section.
|
|
384
|
|
385 If no menu is found, the function inserts two newlines just before the
|
|
386 end of the section, and leaves point there where a menu ought to be."
|
|
387 (goto-char beginning)
|
|
388 (if (not (re-search-forward "^@menu" first 'goto-end))
|
|
389 (progn (insert "\n\n") (forward-line -2) nil)
|
|
390 t))
|
|
391
|
|
392 (defun texinfo-incorporate-descriptions (new-menu-list)
|
|
393 "Copy the old menu line descriptions that exist to the new menu.
|
|
394
|
|
395 Point must be at beginning of old menu.
|
|
396
|
|
397 If the node-name of the new menu entry cannot be found in the old
|
|
398 menu, use the new section title for the description, but if the
|
|
399 node-name of the new menu is found in the old menu, replace the
|
|
400 section title with the old description, whatever it may be.
|
|
401
|
|
402 For this function, the new menu is a list made up of lists of dotted
|
|
403 pairs in which the first element of the pair is the node name and the
|
|
404 second element the description. The new menu is changed destructively.
|
|
405 The old menu is the menu as it appears in the texinfo file."
|
|
406
|
|
407 (let ((new-menu-list-pointer new-menu-list)
|
|
408 (end-of-menu (texinfo-menu-end)))
|
|
409 (while new-menu-list
|
|
410 (save-excursion ; keep point at beginning of menu
|
|
411 (if (search-forward
|
|
412 (concat "\* " ; so only menu entries are found
|
|
413 (car (car new-menu-list))
|
|
414 ":") ; so only complete entries are found
|
|
415 end-of-menu
|
|
416 t)
|
|
417 (setcdr (car new-menu-list)
|
|
418 (texinfo-menu-copy-old-description end-of-menu))))
|
|
419 (setq new-menu-list (cdr new-menu-list)))
|
|
420 (setq new-menu-list new-menu-list-pointer)))
|
|
421
|
|
422 (defun texinfo-menu-copy-old-description (end-of-menu)
|
|
423 "Return description field of old menu line as string.
|
|
424 Point must be located just after the node name. Point left before description.
|
|
425 Single argument, END-OF-MENU, is position limiting search."
|
|
426 (skip-chars-forward "[:.,\t\n ]+")
|
|
427 ;; don't copy a carriage return at line beginning with asterisk!
|
|
428 ;; do copy a description that begins with an `@'!
|
|
429 (if (and (looking-at "\\(\\w+\\|@\\)")
|
|
430 (not (looking-at "\\(^\\* \\|^@end menu\\)")))
|
|
431 (buffer-substring
|
|
432 (point)
|
|
433 (save-excursion
|
|
434 (re-search-forward "\\(^\\* \\|^@end menu\\)" end-of-menu t)
|
|
435 (forward-line -1)
|
|
436 (end-of-line) ; go to end of last description line
|
|
437 (point)))
|
|
438 ""))
|
|
439
|
|
440 (defun texinfo-menu-end ()
|
|
441 "Return position of end of menu. Does not change location of point.
|
|
442 Signal an error if not end of menu."
|
|
443 (save-excursion
|
|
444 (if (re-search-forward "^@end menu" nil t)
|
|
445 (point)
|
|
446 (error "Menu does not have an end."))))
|
|
447
|
|
448 (defun texinfo-delete-old-menu (beginning first)
|
|
449 "Delete the old menu. Point must be in or after menu.
|
|
450 First argument is position of the beginning of the section in which
|
|
451 the menu will be located; second argument is the position of the first
|
|
452 node within the section."
|
|
453 ;; No third arg to search, so error if search fails.
|
|
454 (re-search-backward "^@menu" beginning)
|
|
455 (delete-region (point)
|
|
456 (save-excursion
|
|
457 (re-search-forward "^@end menu" first)
|
|
458 (point))))
|
|
459
|
|
460
|
|
461 ;;;; Inserting new menu
|
|
462
|
|
463 ;; try 32, but perhaps 24 is better
|
|
464 (defvar texinfo-column-for-description 32
|
|
465 "*Column at which descriptions start in a Texinfo menu.")
|
|
466
|
|
467 (defun texinfo-insert-menu (menu-list node-name)
|
|
468 "Insert formatted menu at point.
|
|
469 Indents the first line of the description, if any, to the value of
|
|
470 texinfo-column-for-description.
|
|
471
|
|
472 MENU-LIST has form:
|
|
473
|
|
474 \(\(\"node-name1\" . \"description\"\)
|
|
475 \(\"node-name\" . \"description\"\) ... \)
|
|
476
|
|
477 However, there does not need to be a description field."
|
|
478
|
|
479 (insert "@menu\n")
|
|
480 (while menu-list
|
|
481 (if (cdr (car menu-list)) ; menu-list has description entry
|
|
482 (progn
|
|
483 (insert
|
|
484 (format "* %s::" (car (car menu-list)))) ; node-name entry
|
|
485 (indent-to texinfo-column-for-description 2)
|
|
486 (insert
|
|
487 (format "%s\n" (cdr (car menu-list))))) ; description entry
|
|
488 ;; else menu-list lacks description entry
|
|
489 (insert
|
|
490 (format "* %s::\n" (car (car menu-list))))) ; node-name entry
|
|
491 (setq menu-list (cdr menu-list)))
|
|
492 (insert "@end menu")
|
|
493 (message
|
|
494 "Updated \"%s\" level menu following node: %s ... "
|
|
495 level node-name))
|
|
496
|
|
497
|
|
498 ;;;; Handling description indentation
|
|
499
|
|
500 ; Since the make-menu functions indent descriptions, these functions
|
|
501 ; are useful primarily for indenting a single menu specially.
|
|
502
|
|
503 (defun texinfo-indent-menu-description (column &optional region-p)
|
|
504 "Indent every description in menu following point to COLUMN.
|
|
505 Non-nil argument (prefix, if interactive) means indent every
|
|
506 description in every menu in the region. Does not indent second and
|
|
507 subsequent lines of a multi-line description."
|
|
508
|
|
509 (interactive
|
|
510 "nIndent menu descriptions to (column number): \nP")
|
|
511 (save-excursion
|
|
512 (save-restriction
|
|
513 (widen)
|
|
514 (if (not region-p)
|
|
515 (progn
|
|
516 (re-search-forward "^@menu")
|
|
517 (texinfo-menu-indent-description column)
|
|
518 (message
|
|
519 "Indented descriptions in menu. You may save the buffer."))
|
|
520 ;;else
|
|
521 (message "Indenting every menu description in region... ")
|
|
522 (goto-char (region-beginning))
|
|
523 (while (and (< (point) (region-end))
|
|
524 (texinfo-locate-menu-p))
|
|
525 (forward-line 1)
|
|
526 (texinfo-menu-indent-description column))
|
|
527 (message "Indenting done. You may save the buffer.")))))
|
|
528
|
|
529 (defun texinfo-menu-indent-description (to-column-number)
|
|
530 "Indent the Texinfo file menu description to TO-COLUMN-NUMBER.
|
|
531 Start with point just after the word `menu' in the `@menu' line and
|
|
532 leave point on the line before the `@end menu' line. Does not indent
|
|
533 second and subsequent lines of a multi-line description."
|
|
534 (let* ((beginning-of-next-line (point)))
|
|
535 (while (< beginning-of-next-line
|
|
536 (save-excursion ; beginning of end menu line
|
|
537 (goto-char (texinfo-menu-end))
|
|
538 (beginning-of-line)
|
|
539 (point)))
|
|
540 (if (search-forward "::" (texinfo-menu-end) t)
|
|
541 (progn
|
|
542 (let ((beginning-white-space (point)))
|
|
543 (skip-chars-forward " \t") ; skip over spaces
|
|
544 (if (looking-at "\\(@\\|\\w\\)+") ; if there is text
|
|
545 (progn
|
|
546 ;; remove pre-existing indentation
|
|
547 (delete-region beginning-white-space (point))
|
|
548 (indent-to-column to-column-number))))))
|
|
549 ;; position point at beginning of next line
|
|
550 (forward-line 1)
|
|
551 (setq beginning-of-next-line (point)))))
|
|
552
|
|
553
|
|
554 ;;;; Making the master menu
|
|
555
|
|
556 (defun texinfo-master-menu (update-all-nodes-menus-p)
|
|
557 "Make a master menu for a whole Texinfo file.
|
|
558 Non-nil argument (prefix, if interactive) means first update all
|
|
559 existing nodes and menus. Remove pre-existing master menu, if there is one.
|
|
560
|
|
561 This function creates a master menu that follows the top node. The
|
|
562 master menu includes every entry from all the other menus. It
|
|
563 replaces any existing ordinary menu that follows the top node.
|
|
564
|
|
565 If called with a non-nil argument, this function first updates all the
|
|
566 menus in the buffer (incorporating descriptions from pre-existing
|
|
567 menus) before it constructs the master menu.
|
|
568
|
|
569 The function removes the detailed part of an already existing master
|
|
570 menu. This action depends on the pre-exisitng master menu using the
|
|
571 standard `texinfo-master-menu-header'.
|
|
572
|
|
573 The master menu has the following format, which is adapted from the
|
|
574 recommendation in the Texinfo Manual:
|
|
575
|
|
576 * The first part contains the major nodes in the Texinfo file: the
|
|
577 nodes for the chapters, chapter-like sections, and the major
|
|
578 appendices. This includes the indices, so long as they are in
|
|
579 chapter-like sections, such as unnumbered sections.
|
|
580
|
|
581 * The second and subsequent parts contain a listing of the other,
|
|
582 lower level menus, in order. This way, an inquirer can go
|
|
583 directly to a particular node if he or she is searching for
|
|
584 specific information.
|
|
585
|
|
586 Each of the menus in the detailed node listing is introduced by the
|
|
587 title of the section containing the menu."
|
|
588
|
|
589 (interactive "P")
|
|
590 (widen)
|
|
591 (goto-char (point-min))
|
|
592
|
|
593 ;; Move point to location after `top'.
|
143
|
594 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
|
107
|
595 (error "This buffer needs a Top node!"))
|
|
596
|
|
597 (let ((first-chapter
|
|
598 (save-excursion (re-search-forward "^@node") (point))))
|
|
599 (if (re-search-forward texinfo-master-menu-header first-chapter t)
|
|
600 ;; Remove detailed master menu listing
|
|
601 (progn
|
|
602 (goto-char (match-beginning 0))
|
|
603 (let ((end-of-detailed-menu-descriptions
|
|
604 (save-excursion ; beginning of end menu line
|
|
605 (goto-char (texinfo-menu-end))
|
|
606 (beginning-of-line) (forward-char -1)
|
|
607 (point))))
|
|
608 (delete-region (point) end-of-detailed-menu-descriptions)))))
|
|
609
|
|
610 (if update-all-nodes-menus-p
|
|
611 (progn
|
|
612 (message "Making a master menu...first updating all nodes... ")
|
|
613 (sleep-for 2)
|
|
614 (mark-whole-buffer)
|
|
615 (texinfo-update-node t)
|
|
616
|
|
617 (message "Updating all menus... ")
|
|
618 (sleep-for 2)
|
|
619 (mark-whole-buffer)
|
|
620 (texinfo-make-menu t)))
|
|
621
|
|
622 (message "Now making the master menu... ")
|
|
623 (sleep-for 2)
|
|
624 (goto-char (point-min))
|
|
625 (texinfo-insert-master-menu-list
|
|
626 (texinfo-master-menu-list))
|
|
627
|
|
628 ;; Remove extra newlines that texinfo-insert-master-menu-list
|
|
629 ;; may have inserted.
|
|
630
|
|
631 (save-excursion
|
|
632 (goto-char (point-min))
|
|
633
|
|
634 (re-search-forward texinfo-master-menu-header)
|
|
635 (goto-char (match-beginning 0))
|
|
636 (insert "\n")
|
|
637 (delete-blank-lines)
|
|
638
|
|
639 (re-search-backward "^@menu")
|
|
640 (forward-line -1)
|
|
641 (delete-blank-lines)
|
|
642
|
|
643 (re-search-forward "^@end menu")
|
|
644 (forward-line 1)
|
|
645 (delete-blank-lines))
|
|
646
|
|
647 (message "Done...completed making master menu. You may save the buffer."))
|
|
648
|
|
649 (defun texinfo-master-menu-list ()
|
|
650 "Return a list of menu entries and header lines for the master menu.
|
|
651
|
|
652 Start with the menu for chapters and indices and then find each
|
|
653 following menu and the title of the node preceding that menu.
|
|
654
|
|
655 The master menu list has this form:
|
|
656
|
|
657 \(\(\(... \"entry-1-2\" \"entry-1\"\) \"title-1\"\)
|
|
658 \(\(... \"entry-2-2\" \"entry-2-1\"\) \"title-2\"\)
|
|
659 ...\)
|
|
660
|
|
661 However, there does not need to be a title field."
|
|
662
|
|
663 (let (master-menu-list)
|
|
664 (while (texinfo-locate-menu-p)
|
|
665 (setq master-menu-list
|
|
666 (cons (list
|
|
667 (texinfo-copy-menu)
|
|
668 (texinfo-copy-menu-title))
|
|
669 master-menu-list)))
|
|
670 (reverse master-menu-list)))
|
|
671
|
|
672 (defun texinfo-insert-master-menu-list (master-menu-list)
|
|
673 "Format and insert the master menu in the current buffer."
|
|
674 (goto-char (point-min))
|
|
675 (re-search-forward "^@menu")
|
|
676 (beginning-of-line)
|
|
677 (delete-region (point) ; buffer must have ordinary top menu
|
|
678 (save-excursion
|
|
679 (re-search-forward "^@end menu")
|
|
680 (point)))
|
|
681
|
|
682 (save-excursion ; leave point at beginning of menu
|
|
683 ;; Handle top of menu
|
|
684 (insert "\n@menu\n")
|
|
685 ;; Insert chapter menu entries
|
|
686 (setq this-very-menu-list (reverse (car (car master-menu-list))))
|
|
687 ;;; Tell user what is going on.
|
|
688 (message "Inserting chapter menu entry: %s ... " this-very-menu-list)
|
|
689 (while this-very-menu-list
|
|
690 (insert "* " (car this-very-menu-list) "\n")
|
|
691 (setq this-very-menu-list (cdr this-very-menu-list)))
|
|
692
|
|
693 (setq master-menu-list (cdr master-menu-list))
|
|
694
|
|
695 (insert texinfo-master-menu-header)
|
|
696
|
|
697 ;; Now, insert all the other menus
|
|
698
|
|
699 ;; The menu master-menu-list has a form like this:
|
|
700 ;; ((("beta" "alpha") "title-A")
|
|
701 ;; (("delta" "gamma") "title-B"))
|
|
702
|
|
703 (while master-menu-list
|
|
704
|
|
705 (message
|
|
706 "Inserting menu for %s .... " (car (cdr (car master-menu-list))))
|
|
707 ;; insert title of menu section
|
|
708 (insert "\n" (car (cdr (car master-menu-list))) "\n\n")
|
|
709
|
|
710 ;; insert each menu entry
|
|
711 (setq this-very-menu-list (reverse (car (car master-menu-list))))
|
|
712 (while this-very-menu-list
|
|
713 (insert "* " (car this-very-menu-list) "\n")
|
|
714 (setq this-very-menu-list (cdr this-very-menu-list)))
|
|
715
|
|
716 (setq master-menu-list (cdr master-menu-list)))
|
|
717
|
|
718 ;; Finish menu
|
|
719 (insert "@end menu\n\n")))
|
|
720
|
|
721 (defvar texinfo-master-menu-header
|
|
722 "\n --- The Detailed Node Listing ---\n"
|
|
723 "String inserted before lower level entries in Texinfo master menu.
|
|
724 It comes after the chapter-level menu entries.")
|
|
725
|
|
726 (defun texinfo-locate-menu-p ()
|
|
727 "Find the next menu in the texinfo file.
|
|
728 If found, leave point after word `menu' on the `@menu' line, and return t.
|
|
729 If a menu is not found, do not move point and return nil."
|
|
730 (re-search-forward "\\(^@menu\\)" nil t))
|
|
731
|
|
732 (defun texinfo-copy-menu-title ()
|
|
733 "Return the title of the section preceding the menu as a string.
|
|
734 If such a title cannot be found, return an empty string. Do not move
|
|
735 point."
|
|
736 (save-excursion
|
|
737 (if (re-search-backward
|
|
738 (concat
|
|
739 "\\(^@node\\).*\n" ; match node line
|
|
740 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
|
|
741 "\\|" ; or
|
|
742 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
|
|
743 (eval
|
|
744 (cdr
|
|
745 (assoc (texinfo-hierarchic-level)
|
|
746 texinfo-update-menu-higher-regexps))))
|
|
747 nil
|
|
748 t)
|
|
749 (texinfo-copy-section-title)
|
|
750 " ")))
|
|
751
|
|
752 (defun texinfo-copy-menu ()
|
|
753 "Return the entries of an existing menu as a list.
|
|
754 Start with point just after the word `menu' in the `@menu' line
|
|
755 and leave point on the line before the `@end menu' line."
|
|
756 (let* (this-menu-list
|
|
757 (end-of-menu (texinfo-menu-end)) ; position of end of `@end menu'
|
|
758 (last-entry (save-excursion ; position of beginning of
|
|
759 ; last `* ' entry
|
|
760 (goto-char end-of-menu)
|
|
761 (re-search-backward "^\* ") ; handle multi-line desc.
|
|
762 (point))))
|
|
763 (while (< (point) last-entry)
|
|
764 (if (re-search-forward "^\* " end-of-menu t)
|
|
765 (progn
|
|
766 (setq this-menu-list
|
|
767 (cons
|
|
768 (buffer-substring
|
|
769 (point)
|
|
770 ;; copy multi-line descriptions
|
|
771 (save-excursion
|
|
772 (re-search-forward "\\(^\* \\|^@e\\)" nil t)
|
|
773 (- (point) 3)))
|
|
774 this-menu-list)))))
|
|
775 this-menu-list))
|
|
776
|
|
777
|
|
778 ;;;; Determining the hierarchical level in the texinfo file
|
|
779
|
|
780 (defun texinfo-specific-section-type ()
|
|
781 "Return the specific type of next section, as a string.
|
|
782 For example, \"unnumberedsubsec\". Return \"top\" for top node.
|
|
783
|
|
784 Searches forward for a section. Hence, point must be before the
|
|
785 section whose type will be found. Does not move point. Signal an
|
|
786 error if the node is not the top node and a section is not found."
|
|
787 (save-excursion
|
|
788 (cond
|
143
|
789 ((re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)"
|
|
790 (save-excursion
|
|
791 (end-of-line)
|
|
792 (point))
|
|
793 t)
|
107
|
794 "top")
|
|
795 ((re-search-forward texinfo-section-types-regexp nil t)
|
|
796 (buffer-substring (progn (beginning-of-line) ; copy its name
|
|
797 (1+ (point)))
|
|
798 (progn (forward-word 1)
|
|
799 (point))))
|
|
800 (t
|
|
801 (error
|
|
802 "texinfo-specific-section-type: Chapter or section not found.")))))
|
|
803
|
|
804 (defun texinfo-hierarchic-level ()
|
|
805 "Return the general hierarchal level of the next node in a texinfo file.
|
|
806 Thus, a subheading or appendixsubsec is of type subsection."
|
|
807 (cdr (assoc
|
|
808 (texinfo-specific-section-type)
|
|
809 texinfo-section-to-generic-alist)))
|
|
810
|
|
811
|
|
812 ;;;; Locating the major positions
|
|
813
|
|
814 (defun texinfo-update-menu-region-beginning (level)
|
|
815 "Locate beginning of higher level section this section is within.
|
|
816 Return position of the beginning of the node line; do not move point.
|
|
817 Thus, if this level is subsection, searches backwards for section node.
|
|
818 Only argument is a string of the general type of section."
|
|
819
|
|
820 (cond
|
143
|
821 ((or (string-equal "top" level)
|
|
822 (string-equal "chapter" level))
|
107
|
823 (save-excursion
|
143
|
824 (goto-char (point-min))
|
|
825 (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t)
|
|
826 (beginning-of-line)
|
107
|
827 (point)))
|
|
828 (t
|
|
829 (save-excursion
|
|
830 (re-search-backward
|
|
831 (concat
|
|
832 "\\(^@node\\).*\n" ; match node line
|
|
833 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
|
|
834 "\\|" ; or
|
|
835 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
|
|
836 (eval
|
|
837 (cdr (assoc level texinfo-update-menu-higher-regexps))))
|
|
838 nil
|
|
839 'goto-beginning)
|
|
840 (point)))))
|
|
841
|
|
842 (defun texinfo-update-menu-region-end (level)
|
|
843 "Locate end of higher level section this section is within.
|
|
844 Return position; do not move point. Thus, if this level is a
|
|
845 subsection, find the node for the section this subsection is within.
|
|
846 If level is top or chapter, returns end of file. Only argument is a
|
|
847 string of the general type of section."
|
|
848
|
|
849 (save-excursion
|
|
850 (if (re-search-forward
|
|
851 (concat
|
|
852 "\\(^@node\\).*\n" ; match node line
|
|
853 "\\(\\(\\(^@c\\).*\n\\)" ; match comment line, if any
|
|
854 "\\|" ; or
|
|
855 "\\(^@ifinfo[ ]*\n\\)\\)?" ; ifinfo line, if any
|
|
856 (eval
|
|
857 (cdr (assoc level texinfo-update-menu-higher-regexps))))
|
|
858 nil
|
|
859 'goto-end)
|
|
860 (match-beginning 1)
|
|
861 (point-max))))
|
|
862
|
|
863 (defun texinfo-menu-first-node (beginning end)
|
|
864 "Locate first node of the section the menu will be placed in.
|
|
865 Return position; do not move point.
|
|
866 The menu will be located just before this position.
|
|
867
|
|
868 First argument is the position of the beginning of the section in
|
|
869 which the menu will be located; second argument is the position of the
|
|
870 end of that region; it limits the search."
|
|
871
|
|
872 (save-excursion
|
|
873 (goto-char beginning)
|
|
874 (forward-line 1)
|
|
875 (re-search-forward "^@node" end t)
|
|
876 (beginning-of-line)
|
|
877 (point)))
|
|
878
|
|
879
|
|
880 ;;;; Alists and regular expressions for defining hierarchical levels
|
|
881
|
|
882 (defvar texinfo-section-to-generic-alist
|
|
883 '(("top" . "top")
|
|
884
|
|
885 ("chapter" . "chapter")
|
|
886 ("unnumbered" . "chapter")
|
|
887 ("majorheading" . "chapter")
|
|
888 ("chapheading" . "chapter")
|
|
889 ("appendix" . "chapter")
|
|
890
|
|
891 ("section" . "section")
|
|
892 ("unnumberedsec" . "section")
|
|
893 ("heading" . "section")
|
|
894 ("appendixsec" . "section")
|
|
895
|
|
896 ("subsection" . "subsection")
|
|
897 ("unnumberedsubsec" . "subsection")
|
|
898 ("subheading" . "subsection")
|
|
899 ("appendixsubsec" . "subsection")
|
|
900
|
|
901 ("subsubsection" . "subsubsection")
|
|
902 ("unnumberedsubsubsec" . "subsubsection")
|
|
903 ("subsubheading" . "subsubsection")
|
|
904 ("appendixsubsubsec" . "subsubsection"))
|
|
905 "*An alist of specific and corresponding generic Texinfo section types.
|
|
906 The keys are strings specifying specific types of section; the values
|
|
907 are strings of their corresponding general types.")
|
|
908
|
|
909 (defvar texinfo-section-types-regexp
|
|
910 "^@\\(chapter \\|sect\\|sub\\|unnum\\|major\\|chapheading \\|heading \\|appendix\\)"
|
|
911 "Regexp matching chapter, section, other headings (but not the top node).")
|
|
912
|
|
913 (defvar texinfo-chapter-level-regexp
|
|
914 "chapter\\|unnumbered \\|appendix \\|majorheading\\|chapheading"
|
|
915 "Regular expression matching just the Texinfo chapter level headings.")
|
|
916
|
|
917 (defvar texinfo-section-level-regexp
|
|
918 "section\\|unnumberedsec\\|heading \\|appendixsec"
|
|
919 "Regular expression matching just the Texinfo section level headings.")
|
|
920
|
|
921 (defvar texinfo-subsection-level-regexp
|
|
922 "subsection\\|unnumberedsubsec\\|subheading\\|appendixsubsec"
|
|
923 "Regular expression matching just the Texinfo subsection level headings.")
|
|
924
|
|
925 (defvar texinfo-subsubsection-level-regexp
|
|
926 "subsubsection\\|unnumberedsubsubsec\\|subsubheading\\|appendixsubsubsec"
|
|
927 "Regular expression matching just the Texinfo subsubsection level headings.")
|
|
928
|
|
929 (defvar texinfo-update-menu-same-level-regexps
|
|
930 '(("top" . "top[ \t]+")
|
|
931 ("chapter" .
|
|
932 (concat "\\(^@\\)\\(" texinfo-chapter-level-regexp "\\)[ \t]*"))
|
|
933 ("section" .
|
|
934 (concat "\\(^@\\)\\(" texinfo-section-level-regexp "\\)[ \t]*"))
|
|
935 ("subsection" .
|
|
936 (concat "\\(^@\\)\\(" texinfo-subsection-level-regexp "\\)[ \t]+"))
|
|
937 ("subsubsection" .
|
|
938 (concat "\\(^@\\)\\(" texinfo-subsubsection-level-regexp "\\)[ \t]+")))
|
|
939 "*Regexps for searching for same level sections in a Texinfo file.
|
|
940 The keys are strings specifying the general hierarchical level in the
|
|
941 document; the values are regular expressions.")
|
|
942
|
|
943 (defvar texinfo-update-menu-higher-regexps
|
|
944 '(("top" . "^@node [ \t]*DIR")
|
143
|
945 ("chapter" . "^@node [ \t]*top[ \t]*\\(,\\|$\\)")
|
107
|
946 ("section" .
|
|
947 (concat
|
|
948 "\\(^@\\("
|
|
949 texinfo-chapter-level-regexp
|
|
950 "\\)[ \t]*\\)"))
|
|
951 ("subsection" .
|
|
952 (concat
|
|
953 "\\(^@\\("
|
|
954 texinfo-section-level-regexp
|
|
955 "\\|"
|
|
956 texinfo-chapter-level-regexp
|
|
957 "\\)[ \t]*\\)"))
|
|
958 ("subsubsection" .
|
|
959 (concat
|
|
960 "\\(^@\\("
|
|
961 texinfo-subsection-level-regexp
|
|
962 "\\|"
|
|
963 texinfo-section-level-regexp
|
|
964 "\\|"
|
|
965 texinfo-chapter-level-regexp
|
|
966 "\\)[ \t]*\\)")))
|
|
967 "*Regexps for searching for higher level sections in a Texinfo file.
|
|
968 The keys are strings specifying the general hierarchical level in the
|
|
969 document; the values are regular expressions.")
|
|
970
|
|
971 (defvar texinfo-update-menu-lower-regexps
|
|
972 '(("top" .
|
|
973 (concat
|
|
974 "\\(^@\\("
|
|
975 texinfo-chapter-level-regexp
|
|
976 "\\|"
|
|
977 texinfo-section-level-regexp
|
|
978 "\\|"
|
|
979 texinfo-subsection-level-regexp
|
|
980 "\\|"
|
|
981 texinfo-subsubsection-level-regexp
|
|
982 "\\)[ \t]*\\)"))
|
|
983 ("chapter" .
|
|
984 (concat
|
|
985 "\\(^@\\("
|
|
986 texinfo-section-level-regexp
|
|
987 "\\|"
|
|
988 texinfo-subsection-level-regexp
|
|
989 "\\|"
|
|
990 texinfo-subsubsection-level-regexp
|
|
991 "\\)[ \t]*\\)"))
|
|
992 ("section" .
|
|
993 (concat
|
|
994 "\\(^@\\("
|
|
995 texinfo-subsection-level-regexp
|
|
996 "\\|"
|
|
997 texinfo-subsubsection-level-regexp
|
|
998 "\\)[ \t]+\\)"))
|
|
999 ("subsection" .
|
|
1000 (concat
|
|
1001 "\\(^@\\("
|
|
1002 texinfo-subsubsection-level-regexp
|
|
1003 "\\)[ \t]+\\)"))
|
|
1004 ("subsubsection" . "nothing lower"))
|
|
1005 "*Regexps for searching for lower level sections in a Texinfo file.
|
|
1006 The keys are strings specifying the general hierarchical level in the
|
|
1007 document; the values are regular expressions.")
|
|
1008
|
|
1009
|
|
1010 ;;;; Updating a Node
|
|
1011
|
|
1012 (defun texinfo-update-node (&optional region-p)
|
|
1013 "Without any prefix argument, update the node in which point is located.
|
|
1014 Non-nil argument (prefix, if interactive) means update the nodes in the
|
|
1015 marked region.
|
|
1016
|
|
1017 The functions for creating or updating nodes and menus, and their
|
|
1018 keybindings, are:
|
|
1019
|
|
1020 texinfo-update-node (&optional region-p) \\[texinfo-update-node]
|
|
1021 texinfo-every-node-update () \\[texinfo-every-node-update]
|
|
1022 texinfo-sequential-node-update (&optional region-p)
|
|
1023
|
|
1024 texinfo-make-menu (&optional region-p) \\[texinfo-make-menu]
|
|
1025 texinfo-all-menus-update () \\[texinfo-all-menus-update]
|
|
1026 texinfo-master-menu ()
|
|
1027
|
|
1028 texinfo-indent-menu-description (column &optional region-p)
|
|
1029
|
|
1030 The `texinfo-column-for-description' variable specifies the column to
|
|
1031 which menu descriptions are indented. Its default value is 24."
|
|
1032
|
|
1033 (interactive "P")
|
|
1034 (if (not region-p)
|
|
1035 (let ((auto-fill-hook nil)) ; update a single node
|
|
1036 (if (not (re-search-backward "^@node" (point-min) t))
|
|
1037 (error "Node line not found before this position."))
|
|
1038 (texinfo-update-the-node)
|
|
1039 (message "Done...updated the node. You may save the buffer."))
|
|
1040 ;; else
|
|
1041 (let ((auto-fill-hook nil)
|
|
1042 (beginning (region-beginning))
|
|
1043 (end (region-end)))
|
|
1044 (if (= end beginning)
|
|
1045 (error "Please mark a region!"))
|
|
1046 (save-restriction
|
|
1047 (narrow-to-region beginning end)
|
|
1048 (goto-char beginning)
|
|
1049 (push-mark)
|
|
1050 (while (re-search-forward "^@node" (point-max) t)
|
|
1051 (beginning-of-line)
|
|
1052 (texinfo-update-the-node))
|
|
1053 (message "Done...updated nodes in region. You may save the buffer.")))))
|
|
1054
|
|
1055 (defun texinfo-every-node-update ()
|
|
1056 "Update every node in a Texinfo file."
|
|
1057 (interactive)
|
|
1058 (save-excursion
|
|
1059 (mark-whole-buffer)
|
|
1060 (texinfo-update-node t)
|
|
1061 (message "Done...updated every node. You may save the buffer.")))
|
|
1062
|
|
1063 (defun texinfo-update-the-node ()
|
|
1064 "Update one node. Point must be at the beginning of node line.
|
|
1065 Leave point at the end of the node line."
|
|
1066 (texinfo-check-for-node-name)
|
|
1067 (texinfo-delete-existing-pointers)
|
|
1068 (message "Updating node: %s ... " (texinfo-copy-node-name))
|
|
1069 (save-restriction
|
|
1070 (widen)
|
|
1071 (let*
|
|
1072 ((case-fold-search t)
|
|
1073 (level (texinfo-hierarchic-level))
|
|
1074 (beginning (texinfo-update-menu-region-beginning level))
|
|
1075 (end (texinfo-update-menu-region-end level)))
|
|
1076 (if (string-equal level "top")
|
|
1077 (texinfo-top-pointer-case)
|
|
1078 ;; else
|
|
1079 (texinfo-insert-pointer beginning end level 'next)
|
|
1080 (texinfo-insert-pointer beginning end level 'previous)
|
|
1081 (texinfo-insert-pointer beginning end level 'up)
|
|
1082 (texinfo-clean-up-node-line)))))
|
|
1083
|
|
1084 (defun texinfo-top-pointer-case ()
|
|
1085 "Insert pointers in the Top node. This is a special case.
|
|
1086
|
|
1087 The `Next' pointer is a pointer to a chapter or section at a lower
|
|
1088 hierarchical level in the file. The `Previous' and `Up' pointers are
|
|
1089 to `(dir)'. Point must be at the beginning of the node line, and is
|
|
1090 left at the end of the node line."
|
|
1091
|
|
1092 (texinfo-clean-up-node-line)
|
|
1093 (insert ", "
|
|
1094 (save-excursion
|
|
1095 ;; There may be an @chapter or other such command between
|
|
1096 ;; the top node line and the next node line, as a title
|
|
1097 ;; for an `ifinfo' section. This @chapter command must
|
|
1098 ;; must be skipped. So the procedure is to search for
|
|
1099 ;; the next `@node' line, and then copy its name.
|
|
1100 (if (re-search-forward "^@node" nil t)
|
|
1101 (progn
|
|
1102 (beginning-of-line)
|
|
1103 (texinfo-copy-node-name))
|
|
1104 " "))
|
|
1105 ", (dir), (dir)"))
|
|
1106
|
|
1107 (defun texinfo-check-for-node-name ()
|
|
1108 "Determine whether the node has a node name. Prompt for one if not.
|
|
1109 Point must be at beginning of node line. Does not move point."
|
|
1110 (save-excursion
|
|
1111 (forward-word 1) ; skip over node command
|
|
1112 (skip-chars-forward " \t") ; and over spaces
|
|
1113 (if (not (looking-at "[^,\t\n ]+")) ; regexp based on what info looks for
|
|
1114 ; alternatively, use "[a-zA-Z]+"
|
|
1115 (let ((node-name (read-from-minibuffer "Node name: ")))
|
|
1116 (insert " " node-name)))))
|
|
1117
|
|
1118 (defun texinfo-delete-existing-pointers ()
|
|
1119 "Delete `Next', `Previous', and `Up' pointers.
|
|
1120 Starts from the current position of the cursor, and searches forward
|
|
1121 on the line for a comma and if one is found, deletes the rest of the
|
|
1122 line, including the comma. Leaves point at beginning of line."
|
|
1123 (if (search-forward "," (save-excursion (end-of-line) (point)) t)
|
|
1124 (progn
|
|
1125 (goto-char (1- (point)))
|
|
1126 (kill-line nil)))
|
|
1127 (beginning-of-line))
|
|
1128
|
|
1129 (defun texinfo-find-pointer (beginning end level direction)
|
|
1130 "Move point to section associated with next, previous, or up pointer.
|
|
1131 Return type of pointer (either 'normal or 'no-pointer).
|
|
1132
|
|
1133 The first and second arguments bound the search for a pointer to the
|
|
1134 beginning and end, respectively, of the enclosing higher level
|
|
1135 section. The third argument is a string specifying the general kind
|
|
1136 of section such as \"chapter\ or \"section\". When looking for the
|
|
1137 `Next' pointer, the section found will be at the same hierarchical
|
|
1138 level in the Texinfo file; when looking for the `Previous' pointer,
|
|
1139 the section found will be at the same or higher hierarchical level in
|
|
1140 the Texinfo file; when looking for the `Up' pointer, the section found
|
|
1141 will be at some level higher in the Texinfo file. The fourth argument
|
|
1142 \(one of 'next, 'previous, or 'up\) specifies whether to find the
|
|
1143 `Next', `Previous', or `Up' pointer."
|
|
1144
|
|
1145 (cond ((eq direction 'next)
|
|
1146 (forward-line 3) ; skip over current node
|
|
1147 (if (re-search-forward
|
|
1148 (eval
|
|
1149 (cdr (assoc level texinfo-update-menu-same-level-regexps)))
|
|
1150 end
|
|
1151 t)
|
|
1152 'normal
|
|
1153 'no-pointer))
|
|
1154 ((eq direction 'previous)
|
|
1155 (if (re-search-backward
|
|
1156 (concat
|
|
1157 "\\("
|
|
1158 (eval
|
|
1159 (cdr (assoc level texinfo-update-menu-same-level-regexps)))
|
|
1160 "\\|"
|
|
1161 (eval
|
|
1162 (cdr (assoc level texinfo-update-menu-higher-regexps)))
|
|
1163 "\\)")
|
|
1164 beginning
|
|
1165 t)
|
|
1166 'normal
|
|
1167 'no-pointer))
|
|
1168 ((eq direction 'up)
|
|
1169 (if (re-search-backward
|
|
1170 (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
|
|
1171 (save-excursion
|
|
1172 (goto-char beginning)
|
|
1173 (beginning-of-line)
|
|
1174 (point))
|
|
1175 t)
|
|
1176 'normal
|
|
1177 'no-pointer))
|
|
1178 (t
|
|
1179 (error "texinfo-find-pointer: lack proper arguments"))))
|
|
1180
|
|
1181 (defun texinfo-pointer-name (kind)
|
|
1182 "Return the node name preceding the section command.
|
|
1183 The argument is the kind of section, either normal or no-pointer."
|
|
1184 (let (name)
|
|
1185 (cond ((eq kind 'normal)
|
|
1186 (end-of-line) ; this handles prev node top case
|
|
1187 (re-search-backward ; when point is already
|
|
1188 "^@node" ; at the beginning of @node line
|
|
1189 (save-excursion (forward-line -3))
|
|
1190 t)
|
|
1191 (setq name (texinfo-copy-node-name)))
|
|
1192 ((eq kind 'no-pointer)
|
|
1193 (setq name " "))) ; put a blank in the pointer slot
|
|
1194 name))
|
|
1195
|
|
1196 (defun texinfo-insert-pointer (beginning end level direction)
|
|
1197 "Insert the `Next', `Previous' or `Up' node name at point.
|
|
1198 Move point forward.
|
|
1199
|
|
1200 The first and second arguments bound the search for a pointer to the
|
|
1201 beginning and end, respectively, of the enclosing higher level
|
|
1202 section. The third argument is the hierarchical level of the Texinfo
|
|
1203 file, a string such as \"section\". The fourth argument is direction
|
|
1204 towards which the pointer is directed, one of `next, `previous, or
|
|
1205 'up."
|
|
1206
|
|
1207 (end-of-line)
|
|
1208 (insert
|
|
1209 ", "
|
|
1210 (save-excursion
|
|
1211 (texinfo-pointer-name
|
|
1212 (texinfo-find-pointer beginning end level direction)))))
|
|
1213
|
|
1214 (defun texinfo-clean-up-node-line ()
|
|
1215 "Remove extra commas, if any, at end of node line."
|
|
1216 (end-of-line)
|
|
1217 (skip-chars-backward ", ")
|
|
1218 (delete-region (point) (save-excursion (end-of-line) (point))))
|
|
1219
|
|
1220
|
|
1221 ;;;; Updating nodes sequentially
|
|
1222 ; These sequential update functions insert `Next' or `Previous'
|
|
1223 ; pointers that point to the following or preceding nodes even if they
|
|
1224 ; are at higher or lower hierarchical levels. This means that if a
|
|
1225 ; section contains one or more subsections, the section's `Next'
|
|
1226 ; pointer will point to the subsection and not the following section.
|
|
1227 ; (The subsection to which `Next' points will most likely be the first
|
|
1228 ; item on the section's menu.)
|
|
1229
|
|
1230 (defun texinfo-sequential-node-update (&optional region-p)
|
|
1231 "Update one node (or many) in a Texinfo file with sequential pointers.
|
|
1232
|
|
1233 This function causes the `Next' or `Previous' pointer to point to the
|
|
1234 immediately preceding or following node, even if it is at a higher or
|
|
1235 lower hierarchical level in the document. Continually pressing `n' or
|
|
1236 `p' takes you straight through the file.
|
|
1237
|
|
1238 Without any prefix argument, update the node in which point is located.
|
|
1239 Non-nil argument (prefix, if interactive) means update the nodes in the
|
|
1240 marked region.
|
|
1241
|
|
1242 This command makes it awkward to navigate among sections and
|
|
1243 subsections; it should be used only for those documents that are meant
|
|
1244 to be read like a novel rather than a reference, and for which the
|
|
1245 Info `g*' command is inadequate."
|
|
1246
|
|
1247 (interactive "P")
|
|
1248 (if (not region-p)
|
|
1249 (let ((auto-fill-hook nil)) ; update a single node
|
|
1250 (if (not (re-search-backward "^@node" (point-min) t))
|
|
1251 (error "Node line not found before this position."))
|
|
1252 (texinfo-sequentially-update-the-node)
|
|
1253 (message
|
|
1254 "Done...sequentially updated the node . You may save the buffer."))
|
|
1255 ;; else
|
|
1256 (let ((auto-fill-hook nil)
|
|
1257 (beginning (region-beginning))
|
|
1258 (end (region-end)))
|
|
1259 (if (= end beginning)
|
|
1260 (error "Please mark a region!"))
|
|
1261 (save-restriction
|
|
1262 (narrow-to-region beginning end)
|
|
1263 (goto-char beginning)
|
|
1264 (push-mark)
|
|
1265 (while (re-search-forward "^@node" (point-max) t)
|
|
1266 (beginning-of-line)
|
|
1267 (texinfo-sequentially-update-the-node))
|
|
1268 (message
|
|
1269 "Done...updated the nodes in sequence. You may save the buffer.")))))
|
|
1270
|
|
1271 (defun texinfo-sequentially-update-the-node ()
|
|
1272 "Update one node such that the pointers are sequential.
|
|
1273 A `Next' or `Previous' pointer points to any preceding or following node,
|
|
1274 regardless of its hierarchical level."
|
|
1275
|
|
1276 (texinfo-check-for-node-name)
|
|
1277 (texinfo-delete-existing-pointers)
|
|
1278 (message
|
|
1279 "Sequentially updating node: %s ... " (texinfo-copy-node-name))
|
|
1280 (save-restriction
|
|
1281 (widen)
|
|
1282 (let*
|
|
1283 ((case-fold-search t)
|
|
1284 (level (texinfo-hierarchic-level)))
|
|
1285 (if (string-equal level "top")
|
|
1286 (texinfo-top-pointer-case)
|
|
1287 ;; else
|
|
1288 (texinfo-sequentially-insert-pointer level 'next)
|
|
1289 (texinfo-sequentially-insert-pointer level 'previous)
|
|
1290 (texinfo-sequentially-insert-pointer level 'up)
|
|
1291 (texinfo-clean-up-node-line)))))
|
|
1292
|
|
1293 (defun texinfo-sequentially-find-pointer (level direction)
|
|
1294 "Find next or previous pointer sequentially in Texinfo file, or up pointer.
|
|
1295 Move point to section associated with the pointer. Find point even if
|
|
1296 it is in a different section.
|
|
1297
|
|
1298 Return type of pointer (either 'normal or 'no-pointer).
|
|
1299
|
|
1300 The first argument is a string specifying the general kind of section
|
|
1301 such as \"chapter\ or \"section\". The section found will be at the
|
|
1302 same hierarchical level in the Texinfo file, or, in the case of the up
|
|
1303 pointer, some level higher. The second argument (one of 'next,
|
|
1304 'previous, or 'up) specifies whether to find the `Next', `Previous',
|
|
1305 or `Up' pointer."
|
|
1306
|
|
1307 (cond ((eq direction 'next)
|
|
1308 (forward-line 3) ; skip over current node
|
|
1309 (if (re-search-forward
|
|
1310 texinfo-section-types-regexp
|
|
1311 (point-max)
|
|
1312 t)
|
|
1313 'normal
|
|
1314 'no-pointer))
|
|
1315 ((eq direction 'previous)
|
|
1316 (if (re-search-backward
|
|
1317 texinfo-section-types-regexp
|
|
1318 (point-min)
|
|
1319 t)
|
|
1320 'normal
|
|
1321 'no-pointer))
|
|
1322 ((eq direction 'up)
|
|
1323 (if (re-search-backward
|
|
1324 (eval (cdr (assoc level texinfo-update-menu-higher-regexps)))
|
|
1325 beginning
|
|
1326 t)
|
|
1327 'normal
|
|
1328 'no-pointer))
|
|
1329 (t
|
|
1330 (error "texinfo-sequential-find-pointer: lack proper arguments"))))
|
|
1331
|
|
1332 (defun texinfo-sequentially-insert-pointer (level direction)
|
|
1333 "Insert the `Next', `Previous' or `Up' node name at point.
|
|
1334 Move point forward.
|
|
1335
|
|
1336 The first argument is the hierarchical level of the Texinfo file, a
|
|
1337 string such as \"section\". The second argument is direction, one of
|
|
1338 `next, `previous, or 'up."
|
|
1339
|
|
1340 (end-of-line)
|
|
1341 (insert
|
|
1342 ", "
|
|
1343 (save-excursion
|
|
1344 (texinfo-pointer-name
|
|
1345 (texinfo-sequentially-find-pointer level direction)))))
|
|
1346
|
|
1347
|
|
1348 ;;;; Inserting `@node' lines
|
|
1349 ; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
|
|
1350 ; before the `@chapter', `@section', and such like lines of a region
|
|
1351 ; in a Texinfo file.
|
|
1352
|
|
1353 (defun texinfo-insert-node-lines (&optional title-p)
|
|
1354 "Insert missing `@node' lines in region of Texinfo file.
|
|
1355 Non-nil argument (prefix, if interactive) means also to insert the
|
|
1356 section titles as node names; and also to insert the section titles as
|
|
1357 node names in pre-existing @node lines that lack names."
|
|
1358 (interactive "P")
|
|
1359 (save-excursion
|
|
1360 (let ((begin-region (region-beginning))
|
|
1361 (end-region (region-end)))
|
|
1362 (goto-char begin-region)
|
|
1363 (while (< (point) end-region)
|
|
1364 (re-search-forward texinfo-section-types-regexp nil 'end)
|
|
1365 ;; copy title, since most often, we will need it
|
|
1366 (let ((title
|
|
1367 (progn
|
|
1368 (beginning-of-line)
|
|
1369 (forward-word 1)
|
|
1370 (skip-chars-forward " \t")
|
|
1371 (buffer-substring
|
|
1372 (point)
|
|
1373 (save-excursion (end-of-line) (point))))))
|
|
1374 ;; insert a node if necessary
|
|
1375 (if (re-search-backward
|
|
1376 "^@node"
|
|
1377 (save-excursion
|
|
1378 (forward-line -3)
|
|
1379 (point))
|
|
1380 t)
|
|
1381 ;; @node present, and point at beginning of that line
|
|
1382 (forward-word 1)
|
|
1383 ;; else @node missing, insert one
|
|
1384 (progn
|
|
1385 (beginning-of-line) ; beginning of `@section' line
|
|
1386 (insert "@node\n")
|
|
1387 (backward-char 1))) ; leave point just after `@node'
|
|
1388 ;; insert a title if warranted
|
|
1389 (if title-p
|
|
1390 (progn
|
|
1391 (skip-chars-forward " \t")
|
|
1392 ;; use regexp based on what info looks for
|
|
1393 ;; (alternatively, use "[a-zA-Z]+")
|
|
1394 (if (not (looking-at "[^,\t\n ]+"))
|
|
1395 (progn
|
|
1396 (beginning-of-line)
|
|
1397 (forward-word 1)
|
|
1398 (insert " " title)
|
|
1399 (message "Inserted title %s ... " title)))))
|
|
1400 ;; in any case, go forward beyond current section title
|
|
1401 (forward-line 3)))))
|
|
1402 (if title-p
|
|
1403 (message
|
|
1404 "Done inserting node lines and titles. You may save the buffer.")
|
|
1405 (message "Done inserting node lines. You may save the buffer.")))
|
|
1406
|
|
1407
|
|
1408 ;;;; Update and create menus for multi-file Texinfo sources
|
|
1409
|
|
1410 ;; 1. M-x texinfo-multiple-files-update
|
|
1411 ;;
|
|
1412 ;; Read the include file list of an outer Texinfo file and
|
|
1413 ;; update all highest level nodes in the files listed and insert a
|
|
1414 ;; main menu in the outer file after its top node.
|
|
1415
|
|
1416 ;; 2. C-u M-x texinfo-multiple-files-update
|
|
1417 ;;
|
|
1418 ;; Same as 1, but insert a master menu. (Saves reupdating lower
|
|
1419 ;; level menus and nodes.) This command simply reads every menu,
|
|
1420 ;; so if the menus are wrong, the master menu will be wrong.
|
|
1421 ;; Similarly, if the lower level node pointers are wrong, they
|
|
1422 ;; will stay wrong.
|
|
1423
|
|
1424 ;; 3. C-u 2 M-x texinfo-multiple-files-update
|
|
1425 ;;
|
|
1426 ;; Read the include file list of an outer Texinfo file and
|
|
1427 ;; update all nodes and menus in the files listed and insert a
|
|
1428 ;; master menu in the outer file after its top node.
|
|
1429
|
|
1430 ;;; Note: these functions:
|
|
1431 ;;;
|
|
1432 ;;; * Do not save or delete any buffers. You may fill up your memory.
|
|
1433 ;;; * Do not handle any pre-existing nodes in outer file.
|
|
1434 ;;; Hence, you may need a file for indices.
|
|
1435
|
|
1436
|
|
1437 ;;;; Auxiliary functions for multiple file updating
|
|
1438
|
|
1439 (defun texinfo-multi-file-included-list (outer-file)
|
|
1440 "Return a list of the included files in OUTER-FILE."
|
|
1441 (let ((included-file-list (list outer-file))
|
|
1442 start)
|
|
1443 (save-excursion
|
|
1444 (switch-to-buffer (find-file-noselect outer-file))
|
|
1445 (widen)
|
|
1446 (goto-char (point-min))
|
|
1447 (while (re-search-forward "^@include" nil t)
|
|
1448 (skip-chars-forward " \t")
|
|
1449 (setq start (point))
|
|
1450 (end-of-line)
|
|
1451 (skip-chars-backward " \t")
|
|
1452 (setq included-file-list
|
|
1453 (cons (buffer-substring start (point))
|
|
1454 included-file-list)))
|
|
1455 (nreverse included-file-list))))
|
|
1456
|
|
1457 (defun texinfo-copy-next-section-title ()
|
|
1458 "Return the name of the immediately following section as a string.
|
|
1459
|
|
1460 Start with point at the beginning of the node line. Leave point at the
|
|
1461 same place. If there is no title, returns an empty string."
|
|
1462
|
|
1463 (save-excursion
|
|
1464 (end-of-line)
|
|
1465 (let ((section-end (or
|
|
1466 (save-excursion
|
|
1467 (re-search-forward "\\(^@node\\)" nil t)
|
|
1468 (match-beginning 0))
|
|
1469 (point-max))))
|
|
1470 (if (re-search-forward texinfo-section-types-regexp section-end t)
|
|
1471 ;; copy title
|
|
1472 (let ((title
|
|
1473 (buffer-substring
|
|
1474 (progn (forward-word 1) ; skip over section type
|
|
1475 (skip-chars-forward " \t") ; and over spaces
|
|
1476 (point))
|
|
1477 (progn (end-of-line) (point)))))
|
|
1478 title)
|
|
1479 ""))))
|
|
1480
|
|
1481 (defun texinfo-multi-file-update (files &optional update-everything)
|
|
1482 "Update first node pointers in each file in FILES.
|
|
1483 Return a list of the node names and the title immediate following them.
|
|
1484
|
|
1485 The first file in the list is an outer file; the remaining are
|
|
1486 files included in the outer file with `@include' commands.
|
|
1487
|
|
1488 If optional arg UPDATE-EVERYTHING non-nil, update every menu and
|
|
1489 pointer in each of the included files.
|
|
1490
|
|
1491 Also update the `Top' level node pointers of the outer file.
|
|
1492
|
|
1493 Requirements:
|
|
1494
|
|
1495 * the first file in the FILES list must be the outer file,
|
|
1496 * each of the included files must contain exactly one highest
|
|
1497 hierarchical level node,
|
|
1498 * this node must be the first node in the included file,
|
|
1499 * each highest hierarchical level node must be of the same type.
|
|
1500
|
|
1501 Thus, normally, each included file contains one, and only one,
|
|
1502 chapter.
|
|
1503
|
|
1504 The menu-list has the form:
|
|
1505
|
|
1506 \(\(\"node-name1\" . \"title1\"\)
|
|
1507 \(\"node-name2\" . \"title2\"\) ... \)
|
|
1508
|
|
1509 However, there does not need to be a title field."
|
|
1510
|
|
1511 (let (menu-list)
|
|
1512
|
|
1513 ;; Find the name of the first node of the first included file.
|
|
1514 (switch-to-buffer (find-file-noselect (car (cdr files))))
|
|
1515 (widen)
|
|
1516 (goto-char (point-min))
|
|
1517 (if (not (re-search-forward "^@node" nil t))
|
|
1518 (error "No `@node' line found in %s !" (buffer-name)))
|
|
1519 (beginning-of-line)
|
|
1520 (texinfo-check-for-node-name)
|
|
1521 (setq next-node-name (texinfo-copy-node-name))
|
|
1522
|
|
1523 (setq menu-list
|
|
1524 (cons (cons
|
|
1525 next-node-name
|
|
1526 (texinfo-copy-next-section-title))
|
|
1527 menu-list))
|
|
1528
|
|
1529 ;; Go to outer file
|
|
1530 (switch-to-buffer (find-file-noselect (car files)))
|
|
1531 (goto-char (point-min))
|
143
|
1532 (if (not (re-search-forward "^@node [ \t]*top[ \t]*\\(,\\|$\\)" nil t))
|
107
|
1533 (error "This buffer needs a Top node!"))
|
|
1534 (beginning-of-line)
|
|
1535 (texinfo-delete-existing-pointers)
|
|
1536 (end-of-line)
|
|
1537 (insert ", " next-node-name ", (dir), (dir)")
|
|
1538 (beginning-of-line)
|
|
1539 (setq previous-node-name "Top")
|
|
1540 (setq files (cdr files))
|
|
1541
|
|
1542 (while files
|
|
1543
|
|
1544 (if (not (cdr files))
|
|
1545 ;; No next file
|
|
1546 (setq next-node-name "")
|
|
1547 ;; Else,
|
|
1548 ;; find the name of the first node in the next file.
|
|
1549 (switch-to-buffer (find-file-noselect (car (cdr files))))
|
|
1550 (widen)
|
|
1551 (goto-char (point-min))
|
|
1552 (if (not (re-search-forward "^@node" nil t))
|
|
1553 (error "No `@node' line found in %s !" (buffer-name)))
|
|
1554 (beginning-of-line)
|
|
1555 (texinfo-check-for-node-name)
|
|
1556 (setq next-node-name (texinfo-copy-node-name))
|
|
1557 (setq menu-list
|
|
1558 (cons (cons
|
|
1559 next-node-name
|
|
1560 (texinfo-copy-next-section-title))
|
|
1561 menu-list)))
|
|
1562
|
|
1563 ;; Go to node to be updated.
|
|
1564 (switch-to-buffer (find-file-noselect (car files)))
|
|
1565 (goto-char (point-min))
|
|
1566 (if (not (re-search-forward "^@node" nil t))
|
|
1567 (error "No `@node' line found in %s !" (buffer-name)))
|
|
1568 (beginning-of-line)
|
|
1569 (texinfo-delete-existing-pointers)
|
|
1570 (end-of-line)
|
|
1571 (insert ", " next-node-name ", " previous-node-name ", " up-node-name)
|
|
1572
|
|
1573 (beginning-of-line)
|
|
1574 (setq previous-node-name (texinfo-copy-node-name))
|
|
1575
|
|
1576 ;; Update other menus and nodes if requested.
|
|
1577 (if update-everything (texinfo-all-menus-update t))
|
|
1578
|
|
1579 (setq files (cdr files)))
|
|
1580 (nreverse menu-list)))
|
|
1581
|
|
1582 (defun texinfo-multi-files-insert-main-menu (menu-list)
|
|
1583 "Insert formatted main menu at point.
|
|
1584 Indents the first line of the description, if any, to the value of
|
|
1585 texinfo-column-for-description."
|
|
1586
|
|
1587 (insert "@menu\n")
|
|
1588 (while menu-list
|
|
1589 (if (cdr (car menu-list)) ; menu-list has description entry
|
|
1590 (progn
|
|
1591 (insert
|
|
1592 (format "* %s::" (car (car menu-list)))) ; node-name entry
|
|
1593 (indent-to texinfo-column-for-description 2)
|
|
1594 (insert
|
|
1595 (format "%s\n" (cdr (car menu-list))))) ; description entry
|
|
1596 ;; else menu-list lacks description entry
|
|
1597 (insert
|
|
1598 (format "* %s::\n" (car (car menu-list))))) ; node-name entry
|
|
1599 (setq menu-list (cdr menu-list)))
|
|
1600 (insert "@end menu"))
|
|
1601
|
|
1602
|
|
1603 (defun texinfo-multi-file-master-menu-list (files-list)
|
|
1604 "Return master menu list from files in FILES-LIST.
|
|
1605 Menu entries in each file collected using `texinfo-master-menu-list'.
|
|
1606
|
|
1607 The first file in FILES-LIST must be the outer file; the others must
|
|
1608 be the files included within it. A main menu must already exist."
|
|
1609 (save-excursion
|
|
1610 (let (master-menu-list)
|
|
1611 (while files-list
|
|
1612 (switch-to-buffer (find-file-noselect (car files-list)))
|
|
1613 (message "Working on: %s " (current-buffer))
|
|
1614 (goto-char (point-min))
|
|
1615 (setq master-menu-list
|
|
1616 (append master-menu-list (texinfo-master-menu-list)))
|
|
1617 (setq files-list (cdr files-list)))
|
|
1618 master-menu-list)))
|
|
1619
|
|
1620
|
|
1621 ;;;; The multiple-file update function
|
|
1622
|
|
1623 (defun texinfo-multiple-files-update
|
|
1624 (outer-file &optional update-everything make-master-menu)
|
|
1625 "Update first node pointers in each file included in OUTER-FILE;
|
|
1626 create or update main menu in the outer file that refers to such nodes.
|
|
1627 This does not create or update menus or pointers within the included files.
|
|
1628
|
|
1629 With optional MAKE-MASTER-MENU argument (prefix arg, if interactive),
|
|
1630 insert a master menu in OUTER-FILE. This does not create or update
|
|
1631 menus or pointers within the included files.
|
|
1632
|
|
1633 With optional UPDATE-EVERYTHING argument (numeric prefix arg, if
|
|
1634 interactive), update all the menus and all the `Next', `Previous', and
|
|
1635 `Up' pointers of all the files included in OUTER-FILE before inserting
|
|
1636 a master menu in OUTER-FILE.
|
|
1637
|
|
1638 The command also updates the `Top' level node pointers of OUTER-FILE.
|
|
1639
|
|
1640 Notes:
|
|
1641
|
|
1642 * this command does NOT save any files--you must save the
|
|
1643 outer file and any modified, included files.
|
|
1644
|
|
1645 * except for the `Top' node, this command does NOT handle any
|
|
1646 pre-existing nodes in the outer file; hence, indices must be
|
|
1647 enclosed in an included file.
|
|
1648
|
|
1649 Requirements:
|
|
1650
|
|
1651 * each of the included files must contain exactly one highest
|
|
1652 hierarchical level node,
|
|
1653 * this highest node must be the first node in the included file,
|
|
1654 * each highest hierarchical level node must be of the same type.
|
|
1655
|
|
1656 Thus, normally, each included file contains one, and only one,
|
|
1657 chapter."
|
|
1658
|
|
1659 (interactive "fName of outer `include' file: ")
|
|
1660
|
|
1661 (cond (current-prefix-arg
|
|
1662 (setq make-master-menu (listp current-prefix-arg))
|
|
1663 (setq update-everything (numberp current-prefix-arg))))
|
|
1664
|
|
1665 (let* ((included-file-list (texinfo-multi-file-included-list outer-file))
|
|
1666 (files included-file-list)
|
|
1667 main-menu-list
|
|
1668 next-node-name
|
|
1669 previous-node-name
|
|
1670 (up-node-name "Top"))
|
|
1671
|
|
1672 ;;; Update the pointers
|
|
1673 ;;; and collect the names of the nodes and titles
|
|
1674 (setq main-menu-list (texinfo-multi-file-update files update-everything))
|
|
1675
|
|
1676 ;;; Insert main menu
|
|
1677
|
|
1678 ;; Go to outer file
|
|
1679 (switch-to-buffer (find-file-noselect (car included-file-list)))
|
|
1680 (if (texinfo-old-menu-p
|
|
1681 (point-min)
|
|
1682 (save-excursion
|
|
1683 (re-search-forward "^@include")
|
|
1684 (beginning-of-line)
|
|
1685 (point)))
|
|
1686
|
|
1687 ;; If found, leave point after word `menu' on the `@menu' line.
|
|
1688 (progn
|
|
1689 (texinfo-incorporate-descriptions main-menu-list)
|
|
1690 ;; Delete existing menu.
|
|
1691 (beginning-of-line)
|
|
1692 (delete-region
|
|
1693 (point)
|
|
1694 (save-excursion (re-search-forward "^@end menu") (point)))
|
|
1695 ;; Insert main menu
|
|
1696 (texinfo-multi-files-insert-main-menu main-menu-list))
|
|
1697
|
|
1698 ;; Else no current menu; insert it before `@include'
|
|
1699 (texinfo-multi-files-insert-main-menu main-menu-list))
|
|
1700
|
|
1701 ;;; Insert master menu
|
|
1702
|
|
1703 (if make-master-menu
|
|
1704 (progn
|
|
1705 ;; First, removing detailed part of any pre-existing master menu
|
|
1706 (goto-char (point-min))
|
|
1707 (if (re-search-forward texinfo-master-menu-header nil t)
|
|
1708 ;; Remove detailed master menu listing
|
|
1709 (progn
|
|
1710 (goto-char (match-beginning 0))
|
|
1711 (let ((end-of-detailed-menu-descriptions
|
|
1712 (save-excursion ; beginning of end menu line
|
|
1713 (goto-char (texinfo-menu-end))
|
|
1714 (beginning-of-line) (forward-char -1)
|
|
1715 (point))))
|
|
1716 (delete-region (point) end-of-detailed-menu-descriptions))))
|
|
1717
|
|
1718 ;; Create a master menu and insert it
|
|
1719 (texinfo-insert-master-menu-list
|
|
1720 (texinfo-multi-file-master-menu-list
|
|
1721 included-file-list)))))
|
|
1722 (message "Multiple files updated."))
|
|
1723
|
|
1724 ;;;;;;;;;;;;;;;; end texnfo-upd.el ;;;;;;;;;;;;;;;;
|
584
|
1725
|
|
1726 (provide 'texnfo-upd)
|
|
1727
|