Mercurial > emacs
annotate lisp/progmodes/python.el @ 112222:5f7efaa8604a
* doc/misc/nxml-mode.texi (Introduction): Fix file name typos.
author | Glenn Morris <rgm@gnu.org> |
---|---|
date | Sun, 02 Jan 2011 17:14:03 -0800 |
parents | 376148b31b5e |
children | 02196c405b19 |
rev | line source |
---|---|
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
1 ;;; python.el --- silly walks for Python -*- coding: iso-8859-1 -*- |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2 |
112218
376148b31b5e
Add 2011 to FSF/AIST copyright years.
Glenn Morris <rgm@gnu.org>
parents:
111753
diff
changeset
|
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
101769
fcd47e055a66
Comment (python-mode is now separate from Python).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
4 ;; Free Software Foundation, Inc. |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
5 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
6 ;; Author: Dave Love <fx@gnu.org> |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
7 ;; Maintainer: FSF |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
8 ;; Created: Nov 2003 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
9 ;; Keywords: languages |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
10 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
11 ;; This file is part of GNU Emacs. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
12 |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94628
diff
changeset
|
13 ;; GNU Emacs is free software: you can redistribute it and/or modify |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
14 ;; it under the terms of the GNU General Public License as published by |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94628
diff
changeset
|
15 ;; the Free Software Foundation, either version 3 of the License, or |
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94628
diff
changeset
|
16 ;; (at your option) any later version. |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
17 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
18 ;; GNU Emacs is distributed in the hope that it will be useful, |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
21 ;; GNU General Public License for more details. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
22 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
23 ;; You should have received a copy of the GNU General Public License |
94673
52b7a8c22af5
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
94628
diff
changeset
|
24 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
25 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
26 ;;; Commentary: |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
27 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
28 ;; Major mode for editing Python, with support for inferior processes. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
29 |
101769
fcd47e055a66
Comment (python-mode is now separate from Python).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
30 ;; There is another Python mode, python-mode.el: |
fcd47e055a66
Comment (python-mode is now separate from Python).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
31 ;; http://launchpad.net/python-mode |
fcd47e055a66
Comment (python-mode is now separate from Python).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
32 ;; used by XEmacs, and originally maintained with Python. |
fcd47e055a66
Comment (python-mode is now separate from Python).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
33 ;; That isn't covered by an FSF copyright assignment (?), unlike this |
fcd47e055a66
Comment (python-mode is now separate from Python).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
34 ;; code, and seems not to be well-maintained for Emacs (though I've |
fcd47e055a66
Comment (python-mode is now separate from Python).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
35 ;; submitted fixes). This mode is rather simpler and is better in |
fcd47e055a66
Comment (python-mode is now separate from Python).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
36 ;; other ways. In particular, using the syntax functions with text |
fcd47e055a66
Comment (python-mode is now separate from Python).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
37 ;; properties maintained by font-lock makes it more correct with |
fcd47e055a66
Comment (python-mode is now separate from Python).
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
38 ;; arbitrary string and comment contents. |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
39 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
40 ;; This doesn't implement all the facilities of python-mode.el. Some |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
41 ;; just need doing, e.g. catching exceptions in the inferior Python |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
42 ;; buffer (but see M-x pdb for debugging). [Actually, the use of |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
43 ;; `compilation-shell-minor-mode' now is probably enough for that.] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
44 ;; Others don't seem appropriate. For instance, |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
45 ;; `forward-into-nomenclature' should be done separately, since it's |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
46 ;; not specific to Python, and I've installed a minor mode to do the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
47 ;; job properly in Emacs 23. [CC mode 5.31 contains an incompatible |
106980
66e0d01014c6
replace references to obsolete c-subword-mode
Mark A. Hershberger <mhershberger@intrahealth.org>
parents:
106743
diff
changeset
|
48 ;; feature, `subword-mode' which is intended to have a similar |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
49 ;; effect, but actually only affects word-oriented keybindings.] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
50 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
51 ;; Other things seem more natural or canonical here, e.g. the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
52 ;; {beginning,end}-of-defun implementation dealing with nested |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
53 ;; definitions, and the inferior mode following `cmuscheme'. (The |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
54 ;; inferior mode can find the source of errors from |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
55 ;; `python-send-region' & al via `compilation-shell-minor-mode'.) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
56 ;; There is (limited) symbol completion using lookup in Python and |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
57 ;; Eldoc support also using the inferior process. Successive TABs |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
58 ;; cycle between possible indentations for the line. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
59 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
60 ;; Even where it has similar facilities, this mode is incompatible |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
61 ;; with python-mode.el in some respects. For instance, various key |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
62 ;; bindings are changed to obey Emacs conventions. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
63 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
64 ;; TODO: See various Fixmes below. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
65 |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
66 ;; Fixme: This doesn't support (the nascent) Python 3 . |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
67 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
68 ;;; Code: |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
69 |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
70 (require 'comint) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
71 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
72 (eval-when-compile |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
73 (require 'compile) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
74 (require 'hippie-exp)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
75 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
76 (autoload 'comint-mode "comint") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
77 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
78 (defgroup python nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
79 "Silly walks in the Python language." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
80 :group 'languages |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
81 :version "22.1" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
82 :link '(emacs-commentary-link "python")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
83 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
84 ;;;###autoload |
105870
26baacb565b0
* textmodes/tex-mode.el (tex-alt-dvi-print-command)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105813
diff
changeset
|
85 (add-to-list 'interpreter-mode-alist (cons (purecopy "jython") 'jython-mode)) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
86 ;;;###autoload |
105870
26baacb565b0
* textmodes/tex-mode.el (tex-alt-dvi-print-command)
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105813
diff
changeset
|
87 (add-to-list 'interpreter-mode-alist (cons (purecopy "python") 'python-mode)) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
88 ;;;###autoload |
105798
0ad1fc06bfc8
* puresize.h (BASE_PURESIZE): Increase to 1470000.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105372
diff
changeset
|
89 (add-to-list 'auto-mode-alist (cons (purecopy "\\.py\\'") 'python-mode)) |
0ad1fc06bfc8
* puresize.h (BASE_PURESIZE): Increase to 1470000.
Dan Nicolaescu <dann@ics.uci.edu>
parents:
105372
diff
changeset
|
90 (add-to-list 'same-window-buffer-names (purecopy "*Python*")) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
91 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
92 ;;;; Font lock |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
93 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
94 (defvar python-font-lock-keywords |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
95 `(,(rx symbol-start |
109300
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
96 ;; From v 2.7 reference, § keywords. |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
97 ;; def and class dealt with separately below |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
98 (or "and" "as" "assert" "break" "continue" "del" "elif" "else" |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
99 "except" "exec" "finally" "for" "from" "global" "if" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
100 "import" "in" "is" "lambda" "not" "or" "pass" "print" |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
101 "raise" "return" "try" "while" "with" "yield" |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
102 ;; Not real keywords, but close enough to be fontified as such |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
103 "self" "True" "False") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
104 symbol-end) |
109300
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
105 (,(rx symbol-start "None" symbol-end) ; see § Keywords in 2.7 manual |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
106 . font-lock-constant-face) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
107 ;; Definitions |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
108 (,(rx symbol-start (group "class") (1+ space) (group (1+ (or word ?_)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
109 (1 font-lock-keyword-face) (2 font-lock-type-face)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
110 (,(rx symbol-start (group "def") (1+ space) (group (1+ (or word ?_)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
111 (1 font-lock-keyword-face) (2 font-lock-function-name-face)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
112 ;; Top-level assignments are worth highlighting. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
113 (,(rx line-start (group (1+ (or word ?_))) (0+ space) "=") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
114 (1 font-lock-variable-name-face)) |
106743
2db50e698b85
* progmodes/python.el (python-font-lock-keywords): Handle qualified decorators
Chong Yidong <cyd@stupidchicken.com>
parents:
106574
diff
changeset
|
115 ;; Decorators. |
2db50e698b85
* progmodes/python.el (python-font-lock-keywords): Handle qualified decorators
Chong Yidong <cyd@stupidchicken.com>
parents:
106574
diff
changeset
|
116 (,(rx line-start (* (any " \t")) (group "@" (1+ (or word ?_)) |
2db50e698b85
* progmodes/python.el (python-font-lock-keywords): Handle qualified decorators
Chong Yidong <cyd@stupidchicken.com>
parents:
106574
diff
changeset
|
117 (0+ "." (1+ (or word ?_))))) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
118 (1 font-lock-type-face)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
119 ;; Built-ins. (The next three blocks are from |
109300
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
120 ;; `__builtin__.__dict__.keys()' in Python 2.7) These patterns |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
121 ;; are debateable, but they at least help to spot possible |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
122 ;; shadowing of builtins. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
123 (,(rx symbol-start (or |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
124 ;; exceptions |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
125 "ArithmeticError" "AssertionError" "AttributeError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
126 "BaseException" "DeprecationWarning" "EOFError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
127 "EnvironmentError" "Exception" "FloatingPointError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
128 "FutureWarning" "GeneratorExit" "IOError" "ImportError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
129 "ImportWarning" "IndentationError" "IndexError" "KeyError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
130 "KeyboardInterrupt" "LookupError" "MemoryError" "NameError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
131 "NotImplemented" "NotImplementedError" "OSError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
132 "OverflowError" "PendingDeprecationWarning" "ReferenceError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
133 "RuntimeError" "RuntimeWarning" "StandardError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
134 "StopIteration" "SyntaxError" "SyntaxWarning" "SystemError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
135 "SystemExit" "TabError" "TypeError" "UnboundLocalError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
136 "UnicodeDecodeError" "UnicodeEncodeError" "UnicodeError" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
137 "UnicodeTranslateError" "UnicodeWarning" "UserWarning" |
109300
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
138 "ValueError" "Warning" "ZeroDivisionError" |
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
139 ;; Python 2.7 |
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
140 "BufferError" "BytesWarning" "WindowsError") symbol-end) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
141 . font-lock-type-face) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
142 (,(rx (or line-start (not (any ". \t"))) (* (any " \t")) symbol-start |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
143 (group (or |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
144 ;; callable built-ins, fontified when not appearing as |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
145 ;; object attributes |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
146 "abs" "all" "any" "apply" "basestring" "bool" "buffer" "callable" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
147 "chr" "classmethod" "cmp" "coerce" "compile" "complex" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
148 "copyright" "credits" "delattr" "dict" "dir" "divmod" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
149 "enumerate" "eval" "execfile" "exit" "file" "filter" "float" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
150 "frozenset" "getattr" "globals" "hasattr" "hash" "help" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
151 "hex" "id" "input" "int" "intern" "isinstance" "issubclass" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
152 "iter" "len" "license" "list" "locals" "long" "map" "max" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
153 "min" "object" "oct" "open" "ord" "pow" "property" "quit" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
154 "range" "raw_input" "reduce" "reload" "repr" "reversed" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
155 "round" "set" "setattr" "slice" "sorted" "staticmethod" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
156 "str" "sum" "super" "tuple" "type" "unichr" "unicode" "vars" |
109300
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
157 "xrange" "zip" |
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
158 ;; Python 2.7. |
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
159 "bin" "bytearray" "bytes" "format" "memoryview" "next" "print" |
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
160 )) symbol-end) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
161 (1 font-lock-builtin-face)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
162 (,(rx symbol-start (or |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
163 ;; other built-ins |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
164 "True" "False" "None" "Ellipsis" |
109300
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
165 "_" "__debug__" "__doc__" "__import__" "__name__" "__package__") |
454cfd5e9cc0
Add some font-locking for Python 2.7.
Glenn Morris <rgm@gnu.org>
parents:
107240
diff
changeset
|
166 symbol-end) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
167 . font-lock-builtin-face))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
168 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
169 (defconst python-font-lock-syntactic-keywords |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
170 ;; Make outer chars of matching triple-quote sequences into generic |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
171 ;; string delimiters. Fixme: Is there a better way? |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
172 ;; First avoid a sequence preceded by an odd number of backslashes. |
111385
85a2b871f225
* lisp/progmodes/python.el (python-font-lock-syntactic-keywords):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110115
diff
changeset
|
173 `((,(concat "\\(?:\\([RUru]\\)[Rr]?\\|^\\|[^\\]\\(?:\\\\.\\)*\\)" ;Prefix. |
85a2b871f225
* lisp/progmodes/python.el (python-font-lock-syntactic-keywords):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110115
diff
changeset
|
174 "\\(?:\\('\\)'\\('\\)\\|\\(?2:\"\\)\"\\(?3:\"\\)\\)") |
85a2b871f225
* lisp/progmodes/python.el (python-font-lock-syntactic-keywords):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110115
diff
changeset
|
175 (1 (python-quote-syntax 1) nil lax) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
176 (2 (python-quote-syntax 2)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
177 (3 (python-quote-syntax 3))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
178 ;; This doesn't really help. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
179 ;;; (,(rx (and ?\\ (group ?\n))) (1 " ")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
180 )) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
181 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
182 (defun python-quote-syntax (n) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
183 "Put `syntax-table' property correctly on triple quote. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
184 Used for syntactic keywords. N is the match number (1, 2 or 3)." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
185 ;; Given a triple quote, we have to check the context to know |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
186 ;; whether this is an opening or closing triple or whether it's |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
187 ;; quoted anyhow, and should be ignored. (For that we need to do |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
188 ;; the same job as `syntax-ppss' to be correct and it seems to be OK |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
189 ;; to use it here despite initial worries.) We also have to sort |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
190 ;; out a possible prefix -- well, we don't _have_ to, but I think it |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
191 ;; should be treated as part of the string. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
192 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
193 ;; Test cases: |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
194 ;; ur"""ar""" x='"' # """ |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
195 ;; x = ''' """ ' a |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
196 ;; ''' |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
197 ;; x '"""' x """ \"""" x |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
198 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
199 (goto-char (match-beginning 0)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
200 (cond |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
201 ;; Consider property for the last char if in a fenced string. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
202 ((= n 3) |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
203 (let* ((font-lock-syntactic-keywords nil) |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
204 (syntax (syntax-ppss))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
205 (when (eq t (nth 3 syntax)) ; after unclosed fence |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
206 (goto-char (nth 8 syntax)) ; fence position |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
207 (skip-chars-forward "uUrR") ; skip any prefix |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
208 ;; Is it a matching sequence? |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
209 (if (eq (char-after) (char-after (match-beginning 2))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
210 (eval-when-compile (string-to-syntax "|")))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
211 ;; Consider property for initial char, accounting for prefixes. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
212 ((or (and (= n 2) ; leading quote (not prefix) |
111385
85a2b871f225
* lisp/progmodes/python.el (python-font-lock-syntactic-keywords):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110115
diff
changeset
|
213 (not (match-end 1))) ; prefix is null |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
214 (and (= n 1) ; prefix |
111385
85a2b871f225
* lisp/progmodes/python.el (python-font-lock-syntactic-keywords):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
110115
diff
changeset
|
215 (match-end 1))) ; non-empty |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
216 (let ((font-lock-syntactic-keywords nil)) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
217 (unless (eq 'string (syntax-ppss-context (syntax-ppss))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
218 (eval-when-compile (string-to-syntax "|"))))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
219 ;; Otherwise (we're in a non-matching string) the property is |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
220 ;; nil, which is OK. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
221 ))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
222 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
223 ;; This isn't currently in `font-lock-defaults' as probably not worth |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
224 ;; it -- we basically only mess with a few normally-symbol characters. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
225 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
226 ;; (defun python-font-lock-syntactic-face-function (state) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
227 ;; "`font-lock-syntactic-face-function' for Python mode. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
228 ;; Returns the string or comment face as usual, with side effect of putting |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
229 ;; a `syntax-table' property on the inside of the string or comment which is |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
230 ;; the standard syntax table." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
231 ;; (if (nth 3 state) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
232 ;; (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
233 ;; (goto-char (nth 8 state)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
234 ;; (condition-case nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
235 ;; (forward-sexp) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
236 ;; (error nil)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
237 ;; (put-text-property (1+ (nth 8 state)) (1- (point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
238 ;; 'syntax-table (standard-syntax-table)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
239 ;; 'font-lock-string-face) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
240 ;; (put-text-property (1+ (nth 8 state)) (line-end-position) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
241 ;; 'syntax-table (standard-syntax-table)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
242 ;; 'font-lock-comment-face)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
243 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
244 ;;;; Keymap and syntax |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
245 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
246 (defvar python-mode-map |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
247 (let ((map (make-sparse-keymap))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
248 ;; Mostly taken from python-mode.el. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
249 (define-key map ":" 'python-electric-colon) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
250 (define-key map "\177" 'python-backspace) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
251 (define-key map "\C-c<" 'python-shift-left) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
252 (define-key map "\C-c>" 'python-shift-right) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
253 (define-key map "\C-c\C-k" 'python-mark-block) |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
254 (define-key map "\C-c\C-d" 'python-pdbtrack-toggle-stack-tracking) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
255 (define-key map "\C-c\C-n" 'python-next-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
256 (define-key map "\C-c\C-p" 'python-previous-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
257 (define-key map "\C-c\C-u" 'python-beginning-of-block) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
258 (define-key map "\C-c\C-f" 'python-describe-symbol) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
259 (define-key map "\C-c\C-w" 'python-check) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
260 (define-key map "\C-c\C-v" 'python-check) ; a la sgml-mode |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
261 (define-key map "\C-c\C-s" 'python-send-string) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
262 (define-key map [?\C-\M-x] 'python-send-defun) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
263 (define-key map "\C-c\C-r" 'python-send-region) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
264 (define-key map "\C-c\M-r" 'python-send-region-and-go) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
265 (define-key map "\C-c\C-c" 'python-send-buffer) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
266 (define-key map "\C-c\C-z" 'python-switch-to-python) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
267 (define-key map "\C-c\C-m" 'python-load-file) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
268 (define-key map "\C-c\C-l" 'python-load-file) ; a la cmuscheme |
106482
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105870
diff
changeset
|
269 (substitute-key-definition 'complete-symbol 'completion-at-point |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
270 map global-map) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
271 (define-key map "\C-c\C-i" 'python-find-imports) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
272 (define-key map "\C-c\C-t" 'python-expand-template) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
273 (easy-menu-define python-menu map "Python Mode menu" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
274 `("Python" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
275 :help "Python-specific Features" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
276 ["Shift region left" python-shift-left :active mark-active |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
277 :help "Shift by a single indentation step"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
278 ["Shift region right" python-shift-right :active mark-active |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
279 :help "Shift by a single indentation step"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
280 "-" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
281 ["Mark block" python-mark-block |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
282 :help "Mark innermost block around point"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
283 ["Mark def/class" mark-defun |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
284 :help "Mark innermost definition around point"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
285 "-" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
286 ["Start of block" python-beginning-of-block |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
287 :help "Go to start of innermost definition around point"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
288 ["End of block" python-end-of-block |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
289 :help "Go to end of innermost definition around point"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
290 ["Start of def/class" beginning-of-defun |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
291 :help "Go to start of innermost definition around point"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
292 ["End of def/class" end-of-defun |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
293 :help "Go to end of innermost definition around point"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
294 "-" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
295 ("Templates..." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
296 :help "Expand templates for compound statements" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
297 :filter (lambda (&rest junk) |
94139
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
298 (abbrev-table-menu python-mode-abbrev-table))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
299 "-" |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
300 ["Start interpreter" python-shell |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
301 :help "Run `inferior' Python in separate buffer"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
302 ["Import/reload file" python-load-file |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
303 :help "Load into inferior Python session"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
304 ["Eval buffer" python-send-buffer |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
305 :help "Evaluate buffer en bloc in inferior Python session"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
306 ["Eval region" python-send-region :active mark-active |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
307 :help "Evaluate region en bloc in inferior Python session"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
308 ["Eval def/class" python-send-defun |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
309 :help "Evaluate current definition in inferior Python session"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
310 ["Switch to interpreter" python-switch-to-python |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
311 :help "Switch to inferior Python buffer"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
312 ["Set default process" python-set-proc |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
313 :help "Make buffer's inferior process the default" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
314 :active (buffer-live-p python-buffer)] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
315 ["Check file" python-check :help "Run pychecker"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
316 ["Debugger" pdb :help "Run pdb under GUD"] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
317 "-" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
318 ["Help on symbol" python-describe-symbol |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
319 :help "Use pydoc on symbol at point"] |
106482
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105870
diff
changeset
|
320 ["Complete symbol" completion-at-point |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
321 :help "Complete (qualified) symbol before point"] |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
322 ["Find function" python-find-function |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
323 :help "Try to find source definition of function at point"] |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
324 ["Update imports" python-find-imports |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
325 :help "Update list of top-level imports for completion"])) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
326 map)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
327 ;; Fixme: add toolbar stuff for useful things like symbol help, send |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
328 ;; region, at least. (Shouldn't be specific to Python, obviously.) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
329 ;; eric has items including: (un)indent, (un)comment, restart script, |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
330 ;; run script, debug script; also things for profiling, unit testing. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
331 |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
332 (defvar python-shell-map |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
333 (let ((map (copy-keymap comint-mode-map))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
334 (define-key map [tab] 'tab-to-tab-stop) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
335 (define-key map "\C-c-" 'py-up-exception) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
336 (define-key map "\C-c=" 'py-down-exception) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
337 map) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
338 "Keymap used in *Python* shell buffers.") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
339 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
340 (defvar python-mode-syntax-table |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
341 (let ((table (make-syntax-table))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
342 ;; Give punctuation syntax to ASCII that normally has symbol |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
343 ;; syntax or has word syntax and isn't a letter. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
344 (let ((symbol (string-to-syntax "_")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
345 (sst (standard-syntax-table))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
346 (dotimes (i 128) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
347 (unless (= i ?_) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
348 (if (equal symbol (aref sst i)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
349 (modify-syntax-entry i "." table))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
350 (modify-syntax-entry ?$ "." table) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
351 (modify-syntax-entry ?% "." table) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
352 ;; exceptions |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
353 (modify-syntax-entry ?# "<" table) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
354 (modify-syntax-entry ?\n ">" table) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
355 (modify-syntax-entry ?' "\"" table) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
356 (modify-syntax-entry ?` "$" table) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
357 table)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
358 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
359 ;;;; Utility stuff |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
360 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
361 (defsubst python-in-string/comment () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
362 "Return non-nil if point is in a Python literal (a comment or string)." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
363 ;; We don't need to save the match data. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
364 (nth 8 (syntax-ppss))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
365 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
366 (defconst python-space-backslash-table |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
367 (let ((table (copy-syntax-table python-mode-syntax-table))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
368 (modify-syntax-entry ?\\ " " table) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
369 table) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
370 "`python-mode-syntax-table' with backslash given whitespace syntax.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
371 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
372 (defun python-skip-comments/blanks (&optional backward) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
373 "Skip comments and blank lines. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
374 BACKWARD non-nil means go backwards, otherwise go forwards. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
375 Backslash is treated as whitespace so that continued blank lines |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
376 are skipped. Doesn't move out of comments -- should be outside |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
377 or at end of line." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
378 (let ((arg (if backward |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
379 ;; If we're in a comment (including on the trailing |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
380 ;; newline), forward-comment doesn't move backwards out |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
381 ;; of it. Don't set the syntax table round this bit! |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
382 (let ((syntax (syntax-ppss))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
383 (if (nth 4 syntax) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
384 (goto-char (nth 8 syntax))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
385 (- (point-max))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
386 (point-max)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
387 (with-syntax-table python-space-backslash-table |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
388 (forward-comment arg)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
389 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
390 (defun python-backslash-continuation-line-p () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
391 "Non-nil if preceding line ends with backslash that is not in a comment." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
392 (and (eq ?\\ (char-before (line-end-position 0))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
393 (not (syntax-ppss-context (syntax-ppss))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
394 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
395 (defun python-continuation-line-p () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
396 "Return non-nil if current line continues a previous one. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
397 The criteria are that the previous line ends in a backslash outside |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
398 comments and strings, or that point is within brackets/parens." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
399 (or (python-backslash-continuation-line-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
400 (let ((depth (syntax-ppss-depth |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
401 (save-excursion ; syntax-ppss with arg changes point |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
402 (syntax-ppss (line-beginning-position)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
403 (or (> depth 0) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
404 (if (< depth 0) ; Unbalanced brackets -- act locally |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
405 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
406 (condition-case () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
407 (progn (backward-up-list) t) ; actually within brackets |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
408 (error nil)))))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
409 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
410 (defun python-comment-line-p () |
94740
464e6f78f756
(python-comment-line-p, python-blank-line-p, python-skip-out,
Juanma Barranquero <lekktu@gmail.com>
parents:
94673
diff
changeset
|
411 "Return non-nil if and only if current line has only a comment." |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
412 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
413 (end-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
414 (when (eq 'comment (syntax-ppss-context (syntax-ppss))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
415 (back-to-indentation) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
416 (looking-at (rx (or (syntax comment-start) line-end)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
417 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
418 (defun python-blank-line-p () |
94740
464e6f78f756
(python-comment-line-p, python-blank-line-p, python-skip-out,
Juanma Barranquero <lekktu@gmail.com>
parents:
94673
diff
changeset
|
419 "Return non-nil if and only if current line is blank." |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
420 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
421 (beginning-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
422 (looking-at "\\s-*$"))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
423 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
424 (defun python-beginning-of-string () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
425 "Go to beginning of string around point. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
426 Do nothing if not in string." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
427 (let ((state (syntax-ppss))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
428 (when (eq 'string (syntax-ppss-context state)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
429 (goto-char (nth 8 state))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
430 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
431 (defun python-open-block-statement-p (&optional bos) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
432 "Return non-nil if statement at point opens a block. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
433 BOS non-nil means point is known to be at beginning of statement." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
434 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
435 (unless bos (python-beginning-of-statement)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
436 (looking-at (rx (and (or "if" "else" "elif" "while" "for" "def" |
77678
0b0c0f93563c
(python-font-lock-keywords, python-open-block-statement-p, python-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77663
diff
changeset
|
437 "class" "try" "except" "finally" "with") |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
438 symbol-end))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
439 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
440 (defun python-close-block-statement-p (&optional bos) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
441 "Return non-nil if current line is a statement closing a block. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
442 BOS non-nil means point is at beginning of statement. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
443 The criteria are that the line isn't a comment or in string and |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
444 starts with keyword `raise', `break', `continue' or `pass'." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
445 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
446 (unless bos (python-beginning-of-statement)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
447 (back-to-indentation) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
448 (looking-at (rx (or "return" "raise" "break" "continue" "pass") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
449 symbol-end)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
450 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
451 (defun python-outdent-p () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
452 "Return non-nil if current line should outdent a level." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
453 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
454 (back-to-indentation) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
455 (and (looking-at (rx (and (or "else" "finally" "except" "elif") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
456 symbol-end))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
457 (not (python-in-string/comment)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
458 ;; Ensure there's a previous statement and move to it. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
459 (zerop (python-previous-statement)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
460 (not (python-close-block-statement-p t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
461 ;; Fixme: check this |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
462 (not (python-open-block-statement-p))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
463 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
464 ;;;; Indentation. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
465 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
466 (defcustom python-indent 4 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
467 "Number of columns for a unit of indentation in Python mode. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
468 See also `\\[python-guess-indent]'" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
469 :group 'python |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
470 :type 'integer) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
471 (put 'python-indent 'safe-local-variable 'integerp) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
472 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
473 (defcustom python-guess-indent t |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
474 "Non-nil means Python mode guesses `python-indent' for the buffer." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
475 :type 'boolean |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
476 :group 'python) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
477 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
478 (defcustom python-indent-string-contents t |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
479 "Non-nil means indent contents of multi-line strings together. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
480 This means indent them the same as the preceding non-blank line. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
481 Otherwise preserve their indentation. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
482 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
483 This only applies to `doc' strings, i.e. those that form statements; |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
484 the indentation is preserved in others." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
485 :type '(choice (const :tag "Align with preceding" t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
486 (const :tag "Preserve indentation" nil)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
487 :group 'python) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
488 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
489 (defcustom python-honour-comment-indentation nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
490 "Non-nil means indent relative to preceding comment line. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
491 Only do this for comments where the leading comment character is |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
492 followed by space. This doesn't apply to comment lines, which |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
493 are always indented in lines with preceding comments." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
494 :type 'boolean |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
495 :group 'python) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
496 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
497 (defcustom python-continuation-offset 4 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
498 "Number of columns of additional indentation for continuation lines. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
499 Continuation lines follow a backslash-terminated line starting a |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
500 statement." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
501 :group 'python |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
502 :type 'integer) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
503 |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
504 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
505 (defcustom python-default-interpreter 'cpython |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
506 "*Which Python interpreter is used by default. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
507 The value for this variable can be either `cpython' or `jpython'. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
508 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
509 When the value is `cpython', the variables `python-python-command' and |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
510 `python-python-command-args' are consulted to determine the interpreter |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
511 and arguments to use. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
512 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
513 When the value is `jpython', the variables `python-jpython-command' and |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
514 `python-jpython-command-args' are consulted to determine the interpreter |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
515 and arguments to use. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
516 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
517 Note that this variable is consulted only the first time that a Python |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
518 mode buffer is visited during an Emacs session. After that, use |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
519 \\[python-toggle-shells] to change the interpreter shell." |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
520 :type '(choice (const :tag "Python (a.k.a. CPython)" cpython) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
521 (const :tag "JPython" jpython)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
522 :group 'python) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
523 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
524 (defcustom python-python-command-args '("-i") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
525 "*List of string arguments to be used when starting a Python shell." |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
526 :type '(repeat string) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
527 :group 'python) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
528 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
529 (defcustom python-jython-command-args '("-i") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
530 "*List of string arguments to be used when starting a Jython shell." |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
531 :type '(repeat string) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
532 :group 'python |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
533 :tag "JPython Command Args") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
534 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
535 ;; for toggling between CPython and JPython |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
536 (defvar python-which-shell nil) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
537 (defvar python-which-args python-python-command-args) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
538 (defvar python-which-bufname "Python") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
539 (make-variable-buffer-local 'python-which-shell) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
540 (make-variable-buffer-local 'python-which-args) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
541 (make-variable-buffer-local 'python-which-bufname) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
542 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
543 (defcustom python-pdbtrack-do-tracking-p t |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
544 "*Controls whether the pdbtrack feature is enabled or not. |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
545 |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
546 When non-nil, pdbtrack is enabled in all comint-based buffers, |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
547 e.g. shell interaction buffers and the *Python* buffer. |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
548 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
549 When using pdb to debug a Python program, pdbtrack notices the |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
550 pdb prompt and presents the line in the source file where the |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
551 program is stopped in a pop-up buffer. It's similar to what |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
552 gud-mode does for debugging C programs with gdb, but without |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
553 having to restart the program." |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
554 :type 'boolean |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
555 :group 'python) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
556 (make-variable-buffer-local 'python-pdbtrack-do-tracking-p) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
557 |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
558 (defcustom python-pdbtrack-minor-mode-string " PDB" |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
559 "*Minor-mode sign to be displayed when pdbtrack is active." |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
560 :type 'string |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
561 :group 'python) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
562 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
563 ;; Add a designator to the minor mode strings |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
564 (or (assq 'python-pdbtrack-is-tracking-p minor-mode-alist) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
565 (push '(python-pdbtrack-is-tracking-p python-pdbtrack-minor-mode-string) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
566 minor-mode-alist)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
567 |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
568 ;; Bind python-file-queue before installing the kill-emacs-hook. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
569 (defvar python-file-queue nil |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
570 "Queue of Python temp files awaiting execution. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
571 Currently-active file is at the head of the list.") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
572 |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
573 (defcustom python-shell-prompt-alist |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
574 '(("ipython" . "^In \\[[0-9]+\\]: *") |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
575 (t . "^>>> ")) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
576 "Alist of Python input prompts. |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
577 Each element has the form (PROGRAM . REGEXP), where PROGRAM is |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
578 the value of `python-python-command' for the python process and |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
579 REGEXP is a regular expression matching the Python prompt. |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
580 PROGRAM can also be t, which specifies the default when no other |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
581 element matches `python-python-command'." |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
582 :type 'string |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
583 :group 'python |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
584 :version "24.1") |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
585 |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
586 (defcustom python-shell-continuation-prompt-alist |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
587 '(("ipython" . "^ [.][.][.]+: *") |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
588 (t . "^[.][.][.] ")) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
589 "Alist of Python continued-line prompts. |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
590 Each element has the form (PROGRAM . REGEXP), where PROGRAM is |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
591 the value of `python-python-command' for the python process and |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
592 REGEXP is a regular expression matching the Python prompt for |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
593 continued lines. |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
594 PROGRAM can also be t, which specifies the default when no other |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
595 element matches `python-python-command'." |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
596 :type 'string |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
597 :group 'python |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
598 :version "24.1") |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
599 |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
600 (defvar python-pdbtrack-is-tracking-p nil) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
601 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
602 (defconst python-pdbtrack-stack-entry-regexp |
107240
8953c1cd8568
Minor Python mode fix (Bug#5653).
Chong Yidong <cyd@stupidchicken.com>
parents:
106980
diff
changeset
|
603 "^> \\(.*\\)(\\([0-9]+\\))\\([?a-zA-Z0-9_<>]+\\)()" |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
604 "Regular expression pdbtrack uses to find a stack trace entry.") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
605 |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
606 (defconst python-pdbtrack-input-prompt "\n[(<]*[Pp]db[>)]+ " |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
607 "Regular expression pdbtrack uses to recognize a pdb prompt.") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
608 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
609 (defconst python-pdbtrack-track-range 10000 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
610 "Max number of characters from end of buffer to search for stack entry.") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
611 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
612 (defun python-guess-indent () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
613 "Guess step for indentation of current buffer. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
614 Set `python-indent' locally to the value guessed." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
615 (interactive) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
616 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
617 (save-restriction |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
618 (widen) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
619 (goto-char (point-min)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
620 (let (done indent) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
621 (while (and (not done) (not (eobp))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
622 (when (and (re-search-forward (rx ?: (0+ space) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
623 (or (syntax comment-start) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
624 line-end)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
625 nil 'move) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
626 (python-open-block-statement-p)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
627 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
628 (python-beginning-of-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
629 (let ((initial (current-indentation))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
630 (if (zerop (python-next-statement)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
631 (setq indent (- (current-indentation) initial))) |
77663
32334cd7302e
(python-guess-indent): Check non-nullness before comparing indent against
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77568
diff
changeset
|
632 (if (and indent (>= indent 2) (<= indent 8)) ; sanity check |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
633 (setq done t)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
634 (when done |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
635 (when (/= indent (default-value 'python-indent)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
636 (set (make-local-variable 'python-indent) indent) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
637 (unless (= tab-width python-indent) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
638 (setq indent-tabs-mode nil))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
639 indent))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
640 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
641 ;; Alist of possible indentations and start of statement they would |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
642 ;; close. Used in indentation cycling (below). |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
643 (defvar python-indent-list nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
644 "Internal use.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
645 ;; Length of the above |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
646 (defvar python-indent-list-length nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
647 "Internal use.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
648 ;; Current index into the alist. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
649 (defvar python-indent-index nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
650 "Internal use.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
651 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
652 (defun python-calculate-indentation () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
653 "Calculate Python indentation for line at point." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
654 (setq python-indent-list nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
655 python-indent-list-length 1) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
656 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
657 (beginning-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
658 (let ((syntax (syntax-ppss)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
659 start) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
660 (cond |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
661 ((eq 'string (syntax-ppss-context syntax)) ; multi-line string |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
662 (if (not python-indent-string-contents) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
663 (current-indentation) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
664 ;; Only respect `python-indent-string-contents' in doc |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
665 ;; strings (defined as those which form statements). |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
666 (if (not (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
667 (python-beginning-of-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
668 (looking-at (rx (or (syntax string-delimiter) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
669 (syntax string-quote)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
670 (current-indentation) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
671 ;; Find indentation of preceding non-blank line within string. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
672 (setq start (nth 8 syntax)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
673 (forward-line -1) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
674 (while (and (< start (point)) (looking-at "\\s-*$")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
675 (forward-line -1)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
676 (current-indentation)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
677 ((python-continuation-line-p) ; after backslash, or bracketed |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
678 (let ((point (point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
679 (open-start (cadr syntax)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
680 (backslash (python-backslash-continuation-line-p)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
681 (colon (eq ?: (char-before (1- (line-beginning-position)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
682 (if open-start |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
683 ;; Inside bracketed expression. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
684 (progn |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
685 (goto-char (1+ open-start)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
686 ;; Look for first item in list (preceding point) and |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
687 ;; align with it, if found. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
688 (if (with-syntax-table python-space-backslash-table |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
689 (let ((parse-sexp-ignore-comments t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
690 (condition-case () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
691 (progn (forward-sexp) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
692 (backward-sexp) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
693 (< (point) point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
694 (error nil)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
695 ;; Extra level if we're backslash-continued or |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
696 ;; following a key. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
697 (if (or backslash colon) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
698 (+ python-indent (current-column)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
699 (current-column)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
700 ;; Otherwise indent relative to statement start, one |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
701 ;; level per bracketing level. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
702 (goto-char (1+ open-start)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
703 (python-beginning-of-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
704 (+ (current-indentation) (* (car syntax) python-indent)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
705 ;; Otherwise backslash-continued. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
706 (forward-line -1) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
707 (if (python-continuation-line-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
708 ;; We're past first continuation line. Align with |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
709 ;; previous line. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
710 (current-indentation) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
711 ;; First continuation line. Indent one step, with an |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
712 ;; extra one if statement opens a block. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
713 (python-beginning-of-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
714 (+ (current-indentation) python-continuation-offset |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
715 (if (python-open-block-statement-p t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
716 python-indent |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
717 0)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
718 ((bobp) 0) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
719 ;; Fixme: Like python-mode.el; not convinced by this. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
720 ((looking-at (rx (0+ space) (syntax comment-start) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
721 (not (any " \t\n")))) ; non-indentable comment |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
722 (current-indentation)) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
723 ((and python-honour-comment-indentation |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
724 ;; Back over whitespace, newlines, non-indentable comments. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
725 (catch 'done |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
726 (while (cond ((bobp) nil) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
727 ((not (forward-comment -1)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
728 nil) ; not at comment start |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
729 ;; Now at start of comment -- trailing one? |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
730 ((/= (current-column) (current-indentation)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
731 nil) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
732 ;; Indentable comment, like python-mode.el? |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
733 ((and (looking-at (rx (syntax comment-start) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
734 (or space line-end))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
735 (/= 0 (current-column))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
736 (throw 'done (current-column))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
737 ;; Else skip it (loop). |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
738 (t)))))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
739 (t |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
740 (python-indentation-levels) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
741 ;; Prefer to indent comments with an immediately-following |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
742 ;; statement, e.g. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
743 ;; ... |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
744 ;; # ... |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
745 ;; def ... |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
746 (when (and (> python-indent-list-length 1) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
747 (python-comment-line-p)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
748 (forward-line) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
749 (unless (python-comment-line-p) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
750 (let ((elt (assq (current-indentation) python-indent-list))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
751 (setq python-indent-list |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
752 (nconc (delete elt python-indent-list) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
753 (list elt)))))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
754 (caar (last python-indent-list))))))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
755 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
756 ;;;; Cycling through the possible indentations with successive TABs. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
757 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
758 ;; These don't need to be buffer-local since they're only relevant |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
759 ;; during a cycle. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
760 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
761 (defun python-initial-text () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
762 "Text of line following indentation and ignoring any trailing comment." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
763 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
764 (buffer-substring (progn |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
765 (back-to-indentation) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
766 (point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
767 (progn |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
768 (end-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
769 (forward-comment -1) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
770 (point))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
771 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
772 (defconst python-block-pairs |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
773 '(("else" "if" "elif" "while" "for" "try" "except") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
774 ("elif" "if" "elif") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
775 ("except" "try" "except") |
110115
fae81355c62c
* progmodes/python.el (python-block-pairs): Allow use of "finally" with "else" (Bug#3991).
Chong Yidong <cyd@stupidchicken.com>
parents:
109300
diff
changeset
|
776 ("finally" "else" "try" "except")) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
777 "Alist of keyword matches. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
778 The car of an element is a keyword introducing a statement which |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
779 can close a block opened by a keyword in the cdr.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
780 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
781 (defun python-first-word () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
782 "Return first word (actually symbol) on the line." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
783 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
784 (back-to-indentation) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
785 (current-word t))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
786 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
787 (defun python-indentation-levels () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
788 "Return a list of possible indentations for this line. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
789 It is assumed not to be a continuation line or in a multi-line string. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
790 Includes the default indentation and those which would close all |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
791 enclosing blocks. Elements of the list are actually pairs: |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
792 \(INDENTATION . TEXT), where TEXT is the initial text of the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
793 corresponding block opening (or nil)." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
794 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
795 (let ((initial "") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
796 levels indent) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
797 ;; Only one possibility immediately following a block open |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
798 ;; statement, assuming it doesn't have a `suite' on the same line. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
799 (cond |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
800 ((save-excursion (and (python-previous-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
801 (python-open-block-statement-p t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
802 (setq indent (current-indentation)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
803 ;; Check we don't have something like: |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
804 ;; if ...: ... |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
805 (if (progn (python-end-of-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
806 (python-skip-comments/blanks t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
807 (eq ?: (char-before))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
808 (setq indent (+ python-indent indent))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
809 (push (cons indent initial) levels)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
810 ;; Only one possibility for comment line immediately following |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
811 ;; another. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
812 ((save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
813 (when (python-comment-line-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
814 (forward-line -1) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
815 (if (python-comment-line-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
816 (push (cons (current-indentation) initial) levels))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
817 ;; Fixme: Maybe have a case here which indents (only) first |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
818 ;; line after a lambda. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
819 (t |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
820 (let ((start (car (assoc (python-first-word) python-block-pairs)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
821 (python-previous-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
822 ;; Is this a valid indentation for the line of interest? |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
823 (unless (or (if start ; potentially only outdentable |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
824 ;; Check for things like: |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
825 ;; if ...: ... |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
826 ;; else ...: |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
827 ;; where the second line need not be outdented. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
828 (not (member (python-first-word) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
829 (cdr (assoc start |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
830 python-block-pairs))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
831 ;; Not sensible to indent to the same level as |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
832 ;; previous `return' &c. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
833 (python-close-block-statement-p)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
834 (push (cons (current-indentation) (python-initial-text)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
835 levels)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
836 (while (python-beginning-of-block) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
837 (when (or (not start) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
838 (member (python-first-word) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
839 (cdr (assoc start python-block-pairs)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
840 (push (cons (current-indentation) (python-initial-text)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
841 levels)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
842 (prog1 (or levels (setq levels '((0 . "")))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
843 (setq python-indent-list levels |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
844 python-indent-list-length (length python-indent-list)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
845 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
846 ;; This is basically what `python-indent-line' would be if we didn't |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
847 ;; do the cycling. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
848 (defun python-indent-line-1 (&optional leave) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
849 "Subroutine of `python-indent-line'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
850 Does non-repeated indentation. LEAVE non-nil means leave |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
851 indentation if it is valid, i.e. one of the positions returned by |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
852 `python-calculate-indentation'." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
853 (let ((target (python-calculate-indentation)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
854 (pos (- (point-max) (point)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
855 (if (or (= target (current-indentation)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
856 ;; Maybe keep a valid indentation. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
857 (and leave python-indent-list |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
858 (assq (current-indentation) python-indent-list))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
859 (if (< (current-column) (current-indentation)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
860 (back-to-indentation)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
861 (beginning-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
862 (delete-horizontal-space) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
863 (indent-to target) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
864 (if (> (- (point-max) pos) (point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
865 (goto-char (- (point-max) pos)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
866 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
867 (defun python-indent-line () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
868 "Indent current line as Python code. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
869 When invoked via `indent-for-tab-command', cycle through possible |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
870 indentations for current line. The cycle is broken by a command |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
871 different from `indent-for-tab-command', i.e. successive TABs do |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
872 the cycling." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
873 (interactive) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
874 (if (and (eq this-command 'indent-for-tab-command) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
875 (eq last-command this-command)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
876 (if (= 1 python-indent-list-length) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
877 (message "Sole indentation") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
878 (progn (setq python-indent-index |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
879 (% (1+ python-indent-index) python-indent-list-length)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
880 (beginning-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
881 (delete-horizontal-space) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
882 (indent-to (car (nth python-indent-index python-indent-list))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
883 (if (python-block-end-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
884 (let ((text (cdr (nth python-indent-index |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
885 python-indent-list)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
886 (if text |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
887 (message "Closes: %s" text)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
888 (python-indent-line-1) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
889 (setq python-indent-index (1- python-indent-list-length)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
890 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
891 (defun python-indent-region (start end) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
892 "`indent-region-function' for Python. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
893 Leaves validly-indented lines alone, i.e. doesn't indent to |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
894 another valid position." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
895 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
896 (goto-char end) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
897 (setq end (point-marker)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
898 (goto-char start) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
899 (or (bolp) (forward-line 1)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
900 (while (< (point) end) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
901 (or (and (bolp) (eolp)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
902 (python-indent-line-1 t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
903 (forward-line 1)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
904 (move-marker end nil))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
905 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
906 (defun python-block-end-p () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
907 "Non-nil if this is a line in a statement closing a block, |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
908 or a blank line indented to where it would close a block." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
909 (and (not (python-comment-line-p)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
910 (or (python-close-block-statement-p t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
911 (< (current-indentation) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
912 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
913 (python-previous-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
914 (current-indentation)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
915 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
916 ;;;; Movement. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
917 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
918 ;; Fixme: Define {for,back}ward-sexp-function? Maybe skip units like |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
919 ;; block, statement, depending on context. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
920 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
921 (defun python-beginning-of-defun () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
922 "`beginning-of-defun-function' for Python. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
923 Finds beginning of innermost nested class or method definition. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
924 Returns the name of the definition found at the end, or nil if |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
925 reached start of buffer." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
926 (let ((ci (current-indentation)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
927 (def-re (rx line-start (0+ space) (or "def" "class") (1+ space) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
928 (group (1+ (or word (syntax symbol)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
929 found lep) ;; def-line |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
930 (if (python-comment-line-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
931 (setq ci most-positive-fixnum)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
932 (while (and (not (bobp)) (not found)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
933 ;; Treat bol at beginning of function as outside function so |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
934 ;; that successive C-M-a makes progress backwards. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
935 ;;(setq def-line (looking-at def-re)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
936 (unless (bolp) (end-of-line)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
937 (setq lep (line-end-position)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
938 (if (and (re-search-backward def-re nil 'move) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
939 ;; Must be less indented or matching top level, or |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
940 ;; equally indented if we started on a definition line. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
941 (let ((in (current-indentation))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
942 (or (and (zerop ci) (zerop in)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
943 (= lep (line-end-position)) ; on initial line |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
944 ;; Not sure why it was like this -- fails in case of |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
945 ;; last internal function followed by first |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
946 ;; non-def statement of the main body. |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
947 ;; (and def-line (= in ci)) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
948 (= in ci) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
949 (< in ci))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
950 (not (python-in-string/comment))) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
951 (setq found t))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
952 found)) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
953 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
954 (defun python-end-of-defun () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
955 "`end-of-defun-function' for Python. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
956 Finds end of innermost nested class or method definition." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
957 (let ((orig (point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
958 (pattern (rx line-start (0+ space) (or "def" "class") space))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
959 ;; Go to start of current block and check whether it's at top |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
960 ;; level. If it is, and not a block start, look forward for |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
961 ;; definition statement. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
962 (when (python-comment-line-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
963 (end-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
964 (forward-comment most-positive-fixnum)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
965 (if (not (python-open-block-statement-p)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
966 (python-beginning-of-block)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
967 (if (zerop (current-indentation)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
968 (unless (python-open-block-statement-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
969 (while (and (re-search-forward pattern nil 'move) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
970 (python-in-string/comment))) ; just loop |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
971 (unless (eobp) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
972 (beginning-of-line))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
973 ;; Don't move before top-level statement that would end defun. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
974 (end-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
975 (python-beginning-of-defun)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
976 ;; If we got to the start of buffer, look forward for |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
977 ;; definition statement. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
978 (if (and (bobp) (not (looking-at "def\\|class"))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
979 (while (and (not (eobp)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
980 (re-search-forward pattern nil 'move) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
981 (python-in-string/comment)))) ; just loop |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
982 ;; We're at a definition statement (or end-of-buffer). |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
983 (unless (eobp) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
984 (python-end-of-block) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
985 ;; Count trailing space in defun (but not trailing comments). |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
986 (skip-syntax-forward " >") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
987 (unless (eobp) ; e.g. missing final newline |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
988 (beginning-of-line))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
989 ;; Catch pathological cases like this, where the beginning-of-defun |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
990 ;; skips to a definition we're not in: |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
991 ;; if ...: |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
992 ;; ... |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
993 ;; else: |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
994 ;; ... # point here |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
995 ;; ... |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
996 ;; def ... |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
997 (if (< (point) orig) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
998 (goto-char (point-max))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
999 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1000 (defun python-beginning-of-statement () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1001 "Go to start of current statement. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1002 Accounts for continuation lines, multi-line strings, and |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1003 multi-line bracketed expressions." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1004 (beginning-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1005 (python-beginning-of-string) |
94590 | 1006 (let (point) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1007 (while (and (python-continuation-line-p) |
94590 | 1008 (if point |
1009 (< (point) point) | |
1010 t)) | |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1011 (beginning-of-line) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1012 (if (python-backslash-continuation-line-p) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1013 (progn |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1014 (forward-line -1) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1015 (while (python-backslash-continuation-line-p) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1016 (forward-line -1))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1017 (python-beginning-of-string) |
94590 | 1018 (python-skip-out)) |
1019 (setq point (point)))) | |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1020 (back-to-indentation)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1021 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1022 (defun python-skip-out (&optional forward syntax) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1023 "Skip out of any nested brackets. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1024 Skip forward if FORWARD is non-nil, else backward. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1025 If SYNTAX is non-nil it is the state returned by `syntax-ppss' at point. |
94740
464e6f78f756
(python-comment-line-p, python-blank-line-p, python-skip-out,
Juanma Barranquero <lekktu@gmail.com>
parents:
94673
diff
changeset
|
1026 Return non-nil if and only if skipping was done." |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1027 (let ((depth (syntax-ppss-depth (or syntax (syntax-ppss)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1028 (forward (if forward -1 1))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1029 (unless (zerop depth) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1030 (if (> depth 0) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1031 ;; Skip forward out of nested brackets. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1032 (condition-case () ; beware invalid syntax |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1033 (progn (backward-up-list (* forward depth)) t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1034 (error nil)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1035 ;; Invalid syntax (too many closed brackets). |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1036 ;; Skip out of as many as possible. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1037 (let (done) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1038 (while (condition-case () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1039 (progn (backward-up-list forward) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1040 (setq done t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1041 (error nil))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1042 done))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1043 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1044 (defun python-end-of-statement () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1045 "Go to the end of the current statement and return point. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1046 Usually this is the start of the next line, but if this is a |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1047 multi-line statement we need to skip over the continuation lines. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1048 On a comment line, go to end of line." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1049 (end-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1050 (while (let (comment) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1051 ;; Move past any enclosing strings and sexps, or stop if |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1052 ;; we're in a comment. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1053 (while (let ((s (syntax-ppss))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1054 (cond ((eq 'comment (syntax-ppss-context s)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1055 (setq comment t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1056 nil) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1057 ((eq 'string (syntax-ppss-context s)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1058 ;; Go to start of string and skip it. |
80881
4882ec1204fb
(python-end-of-block): Revert last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
80874
diff
changeset
|
1059 (let ((pos (point))) |
4882ec1204fb
(python-end-of-block): Revert last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
80874
diff
changeset
|
1060 (goto-char (nth 8 s)) |
4882ec1204fb
(python-end-of-block): Revert last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
80874
diff
changeset
|
1061 (condition-case () ; beware invalid syntax |
4882ec1204fb
(python-end-of-block): Revert last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
80874
diff
changeset
|
1062 (progn (forward-sexp) t) |
4882ec1204fb
(python-end-of-block): Revert last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
80874
diff
changeset
|
1063 ;; If there's a mismatched string, make sure |
4882ec1204fb
(python-end-of-block): Revert last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
80874
diff
changeset
|
1064 ;; we still overall move *forward*. |
4882ec1204fb
(python-end-of-block): Revert last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
80874
diff
changeset
|
1065 (error (goto-char pos) (end-of-line))))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1066 ((python-skip-out t s)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1067 (end-of-line)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1068 (unless comment |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1069 (eq ?\\ (char-before)))) ; Line continued? |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1070 (end-of-line 2)) ; Try next line. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1071 (point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1072 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1073 (defun python-previous-statement (&optional count) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1074 "Go to start of previous statement. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1075 With argument COUNT, do it COUNT times. Stop at beginning of buffer. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1076 Return count of statements left to move." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1077 (interactive "p") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1078 (unless count (setq count 1)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1079 (if (< count 0) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1080 (python-next-statement (- count)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1081 (python-beginning-of-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1082 (while (and (> count 0) (not (bobp))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1083 (python-skip-comments/blanks t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1084 (python-beginning-of-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1085 (unless (bobp) (setq count (1- count)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1086 count)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1087 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1088 (defun python-next-statement (&optional count) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1089 "Go to start of next statement. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1090 With argument COUNT, do it COUNT times. Stop at end of buffer. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1091 Return count of statements left to move." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1092 (interactive "p") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1093 (unless count (setq count 1)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1094 (if (< count 0) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1095 (python-previous-statement (- count)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1096 (beginning-of-line) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1097 (let (bogus) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1098 (while (and (> count 0) (not (eobp)) (not bogus)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1099 (python-end-of-statement) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1100 (python-skip-comments/blanks) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1101 (if (eq 'string (syntax-ppss-context (syntax-ppss))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1102 (setq bogus t) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1103 (unless (eobp) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1104 (setq count (1- count)))))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1105 count)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1106 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1107 (defun python-beginning-of-block (&optional arg) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1108 "Go to start of current block. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1109 With numeric arg, do it that many times. If ARG is negative, call |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1110 `python-end-of-block' instead. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1111 If point is on the first line of a block, use its outer block. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1112 If current statement is in column zero, don't move and return nil. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1113 Otherwise return non-nil." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1114 (interactive "p") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1115 (unless arg (setq arg 1)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1116 (cond |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1117 ((zerop arg)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1118 ((< arg 0) (python-end-of-block (- arg))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1119 (t |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1120 (let ((point (point))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1121 (if (or (python-comment-line-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1122 (python-blank-line-p)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1123 (python-skip-comments/blanks t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1124 (python-beginning-of-statement) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1125 (let ((ci (current-indentation))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1126 (if (zerop ci) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1127 (not (goto-char point)) ; return nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1128 ;; Look upwards for less indented statement. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1129 (if (catch 'done |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1130 ;;; This is slower than the below. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1131 ;;; (while (zerop (python-previous-statement)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1132 ;;; (when (and (< (current-indentation) ci) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1133 ;;; (python-open-block-statement-p t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1134 ;;; (beginning-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1135 ;;; (throw 'done t))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1136 (while (and (zerop (forward-line -1))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1137 (when (and (< (current-indentation) ci) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1138 (not (python-comment-line-p)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1139 ;; Move to beginning to save effort in case |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1140 ;; this is in string. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1141 (progn (python-beginning-of-statement) t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1142 (python-open-block-statement-p t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1143 (beginning-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1144 (throw 'done t))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1145 (not (goto-char point))) ; Failed -- return nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1146 (python-beginning-of-block (1- arg))))))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1147 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1148 (defun python-end-of-block (&optional arg) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1149 "Go to end of current block. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1150 With numeric arg, do it that many times. If ARG is negative, |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1151 call `python-beginning-of-block' instead. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1152 If current statement is in column zero and doesn't open a block, |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1153 don't move and return nil. Otherwise return t." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1154 (interactive "p") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1155 (unless arg (setq arg 1)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1156 (if (< arg 0) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1157 (python-beginning-of-block (- arg)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1158 (while (and (> arg 0) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1159 (let* ((point (point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1160 (_ (if (python-comment-line-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1161 (python-skip-comments/blanks t))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1162 (ci (current-indentation)) |
80881
4882ec1204fb
(python-end-of-block): Revert last change.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
80874
diff
changeset
|
1163 (open (python-open-block-statement-p))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1164 (if (and (zerop ci) (not open)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1165 (not (goto-char point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1166 (catch 'done |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1167 (while (zerop (python-next-statement)) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1168 (when (or (and open (<= (current-indentation) ci)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1169 (< (current-indentation) ci)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1170 (python-skip-comments/blanks t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1171 (beginning-of-line 2) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1172 (throw 'done t))))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1173 (setq arg (1- arg))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1174 (zerop arg))) |
81824
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
1175 |
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
1176 (defvar python-which-func-length-limit 40 |
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
1177 "Non-strict length limit for `python-which-func' output.") |
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
1178 |
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
1179 (defun python-which-func () |
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
1180 (let ((function-name (python-current-defun python-which-func-length-limit))) |
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
1181 (set-text-properties 0 (length function-name) nil function-name) |
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
1182 function-name)) |
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
1183 |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1184 |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1185 ;;;; Imenu. |
82224
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
1186 |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1187 ;; For possibily speeding this up, here's the top of the ELP profile |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1188 ;; for rescanning pydoc.py (2.2k lines, 90kb): |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1189 ;; Function Name Call Count Elapsed Time Average Time |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1190 ;; ==================================== ========== ============= ============ |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1191 ;; python-imenu-create-index 156 2.430906 0.0155827307 |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1192 ;; python-end-of-defun 155 1.2718260000 0.0082053290 |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1193 ;; python-end-of-block 155 1.1898689999 0.0076765741 |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1194 ;; python-next-statement 2970 1.024717 0.0003450225 |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1195 ;; python-end-of-statement 2970 0.4332190000 0.0001458649 |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1196 ;; python-beginning-of-defun 265 0.0918479999 0.0003465962 |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1197 ;; python-skip-comments/blanks 3125 0.0753319999 2.410...e-05 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1198 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1199 (defvar python-recursing) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1200 (defun python-imenu-create-index () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1201 "`imenu-create-index-function' for Python. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1202 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1203 Makes nested Imenu menus from nested `class' and `def' statements. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1204 The nested menus are headed by an item referencing the outer |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1205 definition; it has a space prepended to the name so that it sorts |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1206 first with `imenu--sort-by-name' (though, unfortunately, sub-menus |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1207 precede it)." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1208 (unless (boundp 'python-recursing) ; dynamically bound below |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1209 ;; Normal call from Imenu. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1210 (goto-char (point-min)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1211 ;; Without this, we can get an infloop if the buffer isn't all |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1212 ;; fontified. I guess this is really a bug in syntax.el. OTOH, |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1213 ;; _with_ this, imenu doesn't immediately work; I can't figure out |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1214 ;; what's going on, but it must be something to do with timers in |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1215 ;; font-lock. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1216 ;; This can't be right, especially not when jit-lock is not used. --Stef |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1217 ;; (unless (get-text-property (1- (point-max)) 'fontified) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1218 ;; (font-lock-fontify-region (point-min) (point-max))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1219 ) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1220 (let (index-alist) ; accumulated value to return |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1221 (while (re-search-forward |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1222 (rx line-start (0+ space) ; leading space |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1223 (or (group "def") (group "class")) ; type |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1224 (1+ space) (group (1+ (or word ?_)))) ; name |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1225 nil t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1226 (unless (python-in-string/comment) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1227 (let ((pos (match-beginning 0)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1228 (name (match-string-no-properties 3))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1229 (if (match-beginning 2) ; def or class? |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1230 (setq name (concat "class " name))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1231 (save-restriction |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1232 (narrow-to-defun) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1233 (let* ((python-recursing t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1234 (sublist (python-imenu-create-index))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1235 (if sublist |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1236 (progn (push (cons (concat " " name) pos) sublist) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1237 (push (cons name sublist) index-alist)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1238 (push (cons name pos) index-alist))))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1239 (unless (boundp 'python-recursing) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1240 ;; Look for module variables. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1241 (let (vars) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1242 (goto-char (point-min)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1243 (while (re-search-forward |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1244 (rx line-start (group (1+ (or word ?_))) (0+ space) "=") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1245 nil t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1246 (unless (python-in-string/comment) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1247 (push (cons (match-string 1) (match-beginning 1)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1248 vars))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1249 (setq index-alist (nreverse index-alist)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1250 (if vars |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1251 (push (cons "Module variables" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1252 (nreverse vars)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1253 index-alist)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1254 index-alist)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1255 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1256 ;;;; `Electric' commands. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1257 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1258 (defun python-electric-colon (arg) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1259 "Insert a colon and maybe outdent the line if it is a statement like `else'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1260 With numeric ARG, just insert that many colons. With \\[universal-argument], |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1261 just insert a single colon." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1262 (interactive "*P") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1263 (self-insert-command (if (not (integerp arg)) 1 arg)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1264 (and (not arg) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1265 (eolp) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1266 (python-outdent-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1267 (not (python-in-string/comment)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1268 (> (current-indentation) (python-calculate-indentation)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1269 (python-indent-line))) ; OK, do it |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1270 (put 'python-electric-colon 'delete-selection t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1271 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1272 (defun python-backspace (arg) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1273 "Maybe delete a level of indentation on the current line. |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
1274 Do so if point is at the end of the line's indentation outside |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
1275 strings and comments. |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1276 Otherwise just call `backward-delete-char-untabify'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1277 Repeat ARG times." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1278 (interactive "*p") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1279 (if (or (/= (current-indentation) (current-column)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1280 (bolp) |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
1281 (python-continuation-line-p) |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
1282 (python-in-string/comment)) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1283 (backward-delete-char-untabify arg) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1284 ;; Look for the largest valid indentation which is smaller than |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1285 ;; the current indentation. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1286 (let ((indent 0) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1287 (ci (current-indentation)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1288 (indents (python-indentation-levels)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1289 initial) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1290 (dolist (x indents) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1291 (if (< (car x) ci) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1292 (setq indent (max indent (car x))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1293 (setq initial (cdr (assq indent indents))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1294 (if (> (length initial) 0) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1295 (message "Closes %s" initial)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1296 (delete-horizontal-space) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1297 (indent-to indent)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1298 (put 'python-backspace 'delete-selection 'supersede) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1299 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1300 ;;;; pychecker |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1301 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1302 (defcustom python-check-command "pychecker --stdlib" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1303 "Command used to check a Python file." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1304 :type 'string |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1305 :group 'python) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1306 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1307 (defvar python-saved-check-command nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1308 "Internal use.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1309 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1310 ;; After `sgml-validate-command'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1311 (defun python-check (command) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1312 "Check a Python file (default current buffer's file). |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1313 Runs COMMAND, a shell command, as if by `compile'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1314 See `python-check-command' for the default." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1315 (interactive |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1316 (list (read-string "Checker command: " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1317 (or python-saved-check-command |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1318 (concat python-check-command " " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1319 (let ((name (buffer-file-name))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1320 (if name |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1321 (file-name-nondirectory name)))))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1322 (setq python-saved-check-command command) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1323 (require 'compile) ;To define compilation-* variables. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1324 (save-some-buffers (not compilation-ask-about-save) nil) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1325 (let ((compilation-error-regexp-alist |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1326 (cons '("(\\([^,]+\\), line \\([0-9]+\\))" 1 2) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1327 compilation-error-regexp-alist))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1328 (compilation-start command))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1329 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1330 ;;;; Inferior mode stuff (following cmuscheme). |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1331 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1332 (defcustom python-python-command "python" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1333 "Shell command to run Python interpreter. |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1334 Any arguments can't contain whitespace." |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1335 :group 'python |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1336 :type 'string) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1337 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1338 (defcustom python-jython-command "jython" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1339 "Shell command to run Jython interpreter. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1340 Any arguments can't contain whitespace." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1341 :group 'python |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1342 :type 'string) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1343 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1344 (defvar python-command python-python-command |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1345 "Actual command used to run Python. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1346 May be `python-python-command' or `python-jython-command', possibly |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1347 modified by the user. Additional arguments are added when the command |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1348 is used by `run-python' et al.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1349 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1350 (defvar python-buffer nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1351 "*The current Python process buffer. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1352 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1353 Commands that send text from source buffers to Python processes have |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1354 to choose a process to send to. This is determined by buffer-local |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1355 value of `python-buffer'. If its value in the current buffer, |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1356 i.e. both any local value and the default one, is nil, `run-python' |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1357 and commands that send to the Python process will start a new process. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1358 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1359 Whenever \\[run-python] starts a new process, it resets the default |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1360 value of `python-buffer' to be the new process's buffer and sets the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1361 buffer-local value similarly if the current buffer is in Python mode |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1362 or Inferior Python mode, so that source buffer stays associated with a |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1363 specific sub-process. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1364 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1365 Use \\[python-set-proc] to set the default value from a buffer with a |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1366 local value.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1367 (make-variable-buffer-local 'python-buffer) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1368 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1369 (defconst python-compilation-regexp-alist |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1370 ;; FIXME: maybe these should move to compilation-error-regexp-alist-alist. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1371 ;; The first already is (for CAML), but the second isn't. Anyhow, |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1372 ;; these are specific to the inferior buffer. -- fx |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1373 `((,(rx line-start (1+ (any " \t")) "File \"" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1374 (group (1+ (not (any "\"<")))) ; avoid `<stdin>' &c |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1375 "\", line " (group (1+ digit))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1376 1 2) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1377 (,(rx " in file " (group (1+ not-newline)) " on line " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1378 (group (1+ digit))) |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
1379 1 2) |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
1380 ;; pdb stack trace |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
1381 (,(rx line-start "> " (group (1+ (not (any "(\"<")))) |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
1382 "(" (group (1+ digit)) ")" (1+ (not (any "("))) "()") |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1383 1 2)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1384 "`compilation-error-regexp-alist' for inferior Python.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1385 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1386 (defvar inferior-python-mode-map |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1387 (let ((map (make-sparse-keymap))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1388 ;; This will inherit from comint-mode-map. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1389 (define-key map "\C-c\C-l" 'python-load-file) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1390 (define-key map "\C-c\C-v" 'python-check) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1391 ;; Note that we _can_ still use these commands which send to the |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
1392 ;; Python process even at the prompt iff we have a normal prompt, |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1393 ;; i.e. '>>> ' and not '... '. See the comment before |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1394 ;; python-send-region. Fixme: uncomment these if we address that. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1395 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1396 ;; (define-key map [(meta ?\t)] 'python-complete-symbol) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1397 ;; (define-key map "\C-c\C-f" 'python-describe-symbol) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1398 map)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1399 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1400 (defvar inferior-python-mode-syntax-table |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1401 (let ((st (make-syntax-table python-mode-syntax-table))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1402 ;; Don't get confused by apostrophes in the process's output (e.g. if |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1403 ;; you execute "help(os)"). |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1404 (modify-syntax-entry ?\' "." st) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1405 ;; Maybe we should do the same for double quotes? |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1406 ;; (modify-syntax-entry ?\" "." st) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1407 st)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1408 |
87057
309e0523903f
(compilation-shell-minor-mode): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86970
diff
changeset
|
1409 ;; Autoloaded. |
309e0523903f
(compilation-shell-minor-mode): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86970
diff
changeset
|
1410 (declare-function compilation-shell-minor-mode "compile" (&optional arg)) |
309e0523903f
(compilation-shell-minor-mode): Declare as a function.
Glenn Morris <rgm@gnu.org>
parents:
86970
diff
changeset
|
1411 |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1412 (defvar python--prompt-regexp nil) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1413 |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1414 (defun python--set-prompt-regexp () |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1415 (let ((prompt (cdr-safe (or (assoc python-python-command |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1416 python-shell-prompt-alist) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1417 (assq t python-shell-prompt-alist)))) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1418 (cprompt (cdr-safe (or (assoc python-python-command |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1419 python-shell-continuation-prompt-alist) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1420 (assq t python-shell-continuation-prompt-alist))))) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1421 (set (make-local-variable 'comint-prompt-regexp) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1422 (concat "\\(" |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1423 (mapconcat 'identity |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1424 (delq nil (list prompt cprompt "^([Pp]db) ")) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1425 "\\|") |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1426 "\\)")) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1427 (set (make-local-variable 'python--prompt-regexp) prompt))) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1428 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1429 ;; Fixme: This should inherit some stuff from `python-mode', but I'm |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1430 ;; not sure how much: at least some keybindings, like C-c C-f; |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1431 ;; syntax?; font-locking, e.g. for triple-quoted strings? |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1432 (define-derived-mode inferior-python-mode comint-mode "Inferior Python" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1433 "Major mode for interacting with an inferior Python process. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1434 A Python process can be started with \\[run-python]. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1435 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1436 Hooks `comint-mode-hook' and `inferior-python-mode-hook' are run in |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1437 that order. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1438 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1439 You can send text to the inferior Python process from other buffers |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1440 containing Python source. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1441 * \\[python-switch-to-python] switches the current buffer to the Python |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1442 process buffer. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1443 * \\[python-send-region] sends the current region to the Python process. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1444 * \\[python-send-region-and-go] switches to the Python process buffer |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1445 after sending the text. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1446 For running multiple processes in multiple buffers, see `run-python' and |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1447 `python-buffer'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1448 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1449 \\{inferior-python-mode-map}" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1450 :group 'python |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1451 (require 'ansi-color) ; for ipython |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1452 (setq mode-line-process '(":%s")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1453 (set (make-local-variable 'comint-input-filter) 'python-input-filter) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1454 (add-hook 'comint-preoutput-filter-functions #'python-preoutput-filter |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1455 nil t) |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1456 (python--set-prompt-regexp) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1457 (set (make-local-variable 'compilation-error-regexp-alist) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1458 python-compilation-regexp-alist) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1459 (compilation-shell-minor-mode 1)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1460 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1461 (defcustom inferior-python-filter-regexp "\\`\\s-*\\S-?\\S-?\\s-*\\'" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1462 "Input matching this regexp is not saved on the history list. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1463 Default ignores all inputs of 0, 1, or 2 non-blank characters." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1464 :type 'regexp |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1465 :group 'python) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1466 |
111752
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1467 (defcustom python-remove-cwd-from-path t |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1468 "Whether to allow loading of Python modules from the current directory. |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1469 If this is non-nil, Emacs removes '' from sys.path when starting |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1470 an inferior Python process. This is the default, for security |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1471 reasons, as it is easy for the Python process to be started |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1472 without the user's realization (e.g. to perform completion)." |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1473 :type 'boolean |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1474 :group 'python |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1475 :version "23.3") |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1476 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1477 (defun python-input-filter (str) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1478 "`comint-input-filter' function for inferior Python. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1479 Don't save anything for STR matching `inferior-python-filter-regexp'." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1480 (not (string-match inferior-python-filter-regexp str))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1481 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1482 ;; Fixme: Loses with quoted whitespace. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1483 (defun python-args-to-list (string) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1484 (let ((where (string-match "[ \t]" string))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1485 (cond ((null where) (list string)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1486 ((not (= where 0)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1487 (cons (substring string 0 where) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1488 (python-args-to-list (substring string (+ 1 where))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1489 (t (let ((pos (string-match "[^ \t]" string))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1490 (if pos (python-args-to-list (substring string pos)))))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1491 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1492 (defvar python-preoutput-result nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1493 "Data from last `_emacs_out' line seen by the preoutput filter.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1494 |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1495 (defvar python-preoutput-continuation nil |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1496 "If non-nil, funcall this when `python-preoutput-filter' sees `_emacs_ok'.") |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1497 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1498 (defvar python-preoutput-leftover nil) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1499 (defvar python-preoutput-skip-next-prompt nil) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1500 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1501 ;; Using this stops us getting lines in the buffer like |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1502 ;; >>> ... ... >>> |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1503 ;; Also look for (and delete) an `_emacs_ok' string and call |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1504 ;; `python-preoutput-continuation' if we get it. |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1505 (defun python-preoutput-filter (s) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1506 "`comint-preoutput-filter-functions' function: ignore prompts not at bol." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1507 (when python-preoutput-leftover |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1508 (setq s (concat python-preoutput-leftover s)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1509 (setq python-preoutput-leftover nil)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1510 (let ((start 0) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1511 (res "")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1512 ;; First process whole lines. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1513 (while (string-match "\n" s start) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1514 (let ((line (substring s start (setq start (match-end 0))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1515 ;; Skip prompt if needed. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1516 (when (and python-preoutput-skip-next-prompt |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1517 (string-match comint-prompt-regexp line)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1518 (setq python-preoutput-skip-next-prompt nil) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1519 (setq line (substring line (match-end 0)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1520 ;; Recognize special _emacs_out lines. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1521 (if (and (string-match "\\`_emacs_out \\(.*\\)\n\\'" line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1522 (local-variable-p 'python-preoutput-result)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1523 (progn |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1524 (setq python-preoutput-result (match-string 1 line)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1525 (set (make-local-variable 'python-preoutput-skip-next-prompt) t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1526 (setq res (concat res line))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1527 ;; Then process the remaining partial line. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1528 (unless (zerop start) (setq s (substring s start))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1529 (cond ((and (string-match comint-prompt-regexp s) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1530 ;; Drop this prompt if it follows an _emacs_out... |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1531 (or python-preoutput-skip-next-prompt |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1532 ;; ... or if it's not gonna be inserted at BOL. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1533 ;; Maybe we could be more selective here. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1534 (if (zerop (length res)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1535 (not (bolp)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1536 (string-match ".\\'" res)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1537 ;; The need for this seems to be system-dependent: |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1538 ;; What is this all about, exactly? --Stef |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1539 ;; (if (and (eq ?. (aref s 0))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1540 ;; (accept-process-output (get-buffer-process (current-buffer)) 1)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1541 (setq python-preoutput-skip-next-prompt nil) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1542 res) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1543 ((let ((end (min (length "_emacs_out ") (length s)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1544 (eq t (compare-strings s nil end "_emacs_out " nil end))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1545 ;; The leftover string is a prefix of _emacs_out so we don't know |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1546 ;; yet whether it's an _emacs_out or something else: wait until we |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1547 ;; get more output so we can resolve this ambiguity. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1548 (set (make-local-variable 'python-preoutput-leftover) s) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1549 res) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1550 (t (concat res s))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1551 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1552 (autoload 'comint-check-proc "comint") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1553 |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1554 (defvar python-version-checked nil) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1555 (defun python-check-version (cmd) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1556 "Check that CMD runs a suitable version of Python." |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1557 ;; Fixme: Check on Jython. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1558 (unless (or python-version-checked |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1559 (equal 0 (string-match (regexp-quote python-python-command) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1560 cmd))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1561 (unless (shell-command-to-string cmd) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1562 (error "Can't run Python command `%s'" cmd)) |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1563 (let* ((res (shell-command-to-string |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1564 (concat cmd |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1565 " -c \"from sys import version_info;\ |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1566 print version_info >= (2, 2) and version_info < (3, 0)\"")))) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1567 (unless (string-match "True" res) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1568 (error "Only Python versions >= 2.2 and < 3.0 are supported"))) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1569 (setq python-version-checked t))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1570 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1571 ;;;###autoload |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1572 (defun run-python (&optional cmd noshow new) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1573 "Run an inferior Python process, input and output via buffer *Python*. |
111752
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1574 CMD is the Python command to run. NOSHOW non-nil means don't |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1575 show the buffer automatically. |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1576 |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1577 Interactively, a prefix arg means to prompt for the initial |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1578 Python command line (default is `python-command'). |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1579 |
111752
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1580 A new process is started if one isn't running attached to |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1581 `python-buffer', or if called from Lisp with non-nil arg NEW. |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1582 Otherwise, if a process is already running in `python-buffer', |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1583 switch to that buffer. |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1584 |
111752
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1585 This command runs the hook `inferior-python-mode-hook' after |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1586 running `comint-mode-hook'. Type \\[describe-mode] in the |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1587 process buffer for a list of commands. |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1588 |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1589 By default, Emacs inhibits the loading of Python modules from the |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1590 current working directory, for security reasons. To disable this |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1591 behavior, change `python-remove-cwd-from-path' to nil." |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1592 (interactive (if current-prefix-arg |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1593 (list (read-string "Run Python: " python-command) nil t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1594 (list python-command))) |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1595 (require 'ansi-color) ; for ipython |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1596 (unless cmd (setq cmd python-command)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1597 (python-check-version cmd) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1598 (setq python-command cmd) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1599 ;; Fixme: Consider making `python-buffer' buffer-local as a buffer |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1600 ;; (not a name) in Python buffers from which `run-python' &c is |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1601 ;; invoked. Would support multiple processes better. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1602 (when (or new (not (comint-check-proc python-buffer))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1603 (with-current-buffer |
97689
5f56382dc026
(run-python): Remove '' from sys.path.
Romain Francoise <romain@orebokech.com>
parents:
94740
diff
changeset
|
1604 (let* ((cmdlist |
111752
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1605 (append (python-args-to-list cmd) '("-i") |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1606 (if python-remove-cwd-from-path |
3776ded7f730
Make the sys.path remove in Python mode customizable (Bug#7454).
Chong Yidong <cyd@stupidchicken.com>
parents:
111750
diff
changeset
|
1607 '("-c" "import sys; sys.path.remove('')")))) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1608 (path (getenv "PYTHONPATH")) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1609 (process-environment ; to import emacs.py |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1610 (cons (concat "PYTHONPATH=" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1611 (if path (concat path path-separator)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1612 data-directory) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1613 process-environment)) |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1614 ;; If we use a pipe, unicode characters are not printed |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1615 ;; correctly (Bug#5794) and IPython does not work at |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1616 ;; all (Bug#5390). |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1617 (process-connection-type t)) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1618 (apply 'make-comint-in-buffer "Python" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1619 (generate-new-buffer "*Python*") |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1620 (car cmdlist) nil (cdr cmdlist))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1621 (setq-default python-buffer (current-buffer)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1622 (setq python-buffer (current-buffer)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1623 (accept-process-output (get-buffer-process python-buffer) 5) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1624 (inferior-python-mode) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1625 ;; Load function definitions we need. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1626 ;; Before the preoutput function was used, this was done via -c in |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1627 ;; cmdlist, but that loses the banner and doesn't run the startup |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1628 ;; file. The code might be inline here, but there's enough that it |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1629 ;; seems worth putting in a separate file, and it's probably cleaner |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1630 ;; to put it in a module. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1631 ;; Ensure we're at a prompt before doing anything else. |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1632 (python-send-string "import emacs") |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1633 ;; The following line was meant to ensure that we're at a prompt |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1634 ;; before doing anything else. However, this can cause Emacs to |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1635 ;; hang waiting for a response, if that Python function fails |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1636 ;; (i.e. raises an exception). |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1637 ;; (python-send-receive "print '_emacs_out ()'") |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1638 )) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1639 (if (derived-mode-p 'python-mode) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1640 (setq python-buffer (default-value 'python-buffer))) ; buffer-local |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1641 ;; Without this, help output goes into the inferior python buffer if |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1642 ;; the process isn't already running. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1643 (sit-for 1 t) ;Should we use accept-process-output instead? --Stef |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1644 (unless noshow (pop-to-buffer python-buffer t))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1645 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1646 (defun python-send-command (command) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1647 "Like `python-send-string' but resets `compilation-shell-minor-mode'." |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1648 (when (python-check-comint-prompt) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1649 (with-current-buffer (process-buffer (python-proc)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1650 (goto-char (point-max)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1651 (compilation-forget-errors) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1652 (python-send-string command) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1653 (setq compilation-last-buffer (current-buffer))))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1654 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1655 (defun python-send-region (start end) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1656 "Send the region to the inferior Python process." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1657 ;; The region is evaluated from a temporary file. This avoids |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1658 ;; problems with blank lines, which have different semantics |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1659 ;; interactively and in files. It also saves the inferior process |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1660 ;; buffer filling up with interpreter prompts. We need a Python |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1661 ;; function to remove the temporary file when it has been evaluated |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1662 ;; (though we could probably do it in Lisp with a Comint output |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1663 ;; filter). This function also catches exceptions and truncates |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1664 ;; tracebacks not to mention the frame of the function itself. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1665 ;; |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1666 ;; The `compilation-shell-minor-mode' parsing takes care of relating |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1667 ;; the reference to the temporary file to the source. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1668 ;; |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1669 ;; Fixme: Write a `coding' header to the temp file if the region is |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1670 ;; non-ASCII. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1671 (interactive "r") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1672 (let* ((f (make-temp-file "py")) |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1673 (command |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1674 ;; IPython puts the FakeModule module into __main__ so |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1675 ;; emacs.eexecfile becomes useless. |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1676 (if (string-match "^ipython" python-command) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1677 (format "execfile %S" f) |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1678 (format "emacs.eexecfile(%S)" f))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1679 (orig-start (copy-marker start))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1680 (when (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1681 (goto-char start) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1682 (/= 0 (current-indentation))) ; need dummy block |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1683 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1684 (goto-char orig-start) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1685 ;; Wrong if we had indented code at buffer start. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1686 (set-marker orig-start (line-beginning-position 0))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1687 (write-region "if True:\n" nil f nil 'nomsg)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1688 (write-region start end f t 'nomsg) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1689 (python-send-command command) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1690 (with-current-buffer (process-buffer (python-proc)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1691 ;; Tell compile.el to redirect error locations in file `f' to |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1692 ;; positions past marker `orig-start'. It has to be done *after* |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1693 ;; `python-send-command''s call to `compilation-forget-errors'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1694 (compilation-fake-loc orig-start f)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1695 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1696 (defun python-send-string (string) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1697 "Evaluate STRING in inferior Python process." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1698 (interactive "sPython command: ") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1699 (comint-send-string (python-proc) string) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1700 (unless (string-match "\n\\'" string) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1701 ;; Make sure the text is properly LF-terminated. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1702 (comint-send-string (python-proc) "\n")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1703 (when (string-match "\n[ \t].*\n?\\'" string) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1704 ;; If the string contains a final indented line, add a second newline so |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1705 ;; as to make sure we terminate the multiline instruction. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1706 (comint-send-string (python-proc) "\n"))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1707 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1708 (defun python-send-buffer () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1709 "Send the current buffer to the inferior Python process." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1710 (interactive) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1711 (python-send-region (point-min) (point-max))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1712 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1713 ;; Fixme: Try to define the function or class within the relevant |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1714 ;; module, not just at top level. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1715 (defun python-send-defun () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1716 "Send the current defun (class or method) to the inferior Python process." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1717 (interactive) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1718 (save-excursion (python-send-region (progn (beginning-of-defun) (point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1719 (progn (end-of-defun) (point))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1720 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1721 (defun python-switch-to-python (eob-p) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1722 "Switch to the Python process buffer, maybe starting new process. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1723 With prefix arg, position cursor at end of buffer." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1724 (interactive "P") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1725 (pop-to-buffer (process-buffer (python-proc)) t) ;Runs python if needed. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1726 (when eob-p |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1727 (push-mark) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1728 (goto-char (point-max)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1729 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1730 (defun python-send-region-and-go (start end) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1731 "Send the region to the inferior Python process. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1732 Then switch to the process buffer." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1733 (interactive "r") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1734 (python-send-region start end) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1735 (python-switch-to-python t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1736 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1737 (defcustom python-source-modes '(python-mode jython-mode) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1738 "Used to determine if a buffer contains Python source code. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1739 If a file is loaded into a buffer that is in one of these major modes, |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1740 it is considered Python source by `python-load-file', which uses the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1741 value to determine defaults." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1742 :type '(repeat function) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1743 :group 'python) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1744 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1745 (defvar python-prev-dir/file nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1746 "Caches (directory . file) pair used in the last `python-load-file' command. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1747 Used for determining the default in the next one.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1748 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1749 (autoload 'comint-get-source "comint") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1750 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1751 (defun python-load-file (file-name) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1752 "Load a Python file FILE-NAME into the inferior Python process. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1753 If the file has extension `.py' import or reload it as a module. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1754 Treating it as a module keeps the global namespace clean, provides |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1755 function location information for debugging, and supports users of |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1756 module-qualified names." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1757 (interactive (comint-get-source "Load Python file: " python-prev-dir/file |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1758 python-source-modes |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1759 t)) ; because execfile needs exact name |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1760 (comint-check-source file-name) ; Check to see if buffer needs saving. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1761 (setq python-prev-dir/file (cons (file-name-directory file-name) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1762 (file-name-nondirectory file-name))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1763 (with-current-buffer (process-buffer (python-proc)) ;Runs python if needed. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1764 ;; Fixme: I'm not convinced by this logic from python-mode.el. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1765 (python-send-command |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1766 (if (string-match "\\.py\\'" file-name) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1767 (let ((module (file-name-sans-extension |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1768 (file-name-nondirectory file-name)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1769 (format "emacs.eimport(%S,%S)" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1770 module (file-name-directory file-name))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1771 (format "execfile(%S)" file-name))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1772 (message "%s loaded" file-name))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1773 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1774 (defun python-proc () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1775 "Return the current Python process. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1776 See variable `python-buffer'. Starts a new process if necessary." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1777 ;; Fixme: Maybe should look for another active process if there |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1778 ;; isn't one for `python-buffer'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1779 (unless (comint-check-proc python-buffer) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1780 (run-python nil t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1781 (get-buffer-process (if (derived-mode-p 'inferior-python-mode) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1782 (current-buffer) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1783 python-buffer))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1784 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1785 (defun python-set-proc () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1786 "Set the default value of `python-buffer' to correspond to this buffer. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1787 If the current buffer has a local value of `python-buffer', set the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1788 default (global) value to that. The associated Python process is |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1789 the one that gets input from \\[python-send-region] et al when used |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1790 in a buffer that doesn't have a local value of `python-buffer'." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1791 (interactive) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1792 (if (local-variable-p 'python-buffer) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1793 (setq-default python-buffer python-buffer) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1794 (error "No local value of `python-buffer'"))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1795 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1796 ;;;; Context-sensitive help. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1797 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1798 (defconst python-dotty-syntax-table |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1799 (let ((table (make-syntax-table))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1800 (set-char-table-parent table python-mode-syntax-table) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1801 (modify-syntax-entry ?. "_" table) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1802 table) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1803 "Syntax table giving `.' symbol syntax. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1804 Otherwise inherits from `python-mode-syntax-table'.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1805 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1806 (defvar view-return-to-alist) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1807 (eval-when-compile (autoload 'help-buffer "help-fns")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1808 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1809 (defvar python-imports) ; forward declaration |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1810 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1811 ;; Fixme: Should this actually be used instead of info-look, i.e. be |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1812 ;; bound to C-h S? [Probably not, since info-look may work in cases |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1813 ;; where this doesn't.] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1814 (defun python-describe-symbol (symbol) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1815 "Get help on SYMBOL using `help'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1816 Interactively, prompt for symbol. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1817 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1818 Symbol may be anything recognized by the interpreter's `help' |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1819 command -- e.g. `CALLS' -- not just variables in scope in the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1820 interpreter. This only works for Python version 2.2 or newer |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1821 since earlier interpreters don't support `help'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1822 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1823 In some cases where this doesn't find documentation, \\[info-lookup-symbol] |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1824 will." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1825 ;; Note that we do this in the inferior process, not a separate one, to |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1826 ;; ensure the environment is appropriate. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1827 (interactive |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1828 (let ((symbol (with-syntax-table python-dotty-syntax-table |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1829 (current-word))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1830 (enable-recursive-minibuffers t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1831 (list (read-string (if symbol |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1832 (format "Describe symbol (default %s): " symbol) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1833 "Describe symbol: ") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1834 nil nil symbol)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1835 (if (equal symbol "") (error "No symbol")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1836 ;; Ensure we have a suitable help buffer. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1837 ;; Fixme: Maybe process `Related help topics' a la help xrefs and |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1838 ;; allow C-c C-f in help buffer. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1839 (let ((temp-buffer-show-hook ; avoid xref stuff |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1840 (lambda () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1841 (toggle-read-only 1) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1842 (setq view-return-to-alist |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1843 (list (cons (selected-window) help-return-method)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1844 (with-output-to-temp-buffer (help-buffer) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1845 (with-current-buffer standard-output |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1846 ;; Fixme: Is this actually useful? |
105372
bd2966850aac
Use `called-interactively-p' instead of `interactive-p'.
Juanma Barranquero <lekktu@gmail.com>
parents:
104774
diff
changeset
|
1847 (help-setup-xref (list 'python-describe-symbol symbol) |
bd2966850aac
Use `called-interactively-p' instead of `interactive-p'.
Juanma Barranquero <lekktu@gmail.com>
parents:
104774
diff
changeset
|
1848 (called-interactively-p 'interactive)) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1849 (set (make-local-variable 'comint-redirect-subvert-readonly) t) |
104386
2e0765155e47
Use help-print-return-message rather than the now obsolete alias.
Glenn Morris <rgm@gnu.org>
parents:
102153
diff
changeset
|
1850 (help-print-return-message)))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1851 (comint-redirect-send-command-to-process (format "emacs.ehelp(%S, %s)" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1852 symbol python-imports) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1853 "*Help*" (python-proc) nil nil)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1854 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1855 (add-to-list 'debug-ignored-errors "^No symbol") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1856 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1857 (defun python-send-receive (string) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1858 "Send STRING to inferior Python (if any) and return result. |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1859 The result is what follows `_emacs_out' in the output. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1860 This is a no-op if `python-check-comint-prompt' returns nil." |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1861 (python-send-string string) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1862 (let ((proc (python-proc))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1863 (with-current-buffer (process-buffer proc) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1864 (when (python-check-comint-prompt proc) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1865 (set (make-local-variable 'python-preoutput-result) nil) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1866 (while (progn |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1867 (accept-process-output proc 5) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1868 (null python-preoutput-result))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1869 (prog1 python-preoutput-result |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1870 (kill-local-variable 'python-preoutput-result)))))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1871 |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1872 (defun python-check-comint-prompt (&optional proc) |
94740
464e6f78f756
(python-comment-line-p, python-blank-line-p, python-skip-out,
Juanma Barranquero <lekktu@gmail.com>
parents:
94673
diff
changeset
|
1873 "Return non-nil if and only if there's a normal prompt in the inferior buffer. |
464e6f78f756
(python-comment-line-p, python-blank-line-p, python-skip-out,
Juanma Barranquero <lekktu@gmail.com>
parents:
94673
diff
changeset
|
1874 If there isn't, it's probably not appropriate to send input to return Eldoc |
464e6f78f756
(python-comment-line-p, python-blank-line-p, python-skip-out,
Juanma Barranquero <lekktu@gmail.com>
parents:
94673
diff
changeset
|
1875 information etc. If PROC is non-nil, check the buffer for that process." |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1876 (with-current-buffer (process-buffer (or proc (python-proc))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1877 (save-excursion |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1878 (save-match-data |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1879 (re-search-backward (concat python--prompt-regexp " *\\=") |
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
1880 nil t))))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1881 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1882 ;; Fixme: Is there anything reasonable we can do with random methods? |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1883 ;; (Currently only works with functions.) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1884 (defun python-eldoc-function () |
78897
9aa24f503773
(python-eldoc-function): Doc fix.
Juanma Barranquero <lekktu@gmail.com>
parents:
78755
diff
changeset
|
1885 "`eldoc-documentation-function' for Python. |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1886 Only works when point is in a function name, not its arg list, for |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1887 instance. Assumes an inferior Python is running." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1888 (let ((symbol (with-syntax-table python-dotty-syntax-table |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1889 (current-word)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1890 ;; This is run from timers, so inhibit-quit tends to be set. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1891 (with-local-quit |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1892 ;; First try the symbol we're on. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1893 (or (and symbol |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1894 (python-send-receive (format "emacs.eargs(%S, %s)" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1895 symbol python-imports))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1896 ;; Try moving to symbol before enclosing parens. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1897 (let ((s (syntax-ppss))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1898 (unless (zerop (car s)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1899 (when (eq ?\( (char-after (nth 1 s))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1900 (save-excursion |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1901 (goto-char (nth 1 s)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1902 (skip-syntax-backward "-") |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1903 (let ((point (point))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1904 (skip-chars-backward "a-zA-Z._") |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1905 (if (< (point) point) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1906 (python-send-receive |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1907 (format "emacs.eargs(%S, %s)" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1908 (buffer-substring-no-properties (point) point) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1909 python-imports)))))))))))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1910 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1911 ;;;; Info-look functionality. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1912 |
87124
8411562edbb6
Remove directory part from filenames in function declarations.
Glenn Morris <rgm@gnu.org>
parents:
87057
diff
changeset
|
1913 (declare-function info-lookup-maybe-add-help "info-look" (&rest arg)) |
86247
fc93e9674475
* progmodes/python.el (info-lookup-maybe-add-help):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
85840
diff
changeset
|
1914 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1915 (defun python-after-info-look () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1916 "Set up info-look for Python. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1917 Used with `eval-after-load'." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1918 (let* ((version (let ((s (shell-command-to-string (concat python-command |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1919 " -V")))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1920 (string-match "^Python \\([0-9]+\\.[0-9]+\\>\\)" s) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1921 (match-string 1 s))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1922 ;; Whether info files have a Python version suffix, e.g. in Debian. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1923 (versioned |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1924 (with-temp-buffer |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1925 (with-no-warnings (Info-mode)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1926 (condition-case () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1927 ;; Don't use `info' because it would pop-up a *info* buffer. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1928 (with-no-warnings |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1929 (Info-goto-node (format "(python%s-lib)Miscellaneous Index" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1930 version)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
1931 t) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1932 (error nil))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1933 (info-lookup-maybe-add-help |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1934 :mode 'python-mode |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1935 :regexp "[[:alnum:]_]+" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1936 :doc-spec |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1937 ;; Fixme: Can this reasonably be made specific to indices with |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1938 ;; different rules? Is the order of indices optimal? |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1939 ;; (Miscellaneous in -ref first prefers lookup of keywords, for |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1940 ;; instance.) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1941 (if versioned |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1942 ;; The empty prefix just gets us highlighted terms. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1943 `((,(concat "(python" version "-ref)Miscellaneous Index") nil "") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1944 (,(concat "(python" version "-ref)Module Index" nil "")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1945 (,(concat "(python" version "-ref)Function-Method-Variable Index" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1946 nil "")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1947 (,(concat "(python" version "-ref)Class-Exception-Object Index" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1948 nil "")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1949 (,(concat "(python" version "-lib)Module Index" nil "")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1950 (,(concat "(python" version "-lib)Class-Exception-Object Index" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1951 nil "")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1952 (,(concat "(python" version "-lib)Function-Method-Variable Index" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1953 nil "")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1954 (,(concat "(python" version "-lib)Miscellaneous Index" nil ""))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1955 '(("(python-ref)Miscellaneous Index" nil "") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1956 ("(python-ref)Module Index" nil "") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1957 ("(python-ref)Function-Method-Variable Index" nil "") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1958 ("(python-ref)Class-Exception-Object Index" nil "") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1959 ("(python-lib)Module Index" nil "") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1960 ("(python-lib)Class-Exception-Object Index" nil "") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1961 ("(python-lib)Function-Method-Variable Index" nil "") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1962 ("(python-lib)Miscellaneous Index" nil "")))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1963 (eval-after-load "info-look" '(python-after-info-look)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1964 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1965 ;;;; Miscellany. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1966 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1967 (defcustom python-jython-packages '("java" "javax" "org" "com") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1968 "Packages implying `jython-mode'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1969 If these are imported near the beginning of the buffer, `python-mode' |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1970 actually punts to `jython-mode'." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1971 :type '(repeat string) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1972 :group 'python) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1973 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1974 ;; Called from `python-mode', this causes a recursive call of the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1975 ;; mode. See logic there to break out of the recursion. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1976 (defun python-maybe-jython () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1977 "Invoke `jython-mode' if the buffer appears to contain Jython code. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1978 The criterion is either a match for `jython-mode' via |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1979 `interpreter-mode-alist' or an import of a module from the list |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1980 `python-jython-packages'." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1981 ;; The logic is taken from python-mode.el. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1982 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1983 (save-restriction |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1984 (widen) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1985 (goto-char (point-min)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1986 (let ((interpreter (if (looking-at auto-mode-interpreter-regexp) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1987 (match-string 2)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1988 (if (and interpreter (eq 'jython-mode |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1989 (cdr (assoc (file-name-nondirectory |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1990 interpreter) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1991 interpreter-mode-alist)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1992 (jython-mode) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1993 (if (catch 'done |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1994 (while (re-search-forward |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1995 (rx line-start (or "import" "from") (1+ space) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1996 (group (1+ (not (any " \t\n."))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1997 (+ (point-min) 10000) ; Probably not worth customizing. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1998 t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
1999 (if (member (match-string 1) python-jython-packages) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2000 (throw 'done t)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2001 (jython-mode))))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2002 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2003 (defun python-fill-paragraph (&optional justify) |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2004 "`fill-paragraph-function' handling multi-line strings and possibly comments. |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2005 If any of the current line is in or at the end of a multi-line string, |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2006 fill the string or the paragraph of it that point is in, preserving |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2007 the string's indentation." |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2008 (interactive "P") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2009 (or (fill-comment-paragraph justify) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2010 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2011 (end-of-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2012 (let* ((syntax (syntax-ppss)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2013 (orig (point)) |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2014 start end) |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2015 (cond ((nth 4 syntax) ; comment. fixme: loses with trailing one |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2016 (let (fill-paragraph-function) |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2017 (fill-paragraph justify))) |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2018 ;; The `paragraph-start' and `paragraph-separate' |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2019 ;; variables don't allow us to delimit the last |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2020 ;; paragraph in a multi-line string properly, so narrow |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2021 ;; to the string and then fill around (the end of) the |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2022 ;; current line. |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2023 ((eq t (nth 3 syntax)) ; in fenced string |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2024 (goto-char (nth 8 syntax)) ; string start |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2025 (setq start (line-beginning-position)) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2026 (setq end (condition-case () ; for unbalanced quotes |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2027 (progn (forward-sexp) |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2028 (- (point) 3)) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2029 (error (point-max))))) |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2030 ((re-search-backward "\\s|\\s-*\\=" nil t) ; end of fenced string |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2031 (forward-char) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2032 (setq end (point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2033 (condition-case () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2034 (progn (backward-sexp) |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2035 (setq start (line-beginning-position))) |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2036 (error nil)))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2037 (when end |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2038 (save-restriction |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2039 (narrow-to-region start end) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2040 (goto-char orig) |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2041 ;; Avoid losing leading and trailing newlines in doc |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2042 ;; strings written like: |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2043 ;; """ |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2044 ;; ... |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2045 ;; """ |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2046 (let ((paragraph-separate |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2047 ;; Note that the string could be part of an |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2048 ;; expression, so it can have preceding and |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2049 ;; trailing non-whitespace. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2050 (concat |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2051 (rx (or |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2052 ;; Opening triple quote without following text. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2053 (and (* nonl) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2054 (group (syntax string-delimiter)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2055 (repeat 2 (backref 1)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2056 ;; Fixme: Not sure about including |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2057 ;; trailing whitespace. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2058 (* (any " \t")) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2059 eol) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2060 ;; Closing trailing quote without preceding text. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2061 (and (group (any ?\" ?')) (backref 2) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2062 (syntax string-delimiter)))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2063 "\\(?:" paragraph-separate "\\)")) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2064 fill-paragraph-function) |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2065 (fill-paragraph justify))))))) t) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2066 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2067 (defun python-shift-left (start end &optional count) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2068 "Shift lines in region COUNT (the prefix arg) columns to the left. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2069 COUNT defaults to `python-indent'. If region isn't active, just shift |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2070 current line. The region shifted includes the lines in which START and |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2071 END lie. It is an error if any lines in the region are indented less than |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2072 COUNT columns." |
102153
603bb57bb542
(python-shift-left, python-shift-right):
Martin Rudalics <rudalics@gmx.at>
parents:
101984
diff
changeset
|
2073 (interactive |
603bb57bb542
(python-shift-left, python-shift-right):
Martin Rudalics <rudalics@gmx.at>
parents:
101984
diff
changeset
|
2074 (if mark-active |
603bb57bb542
(python-shift-left, python-shift-right):
Martin Rudalics <rudalics@gmx.at>
parents:
101984
diff
changeset
|
2075 (list (region-beginning) (region-end) current-prefix-arg) |
603bb57bb542
(python-shift-left, python-shift-right):
Martin Rudalics <rudalics@gmx.at>
parents:
101984
diff
changeset
|
2076 (list (line-beginning-position) (line-end-position) current-prefix-arg))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2077 (if count |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2078 (setq count (prefix-numeric-value count)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2079 (setq count python-indent)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2080 (when (> count 0) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2081 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2082 (goto-char start) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2083 (while (< (point) end) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2084 (if (and (< (current-indentation) count) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2085 (not (looking-at "[ \t]*$"))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2086 (error "Can't shift all lines enough")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2087 (forward-line)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2088 (indent-rigidly start end (- count))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2089 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2090 (add-to-list 'debug-ignored-errors "^Can't shift all lines enough") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2091 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2092 (defun python-shift-right (start end &optional count) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2093 "Shift lines in region COUNT (the prefix arg) columns to the right. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2094 COUNT defaults to `python-indent'. If region isn't active, just shift |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2095 current line. The region shifted includes the lines in which START and |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2096 END lie." |
102153
603bb57bb542
(python-shift-left, python-shift-right):
Martin Rudalics <rudalics@gmx.at>
parents:
101984
diff
changeset
|
2097 (interactive |
603bb57bb542
(python-shift-left, python-shift-right):
Martin Rudalics <rudalics@gmx.at>
parents:
101984
diff
changeset
|
2098 (if mark-active |
603bb57bb542
(python-shift-left, python-shift-right):
Martin Rudalics <rudalics@gmx.at>
parents:
101984
diff
changeset
|
2099 (list (region-beginning) (region-end) current-prefix-arg) |
603bb57bb542
(python-shift-left, python-shift-right):
Martin Rudalics <rudalics@gmx.at>
parents:
101984
diff
changeset
|
2100 (list (line-beginning-position) (line-end-position) current-prefix-arg))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2101 (if count |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2102 (setq count (prefix-numeric-value count)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2103 (setq count python-indent)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2104 (indent-rigidly start end count)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2105 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2106 (defun python-outline-level () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2107 "`outline-level' function for Python mode. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2108 The level is the number of `python-indent' steps of indentation |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2109 of current line." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2110 (1+ (/ (current-indentation) python-indent))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2111 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2112 ;; Fixme: Consider top-level assignments, imports, &c. |
81824
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
2113 (defun python-current-defun (&optional length-limit) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2114 "`add-log-current-defun-function' for Python." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2115 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2116 ;; Move up the tree of nested `class' and `def' blocks until we |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2117 ;; get to zero indentation, accumulating the defined names. |
82224
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2118 (let ((accum) |
81824
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
2119 (length -1)) |
82224
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2120 (catch 'done |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2121 (while (or (null length-limit) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2122 (null (cdr accum)) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2123 (< length length-limit)) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2124 (let ((started-from (point))) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2125 (python-beginning-of-block) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2126 (end-of-line) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2127 (beginning-of-defun) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2128 (when (= (point) started-from) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2129 (throw 'done nil))) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2130 (when (looking-at (rx (0+ space) (or "def" "class") (1+ space) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2131 (group (1+ (or word (syntax symbol)))))) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2132 (push (match-string 1) accum) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2133 (setq length (+ length 1 (length (car accum))))) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2134 (when (= (current-indentation) 0) |
bda0322e3767
Fix infinite loop in python.el
Vinicius Jose Latorre <viniciusjl@ig.com.br>
parents:
82221
diff
changeset
|
2135 (throw 'done nil)))) |
81824
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
2136 (when accum |
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
2137 (when (and length-limit (> length length-limit)) |
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
2138 (setcar accum "..")) |
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
2139 (mapconcat 'identity accum "."))))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2140 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2141 (defun python-mark-block () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2142 "Mark the block around point. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2143 Uses `python-beginning-of-block', `python-end-of-block'." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2144 (interactive) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2145 (push-mark) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2146 (python-beginning-of-block) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2147 (push-mark (point) nil t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2148 (python-end-of-block) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2149 (exchange-point-and-mark)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2150 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2151 ;; Fixme: Provide a find-function-like command to find source of a |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2152 ;; definition (separate from BicycleRepairMan). Complicated by |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2153 ;; finding the right qualified name. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2154 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2155 ;;;; Completion. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2156 |
87856
4f657ba160d6
Martin Svenson <phromo at gmail.com> (tiny change)
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
2157 ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2008-01/msg00076.html |
4f657ba160d6
Martin Svenson <phromo at gmail.com> (tiny change)
Glenn Morris <rgm@gnu.org>
parents:
87649
diff
changeset
|
2158 (defvar python-imports "None" |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2159 "String of top-level import statements updated by `python-find-imports'.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2160 (make-variable-buffer-local 'python-imports) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2161 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2162 ;; Fixme: Should font-lock try to run this when it deals with an import? |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2163 ;; Maybe not a good idea if it gets run multiple times when the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2164 ;; statement is being edited, and is more likely to end up with |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2165 ;; something syntactically incorrect. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2166 ;; However, what we should do is to trundle up the block tree from point |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2167 ;; to extract imports that appear to be in scope, and add those. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2168 (defun python-find-imports () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2169 "Find top-level imports, updating `python-imports'." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2170 (interactive) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2171 (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2172 (let (lines) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2173 (goto-char (point-min)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2174 (while (re-search-forward "^import\\>\\|^from\\>" nil t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2175 (unless (syntax-ppss-context (syntax-ppss)) |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2176 (let ((start (line-beginning-position))) |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2177 ;; Skip over continued lines. |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2178 (while (and (eq ?\\ (char-before (line-end-position))) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2179 (= 0 (forward-line 1))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2180 t) |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2181 (push (buffer-substring start (line-beginning-position 2)) |
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2182 lines)))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2183 (setq python-imports |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2184 (if lines |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2185 (apply #'concat |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2186 ;; This is probably best left out since you're unlikely to need the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2187 ;; doc for a function in the buffer and the import will lose if the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2188 ;; Python sub-process' working directory isn't the same as the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2189 ;; buffer's. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2190 ;; (if buffer-file-name |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2191 ;; (concat |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2192 ;; "import " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2193 ;; (file-name-sans-extension |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2194 ;; (file-name-nondirectory buffer-file-name)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2195 (nreverse lines)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2196 "None")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2197 (when lines |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2198 (set-text-properties 0 (length python-imports) nil python-imports) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2199 ;; The output ends up in the wrong place if the string we |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2200 ;; send contains newlines (from the imports). |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2201 (setq python-imports |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2202 (replace-regexp-in-string "\n" "\\n" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2203 (format "%S" python-imports) t t)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2204 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2205 ;; Fixme: This fails the first time if the sub-process isn't already |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2206 ;; running. Presumably a timing issue with i/o to the process. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2207 (defun python-symbol-completions (symbol) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2208 "Return a list of completions of the string SYMBOL from Python process. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2209 The list is sorted. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2210 Uses `python-imports' to load modules against which to complete." |
106574
427e81917607
* progmodes/python.el (python-symbol-completions): Remove text
Chong Yidong <cyd@stupidchicken.com>
parents:
106482
diff
changeset
|
2211 (when (stringp symbol) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2212 (let ((completions |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2213 (condition-case () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2214 (car (read-from-string |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2215 (python-send-receive |
106574
427e81917607
* progmodes/python.el (python-symbol-completions): Remove text
Chong Yidong <cyd@stupidchicken.com>
parents:
106482
diff
changeset
|
2216 (format "emacs.complete(%S,%s)" |
427e81917607
* progmodes/python.el (python-symbol-completions): Remove text
Chong Yidong <cyd@stupidchicken.com>
parents:
106482
diff
changeset
|
2217 (substring-no-properties symbol) |
427e81917607
* progmodes/python.el (python-symbol-completions): Remove text
Chong Yidong <cyd@stupidchicken.com>
parents:
106482
diff
changeset
|
2218 python-imports)))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2219 (error nil)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2220 (sort |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2221 ;; We can get duplicates from the above -- don't know why. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2222 (delete-dups completions) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2223 #'string<)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2224 |
106482
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105870
diff
changeset
|
2225 (defun python-completion-at-point () |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2226 (let ((end (point)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2227 (start (save-excursion |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2228 (and (re-search-backward |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2229 (rx (or buffer-start (regexp "[^[:alnum:]._]")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2230 (group (1+ (regexp "[[:alnum:]._]"))) point) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2231 nil t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2232 (match-beginning 1))))) |
106482
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105870
diff
changeset
|
2233 (when start |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105870
diff
changeset
|
2234 (list start end |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105870
diff
changeset
|
2235 (completion-table-dynamic 'python-symbol-completions))))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2236 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2237 ;;;; FFAP support |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2238 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2239 (defun python-module-path (module) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2240 "Function for `ffap-alist' to return path to MODULE." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2241 (python-send-receive (format "emacs.modpath (%S)" module))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2242 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2243 (eval-after-load "ffap" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2244 '(push '(python-mode . python-module-path) ffap-alist)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2245 |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2246 ;;;; Find-function support |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2247 |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2248 ;; Fixme: key binding? |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2249 |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2250 (defun python-find-function (name) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2251 "Find source of definition of function NAME. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2252 Interactively, prompt for name." |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2253 (interactive |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2254 (let ((symbol (with-syntax-table python-dotty-syntax-table |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2255 (current-word))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2256 (enable-recursive-minibuffers t)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2257 (list (read-string (if symbol |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2258 (format "Find location of (default %s): " symbol) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2259 "Find location of: ") |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2260 nil nil symbol)))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2261 (unless python-imports |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2262 (error "Not called from buffer visiting Python file")) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2263 (let* ((loc (python-send-receive (format "emacs.location_of (%S, %s)" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2264 name python-imports))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2265 (loc (car (read-from-string loc))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2266 (file (car loc)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2267 (line (cdr loc))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2268 (unless file (error "Don't know where `%s' is defined" name)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2269 (pop-to-buffer (find-file-noselect file)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2270 (when (integerp line) |
104774
468b7fa34d2c
Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents:
104386
diff
changeset
|
2271 (goto-char (point-min)) |
468b7fa34d2c
Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents:
104386
diff
changeset
|
2272 (forward-line (1- line))))) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2273 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2274 ;;;; Skeletons |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2275 |
101984
84b9607bddb0
(python-use-skeletons): Re-add.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101769
diff
changeset
|
2276 (defcustom python-use-skeletons nil |
84b9607bddb0
(python-use-skeletons): Re-add.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101769
diff
changeset
|
2277 "Non-nil means template skeletons will be automagically inserted. |
84b9607bddb0
(python-use-skeletons): Re-add.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101769
diff
changeset
|
2278 This happens when pressing \"if<SPACE>\", for example, to prompt for |
84b9607bddb0
(python-use-skeletons): Re-add.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101769
diff
changeset
|
2279 the if condition." |
84b9607bddb0
(python-use-skeletons): Re-add.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101769
diff
changeset
|
2280 :type 'boolean |
84b9607bddb0
(python-use-skeletons): Re-add.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101769
diff
changeset
|
2281 :group 'python) |
84b9607bddb0
(python-use-skeletons): Re-add.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101769
diff
changeset
|
2282 |
85840
d227ffcaa3fe
(python-mode-abbrev-table): Use :regexp.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
85598
diff
changeset
|
2283 (define-abbrev-table 'python-mode-abbrev-table () |
94139
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2284 "Abbrev table for Python mode." |
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2285 :case-fixed t |
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2286 ;; Allow / inside abbrevs. |
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2287 :regexp "\\(?:^\\|[^/]\\)\\<\\([[:word:]/]+\\)\\W*" |
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2288 ;; Only expand in code. |
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2289 :enable-function (lambda () (not (python-in-string/comment)))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2290 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2291 (eval-when-compile |
94139
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2292 ;; Define a user-level skeleton and add it to the abbrev table. |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2293 (defmacro def-python-skeleton (name &rest elements) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2294 (let* ((name (symbol-name name)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2295 (function (intern (concat "python-insert-" name)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2296 `(progn |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2297 ;; Usual technique for inserting a skeleton, but expand |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2298 ;; to the original abbrev instead if in a comment or string. |
101984
84b9607bddb0
(python-use-skeletons): Re-add.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101769
diff
changeset
|
2299 (when python-use-skeletons |
84b9607bddb0
(python-use-skeletons): Re-add.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101769
diff
changeset
|
2300 (define-abbrev python-mode-abbrev-table ,name "" |
84b9607bddb0
(python-use-skeletons): Re-add.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101769
diff
changeset
|
2301 ',function |
84b9607bddb0
(python-use-skeletons): Re-add.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
101769
diff
changeset
|
2302 nil t)) ; system abbrev |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2303 (define-skeleton ,function |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2304 ,(format "Insert Python \"%s\" template." name) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2305 ,@elements))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2306 (put 'def-python-skeleton 'lisp-indent-function 2) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2307 |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2308 ;; From `skeleton-further-elements' set below: |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2309 ;; `<': outdent a level; |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2310 ;; `^': delete indentation on current line and also previous newline. |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2311 ;; Not quite like `delete-indentation'. Assumes point is at |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2312 ;; beginning of indentation. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2313 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2314 (def-python-skeleton if |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2315 "Condition: " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2316 "if " str ":" \n |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2317 > -1 ; Fixme: I don't understand the spurious space this removes. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2318 _ \n |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2319 ("other condition, %s: " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2320 < ; Avoid wrong indentation after block opening. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2321 "elif " str ":" \n |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2322 > _ \n nil) |
87857
6f654ccab302
Quote all calls to "auxiliary skeleton"s to prevent infloops.
Glenn Morris <rgm@gnu.org>
parents:
87856
diff
changeset
|
2323 '(python-else) | ^) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2324 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2325 (define-skeleton python-else |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2326 "Auxiliary skeleton." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2327 nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2328 (unless (eq ?y (read-char "Add `else' clause? (y for yes or RET for no) ")) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2329 (signal 'quit t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2330 < "else:" \n |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2331 > _ \n) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2332 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2333 (def-python-skeleton while |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2334 "Condition: " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2335 "while " str ":" \n |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2336 > -1 _ \n |
87857
6f654ccab302
Quote all calls to "auxiliary skeleton"s to prevent infloops.
Glenn Morris <rgm@gnu.org>
parents:
87856
diff
changeset
|
2337 '(python-else) | ^) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2338 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2339 (def-python-skeleton for |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2340 "Target, %s: " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2341 "for " str " in " (skeleton-read "Expression, %s: ") ":" \n |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2342 > -1 _ \n |
87857
6f654ccab302
Quote all calls to "auxiliary skeleton"s to prevent infloops.
Glenn Morris <rgm@gnu.org>
parents:
87856
diff
changeset
|
2343 '(python-else) | ^) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2344 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2345 (def-python-skeleton try/except |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2346 nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2347 "try:" \n |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2348 > -1 _ \n |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2349 ("Exception, %s: " |
87857
6f654ccab302
Quote all calls to "auxiliary skeleton"s to prevent infloops.
Glenn Morris <rgm@gnu.org>
parents:
87856
diff
changeset
|
2350 < "except " str '(python-target) ":" \n |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2351 > _ \n nil) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2352 < "except:" \n |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2353 > _ \n |
87857
6f654ccab302
Quote all calls to "auxiliary skeleton"s to prevent infloops.
Glenn Morris <rgm@gnu.org>
parents:
87856
diff
changeset
|
2354 '(python-else) | ^) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2355 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2356 (define-skeleton python-target |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2357 "Auxiliary skeleton." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2358 "Target, %s: " ", " str | -2) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2359 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2360 (def-python-skeleton try/finally |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2361 nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2362 "try:" \n |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2363 > -1 _ \n |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2364 < "finally:" \n |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2365 > _ \n) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2366 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2367 (def-python-skeleton def |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2368 "Name: " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2369 "def " str " (" ("Parameter, %s: " (unless (equal ?\( (char-before)) ", ") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2370 str) "):" \n |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2371 "\"\"\"" - "\"\"\"" \n ; Fixme: extra space inserted -- why?). |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2372 > _ \n) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2373 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2374 (def-python-skeleton class |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2375 "Name: " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2376 "class " str " (" ("Inheritance, %s: " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2377 (unless (equal ?\( (char-before)) ", ") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2378 str) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2379 & ")" | -2 ; close list or remove opening |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2380 ":" \n |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2381 "\"\"\"" - "\"\"\"" \n |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2382 > _ \n) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2383 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2384 (defvar python-default-template "if" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2385 "Default template to expand by `python-expand-template'. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2386 Updated on each expansion.") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2387 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2388 (defun python-expand-template (name) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2389 "Expand template named NAME. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2390 Interactively, prompt for the name with completion." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2391 (interactive |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2392 (list (completing-read (format "Template to expand (default %s): " |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2393 python-default-template) |
94139
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2394 python-mode-abbrev-table nil t nil nil |
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2395 python-default-template))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2396 (if (equal "" name) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2397 (setq name python-default-template) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2398 (setq python-default-template name)) |
94139
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2399 (let ((sym (abbrev-symbol name python-mode-abbrev-table))) |
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2400 (if sym |
1e40bf35d15e
(python-mode-map): Use abbrev-table-menu.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
92111
diff
changeset
|
2401 (abbrev-insert sym) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2402 (error "Undefined template: %s" name)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2403 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2404 ;;;; Bicycle Repair Man support |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2405 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2406 (autoload 'pymacs-load "pymacs" nil t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2407 (autoload 'brm-init "bikemacs") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2408 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2409 ;; I'm not sure how useful BRM really is, and it's certainly dangerous |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2410 ;; the way it modifies files outside Emacs... Also note that the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2411 ;; current BRM loses with tabs used for indentation -- I submitted a |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2412 ;; fix <URL:http://www.loveshack.ukfsn.org/emacs/bikeemacs.py.diff>. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2413 (defun python-setup-brm () |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2414 "Set up Bicycle Repair Man refactoring tool (if available). |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2415 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2416 Note that the `refactoring' features change files independently of |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2417 Emacs and may modify and save the contents of the current buffer |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2418 without confirmation." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2419 (interactive) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2420 (condition-case data |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2421 (unless (fboundp 'brm-rename) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2422 (pymacs-load "bikeemacs" "brm-") ; first line of normal recipe |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2423 (let ((py-mode-map (make-sparse-keymap)) ; it assumes this |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2424 (features (cons 'python-mode features))) ; and requires this |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2425 (brm-init) ; second line of normal recipe |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2426 (remove-hook 'python-mode-hook ; undo this from `brm-init' |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2427 '(lambda () (easy-menu-add brm-menu))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2428 (easy-menu-define |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2429 python-brm-menu python-mode-map |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2430 "Bicycle Repair Man" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2431 '("BicycleRepairMan" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2432 :help "Interface to navigation and refactoring tool" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2433 "Queries" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2434 ["Find References" brm-find-references |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2435 :help "Find references to name at point in compilation buffer"] |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2436 ["Find Definition" brm-find-definition |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2437 :help "Find definition of name at point"] |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2438 "-" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2439 "Refactoring" |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2440 ["Rename" brm-rename |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2441 :help "Replace name at point with a new name everywhere"] |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2442 ["Extract Method" brm-extract-method |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2443 :active (and mark-active (not buffer-read-only)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2444 :help "Replace statements in region with a method"] |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2445 ["Extract Local Variable" brm-extract-local-variable |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2446 :active (and mark-active (not buffer-read-only)) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2447 :help "Replace expression in region with an assignment"] |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2448 ["Inline Local Variable" brm-inline-local-variable |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2449 :help |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2450 "Substitute uses of variable at point with its definition"] |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2451 ;; Fixme: Should check for anything to revert. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2452 ["Undo Last Refactoring" brm-undo :help ""])))) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2453 (error (error "BicycleRepairMan setup failed: %s" data)))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2454 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2455 ;;;; Modes. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2456 |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2457 ;; pdb tracking is alert once this file is loaded, but takes no action if |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2458 ;; `python-pdbtrack-do-tracking-p' is nil. |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2459 (add-hook 'comint-output-filter-functions 'python-pdbtrack-track-stack-file) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2460 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2461 (defvar outline-heading-end-regexp) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2462 (defvar eldoc-documentation-function) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2463 (defvar python-mode-running) ;Dynamically scoped var. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2464 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2465 ;;;###autoload |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2466 (define-derived-mode python-mode fundamental-mode "Python" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2467 "Major mode for editing Python files. |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2468 Turns on Font Lock mode unconditionally since it is currently required |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2469 for correct parsing of the source. |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2470 See also `jython-mode', which is actually invoked if the buffer appears to |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2471 contain Jython code. See also `run-python' and associated Python mode |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2472 commands for running Python under Emacs. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2473 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2474 The Emacs commands which work with `defun's, e.g. \\[beginning-of-defun], deal |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2475 with nested `def' and `class' blocks. They take the innermost one as |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2476 current without distinguishing method and class definitions. Used multiple |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2477 times, they move over others at the same indentation level until they reach |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2478 the end of definitions at that level, when they move up a level. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2479 \\<python-mode-map> |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2480 Colon is electric: it outdents the line if appropriate, e.g. for |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2481 an else statement. \\[python-backspace] at the beginning of an indented statement |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2482 deletes a level of indentation to close the current block; otherwise it |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2483 deletes a character backward. TAB indents the current line relative to |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2484 the preceding code. Successive TABs, with no intervening command, cycle |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2485 through the possibilities for indentation on the basis of enclosing blocks. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2486 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2487 \\[fill-paragraph] fills comments and multi-line strings appropriately, but has no |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2488 effect outside them. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2489 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2490 Supports Eldoc mode (only for functions, using a Python process), |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2491 Info-Look and Imenu. In Outline minor mode, `class' and `def' |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2492 lines count as headers. Symbol completion is available in the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2493 same way as in the Python shell using the `rlcompleter' module |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2494 and this is added to the Hippie Expand functions locally if |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2495 Hippie Expand mode is turned on. Completion of symbols of the |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2496 form x.y only works if the components are literal |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2497 module/attribute names, not variables. An abbrev table is set up |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2498 with skeleton expansions for compound statement templates. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2499 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2500 \\{python-mode-map}" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2501 :group 'python |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2502 (set (make-local-variable 'font-lock-defaults) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2503 '(python-font-lock-keywords nil nil nil nil |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2504 (font-lock-syntactic-keywords |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2505 . python-font-lock-syntactic-keywords) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2506 ;; This probably isn't worth it. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2507 ;; (font-lock-syntactic-face-function |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2508 ;; . python-font-lock-syntactic-face-function) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2509 )) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2510 (set (make-local-variable 'parse-sexp-lookup-properties) t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2511 (set (make-local-variable 'parse-sexp-ignore-comments) t) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2512 (set (make-local-variable 'comment-start) "# ") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2513 (set (make-local-variable 'indent-line-function) #'python-indent-line) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2514 (set (make-local-variable 'indent-region-function) #'python-indent-region) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2515 (set (make-local-variable 'paragraph-start) "\\s-*$") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2516 (set (make-local-variable 'fill-paragraph-function) 'python-fill-paragraph) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2517 (set (make-local-variable 'require-final-newline) mode-require-final-newline) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2518 (set (make-local-variable 'add-log-current-defun-function) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2519 #'python-current-defun) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2520 (set (make-local-variable 'outline-regexp) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2521 (rx (* space) (or "class" "def" "elif" "else" "except" "finally" |
77678
0b0c0f93563c
(python-font-lock-keywords, python-open-block-statement-p, python-mode):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
77663
diff
changeset
|
2522 "for" "if" "try" "while" "with") |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2523 symbol-end)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2524 (set (make-local-variable 'outline-heading-end-regexp) ":\\s-*\n") |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2525 (set (make-local-variable 'outline-level) #'python-outline-level) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2526 (set (make-local-variable 'open-paren-in-column-0-is-defun-start) nil) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2527 (make-local-variable 'python-saved-check-command) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2528 (set (make-local-variable 'beginning-of-defun-function) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2529 'python-beginning-of-defun) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2530 (set (make-local-variable 'end-of-defun-function) 'python-end-of-defun) |
81824
0a0e79e50844
(python-which-func-length-limit): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
81392
diff
changeset
|
2531 (add-hook 'which-func-functions 'python-which-func nil t) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2532 (setq imenu-create-index-function #'python-imenu-create-index) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2533 (set (make-local-variable 'eldoc-documentation-function) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2534 #'python-eldoc-function) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2535 (add-hook 'eldoc-mode-hook |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2536 (lambda () (run-python nil t)) ; need it running |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2537 nil t) |
106482
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105870
diff
changeset
|
2538 (add-hook 'completion-at-point-functions |
806e9f7990d8
* minibuffer.el (completion-at-point-functions): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105870
diff
changeset
|
2539 'python-completion-at-point nil 'local) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2540 ;; Fixme: should be in hideshow. This seems to be of limited use |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2541 ;; since it isn't (can't be) indentation-based. Also hide-level |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2542 ;; doesn't seem to work properly. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2543 (add-to-list 'hs-special-modes-alist |
78755
38a441bc4532
Merge changes from Dave Love's v2007-Sep-10.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78487
diff
changeset
|
2544 `(python-mode "^\\s-*\\(?:def\\|class\\)\\>" nil "#" |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2545 ,(lambda (arg) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2546 (python-end-of-defun) |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2547 (skip-chars-backward " \t\n")) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2548 nil)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2549 (set (make-local-variable 'skeleton-further-elements) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2550 '((< '(backward-delete-char-untabify (min python-indent |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2551 (current-column)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2552 (^ '(- (1+ (current-indentation)))))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2553 ;; Python defines TABs as being 8-char wide. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2554 (set (make-local-variable 'tab-width) 8) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2555 (unless font-lock-mode (font-lock-mode 1)) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2556 (when python-guess-indent (python-guess-indent)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2557 ;; Let's make it harder for the user to shoot himself in the foot. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2558 (unless (= tab-width python-indent) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2559 (setq indent-tabs-mode nil)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2560 (set (make-local-variable 'python-command) python-python-command) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2561 (python-find-imports) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2562 (unless (boundp 'python-mode-running) ; kill the recursion from jython-mode |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2563 (let ((python-mode-running t)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2564 (python-maybe-jython)))) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2565 |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2566 ;; Not done automatically in Emacs 21 or 22. |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2567 (defcustom python-mode-hook nil |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2568 "Hook run when entering Python mode." |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2569 :group 'python |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2570 :type 'hook) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2571 (custom-add-option 'python-mode-hook 'imenu-add-menubar-index) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2572 (custom-add-option 'python-mode-hook |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2573 (lambda () |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2574 "Turn off Indent Tabs mode." |
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2575 (setq indent-tabs-mode nil))) |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2576 (custom-add-option 'python-mode-hook 'turn-on-eldoc-mode) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2577 (custom-add-option 'python-mode-hook 'abbrev-mode) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2578 (custom-add-option 'python-mode-hook 'python-setup-brm) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2579 |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2580 ;;;###autoload |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2581 (define-derived-mode jython-mode python-mode "Jython" |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2582 "Major mode for editing Jython files. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2583 Like `python-mode', but sets up parameters for Jython subprocesses. |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2584 Runs `jython-mode-hook' after `python-mode-hook'." |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2585 :group 'python |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2586 (set (make-local-variable 'python-command) python-jython-command)) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2587 |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2588 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2589 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2590 ;; pdbtrack features |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2591 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2592 (defun python-comint-output-filter-function (string) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2593 "Watch output for Python prompt and exec next file waiting in queue. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2594 This function is appropriate for `comint-output-filter-functions'." |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2595 ;; TBD: this should probably use split-string |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
2596 (when (and (string-match python--prompt-regexp string) |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2597 python-file-queue) |
92111
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2598 (condition-case nil |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2599 (delete-file (car python-file-queue)) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2600 (error nil)) |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2601 (setq python-file-queue (cdr python-file-queue)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2602 (if python-file-queue |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2603 (let ((pyproc (get-buffer-process (current-buffer)))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2604 (python-execute-file pyproc (car python-file-queue)))))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2605 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2606 (defun python-pdbtrack-overlay-arrow (activation) |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2607 "Activate or deactivate arrow at beginning-of-line in current buffer." |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2608 (if activation |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2609 (progn |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2610 (setq overlay-arrow-position (make-marker) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2611 overlay-arrow-string "=>" |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2612 python-pdbtrack-is-tracking-p t) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2613 (set-marker overlay-arrow-position |
92111
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2614 (save-excursion (beginning-of-line) (point)) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2615 (current-buffer))) |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2616 (setq overlay-arrow-position nil |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2617 python-pdbtrack-is-tracking-p nil))) |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2618 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2619 (defun python-pdbtrack-track-stack-file (text) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2620 "Show the file indicated by the pdb stack entry line, in a separate window. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2621 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2622 Activity is disabled if the buffer-local variable |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2623 `python-pdbtrack-do-tracking-p' is nil. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2624 |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2625 We depend on the pdb input prompt being a match for |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2626 `python-pdbtrack-input-prompt'. |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2627 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2628 If the traceback target file path is invalid, we look for the |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2629 most recently visited python-mode buffer which either has the |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2630 name of the current function or class, or which defines the |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2631 function or class. This is to provide for scripts not in the |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2632 local filesytem (e.g., Zope's 'Script \(Python)', but it's not |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2633 Zope specific). If you put a copy of the script in a buffer |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2634 named for the script and activate python-mode, then pdbtrack will |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2635 find it." |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2636 ;; Instead of trying to piece things together from partial text |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2637 ;; (which can be almost useless depending on Emacs version), we |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2638 ;; monitor to the point where we have the next pdb prompt, and then |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2639 ;; check all text from comint-last-input-end to process-mark. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2640 ;; |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2641 ;; Also, we're very conservative about clearing the overlay arrow, |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2642 ;; to minimize residue. This means, for instance, that executing |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2643 ;; other pdb commands wipe out the highlight. You can always do a |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2644 ;; 'where' (aka 'w') PDB command to reveal the overlay arrow. |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2645 |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2646 (let* ((origbuf (current-buffer)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2647 (currproc (get-buffer-process origbuf))) |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2648 |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2649 (if (not (and currproc python-pdbtrack-do-tracking-p)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2650 (python-pdbtrack-overlay-arrow nil) |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2651 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2652 (let* ((procmark (process-mark currproc)) |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2653 (block (buffer-substring (max comint-last-input-end |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2654 (- procmark |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2655 python-pdbtrack-track-range)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2656 procmark)) |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2657 target target_fname target_lineno target_buffer) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2658 |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2659 (if (not (string-match (concat python-pdbtrack-input-prompt "$") block)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2660 (python-pdbtrack-overlay-arrow nil) |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2661 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2662 (setq target (python-pdbtrack-get-source-buffer block)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2663 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2664 (if (stringp target) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2665 (progn |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2666 (python-pdbtrack-overlay-arrow nil) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2667 (message "pdbtrack: %s" target)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2668 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2669 (setq target_lineno (car target) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2670 target_buffer (cadr target) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2671 target_fname (buffer-file-name target_buffer)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2672 (switch-to-buffer-other-window target_buffer) |
104774
468b7fa34d2c
Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents:
104386
diff
changeset
|
2673 (goto-char (point-min)) |
468b7fa34d2c
Use forward-line rather than goto-line.
Glenn Morris <rgm@gnu.org>
parents:
104386
diff
changeset
|
2674 (forward-line (1- target_lineno)) |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2675 (message "pdbtrack: line %s, file %s" target_lineno target_fname) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2676 (python-pdbtrack-overlay-arrow t) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2677 (pop-to-buffer origbuf t) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2678 ;; in large shell buffers, above stuff may cause point to lag output |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2679 (goto-char procmark) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2680 ))))) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2681 ) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2682 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2683 (defun python-pdbtrack-get-source-buffer (block) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2684 "Return line number and buffer of code indicated by block's traceback text. |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2685 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2686 We look first to visit the file indicated in the trace. |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2687 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2688 Failing that, we look for the most recently visited python-mode buffer |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2689 with the same name or having the named function. |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2690 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2691 If we're unable find the source code we return a string describing the |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2692 problem." |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2693 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2694 (if (not (string-match python-pdbtrack-stack-entry-regexp block)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2695 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2696 "Traceback cue not found" |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2697 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2698 (let* ((filename (match-string 1 block)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2699 (lineno (string-to-number (match-string 2 block))) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2700 (funcname (match-string 3 block)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2701 funcbuffer) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2702 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2703 (cond ((file-exists-p filename) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2704 (list lineno (find-file-noselect filename))) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2705 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2706 ((setq funcbuffer (python-pdbtrack-grub-for-buffer funcname lineno)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2707 (if (string-match "/Script (Python)$" filename) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2708 ;; Add in number of lines for leading '##' comments: |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2709 (setq lineno |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2710 (+ lineno |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105798
diff
changeset
|
2711 (with-current-buffer funcbuffer |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2712 (if (equal (point-min)(point-max)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2713 0 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2714 (count-lines |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2715 (point-min) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2716 (max (point-min) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2717 (string-match "^\\([^#]\\|#[^#]\\|#$\\)" |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2718 (buffer-substring |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2719 (point-min) (point-max))) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2720 ))))))) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2721 (list lineno funcbuffer)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2722 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2723 ((= (elt filename 0) ?\<) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2724 (format "(Non-file source: '%s')" filename)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2725 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2726 (t (format "Not found: %s(), %s" funcname filename))) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2727 ) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2728 ) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2729 ) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2730 |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2731 (defun python-pdbtrack-grub-for-buffer (funcname lineno) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2732 "Find recent python-mode buffer named, or having function named funcname." |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2733 (let ((buffers (buffer-list)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2734 buf |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2735 got) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2736 (while (and buffers (not got)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2737 (setq buf (car buffers) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2738 buffers (cdr buffers)) |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105798
diff
changeset
|
2739 (if (and (with-current-buffer buf |
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105798
diff
changeset
|
2740 (string= major-mode "python-mode")) |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2741 (or (string-match funcname (buffer-name buf)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2742 (string-match (concat "^\\s-*\\(def\\|class\\)\\s-+" |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2743 funcname "\\s-*(") |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105798
diff
changeset
|
2744 (with-current-buffer buf |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2745 (buffer-substring (point-min) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2746 (point-max)))))) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2747 (setq got buf))) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2748 got)) |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2749 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2750 (defun python-toggle-shells (arg) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2751 "Toggles between the CPython and JPython shells. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2752 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2753 With positive argument ARG (interactively \\[universal-argument]), |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2754 uses the CPython shell, with negative ARG uses the JPython shell, and |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2755 with a zero argument, toggles the shell. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2756 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2757 Programmatically, ARG can also be one of the symbols `cpython' or |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2758 `jpython', equivalent to positive arg and negative arg respectively." |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2759 (interactive "P") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2760 ;; default is to toggle |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2761 (if (null arg) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2762 (setq arg 0)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2763 ;; preprocess arg |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2764 (cond |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2765 ((equal arg 0) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2766 ;; toggle |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2767 (if (string-equal python-which-bufname "Python") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2768 (setq arg -1) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2769 (setq arg 1))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2770 ((equal arg 'cpython) (setq arg 1)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2771 ((equal arg 'jpython) (setq arg -1))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2772 (let (msg) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2773 (cond |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2774 ((< 0 arg) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2775 ;; set to CPython |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2776 (setq python-which-shell python-python-command |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2777 python-which-args python-python-command-args |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2778 python-which-bufname "Python" |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2779 msg "CPython" |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2780 mode-name "Python")) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2781 ((> 0 arg) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2782 (setq python-which-shell python-jython-command |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2783 python-which-args python-jython-command-args |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2784 python-which-bufname "JPython" |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2785 msg "JPython" |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2786 mode-name "JPython"))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2787 (message "Using the %s shell" msg))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2788 |
92111
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2789 ;; Python subprocess utilities and filters |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2790 (defun python-execute-file (proc filename) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2791 "Send to Python interpreter process PROC \"execfile('FILENAME')\". |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2792 Make that process's buffer visible and force display. Also make |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2793 comint believe the user typed this string so that |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2794 `kill-output-from-shell' does The Right Thing." |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2795 (let ((curbuf (current-buffer)) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2796 (procbuf (process-buffer proc)) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2797 ; (comint-scroll-to-bottom-on-output t) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2798 (msg (format "## working on region in file %s...\n" filename)) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2799 ;; add some comment, so that we can filter it out of history |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2800 (cmd (format "execfile(r'%s') # PYTHON-MODE\n" filename))) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2801 (unwind-protect |
105813
df4934f25eef
* textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
105798
diff
changeset
|
2802 (with-current-buffer procbuf |
92111
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2803 (goto-char (point-max)) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2804 (move-marker (process-mark proc) (point)) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2805 (funcall (process-filter proc) proc msg)) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2806 (set-buffer curbuf)) |
105ec1146aa7
Finish pdbtrack integration cleanup, settling missing-functions
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92060
diff
changeset
|
2807 (process-send-string proc cmd))) |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
2808 |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2809 ;;;###autoload |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2810 (defun python-shell (&optional argprompt) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2811 "Start an interactive Python interpreter in another window. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2812 This is like Shell mode, except that Python is running in the window |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2813 instead of a shell. See the `Interactive Shell' and `Shell Mode' |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2814 sections of the Emacs manual for details, especially for the key |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2815 bindings active in the `*Python*' buffer. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2816 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2817 With optional \\[universal-argument], the user is prompted for the |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2818 flags to pass to the Python interpreter. This has no effect when this |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2819 command is used to switch to an existing process, only when a new |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2820 process is started. If you use this, you will probably want to ensure |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2821 that the current arguments are retained (they will be included in the |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2822 prompt). This argument is ignored when this function is called |
111593
d4d6fcc60f7b
* lisp/progmodes/python.el (python-shell): Doc fix.
Glenn Morris <rgm@gnu.org>
parents:
111385
diff
changeset
|
2823 programmatically. |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2824 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2825 Note: You can toggle between using the CPython interpreter and the |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2826 JPython interpreter by hitting \\[python-toggle-shells]. This toggles |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2827 buffer local variables which control whether all your subshell |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2828 interactions happen to the `*JPython*' or `*Python*' buffers (the |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2829 latter is the name used for the CPython buffer). |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2830 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2831 Warning: Don't use an interactive Python if you change sys.ps1 or |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2832 sys.ps2 from their default values, or if you're running code that |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2833 prints `>>> ' or `... ' at the start of a line. `python-mode' can't |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2834 distinguish your output from Python's output, and assumes that `>>> ' |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2835 at the start of a line is a prompt from Python. Similarly, the Emacs |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2836 Shell mode code assumes that both `>>> ' and `... ' at the start of a |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2837 line are Python prompts. Bad things can happen if you fool either |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2838 mode. |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2839 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2840 Warning: If you do any editing *in* the process buffer *while* the |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2841 buffer is accepting output from Python, do NOT attempt to `undo' the |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2842 changes. Some of the output (nowhere near the parts you changed!) may |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2843 be lost if you do. This appears to be an Emacs bug, an unfortunate |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2844 interaction between undo and process filters; the same problem exists in |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2845 non-Python process buffers using the default (Emacs-supplied) process |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2846 filter." |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2847 (interactive "P") |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
2848 (require 'ansi-color) ; For ipython |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2849 ;; Set the default shell if not already set |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2850 (when (null python-which-shell) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2851 (python-toggle-shells python-default-interpreter)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2852 (let ((args python-which-args)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2853 (when (and argprompt |
105372
bd2966850aac
Use `called-interactively-p' instead of `interactive-p'.
Juanma Barranquero <lekktu@gmail.com>
parents:
104774
diff
changeset
|
2854 (called-interactively-p 'interactive) |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2855 (fboundp 'split-string)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2856 ;; TBD: Perhaps force "-i" in the final list? |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2857 (setq args (split-string |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2858 (read-string (concat python-which-bufname |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2859 " arguments: ") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2860 (concat |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2861 (mapconcat 'identity python-which-args " ") " ") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2862 )))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2863 (switch-to-buffer-other-window |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2864 (apply 'make-comint python-which-bufname python-which-shell nil args)) |
92060
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2865 (set-process-sentinel (get-buffer-process (current-buffer)) |
fd85a7810d53
Revise pdbtrack functionality to incorporate advances in python-mode.el.
Ken Manheimer <ken.manheimer@gmail.com>
parents:
92055
diff
changeset
|
2866 'python-sentinel) |
111753
f84b2c2c0b1b
Backport fixes for Bug#5390 and Bug#5694 from trunk.
Chong Yidong <cyd@stupidchicken.com>
parents:
111752
diff
changeset
|
2867 (python--set-prompt-regexp) |
91964
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2868 (add-hook 'comint-output-filter-functions |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2869 'python-comint-output-filter-function nil t) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2870 ;; pdbtrack |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2871 (set-syntax-table python-mode-syntax-table) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2872 (use-local-map python-shell-map))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2873 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2874 (defun python-pdbtrack-toggle-stack-tracking (arg) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2875 (interactive "P") |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2876 (if (not (get-buffer-process (current-buffer))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2877 (error "No process associated with buffer '%s'" (current-buffer))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2878 ;; missing or 0 is toggle, >0 turn on, <0 turn off |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2879 (if (or (not arg) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2880 (zerop (setq arg (prefix-numeric-value arg)))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2881 (setq python-pdbtrack-do-tracking-p (not python-pdbtrack-do-tracking-p)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2882 (setq python-pdbtrack-do-tracking-p (> arg 0))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2883 (message "%sabled Python's pdbtrack" |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2884 (if python-pdbtrack-do-tracking-p "En" "Dis"))) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2885 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2886 (defun turn-on-pdbtrack () |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2887 (interactive) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2888 (python-pdbtrack-toggle-stack-tracking 1)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2889 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2890 (defun turn-off-pdbtrack () |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2891 (interactive) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2892 (python-pdbtrack-toggle-stack-tracking 0)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2893 |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2894 (defun python-sentinel (proc msg) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2895 (setq overlay-arrow-position nil)) |
70017176d475
Also require comint when loading.
Nick Roberts <nickrob@snap.net.nz>
parents:
87857
diff
changeset
|
2896 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2897 (provide 'python) |
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2898 (provide 'python-21) |
92055
373b00a4775c
Merge from Dave Love's 2008-01-20 version.
Chong Yidong <cyd@stupidchicken.com>
parents:
91964
diff
changeset
|
2899 |
77568
da9f2ed7fb46
Restore file pending consideration of legal issues.
Glenn Morris <rgm@gnu.org>
parents:
diff
changeset
|
2900 ;;; python.el ends here |