Debian Codegraph @

progs/arm-texi-index.el

raw
1 ;;; Insert texinfo index entries into arm*.texinfo -*- lexical-binding:t -*-
2
3 ;; Copyright (C) 2020 Free Software Foundation, Inc.
4 ;;
5 ;; Author: Stephen Leake <[email protected]>
6 ;; Maintainer: Stephen Leake <[email protected]>
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 3 of the License, or
13 ;; (at your option) 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. If not, see <http://www.gnu.org/licenses/>.
22
23 (defun insert-index-entries ()
24 "Read the index @chapter, insert @cindex entries in sections."
25 ;; The texinfo file is produced by the arm_form executable; see
26 ;; arm_texi.adb for some info.
27 (goto-char (point-min))
28
29 ;; First add the menu entry
30 (search-forward "@menu")
31 (search-forward "@end menu")
32 (goto-char (line-beginning-position))
33 (insert "* Concept Index :: Concept Index\n")
34
35 ;; now the command to build the index and print it
36 (goto-char (point-max))
37 (goto-char (line-beginning-position 0))
38 (insert "@node Concept Index\n")
39 (insert "@unnumbered Concept Index\n")
40 (insert "@printindex cp\n")
41
42 ;; Now insert all the @cindex items
43 (search-backward "@chapter Index")
44
45 (let (next-search-pos)
46 (while (search-forward-regexp "@ref{ \\([0-9]+\\), \\([0-9.(/)]+\\)}" nil t)
47 (setq next-search-pos (copy-marker (point))) ;; we are inserting text before this point!
48
49 ;; There can be more than one @ref on a line; they are all for the
50 ;; same entry; texinfo can handle that.
51 (let ((ref (match-string-no-properties 1))
52 text)
53 (goto-char (line-beginning-position))
54 (when (looking-at "\\(?:@w{ }\\)*\\(.*?\\)@w{ }")
55 (setq text (match-string-no-properties 1))
56 (goto-char (point-min))
57 (search-forward (concat "@anchor{ " ref "}"))
58 (insert (concat "\n@cindex " text "\n")))
59 (goto-char next-search-pos)))))
60
61 (defun do-index (filename)
62 (find-file filename)
63 (insert-index-entries)
64 (save-buffer))
65
66 (provide 'arm-texi-index)
67 ;;; ada-mode.el ends here