annotate lisp/packages/doctex.el @ 58:8b0bdfdf0cf0 r19-16-pre4

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