annotate .elisp/doctest-mode.el @ 3:1921c0b85a82

Handy keybindings.
author Augie Fackler <durin42@gmail.com>
date Wed, 26 Nov 2008 18:47:20 -0600
parents c30d68fbd368
children b5d75594b356
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 ;;; doctest-mode.el --- Major mode for editing Python doctest files
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3 ;; Copyright (C) 2004-2007 Edward Loper
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
5 ;; Author: Edward Loper
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6 ;; Maintainer: edloper@alum.mit.edu
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7 ;; Created: Aug 2004
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 ;; Keywords: python doctest unittest test docstring
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10 (defconst doctest-version "0.5 alpha"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
11 "`doctest-mode' version number.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
12
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
13 ;; This software is provided as-is, without express or implied
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
14 ;; warranty. Permission to use, copy, modify, distribute or sell this
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
15 ;; software, without fee, for any purpose and by any individual or
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
16 ;; organization, is hereby granted, provided that the above copyright
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
17 ;; notice and this paragraph appear in all copies.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
18
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
19 ;; This is a major mode for editing text files that contain Python
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
20 ;; doctest examples. Doctest is a testing framework for Python that
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
21 ;; emulates an interactive session, and checks the result of each
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
22 ;; command. For more information, see the Python library reference:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
23 ;; <http://docs.python.org/lib/module-doctest.html>
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
24
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
25 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
26 ;;; Table of Contents
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
28 ;; 1. Customization: use-editable variables to customize
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
29 ;; doctest-mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
30 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
31 ;; 2. Fonts: defines new font-lock faces.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
32 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
33 ;; 3. Constants: various consts (mainly regexps) used by the rest
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
34 ;; of the code.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
35 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
36 ;; 4. Syntax Highlighting: defines variables and functions used by
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
37 ;; font-lock-mode to perform syntax highlighting.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
38 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
39 ;; 5. Source code editing & indentation: commands used to
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
40 ;; automatically indent, dedent, & handle prompts.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
41 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
42 ;; 6. Code Execution: commands used to start doctest processes,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
43 ;; and handle their output.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
44 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
45 ;; 7. Markers: functions used to insert markers at the start of
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
46 ;; doctest examples. These are used to keep track of the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47 ;; correspondence between examples in the source buffer and
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48 ;; results in the output buffer.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
49 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 ;; 8. Navigation: commands used to navigate between failed examples.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
51 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
52 ;; 9. Replace Output: command used to replace a doctest example's
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
53 ;; expected output with its actual output.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
54 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
55 ;; 10. Helper functions: various helper functions used by the rest
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
56 ;; of the code.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
57 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
58 ;; 11. Emacs compatibility functions: defines compatible versions of
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
59 ;; functions that are defined for some versions of emacs but not
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
60 ;; others.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
61 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
62 ;; 12. Doctest Results Mode: defines doctest-results-mode, which is
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
63 ;; used for the output generated by doctest.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
64 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
65 ;; 13. Doctest Mode: defines doctest-mode itself.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
66 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
67
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
68
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
69 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70 ;;; Customizable Constants
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
71 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
72
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
73 (defgroup doctest nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
74 "Support for the Python doctest framework"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
75 :group 'languages
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
76 :prefix "doctest-")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
77
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
78 (defcustom doctest-default-margin 4
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
79 "The default pre-prompt margin for doctest examples."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
80 :type 'integer
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
81 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
82
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
83 (defcustom doctest-avoid-trailing-whitespace t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 "If true, then delete trailing whitespace when inserting a newline."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 :type 'boolean
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 (defcustom doctest-temp-directory
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89 (let ((ok '(lambda (x)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
90 (and x
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
91 (setq x (expand-file-name x)) ; always true
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
92 (file-directory-p x)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
93 (file-writable-p x)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
94 x))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
95 (or (funcall ok (getenv "TMPDIR"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
96 (funcall ok "/usr/tmp")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
97 (funcall ok "/tmp")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
98 (funcall ok "/var/tmp")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
99 (funcall ok ".")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
100 (error (concat "Couldn't find a usable temp directory -- "
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
101 "set `doctest-temp-directory'"))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
102 "Directory used for temporary files created when running doctest.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
103 By default, the first directory from this list that exists and that you
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
104 can write into: the value (if any) of the environment variable TMPDIR,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
105 /usr/tmp, /tmp, /var/tmp, or the current directory."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
106 :type 'string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
107 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
108
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
109 (defcustom doctest-hide-example-source nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
110 "If true, then don't display the example source code for each
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
111 failure in the results buffer."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
112 :type 'boolean
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
113 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
114
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
115 (defcustom doctest-python-command "python"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
116 "Shell command used to start the python interpreter"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
117 :type 'string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
118 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
119
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
120 (defcustom doctest-results-buffer-name "*doctest-output (%N)*"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
121 "The name of the buffer used to store the output of the doctest
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
122 command. This name can contain the following special sequences:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
123 %n -- replaced by the doctest buffer's name.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
124 %N -- replaced by the doctest buffer's name, with '.doctest'
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
125 stripped off.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
126 %f -- replaced by the doctest buffer's filename."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
127 :type 'string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
128 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
129
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
130 (defcustom doctest-optionflags '()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
131 "Option flags for doctest"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
132 :group 'doctest
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
133 :type '(repeat (choice (const :tag "Select an option..." "")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
134 (const :tag "Normalize whitespace"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
135 "NORMALIZE_WHITESPACE")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
136 (const :tag "Ellipsis"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
137 "ELLIPSIS")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
138 (const :tag "Don't accept True for 1"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
139 "DONT_ACCEPT_TRUE_FOR_1")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
140 (const :tag "Don't accept <BLANKLINE>"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
141 "DONT_ACCEPT_BLANKLINE")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
142 (const :tag "Ignore Exception detail"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
143 "IGNORE_EXCEPTION_DETAIL")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
144 (const :tag "Report only first failure"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
145 "REPORT_ONLY_FIRST_FAILURE")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
146 )))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
147
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
148 (defcustom doctest-async t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
149 "If true, then doctest will be run asynchronously."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
150 :type 'boolean
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
151 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
152
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
153 (defcustom doctest-trim-exceptions t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
154 "If true, then any exceptions inserted by doctest-replace-output
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
155 will have the stack trace lines trimmed."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
156 :type 'boolean
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
157 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
158
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
159 (defcustom doctest-highlight-strings t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
160 "If true, then highlight strings. If you find that doctest-mode
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
161 is responding slowly when you type, turning this off might help."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
162 :type 'boolean
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
163 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
164
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
165 (defcustom doctest-follow-output t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
166 "If true, then when doctest is run asynchronously, the output buffer
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
167 will scroll to display its output as it is generated. If false, then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
168 the output buffer not scroll."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
169 :type 'boolean
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
170 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
171
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
172 (defvar doctest-mode-hook nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
173 "Hook called by `doctest-mode'.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
174
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
175 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
176 ;;; Fonts
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
177 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
178
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
179 (defface doctest-prompt-face
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
180 '((((class color) (background dark))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
181 (:foreground "#68f"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
182 (t (:foreground "#226")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
183 "Face for Python prompts in doctest examples."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
184 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
185
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
186 (defface doctest-output-face
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
187 '((((class color) (background dark))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
188 (:foreground "#afd"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
189 (t (:foreground "#262")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
190 "Face for the output of doctest examples."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
191 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
192
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
193 (defface doctest-output-marker-face
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
194 '((((class color) (background dark))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
195 (:foreground "#0f0"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
196 (t (:foreground "#080")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
197 "Face for markers in the output of doctest examples."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
198 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
199
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
200 (defface doctest-output-traceback-face
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
201 '((((class color) (background dark))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
202 (:foreground "#f88"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
203 (t (:foreground "#622")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
204 "Face for traceback headers in the output of doctest examples."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
205 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
206
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
207 (defface doctest-results-divider-face
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
208 '((((class color) (background dark))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
209 (:foreground "#08f"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
210 (t (:foreground "#00f")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
211 "Face for dividers in the doctest results window."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
212 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
213
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
214 (defface doctest-results-loc-face
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
215 '((((class color) (background dark))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
216 (:foreground "#0f8"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
217 (t (:foreground "#084")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
218 "Face for location headers in the doctest results window."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
219 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
220
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
221 (defface doctest-results-header-face
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
222 '((((class color) (background dark))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
223 (:foreground "#8ff"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
224 (t (:foreground "#088")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
225 "Face for sub-headers in the doctest results window."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
226 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
227
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
228 (defface doctest-results-selection-face
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
229 '((((class color) (background dark))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
230 (:foreground "#ff0" :background "#008"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
231 (t (:background "#088" :foreground "#fff")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
232 "Face for selected failure's location header in the results window."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
233 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
234
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
235 (defface doctest-selection-face
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
236 '((((class color) (background dark))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
237 (:foreground "#ff0" :background "#00f" :bold t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
238 (t (:foreground "#f00")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
239 "Face for selected example's prompt"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
240 :group 'doctest)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
241
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
242 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
243 ;;; Constants
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
244 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
245
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
246 (defconst doctest-prompt-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
247 "^\\(?:\\([ \t]*\\)\\(>>> ?\\|[.][.][.] ?\\)\\([ \t]*\\)\\)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
248 "Regular expression for doctest prompts. It defines three groups:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
249 the pre-prompt margin; the prompt; and the post-prompt indentation.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
250
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
251 (defconst doctest-open-block-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
252 "[^\n]+:[ \t]*\\(#.*\\)?$"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
253 "Regular expression for a line that opens a block")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
254
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
255 (defconst doctest-close-block-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
256 "\\(return\\|raise\\|break\\|continue\\|pass\\)\\b"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
257 "Regular expression for a line that closes a block")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
258
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
259 (defconst doctest-example-source-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
260 "^Failed example:\n\\(\n\\| [^\n]*\n\\)+"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
261 "Regular expression for example source in doctest's output.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
262
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
263 (defconst doctest-results-divider-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
264 "^\\([*]\\{60,\\}\\)$"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
265 "Regular expression for example dividers in doctest's output.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
266
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
267 (defconst doctest-py24-results-loc-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
268 "^File \"[^\"]+\", line \\([0-9]+\\), in [^\n]+"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
269 "Regular expression for example location markers in doctest's output.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
270
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
271 (defconst doctest-py21-results-loc-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
272 "^from line #\\([0-9]+\\) of [^\n]*"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
273 "Regular expression for example location markers in doctest's output,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
274 when the output was generated by an old version of doctest.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
275
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
276 (defconst doctest-results-header-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
277 "^\\([^ \n\t].+:\\|Expected nothing\\|Got nothing\\)$"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
278 "Regular expression for example headers in doctest's output.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
279
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
280 (defconst doctest-traceback-header-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
281 "^[ \t]*Traceback (\\(most recent call last\\|innermost last\\)):"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
282 "Regular expression for Python traceback headers.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
283
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
284 (defconst doctest-py21-results-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
285 "^from line #"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
286 "Regular expression used to test which version of doctest was used.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
287
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
288 ;; nb: There's a bug in Python's traceback.print_exception function
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
289 ;; which causes SyntaxError exceptions to be displayed incorrectly;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
290 ;; which prevents this regexp from matching. But there shouldn't be
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
291 ;; too many people testing for SyntaxErrors, so I won't worry about
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
292 ;; it.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
293 (defconst doctest-traceback-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
294 (let ((nonprompt
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
295 ;; This matches any non-blank line that doesn't start with
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
296 ;; a prompt (... or >>>).
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
297 (concat
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
298 "\\(?:[.][.][^.\n]\\|[>][>][^>\n]\\|"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
299 "[.][^.\n]\\|[>][^>\n]\\|[^.>\n \t]\\)[^\n]*")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
300 (concat
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
301 "^\\(\\([ \t]*\\)Traceback "
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
302 "(\\(?:most recent call last\\|innermost last\\)):\n\\)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
303 "\\(?:\\2[ \t]+[^ \t\n][^\n]*\n\\)*"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
304 "\\(\\(?:\\2" nonprompt "\n\\)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
305 "\\(?:\\2[ \t]*" nonprompt "\n\\)*\\)"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
306 "Regular expression that matches a complete exception traceback.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
307 It contains three groups: group 1 is the header line; group 2 is
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
308 the indentation; and group 3 is the exception message.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
309
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
310 (defconst doctest-blankline-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
311 "^[ \t]*<BLANKLINE>"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
312 "Regular expression that matches blank line markers in doctest
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
313 output.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
314
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
315 (defconst doctest-outdent-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
316 (concat "\\(" (mapconcat 'identity
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
317 '("else:"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
318 "except\\(\\s +.*\\)?:"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
319 "finally:"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
320 "elif\\s +.*:")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
321 "\\|")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
322 "\\)")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
323 "Regular expression for a line that should be outdented. Any line
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
324 that matches `doctest-outdent-re', but does not follow a line matching
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
325 `doctest-no-outdent-re', will be outdented.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
326
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
327 ;; It's not clear to me *why* the behavior given by this definition of
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
328 ;; doctest-no-outdent-re is desirable; but it's basically just copied
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
329 ;; from python-mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
330 (defconst doctest-no-outdent-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
331 (concat
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
332 "\\("
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
333 (mapconcat 'identity
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
334 (list "try:"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
335 "except\\(\\s +.*\\)?:"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
336 "while\\s +.*:"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
337 "for\\s +.*:"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
338 "if\\s +.*:"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
339 "elif\\s +.*:"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
340 "\\(return\\|raise\\|break\\|continue\\|pass\\)[ \t\n]"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
341 )
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
342 "\\|")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
343 "\\)")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
344 "Regular expression matching lines not to outdent after. Any line
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
345 that matches `doctest-outdent-re', but does not follow a line matching
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
346 `doctest-no-outdent-re', will be outdented.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
347
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
348 (defconst doctest-script
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
349 "\
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
350 from doctest import *
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
351 import sys
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
352 if '%m':
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
353 import imp
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
354 try:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
355 m = imp.load_source('__imported__', '%m')
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
356 globs = m.__dict__
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
357 except Exception, e:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
358 print ('doctest-mode encountered an error while importing '
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
359 'the current buffer:\\n\\n %s' % e)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
360 sys.exit(1)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
361 else:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
362 globs = {}
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
363 doc = open('%t').read()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
364 if sys.version_info[:2] >= (2,4):
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
365 test = DocTestParser().get_doctest(doc, globs, '%n', '%f', 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
366 r = DocTestRunner(optionflags=%l)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
367 r.run(test)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
368 else:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
369 Tester(globs=globs).runstring(doc, '%f')"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
370 ;; Docstring:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
371 "Python script used to run doctest.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
372 The following special sequences are defined:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
373 %n -- replaced by the doctest buffer's name.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
374 %f -- replaced by the doctest buffer's filename.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
375 %l -- replaced by the doctest flags string.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
376 %t -- replaced by the name of the tempfile containing the doctests."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
377 )
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
378
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
379 (defconst doctest-keyword-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
380 (let* ((kw1 (mapconcat 'identity
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
381 '("and" "assert" "break" "class"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
382 "continue" "def" "del" "elif"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
383 "else" "except" "exec" "for"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
384 "from" "global" "if" "import"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
385 "in" "is" "lambda" "not"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
386 "or" "pass" "print" "raise"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
387 "return" "while" "yield"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
388 )
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
389 "\\|"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
390 (kw2 (mapconcat 'identity
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
391 '("else:" "except:" "finally:" "try:")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
392 "\\|"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
393 (kw3 (mapconcat 'identity
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
394 '("ArithmeticError" "AssertionError"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
395 "AttributeError" "DeprecationWarning" "EOFError"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
396 "Ellipsis" "EnvironmentError" "Exception" "False"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
397 "FloatingPointError" "FutureWarning" "IOError"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
398 "ImportError" "IndentationError" "IndexError"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
399 "KeyError" "KeyboardInterrupt" "LookupError"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
400 "MemoryError" "NameError" "None" "NotImplemented"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
401 "NotImplementedError" "OSError" "OverflowError"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
402 "OverflowWarning" "PendingDeprecationWarning"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
403 "ReferenceError" "RuntimeError" "RuntimeWarning"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
404 "StandardError" "StopIteration" "SyntaxError"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
405 "SyntaxWarning" "SystemError" "SystemExit"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
406 "TabError" "True" "TypeError" "UnboundLocalError"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
407 "UnicodeDecodeError" "UnicodeEncodeError"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
408 "UnicodeError" "UnicodeTranslateError"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
409 "UserWarning" "ValueError" "Warning"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
410 "ZeroDivisionError" "__debug__"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
411 "__import__" "__name__" "abs" "apply" "basestring"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
412 "bool" "buffer" "callable" "chr" "classmethod"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
413 "cmp" "coerce" "compile" "complex" "copyright"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
414 "delattr" "dict" "dir" "divmod"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
415 "enumerate" "eval" "execfile" "exit" "file"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
416 "filter" "float" "getattr" "globals" "hasattr"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
417 "hash" "hex" "id" "input" "int" "intern"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
418 "isinstance" "issubclass" "iter" "len" "license"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
419 "list" "locals" "long" "map" "max" "min" "object"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
420 "oct" "open" "ord" "pow" "property" "range"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
421 "raw_input" "reduce" "reload" "repr" "round"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
422 "setattr" "slice" "staticmethod" "str" "sum"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
423 "super" "tuple" "type" "unichr" "unicode" "vars"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
424 "xrange" "zip")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
425 "\\|"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
426 (pseudokw (mapconcat 'identity
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
427 '("self" "None" "True" "False" "Ellipsis")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
428 "\\|"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
429 (string (concat "'\\(?:\\\\[^\n]\\|[^\n']*\\)'" "\\|"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
430 "\"\\(?:\\\\[^\n]\\|[^\n\"]*\\)\""))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
431 (brk "\\(?:[ \t(]\\|$\\)"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
432 (concat
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
433 ;; Comments (group 1)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
434 "\\(#.*\\)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
435 ;; Function & Class Definitions (groups 2-3)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
436 "\\|\\b\\(class\\|def\\)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
437 "[ \t]+\\([a-zA-Z_][a-zA-Z0-9_]*\\)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
438 ;; Builtins preceeded by '.'(group 4)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
439 "\\|[.][\t ]*\\(" kw3 "\\)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
440 ;; Keywords & builtins (group 5)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
441 "\\|\\b\\(" kw1 "\\|" kw2 "\\|"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
442 kw3 "\\|" pseudokw "\\)" brk
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
443 ;; Decorators (group 6)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
444 "\\|\\(@[a-zA-Z_][a-zA-Z0-9_]*\\)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
445 ))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
446 "A regular expression used for syntax highlighting of Python
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
447 source code.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
448
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
449 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
450 ;;; Syntax Highlighting (font-lock mode)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
451 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
452
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
453 ;; Define the font-lock keyword table.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
454 (defconst doctest-font-lock-keywords
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
455 `(
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
456 ;; The following pattern colorizes source lines. In particular,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
457 ;; it first matches prompts, and then looks for any of the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
458 ;; following matches *on the same line* as the prompt. It uses
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
459 ;; the form:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
460 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
461 ;; (MATCHER MATCH-HIGHLIGHT
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
462 ;; (ANCHOR-MATCHER nil nil MATCH-HIGHLIGHT))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
463 ;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
464 ;; See the variable documentation for font-lock-keywords for a
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
465 ;; description of what each of those means.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
466 ("^[ \t]*\\(>>>\\|\\.\\.\\.\\)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
467 (1 'doctest-prompt-face)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
468 (doctest-source-matcher
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
469 nil nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
470 (1 'font-lock-comment-face t t) ; comments
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
471 (2 'font-lock-keyword-face t t) ; def/class
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
472 (3 'font-lock-type-face t t) ; func/class name
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
473 ;; group 4 (builtins preceeded by '.') gets no colorization.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
474 (5 'font-lock-keyword-face t t) ; keywords & builtins
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
475 (6 'font-lock-preprocessor-face t t) ; decorators
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
476 (7 'font-lock-string-face t t) ; strings
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
477 ))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
478
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
479 ;; The following pattern colorizes output lines. In particular,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
480 ;; it uses doctest-output-line-matcher to check if this is an
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
481 ;; output line, and if so, it colorizes it, and any special
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
482 ;; markers it contains.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
483 (doctest-output-line-matcher
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
484 (0 'doctest-output-face t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
485 ("\\.\\.\\." (beginning-of-line) (end-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
486 (0 'doctest-output-marker-face t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
487 (,doctest-blankline-re (beginning-of-line) (end-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
488 (0 'doctest-output-marker-face t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
489 (doctest-traceback-line-matcher (beginning-of-line) (end-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
490 (0 'doctest-output-traceback-face t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
491 (,doctest-traceback-header-re (beginning-of-line) (end-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
492 (0 'doctest-output-traceback-face t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
493 )
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
494
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
495 ;; A PS1 prompt followed by a non-space is an error.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
496 ("^[ \t]*\\(>>>[^ \t\n][^\n]*\\)" (1 'font-lock-warning-face t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
497 )
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
498 "Expressions to highlight in doctest-mode.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
499
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
500 (defconst doctest-results-font-lock-keywords
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
501 `((,doctest-results-divider-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
502 (0 'doctest-results-divider-face))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
503 (,doctest-py24-results-loc-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
504 (0 'doctest-results-loc-face))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
505 (,doctest-results-header-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
506 (0 'doctest-results-header-face))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
507 (doctest-results-selection-matcher
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
508 (0 'doctest-results-selection-face t)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
509 "Expressions to highlight in doctest-results-mode.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
510
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
511 (defun doctest-output-line-matcher (limit)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
512 "A `font-lock-keyword' MATCHER that returns t if the current
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
513 line is the expected output for a doctest example, and if so,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
514 sets `match-data' so that group 0 spans the current line."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
515 ;; The real work is done by doctest-find-output-line.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
516 (when (doctest-find-output-line limit)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
517 ;; If we found one, then mark the entire line.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
518 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
519 (re-search-forward "[^\n]*" limit)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
520
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
521 (defun doctest-traceback-line-matcher (limit)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
522 "A `font-lock-keyword' MATCHER that returns t if the current line is
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
523 the beginning of a traceback, and if so, sets `match-data' so that
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
524 group 0 spans the entire traceback. n.b.: limit is ignored."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
525 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
526 (when (looking-at doctest-traceback-re)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
527 (goto-char (match-end 0))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
528 t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
529
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
530 (defun doctest-source-matcher (limit)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
531 "A `font-lock-keyword' MATCHER that returns t if the current line
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
532 contains a Python source expression that should be highlighted
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
533 after the point. If so, it sets `match-data' to cover the string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
534 literal. The groups in `match-data' should be interpreted as follows:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
535
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
536 Group 1: comments
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
537 Group 2: def/class
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
538 Group 3: function/class name
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
539 Group 4: builtins preceeded by '.'
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
540 Group 5: keywords & builtins
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
541 Group 6: decorators
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
542 Group 7: strings
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
543 "
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
544 (let ((matchdata nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
545 ;; First, look for string literals.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
546 (when doctest-highlight-strings
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
547 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
548 (when (doctest-string-literal-matcher limit)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
549 (setq matchdata
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
550 (list (match-beginning 0) (match-end 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
551 nil nil nil nil nil nil nil nil nil nil nil nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
552 (match-beginning 0) (match-end 0))))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
553 ;; Then, look for other keywords. If they occur before the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
554 ;; string literal, then they take precedence.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
555 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
556 (when (and (re-search-forward doctest-keyword-re limit t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
557 (or (null matchdata)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
558 (< (match-beginning 0) (car matchdata))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
559 (setq matchdata (match-data))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
560 (when matchdata
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
561 (set-match-data matchdata)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
562 (goto-char (match-end 0))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
563 t)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
564
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
565 (defun doctest-string-literal-matcher (limit &optional debug)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
566 "A `font-lock-keyword' MATCHER that returns t if the current line
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
567 contains a string literal starting at or after the point. If so, it
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
568 expands `match-data' to cover the string literal. This matcher uses
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
569 `doctest-statement-info' to collect information about strings that
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
570 continue over multiple lines. It therefore might be a little slow for
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
571 very large statements."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
572 (let* ((stmt-info (doctest-statement-info))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
573 (quotes (reverse (nth 5 stmt-info)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
574 (result nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
575 (if debug (doctest-debug "quotes %s" quotes))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
576 (while (and quotes (null result))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
577 (let* ((quote (pop quotes))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
578 (start (car quote))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
579 (end (min limit (or (cdr quote) limit))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
580 (if debug (doctest-debug "quote %s-%s pt=%s lim=%s"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
581 start end (point) limit))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
582 (when (or (and (<= (point) start) (< start limit))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
583 (and (< start (point)) (< (point) end)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
584 (setq start (max start (point)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
585 (set-match-data (list start end))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
586 (if debug (doctest-debug "marking string %s" (match-data)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
587 (goto-char end)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
588 (setq result t))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
589 result))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
590
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
591 (defun doctest-results-selection-matcher (limit)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
592 "Matches from `doctest-selected-failure' to the end of the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
593 line. This is used to highlight the currently selected failure."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
594 (when (and doctest-selected-failure
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
595 (<= (point) doctest-selected-failure)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
596 (< doctest-selected-failure limit))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
597 (goto-char doctest-selected-failure)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
598 (re-search-forward "[^\n]+" limit)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
599
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
600 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
601 ;;; Source code editing & indentation
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
602 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
603
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
604 (defun doctest-indent-source-line (&optional dedent-only)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
605 "Re-indent the current line, as doctest source code. I.e., add a
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
606 prompt to the current line if it doesn't have one, and re-indent the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
607 source code (to the right of the prompt). If `dedent-only' is true,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
608 then don't increase the indentation level any."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
609 (interactive "*")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
610 (let ((indent-end nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
611 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
612 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
613 (let ((new-indent (doctest-current-source-line-indentation dedent-only))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
614 (new-margin (doctest-current-source-line-margin))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
615 (line-had-prompt (looking-at doctest-prompt-re)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
616 ;; Delete the old prompt (if any).
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
617 (when line-had-prompt
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
618 (goto-char (match-beginning 2))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
619 (delete-char (- (match-end 2) (match-beginning 2))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
620 ;; Delete the old indentation.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
621 (delete-backward-char (skip-chars-forward " \t"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
622 ;; If it's a continuation line, or a new PS1 prompt,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
623 ;; then copy the margin.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
624 (when (or new-indent (not line-had-prompt))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
625 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
626 (delete-backward-char (skip-chars-forward " \t"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
627 (insert-char ?\ new-margin))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
628 ;; Add the new prompt.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
629 (insert-string (if new-indent "... " ">>> "))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
630 ;; Add the new indentation
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
631 (if new-indent (insert-char ?\ new-indent))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
632 (setq indent-end (point))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
633 ;; If we're left of the indentation end, then move up to the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
634 ;; indentation end.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
635 (if (< (point) indent-end) (goto-char indent-end))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
636
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
637 (defun doctest-current-source-line-indentation (&optional dedent-only)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
638 "Return the post-prompt indent to use for this line. This is an
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
639 integer for a continuation lines, and nil for non-continuation lines."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
640 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
641 ;; Examine the previous doctest line (if present).
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
642 (let* ((prev-stmt-info (doctest-prev-statement-info))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
643 (prev-stmt-indent (nth 0 prev-stmt-info))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
644 (continuation-indent (nth 1 prev-stmt-info))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
645 (prev-stmt-opens-block (nth 2 prev-stmt-info))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
646 (prev-stmt-closes-block (nth 3 prev-stmt-info))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
647 (prev-stmt-blocks-outdent (nth 4 prev-stmt-info))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
648 )
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
649 ;; Examine this doctest line.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
650 (let* ((curr-line-indent 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
651 (curr-line-outdented nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
652 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
653 (when (looking-at doctest-prompt-re)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
654 (setq curr-line-indent (- (match-end 3) (match-beginning 3)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
655 (goto-char (match-end 3)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
656 (setq curr-line-outdented (and (looking-at doctest-outdent-re)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
657 (not prev-stmt-blocks-outdent)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
658 ;; Compute the overall indent.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
659 (let ((indent (or continuation-indent
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
660 (+ prev-stmt-indent
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
661 (if curr-line-outdented -4 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
662 (if prev-stmt-opens-block 4 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
663 (if prev-stmt-closes-block -4 0)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
664 ;; If dedent-only is true, then make sure we don't indent.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
665 (when dedent-only
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
666 (setq indent (min indent curr-line-indent)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
667 ;; If indent=0 and we're not outdented, then set indent to
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
668 ;; nil (to signify the start of a new source example).
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
669 (when (and (= indent 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
670 (not (or curr-line-outdented continuation-indent)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
671 (setq indent nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
672 ;; Return the indentation.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
673 indent)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
674
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
675 (defun doctest-prev-statement-info (&optional debug)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
676 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
677 (forward-line -1)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
678 (doctest-statement-info debug)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
679
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
680 (defun doctest-statement-info (&optional debug)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
681 "Collect info about the previous statement, and return it as a list:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
682
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
683 (INDENT, CONTINUATION, OPENS-BLOCK, CLOSES-BLOCK, BLOCKS-OUTDENT,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
684 QUOTES)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
685
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
686 INDENT -- The indentation of the previous statement (after the prompt)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
687
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
688 CONTINUATION -- If the previous statement is incomplete (e.g., has an
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
689 open paren or quote), then this is the appropriate indentation
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
690 level; otherwise, it's nil.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
691
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
692 OPENS-BLOCK -- True if the previous statement opens a Python control
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
693 block.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
694
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
695 CLOSES-BLOCK -- True if the previous statement closes a Python control
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
696 block.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
697
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
698 BLOCKS-OUTDENT -- True if the previous statement should 'block the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
699 next statement from being considered an outdent.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
700
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
701 QUOTES -- A list of (START . END) pairs for all quotation strings.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
702 "
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
703 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
704 (end-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
705 (let ((end (point)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
706 (while (and (doctest-on-source-line-p "...") (= (forward-line -1) 0)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
707 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
708 ;; If there's no previous >>> line, then give up.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
709 ((not (doctest-on-source-line-p ">>>"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
710 '(0 nil nil nil nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
711
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
712 ;; If there is a previous statement, walk through the source
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
713 ;; code, checking for operators that may be of interest.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
714 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
715 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
716 (let* ((quote-mark nil) (nesting 0) (indent-stack '())
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
717 (stmt-indent 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
718 (stmt-opens-block nil)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
719 (stmt-closes-block nil)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
720 (stmt-blocks-outdent nil)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
721 (quotes '())
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
722 (elt-re (concat "\\\\[^\n]\\|"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
723 "(\\|)\\|\\[\\|\\]\\|{\\|}\\|"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
724 "\"\"\"\\|\'\'\'\\|\"\\|\'\\|"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
725 "#[^\n]*\\|" doctest-prompt-re)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
726 (while (re-search-forward elt-re end t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
727 (let* ((elt (match-string 0))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
728 (elt-first-char (substring elt 0 1)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
729 (if debug (doctest-debug "Debug: %s" elt))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
730 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
731 ;; Close quote -- set quote-mark back to nil. The
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
732 ;; second case is for cases like: ' '''
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
733 (quote-mark
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
734 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
735 ((equal quote-mark elt)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
736 (setq quote-mark nil)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
737 (setcdr (car quotes) (point)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
738 ((equal quote-mark elt-first-char)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
739 (setq quote-mark nil)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
740 (setcdr (car quotes) (point))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
741 (backward-char 2))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
742 ;; Prompt -- check if we're starting a new stmt. If so,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
743 ;; then collect various info about it.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
744 ((string-match doctest-prompt-re elt)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
745 (when (and (null quote-mark) (= nesting 0))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
746 (let ((indent (- (match-end 3) (match-end 2))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
747 (unless (looking-at "[ \t]*\n")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
748 (setq stmt-indent indent)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
749 (setq stmt-opens-block
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
750 (looking-at doctest-open-block-re))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
751 (setq stmt-closes-block
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
752 (looking-at doctest-close-block-re))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
753 (setq stmt-blocks-outdent
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
754 (looking-at doctest-no-outdent-re))))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
755 ;; Open paren -- increment nesting, and update indent-stack.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
756 ((string-match "(\\|\\[\\|{" elt-first-char)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
757 (let ((elt-pos (point))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
758 (at-eol (looking-at "[ \t]*\n"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
759 (indent 0))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
760 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
761 (re-search-backward doctest-prompt-re)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
762 (if at-eol
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
763 (setq indent (+ 4 (- (match-end 3) (match-end 2))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
764 (setq indent (- elt-pos (match-end 2))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
765 (push indent indent-stack)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
766 (setq nesting (+ nesting 1)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
767 ;; Close paren -- decrement nesting, and pop indent-stack.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
768 ((string-match ")\\|\\]\\|}" elt-first-char)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
769 (setq indent-stack (cdr indent-stack))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
770 (setq nesting (max 0 (- nesting 1))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
771 ;; Open quote -- set quote-mark.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
772 ((string-match "\"\\|\'" elt-first-char)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
773 (push (cons (- (point) (length elt)) nil) quotes)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
774 (setq quote-mark elt)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
775
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
776 (let* ((continuation-indent
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
777 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
778 (quote-mark 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
779 ((> nesting 0) (if (null indent-stack) 0 (car indent-stack)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
780 (t nil)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
781 (result
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
782 (list stmt-indent continuation-indent
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
783 stmt-opens-block stmt-closes-block
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
784 stmt-blocks-outdent quotes)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
785 (if debug (doctest-debug "Debug: %s" result))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
786 result)))))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
787
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
788 (defun doctest-current-source-line-margin ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
789 "Return the pre-prompt margin to use for this source line. This is
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
790 copied from the most recent source line, or set to
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
791 `doctest-default-margin' if there are no preceeding source lines."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
792 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
793 (save-restriction
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
794 (when (doctest-in-mmm-docstring-overlay)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
795 (doctest-narrow-to-mmm-overlay))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
796 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
797 (forward-line -1)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
798 (while (and (not (doctest-on-source-line-p))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
799 (re-search-backward doctest-prompt-re nil t))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
800 (cond ((looking-at doctest-prompt-re)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
801 (- (match-end 1) (match-beginning 1)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
802 ((doctest-in-mmm-docstring-overlay)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
803 (doctest-default-margin-in-mmm-docstring-overlay))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
804 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
805 doctest-default-margin))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
806
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
807 (defun doctest-electric-backspace ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
808 "Delete the preceeding character, level of indentation, or
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
809 prompt.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
810
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
811 If point is at the leftmost column, delete the preceding newline.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
812
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
813 Otherwise, if point is at the first non-whitespace character
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
814 following an indented source line's prompt, then reduce the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
815 indentation to the next multiple of 4; and update the source line's
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
816 prompt, when necessary.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
817
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
818 Otherwise, if point is at the first non-whitespace character
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
819 following an unindented source line's prompt, then remove the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
820 prompt (converting the line to an output line or text line).
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
821
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
822 Otherwise, if point is at the first non-whitespace character of a
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
823 line, the delete the line's indentation.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
824
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
825 Otherwise, delete the preceeding character.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
826 "
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
827 (interactive "*")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
828 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
829 ;; Beginning of line: delete preceeding newline.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
830 ((bolp) (backward-delete-char 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
831
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
832 ;; First non-ws char following prompt: dedent or remove prompt.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
833 ((and (looking-at "[^ \t\n]\\|$") (doctest-looking-back doctest-prompt-re))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
834 (let* ((prompt-beg (match-beginning 2))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
835 (indent-beg (match-beginning 3)) (indent-end (match-end 3))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
836 (old-indent (- indent-end indent-beg))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
837 (new-indent (* (/ (- old-indent 1) 4) 4)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
838 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
839 ;; Indented source line: dedent it.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
840 ((> old-indent 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
841 (goto-char indent-beg)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
842 (delete-region indent-beg indent-end)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
843 (insert-char ?\ new-indent)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
844 ;; Change prompt to PS1, when appropriate.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
845 (when (and (= new-indent 0) (not (looking-at doctest-outdent-re)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
846 (delete-backward-char 4)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
847 (insert-string ">>> ")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
848 ;; Non-indented source line: remove prompt.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
849 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
850 (goto-char indent-end)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
851 (delete-region prompt-beg indent-end)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
852
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
853 ;; First non-ws char of a line: delete all indentation.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
854 ((and (looking-at "[^ \n\t]\\|$") (doctest-looking-back "^[ \t]+"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
855 (delete-region (match-beginning 0) (match-end 0)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
856
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
857 ;; Otherwise: delete a character.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
858 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
859 (backward-delete-char 1))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
860
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
861 (defun doctest-newline-and-indent ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
862 "Insert a newline, and indent the new line appropriately.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
863
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
864 If the current line is a source line containing a bare prompt,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
865 then clear the current line, and insert a newline.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
866
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
867 Otherwise, if the current line is a source line, then insert a
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
868 newline, and add an appropriately indented prompt to the new
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
869 line.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
870
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
871 Otherwise, if the current line is an output line, then insert a
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
872 newline and indent the new line to match the example's margin.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
873
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
874 Otherwise, insert a newline.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
875
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
876 If `doctest-avoid-trailing-whitespace' is true, then clear any
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
877 whitespace to the left of the point before inserting a newline.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
878 "
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
879 (interactive "*")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
880 ;; If we're avoiding trailing spaces, then delete WS before point.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
881 (if doctest-avoid-trailing-whitespace
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
882 (delete-char (- (skip-chars-backward " \t"))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
883 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
884 ;; If we're on an empty prompt, delete it.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
885 ((doctest-on-empty-source-line-p)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
886 (delete-region (match-beginning 0) (match-end 0))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
887 (insert-char ?\n 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
888 ;; If we're on a doctest line, add a new prompt.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
889 ((doctest-on-source-line-p)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
890 (insert-char ?\n 1)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
891 (doctest-indent-source-line))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
892 ;; If we're in doctest output, indent to the margin.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
893 ((doctest-on-output-line-p)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
894 (insert-char ?\n 1)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
895 (insert-char ?\ (doctest-current-source-line-margin)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
896 ;; Otherwise, just add a newline.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
897 (t (insert-char ?\n 1))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
898
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
899 (defun doctest-electric-colon ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
900 "Insert a colon, and dedent the line when appropriate."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
901 (interactive "*")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
902 (insert-char ?: 1)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
903 (when (doctest-on-source-line-p)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
904 (doctest-indent-source-line t)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
905
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
906 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
907 ;;; Code Execution
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
908 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
909
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
910 (defun doctest-execute ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
911 "Run doctest on the current buffer, or on the current docstring
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
912 if the point is inside an `mmm-mode' `doctest-docstring' region.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
913 Display the results in the *doctest-output* buffer."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
914 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
915 (doctest-execute-region (point-min) (point-max) nil t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
916
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
917 (defun doctest-execute-with-diff ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
918 "Run doctest on the current buffer, or on the current docstring
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
919 if the point is inside an `mmm-mode' `doctest-docstring' region.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
920 Display the results in the *doctest-output* buffer, using diff format."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
921 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
922 (doctest-execute-region (point-min) (point-max) t t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
923
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
924 (defun doctest-execute-buffer-with-diff ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
925 "Run doctest on the current buffer, and display the results in the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
926 *doctest-output* buffer, using the diff format."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
927 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
928 (doctest-execute-region (point-min) (point-max) t nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
929
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
930 (defun doctest-execute-buffer ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
931 "Run doctest on the current buffer, and display the results in the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
932 *doctest-output* buffer."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
933 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
934 (doctest-execute-region (point-min) (point-max) nil nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
935
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
936 (defun doctest-execute-region (start end &optional diff
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
937 check-for-mmm-docstring-overlay)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
938 "Run doctest on the current buffer, and display the results in the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
939 *doctest-output* buffer."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
940 (interactive "r")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
941 ;; If it's already running, give the user a chance to restart it.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
942 (when (doctest-process-live-p doctest-async-process)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
943 (when (y-or-n-p "Doctest is already running. Restart it? ")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
944 (doctest-cancel-async-process)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
945 (message "Killing doctest...")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
946 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
947 ((and doctest-async (doctest-process-live-p doctest-async-process))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
948 (message "Can't run two doctest processes at once!"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
949 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
950 (let* ((results-buf-name (doctest-results-buffer-name))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
951 (in-docstring (and check-for-mmm-docstring-overlay
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
952 (doctest-in-mmm-docstring-overlay)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
953 (temp (doctest-temp-name)) (dir doctest-temp-directory)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
954 (input-file (expand-file-name (concat temp ".py") dir))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
955 (globs-file (when in-docstring
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
956 (expand-file-name (concat temp "-globs.py") dir)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
957 (cur-buf (current-buffer))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
958 (in-buf (get-buffer-create "*doctest-input*"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
959 (script (doctest-script input-file globs-file diff)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
960 ;; If we're in a docstring, narrow start & end.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
961 (when in-docstring
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
962 (let ((bounds (doctest-mmm-overlay-bounds)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
963 (setq start (max start (car bounds))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
964 end (min end (cdr bounds)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
965 ;; Write the doctests to a file.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
966 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
967 (goto-char (min start end))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
968 (let ((lineno (doctest-line-number)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
969 (set-buffer in-buf)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
970 ;; Add blank lines, to keep line numbers the same:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
971 (dotimes (n (- lineno 1)) (insert-string "\n"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
972 ;; Add the selected region
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
973 (insert-buffer-substring cur-buf start end)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
974 ;; Write it to a file
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
975 (write-file input-file)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
976 ;; If requested, write the buffer to a file for use as globs.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
977 (when globs-file
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
978 (let ((cur-buf-start (point-min)) (cur-buf-end (point-max)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
979 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
980 (set-buffer in-buf)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
981 (delete-region (point-min) (point-max))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
982 (insert-buffer-substring cur-buf cur-buf-start cur-buf-end)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
983 (write-file globs-file))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
984 ;; Dispose of in-buf (we're done with it now.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
985 (kill-buffer in-buf)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
986 ;; Prepare the results buffer. Clear it, if it contains
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
987 ;; anything, and set its mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
988 (setq doctest-results-buffer (get-buffer-create results-buf-name))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
989 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
990 (set-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
991 (toggle-read-only 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
992 (delete-region (point-min) (point-max))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
993 (doctest-results-mode)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
994 (setq doctest-source-buffer cur-buf)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
995 )
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
996 ;; Add markers to examples, and record what line number each one
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
997 ;; starts at. That way, if the input buffer is edited, we can
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
998 ;; still find corresponding examples in the output.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
999 (doctest-mark-examples)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1000
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1001 ;; Run doctest
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1002 (cond (doctest-async
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1003 ;; Asynchronous mode:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1004 (let ((process (start-process "*doctest*" doctest-results-buffer
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1005 doctest-python-command
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1006 "-c" script)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1007 ;; Store some information about the process.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1008 (setq doctest-async-process-buffer cur-buf)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1009 (setq doctest-async-process process)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1010 (push input-file doctest-async-process-tempfiles)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1011 (when globs-file
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1012 (push globs-file doctest-async-process-tempfiles))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1013 ;; Set up a sentinel to respond when it's done running.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1014 (set-process-sentinel process 'doctest-async-process-sentinel)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1015
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1016 ;; Show the output window.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1017 (let ((w (display-buffer doctest-results-buffer)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1018 (when doctest-follow-output
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1019 ;; Insert a newline, which will move the buffer's
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1020 ;; point past the process's mark -- this causes the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1021 ;; window to scroll as new output is generated.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1022 (save-current-buffer
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1023 (set-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1024 (insert-string "\n")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1025 (set-window-point w (point)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1026
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1027 ;; Let the user know the process is running.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1028 (doctest-update-mode-line ":running")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1029 (message "Running doctest...")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1030 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1031 ;; Synchronous mode:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1032 (call-process doctest-python-command nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1033 doctest-results-buffer t "-c" script)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1034 (doctest-handle-output)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1035 (delete-file input-file)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1036 (when globs-file
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1037 (delete-file globs-file))))))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1038
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1039 (defun doctest-handle-output ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1040 "This function, which is called after the 'doctest' process spawned
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1041 by doctest-execute-buffer has finished, checks the doctest results
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1042 buffer. If that buffer is empty, it reports no errors and hides it;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1043 if that buffer is not empty, it reports that errors occured, displays
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1044 the buffer, and runs doctest-postprocess-results."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1045 ;; If any tests failed, display them.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1046 (cond ((not (buffer-live-p doctest-results-buffer))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1047 (doctest-warn "Results buffer not found!"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1048 ((> (buffer-size doctest-results-buffer) 1)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1049 (display-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1050 (doctest-postprocess-results)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1051 (let ((num (length doctest-example-markers)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1052 (message "%d doctest example%s failed!" num
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1053 (if (= num 1) "" "s"))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1054 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1055 (display-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1056 (delete-windows-on doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1057 (message "All doctest examples passed!"))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1058
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1059 (defun doctest-async-process-sentinel (process state)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1060 "A process sentinel, called when the asynchronous doctest process
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1061 completes, which calls doctest-handle-output."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1062 ;; Check to make sure we got the process we're expecting. On
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1063 ;; some operating systems, this will end up getting called twice
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1064 ;; when we use doctest-cancel-async-process; this check keeps us
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1065 ;; from trying to clean up after the same process twice (since we
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1066 ;; set doctest-async-process to nil when we're done).
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1067 (when (and (equal process doctest-async-process)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1068 (buffer-live-p doctest-async-process-buffer))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1069 (save-current-buffer
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1070 (set-buffer doctest-async-process-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1071 (cond ((not (buffer-live-p doctest-results-buffer))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1072 (doctest-warn "Results buffer not found!"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1073 ((equal state "finished\n")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1074 (doctest-handle-output)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1075 (let ((window (get-buffer-window
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1076 doctest-async-process-buffer t)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1077 (when window (set-window-point window (point)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1078 ((equal state "killed\n")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1079 (message "Doctest killed."))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1080 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1081 (message "Doctest failed -- %s" state)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1082 (display-buffer doctest-results-buffer)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1083 (doctest-update-mode-line "")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1084 (while doctest-async-process-tempfiles
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1085 (delete-file (pop doctest-async-process-tempfiles)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1086 (setq doctest-async-process nil))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1087
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1088 (defun doctest-cancel-async-process ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1089 "If a doctest process is running, then kill it."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1090 (interactive "")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1091 (when (doctest-process-live-p doctest-async-process)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1092 ;; Update the modeline
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1093 (doctest-update-mode-line ":killing")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1094 ;; Kill the process.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1095 (kill-process doctest-async-process)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1096 ;; Run the sentinel. (Depending on what OS we're on, the sentinel
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1097 ;; may end up getting called once or twice.)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1098 (doctest-async-process-sentinel doctest-async-process "killed\n")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1099 ))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1100
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1101 (defun doctest-postprocess-results ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1102 "Post-process the doctest results buffer: check what version of
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1103 doctest was used, and set doctest-results-py-version accordingly;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1104 turn on read-only mode; filter the example markers; hide the example
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1105 source (if `doctest-hide-example-source' is non-nil); and select the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1106 first failure."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1107 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1108 (set-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1109 ;; Check if we're using an old doctest version.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1110 (goto-char (point-min))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1111 (if (re-search-forward doctest-py21-results-re nil t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1112 (setq doctest-results-py-version 'py21)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1113 (setq doctest-results-py-version 'py24))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1114 ;; Turn on read-only mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1115 (toggle-read-only t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1116
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1117 (doctest-filter-example-markers)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1118 (if doctest-hide-example-source
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1119 (doctest-hide-example-source))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1120 (doctest-next-failure 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1121
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1122 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1123 ;;; Markers
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1124 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1125
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1126 (defun doctest-mark-examples ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1127 "Add a marker at the beginning of every (likely) example in the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1128 input buffer; and create a list, `doctest-example-markers',
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1129 which maps from markers to the line numbers they originally occured
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1130 on. This will allow us to find the corresponding example in the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1131 doctest output, even if the input buffer is edited."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1132 (dolist (marker-info doctest-example-markers)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1133 (set-marker (car marker-info) nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1134 (setq doctest-example-markers '())
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1135 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1136 (goto-char (point-min))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1137 (while (re-search-forward "^ *>>> " nil t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1138 (backward-char 4)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1139 (push (cons (point-marker) (doctest-line-number))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1140 doctest-example-markers)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1141 (forward-char 4))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1142
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1143 (defun doctest-filter-example-markers ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1144 "Remove any entries from `doctest-example-markers' that do not
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1145 correspond to a failed example."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1146 (let ((filtered nil) (markers doctest-example-markers))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1147 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1148 (set-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1149 (goto-char (point-max))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1150 (while (re-search-backward (doctest-results-loc-re) nil t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1151 (let ((lineno (string-to-int (match-string 1))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1152 (when (equal doctest-results-py-version 'py21)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1153 (setq lineno (+ lineno 1)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1154 (while (and markers (< lineno (cdar markers)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1155 (set-marker (caar markers) nil)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1156 (setq markers (cdr markers)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1157 (if (and markers (= lineno (cdar markers)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1158 (push (pop markers) filtered)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1159 (doctest-warn "Example expected on line %d but not found %s"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1160 lineno markers)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1161 (dolist (marker-info markers)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1162 (set-marker (car marker-info) nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1163 (setq doctest-example-markers filtered)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1164
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1165 (defun doctest-prev-example-marker ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1166 "Helper for doctest-replace-output: move to the preceeding example
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1167 marker, and return the corresponding 'original' lineno. If none is
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1168 found, return nil."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1169 (let ((lineno nil)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1170 (pos nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1171 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1172 (end-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1173 (when (re-search-backward "^\\( *\\)>>> " nil t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1174 (goto-char (match-end 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1175 (dolist (marker-info doctest-example-markers)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1176 (when (= (marker-position (car marker-info)) (point))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1177 (setq lineno (cdr marker-info))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1178 (setq pos (point))))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1179 (unless (null lineno)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1180 (goto-char pos)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1181 lineno)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1182
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1183 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1184 ;;; Navigation
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1185 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1186
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1187 (defun doctest-next-failure (count)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1188 "Move to the top of the next failing example, and highlight the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1189 example's failure description in *doctest-output*."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1190 (interactive "p")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1191 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1192 ((and doctest-async (doctest-process-live-p doctest-async-process))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1193 (message "Wait for doctest to finish running!"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1194 ((not (doctest-results-buffer-valid-p))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1195 (message "Run doctest first! (C-c C-c)"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1196 ((equal count 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1197 t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1198 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1199 (let ((marker nil) (example-markers doctest-example-markers)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1200 (results-window (display-buffer doctest-results-buffer)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1201 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1202 (set-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1203 ;; Pick up where we left off.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1204 ;; (nb: doctest-selected-failure is buffer-local)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1205 (goto-char (or doctest-selected-failure (point-min)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1206 ;; Skip past anything on *this* line.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1207 (if (>= count 0) (end-of-line) (beginning-of-line))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1208 ;; Look for the next failure
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1209 (when
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1210 (if (>= count 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1211 (re-search-forward (doctest-results-loc-re) nil t count)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1212 (re-search-backward (doctest-results-loc-re) nil t (- count)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1213 ;; We found a failure:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1214 (let ((old-selected-failure doctest-selected-failure))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1215 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1216 ;; Extract the line number for the doctest file.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1217 (let ((orig-lineno (string-to-int (match-string 1))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1218 (when (equal doctest-results-py-version 'py21)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1219 (setq orig-lineno (+ orig-lineno 1)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1220 (dolist (marker-info example-markers)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1221 (when (= orig-lineno (cdr marker-info))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1222 (setq marker (car marker-info)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1223
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1224 ;; Update the window cursor.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1225 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1226 (set-window-point results-window (point))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1227 ;; Store our position for next time.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1228 (setq doctest-selected-failure (point))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1229 ;; Update selection.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1230 (doctest-fontify-line old-selected-failure)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1231 (doctest-fontify-line doctest-selected-failure))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1232
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1233 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1234 ;; We found a failure -- move point to the selected failure.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1235 (marker
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1236 (goto-char (marker-position marker))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1237 (beginning-of-line))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1238 ;; We didn't find a failure, but there is one -- wrap.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1239 ((> (length doctest-example-markers) 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1240 (if (>= count 0) (doctest-first-failure) (doctest-last-failure)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1241 ;; We didn't find a failure -- alert the user.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1242 (t (message "No failures found!")))))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1243
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1244 (defun doctest-prev-failure (count)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1245 "Move to the top of the previous failing example, and highlight
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1246 the example's failure description in *doctest-output*."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1247 (interactive "p")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1248 (doctest-next-failure (- count)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1249
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1250 (defun doctest-first-failure ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1251 "Move to the top of the first failing example, and highlight
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1252 the example's failure description in *doctest-output*."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1253 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1254 (if (buffer-live-p doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1255 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1256 (set-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1257 (let ((old-selected-failure doctest-selected-failure))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1258 (setq doctest-selected-failure (point-min))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1259 (doctest-fontify-line old-selected-failure))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1260 (doctest-next-failure 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1261
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1262 (defun doctest-last-failure ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1263 "Move to the top of the last failing example, and highlight
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1264 the example's failure description in *doctest-output*."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1265 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1266 (if (buffer-live-p doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1267 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1268 (set-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1269 (let ((old-selected-failure doctest-selected-failure))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1270 (setq doctest-selected-failure (point-max))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1271 (doctest-fontify-line old-selected-failure))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1272 (doctest-next-failure -1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1273
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1274 (defun doctest-select-failure ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1275 "Move to the top of the currently selected example, and select that
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1276 example in the source buffer. Intended for use in the results
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1277 buffer."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1278 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1279 (re-search-backward doctest-results-divider-re)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1280 (let ((old-selected-failure doctest-selected-failure))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1281 (setq doctest-selected-failure (point))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1282 (doctest-fontify-line doctest-selected-failure)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1283 (doctest-fontify-line old-selected-failure))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1284 (pop-to-buffer doctest-source-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1285 (doctest-next-failure 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1286
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1287 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1288 ;;; Replace Output
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1289 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1290
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1291 (defun doctest-replace-output ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1292 "Move to the top of the closest example, and replace its output
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1293 with the 'got' output from the *doctest-output* buffer. An error is
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1294 displayed if the chosen example is not listed in *doctest-output*, or
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1295 if the 'expected' output for the example does not exactly match the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1296 output listed in the source buffer. The user is asked to confirm the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1297 replacement."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1298 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1299 ;; Move to the beginning of the example.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1300 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1301 ((and doctest-async (doctest-process-live-p doctest-async-process))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1302 (message "Wait for doctest to finish running!"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1303 ((not (doctest-results-buffer-valid-p))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1304 (message "Run doctest first! (C-c C-c)"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1305 ((save-excursion (set-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1306 (equal doctest-results-py-version 'py21))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1307 (error "doctest-replace-output requires python 2.4+"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1308 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1309 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1310 (save-restriction
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1311 (when (doctest-in-mmm-docstring-overlay)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1312 (doctest-narrow-to-mmm-overlay))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1313
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1314 (let* ((orig-buffer (current-buffer))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1315 ;; Find an example, and look up its original lineno.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1316 (lineno (doctest-prev-example-marker))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1317 ;; Find the example's indentation.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1318 (prompt-indent (doctest-line-indentation)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1319
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1320 ;; Switch to the output buffer, and look for the example.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1321 ;; If we don't find one, complain.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1322 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1323 ((null lineno) (message "Doctest example not found"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1324 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1325 (set-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1326 (goto-char (point-min))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1327 (let ((output-re (format "^File .*, line %s," lineno)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1328 (when (not (re-search-forward output-re nil t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1329 (message "This doctest example did not fail")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1330 (setq lineno nil)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1331
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1332 ;; If we didn't find an example, give up.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1333 (when (not (null lineno))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1334 ;; Get the output's 'expected' & 'got' texts.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1335 (let ((doctest-got nil) (doctest-expected nil) (header nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1336 (while (setq header (doctest-results-next-header))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1337 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1338 ((equal header "Failed example:")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1339 t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1340 ((equal header "Expected nothing")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1341 (setq doctest-expected ""))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1342 ((equal header "Expected:")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1343 (unless (re-search-forward "^\\(\\( \\).*\n\\)*" nil t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1344 (error "Error parsing doctest output"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1345 (setq doctest-expected (doctest-replace-regexp-in-string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1346 "^ " prompt-indent
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1347 (match-string 0))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1348 ((equal header "Got nothing")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1349 (setq doctest-got ""))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1350 ((or (equal header "Got:") (equal header "Exception raised:"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1351 (unless (re-search-forward "^\\(\\( \\).*\n\\)*" nil t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1352 (error "Error parsing doctest output"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1353 (setq doctest-got (doctest-replace-regexp-in-string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1354 "^ " prompt-indent (match-string 0))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1355 ((string-match "^Differences" header)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1356 (error (concat "doctest-replace-output can not be used "
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1357 "with diff style output")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1358 (t (error "Unexpected header %s" header))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1359
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1360 ;; Go back to the source buffer.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1361 (set-buffer orig-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1362
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1363 ;; Skip ahead to the output.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1364 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1365 (unless (re-search-forward "^ *>>>.*")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1366 (error "Error parsing doctest output"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1367 (re-search-forward "\\(\n *\\.\\.\\..*\\)*\n?")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1368 (when (looking-at "\\'") (insert-char ?\n))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1369
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1370 ;; Check that the output matches.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1371 (let ((start (point)) end)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1372 (cond ((re-search-forward "^ *\\(>>>.*\\|$\\)" nil t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1373 (setq end (match-beginning 0)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1374 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1375 (goto-char (point-max))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1376 (insert-string "\n")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1377 (setq end (point-max))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1378 (when (and doctest-expected
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1379 (not (equal (buffer-substring start end)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1380 doctest-expected)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1381 (warn "{%s} {%s}" (buffer-substring start end)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1382 doctest-expected)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1383 (error (concat "This example's output has been modified "
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1384 "since doctest was last run")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1385 (setq doctest-expected (buffer-substring start end))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1386 (goto-char end))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1387
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1388 ;; Trim exceptions
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1389 (when (and doctest-trim-exceptions
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1390 (string-match doctest-traceback-re
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1391 doctest-got))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1392 (let ((s1 0) (e1 (match-end 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1393 (s2 (match-beginning 2)) (e2 (match-end 2))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1394 (s3 (match-beginning 3)) (e3 (length doctest-got)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1395 (setq doctest-got
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1396 (concat (substring doctest-got s1 e1)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1397 (substring doctest-got s2 e2) " . . .\n"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1398 (substring doctest-got s3 e3)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1399
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1400 ;; Confirm it with the user.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1401 (let ((confirm-buffer (get-buffer-create "*doctest-confirm*")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1402 (set-buffer confirm-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1403 ;; Erase anything left over in the buffer.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1404 (delete-region (point-min) (point-max))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1405 ;; Write a confirmation message
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1406 (if (equal doctest-expected "")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1407 (insert-string "Replace nothing\n")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1408 (insert-string (concat "Replace:\n" doctest-expected)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1409 (if (equal doctest-got "")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1410 (insert-string "With nothing\n")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1411 (insert-string (concat "With:\n" doctest-got)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1412 (let ((confirm-window (display-buffer confirm-buffer)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1413 ;; Shrink the confirm window.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1414 (shrink-window-if-larger-than-buffer confirm-window)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1415 ;; Return to the original buffer.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1416 (set-buffer orig-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1417 ;; Match the old expected region.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1418 (when doctest-expected
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1419 (search-backward doctest-expected))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1420 (when (equal doctest-expected "") (backward-char 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1421 ;; Get confirmation & do the replacement
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1422 (widen)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1423 (cond ((y-or-n-p "Ok to replace? ")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1424 (when (equal doctest-expected "") (forward-char 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1425 (replace-match doctest-got t t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1426 (message "Replaced."))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1427 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1428 (message "Replace cancelled.")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1429 ;; Clean up our confirm window
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1430 (kill-buffer confirm-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1431 (delete-window confirm-window)))))))))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1432
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1433 (defun doctest-results-next-header ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1434 "Move to the next header in the doctest results buffer, and return
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1435 the string contents of that header. If no header is found, return
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1436 nil."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1437 (if (re-search-forward (concat doctest-results-header-re "\\|"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1438 doctest-results-divider-re) nil t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1439 (let ((result (match-string 0)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1440 (if (string-match doctest-results-header-re result)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1441 result
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1442 nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1443 nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1444
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1445 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1446 ;;; mmm-mode support
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1447 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1448 ;; MMM Mode is a minor mode for Emacs which allows Multiple Major
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1449 ;; Modes to coexist in a single buffer.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1450
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1451 ;;;###autoload
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1452 (defun doctest-register-mmm-classes (&optional add-mode-ext-classes
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1453 fix-mmm-fontify-region-bug)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1454 "Register doctest's mmm classes, allowing doctest to be used as a
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1455 submode region in other major modes, such as python-mode and rst-mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1456 Two classes are registered:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1457
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1458 `doctest-docstring'
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1459
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1460 Used to edit docstrings containing doctest examples in python-
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1461 mode. Docstring submode regions start and end with triple-quoted
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1462 strings (\"\"\"). In order to avoid confusing start-string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1463 markers and end-string markers, all triple-quote strings in the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1464 buffer are treated as submode regions (even if they're not
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1465 actually docstrings). Use (C-c % C-d) to insert a new doctest-
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1466 docstring region. When `doctest-execute' (C-c C-c) is called
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1467 inside a doctest-docstring region, it executes just the current
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1468 docstring. The globals for this execution are constructed by
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1469 importing the current buffer's contents in Python.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1470
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1471 `doctest-example'
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1472
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1473 Used to edit doctest examples in text-editing modes, such as
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1474 `rst-mode' or `text-mode'. Docstring submode regions start with
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1475 optionally indented prompts (>>>) and end with blank lines. Use
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1476 (C-c % C-e) to insert a new doctest-example region. When
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1477 `doctest-execute' (C-c C-c) is called inside a doctest-example
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1478 region, it executes all examples in the buffer.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1479
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1480 If ADD-MODE-EXT-CLASSES is true, then register the new classes in
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1481 `mmm-mode-ext-classes-alist', which will cause them to be used by
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1482 default in the following modes:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1483
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1484 doctest-docstring: python-mode
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1485 doctest-example: rst-mode
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1486
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1487 If FIX-MMM-FONTIFY-REGION-BUG is true, then register a hook that will
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1488 fix a bug in `mmm-fontify-region' that affects some (but not all)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1489 versions of emacs. (See `doctest-fixed-mmm-fontify-region' for more
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1490 info.)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1491 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1492 (require 'mmm-auto)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1493 (mmm-add-classes
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1494 '(
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1495 ;; === doctest-docstring ===
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1496 (doctest-docstring :submode doctest-mode
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1497
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1498 ;; The front is any triple-quote. Include it in the submode region,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1499 ;; to prevent clashes between the two syntax tables over quotes.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1500 :front "\\(\"\"\"\\|'''\\)" :include-front t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1501
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1502 ;; The back matches the front. Include just the first character
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1503 ;; of the quote. If we didn't include at least one quote, then
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1504 ;; the outer modes quote-counting would be thrown off. But if
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1505 ;; we include all three, we run into a bug in mmm-mode. See
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1506 ;; <http://tinyurl.com/2fa83w> for more info about the bug.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1507 :save-matches t :back "~1" :back-offset 1 :end-not-begin t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1508
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1509 ;; Define a skeleton for entering new docstrings.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1510 :insert ((?d docstring nil @ "\"\"" @ "\"" \n
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1511 _ \n "\"" @ "\"\"" @)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1512
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1513 ;; === doctest-example ===
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1514 (doctest-example
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1515 :submode doctest-mode
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1516 ;; The front is an optionally indented prompt.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1517 :front "^[ \t]*>>>" :include-front t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1518 ;; The back is a blank line.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1519 :back "^[ \t]*$"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1520 ;; Define a skeleton for entering new docstrings.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1521 :insert ((?e doctest-example nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1522 @ @ " >>> " _ "\n\n" @ @)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1523
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1524 ;; Register some local variables that need to be saved.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1525 (add-to-list 'mmm-save-local-variables
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1526 '(doctest-results-buffer buffer))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1527 (add-to-list 'mmm-save-local-variables
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1528 '(doctest-example-markers buffer))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1529
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1530 ;; Register association with modes, if requested.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1531 (when add-mode-ext-classes
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1532 (mmm-add-mode-ext-class 'python-mode nil 'doctest-docstring)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1533 (mmm-add-mode-ext-class 'rst-mode nil 'doctest-example))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1534
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1535 ;; Fix the buggy mmm-fontify-region, if requested.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1536 (when fix-mmm-fontify-region-bug
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1537 (add-hook 'mmm-mode-hook 'doctest-fix-mmm-fontify-region-bug)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1538
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1539 (defvar doctest-old-mmm-fontify-region 'nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1540 "Used to hold the original definition of `mmm-fontify-region' when it
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1541 is rebound by `doctest-fix-mmm-fontify-region-bug'.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1542
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1543 (defun doctest-fix-mmm-fontify-region-bug ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1544 "A function for `mmm-mode-hook' which fixes a potential bug in
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1545 `mmm-fontify-region' by using `doctest-fixed-mmm-fontify-region'
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1546 instead. (See `doctest-fixed-mmm-fontify-region' for more info.)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1547 (setq font-lock-fontify-region-function
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1548 'doctest-fixed-mmm-fontify-region))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1549
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1550 (defun doctest-fixed-mmm-fontify-region (start stop &optional loudly)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1551 "A replacement for `mmm-fontify-region', which fixes a bug caused by
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1552 versions of emacs where post-command-hooks are run *before*
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1553 fontification. `mmm-mode' assumes that its post-command-hook will be
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1554 run after fontification; and if it's not, then mmm-mode can end up
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1555 with the wrong local variables, keymap, etc. after fontification. We
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1556 fix that here by redefining `mmm-fontify-region' to remember what
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1557 submode overlay it started in; and to return to that overlay after
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1558 fontification is complete. The original definition of
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1559 `mmm-fontify-region' is stored in `doctest-old-mmm-fontify-region'."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1560 (let ((overlay mmm-current-overlay))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1561 (mmm-fontify-region start stop loudly)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1562 (if (and overlay (or (< (point) (overlay-start overlay))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1563 (> (point) (overlay-end overlay))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1564 (goto-char (overlay-start overlay)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1565 (mmm-update-submode-region)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1566
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1567 (defun doctest-in-mmm-docstring-overlay ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1568 (and (featurep 'mmm-auto)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1569 (mmm-overlay-at (point))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1570 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1571 (goto-char (overlay-start (mmm-overlay-at (point))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1572 (looking-at "\"\"\"\\|\'\'\'"))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1573
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1574 (defun doctest-narrow-to-mmm-overlay ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1575 "If we're in an mmm-mode overlay, then narrow to that overlay.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1576 This is useful, e.g., to keep from interpreting the close-quote of a
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1577 docstring as part of the example's output."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1578 (let ((bounds (doctest-mmm-overlay-bounds)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1579 (when bounds (narrow-to-region (car bounds) (cdr bounds)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1580
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1581 (defun doctest-default-margin-in-mmm-docstring-overlay ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1582 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1583 (let ((pos (car (doctest-mmm-overlay-bounds))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1584 (goto-char pos)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1585 (when (doctest-looking-back "\"\"\"\\|\'\'\'")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1586 (setq pos (- pos 3)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1587 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1588 (- pos (point)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1589
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1590 (defun doctest-mmm-overlay-bounds ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1591 (when (featurep 'mmm-auto)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1592 (let ((overlay (mmm-overlay-at (point))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1593 (when overlay
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1594 (let ((start (overlay-start overlay))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1595 (end (overlay-end overlay)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1596 (when (doctest-in-mmm-docstring-overlay)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1597 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1598 (goto-char start)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1599 (re-search-forward "[\"\']*")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1600 (setq start (point))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1601 (goto-char end)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1602 (while (doctest-looking-back "[\"\']")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1603 (backward-char 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1604 (setq end (point))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1605 (cons start end))))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1606
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1607 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1608 ;;; Helper functions
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1609 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1610
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1611 (defun doctest-on-source-line-p (&optional prompt)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1612 "Return true if the current line is a source line. The optional
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1613 argument prompt can be used to specify which type of source
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1614 line (... or >>>)."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1615 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1616 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1617 ;; Check if we're looking at a prompt (of the right type).
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1618 (when (and (looking-at doctest-prompt-re)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1619 (or (null prompt)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1620 (equal prompt (substring (match-string 2) 0 3))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1621 ;; Scan backwards to make sure there's a >>> somewhere. Otherwise,
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1622 ;; this might be a '...' in the text or in an example's output.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1623 (while (looking-at "^[ \t]*[.][.][.]")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1624 (forward-line -1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1625 (looking-at "^[ \t]*>>>"))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1626
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1627 (defun doctest-on-empty-source-line-p ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1628 "Return true if the current line contains a bare prompt."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1629 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1630 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1631 (and (doctest-on-source-line-p)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1632 (looking-at (concat doctest-prompt-re "$")))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1633
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1634 (defun doctest-on-output-line-p ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1635 "Return true if the current line is an output line."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1636 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1637 (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1638 ;; The line must not be blank or a source line.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1639 (when (not (or (doctest-on-source-line-p) (looking-at "[ \t]*$")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1640 ;; The line must follow a source line, with no intervening blank
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1641 ;; lines.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1642 (while (not (or (doctest-on-source-line-p) (looking-at "[ \t]*$")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1643 (= (point) (point-min))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1644 (forward-line -1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1645 (doctest-on-source-line-p))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1646
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1647 (defun doctest-find-output-line (&optional limit)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1648 "Move forward to the next doctest output line (staying within
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1649 the given bounds). Return the character position of the doctest
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1650 output line if one was found, and false otherwise."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1651 (let ((found-it nil) ; point where we found an output line
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1652 (limit (or limit (point-max)))) ; default value for limit
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1653 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1654 ;; Keep moving forward, one line at a time, until we find a
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1655 ;; doctest output line.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1656 (while (and (not found-it) (< (point) limit) (not (eobp)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1657 (if (and (not (eolp)) (doctest-on-output-line-p))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1658 (setq found-it (point))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1659 (forward-line))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1660 ;; If we found a doctest output line, then go to it.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1661 (if found-it (goto-char found-it))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1662
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1663 (defun doctest-line-indentation ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1664 "Helper for doctest-replace-output: return the whitespace indentation
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1665 at the beginning of this line."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1666 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1667 (end-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1668 (re-search-backward "^\\( *\\)" nil t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1669 (match-string 1)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1670
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1671 (defun doctest-optionflags (&optional diff)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1672 "Return a string describing the optionflags that should be used
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1673 by doctest. If DIFF is non-nil, then add the REPORT_UDIFF flag."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1674 (let ((flags "0"))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1675 (dolist (flag doctest-optionflags)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1676 (setq flags (concat flags "|" flag)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1677 (if diff (concat flags "|" "REPORT_UDIFF") flags)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1678
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1679 (defun doctest-results-loc-re ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1680 "Return the regexp that should be used to look for doctest example
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1681 location markers in doctest's output (based on which version of
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1682 doctest was used"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1683 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1684 ((equal doctest-results-py-version 'py21)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1685 doctest-py21-results-loc-re)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1686 ((equal doctest-results-py-version 'py24)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1687 doctest-py24-results-loc-re)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1688 (t (error "bad value for doctest-results-py-version"))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1689
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1690 (defun doctest-results-buffer-name ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1691 "Return the buffer name that should be used for the doctest results
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1692 buffer. This is computed from the variable
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1693 `doctest-results-buffer-name'."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1694 (doctest-replace-regexp-in-string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1695 "%[nfN]"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1696 (lambda (sym)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1697 (cond ((equal sym "%n") (buffer-name))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1698 ((equal sym "%N") (doctest-replace-regexp-in-string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1699 "[.]doctest$" "" (buffer-name) t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1700 ((equal sym "%f") (buffer-file-name))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1701 doctest-results-buffer-name t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1702
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1703 (defun doctest-script (input-file globs-file diff)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1704 "..."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1705 (doctest-replace-regexp-in-string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1706 "%[tnflm]"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1707 (lambda (sym)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1708 (cond ((equal sym "%n") (buffer-name))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1709 ((equal sym "%f") (buffer-file-name))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1710 ((equal sym "%l") (doctest-optionflags diff))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1711 ((equal sym "%t") input-file)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1712 ((equal sym "%m") (or globs-file ""))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1713 doctest-script t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1714
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1715 (defun doctest-hide-example-source ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1716 "Delete the source code listings from the results buffer (since it's
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1717 easy enough to see them in the original buffer)"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1718 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1719 (set-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1720 (toggle-read-only 0)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1721 (goto-char (point-min))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1722 (while (re-search-forward doctest-example-source-re nil t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1723 (replace-match "" nil nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1724 (toggle-read-only t)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1725
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1726 (defun doctest-results-buffer-valid-p ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1727 "Return true if this buffer has a live results buffer; and that
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1728 results buffer reports this buffer as its source buffer. (Two
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1729 buffers in doctest-mode might point to the same results buffer;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1730 but only one of them will be equal to that results buffer's
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1731 source buffer."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1732 (let ((cur-buf (current-buffer)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1733 (and (buffer-live-p doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1734 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1735 (set-buffer doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1736 (equal cur-buf doctest-source-buffer)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1737
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1738 (defun doctest-update-mode-line (value)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1739 "Update the doctest mode line with the given string value. This
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1740 is used to display information about asynchronous processes that
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1741 are run by doctest-mode."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1742 (setq doctest-mode-line-process
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1743 value)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1744 (force-mode-line-update t))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1745
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1746 (defun doctest-version ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1747 "Echo the current version of `doctest-mode' in the minibuffer."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1748 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1749 (message "Using `doctest-mode' version %s" doctest-version))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1750
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1751 (defun doctest-warn (msg &rest args)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1752 "Display a doctest warning message."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1753 (if (fboundp 'display-warning)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1754 (display-warning 'doctest (apply 'format msg args))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1755 (apply 'message msg args)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1756
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1757 (defun doctest-debug (msg &rest args)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1758 "Display a doctest debug message."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1759 (if (fboundp 'display-warning)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1760 (display-warning 'doctest (apply 'format msg args) 'debug)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1761 (apply 'message msg args)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1762
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1763 (defvar doctest-serial-number 0) ;used if broken-temp-names.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1764 (defun doctest-temp-name ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1765 "Return a new temporary filename, for use in calling doctest."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1766 (if (memq 'broken-temp-names features)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1767 (let
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1768 ((sn doctest-serial-number)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1769 (pid (and (fboundp 'emacs-pid) (emacs-pid))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1770 (setq doctest-serial-number (1+ doctest-serial-number))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1771 (if pid
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1772 (format "doctest-%d-%d" sn pid)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1773 (format "doctest-%d" sn)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1774 (make-temp-name "doctest-")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1775
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1776 (defun doctest-fontify-line (charpos)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1777 "Run font-lock-fontify-region on the line containing the given
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1778 position."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1779 (if (and charpos (functionp 'font-lock-fontify-region))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1780 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1781 (goto-char charpos)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1782 (let ((beg (progn (beginning-of-line) (point)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1783 (end (progn (end-of-line) (point))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1784 (font-lock-fontify-region beg end)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1785
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1786 (defun doctest-do-auto-fill ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1787 "If the current line is a soucre line or an output line, do nothing.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1788 Otherwise, call (do-auto-fill)."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1789 (cond
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1790 ;; Don't wrap source lines.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1791 ((doctest-on-source-line-p) nil)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1792 ;; Don't wrap output lines
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1793 ((doctest-on-output-line-p) nil)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1794 ;; Wrap all other lines
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1795 (t (do-auto-fill))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1796
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1797 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1798 ;;; Emacs Compatibility Functions
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1799 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1800 ;; Define compatible versions of functions that are defined
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1801 ;; for some versions of emacs but not others.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1802
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1803 ;; Backwards compatibility: looking-back
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1804 (cond ((fboundp 'looking-back) ;; Emacs 22.x
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1805 (defalias 'doctest-looking-back 'looking-back))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1806 (t
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1807 (defun doctest-looking-back (regexp)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1808 "Return true if text before point matches REGEXP."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1809 (save-excursion
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1810 (let ((orig-pos (point)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1811 ;; Search backwards for the regexp.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1812 (if (re-search-backward regexp nil t)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1813 ;; Check if it ends at the original point.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1814 (= orig-pos (match-end 0))))))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1815
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1816 ;; Backwards compatibility: replace-regexp-in-string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1817 (cond ((fboundp 'replace-regexp-in-string)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1818 (defalias 'doctest-replace-regexp-in-string 'replace-regexp-in-string))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1819 (t ;; XEmacs 21.x or Emacs 20.x
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1820 (defun doctest-replace-regexp-in-string
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1821 (regexp rep string &optional fixedcase literal)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1822 "Replace all matches for REGEXP with REP in STRING."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1823 (let ((start 0))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1824 (while (and (< start (length string))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1825 (string-match regexp string start))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1826 (setq start (+ (match-end 0) 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1827 (let ((newtext (if (functionp rep)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1828 (save-match-data
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1829 (funcall rep (match-string 0 string)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1830 rep)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1831 (setq string (replace-match newtext fixedcase
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1832 literal string)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1833 string)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1834
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1835 ;; Backwards compatibility: line-number
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1836 (cond ((fboundp 'line-number) ;; XEmacs
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1837 (defalias 'doctest-line-number 'line-number))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1838 ((fboundp 'line-number-at-pos) ;; Emacs 22.x
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1839 (defalias 'doctest-line-number 'line-number-at-pos))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1840 (t ;; Emacs 21.x
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1841 (defun doctest-line-number (&optional pos)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1842 "Return the line number of POS (default=point)."
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1843 (1+ (count-lines 1
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1844 (save-excursion (progn (beginning-of-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1845 (or pos (point)))))))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1846
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1847 ;; Backwards compatibility: process-live-p
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1848 (cond ((fboundp 'process-live-p) ;; XEmacs
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1849 (defalias 'doctest-process-live-p 'process-live-p))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1850 (t ;; Emacs
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1851 (defun doctest-process-live-p (process)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1852 (and (processp process)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1853 (equal (process-status process) 'run)))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1854
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1855 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1856 ;;; Doctest Results Mode (output of doctest-execute-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1857 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1858
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1859 ;; Register the font-lock keywords (xemacs)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1860 (put 'doctest-results-mode 'font-lock-defaults
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1861 '(doctest-results-font-lock-keywords))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1862
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1863 ;; Register the font-lock keywords (older versions of gnu emacs)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1864 (when (boundp 'font-lock-defaults-alist)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1865 (add-to-list 'font-lock-defaults-alist
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1866 '(doctest-results-mode doctest-results-font-lock-keywords
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1867 nil nil nil nil)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1868
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1869 (defvar doctest-selected-failure nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1870 "The location of the currently selected failure.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1871 This variable is uffer-local to doctest-results-mode buffers.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1872
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1873 (defvar doctest-source-buffer nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1874 "The buffer that spawned this one.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1875 This variable is uffer-local to doctest-results-mode buffers.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1876
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1877 (defvar doctest-results-py-version nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1878 "A symbol indicating which version of Python was used to generate
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1879 the results in a doctest-results-mode buffer. Can be either the
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1880 symbol `py21' or the symbol `py24'.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1881 This variable is uffer-local to doctest-results-mode buffers.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1882
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1883 ;; Keymap for doctest-results-mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1884 (defconst doctest-results-mode-map
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1885 (let ((map (make-keymap)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1886 (define-key map [return] 'doctest-select-failure)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1887 map)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1888 "Keymap for doctest-results-mode.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1889
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1890 ;; Syntax table for doctest-results-mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1891 (defvar doctest-results-mode-syntax-table nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1892 "Syntax table used in `doctest-results-mode' buffers.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1893 (when (not doctest-results-mode-syntax-table)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1894 (setq doctest-results-mode-syntax-table (make-syntax-table))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1895 (dolist (entry '(("(" . "()") ("[" . "(]") ("{" . "(}")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1896 (")" . ")(") ("]" . ")[") ("}" . "){")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1897 ("$%&*+-/<=>|'\"`" . ".") ("_" . "w")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1898 (dolist (char (string-to-list (car entry)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1899 (modify-syntax-entry char (cdr entry)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1900 doctest-results-mode-syntax-table))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1901
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1902 ;; Define the mode
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1903 (defun doctest-results-mode ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1904 "A major mode used to display the results of running doctest.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1905 See `doctest-mode'.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1906
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1907 \\{doctest-results-mode-map}"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1908 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1909
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1910 ;; Declare local variables.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1911 (kill-all-local-variables)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1912 (make-local-variable 'font-lock-defaults)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1913 (make-local-variable 'doctest-selected-failure)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1914 (make-local-variable 'doctest-source-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1915 (make-local-variable 'doctest-results-py-version)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1916
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1917 ;; Define local variables.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1918 (setq major-mode 'doctest-results-mode
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1919 mode-name "Doctest-Results"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1920 mode-line-process 'doctest-mode-line-process
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1921 font-lock-defaults '(doctest-results-font-lock-keywords
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1922 nil nil nil nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1923 ;; Define keymap.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1924 (use-local-map doctest-results-mode-map)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1925
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1926 ;; Define the syntax table.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1927 (set-syntax-table doctest-results-mode-syntax-table)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1928
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1929 ;; Enable font-lock mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1930 (if (featurep 'font-lock) (font-lock-mode 1)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1931
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1932 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1933 ;;; Doctest Mode
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1934 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1935
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1936 ;; Register the font-lock keywords (xemacs)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1937 (put 'doctest-mode 'font-lock-defaults '(doctest-font-lock-keywords
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1938 nil nil nil nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1939
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1940 ;; Register the font-lock keywords (older versions of gnu emacs)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1941 (when (boundp 'font-lock-defaults-alist)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1942 (add-to-list 'font-lock-defaults-alist
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1943 '(doctest-mode doctest-font-lock-keywords
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1944 nil nil nil nil)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1945
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1946 (defvar doctest-results-buffer nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1947 "The output buffer for doctest-mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1948 This variable is buffer-local to doctest-mode buffers.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1949
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1950 (defvar doctest-example-markers nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1951 "A list mapping markers to the line numbers at which they appeared
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1952 in the buffer at the time doctest was last run. This is used to find
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1953 'original' line numbers, which can be used to search the doctest
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1954 output buffer. It's encoded as a list of (MARKER . POS) tuples, in
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1955 reverse POS order.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1956 This variable is buffer-local to doctest-mode buffers.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1957
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1958 ;; These are global, since we only one run process at a time:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1959 (defvar doctest-async-process nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1960 "The process object created by the asynchronous doctest process")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1961 (defvar doctest-async-process-tempfiles nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1962 "A list of tempfile names created by the asynchronous doctest process")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1963 (defvar doctest-async-process-buffer nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1964 "The source buffer for the asynchronous doctest process")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1965 (defvar doctest-mode-line-process ""
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1966 "A string displayed on the modeline, to indicate when doctest is
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1967 running asynchronously.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1968
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1969 ;; Keymap for doctest-mode. n.b.: we intentionally define [tab]
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1970 ;; rather than overriding indent-line-function, since we don't want
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1971 ;; doctest-indent-source-line to be called by do-auto-fill.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1972 (defconst doctest-mode-map
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1973 (let ((map (make-keymap)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1974 (define-key map [backspace] 'doctest-electric-backspace)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1975 (define-key map [return] 'doctest-newline-and-indent)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1976 (define-key map [tab] 'doctest-indent-source-line)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1977 (define-key map ":" 'doctest-electric-colon)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1978 (define-key map "\C-c\C-v" 'doctest-version)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1979 (define-key map "\C-c\C-c" 'doctest-execute)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1980 (define-key map "\C-c\C-d" 'doctest-execute-with-diff)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1981 (define-key map "\C-c\C-n" 'doctest-next-failure)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1982 (define-key map "\C-c\C-p" 'doctest-prev-failure)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1983 (define-key map "\C-c\C-a" 'doctest-first-failure)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1984 (define-key map "\C-c\C-e" 'doctest-last-failure)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1985 (define-key map "\C-c\C-z" 'doctest-last-failure)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1986 (define-key map "\C-c\C-r" 'doctest-replace-output)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1987 (define-key map "\C-c|" 'doctest-execute-region)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1988 map)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1989 "Keymap for doctest-mode.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1990
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1991 ;; Syntax table for doctest-mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1992 (defvar doctest-mode-syntax-table nil
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1993 "Syntax table used in `doctest-mode' buffers.")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1994 (when (not doctest-mode-syntax-table)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1995 (setq doctest-mode-syntax-table (make-syntax-table))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1996 (dolist (entry '(("(" . "()") ("[" . "(]") ("{" . "(}")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1997 (")" . ")(") ("]" . ")[") ("}" . "){")
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1998 ("$%&*+-/<=>|'\"`" . ".") ("_" . "w")))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1999 (dolist (char (string-to-list (car entry)))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2000 (modify-syntax-entry char (cdr entry) doctest-mode-syntax-table))))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2001
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2002 ;; Use doctest mode for files ending in .doctest
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2003 ;;;###autoload
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2004 (add-to-list 'auto-mode-alist '("\\.doctest$" . doctest-mode))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2005
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2006 ;;;###autoload
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2007 (defun doctest-mode ()
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2008 "A major mode for editing text files that contain Python
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2009 doctest examples. Doctest is a testing framework for Python that
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2010 emulates an interactive session, and checks the result of each
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2011 command. For more information, see the Python library reference:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2012 <http://docs.python.org/lib/module-doctest.html>
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2013
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2014 `doctest-mode' defines three kinds of line, each of which is
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2015 treated differently:
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2016
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2017 - 'Source lines' are lines consisting of a Python prompt
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2018 ('>>>' or '...'), followed by source code. Source lines are
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2019 colored (similarly to `python-mode') and auto-indented.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2020
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2021 - 'Output lines' are non-blank lines immediately following
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2022 source lines. They are colored using several doctest-
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2023 specific output faces.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2024
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2025 - 'Text lines' are any other lines. They are not processed in
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2026 any special way.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2027
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2028 \\{doctest-mode-map}"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2029 (interactive)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2030
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2031 ;; Declare local variables.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2032 (kill-all-local-variables)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2033 (make-local-variable 'font-lock-defaults)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2034 (make-local-variable 'doctest-results-buffer)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2035 (make-local-variable 'doctest-example-markers)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2036
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2037 ;; Define local variables.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2038 (setq major-mode 'doctest-mode
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2039 mode-name "Doctest"
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2040 mode-line-process 'doctest-mode-line-process
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2041 font-lock-defaults '(doctest-font-lock-keywords
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2042 nil nil nil nil))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2043
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2044 ;; Define keymap.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2045 (use-local-map doctest-mode-map)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2046
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2047 ;; Define the syntax table.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2048 (set-syntax-table doctest-mode-syntax-table)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2049
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2050 ;; Enable auto-fill mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2051 (auto-fill-mode 1)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2052 (setq auto-fill-function 'doctest-do-auto-fill)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2053
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2054 ;; Enable font-lock mode.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2055 (if (featurep 'font-lock) (font-lock-mode 1))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2056
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2057 ;; Run the mode hook.
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2058 (run-hooks 'doctest-mode-hook))
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2059
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2060 (provide 'doctest-mode)
c30d68fbd368 Initial import from svn.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2061 ;;; doctest-mode.el ends here