Mercurial > emacs
annotate lisp/progmodes/python.el @ 55300:2db456741f80
(python-compilation-line-number): Remove.
(python-compilation-regexp-alist): Don't use it any more.
(python-orig-start, python-input-filter): Remove.
(inferior-python-mode): Don't set up comint-input-filter-functions.
(python-send-region): Use compilation-fake-loc.
| author | Stefan Monnier <monnier@iro.umontreal.ca> |
|---|---|
| date | Sat, 01 May 2004 21:16:07 +0000 |
| parents | 780b94f913fe |
| children | a828ab1b3079 |
| rev | line source |
|---|---|
| 54789 | 1 ;;; python.el --- silly walks for Python |
| 2 | |
| 3 ;; Copyright (C) 2003, 04 Free Software Foundation, Inc. | |
| 4 | |
| 5 ;; Author: Dave Love <fx@gnu.org> | |
|
54943
07e279030b6f
(python-compilation-line-number): Fix braindamage.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54938
diff
changeset
|
6 ;; Maintainer: FSF |
| 54789 | 7 ;; Created: Nov 2003 |
| 8 ;; Keywords: languages | |
| 9 | |
| 10 ;; This file is part of GNU Emacs. | |
| 11 | |
| 12 ;; This file is free software; you can redistribute it and/or modify | |
| 13 ;; it under the terms of the GNU General Public License as published by | |
| 14 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 15 ;; any later version. | |
| 16 | |
| 17 ;; This file is distributed in the hope that it will be useful, | |
| 18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 20 ;; GNU General Public License for more details. | |
| 21 | |
| 22 ;; You should have received a copy of the GNU General Public License | |
| 23 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
| 24 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 25 ;; Boston, MA 02111-1307, USA. | |
| 26 | |
| 27 ;;; Commentary: | |
| 28 | |
| 29 ;; Major mode for editing Python, with support for inferior processes. | |
| 30 | |
| 31 ;; There is another Python mode, python-mode.el, used by XEmacs and | |
| 32 ;; maintained with Python. That isn't covered by an FSF copyright | |
| 33 ;; assignment, unlike this code, and seems not to be well-maintained | |
| 34 ;; for Emacs (though I've submitted fixes). This mode is rather | |
| 35 ;; simpler and is, perhaps, better in other ways. In particular, | |
| 36 ;; using the syntax functions with text properties maintained by | |
| 37 ;; font-lock should make it more correct with arbitrary string and | |
| 38 ;; comment contents. | |
| 39 | |
| 40 ;; This doesn't implement all the facilities of python-mode.el. Some | |
| 41 ;; just need doing, e.g. catching exceptions in the inferior Python | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
42 ;; buffer (but see M-x pdb for debugging). [Actually, the use of |
| 54789 | 43 ;; `compilation-minor-mode' now is probably enough for that.] Others |
| 44 ;; don't seem appropriate. For instance, `forward-into-nomenclature' | |
| 45 ;; should be done separately, since it's not specific to Python, and | |
| 46 ;; I've installed a minor mode to do the job properly in Emacs 22. | |
| 47 ;; Other things seem more natural or canonical here, e.g. the | |
| 48 ;; {beginning,end}-of-defun implementation dealing with nested | |
| 49 ;; definitions, and the inferior mode following `cmuscheme'. (The | |
| 50 ;; inferior mode should be able to find the source of errors from | |
| 51 ;; `python-send-region' & al via `compilation-minor-mode', but I can't | |
| 52 ;; make that work with the current (March '04) compile.el.) | |
| 53 ;; Successive TABs cycle between possible indentations for the line. | |
| 54 | |
| 55 ;; Even where it has similar facilities, this is incompatible with | |
| 56 ;; python-mode.el in various respects. For instance, various key | |
| 57 ;; bindings are changed to obey Emacs conventions, and things like | |
| 58 ;; marking blocks and `beginning-of-defun' behave differently. | |
| 59 | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
60 ;; TODO: See various Fixmes below. It should be possible to arrange |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
61 ;; some sort of completion using the inferior interpreter. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
62 |
| 54789 | 63 ;;; Code: |
| 64 | |
| 65 ;; It's messy to autoload the relevant comint functions so that comint | |
| 66 ;; is only required when inferior Python is used. | |
| 67 (require 'comint) | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
68 (eval-when-compile |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
69 (require 'compile) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
70 (autoload 'info-lookup-maybe-add-help "info-look")) |
|
54938
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
71 (autoload 'compilation-start "compile") |
| 54789 | 72 |
| 73 (defgroup python nil | |
| 74 "Silly walks in the Python language" | |
| 75 :group 'languages | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
76 :version "21.4" |
| 54789 | 77 :link '(emacs-commentary-link "python")) |
| 78 | |
| 79 ;;;###autoload | |
| 80 (add-to-list 'interpreter-mode-alist '("jython" . jython-mode)) | |
| 81 ;;;###autoload | |
| 82 (add-to-list 'interpreter-mode-alist '("python" . python-mode)) | |
| 83 ;;;###autoload | |
| 84 (add-to-list 'auto-mode-alist '("\\.py\\'" . python-mode)) | |
| 85 | |
| 86 ;;;; Font lock | |
| 87 | |
| 88 (defvar python-font-lock-keywords | |
| 89 `(,(rx (and word-start | |
| 90 ;; From v 2.3 reference. | |
| 91 ;; def and class dealt with separately below | |
| 92 (or "and" "assert" "break" "continue" "del" "elif" "else" | |
| 93 "except" "exec" "finally" "for" "from" "global" "if" | |
| 94 "import" "in" "is" "lambda" "not" "or" "pass" "print" | |
| 95 "raise" "return" "try" "while" "yield" | |
| 96 ;; Future keywords | |
| 97 "as" "None") | |
| 98 word-end)) | |
| 99 (,(rx (and word-start (group "class") (1+ space) (group (1+ word)))) | |
| 100 (1 font-lock-keyword-face) (2 font-lock-type-face)) | |
| 101 (,(rx (and word-start (group "def") (1+ space) (group (1+ word)))) | |
| 102 (1 font-lock-keyword-face) (2 font-lock-function-name-face)))) | |
| 103 | |
| 104 (defconst python-font-lock-syntactic-keywords | |
| 105 ;; Make outer chars of matching triple-quote sequences into generic | |
| 106 ;; string delimiters. Fixme: Is there a better way? | |
| 107 `((,(rx (and (group (optional (any "uUrR"))) ; prefix gets syntax property | |
| 108 (optional (any "rR")) ; possible second prefix | |
| 109 (group (syntax string-quote)) ; maybe gets property | |
| 110 (backref 2) ; per first quote | |
| 111 (group (backref 2)))) ; maybe gets property | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
112 (1 (python-quote-syntax 1)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
113 (2 (python-quote-syntax 2)) |
| 54789 | 114 (3 (python-quote-syntax 3))) |
| 115 ;; This doesn't really help. | |
| 116 ;;; (,(rx (and ?\\ (group ?\n))) (1 " ")) | |
| 117 )) | |
| 118 | |
| 119 (defun python-quote-syntax (n) | |
| 120 "Put `syntax-table' property correctly on triple quote. | |
| 121 Used for syntactic keywords. N is the match number (1, 2 or 3)." | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
122 ;; Given a triple quote, we have to check the context to know |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
123 ;; whether this is an opening or closing triple or whether it's |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
124 ;; quoted anyhow, and should be ignored. (For that we need to do |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
125 ;; the same job as `syntax-ppss' to be correct and it seems to be OK |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
126 ;; to use it here despite initial worries.) We also have to sort |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
127 ;; out a possible prefix -- well, we don't _have_ to, but I think it |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
128 ;; should be treated as part of the string. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
129 |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
130 ;; Test cases: |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
131 ;; ur"""ar""" x='"' # """ |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
132 ;; x = ''' """ ' a |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
133 ;; ''' |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
134 ;; x '"""' x |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
135 (save-excursion |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
136 (goto-char (match-beginning 0)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
137 (unless (eq ?\\ (char-before)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
138 (cond |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
139 ;; Consider property for the last char if in a fenced string. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
140 ((= n 3) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
141 (let ((syntax (syntax-ppss))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
142 (when (eq t (nth 3 syntax)) ; after unclosed fence |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
143 (goto-char (nth 8 syntax)) ; fence position |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
144 ;; Skip any prefix. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
145 (if (memq (char-after) '(?u ?U ?R ?r)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
146 (skip-chars-forward "uUrR")) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
147 ;; Is it a matching sequence? |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
148 (if (eq (char-after) (char-after (match-beginning 2))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
149 (eval-when-compile (string-to-syntax "|")))))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
150 ;; Consider property for initial char, accounting for prefixes. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
151 ((or (and (= n 2) ; not prefix |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
152 (= (match-beginning 1) (match-end 1))) ; prefix is null |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
153 (and (= n 1) ; prefix |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
154 (/= (match-beginning 1) (match-end 1)))) ; non-empty |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
155 (unless (eq 'string (syntax-ppss-context (syntax-ppss))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
156 (eval-when-compile (string-to-syntax "|"))))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
157 ;; Otherwise (we're in a non-matching string) the property is |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
158 ;; nil, which is OK. |
| 54789 | 159 ))) |
| 160 | |
| 161 ;; This isn't currently in `font-lock-defaults' as probably not worth | |
| 162 ;; it -- we basically only mess with a few normally-symbol characters. | |
| 163 | |
| 164 ;; (defun python-font-lock-syntactic-face-function (state) | |
| 165 ;; "`font-lock-syntactic-face-function' for Python mode. | |
| 166 ;; Returns the string or comment face as usual, with side effect of putting | |
| 167 ;; a `syntax-table' property on the inside of the string or comment which is | |
| 168 ;; the standard syntax table." | |
| 169 ;; (if (nth 3 state) | |
| 170 ;; (save-excursion | |
| 171 ;; (goto-char (nth 8 state)) | |
| 172 ;; (condition-case nil | |
| 173 ;; (forward-sexp) | |
| 174 ;; (error nil)) | |
| 175 ;; (put-text-property (1+ (nth 8 state)) (1- (point)) | |
| 176 ;; 'syntax-table (standard-syntax-table)) | |
| 177 ;; 'font-lock-string-face) | |
| 178 ;; (put-text-property (1+ (nth 8 state)) (line-end-position) | |
| 179 ;; 'syntax-table (standard-syntax-table)) | |
| 180 ;; 'font-lock-comment-face)) | |
| 181 | |
| 182 ;;;; Keymap and syntax | |
| 183 | |
| 184 (defvar python-mode-map | |
| 185 (let ((map (make-sparse-keymap))) | |
| 186 ;; Mostly taken from python-mode.el. | |
| 187 (define-key map ":" 'python-electric-colon) | |
| 188 (define-key map "\177" 'python-backspace) | |
| 189 (define-key map "\C-c<" 'python-shift-left) | |
| 190 (define-key map "\C-c>" 'python-shift-right) | |
| 191 (define-key map "\C-c\C-k" 'python-mark-block) | |
| 192 (define-key map "\C-c\C-n" 'python-next-statement) | |
| 193 (define-key map "\C-c\C-p" 'python-previous-statement) | |
| 194 (define-key map "\C-c\C-u" 'python-beginning-of-block) | |
| 195 (define-key map "\C-c\C-f" 'python-describe-symbol) | |
| 196 (define-key map "\C-c\C-w" 'python-check) | |
| 197 (define-key map "\C-c\C-v" 'python-check) ; a la sgml-mode | |
| 198 (define-key map "\C-c\C-s" 'python-send-string) | |
| 199 (define-key map [?\C-\M-x] 'python-send-defun) | |
| 200 (define-key map "\C-c\C-r" 'python-send-region) | |
| 201 (define-key map "\C-c\M-r" 'python-send-region-and-go) | |
| 202 (define-key map "\C-c\C-c" 'python-send-buffer) | |
| 203 (define-key map "\C-c\C-z" 'python-switch-to-python) | |
| 204 (define-key map "\C-c\C-m" 'python-load-file) | |
| 205 (define-key map "\C-c\C-l" 'python-load-file) ; a la cmuscheme | |
| 206 ;; Fixme: Add :help to menu. | |
| 207 (easy-menu-define python-menu map "Python Mode menu" | |
| 208 '("Python" | |
| 209 ["Shift region left" python-shift-left :active mark-active] | |
| 210 ["Shift region right" python-shift-right :active mark-active] | |
| 211 "-" | |
| 212 ["Mark block" python-mark-block] | |
| 213 ["Mark def/class" mark-defun | |
| 214 :help "Mark innermost definition around point"] | |
| 215 "-" | |
| 216 ["Start of block" python-beginning-of-block] | |
| 217 ["End of block" python-end-of-block] | |
| 218 ["Start of def/class" beginning-of-defun | |
| 219 :help "Go to start of innermost definition around point"] | |
| 220 ["End of def/class" end-of-defun | |
| 221 :help "Go to end of innermost definition around point"] | |
| 222 "-" | |
| 223 ["Start interpreter" run-python | |
| 224 :help "Run `inferior' Python in separate buffer"] | |
| 225 ["Import/reload file" python-load-file | |
| 226 :help "Load into inferior Python session"] | |
| 227 ["Eval buffer" python-send-buffer | |
| 228 :help "Evaluate buffer en bloc in inferior Python session"] | |
| 229 ["Eval region" python-send-region :active mark-active | |
| 230 :help "Evaluate region en bloc in inferior Python session"] | |
| 231 ["Eval def/class" python-send-defun | |
| 232 :help "Evaluate current definition in inferior Python session"] | |
| 233 ["Switch to interpreter" python-switch-to-python | |
| 234 :help "Switch to inferior Python buffer"] | |
| 235 ["Check file" python-check :help "Run pychecker"] | |
| 236 ["Debugger" pdb :help "Run pdb under GUD"] | |
| 237 "-" | |
| 238 ["Help on symbol" python-describe-symbol | |
| 239 :help "Use pydoc on symbol at point"])) | |
| 240 map)) | |
| 241 | |
| 242 (defvar python-mode-syntax-table | |
| 243 (let ((table (make-syntax-table))) | |
| 244 ;; Give punctuation syntax to ASCII that normally has symbol | |
| 245 ;; syntax or has word syntax and isn't a letter. | |
| 246 (let ((symbol (string-to-syntax "_")) | |
| 247 (sst (standard-syntax-table))) | |
| 248 (dotimes (i 128) | |
| 249 (unless (= i ?_) | |
| 250 (if (equal symbol (aref sst i)) | |
| 251 (modify-syntax-entry i "." table))))) | |
| 252 (modify-syntax-entry ?$ "." table) | |
| 253 (modify-syntax-entry ?% "." table) | |
| 254 ;; exceptions | |
| 255 (modify-syntax-entry ?# "<" table) | |
| 256 (modify-syntax-entry ?\n ">" table) | |
| 257 (modify-syntax-entry ?' "\"" table) | |
| 258 (modify-syntax-entry ?` "$" table) | |
| 259 table)) | |
| 260 | |
| 261 ;;;; Utility stuff | |
| 262 | |
| 263 (defsubst python-in-string/comment () | |
| 264 "Return non-nil if point is in a Python literal (a comment or string). | |
| 265 Optional argument LIM indicates the beginning of the containing form, | |
| 266 i.e. the limit on how far back to scan." | |
| 267 (syntax-ppss-context (syntax-ppss))) | |
| 268 | |
| 269 (defconst python-space-backslash-table | |
| 270 (let ((table (copy-syntax-table python-mode-syntax-table))) | |
| 271 (modify-syntax-entry ?\\ " " table) | |
| 272 table) | |
| 273 "`python-mode-syntax-table' with backslash given whitespace syntax.") | |
| 274 | |
| 275 (defun python-skip-comments/blanks (&optional backward) | |
| 276 "Skip comments and blank lines. | |
| 277 BACKWARD non-nil means go backwards, otherwise go forwards. Backslash is | |
| 278 treated as whitespace so that continued blank lines are skipped. | |
| 279 Doesn't move out of comments -- should be outside or at end of line." | |
| 280 (with-syntax-table python-space-backslash-table | |
| 281 (forward-comment (if backward | |
| 282 most-negative-fixnum | |
| 283 most-positive-fixnum)))) | |
| 284 | |
| 285 (defun python-backslash-continuation-line-p () | |
| 286 "Non-nil if preceding line ends with backslash that is not in a comment." | |
| 287 (and (eq ?\\ (char-before (line-end-position 0))) | |
| 288 (not (syntax-ppss-context (syntax-ppss))))) | |
| 289 | |
| 290 (defun python-continuation-line-p () | |
| 291 "Return non-nil if current line continues a previous one. | |
| 292 The criteria are that the previous line ends in a backslash outside | |
| 293 comments and strings, or that the bracket/paren nesting depth is nonzero." | |
| 294 (or (and (eq ?\\ (char-before (line-end-position 0))) | |
| 295 (not (syntax-ppss-context (syntax-ppss)))) | |
| 296 (/= 0 (syntax-ppss-depth | |
| 297 (save-excursion ; syntax-ppss with arg changes point | |
| 298 (syntax-ppss (line-beginning-position))))))) | |
| 299 | |
| 300 (defun python-comment-line-p () | |
| 301 "Return non-nil if current line has only a comment or is blank." | |
| 302 (save-excursion | |
| 303 (back-to-indentation) | |
| 304 (looking-at (rx (or (syntax comment-start) line-end))))) | |
| 305 | |
| 306 (defun python-beginning-of-string () | |
| 307 "Go to beginning of string around point. | |
| 308 Do nothing if not in string." | |
| 309 (let ((state (syntax-ppss))) | |
| 310 (when (nth 3 state) | |
| 311 (goto-char (nth 8 state))))) | |
| 312 | |
| 313 (defun python-open-block-statement-p (&optional bos) | |
| 314 "Return non-nil if statement at point opens a block. | |
| 315 BOS non-nil means point is known to be at beginning of statement." | |
| 316 (save-excursion | |
| 317 (unless bos (python-beginning-of-statement)) | |
| 318 (and (not (python-comment-line-p)) | |
| 319 (re-search-forward (rx (and ?: (0+ space) | |
| 320 (optional (and (syntax comment-start) | |
| 321 (0+ not-newline))) | |
| 322 line-end)) | |
| 323 (save-excursion (python-end-of-statement)) | |
| 324 t) | |
| 325 (not (python-in-string/comment))))) | |
| 326 | |
| 327 (defun python-close-block-statement-p (&optional bos) | |
| 328 "Return non-nil if current line is a statement closing a block. | |
| 329 BOS non-nil means point is at beginning of statement. | |
| 330 The criteria are that the line isn't a comment or in string and starts with | |
| 331 keyword `raise', `break', `continue' or `pass'." | |
| 332 (save-excursion | |
| 333 (unless bos (python-beginning-of-statement)) | |
| 334 (back-to-indentation) | |
| 335 (looking-at (rx (and (or "return" "raise" "break" "continue" "pass") | |
| 336 word-end))))) | |
| 337 | |
| 338 (defun python-outdent-p () | |
| 339 "Return non-nil if current line should outdent a level." | |
| 340 (save-excursion | |
| 341 (back-to-indentation) | |
| 342 (and (looking-at (rx (and (or (and (or "else" "finally") word-end) | |
| 343 (and (or "except" "elif") word-end | |
| 344 (1+ (not (any ?:))))) | |
| 345 (optional space) ":" (optional space) | |
| 346 (or (syntax comment-start) line-end)))) | |
| 347 (progn (end-of-line) | |
| 348 (not (python-in-string/comment))) | |
| 349 ;; Ensure there's a previous statement and move to it. | |
| 350 (zerop (python-previous-statement)) | |
| 351 (not (python-close-block-statement-p t)) | |
| 352 ;; Fixme: check this | |
| 353 (not (looking-at (rx (and (or (and (or "if" "elif" "except" | |
| 354 "for" "while") | |
| 355 word-end (1+ (not (any ?:)))) | |
| 356 (and "try" word-end)) | |
| 357 (optional space) ":" (optional space) | |
| 358 (or (syntax comment-start) line-end))))) | |
| 359 (progn (end-of-line) | |
| 360 (not (python-in-string/comment)))))) | |
| 361 | |
| 362 ;;;; Indentation. | |
| 363 | |
| 364 (defcustom python-indent 4 | |
| 365 "*Number of columns for a unit of indentation in Python mode. | |
| 366 See also `\\[python-guess-indent]'" | |
| 367 :group 'python | |
| 368 :type 'integer) | |
| 369 | |
| 370 (defcustom python-guess-indent t | |
| 371 "*Non-nil means Python mode guesses `python-indent' for the buffer." | |
| 372 :type 'boolean | |
| 373 :group 'python) | |
| 374 | |
| 375 (defcustom python-indent-string-contents t | |
| 376 "*Non-nil means indent contents of multi-line strings together. | |
| 377 This means indent them the same as the preceding non-blank line. | |
| 378 Otherwise indent them to column zero." | |
| 379 :type '(choice (const :tag "Align with preceding" t) | |
| 380 (const :tag "Indent to column 0" nil)) | |
| 381 :group 'python) | |
| 382 | |
| 383 (defcustom python-honour-comment-indentation nil | |
| 384 "Non-nil means indent relative to preceding comment line. | |
| 385 Only do this for comments where the leading comment character is followed | |
| 386 by space." | |
| 387 :type 'boolean | |
| 388 :group 'python) | |
| 389 | |
| 390 (defcustom python-continuation-offset 4 | |
| 391 "*Number of columns of additional indentation for continuation lines. | |
| 392 Continuation lines follow a backslash-terminated line starting a statement." | |
| 393 :group 'python | |
| 394 :type 'integer) | |
| 395 | |
| 396 (defun python-guess-indent () | |
| 397 "Guess step for indentation of current buffer. | |
| 398 Set `python-indent' locally to the value guessed." | |
| 399 (interactive) | |
| 400 (save-excursion | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
401 (save-restriction |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
402 (widen) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
403 (goto-char (point-min)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
404 (let (done indent) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
405 (while (and (not done) (not (eobp))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
406 (when (and (re-search-forward (rx (and ?: (0+ space) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
407 (or (syntax comment-start) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
408 line-end))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
409 nil 'move) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
410 (python-open-block-statement-p)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
411 (save-excursion |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
412 (python-beginning-of-statement) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
413 (let ((initial (current-indentation))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
414 (if (zerop (python-next-statement)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
415 (setq indent (- (current-indentation) initial))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
416 (if (and (>= indent 2) (<= indent 8)) ; sanity check |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
417 (setq done t)))))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
418 (when done |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
419 (when (/= indent (default-value 'python-indent)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
420 (set (make-local-variable 'python-indent) indent) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
421 (unless (= tab-width python-indent) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
422 (setq indent-tabs-mode nil))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
423 indent))))) |
| 54789 | 424 |
| 425 (defun python-calculate-indentation () | |
| 426 "Calculate Python indentation for line at point." | |
| 427 (save-excursion | |
| 428 (beginning-of-line) | |
| 429 (let ((syntax (syntax-ppss)) | |
| 430 start) | |
| 431 (cond | |
| 432 ((eq 'string (syntax-ppss-context syntax)) ; multi-line string | |
| 433 (if (not python-indent-string-contents) | |
| 434 0 | |
| 435 (save-excursion | |
| 436 ;; Find indentation of preceding non-blank line within string. | |
| 437 (setq start (nth 8 syntax)) | |
| 438 (forward-line -1) | |
| 439 (while (and (< start (point)) (looking-at "\\s-*$")) | |
| 440 (forward-line -1)) | |
| 441 (current-indentation)))) | |
| 442 ((python-continuation-line-p) | |
| 443 (let ((point (point)) | |
| 444 (open-start (cadr syntax))) | |
| 445 (if open-start | |
| 446 ;; Inside bracketed expression. | |
| 447 (progn | |
| 448 (goto-char (1+ open-start)) | |
| 449 ;; Look for first item in list (preceding point) and | |
| 450 ;; align with it, if found. | |
| 451 (if (with-syntax-table python-space-backslash-table | |
| 452 (let ((parse-sexp-ignore-comments t)) | |
| 453 (condition-case () | |
| 454 (progn (forward-sexp) | |
| 455 (backward-sexp) | |
| 456 (< (point) point)) | |
| 457 (error nil)))) | |
| 458 (current-column) | |
| 459 ;; Otherwise indent relative to statement start, one | |
| 460 ;; level per bracketing level. | |
| 461 (goto-char (1+ open-start)) | |
| 462 (python-beginning-of-statement) | |
| 463 (+ (current-indentation) (* (car syntax) python-indent)))) | |
| 464 ;; Otherwise backslash-continued. | |
| 465 (forward-line -1) | |
| 466 (if (python-continuation-line-p) | |
| 467 ;; We're past first continuation line. Align with | |
| 468 ;; previous line. | |
| 469 (current-indentation) | |
| 470 ;; First continuation line. Indent one step, with an | |
| 471 ;; extra one if statement opens a block. | |
| 472 (save-excursion | |
| 473 (python-beginning-of-statement) | |
| 474 (+ (current-indentation) python-continuation-offset | |
| 475 (if (python-open-block-statement-p t) | |
| 476 python-indent | |
| 477 0))))))) | |
| 478 ((bobp) 0) | |
| 479 ;; Fixme: Like python-mode.el; not convinced by this. | |
| 480 ((looking-at (rx (and (0+ space) (syntax comment-start) | |
| 481 (not (any " \t\n"))))) ; non-indentable comment | |
| 482 (current-indentation)) | |
| 483 (t (let ((point (point))) | |
| 484 (if python-honour-comment-indentation | |
| 485 ;; Back over whitespace, newlines, non-indentable comments. | |
| 486 (catch 'done | |
| 487 (while t | |
| 488 (if (cond ((bobp)) | |
| 489 ;; not at comment start | |
| 490 ((not (forward-comment -1)) | |
| 491 (python-beginning-of-statement) | |
| 492 t) | |
| 493 ;; trailing comment | |
| 494 ((/= (current-column) (current-indentation)) | |
| 495 (python-beginning-of-statement) | |
| 496 t) | |
| 497 ;; indentable comment like python-mode.el | |
| 498 ((and (looking-at (rx (and (syntax comment-start) | |
| 499 (or space line-end)))) | |
| 500 (/= 0 (current-column))))) | |
| 501 (throw 'done t)))) | |
| 502 ;; Else back over all comments. | |
| 503 (python-skip-comments/blanks t) | |
| 504 (python-beginning-of-statement)) | |
| 505 ;; don't lose on bogus outdent | |
| 506 (max 0 (+ (current-indentation) | |
| 507 (or (cond ((python-open-block-statement-p t) | |
| 508 python-indent) | |
| 509 ((python-close-block-statement-p t) | |
| 510 (- python-indent))) | |
| 511 (progn (goto-char point) | |
| 512 (if (python-outdent-p) | |
| 513 (- python-indent))) | |
| 514 0))))))))) | |
| 515 | |
| 516 ;;;; Cycling through the possible indentations with successive TABs. | |
| 517 | |
| 518 ;; These don't need to be buffer-local since they're only relevant | |
| 519 ;; during a cycle. | |
| 520 | |
| 521 ;; Alist of possible indentations and start of statement they would close. | |
| 522 (defvar python-indent-list nil | |
| 523 "Internal use.") | |
| 524 ;; Length of the above | |
| 525 (defvar python-indent-list-length nil | |
| 526 "Internal use.") | |
| 527 ;; Current index into the alist. | |
| 528 (defvar python-indent-index nil | |
| 529 "Internal use.") | |
| 530 | |
| 531 (defun python-initial-text () | |
| 532 "Text of line following indentation and ignoring any trailing comment." | |
| 533 (buffer-substring (+ (line-beginning-position) (current-indentation)) | |
| 534 (save-excursion | |
| 535 (end-of-line) | |
| 536 (forward-comment -1) | |
| 537 (point)))) | |
| 538 | |
| 539 (defun python-indentation-levels () | |
| 540 "Return a list of possible indentations for this statement. | |
| 541 Includes the default indentation and those which would close all | |
| 542 enclosing blocks." | |
| 543 (save-excursion | |
| 544 (let ((levels (list (cons (current-indentation) nil)))) | |
| 545 ;; Only one possibility if we immediately follow a block open or | |
| 546 ;; are in a continuation line. | |
| 547 (unless (or (python-continuation-line-p) | |
| 548 (save-excursion (and (python-previous-statement) | |
| 549 (python-open-block-statement-p t)))) | |
| 550 (while (python-beginning-of-block) | |
| 551 (push (cons (current-indentation) (python-initial-text)) | |
| 552 levels))) | |
| 553 levels))) | |
| 554 | |
| 555 ;; This is basically what `python-indent-line' would be if we didn't | |
| 556 ;; do the cycling. | |
| 557 (defun python-indent-line-1 () | |
| 558 "Subroutine of `python-indent-line'." | |
| 559 (let ((target (python-calculate-indentation)) | |
| 560 (pos (- (point-max) (point)))) | |
| 561 (if (= target (current-indentation)) | |
| 562 (if (< (current-column) (current-indentation)) | |
| 563 (back-to-indentation)) | |
| 564 (beginning-of-line) | |
| 565 (delete-horizontal-space) | |
| 566 (indent-to target) | |
| 567 (if (> (- (point-max) pos) (point)) | |
| 568 (goto-char (- (point-max) pos)))))) | |
| 569 | |
| 570 ;; Fixme: Is the arg necessary? | |
| 571 (defun python-indent-line (&optional arg) | |
| 572 "Indent current line as Python code. | |
| 573 When invoked via `indent-for-tab-command', cycle through possible | |
| 574 indentations for current line. The cycle is broken by a command different | |
| 575 from `indent-for-tab-command', i.e. successive TABs do the cycling." | |
| 576 (interactive) | |
| 577 ;; Don't do extra work if invoked via `indent-region', for instance. | |
| 578 (if (not (eq this-command 'indent-for-tab-command)) | |
| 579 (python-indent-line-1) | |
| 580 (if (eq last-command this-command) | |
| 581 (if (= 1 python-indent-list-length) | |
| 582 (message "Sole indentation") | |
| 583 (progn (setq python-indent-index (% (1+ python-indent-index) | |
| 584 python-indent-list-length)) | |
| 585 (beginning-of-line) | |
| 586 (delete-horizontal-space) | |
| 587 (indent-to (car (nth python-indent-index python-indent-list))) | |
| 588 (let ((text (cdr (nth python-indent-index | |
| 589 python-indent-list)))) | |
| 590 (if text (message "Closes: %s" text))))) | |
| 591 (python-indent-line-1) | |
| 592 (setq python-indent-list (python-indentation-levels) | |
| 593 python-indent-list-length (length python-indent-list) | |
| 594 python-indent-index (1- python-indent-list-length))))) | |
| 595 | |
| 596 ;;;; Movement. | |
| 597 | |
| 598 (defun python-beginning-of-defun () | |
| 599 "`beginning-of-defun-function' for Python. | |
| 600 Finds beginning of innermost nested class or method definition. | |
| 601 Returns the name of the definition found at the end, or nil if reached | |
| 602 start of buffer." | |
| 603 (let ((ci (current-indentation)) | |
| 604 (def-re (rx (and line-start (0+ space) (or "def" "class") | |
| 605 (1+ space) | |
| 606 (group (1+ (or word (syntax symbol))))))) | |
|
54888
89ed55db7532
(python-orig-start-line, python-orig-file): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54886
diff
changeset
|
607 found lep def-line) |
| 54789 | 608 (if (python-comment-line-p) |
| 609 (setq ci most-positive-fixnum)) | |
| 610 (while (and (not (bobp)) (not found)) | |
| 611 ;; Treat bol at beginning of function as outside function so | |
| 612 ;; that successive C-M-a makes progress backwards. | |
| 613 (setq def-line (looking-at def-re)) | |
| 614 (unless (bolp) (end-of-line)) | |
| 615 (setq lep (line-end-position)) | |
| 616 (if (and (re-search-backward def-re nil 'move) | |
| 617 ;; Must be less indented or matching top level, or | |
| 618 ;; equally indented if we started on a definition line. | |
| 619 (let ((in (current-indentation))) | |
| 620 (or (and (zerop ci) (zerop in)) | |
| 621 (= lep (line-end-position)) ; on initial line | |
| 622 (and def-line (= in ci)) | |
| 623 (< in ci))) | |
| 624 (not (python-in-string/comment))) | |
| 625 (setq found t))))) | |
| 626 | |
| 627 (defun python-end-of-defun () | |
| 628 "`end-of-defun-function' for Python. | |
| 629 Finds end of innermost nested class or method definition." | |
| 630 (let ((orig (point)) | |
| 631 (pattern (rx (and line-start (0+ space) | |
| 632 (or "def" "class") space)))) | |
| 633 ;; Go to start of current block and check whether it's at top | |
| 634 ;; level. If it is, and not a block start, look forward for | |
| 635 ;; definition statement. | |
| 636 (when (python-comment-line-p) | |
| 637 (end-of-line) | |
| 638 (forward-comment most-positive-fixnum)) | |
| 639 (if (not (python-open-block-statement-p)) | |
| 640 (python-beginning-of-block)) | |
| 641 (if (zerop (current-indentation)) | |
| 642 (unless (python-open-block-statement-p) | |
| 643 (while (and (re-search-forward pattern nil 'move) | |
| 644 (python-in-string/comment))) ; just loop | |
| 645 (unless (eobp) | |
| 646 (beginning-of-line))) | |
| 647 ;; Don't move before top-level statement that would end defun. | |
| 648 (end-of-line) | |
| 649 (python-beginning-of-defun)) | |
| 650 ;; If we got to the start of buffer, look forward for | |
| 651 ;; definition statement. | |
| 652 (if (and (bobp) (not (looking-at "def\\|class"))) | |
| 653 (while (and (not (eobp)) | |
| 654 (re-search-forward pattern nil 'move) | |
| 655 (python-in-string/comment)))) ; just loop | |
| 656 ;; We're at a definition statement (or end-of-buffer). | |
| 657 (unless (eobp) | |
| 658 (python-end-of-block) | |
| 659 ;; Count trailing space in defun (but not trailing comments). | |
| 660 (skip-syntax-forward " >") | |
| 661 (beginning-of-line)) | |
| 662 ;; Catch pathological case like this, where the beginning-of-defun | |
| 663 ;; skips to a definition we're not in: | |
| 664 ;; if ...: | |
| 665 ;; ... | |
| 666 ;; else: | |
| 667 ;; ... # point here | |
| 668 ;; ... | |
| 669 ;; def ... | |
| 670 (if (< (point) orig) | |
| 671 (goto-char (point-max))))) | |
| 672 | |
| 673 (defun python-beginning-of-statement () | |
| 674 "Go to start of current statement. | |
| 675 Accounts for continuation lines, multi-line strings, and multi-line bracketed | |
| 676 expressions." | |
| 677 (beginning-of-line) | |
| 678 (python-beginning-of-string) | |
| 679 (while (python-continuation-line-p) | |
| 680 (beginning-of-line) | |
| 681 (if (python-backslash-continuation-line-p) | |
| 682 (while (python-backslash-continuation-line-p) | |
| 683 (forward-line -1)) | |
| 684 (python-beginning-of-string) | |
| 685 ;; Skip forward out of nested brackets. | |
| 686 (condition-case () ; beware invalid syntax | |
| 687 (progn (backward-up-list (syntax-ppss-depth (syntax-ppss))) t) | |
| 688 (error (end-of-line))))) | |
| 689 (back-to-indentation)) | |
| 690 | |
| 691 (defun python-end-of-statement () | |
| 692 "Go to the end of the current statement and return point. | |
| 693 Usually this is the start of the next line, but if this is a | |
| 694 multi-line statement we need to skip over the continuation lines. | |
| 695 On a comment line, go to end of line." | |
| 696 (end-of-line) | |
| 697 (while (let (comment) | |
| 698 ;; Move past any enclosing strings and sexps, or stop if | |
| 699 ;; we're in a comment. | |
| 700 (while (let ((s (syntax-ppss))) | |
| 701 (cond ((eq 'comment (syntax-ppss-context s)) | |
| 702 (setq comment t) | |
| 703 nil) | |
| 704 ((eq 'string (syntax-ppss-context s)) | |
| 705 ;; Go to start of string and skip it. | |
| 706 (goto-char (nth 8 s)) | |
| 707 (condition-case () ; beware invalid syntax | |
| 708 (progn (forward-sexp) t) | |
| 709 (error (end-of-line)))) | |
| 710 ((> (syntax-ppss-depth s) 0) | |
| 711 ;; Skip forward out of nested brackets. | |
| 712 (condition-case () ; beware invalid syntax | |
| 713 (progn (backward-up-list | |
| 714 (- (syntax-ppss-depth s))) | |
| 715 t) | |
| 716 (error (end-of-line)))))) | |
| 717 (end-of-line)) | |
| 718 (unless comment | |
| 719 (eq ?\\ (char-before)))) ; Line continued? | |
| 720 (end-of-line 2)) ; Try next line. | |
| 721 (point)) | |
| 722 | |
| 723 (defun python-previous-statement (&optional count) | |
| 724 "Go to start of previous statement. | |
| 725 With argument COUNT, do it COUNT times. Stop at beginning of buffer. | |
| 726 Return count of statements left to move." | |
| 727 (interactive "p") | |
| 728 (unless count (setq count 1)) | |
| 729 (if (< count 0) | |
| 730 (python-next-statement (- count)) | |
| 731 (python-beginning-of-statement) | |
| 732 (while (and (> count 0) (not (bobp))) | |
| 733 (python-skip-comments/blanks t) | |
| 734 (python-beginning-of-statement) | |
| 735 (unless (bobp) (setq count (1- count)))) | |
| 736 count)) | |
| 737 | |
| 738 (defun python-next-statement (&optional count) | |
| 739 "Go to start of next statement. | |
| 740 With argument COUNT, do it COUNT times. Stop at end of buffer. | |
| 741 Return count of statements left to move." | |
| 742 (interactive "p") | |
| 743 (unless count (setq count 1)) | |
| 744 (if (< count 0) | |
| 745 (python-previous-statement (- count)) | |
| 746 (beginning-of-line) | |
| 747 (while (and (> count 0) (not (eobp))) | |
| 748 (python-end-of-statement) | |
| 749 (python-skip-comments/blanks) | |
| 750 (setq count (1- count))) | |
| 751 count)) | |
| 752 | |
| 753 (defun python-beginning-of-block (&optional arg) | |
| 754 "Go to start of current block. | |
| 755 With numeric arg, do it that many times. If ARG is negative, call | |
| 756 `python-end-of-block' instead. | |
| 757 If point is on the first line of a block, use its outer block. | |
| 758 If current statement is in column zero, don't move and return nil. | |
| 759 Otherwise return non-nil." | |
| 760 (interactive "p") | |
| 761 (unless arg (setq arg 1)) | |
| 762 (cond | |
| 763 ((zerop arg)) | |
| 764 ((< arg 0) (python-end-of-block (- arg))) | |
| 765 (t | |
| 766 (let ((point (point))) | |
| 767 (if (python-comment-line-p) | |
| 768 (python-skip-comments/blanks t)) | |
| 769 (python-beginning-of-statement) | |
| 770 (let ((ci (current-indentation))) | |
| 771 (if (zerop ci) | |
| 772 (not (goto-char point)) ; return nil | |
| 773 ;; Look upwards for less indented statement. | |
| 774 (if (catch 'done | |
| 775 ;;; This is slower than the below. | |
| 776 ;;; (while (zerop (python-previous-statement)) | |
| 777 ;;; (when (and (< (current-indentation) ci) | |
| 778 ;;; (python-open-block-statement-p t)) | |
| 779 ;;; (beginning-of-line) | |
| 780 ;;; (throw 'done t))) | |
| 781 (while (and (zerop (forward-line -1))) | |
| 782 (when (and (< (current-indentation) ci) | |
| 783 (not (python-comment-line-p)) | |
| 784 ;; Move to beginning to save effort in case | |
| 785 ;; this is in string. | |
| 786 (progn (python-beginning-of-statement) t) | |
| 787 (python-open-block-statement-p t)) | |
| 788 (beginning-of-line) | |
| 789 (throw 'done t))) | |
| 790 (not (goto-char point))) ; Failed -- return nil | |
| 791 (python-beginning-of-block (1- arg))))))))) | |
| 792 | |
| 793 (defun python-end-of-block (&optional arg) | |
| 794 "Go to end of current block. | |
| 795 With numeric arg, do it that many times. If ARG is negative, call | |
| 796 `python-beginning-of-block' instead. | |
| 797 If current statement is in column zero and doesn't open a block, don't | |
| 798 move and return nil. Otherwise return t." | |
| 799 (interactive "p") | |
| 800 (unless arg (setq arg 1)) | |
| 801 (if (< arg 0) | |
| 802 (python-beginning-of-block (- arg))) | |
| 803 (while (and (> arg 0) | |
| 804 (let* ((point (point)) | |
| 805 (_ (if (python-comment-line-p) | |
| 806 (python-skip-comments/blanks t))) | |
| 807 (ci (current-indentation)) | |
| 808 (open (python-open-block-statement-p))) | |
| 809 (if (and (zerop ci) (not open)) | |
| 810 (not (goto-char point)) | |
| 811 (catch 'done | |
| 812 (while (zerop (python-next-statement)) | |
| 813 (when (or (and open (<= (current-indentation) ci)) | |
| 814 (< (current-indentation) ci)) | |
| 815 (python-skip-comments/blanks t) | |
| 816 (beginning-of-line 2) | |
| 817 (throw 'done t))) | |
| 818 (not (goto-char point)))))) | |
| 819 (setq arg (1- arg))) | |
| 820 (zerop arg)) | |
| 821 | |
| 822 ;;;; Imenu. | |
| 823 | |
|
54888
89ed55db7532
(python-orig-start-line, python-orig-file): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54886
diff
changeset
|
824 (defvar python-recursing) |
| 54789 | 825 (defun python-imenu-create-index () |
| 826 "`imenu-create-index-function' for Python. | |
| 827 | |
| 828 Makes nested Imenu menus from nested `class' and `def' statements. | |
| 829 The nested menus are headed by an item referencing the outer | |
| 830 definition; it has a space prepended to the name so that it sorts | |
|
54938
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
831 first with `imenu--sort-by-name' (though, unfortunately, sub-menus |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
832 precede it)." |
|
54888
89ed55db7532
(python-orig-start-line, python-orig-file): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54886
diff
changeset
|
833 (unless (boundp 'python-recursing) ; dynamically bound below |
| 54789 | 834 (goto-char (point-min))) ; normal call from Imenu |
| 835 (let (index-alist ; accumulated value to return | |
|
54888
89ed55db7532
(python-orig-start-line, python-orig-file): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54886
diff
changeset
|
836 name) |
| 54789 | 837 (while (re-search-forward |
| 838 (rx (and line-start (0+ space) ; leading space | |
| 839 (or (group "def") (group "class")) ; type | |
| 840 (1+ space) (group (1+ (or word ?_))))) ; name | |
| 841 nil t) | |
| 842 (unless (python-in-string/comment) | |
| 843 (let ((pos (match-beginning 0)) | |
| 844 (name (match-string-no-properties 3))) | |
| 845 (if (match-beginning 2) ; def or class? | |
| 846 (setq name (concat "class " name))) | |
| 847 (save-restriction | |
| 848 (narrow-to-defun) | |
|
54888
89ed55db7532
(python-orig-start-line, python-orig-file): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54886
diff
changeset
|
849 (let* ((python-recursing t) |
| 54789 | 850 (sublist (python-imenu-create-index))) |
| 851 (if sublist | |
| 852 (progn (push (cons (concat " " name) pos) sublist) | |
| 853 (push (cons name sublist) index-alist)) | |
| 854 (push (cons name pos) index-alist))))))) | |
| 855 (nreverse index-alist))) | |
| 856 | |
| 857 ;;;; `Electric' commands. | |
| 858 | |
| 859 (defun python-electric-colon (arg) | |
| 860 "Insert a colon and maybe outdent the line if it is a statement like `else'. | |
| 861 With numeric ARG, just insert that many colons. With \\[universal-argument], | |
| 862 just insert a single colon." | |
| 863 (interactive "*P") | |
| 864 (self-insert-command (if (not (integerp arg)) 1 arg)) | |
| 865 (and (not arg) | |
| 866 (eolp) | |
| 867 (python-outdent-p) | |
| 868 (not (python-in-string/comment)) | |
| 869 (> (current-indentation) (python-calculate-indentation)) | |
| 870 (python-indent-line))) ; OK, do it | |
| 871 (put 'python-electric-colon 'delete-selection t) | |
| 872 | |
| 873 (defun python-backspace (arg) | |
| 874 "Maybe delete a level of indentation on the current line. | |
| 875 If not at the end of line's indentation, or on a comment line, just call | |
| 876 `backward-delete-char-untabify'. With ARG, repeat that many times." | |
| 877 (interactive "*p") | |
| 878 (if (or (/= (current-indentation) (current-column)) | |
| 879 (bolp) | |
| 880 (python-continuation-line-p)) | |
| 881 (backward-delete-char-untabify arg) | |
| 882 (let ((indent 0)) | |
| 883 (save-excursion | |
| 884 (while (and (> arg 0) (python-beginning-of-block)) | |
| 885 (setq arg (1- arg))) | |
| 886 (when (zerop arg) | |
| 887 (setq indent (current-indentation)) | |
| 888 (message "Closes %s" (python-initial-text)))) | |
| 889 (delete-horizontal-space) | |
| 890 (indent-to indent)))) | |
| 891 (put 'python-backspace 'delete-selection 'supersede) | |
| 892 | |
| 893 ;;;; pychecker | |
| 894 | |
| 895 (defcustom python-check-command "pychecker --stdlib" | |
| 896 "*Command used to check a Python file." | |
| 897 :type 'string | |
| 898 :group 'python) | |
| 899 | |
| 900 (defvar python-saved-check-command nil | |
| 901 "Internal use.") | |
| 902 | |
| 903 ;; After `sgml-validate-command'. | |
| 904 (defun python-check (command) | |
| 905 "Check a Python file (default current buffer's file). | |
| 906 Runs COMMAND, a shell command, as if by `compile'. | |
| 907 See `python-check-command' for the default." | |
| 908 (interactive | |
| 909 (list (read-string "Checker command: " | |
| 910 (or python-saved-check-command | |
| 911 (concat python-check-command " " | |
| 912 (let ((name (buffer-file-name))) | |
| 913 (if name | |
| 914 (file-name-nondirectory name)))))))) | |
| 915 (setq python-saved-check-command command) | |
| 916 (save-some-buffers (not compilation-ask-about-save) nil) | |
| 917 (compilation-start command)) | |
| 918 | |
| 919 ;;;; Inferior mode stuff (following cmuscheme). | |
| 920 | |
| 921 (defcustom python-python-command "python" | |
| 922 "*Shell command to run Python interpreter. | |
| 923 Any arguments can't contain whitespace." | |
| 924 :group 'python | |
| 925 :type 'string) | |
| 926 | |
| 927 (defcustom python-jython-command "jython" | |
| 928 "*Shell command to run Jython interpreter. | |
| 929 Any arguments can't contain whitespace." | |
| 930 :group 'python | |
| 931 :type 'string) | |
| 932 | |
| 933 (defvar python-command python-python-command | |
| 934 "Actual command used to run Python. | |
| 935 May be `python-python-command' or `python-jython-command'. | |
| 936 Additional arguments are added when the command is used by `run-python' | |
| 937 et al.") | |
| 938 | |
| 939 (defvar python-buffer nil | |
|
54938
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
940 "The current python process buffer." |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
941 ;; Fixme: a single process is currently assumed, so that this doc |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
942 ;; is misleading. |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
943 |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
944 ;; "*The current python process buffer. |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
945 ;; To run multiple Python processes, start the first with \\[run-python]. |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
946 ;; It will be in a buffer named *Python*. Rename that with |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
947 ;; \\[rename-buffer]. Now start a new process with \\[run-python]. It |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
948 ;; will be in a new buffer, named *Python*. Switch between the different |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
949 ;; process buffers with \\[switch-to-buffer]. |
| 54789 | 950 |
|
54938
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
951 ;; Commands that send text from source buffers to Python processes have |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
952 ;; to choose a process to send to. This is determined by global variable |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
953 ;; `python-buffer'. Suppose you have three inferior Pythons running: |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
954 ;; Buffer Process |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
955 ;; foo python |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
956 ;; bar python<2> |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
957 ;; *Python* python<3> |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
958 ;; If you do a \\[python-send-region-and-go] command on some Python source |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
959 ;; code, what process does it go to? |
| 54789 | 960 |
|
54938
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
961 ;; - In a process buffer (foo, bar, or *Python*), send it to that process. |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
962 ;; - In some other buffer (e.g. a source file), send it to the process |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
963 ;; attached to `python-buffer'. |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
964 ;; Process selection is done by function `python-proc'. |
| 54789 | 965 |
|
54938
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
966 ;; Whenever \\[run-python] starts a new process, it resets `python-buffer' |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
967 ;; to be the new process's buffer. If you only run one process, this will |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
968 ;; do the right thing. If you run multiple processes, you can change |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
969 ;; `python-buffer' to another process buffer with \\[set-variable]." |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
970 ) |
| 54789 | 971 |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
972 (defconst python-compilation-regexp-alist |
|
55300
2db456741f80
(python-compilation-line-number): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55240
diff
changeset
|
973 ;; FIXME: maybe this should be moved to compilation-error-regexp-alist-alist. |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
974 `((,(rx (and line-start (1+ (any " \t")) "File \"" |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
975 (group (1+ (not (any "\"<")))) ; avoid `<stdin>' &c |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
976 "\", line " (group (1+ digit)))) |
|
55300
2db456741f80
(python-compilation-line-number): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55240
diff
changeset
|
977 1 2)) |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
978 "`compilation-error-regexp-alist' for inferior Python.") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
979 |
|
54938
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
980 ;; Fixme: This should inherit some stuff from python-mode, but I'm not |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
981 ;; sure how much: at least some keybindings, like C-c C-f; syntax?; |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
982 ;; font-locking, e.g. for triple-quoted strings? |
| 54789 | 983 (define-derived-mode inferior-python-mode comint-mode "Inferior Python" |
| 984 "Major mode for interacting with an inferior Python process. | |
| 985 A Python process can be started with \\[run-python]. | |
| 986 | |
| 987 Hooks `comint-mode-hook' and `inferior-python-mode-hook' are run in | |
| 988 that order. | |
| 989 | |
| 990 You can send text to the inferior Python process from other buffers containing | |
| 991 Python source. | |
| 992 * `python-switch-to-python' switches the current buffer to the Python | |
| 993 process buffer. | |
| 994 * `python-send-region' sends the current region to the Python process. | |
| 995 * `python-send-region-and-go' switches to the Python process buffer | |
| 996 after sending the text. | |
| 997 For running multiple processes in multiple buffers, see `python-buffer'. | |
| 998 | |
| 999 \\{inferior-python-mode-map}" | |
| 1000 :group 'python | |
| 1001 (set-syntax-table python-mode-syntax-table) | |
| 1002 (setq mode-line-process '(":%s")) | |
| 1003 ;; Fixme: Maybe install some python-mode bindings too. | |
| 1004 (define-key inferior-python-mode-map "\C-c\C-l" 'python-load-file) | |
| 1005 (define-key inferior-python-mode-map "\C-c\C-z" 'python-switch-to-python) | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1006 (add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1007 nil t) |
|
54938
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
1008 ;; Still required by `comint-redirect-send-command', for instance |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
1009 ;; (and we need to match things like `>>> ... >>> '): |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1010 (set (make-local-variable 'comint-prompt-regexp) "^\\([>.]\\{3\\} \\)+") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1011 (set (make-local-variable 'compilation-error-regexp-alist) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1012 python-compilation-regexp-alist) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1013 (compilation-shell-minor-mode 1)) |
| 54789 | 1014 |
| 1015 (defcustom inferior-python-filter-regexp "\\`\\s-*\\S-?\\S-?\\s-*\\'" | |
| 1016 "*Input matching this regexp is not saved on the history list. | |
| 1017 Default ignores all inputs of 0, 1, or 2 non-blank characters." | |
| 1018 :type 'regexp | |
| 1019 :group 'python) | |
| 1020 | |
| 1021 ;; Fixme: Loses with quoted whitespace. | |
| 1022 (defun python-args-to-list (string) | |
| 1023 (let ((where (string-match "[ \t]" string))) | |
| 1024 (cond ((null where) (list string)) | |
| 1025 ((not (= where 0)) | |
| 1026 (cons (substring string 0 where) | |
| 1027 (python-args-to-list (substring string (+ 1 where))))) | |
| 1028 (t (let ((pos (string-match "[^ \t]" string))) | |
| 1029 (if pos (python-args-to-list (substring string pos)))))))) | |
| 1030 | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1031 (defvar python-preoutput-result nil |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1032 "Data from output line last `_emacs_out' line seen by the preoutput filter.") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1033 |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1034 (defvar python-preoutput-continuation nil |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1035 "If non-nil, funcall this when `python-preoutput-filter' sees `_emacs_ok'.") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1036 |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1037 ;; Using this stops us getting lines in the buffer like |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1038 ;; >>> ... ... >>> |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1039 ;; Also look for (and delete) an `_emacs_ok' string and call |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1040 ;; `python-preoutput-continuation' if we get it. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1041 (defun python-preoutput-filter (s) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1042 "`comint-preoutput-filter-functions' function: ignore prompts not at bol." |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1043 (cond ((and (string-match "\\`[.>]\\{3\\} \\'" s) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1044 (/= (let ((inhibit-field-text-motion t)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1045 (line-beginning-position)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1046 (point))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1047 "") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1048 ((string= s "_emacs_ok\n") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1049 (when python-preoutput-continuation |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1050 (funcall python-preoutput-continuation) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1051 (setq python-preoutput-continuation nil)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1052 "") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1053 ((string-match "_emacs_out \\(.*\\)\n" s) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1054 (setq python-preoutput-result (match-string 1 s)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1055 "") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1056 (t s))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1057 |
| 54789 | 1058 ;;;###autoload |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1059 (defun run-python (&optional cmd noshow) |
| 54789 | 1060 "Run an inferior Python process, input and output via buffer *Python*. |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1061 CMD is the Python command to run. NOSHOW non-nil means don't show the |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1062 buffer automatically. |
| 54789 | 1063 If there is a process already running in `*Python*', switch to |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1064 that buffer. Interactively a prefix arg, allows you to edit the initial |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1065 command line (default is the value of `python-command'); `-i' etc. args |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1066 will be added to this as appropriate. Runs the hooks |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1067 `inferior-python-mode-hook' (after the `comint-mode-hook' is run). |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1068 \(Type \\[describe-mode] in the process buffer for a list of commands.)" |
| 54789 | 1069 (interactive (list (if current-prefix-arg |
| 1070 (read-string "Run Python: " python-command) | |
| 1071 python-command))) | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1072 (unless cmd (setq cmd python-python-command)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1073 (setq python-command cmd) |
| 54789 | 1074 ;; Fixme: Consider making `python-buffer' buffer-local as a buffer |
| 1075 ;; (not a name) in Python buffers from which `run-python' &c is | |
| 1076 ;; invoked. Would support multiple processes better. | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1077 (unless (comint-check-proc "*Python*") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1078 (let ((cmdlist (append (python-args-to-list cmd) '("-i")))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1079 (set-buffer (apply 'make-comint "Python" (car cmdlist) nil |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1080 (cdr cmdlist)))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1081 (inferior-python-mode) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1082 ;; Load function defintions we need. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1083 ;; Before the preoutput function was used, this was done via -c in |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1084 ;; cmdlist, but that loses the banner and doesn't run the startup |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1085 ;; file. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1086 (python-send-string "\ |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1087 def _emacs_execfile (file): # execute file and remove it |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1088 from os import remove |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1089 try: execfile (file, globals (), globals ()) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1090 finally: remove (file) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1091 |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1092 def _emacs_args (name): # get arglist of name for eldoc &c |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1093 import inspect |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1094 parts = name.split ('.') |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1095 if len (parts) > 1: |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1096 try: exec 'import ' + parts[0] |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1097 except: return None |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1098 try: exec 'func='+name # lose if name is keyword or undefined |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1099 except: return None |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1100 if inspect.isbuiltin (func): |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1101 doc = func.__doc__ |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1102 if doc.find (' ->') != -1: |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1103 print '_emacs_out', doc.split (' ->')[0] |
|
54886
476bf87a815c
(run-python): Fix use of \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54881
diff
changeset
|
1104 elif doc.find ('\\n') != -1: |
|
476bf87a815c
(run-python): Fix use of \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54881
diff
changeset
|
1105 print '_emacs_out', doc.split ('\\n')[0] |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1106 return None |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1107 if inspect.ismethod (func): func = func.im_func |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1108 if not inspect.isfunction (func): |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1109 return None |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1110 (args, varargs, varkw, defaults) = inspect.getargspec (func) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1111 print '_emacs_out', func.__name__+inspect.formatargspec (args, varargs, varkw, defaults) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1112 |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1113 print '_emacs_ok'")) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1114 (unless noshow (pop-to-buffer (setq python-buffer "*Python*")))) |
| 54789 | 1115 |
|
55240
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1116 (defun python-send-command (command) |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1117 "Like `python-send-string' but resets `compilation-minor-mode'." |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1118 (let ((end (marker-position (process-mark (python-proc))))) |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1119 (compilation-forget-errors) |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1120 (python-send-string command) |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1121 (set-marker compilation-parsing-end end) |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1122 (setq compilation-last-buffer (current-buffer)))) |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1123 |
| 54789 | 1124 (defun python-send-region (start end) |
| 1125 "Send the region to the inferior Python process." | |
| 1126 ;; The region is evaluated from a temporary file. This avoids | |
| 1127 ;; problems with blank lines, which have different semantics | |
| 1128 ;; interactively and in files. It also saves the inferior process | |
| 1129 ;; buffer filling up with interpreter prompts. We need a function | |
| 1130 ;; to remove the temporary file when it has been evaluated, which | |
| 1131 ;; unfortunately means using a not-quite pristine interpreter | |
| 1132 ;; initially. Unfortunately we also get tracebacks which look like: | |
| 1133 ;; | |
| 1134 ;; >>> Traceback (most recent call last): | |
| 1135 ;; File "<stdin>", line 1, in ? | |
| 1136 ;; File "<string>", line 4, in _emacs_execfile | |
| 1137 ;; File "/tmp/py7734RSB", line 11 | |
| 1138 ;; | |
| 1139 ;; The compilation-minor-mode parsing takes care of relating the | |
| 1140 ;; reference to the temporary file to the source. Fixme: | |
| 1141 ;; comint-filter the first two lines of the traceback? | |
| 1142 (interactive "r") | |
| 1143 (let* ((f (make-temp-file "py")) | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1144 (command (format "_emacs_execfile(%S)" f)) |
|
54888
89ed55db7532
(python-orig-start-line, python-orig-file): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54886
diff
changeset
|
1145 (orig-start (copy-marker start))) |
| 54789 | 1146 (if (save-excursion |
| 1147 (goto-char start) | |
| 1148 (/= 0 (current-indentation))) ; need dummy block | |
| 1149 (write-region "if True:\n" nil f nil 'nomsg)) | |
| 1150 (write-region start end f t 'nomsg) | |
| 1151 (when python-buffer | |
| 1152 (with-current-buffer python-buffer | |
|
55300
2db456741f80
(python-compilation-line-number): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55240
diff
changeset
|
1153 (python-send-command command) |
|
2db456741f80
(python-compilation-line-number): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55240
diff
changeset
|
1154 ;; Tell compile.el to redirect error locations in file `f' to |
|
2db456741f80
(python-compilation-line-number): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55240
diff
changeset
|
1155 ;; positions past marker `orig-start'. It has to be done *after* |
|
2db456741f80
(python-compilation-line-number): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55240
diff
changeset
|
1156 ;; python-send-command's call to compilation-forget-errors. |
|
2db456741f80
(python-compilation-line-number): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55240
diff
changeset
|
1157 (compilation-fake-loc orig-start f))))) |
| 54789 | 1158 |
| 1159 (defun python-send-string (string) | |
| 1160 "Evaluate STRING in inferior Python process." | |
| 1161 (interactive "sPython command: ") | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1162 (comint-send-string (python-proc) string) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1163 (comint-send-string (python-proc) "\n\n")) |
| 54789 | 1164 |
| 1165 (defun python-send-buffer () | |
| 1166 "Send the current buffer to the inferior Python process." | |
| 1167 (interactive) | |
| 1168 (python-send-region (point-min) (point-max))) | |
| 1169 | |
| 1170 (defun python-send-defun () | |
| 1171 "Send the current defun (class or method) to the inferior Python process." | |
| 1172 (interactive) | |
| 1173 (save-excursion (python-send-region (progn (beginning-of-defun) (point)) | |
| 1174 (progn (end-of-defun) (point))))) | |
| 1175 | |
| 1176 (defun python-switch-to-python (eob-p) | |
| 1177 "Switch to the Python process buffer. | |
| 1178 With prefix arg, position cursor at end of buffer." | |
| 1179 (interactive "P") | |
| 1180 (if (get-buffer python-buffer) | |
| 1181 (pop-to-buffer python-buffer) | |
| 1182 (error "No current process buffer. See variable `python-buffer'")) | |
| 1183 (when eob-p | |
| 1184 (push-mark) | |
| 1185 (goto-char (point-max)))) | |
| 1186 | |
| 1187 (add-to-list 'debug-ignored-errors "^No current process buffer.") | |
| 1188 | |
| 1189 (defun python-send-region-and-go (start end) | |
| 1190 "Send the region to the inferior Python process. | |
| 1191 Then switch to the process buffer." | |
| 1192 (interactive "r") | |
| 1193 (python-send-region start end) | |
| 1194 (python-switch-to-python t)) | |
| 1195 | |
| 1196 (defcustom python-source-modes '(python-mode jython-mode) | |
| 1197 "*Used to determine if a buffer contains Python source code. | |
| 1198 If it's loaded into a buffer that is in one of these major modes, it's | |
| 1199 considered a Python source file by `python-load-file'. | |
| 1200 Used by these commands to determine defaults." | |
| 1201 :type '(repeat function) | |
| 1202 :group 'python) | |
| 1203 | |
| 1204 (defvar python-prev-dir/file nil | |
| 1205 "Caches (directory . file) pair used in the last `python-load-file' command. | |
| 1206 Used for determining the default in the next one.") | |
| 1207 | |
| 1208 (defun python-load-file (file-name) | |
| 1209 "Load a Python file FILE-NAME into the inferior Python process. | |
| 1210 If the file has extension `.py' import or reload it as a module. | |
| 1211 Treating it as a module keeps the global namespace clean, provides | |
| 1212 function location information for debugging, and supports users of | |
| 1213 module-qualified names." | |
| 1214 (interactive (comint-get-source "Load Python file: " python-prev-dir/file | |
| 1215 python-source-modes | |
| 1216 t)) ; because execfile needs exact name | |
| 1217 (comint-check-source file-name) ; Check to see if buffer needs saved. | |
| 1218 (setq python-prev-dir/file (cons (file-name-directory file-name) | |
| 1219 (file-name-nondirectory file-name))) | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1220 (when python-buffer |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1221 (with-current-buffer python-buffer |
|
55240
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1222 ;; Fixme: I'm not convinced by this logic from python-mode.el. |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1223 (python-send-command |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1224 (if (string-match "\\.py\\'" file-name) |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1225 ;; Fixme: make sure the directory is in the path list |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1226 (let ((module (file-name-sans-extension |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1227 (file-name-nondirectory file-name)))) |
|
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1228 (format "\ |
|
54886
476bf87a815c
(run-python): Fix use of \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54881
diff
changeset
|
1229 if globals().has_key(%S): reload(%s) |
|
476bf87a815c
(run-python): Fix use of \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54881
diff
changeset
|
1230 else: import %s |
| 54789 | 1231 " module module module)) |
|
55240
780b94f913fe
(python-send-command): New fun.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
55054
diff
changeset
|
1232 (format "execfile('%s')" file-name)))))) |
| 54789 | 1233 |
| 1234 ;; Fixme: Should this start a process if there isn't one? (Unlike cmuscheme.) | |
| 1235 (defun python-proc () | |
| 1236 "Return the current Python process. See variable `python-buffer'." | |
| 1237 (let ((proc (get-buffer-process (if (eq major-mode 'inferior-python-mode) | |
| 1238 (current-buffer) | |
| 1239 python-buffer)))) | |
| 1240 (or proc (error "No current process. See variable `python-buffer'")))) | |
| 1241 | |
| 1242 ;;;; Context-sensitive help. | |
| 1243 | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1244 (defconst python-dotty-syntax-table |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1245 (let ((table (make-syntax-table))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1246 (set-char-table-parent table python-mode-syntax-table) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1247 (modify-syntax-entry ?. "_" table) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1248 table) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1249 "Syntax table giving `.' symbol syntax. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1250 Otherwise inherits from `python-mode-syntax-table'.") |
| 54789 | 1251 |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1252 ;; Fixme: Should this actually be used instead of info-look, i.e. be |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1253 ;; bound to C-h S? |
| 54789 | 1254 (defun python-describe-symbol (symbol) |
| 1255 "Get help on SYMBOL using `pydoc'. | |
| 1256 Interactively, prompt for symbol." | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1257 ;; Note that we do this in the inferior process, not a separate one to |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1258 ;; ensure the environment is appropriate. |
| 54789 | 1259 (interactive |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1260 (let ((symbol (with-syntax-table python-dotty-syntax-table |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1261 (current-word))) |
| 54789 | 1262 (enable-recursive-minibuffers t) |
| 1263 val) | |
| 1264 (setq val (read-string (if symbol | |
|
54886
476bf87a815c
(run-python): Fix use of \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54881
diff
changeset
|
1265 (format "Describe symbol (default %s): " |
| 54789 | 1266 symbol) |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1267 "Describe symbol: ") |
| 54789 | 1268 nil nil symbol)) |
| 1269 (list (or val symbol)))) | |
| 1270 (if (equal symbol "") (error "No symbol")) | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1271 (let* ((func `(lambda () |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1272 (comint-redirect-send-command (format "help(%S)\n" ,symbol) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1273 "*Help*" nil)))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1274 ;; Ensure we have a suitable help buffer. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1275 (let (temp-buffer-show-hook) ; avoid xref stuff |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1276 (with-output-to-temp-buffer "*Help*" |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1277 (with-current-buffer standard-output |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1278 (set (make-local-variable 'comint-redirect-subvert-readonly) t)))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1279 (if (and python-buffer (get-buffer python-buffer)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1280 (with-current-buffer python-buffer |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1281 (funcall func)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1282 (setq python-preoutput-continuation func) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1283 (run-python nil t)))) |
| 54789 | 1284 |
| 1285 (add-to-list 'debug-ignored-errors "^No symbol") | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1286 |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1287 ;; Fixme: try to make it work with point in the arglist. Also, is |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1288 ;; there anything reasonable we can do with random methods? |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1289 ;; (Currently only works with functions.) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1290 (defun python-eldoc-function () |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1291 "`eldoc-print-current-symbol-info' for Python. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1292 Only works when point is in a function name, not its arglist, for instance. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1293 Assumes an inferior Python is running." |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1294 (let ((symbol (with-syntax-table python-dotty-syntax-table |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1295 (current-word))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1296 (proc (and python-buffer (python-proc)))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1297 (when (and proc symbol) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1298 (python-send-string |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1299 (format "_emacs_args(%S)" symbol)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1300 (setq python-preoutput-result nil) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1301 (accept-process-output proc 1) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1302 python-preoutput-result))) |
| 54789 | 1303 |
| 1304 ;;;; Info-look functionality. | |
| 1305 | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1306 (defun python-after-info-look () |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1307 "Set up info-look for Python. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1308 Used with `eval-after-load'." |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1309 (let* ((version (let ((s (shell-command-to-string (concat python-command |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1310 " -V")))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1311 (string-match "^Python \\([0-9]+\\.[0-9]+\\>\\)" s) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1312 (match-string 1 s))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1313 ;; Whether info files have a Python version suffix, e.g. in Debian. |
|
54938
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
1314 (versioned |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1315 (with-temp-buffer |
|
54938
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
1316 (with-no-warnings (Info-mode)) |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1317 (condition-case () |
|
54888
89ed55db7532
(python-orig-start-line, python-orig-file): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54886
diff
changeset
|
1318 ;; Don't use `info' because it would pop-up a *info* buffer. |
|
54938
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
1319 (with-no-warnings |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
1320 (Info-goto-node (format "(python%s-lib)Miscellaneous Index" |
|
109b2bf180dd
(python-after-info-look): Use with-no-warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54888
diff
changeset
|
1321 version))) |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1322 (error nil))))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1323 (info-lookup-maybe-add-help |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1324 :mode 'python-mode |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1325 :regexp "[[:alnum:]_]+" |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1326 :doc-spec |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1327 ;; Fixme: Can this reasonably be made specific to indices with |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1328 ;; different rules? Is the order of indices optimal? |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1329 ;; (Miscellaneous in -ref first prefers lookup of keywords, for |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1330 ;; instance.) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1331 (if versioned |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1332 ;; The empty prefix just gets us highlighted terms. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1333 `((,(concat "(python" version "-ref)Miscellaneous Index") nil "") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1334 (,(concat "(python" version "-ref)Module Index" nil "")) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1335 (,(concat "(python" version "-ref)Function-Method-Variable Index" |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1336 nil "")) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1337 (,(concat "(python" version "-ref)Class-Exception-Object Index" |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1338 nil "")) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1339 (,(concat "(python" version "-lib)Module Index" nil "")) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1340 (,(concat "(python" version "-lib)Class-Exception-Object Index" |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1341 nil "")) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1342 (,(concat "(python" version "-lib)Function-Method-Variable Index" |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1343 nil "")) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1344 (,(concat "(python" version "-lib)Miscellaneous Index" nil ""))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1345 '(("(python-ref)Miscellaneous Index" nil "") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1346 ("(python-ref)Module Index" nil "") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1347 ("(python-ref)Function-Method-Variable Index" nil "") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1348 ("(python-ref)Class-Exception-Object Index" nil "") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1349 ("(python-lib)Module Index" nil "") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1350 ("(python-lib)Class-Exception-Object Index" nil "") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1351 ("(python-lib)Function-Method-Variable Index" nil "") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1352 ("(python-lib)Miscellaneous Index" nil "")))))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1353 (eval-after-load "info-look" '(python-after-info-look)) |
| 54789 | 1354 |
| 1355 ;;;; Miscellancy. | |
| 1356 | |
| 1357 (defcustom python-jython-packages '("java" "javax" "org" "com") | |
| 1358 "Packages implying `jython-mode'. | |
| 1359 If these are imported near the beginning of the buffer, `python-mode' | |
| 1360 actually punts to `jython-mode'." | |
| 1361 :type '(repeat string) | |
| 1362 :group 'python) | |
| 1363 | |
| 1364 ;; Called from `python-mode', this causes a recursive call of the | |
| 1365 ;; mode. See logic there to break out of the recursion. | |
| 1366 (defun python-maybe-jython () | |
| 1367 "Invoke `jython-mode' if the buffer appears to contain Jython code. | |
| 1368 The criterion is either a match for `jython-mode' via | |
| 1369 `interpreter-mode-alist' or an import of a module from the list | |
| 1370 `python-jython-packages'." | |
| 1371 ;; The logic is taken from python-mode.el. | |
| 1372 (save-excursion | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1373 (save-restriction |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1374 (widen) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1375 (goto-char (point-min)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1376 (let ((interpreter (if (looking-at auto-mode-interpreter-regexp) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1377 (match-string 2)))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1378 (if (and interpreter (eq 'jython-mode |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1379 (cdr (assoc (file-name-nondirectory |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1380 interpreter) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1381 interpreter-mode-alist)))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1382 (jython-mode) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1383 (if (catch 'done |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1384 (while (re-search-forward |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1385 (rx (and line-start (or "import" "from") (1+ space) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1386 (group (1+ (not (any " \t\n.")))))) |
|
55054
ee7e5daa7ffd
(python-maybe-jython): Don't assume point-min==1.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54943
diff
changeset
|
1387 (+ (point-min) 10000) ; Probably not worth customizing. |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1388 t) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1389 (if (member (match-string 1) python-jython-packages) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1390 (throw 'done t)))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1391 (jython-mode))))))) |
| 54789 | 1392 |
| 1393 (defun python-fill-paragraph (&optional justify) | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1394 "`fill-paragraph-function' handling comments and multi-line strings. |
| 54789 | 1395 If any of the current line is a comment, fill the comment or the |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1396 paragraph of it that point is in, preserving the comment's |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1397 indentation and initial comment characters. Similarly if the end |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1398 of the current line is in or at the end of a multi-line string. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1399 Otherwise, do nothing." |
| 54789 | 1400 (interactive "P") |
| 1401 (or (fill-comment-paragraph justify) | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1402 ;; The `paragraph-start' and `paragraph-separate' variables |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1403 ;; don't allow us to delimit the last paragraph in a multi-line |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1404 ;; string properly, so narrow to the string and then fill around |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1405 ;; (the end of) the current line. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1406 (save-excursion |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1407 (end-of-line) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1408 (let* ((syntax (syntax-ppss)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1409 (orig (point)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1410 (start (nth 8 syntax)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1411 end) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1412 (cond ((eq t (nth 3 syntax)) ; in fenced string |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1413 (goto-char (nth 8 syntax)) ; string start |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1414 (condition-case () ; for unbalanced quotes |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1415 (progn (forward-sexp) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1416 (setq end (point))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1417 (error (setq end (point-max))))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1418 ((re-search-backward "\\s|\\s-*\\=" nil t) ; end of fenced |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1419 ; string |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1420 (forward-char) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1421 (setq end (point)) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1422 (condition-case () |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1423 (progn (backward-sexp) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1424 (setq start (point))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1425 (error nil)))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1426 (when end |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1427 (save-restriction |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1428 (narrow-to-region start end) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1429 (goto-char orig) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1430 (fill-paragraph justify)))))) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1431 t) |
| 54789 | 1432 |
| 1433 (defun python-shift-left (start end &optional count) | |
| 1434 "Shift lines in region COUNT (the prefix arg) columns to the left. | |
| 1435 COUNT defaults to `python-indent'. If region isn't active, just shift | |
| 1436 current line. The region shifted includes the lines in which START and | |
| 1437 END lie. It is an error if any lines in the region are indented less than | |
| 1438 COUNT columns." | |
| 1439 (interactive (if mark-active | |
| 1440 (list (region-beginning) (region-end) current-prefix-arg) | |
| 1441 (list (point) (point) current-prefix-arg))) | |
| 1442 (if count | |
| 1443 (setq count (prefix-numeric-value count)) | |
| 1444 (setq count python-indent)) | |
| 1445 (when (> count 0) | |
| 1446 (save-excursion | |
| 1447 (goto-char start) | |
| 1448 (while (< (point) end) | |
| 1449 (if (and (< (current-indentation) count) | |
| 1450 (not (looking-at "[ \t]*$"))) | |
| 1451 (error "Can't shift all lines enough")) | |
| 1452 (forward-line)) | |
| 1453 (indent-rigidly start end (- count))))) | |
| 1454 | |
| 1455 (add-to-list 'debug-ignored-errors "^Can't shift all lines enough") | |
| 1456 | |
| 1457 (defun python-shift-right (start end &optional count) | |
| 1458 "Shift lines in region COUNT (the prefix arg) columns to the right. | |
| 1459 COUNT defaults to `python-indent'. If region isn't active, just shift | |
| 1460 current line. The region shifted includes the lines in which START and | |
| 1461 END lie." | |
| 1462 (interactive (if mark-active | |
| 1463 (list (region-beginning) (region-end) current-prefix-arg) | |
| 1464 (list (point) (point) current-prefix-arg))) | |
| 1465 (if count | |
| 1466 (setq count (prefix-numeric-value count)) | |
| 1467 (setq count python-indent)) | |
| 1468 (indent-rigidly start end count)) | |
| 1469 | |
| 1470 (defun python-outline-level () | |
| 1471 "`outline-level' function for Python mode. | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1472 The level is the number of `python-indent' steps of indentation |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1473 of current line." |
| 54789 | 1474 (/ (current-indentation) python-indent)) |
| 1475 | |
| 1476 ;; Fixme: Consider top-level assignments, imports, &c. | |
| 1477 (defun python-current-defun () | |
| 1478 "`add-log-current-defun-function' for Python." | |
| 1479 (save-excursion | |
| 1480 ;; Move up the tree of nested `class' and `def' blocks until we | |
| 1481 ;; get to zero indentation, accumulating the defined names. | |
| 1482 (let ((start t) | |
| 1483 accum) | |
| 1484 (while (or start (> (current-indentation) 0)) | |
| 1485 (setq start nil) | |
| 1486 (python-beginning-of-block) | |
| 1487 (end-of-line) | |
| 1488 (beginning-of-defun) | |
| 1489 (if (looking-at (rx (and (0+ space) (or "def" "class") (1+ space) | |
| 1490 (group (1+ (or word (syntax symbol)))) | |
| 1491 word-end))) | |
| 1492 (push (match-string 1) accum))) | |
| 1493 (if accum (mapconcat 'identity accum "."))))) | |
| 1494 | |
| 1495 (defun python-mark-block () | |
| 1496 "Mark the block around point. | |
| 1497 Uses `python-beginning-of-block', `python-end-of-block'." | |
| 1498 (interactive) | |
| 1499 (push-mark) | |
| 1500 (python-beginning-of-block) | |
| 1501 (push-mark (point) nil t) | |
| 1502 (python-end-of-block) | |
| 1503 (exchange-point-and-mark)) | |
| 1504 | |
| 1505 ;;;; Modes. | |
| 1506 | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1507 (defvar outline-heading-end-regexp) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1508 (defvar eldoc-print-current-symbol-info-function) |
|
54888
89ed55db7532
(python-orig-start-line, python-orig-file): Remove.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54886
diff
changeset
|
1509 (defvar python-mode-running) |
| 54789 | 1510 ;;;###autoload |
| 1511 (define-derived-mode python-mode fundamental-mode "Python" | |
| 1512 "Major mode for editing Python files. | |
| 1513 Turns on Font Lock mode unconditionally since it is required for correct | |
| 1514 parsing of the source. | |
| 1515 See also `jython-mode', which is actually invoked if the buffer appears to | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1516 contain Jython code. See also `run-python' and associated Python mode |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1517 commands for running Python under Emacs. |
| 54789 | 1518 |
| 1519 The Emacs commands which work with `defun's, e.g. \\[beginning-of-defun], deal | |
| 1520 with nested `def' and `class' blocks. They take the innermost one as | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1521 current without distinguishing method and class definitions. Used multiple |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1522 times, they move over others at the same indentation level until they reach |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1523 the end of definitions at that level, when they move up a level. |
| 54789 | 1524 \\<python-mode-map> |
| 1525 Colon is electric: it outdents the line if appropriate, e.g. for | |
| 1526 an else statement. \\[python-backspace] at the beginning of an indented statement | |
| 1527 deletes a level of indentation to close the current block; otherwise it | |
| 1528 deletes a charcter backward. TAB indents the current line relative to | |
| 1529 the preceding code. Successive TABs, with no intervening command, cycle | |
| 1530 through the possibilities for indentation on the basis of enclosing blocks. | |
| 1531 | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1532 \\[fill-paragraph] fills comments and multiline strings appropriately, but has no |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1533 effect outside them. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1534 |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1535 Supports Eldoc mode (only for functions, using a Python process), |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1536 Info-Look and Imenu. In Outline minor mode, `class' and `def' |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1537 lines count as headers. |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1538 |
| 54789 | 1539 \\{python-mode-map}" |
| 1540 :group 'python | |
| 1541 (set (make-local-variable 'font-lock-defaults) | |
| 1542 '(python-font-lock-keywords nil nil ((?_ . "w")) nil | |
| 1543 (font-lock-syntactic-keywords | |
| 1544 . python-font-lock-syntactic-keywords) | |
| 1545 ;;; This probably isn't worth it. | |
| 1546 ;;; (font-lock-syntactic-face-function | |
| 1547 ;;; . python-font-lock-syntactic-face-function) | |
| 1548 )) | |
| 1549 (set (make-local-variable 'parse-sexp-lookup-properties) t) | |
| 1550 (set (make-local-variable 'comment-start) "# ") | |
| 1551 ;; Fixme: define a comment-indent-function? | |
| 1552 (set (make-local-variable 'indent-line-function) #'python-indent-line) | |
| 1553 (set (make-local-variable 'paragraph-start) "\\s-*$") | |
| 1554 (set (make-local-variable 'fill-paragraph-function) | |
| 1555 'python-fill-paragraph) | |
| 1556 (set (make-local-variable 'require-final-newline) t) | |
| 1557 (set (make-local-variable 'add-log-current-defun-function) | |
| 1558 #'python-current-defun) | |
| 1559 ;; Fixme: Generalize to do all blocks? | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1560 (set (make-local-variable 'outline-regexp) "\\s-*\\(def\\|class\\)\\>") |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1561 (set (make-local-variable 'outline-heading-end-regexp) ":\\s-*\n") |
| 54789 | 1562 (set (make-local-variable 'outline-level) #'python-outline-level) |
| 1563 (set (make-local-variable 'open-paren-in-column-0-is-defun-start) nil) | |
| 1564 (make-local-variable 'python-saved-check-command) | |
| 1565 (set (make-local-variable 'beginning-of-defun-function) | |
| 1566 'python-beginning-of-defun) | |
| 1567 (set (make-local-variable 'end-of-defun-function) 'python-end-of-defun) | |
| 1568 (setq imenu-create-index-function #'python-imenu-create-index) | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1569 (set (make-local-variable 'eldoc-print-current-symbol-info-function) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1570 #'python-eldoc-function) |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1571 (add-hook 'eldoc-mode-hook |
|
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1572 '(lambda () (run-python 0 t)) nil t) ; need it running |
| 54789 | 1573 (unless font-lock-mode (font-lock-mode 1)) |
| 1574 (when python-guess-indent (python-guess-indent)) | |
| 1575 (set (make-local-variable 'python-command) python-python-command) | |
| 1576 (unless (boundp 'python-mode-running) ; kill the recursion from jython-mode | |
| 1577 (let ((python-mode-running t)) | |
| 1578 (python-maybe-jython)))) | |
| 1579 | |
| 1580 (custom-add-option 'python-mode-hook 'imenu-add-menubar-index) | |
| 1581 (custom-add-option 'python-mode-hook | |
| 1582 '(lambda () | |
| 1583 "Turn on Indent Tabs mode." | |
| 1584 (set (make-local-variable 'indent-tabs-mode) t))) | |
|
54840
3768540a819c
Doc fixes. Changes for compiler warnings.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
54838
diff
changeset
|
1585 (custom-add-option 'python-mode-hook 'turn-on-eldoc-mode) |
| 54789 | 1586 |
| 1587 ;;;###autoload | |
| 1588 (define-derived-mode jython-mode python-mode "Jython" | |
| 1589 "Major mode for editing Jython files. | |
| 1590 Like `python-mode', but sets up parameters for Jython subprocesses. | |
| 1591 Runs `jython-mode-hook' after `python-mode-hook'." | |
| 1592 :group 'python | |
| 1593 (set (make-local-variable 'python-command) python-jython-command)) | |
| 1594 | |
| 1595 (provide 'python) | |
| 1596 ;; arch-tag: 6fce1d99-a704-4de9-ba19-c6e4912b0554 | |
| 1597 ;;; python.el ends here |
