Annotation of 43BSDReno/contrib/emacs-18.55/lisp/doctex.el, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.