annotate .elisp/doctest-mode.el @ 209:c28a1e2c746a

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