Commit | Line | Data |
---|---|---|
308114ef | 1 | ;;; python.el --- silly walks for Python -*- coding: iso-8859-1 -*- |
66b08d69 | 2 | |
fd579fdc | 3 | ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
e18cc61c | 4 | ;; Free Software Foundation, Inc. |
66b08d69 GM |
5 | |
6 | ;; Author: Dave Love <fx@gnu.org> | |
7 | ;; Maintainer: FSF | |
8 | ;; Created: Nov 2003 | |
9 | ;; Keywords: languages | |
10 | ||
11 | ;; This file is part of GNU Emacs. | |
12 | ||
b1fc2b50 | 13 | ;; GNU Emacs is free software: you can redistribute it and/or modify |
66b08d69 | 14 | ;; it under the terms of the GNU General Public License as published by |
b1fc2b50 GM |
15 | ;; the Free Software Foundation, either version 3 of the License, or |
16 | ;; (at your option) any later version. | |
66b08d69 GM |
17 | |
18 | ;; GNU Emacs is distributed in the hope that it will be useful, | |
19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 | ;; GNU General Public License for more details. | |
22 | ||
23 | ;; You should have received a copy of the GNU General Public License | |
b1fc2b50 | 24 | ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
66b08d69 GM |
25 | |
26 | ;;; Commentary: | |
27 | ||
28 | ;; Major mode for editing Python, with support for inferior processes. | |
29 | ||
e18cc61c GM |
30 | ;; There is another Python mode, python-mode.el: |
31 | ;; http://launchpad.net/python-mode | |
32 | ;; used by XEmacs, and originally maintained with Python. | |
33 | ;; That isn't covered by an FSF copyright assignment (?), unlike this | |
34 | ;; code, and seems not to be well-maintained for Emacs (though I've | |
35 | ;; submitted fixes). This mode is rather simpler and is better in | |
36 | ;; other ways. In particular, using the syntax functions with text | |
37 | ;; properties maintained by font-lock makes it more correct with | |
38 | ;; arbitrary string and comment contents. | |
66b08d69 GM |
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 | |
42 | ;; buffer (but see M-x pdb for debugging). [Actually, the use of | |
43 | ;; `compilation-shell-minor-mode' now is probably enough for that.] | |
44 | ;; Others don't seem appropriate. For instance, | |
45 | ;; `forward-into-nomenclature' should be done separately, since it's | |
46 | ;; not specific to Python, and I've installed a minor mode to do the | |
47 | ;; job properly in Emacs 23. [CC mode 5.31 contains an incompatible | |
aaef4f91 | 48 | ;; feature, `subword-mode' which is intended to have a similar |
66b08d69 GM |
49 | ;; effect, but actually only affects word-oriented keybindings.] |
50 | ||
51 | ;; Other things seem more natural or canonical here, e.g. the | |
52 | ;; {beginning,end}-of-defun implementation dealing with nested | |
53 | ;; definitions, and the inferior mode following `cmuscheme'. (The | |
54 | ;; inferior mode can find the source of errors from | |
55 | ;; `python-send-region' & al via `compilation-shell-minor-mode'.) | |
56 | ;; There is (limited) symbol completion using lookup in Python and | |
57 | ;; Eldoc support also using the inferior process. Successive TABs | |
58 | ;; cycle between possible indentations for the line. | |
59 | ||
60 | ;; Even where it has similar facilities, this mode is incompatible | |
61 | ;; with python-mode.el in some respects. For instance, various key | |
62 | ;; bindings are changed to obey Emacs conventions. | |
63 | ||
64 | ;; TODO: See various Fixmes below. | |
65 | ||
2bcda1d5 CY |
66 | ;; Fixme: This doesn't support (the nascent) Python 3 . |
67 | ||
66b08d69 GM |
68 | ;;; Code: |
69 | ||
d550787c NR |
70 | (require 'comint) |
71 | ||
66b08d69 | 72 | (eval-when-compile |
66b08d69 | 73 | (require 'compile) |
66b08d69 GM |
74 | (require 'hippie-exp)) |
75 | ||
76 | (autoload 'comint-mode "comint") | |
77 | ||
78 | (defgroup python nil | |
79 | "Silly walks in the Python language." | |
80 | :group 'languages | |
81 | :version "22.1" | |
82 | :link '(emacs-commentary-link "python")) | |
83 | \f | |
84 | ;;;###autoload | |
1e8780b1 | 85 | (add-to-list 'interpreter-mode-alist (cons (purecopy "jython") 'jython-mode)) |
66b08d69 | 86 | ;;;###autoload |
1e8780b1 | 87 | (add-to-list 'interpreter-mode-alist (cons (purecopy "python") 'python-mode)) |
66b08d69 | 88 | ;;;###autoload |
ca0a881a DN |
89 | (add-to-list 'auto-mode-alist (cons (purecopy "\\.py\\'") 'python-mode)) |
90 | (add-to-list 'same-window-buffer-names (purecopy "*Python*")) | |
66b08d69 GM |
91 | \f |
92 | ;;;; Font lock | |
93 | ||
94 | (defvar python-font-lock-keywords | |
95 | `(,(rx symbol-start | |
4565b08e | 96 |