Mercurial > hg > xemacs-beta
comparison lisp/packages/doctex.el @ 0:376386a54a3c r19-14
Import from CVS: tag r19-14
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:45:50 +0200 |
parents | |
children | c7528f8e288d |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:376386a54a3c |
---|---|
1 ;;; doctex.el --- grind GNU Emacs DOC file into LaTeX input | |
2 ;;; Copyright (C) 1987 Kyle E. Jones, Tor Lillqvist | |
3 | |
4 ;; Keywords: tex, docs | |
5 | |
6 ;;; This file may be redistributed provided the above copyright | |
7 ;;; notice appears on all copies and that the further free redistribution | |
8 ;;; of this file is not in any way restricted by those who | |
9 ;;; redistribute it. | |
10 | |
11 ;;; Synched up with: Not in FSF. | |
12 | |
13 ;;; Based on Kyle E. Jones's grind-DOC package. | |
14 | |
15 ;;; This software is distributed 'as is', without warranties of any kind. | |
16 | |
17 ;;; This file is not part of GNU Emacs. | |
18 | |
19 ;;; The document that is the output from the (LaTeXify-DOC) function is | |
20 ;;; part of GNU Emacs. | |
21 | |
22 | |
23 (defvar LaTeXify-DOC-style "report" | |
24 "*Should be bound to a string indicating what LaTeX document style | |
25 should be used to format the DOC file. If this variable is set to nil | |
26 the report style will be used.") | |
27 | |
28 (defvar LaTeXify-DOC-style-options "" | |
29 "*A string containing a list of document style options for LaTeX") | |
30 | |
31 (defun LaTeXify-DOC () (interactive) | |
32 "Reads the etc/DOC-xx.xx.x file into a buffer and converts it to a form | |
33 suitable as LaTeX input." | |
34 ; | |
35 ; Make sure we can deal with the macro package and the point size. | |
36 ; | |
37 (cond | |
38 ((not (stringp LaTeXify-DOC-style)) | |
39 (error "LaTeXify-DOC-style must be a string"))) | |
40 ; | |
41 ; Select the DOC file. | |
42 ; | |
43 (find-file (expand-file-name | |
44 (if (fboundp 'dump-emacs) | |
45 (concat "DOC-" emacs-version) | |
46 "DOC") | |
47 exec-directory)) | |
48 (setq buffer-read-only nil) | |
49 (auto-save-mode 0) | |
50 (set-visited-file-name (concat (buffer-file-name) ".tex")) | |
51 (delete-other-windows) | |
52 ; | |
53 ; Save-excursion just in case the DOC file was already selected. | |
54 ; | |
55 (save-excursion | |
56 (let (case-fold-search mode-line-format varstart-point bufstring name odot) | |
57 ; | |
58 ; The first thing we must do is convert the \[COMMAND] sequences | |
59 ; into the keys that the COMMANDs are bound to. | |
60 ; | |
61 (setq mode-line-format | |
62 " Grinding the DOC file... be patient.") | |
63 (sit-for 0) | |
64 (replace-regexp "\\\\{\\(\\s_\\|\\sw\\)*}" | |
65 "]]bgroup]]obeylines\\&]]egroup") | |
66 (setq bufstring (substitute-command-keys (buffer-string))) | |
67 (erase-buffer) | |
68 (insert bufstring) | |
69 ; | |
70 ; Here we make each docstring begin and end with C-_ for | |
71 ; easier manipulation. This is undone later. | |
72 ; | |
73 (goto-char (1+ (point-min))) | |
74 (replace-string "\C-_" "\C-_\C-_" nil) | |
75 (goto-char (point-max)) | |
76 (insert "\C-_") | |
77 ; | |
78 ; Sort the docstrings. This implicitly separates function | |
79 ; documentation from the variable documentation. | |
80 ; | |
81 (sort-regexp-fields nil "\C-_\\([FV].*\\)[^\C-_]*\C-_" "\\1" | |
82 (point-min) (point-max)) | |
83 ; | |
84 ; Handle TeX special characters | |
85 ; | |
86 (goto-char (point-min)) | |
87 (mapcar | |
88 '(lambda (x) (save-excursion (eval x))) | |
89 '((replace-string "#" "]]#") | |
90 (replace-string "$" "]]$") | |
91 (replace-string "%" "]]%") | |
92 (replace-string "&" "]]&") | |
93 (replace-string "~" "]]verb+~+") | |
94 (replace-string "_" "]]verb+_+") | |
95 (replace-string "^" "]]verb+^+") | |
96 (replace-string "\\" "]]verb+]]+") | |
97 (replace-string "{" "]]{") | |
98 (replace-string "}" "]]}") | |
99 (replace-string "<" "]]verb+<+") | |
100 (replace-string ">" "]]verb+>+") | |
101 (replace-string "]]" "\\"))) | |
102 ; | |
103 ; Now add the indentation commands and put ( ...) around the functions | |
104 ; | |
105 (save-restriction | |
106 (goto-char (point-min)) | |
107 (search-forward "\C-_V" (point-max) nil 1) | |
108 (backward-char 2) | |
109 (narrow-to-region (point-min) (dot)) | |
110 (goto-char (point-min)) | |
111 (insert "\\section*{Functions}\n" | |
112 "\\begin{description}\n") | |
113 (while (search-forward "\C-_F" (point-max) t 1) | |
114 (delete-char -2) | |
115 (insert "\n\\item[\\sf(") | |
116 (end-of-line 1) | |
117 (insert " ...)]") | |
118 (search-forward "\C-_" (point-max) nil 1) | |
119 (delete-char -1)) | |
120 (insert "\\end{description}\n")) | |
121 (insert "\\section*{Variables} | |
122 Variables whose documentation begins with an | |
123 asterisk `*' are user definable options. These variables are | |
124 used to customize Emacs. Other variables are generally of | |
125 interest only to Emacs Lisp programmers. | |
126 \\begin{description}\n") | |
127 (while (search-forward "\C-_V" (point-max) t 1) | |
128 (delete-char -2) | |
129 (insert "\n\\item[\\sf ") | |
130 (end-of-line 1) | |
131 (insert "]") | |
132 (search-forward "\C-_" (point-max) nil 1) | |
133 (delete-char -1)) | |
134 (insert "\\end{description}\n" | |
135 "\\end{document}\n") | |
136 ; | |
137 ; Try to make those parameters that are in all-caps look better | |
138 ; | |
139 (goto-char (point-min)) | |
140 (mapcar | |
141 '(lambda (x) (save-excursion (eval x))) | |
142 '((replace-regexp "[A-Z][A-Z]+" "\n{\\\\lowercase{\\\\sf \\&}}" nil) | |
143 (replace-string "\\lowercase{\\sf TAB}" "{\\tt TAB}") | |
144 (replace-string "\\lowercase{\\sf LFD}" "{\\tt LFD}") | |
145 (replace-string "\\lowercase{\\sf RET}" "{\\tt RET}") | |
146 (replace-string "\\lowercase{\\sf ESC}" "{\\tt ESC}") | |
147 (replace-string "\\lowercase{\\sf SPC}" "{\\tt SPC}") | |
148 (replace-string "\\lowercase{\\sf DEL}" "{\\tt DEL}"))) | |
149 ; | |
150 ; Handle document style and front matter | |
151 ; | |
152 (goto-char (point-min)) | |
153 (insert "\\documentstyle[" | |
154 LaTeXify-DOC-style-options | |
155 "]{" LaTeXify-DOC-style "}\n" | |
156 "\\begin{document}\n" | |
157 "\\title{GNU Emacs Lisp Reference \\\\\n" | |
158 "Version " emacs-version " \\\\\n" | |
159 "\\large (gouged with a blunt instrument from the DOC file)}\n" | |
160 "\\author{Richard M. Stallman}\n" | |
161 "\\date{" (substring emacs-build-time 4 8) | |
162 (substring emacs-build-time 20) "}\n" | |
163 "\\maketitle\n") | |
164 ; | |
165 ; Insert the GNU Emacs copyright notice. | |
166 ; | |
167 (insert | |
168 "\\begin{centering}\n" | |
169 "Copyright \\copyright" (substring emacs-build-time 20) | |
170 " Free Software Foundation, Inc. \\\\\n" | |
171 "\\end{centering} | |
172 \\vspace{\\baselineskip} | |
173 \\noindent | |
174 This document is part of GNU Emacs. | |
175 | |
176 GNU Emacs is distributed in the hope that it will be useful, | |
177 but WITHOUT ANY WARRANTY. No author or distributor | |
178 accepts responsibility to anyone for the consequences of using it | |
179 or for whether it serves any particular purpose or works at all, | |
180 unless he says so in writing. Refer to the GNU Emacs General Public | |
181 License for full details. | |
182 | |
183 Everyone is granted permission to copy, modify and redistribute | |
184 GNU Emacs, but only under the conditions described in the | |
185 GNU Emacs General Public License. A copy of this license is | |
186 supposed to have been given to you along with GNU Emacs so you | |
187 can know your rights and responsibilities. It should be in a | |
188 file named COPYING. Among other things, the copyright notice | |
189 and this notice must be preserved on all copies. | |
190 \\newpage\\sloppy\n") | |
191 ; | |
192 ; That's it | |
193 ; | |
194 (message "Grinding completed. Behold!")))) |