Mercurial > dotfiles
annotate .elisp/doctest-mode.el @ 140:7fa84e297c84
emacs modes: use comment-indent-new-line for python
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Tue, 15 Sep 2009 16:59:47 -0500 |
parents | b5d75594b356 |
children | 014e745b2d04 |
rev | line source |
---|---|
0 | 1 ;;; doctest-mode.el --- Major mode for editing Python doctest files |
2 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
3 ;; Copyright (C) 2004 Edward Loper |
0 | 4 |
5 ;; Author: Edward Loper | |
6 ;; Maintainer: edloper@alum.mit.edu | |
7 ;; Created: Aug 2004 | |
8 ;; Keywords: python doctest unittest test docstring | |
9 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
10 (defconst doctest-version "0.2" |
0 | 11 "`doctest-mode' version number.") |
12 | |
13 ;; This software is provided as-is, without express or implied | |
14 ;; warranty. Permission to use, copy, modify, distribute or sell this | |
15 ;; software, without fee, for any purpose and by any individual or | |
16 ;; organization, is hereby granted, provided that the above copyright | |
17 ;; notice and this paragraph appear in all copies. | |
18 | |
19 ;; This is a major mode for editing text files that contain Python | |
20 ;; doctest examples. Doctest is a testing framework for Python that | |
21 ;; emulates an interactive session, and checks the result of each | |
22 ;; command. For more information, see the Python library reference: | |
23 ;; <http://docs.python.org/lib/module-doctest.html> | |
24 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
25 ;; Known bugs: |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
26 ;; - Some places assume prompts are 4 chars (but they can be 3 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
27 ;; if they're bare). |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
28 ;; - String literals are not colored correctly. (We need to color |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
29 ;; string literals on source lines, but *not* output lines or |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
30 ;; text lines; this is hard to do.) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
31 ;; - Output lines starting with "..." are mistakenly interpreted |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
32 ;; as (continuation) source lines. |
0 | 33 |
34 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
35 ;; Customizable Constants |
0 | 36 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
37 | |
38 (defgroup doctest nil | |
39 "Support for the Python doctest framework" | |
40 :group 'languages | |
41 :prefix "doctest-") | |
42 | |
43 (defcustom doctest-default-margin 4 | |
44 "The default pre-prompt margin for doctest examples." | |
45 :type 'integer | |
46 :group 'doctest) | |
47 | |
48 (defcustom doctest-avoid-trailing-whitespace t | |
49 "If true, then delete trailing whitespace when inserting a newline." | |
50 :type 'boolean | |
51 :group 'doctest) | |
52 | |
53 (defcustom doctest-temp-directory | |
54 (let ((ok '(lambda (x) | |
55 (and x | |
56 (setq x (expand-file-name x)) ; always true | |
57 (file-directory-p x) | |
58 (file-writable-p x) | |
59 x)))) | |
60 (or (funcall ok (getenv "TMPDIR")) | |
61 (funcall ok "/usr/tmp") | |
62 (funcall ok "/tmp") | |
63 (funcall ok "/var/tmp") | |
64 (funcall ok ".") | |
65 (error (concat "Couldn't find a usable temp directory -- " | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
66 "set `doctest-temp-directory'")))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
67 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
68 "*Directory used for temporary files created when running doctest. |
0 | 69 By default, the first directory from this list that exists and that you |
70 can write into: the value (if any) of the environment variable TMPDIR, | |
71 /usr/tmp, /tmp, /var/tmp, or the current directory." | |
72 :type 'string | |
73 :group 'doctest) | |
74 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
75 (defcustom hide-example-source t |
0 | 76 "If true, then don't display the example source code for each |
77 failure in the results buffer." | |
78 :type 'boolean | |
79 :group 'doctest) | |
80 | |
81 (defcustom doctest-python-command "python" | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
82 "Shell command used to start the python interpreter") |
0 | 83 |
84 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
85 ;; Fonts |
0 | 86 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
87 | |
88 (defface doctest-prompt-face | |
89 '((((class color) (background dark)) | |
90 (:foreground "#68f")) | |
91 (t (:foreground "#226"))) | |
92 "Face for Python prompts in doctest examples." | |
93 :group 'doctest) | |
94 | |
95 (defface doctest-output-face | |
96 '((((class color) (background dark)) | |
97 (:foreground "#afd")) | |
98 (t (:foreground "#262"))) | |
99 "Face for the output of doctest examples." | |
100 :group 'doctest) | |
101 | |
102 (defface doctest-output-marker-face | |
103 '((((class color) (background dark)) | |
104 (:foreground "#0f0")) | |
105 (t (:foreground "#080"))) | |
106 "Face for markers in the output of doctest examples." | |
107 :group 'doctest) | |
108 | |
109 (defface doctest-output-traceback-face | |
110 '((((class color) (background dark)) | |
111 (:foreground "#f88")) | |
112 (t (:foreground "#622"))) | |
113 "Face for traceback headers in the output of doctest examples." | |
114 :group 'doctest) | |
115 | |
116 (defface doctest-results-divider-face | |
117 '((((class color) (background dark)) | |
118 (:foreground "#08f")) | |
119 (t (:foreground "#00f"))) | |
120 "Face for dividers in the doctest results window." | |
121 :group 'doctest) | |
122 | |
123 (defface doctest-results-loc-face | |
124 '((((class color) (background dark)) | |
125 (:foreground "#0f8")) | |
126 (t (:foreground "#084"))) | |
127 "Face for location headers in the doctest results window." | |
128 :group 'doctest) | |
129 | |
130 (defface doctest-results-header-face | |
131 '((((class color) (background dark)) | |
132 (:foreground "#8ff")) | |
133 (t (:foreground "#088"))) | |
134 "Face for sub-headers in the doctest results window." | |
135 :group 'doctest) | |
136 | |
137 (defface doctest-results-selection-face | |
138 '((((class color) (background dark)) | |
139 (:foreground "#ff0" :background "#008")) | |
140 (t (:background "#088" :foreground "#fff"))) | |
141 "Face for selected failure's location header in the results window." | |
142 :group 'doctest) | |
143 | |
144 (defface doctest-selection-face | |
145 '((((class color) (background dark)) | |
146 (:foreground "#ff0" :background "#00f" :bold t)) | |
147 (t (:foreground "#f00"))) | |
148 "Face for selected example's prompt" | |
149 :group 'doctest) | |
150 | |
151 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
152 ;; Constants |
0 | 153 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
154 | |
155 (defconst doctest-prompt-re | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
156 "^\\([ \t]*\\)\\(>>> ?\\|[.][.][.] ?\\)\\([ \t]*\\)" |
0 | 157 "Regular expression for doctest prompts. It defines three groups: |
158 the pre-prompt margin; the prompt; and the post-prompt indentation.") | |
159 | |
160 (defconst doctest-open-block-re | |
161 "[^\n]+:[ \t]*\\(#.*\\)?$" | |
162 "Regular expression for a line that opens a block") | |
163 | |
164 (defconst doctest-close-block-re | |
165 "\\(return\\|raise\\|break\\|continue\\|pass\\)\\b" | |
166 "Regular expression for a line that closes a block") | |
167 | |
168 (defconst doctest-outdent-re | |
169 (concat "\\(" (mapconcat 'identity | |
170 '("else:" | |
171 "except\\(\\s +.*\\)?:" | |
172 "finally:" | |
173 "elif\\s +.*:") | |
174 "\\|") | |
175 "\\)") | |
176 "Regular expression for a line that should be outdented. Any line | |
177 that matches `doctest-outdent-re', but does not follow a line matching | |
178 `doctest-no-outdent-re', will be outdented.") | |
179 | |
180 (defconst doctest-no-outdent-re | |
181 (concat | |
182 "\\(" | |
183 (mapconcat 'identity | |
184 (list "try:" | |
185 "except\\(\\s +.*\\)?:" | |
186 "while\\s +.*:" | |
187 "for\\s +.*:" | |
188 "if\\s +.*:" | |
189 "elif\\s +.*:" | |
190 "\\(return\\|raise\\|break\\|continue\\|pass\\)[ \t\n]" | |
191 ) | |
192 "\\|") | |
193 "\\)") | |
194 "Regular expression matching lines not to outdent after. Any line | |
195 that matches `doctest-outdent-re', but does not follow a line matching | |
196 `doctest-no-outdent-re', will be outdented.") | |
197 | |
198 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
199 ;; Colorization support (font-lock mode) |
0 | 200 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
201 | |
202 ;; Define the font-lock keyword table. | |
203 (defconst doctest-font-lock-keywords | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
204 (let ((prompt "^[ \t]*\\(>>>\\|\\.\\.\\.\\)") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
205 (kw1 (mapconcat 'identity |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
206 '("and" "assert" "break" "class" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
207 "continue" "def" "del" "elif" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
208 "else" "except" "exec" "for" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
209 "from" "global" "if" "import" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
210 "in" "is" "lambda" "not" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
211 "or" "pass" "print" "raise" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
212 "return" "while" "yield" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
213 ) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
214 "\\|")) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
215 (kw2 (mapconcat 'identity |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
216 '("else:" "except:" "finally:" "try:") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
217 "\\|")) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
218 (kw3 (mapconcat 'identity |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
219 '("ArithmeticError" "AssertionError" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
220 "AttributeError" "DeprecationWarning" "EOFError" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
221 "Ellipsis" "EnvironmentError" "Exception" "False" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
222 "FloatingPointError" "FutureWarning" "IOError" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
223 "ImportError" "IndentationError" "IndexError" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
224 "KeyError" "KeyboardInterrupt" "LookupError" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
225 "MemoryError" "NameError" "None" "NotImplemented" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
226 "NotImplementedError" "OSError" "OverflowError" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
227 "OverflowWarning" "PendingDeprecationWarning" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
228 "ReferenceError" "RuntimeError" "RuntimeWarning" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
229 "StandardError" "StopIteration" "SyntaxError" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
230 "SyntaxWarning" "SystemError" "SystemExit" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
231 "TabError" "True" "TypeError" "UnboundLocalError" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
232 "UnicodeDecodeError" "UnicodeEncodeError" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
233 "UnicodeError" "UnicodeTranslateError" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
234 "UserWarning" "ValueError" "Warning" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
235 "ZeroDivisionError" "__debug__" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
236 "__import__" "__name__" "abs" "apply" "basestring" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
237 "bool" "buffer" "callable" "chr" "classmethod" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
238 "cmp" "coerce" "compile" "complex" "copyright" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
239 "delattr" "dict" "dir" "divmod" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
240 "enumerate" "eval" "execfile" "exit" "file" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
241 "filter" "float" "getattr" "globals" "hasattr" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
242 "hash" "hex" "id" "input" "int" "intern" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
243 "isinstance" "issubclass" "iter" "len" "license" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
244 "list" "locals" "long" "map" "max" "min" "object" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
245 "oct" "open" "ord" "pow" "property" "range" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
246 "raw_input" "reduce" "reload" "repr" "round" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
247 "setattr" "slice" "staticmethod" "str" "sum" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
248 "super" "tuple" "type" "unichr" "unicode" "vars" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
249 "xrange" "zip") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
250 "\\|")) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
251 (pseudokw (mapconcat 'identity |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
252 '("self" "None" "True" "False" "Ellipsis") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
253 "\\|")) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
254 (brk "\\([ \t(]\\|$\\)") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
255 ) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
256 `( |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
257 ;; The following pattern colorizes source lines. In particular, |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
258 ;; it first matches prompts, and then looks for any of the |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
259 ;; following matches *on the same line* as the prompt. It uses |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
260 ;; the form: |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
261 ;; |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
262 ;; (MATCHER MATCH-HIGHLIGHT |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
263 ;; (ANCHOR-MATCHER nil nil MATCH-HIGHLIGHT) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
264 ;; ... |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
265 ;; (ANCHOR-MATCHER nil nil MATCH-HIGHLIGHT)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
266 ;; |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
267 ;; See the variable documentation for font-lock-keywords for a |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
268 ;; description of what each of those means. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
269 (,prompt (1 'doctest-prompt-face) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
270 ;; classes |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
271 ("\\b\\(class\\)[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
272 nil nil (1 'font-lock-keyword-face) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
273 (2 'font-lock-type-face)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
274 ;; functions |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
275 ("\\b\\(def\\)[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
276 nil nil (1 'font-lock-keyword-face) (2 'font-lock-type-face)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
277 ;; keywords |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
278 (,(concat "\\b\\(" kw1 "\\)" brk) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
279 nil nil (1 'font-lock-keyword-face)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
280 ;; builtins when they don't appear as object attributes |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
281 (,(concat "\\(\\b\\|[.]\\)\\(" kw3 "\\)" brk) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
282 nil nil (2 'font-lock-keyword-face)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
283 ;; block introducing keywords with immediately |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
284 ;; following colons. Yes "except" is in both lists. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
285 (,(concat "\\b\\(" kw2 "\\)" brk) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
286 nil nil (1 'font-lock-keyword-face)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
287 ;; `as' but only in "import foo as bar" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
288 ("[ \t]*\\(\\bfrom\\b.*\\)?\\bimport\\b.*\\b\\(as\\)\\b" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
289 nil nil (2 'font-lock-keyword-face)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
290 ;; pseudo-keywords |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
291 (,(concat "\\b\\(" pseudokw "\\)" brk) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
292 nil nil (1 'font-lock-keyword-face)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
293 ;; comments |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
294 ("\\(#.*\\)" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
295 nil nil (1 'font-lock-comment-face))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
296 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
297 ;; The following pattern colorizes output lines. In particular, |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
298 ;; it uses doctest-output-line-matcher to check if this is an |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
299 ;; output line, and if so, it colorizes it, and any special |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
300 ;; markers it contains. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
301 (doctest-output-line-matcher |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
302 (0 'doctest-output-face t) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
303 ("\\.\\.\\." (beginning-of-line) (end-of-line) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
304 (0 'doctest-output-marker-face t)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
305 ("<BLANKLINE>" (beginning-of-line) (end-of-line) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
306 (0 'doctest-output-marker-face t)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
307 ("^Traceback (most recent call last):" (beginning-of-line) (end-of-line) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
308 (0 'doctest-output-traceback-face t)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
309 ("^Traceback (innermost last):" (beginning-of-line) (end-of-line) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
310 (0 'doctest-output-traceback-face t)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
311 ) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
312 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
313 ;; A PS1 prompt followed by a non-space is an error. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
314 ("^[ \t]*\\(>>>[^ \t\n][^\n]*\\)" (1 'font-lock-warning-face t)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
315 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
316 ;; Selected example (to highlight selected failure) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
317 (doctest-selection-matcher (0 'doctest-selection-face t)) |
0 | 318 )) |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
319 "Expressions to highlight in Doctest mode.") |
0 | 320 |
321 (defun doctest-output-line-matcher (limit) | |
322 "A `font-lock-keyword' MATCHER that returns t if the current | |
323 line is the expected output for a doctest example, and if so, | |
324 sets `match-data' so that group 0 spans the current line." | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
325 ;; The real work is done by find-doctest-output-line. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
326 (when (find-doctest-output-line limit) |
0 | 327 ;; If we found one, then mark the entire line. |
328 (beginning-of-line) | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
329 (search-forward-regexp "[^\n]*" limit))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
330 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
331 ;; [XX] Under construction. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
332 (defun doctest-selection-matcher (limit) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
333 (let (found-it) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
334 (while (and (not found-it) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
335 (search-forward-regexp "^[ \t]*\\(>>>\\|[.][.][.]\\)" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
336 limit t)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
337 (if (get-text-property (point) 'doctest-selected) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
338 (setq found-it t))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
339 found-it)) |
0 | 340 |
341 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
342 ;; Source line indentation |
0 | 343 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
344 | |
345 (defun doctest-indent-source-line (&optional dedent-only) | |
346 "Re-indent the current line, as doctest source code. I.e., add a | |
347 prompt to the current line if it doesn't have one, and re-indent the | |
348 source code (to the right of the prompt). If `dedent-only' is true, | |
349 then don't increase the indentation level any." | |
350 (interactive "*") | |
351 (let ((indent-end nil)) | |
352 (save-excursion | |
353 (beginning-of-line) | |
354 (let ((new-indent (doctest-current-source-line-indentation dedent-only)) | |
355 (new-margin (doctest-current-source-line-margin)) | |
356 (line-had-prompt (looking-at doctest-prompt-re))) | |
357 ;; Delete the old prompt (if any). | |
358 (when line-had-prompt | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
359 (goto-char (match-end 1)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
360 (delete-char 4)) |
0 | 361 ;; Delete the old indentation. |
362 (delete-backward-char (skip-chars-forward " \t")) | |
363 ;; If it's a continuation line, or a new PS1 prompt, | |
364 ;; then copy the margin. | |
365 (when (or new-indent (not line-had-prompt)) | |
366 (beginning-of-line) | |
367 (delete-backward-char (skip-chars-forward " \t")) | |
368 (insert-char ?\ new-margin)) | |
369 ;; Add the new prompt. | |
370 (insert-string (if new-indent "... " ">>> ")) | |
371 ;; Add the new indentation | |
372 (if new-indent (insert-char ?\ new-indent)) | |
373 (setq indent-end (point)))) | |
374 ;; If we're left of the indentation end, then move up to the | |
375 ;; indentation end. | |
376 (if (< (point) indent-end) (goto-char indent-end)))) | |
377 | |
378 (defun doctest-current-source-line-indentation (&optional dedent-only) | |
379 "Return the post-prompt indent to use for this line. This is an | |
380 integer for a continuation lines, and nil for non-continuation lines." | |
381 (save-excursion | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
382 (let ((prev-line-indent 0) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
383 (curr-line-indent 0) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
384 (prev-line-opens-block nil) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
385 (prev-line-closes-block nil) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
386 (curr-line-outdented nil)) |
0 | 387 ;; Examine this doctest line. |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
388 (beginning-of-line) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
389 (when (looking-at doctest-prompt-re) |
0 | 390 (setq curr-line-indent (- (match-end 3) (match-beginning 3))) |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
391 (goto-char (match-end 3))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
392 (setq curr-line-outdented (looking-at doctest-outdent-re)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
393 ;; Examine the previous line. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
394 (when (= (forward-line -1) 0) ; move up a line |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
395 (when (looking-at doctest-prompt-re) ; is it a source line? |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
396 (let ((indent-beg (column-at-char (match-beginning 3))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
397 (indent-end (column-at-char (match-end 3)))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
398 (setq prev-line-indent (- indent-end indent-beg)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
399 (goto-char (match-end 3)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
400 (if (looking-at doctest-open-block-re) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
401 (setq prev-line-opens-block t)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
402 (if (looking-at doctest-close-block-re) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
403 (setq prev-line-closes-block t)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
404 (if (looking-at doctest-no-outdent-re) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
405 (setq curr-line-outdented nil)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
406 ))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
407 (let ((indent (+ prev-line-indent |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
408 (if curr-line-outdented -4 0) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
409 (if prev-line-opens-block 4 0) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
410 (if prev-line-closes-block -4 0)))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
411 ;; If dedent-only is true, then make sure we don't indent. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
412 (when dedent-only |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
413 (setq indent (min indent curr-line-indent))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
414 ;; If indent=0 and we're not outdented, then set indent to |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
415 ;; nil (to signify the start of a new source example). |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
416 (when (and (= indent 0) (not curr-line-outdented)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
417 (setq indent nil)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
418 ;; Return the indentation. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
419 indent)))) |
0 | 420 |
421 (defun doctest-current-source-line-margin () | |
422 "Return the pre-prompt margin to use for this source line. This is | |
423 copied from the most recent source line, or set to | |
424 `doctest-default-margin' if there are no preceeding source lines." | |
425 (save-excursion | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
426 (beginning-of-line) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
427 (if (search-backward-regexp doctest-prompt-re nil t) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
428 (let ((margin-beg (column-at-char (match-beginning 1))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
429 (margin-end (column-at-char (match-end 1)))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
430 (- margin-end margin-beg)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
431 doctest-default-margin))) |
0 | 432 |
433 (defun doctest-electric-backspace () | |
434 "Delete the preceeding character, level of indentation, or | |
435 prompt. | |
436 | |
437 If point is at the leftmost column, delete the preceding newline. | |
438 | |
439 Otherwise, if point is at the first non-whitespace character | |
440 following an indented source line's prompt, then reduce the | |
441 indentation to the next multiple of 4; and update the source line's | |
442 prompt, when necessary. | |
443 | |
444 Otherwise, if point is at the first non-whitespace character | |
445 following an unindented source line's prompt, then remove the | |
446 prompt (converting the line to an output line or text line). | |
447 | |
448 Otherwise, if point is at the first non-whitespace character of a | |
449 line, the delete the line's indentation. | |
450 | |
451 Otherwise, delete the preceeding character. | |
452 " | |
453 (interactive "*") | |
454 (cond | |
455 ;; Beginning of line: delete preceeding newline. | |
456 ((bolp) (backward-delete-char 1)) | |
457 | |
458 ;; First non-ws char following prompt: dedent or remove prompt. | |
459 ((and (looking-at "[^ \t\n]\\|$") (doctest-looking-back doctest-prompt-re)) | |
460 (let* ((prompt-beg (match-beginning 2)) | |
461 (indent-beg (match-beginning 3)) (indent-end (match-end 3)) | |
462 (old-indent (- indent-end indent-beg)) | |
463 (new-indent (* (/ (- old-indent 1) 4) 4))) | |
464 (cond | |
465 ;; Indented source line: dedent it. | |
466 ((> old-indent 0) | |
467 (goto-char indent-beg) | |
468 (delete-region indent-beg indent-end) | |
469 (insert-char ?\ new-indent) | |
470 ;; Change prompt to PS1, when appropriate. | |
471 (when (and (= new-indent 0) (not (looking-at doctest-outdent-re))) | |
472 (delete-backward-char 4) | |
473 (insert-string ">>> "))) | |
474 ;; Non-indented source line: remove prompt. | |
475 (t | |
476 (goto-char indent-end) | |
477 (delete-region prompt-beg indent-end))))) | |
478 | |
479 ;; First non-ws char of a line: delete all indentation. | |
480 ((and (looking-at "[^ \n\t]\\|$") (doctest-looking-back "^[ \t]+")) | |
481 (delete-region (match-beginning 0) (match-end 0))) | |
482 | |
483 ;; Otherwise: delete a character. | |
484 (t | |
485 (backward-delete-char 1)))) | |
486 | |
487 (defun doctest-newline-and-indent () | |
488 "Insert a newline, and indent the new line appropriately. | |
489 | |
490 If the current line is a source line containing a bare prompt, | |
491 then clear the current line, and insert a newline. | |
492 | |
493 Otherwise, if the current line is a source line, then insert a | |
494 newline, and add an appropriately indented prompt to the new | |
495 line. | |
496 | |
497 Otherwise, if the current line is an output line, then insert a | |
498 newline and indent the new line to match the example's margin. | |
499 | |
500 Otherwise, insert a newline. | |
501 | |
502 If `doctest-avoid-trailing-whitespace' is true, then clear any | |
503 whitespace to the left of the point before inserting a newline. | |
504 " | |
505 (interactive "*") | |
506 ;; If we're avoiding trailing spaces, then delete WS before point. | |
507 (if doctest-avoid-trailing-whitespace | |
508 (delete-char (- (skip-chars-backward " \t")))) | |
509 (cond | |
510 ;; If we're on an empty prompt, delete it. | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
511 ((on-empty-doctest-source-line) |
0 | 512 (delete-region (match-beginning 0) (match-end 0)) |
513 (insert-char ?\n 1)) | |
514 ;; If we're on a doctest line, add a new prompt. | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
515 ((on-doctest-source-line) |
0 | 516 (insert-char ?\n 1) |
517 (doctest-indent-source-line)) | |
518 ;; If we're in doctest output, indent to the margin. | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
519 ((on-doctest-output-line) |
0 | 520 (insert-char ?\n 1) |
521 (insert-char ?\ (doctest-current-source-line-margin))) | |
522 ;; Otherwise, just add a newline. | |
523 (t (insert-char ?\n 1)))) | |
524 | |
525 (defun doctest-electric-colon () | |
526 "Insert a colon, and dedent the line when appropriate." | |
527 (interactive "*") | |
528 (insert-char ?: 1) | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
529 (when (on-doctest-source-line) |
0 | 530 (doctest-indent-source-line t))) |
531 | |
532 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
533 ;; Code Execution |
0 | 534 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
535 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
536 ;; Add support for options (eg diff!) |
0 | 537 (defun doctest-execute-buffer () |
538 "Run doctest on the current buffer, and display the results in the | |
539 *doctest-output* buffer." | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
540 (interactive "*") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
541 (setq doctest-results-buffer (get-buffer-create "*doctest-output*")) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
542 (let* ((temp (concat (doctest-temp-name) ".py")) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
543 (tempfile (expand-file-name temp doctest-temp-directory)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
544 (cur-buf (current-buffer)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
545 (in-buf (get-buffer-create "*doctest-input*")) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
546 (beg (point-min)) (end (point-max)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
547 (script (concat "from doctest import *\n" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
548 "doc = open('" tempfile "').read()\n" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
549 "test = DocTestParser().get_doctest(" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
550 "doc, {}, '" (buffer-name) "', '" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
551 (buffer-file-name) "', 0)\n" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
552 "r = DocTestRunner()\n" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
553 "r.run(test)\n")) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
554 (cmd (concat doctest-python-command " -c \"" script "\""))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
555 ;; Write buffer to a file. |
0 | 556 (save-excursion |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
557 (set-buffer in-buf) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
558 (insert-buffer-substring cur-buf beg end) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
559 (write-file tempfile)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
560 ;; Run doctest |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
561 (shell-command cmd doctest-results-buffer) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
562 ;; Delete the temp file |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
563 (delete-file tempfile) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
564 ;; Set mode on output buffer. |
0 | 565 (save-excursion |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
566 (set-buffer doctest-results-buffer) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
567 (doctest-results-mode)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
568 ;; If any tests failed, display them. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
569 (cond ((> (buffer-size doctest-results-buffer) 0) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
570 (message "Test failed!") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
571 (display-buffer doctest-results-buffer) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
572 (doctest-postprocess-results)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
573 (t |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
574 (message "Test passed!") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
575 (if (get-buffer-window doctest-results-buffer) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
576 (delete-window (get-buffer-window doctest-results-buffer))))))) |
0 | 577 |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
578 (defun doctest-postprocess-results () |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
579 (doctest-next-failure 1) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
580 (if hide-example-source |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
581 (hide-example-source))) |
0 | 582 |
583 (defun doctest-next-failure (count) | |
584 "Move to the top of the next failing example, and highlight the | |
585 example's failure description in *doctest-output*." | |
586 (interactive "p") | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
587 (let (lineno) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
588 (cond |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
589 ((not (buffer-live-p doctest-results-buffer)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
590 (message "Run doctest first! (C-c C-c)")) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
591 (t |
0 | 592 (save-excursion |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
593 (let ((orig-window (selected-window)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
594 (results-window (display-buffer doctest-results-buffer))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
595 ;; Switch to the results window (so its point gets updated) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
596 (if results-window (select-window results-window)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
597 ;; Pick up where we left off. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
598 ;; (nb: doctest-selected-failure is buffer-local) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
599 (goto-char (or doctest-selected-failure (point-min))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
600 ;; Skip past anything on *this* line. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
601 (if (>= count 0) (end-of-line) (beginning-of-line)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
602 ;; Look for the next failure |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
603 (if (>= count 0) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
604 (re-search-forward doctest-results-loc-re nil t count) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
605 (re-search-backward doctest-results-loc-re nil t (- count))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
606 (cond |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
607 ;; We found a failure: |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
608 ((match-string 2) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
609 (let ((old-selected-failure doctest-selected-failure)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
610 ;; Extract the line number for the doctest file. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
611 (setq lineno (string-to-int (match-string 2))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
612 ;; Store our position for next time. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
613 (beginning-of-line) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
614 (setq doctest-selected-failure (point)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
615 ;; Update selection. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
616 (doctest-fontify-line old-selected-failure) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
617 (doctest-fontify-line doctest-selected-failure))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
618 ;; We didn't find a failure: |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
619 (t |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
620 (message "No failures found!"))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
621 ;; Return to the original window |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
622 (select-window orig-window))))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
623 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
624 (when lineno |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
625 ;; Move point to the selected failure. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
626 (goto-line lineno) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
627 ; ;; Highlight it. [XX] Under construction. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
628 ; (let ((beg (save-excursion (beginning-of-line) (point))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
629 ; (end (save-excursion (end-of-line) (point)))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
630 ; (add-text-properties (point-min) (point-max) '(doctest-selected nil)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
631 ; (add-text-properties beg end '(doctest-selected t)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
632 ; (doctest-fontify-line (point))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
633 ))) |
0 | 634 |
635 (defun doctest-prev-failure (count) | |
636 "Move to the top of the previous failing example, and highlight | |
637 the example's failure description in *doctest-output*." | |
638 (interactive "p") | |
639 (doctest-next-failure (- count))) | |
640 | |
641 (defun doctest-first-failure () | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
642 (interactive "") |
0 | 643 (if (buffer-live-p doctest-results-buffer) |
644 (save-excursion | |
645 (set-buffer doctest-results-buffer) | |
646 (let ((old-selected-failure doctest-selected-failure)) | |
647 (setq doctest-selected-failure (point-min)) | |
648 (doctest-fontify-line old-selected-failure)))) | |
649 (doctest-next-failure 1)) | |
650 | |
651 (defun doctest-last-failure () | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
652 (interactive "") |
0 | 653 (if (buffer-live-p doctest-results-buffer) |
654 (save-excursion | |
655 (set-buffer doctest-results-buffer) | |
656 (let ((old-selected-failure doctest-selected-failure)) | |
657 (setq doctest-selected-failure (point-max)) | |
658 (doctest-fontify-line old-selected-failure)))) | |
659 (doctest-next-failure -1)) | |
660 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
661 (defconst doctest-example-source-re |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
662 "^Failed example:\n\\(\n\\| [^\n]*\n\\)+") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
663 (defun hide-example-source () |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
664 "Delete the source code listings from the results buffer (since it's |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
665 easy enough to see them in the original buffer)" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
666 (save-excursion |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
667 (set-buffer doctest-results-buffer) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
668 (toggle-read-only nil) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
669 (beginning-of-buffer) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
670 (while (re-search-forward doctest-example-source-re nil t) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
671 (replace-match "" nil nil)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
672 (toggle-read-only t))) |
0 | 673 |
674 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
675 ;; Doctest Results Mode (output of doctest-execute-buffer) |
0 | 676 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
677 ;; [XX] Todo: |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
678 ;; - Make it read-only? |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
679 ;; - Hitting enter goes to the corresponding error |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
680 ;; - Clicking goes to corresponding error (not as useful) |
0 | 681 |
682 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
683 (defconst doctest-results-divider-re |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
684 "^\\([*]\\{60,\\}\\)$") |
0 | 685 |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
686 (defconst doctest-results-loc-re |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
687 "^File \"\\([^\"]+\\)\", line \\([0-9]+\\), in \\([^\n]+\\)") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
688 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
689 (defconst doctest-results-header-re |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
690 "^\\([a-zA-Z0-9 ]+:\\)$") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
691 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
692 (defconst doctest-results-font-lock-keywords |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
693 `((,doctest-results-divider-re |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
694 (0 'doctest-results-divider-face)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
695 (,doctest-results-loc-re |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
696 (0 'doctest-results-loc-face)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
697 (,doctest-results-header-re |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
698 (0 'doctest-results-header-face)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
699 (doctest-results-selection-matcher |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
700 (0 'doctest-results-selection-face t)))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
701 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
702 (defun doctest-results-selection-matcher (limit) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
703 "Matches from `doctest-selected-failure' to the end of the |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
704 line. This is used to highlight the currently selected failure." |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
705 (when (and doctest-selected-failure |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
706 (<= (point) doctest-selected-failure) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
707 (< doctest-selected-failure limit)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
708 (goto-char doctest-selected-failure) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
709 (search-forward-regexp "[^\n]+" limit))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
710 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
711 ;; Register the font-lock keywords (xemacs) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
712 (put 'doctest-results-mode 'font-lock-defaults |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
713 '(doctest-results-font-lock-keywords)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
714 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
715 ;; Register the font-lock keywords (gnu emacs) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
716 (defvar font-lock-defaults-alist nil) ; in case we're in xemacs |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
717 (setq font-lock-defaults-alist |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
718 (append font-lock-defaults-alist |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
719 `((doctest-results-mode |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
720 doctest-results-font-lock-keywords |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
721 nil nil nil nil)))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
722 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
723 ;; Define the mode |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
724 (define-derived-mode doctest-results-mode text-mode "Doctest Results" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
725 "docstring" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
726 ;; Enable font-lock mode. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
727 (if (featurep 'font-lock) (font-lock-mode 1)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
728 ;; Keep track of which failure is selected |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
729 (set (make-local-variable 'doctest-selected-failure) nil) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
730 ;; Make the buffer read-only. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
731 (toggle-read-only t)) |
0 | 732 |
733 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
734 ;; Helper functions |
0 | 735 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
736 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
737 (defun on-doctest-source-line () |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
738 "Return true if the current line is a source line." |
0 | 739 (save-excursion |
740 (beginning-of-line) | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
741 (looking-at doctest-prompt-re))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
742 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
743 (defun on-empty-doctest-source-line () |
0 | 744 "Return true if the current line contains a bare prompt." |
745 (save-excursion | |
746 (beginning-of-line) | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
747 (looking-at (concat doctest-prompt-re "$")))) |
0 | 748 |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
749 (defun on-doctest-output-line () |
0 | 750 "Return true if the current line is an output line." |
751 (save-excursion | |
752 (beginning-of-line) | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
753 (let ((prompt-or-blankline (concat doctest-prompt-re "\\|" "^[ \t]*\n"))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
754 ;; The line must not be blank or start with a prompt. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
755 (when (not (looking-at prompt-or-blankline)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
756 ;; The line must follow a line starting with a prompt, with |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
757 ;; no intervening blank lines. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
758 (search-backward-regexp prompt-or-blankline nil t) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
759 (looking-at doctest-prompt-re))))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
760 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
761 (defun find-doctest-output-line (&optional limit) |
0 | 762 "Move forward to the next doctest output line (staying within |
763 the given bounds). Return the character position of the doctest | |
764 output line if one was found, and false otherwise." | |
765 (let ((found-it nil) ; point where we found an output line | |
766 (limit (or limit (point-max)))) ; default value for limit | |
767 (save-excursion | |
768 ;; Keep moving forward, one line at a time, until we find a | |
769 ;; doctest output line. | |
770 (while (and (not found-it) (< (point) limit) (not (eobp))) | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
771 (if (and (not (eolp)) (on-doctest-output-line)) |
0 | 772 (setq found-it (point)) |
773 (forward-line)))) | |
774 ;; If we found a doctest output line, then go to it. | |
775 (if found-it (goto-char found-it)))) | |
776 | |
777 (defun doctest-version () | |
778 "Echo the current version of `doctest-mode' in the minibuffer." | |
779 (interactive) | |
780 (message "Using `doctest-mode' version %s" doctest-version)) | |
781 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
782 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
783 ;; Utility functions |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
784 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
0 | 785 |
786 (defvar doctest-serial-number 0) ;used if broken-temp-names. | |
787 (defun doctest-temp-name () | |
788 (if (memq 'broken-temp-names features) | |
789 (let | |
790 ((sn doctest-serial-number) | |
791 (pid (and (fboundp 'emacs-pid) (emacs-pid)))) | |
792 (setq doctest-serial-number (1+ doctest-serial-number)) | |
793 (if pid | |
794 (format "doctest-%d-%d" sn pid) | |
795 (format "doctest-%d" sn))) | |
796 (make-temp-name "doctest-"))) | |
797 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
798 (defun column-at-char (pos) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
799 "Return the column of the given character position" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
800 (save-excursion (goto-char pos) (current-column))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
801 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
802 (defun doctest-looking-back (regexp) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
803 "Return True if the text before point matches the given regular |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
804 expression. Like looking-at except backwards and slower. (This |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
805 is available as `looking-back' in GNU emacs and |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
806 `looking-at-backwards' in XEmacs, but it's easy enough to define |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
807 from scratch such that it works under both.)" |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
808 (save-excursion |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
809 (let ((orig-pos (point))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
810 ;; Search backwards for the regexp. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
811 (if (re-search-backward regexp nil t) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
812 ;; Check if it ends at the original point. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
813 (= orig-pos (match-end 0)))))) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
814 |
0 | 815 (defun doctest-fontify-line (charpos) |
816 "Run font-lock-fontify-region on the line containing the given | |
817 position." | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
818 (if charpos |
0 | 819 (save-excursion |
820 (goto-char charpos) | |
821 (let ((beg (progn (beginning-of-line) (point))) | |
822 (end (progn (end-of-line) (point)))) | |
823 (font-lock-fontify-region beg end))))) | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
824 |
0 | 825 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
826 ;; Syntax Table |
0 | 827 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
828 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
829 ;; We do *NOT* currently use this, because it applies too |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
830 ;; indiscrimanantly. In particular, we don't want "'" and '"' treated |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
831 ;; as quote marks on text lines. But there's no good way to prevent |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
832 ;; it. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
833 (defvar doctest-syntax-alist nil |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
834 "Syntax alist used in `doctest-mode' buffers.") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
835 (setq doctest-syntax-alist '((?\( . "()") (?\[ . "(]") (?\{ . "(}") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
836 (?\) . ")(") (?\] . ")[") (?\} . "){") |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
837 (?\$ . "." ) (?\% . "." ) (?\& . "." ) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
838 (?\* . "." ) (?\+ . "." ) (?\- . "." ) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
839 (?\/ . "." ) (?\< . "." ) (?\= . "." ) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
840 (?\> . "." ) (?\| . "." ) (?\_ . "w" ) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
841 (?\' . "\"") (?\" . "\"") (?\` . "$" ) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
842 (?\# . "<" ) (?\n . ">" ))) |
0 | 843 |
844 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
845 ;; Key Bindings |
0 | 846 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
847 | |
848 (defconst doctest-mode-map | |
849 (let ((map (make-keymap))) | |
850 (define-key map [backspace] 'doctest-electric-backspace) | |
851 (define-key map [return] 'doctest-newline-and-indent) | |
852 (define-key map [tab] 'doctest-indent-source-line) | |
853 (define-key map ":" 'doctest-electric-colon) | |
854 (define-key map "\C-c\C-v" 'doctest-version) | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
855 (define-key map "\C-c\C-c" 'doctest-execute-buffer) |
0 | 856 (define-key map "\C-c\C-n" 'doctest-next-failure) |
857 (define-key map "\C-c\C-p" 'doctest-prev-failure) | |
858 (define-key map "\C-c\C-a" 'doctest-first-failure) | |
859 (define-key map "\C-c\C-z" 'doctest-last-failure) | |
860 map) | |
861 "Keymap for doctest-mode.") | |
862 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
863 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
864 ;; Define the mode |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
865 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
866 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
867 ;; Register the font-lock keywords (xemacs) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
868 (put 'doctest-mode 'font-lock-defaults '(doctest-font-lock-keywords)) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
869 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
870 ;; Register the font-lock keywords (gnu emacs) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
871 (defvar font-lock-defaults-alist nil) ; in case we're in xemacs |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
872 (setq font-lock-defaults-alist |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
873 (append font-lock-defaults-alist |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
874 `((doctest-mode doctest-font-lock-keywords nil nil nil nil)))) |
0 | 875 |
876 ;; Use doctest mode for files ending in .doctest | |
877 ;;;###autoload | |
878 (add-to-list 'auto-mode-alist '("\\.doctest$" . doctest-mode)) | |
879 | |
880 ;;;###autoload | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
881 (define-derived-mode doctest-mode text-mode "Doctest" |
0 | 882 "A major mode for editing text files that contain Python |
883 doctest examples. Doctest is a testing framework for Python that | |
884 emulates an interactive session, and checks the result of each | |
885 command. For more information, see the Python library reference: | |
886 <http://docs.python.org/lib/module-doctest.html> | |
887 | |
888 `doctest-mode' defines three kinds of line, each of which is | |
889 treated differently: | |
890 | |
891 - 'Source lines' are lines consisting of a Python prompt | |
892 ('>>>' or '...'), followed by source code. Source lines are | |
893 colored (similarly to `python-mode') and auto-indented. | |
894 | |
895 - 'Output lines' are non-blank lines immediately following | |
896 source lines. They are colored using several doctest- | |
897 specific output faces. | |
898 | |
899 - 'Text lines' are any other lines. They are not processed in | |
900 any special way. | |
901 | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
902 \\{doctest-mode-map} |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
903 " |
0 | 904 ;; Enable auto-fill mode. |
905 (auto-fill-mode 1) | |
906 | |
907 ;; Enable font-lock mode. | |
908 (if (featurep 'font-lock) (font-lock-mode 1)) | |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
909 |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
910 ;; Register our indentation function. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
911 (set (make-local-variable 'indent-line-function) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
912 'doctest-indent-source-line) |
0 | 913 |
19
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
914 ;; Keep track of our results buffer. |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
915 (set (make-local-variable 'doctest-results-buffer) nil) |
b5d75594b356
Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
0
diff
changeset
|
916 ) |
0 | 917 |
918 (provide 'doctest-mode) | |
919 ;;; doctest-mode.el ends here |