2 # -*- coding: utf-8 -*-
4 # ===============================================================
5 # pylit_elisp.py: Settings and filters for elisp conversion
6 # ===============================================================
8 # :Date: $Date: 2007-05-14 14:14:54 +0200$
9 # :Version: SVN-Revision $Revision$
11 # :Copyright: 2007 Riccardo Murri
12 # Released under the terms of the GNU General Public License
24 # :0.2: Complete rewrite, following G. Milde's suggestions.
25 # :0.3: * Rewrite filter as iterator generators, the filter interface is
26 # moved to pylit.py(GM)
27 # * require three semicolons (``;;;``) in section header regexp
30 """Emacs lisp for the PyLit code<->text converter.
32 Defaults and filters for elisp (emacs lisp) code
35 __docformat__
= 'restructuredtext'
43 # Regular espressions are used in `ELISP filters` to match
44 # the ELisp sectioning comments::
56 def elisp_code_preprocessor(data
):
57 """Convert Emacs Lisp comment sectioning markers to reST comments.
59 The special headers listed at:
61 http://www.gnu.org/software/emacs/elisp/html_node/Library-Headers.html#Library-Headers
63 are converted to reST comment lines and prefixed with the comment
64 line marker (taken from keyword arguments); all other content is
65 passed through unchanged.
67 For instance, ELisp code:
71 ;; here begins the real coding
72 (defun my-elisp-function () ...)
76 ;; .. |elisp> ;;; Code:
78 ;; here begins the real coding
79 (defun my-elisp-function () ...)
82 # Regular expression matching the special ELisp headers::
85 re
.compile(';;; *(Change *Log|Code|Commentary|Documentation|History):',\
88 # Prepend ``.. |elisp> `` to matching headers, one line at a time::
91 if SECTION_PATTERN
.match(line
):
92 yield pylit
.defaults
.comment_strings
["elisp"] + '.. |elisp> ' + line
97 def elisp_code_postprocessor(data
):
98 """Convert specially-marked reST comments to Emacs Lisp code.
100 In all lines, the prefix ``.. |elisp> `` (note
101 the trailing space!) is stripped from the begin of a line.
103 For instance, the block:
106 .. |elisp> (some-elisp-incantation)
112 (some-elisp-incantation)
116 # Set the prefix to be stripped
117 prefix
= pylit
.defaults
.comment_strings
["elisp"] + '.. |elisp> '
120 if line
.startswith(prefix
):
121 yield line
[len(prefix
):]
130 # Add default values for "elisp" to the `defaults` object from PyLit.
132 # The following code assumes that this plug-in is always evaluated in the
133 # pylit namespace and after pylit.py
137 pylit
.defaults
.languages
[".el"] = "elisp"
138 pylit
.defaults
.comment_strings
["elisp"] = ';; '
141 pylit
.defaults
.preprocessors
["elisp2text"] = elisp_code_preprocessor
142 pylit
.defaults
.postprocessors
["text2elisp"] = elisp_code_postprocessor