annotate .elisp/python-mode.el @ 174:014e745b2d04

python-mode: updating to current bzr version This is bzr revision 351, which is revision-id: barry@python.org-20090320013721-awwzwv1mfl7hicdf
author Augie Fackler <durin42@gmail.com>
date Wed, 16 Dec 2009 22:57:36 -0600
parents b5d75594b356
children 4741c022c7ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1 ;;; python-mode.el --- Major mode for editing Python programs
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3 ;; Copyright (C) 1992,1993,1994 Tim Peters
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
5 ;; Author: 2003-2009 https://launchpad.net/python-mode
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
6 ;; 1995-2002 Barry A. Warsaw
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
7 ;; 1992-1994 Tim Peters
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
8 ;; Maintainer: python-mode@python.org
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
9 ;; Created: Feb 1992
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
10 ;; Keywords: python languages oop
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
11
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
12 (defconst py-version "5.1.0+"
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
13 "`python-mode' version number.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
14
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
15 ;; This file is part of python-mode.el.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
16 ;;
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
17 ;; python-mode.el is free software: you can redistribute it and/or modify it
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
18 ;; under the terms of the GNU General Public License as published by the Free
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
19 ;; Software Foundation, either version 3 of the License, or (at your option)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
20 ;; any later version.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
21 ;;
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
22 ;; python-mode.el is distributed in the hope that it will be useful, but
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
23 ;; WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
24 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
25 ;; for more details.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
26 ;;
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
27 ;; You should have received a copy of the GNU General Public License along
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
28 ;; with python-mode.el. If not, see <http://www.gnu.org/licenses/>.
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
29
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
30 ;;; Commentary:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
31
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
32 ;; This is a major mode for editing Python programs. It was developed by Tim
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
33 ;; Peters after an original idea by Michael A. Guravage. Tim subsequently
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
34 ;; left the net and in 1995, Barry Warsaw inherited the mode. Tim came back
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
35 ;; but disavowed all responsibility for the mode. In fact, we suspect he
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
36 ;; doesn't even use Emacs any more <wink>. In 2003, python-mode.el was moved
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
37 ;; to its own SourceForge project apart from the Python project, and in 2008
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
38 ;; it was moved to Launchpad for all project administration. python-mode.el
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
39 ;; is maintained by the volunteers at the python-mode@python.org mailing
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
40 ;; list.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
41
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
42 ;; python-mode.el is different than, and pre-dates by many years, the
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
43 ;; python.el that comes with FSF Emacs. We'd like to merge the two modes but
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
44 ;; have few cycles to do so. Volunteers are welcome.
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
45
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
46 ;; pdbtrack support contributed by Ken Manheimer, April 2001. Skip Montanaro
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47 ;; has also contributed significantly to python-mode's development.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
48
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
49 ;; Please use Launchpad to submit bugs or patches:
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
50 ;;
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
51 ;; https://launchpad.net/python-mode
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
52
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
53 ;; INSTALLATION:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
54
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
55 ;; To install, just drop this file into a directory on your load-path and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
56 ;; byte-compile it. To set up Emacs to automatically edit files ending in
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
57 ;; ".py" using python-mode add the following to your ~/.emacs file (GNU
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
58 ;; Emacs) or ~/.xemacs/init.el file (XEmacs):
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
59 ;; (setq auto-mode-alist (cons '("\\.py$" . python-mode) auto-mode-alist))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
60 ;; (setq interpreter-mode-alist (cons '("python" . python-mode)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
61 ;; interpreter-mode-alist))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
62 ;; (autoload 'python-mode "python-mode" "Python editing mode." t)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
63 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
64 ;; In XEmacs syntax highlighting should be enabled automatically. In GNU
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
65 ;; Emacs you may have to add these lines to your ~/.emacs file:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
66 ;; (global-font-lock-mode t)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
67 ;; (setq font-lock-maximum-decoration t)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
68
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
69 ;; BUG REPORTING:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
71 ;; As mentioned above, please use the Launchpad python-mode project for
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
72 ;; submitting bug reports or patches. The old recommendation, to use C-c C-b
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
73 ;; will still work, but those reports have a higher chance of getting buried
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
74 ;; in our inboxes. Please include a complete, but concise code sample and a
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
75 ;; recipe for reproducing the bug. Send suggestions and other comments to
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
76 ;; python-mode@python.org.
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
77
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
78 ;; When in a Python mode buffer, do a C-h m for more help. It's doubtful that
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
79 ;; a texinfo manual would be very useful, but if you want to contribute one,
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
80 ;; we'll certainly accept it!
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
81
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
82 ;;; Code:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
83
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84 (require 'comint)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 (require 'custom)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86 (require 'cl)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87 (require 'compile)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 (require 'ansi-color)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
90
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
91 ;; user definable variables
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
92 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
93
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
94 (defgroup python nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
95 "Support for the Python programming language, <http://www.python.org/>"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
96 :group 'languages
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
97 :prefix "py-")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
98
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
99 (defcustom py-tab-always-indent t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
100 "*Non-nil means TAB in Python mode should always reindent the current line,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
101 regardless of where in the line point is when the TAB command is used."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
102 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
103 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
104
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
105 (defcustom py-python-command "python"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
106 "*Shell command used to start Python interpreter."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
107 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
108 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
109
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
110 (make-obsolete-variable 'py-jpython-command 'py-jython-command)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
111 (defcustom py-jython-command "jython"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
112 "*Shell command used to start the Jython interpreter."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
113 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
114 :group 'python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
115 :tag "Jython Command")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
116
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
117 (defcustom py-default-interpreter 'cpython
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
118 "*Which Python interpreter is used by default.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
119 The value for this variable can be either `cpython' or `jython'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
120
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
121 When the value is `cpython', the variables `py-python-command' and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
122 `py-python-command-args' are consulted to determine the interpreter
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
123 and arguments to use.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
124
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
125 When the value is `jython', the variables `py-jython-command' and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
126 `py-jython-command-args' are consulted to determine the interpreter
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
127 and arguments to use.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
128
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
129 Note that this variable is consulted only the first time that a Python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
130 mode buffer is visited during an Emacs session. After that, use
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
131 \\[py-toggle-shells] to change the interpreter shell."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
132 :type '(choice (const :tag "Python (a.k.a. CPython)" cpython)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
133 (const :tag "Jython" jython))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
134 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
135
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
136 (defcustom py-python-command-args '("-i")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
137 "*List of string arguments to be used when starting a Python shell."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
138 :type '(repeat string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
139 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
140
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
141 (make-obsolete-variable 'py-jpython-command-args 'py-jython-command-args)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
142 (defcustom py-jython-command-args '("-i")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
143 "*List of string arguments to be used when starting a Jython shell."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
144 :type '(repeat string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
145 :group 'python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
146 :tag "Jython Command Args")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
147
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
148 (defcustom py-indent-offset 4
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
149 "*Amount of offset per level of indentation.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
150 `\\[py-guess-indent-offset]' can usually guess a good value when
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
151 you're editing someone else's Python code."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
152 :type 'integer
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
153 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
154
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
155 (defcustom py-continuation-offset 4
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
156 "*Additional amount of offset to give for some continuation lines.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
157 Continuation lines are those that immediately follow a backslash
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
158 terminated line. Only those continuation lines for a block opening
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
159 statement are given this extra offset."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
160 :type 'integer
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
161 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
162
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
163 (defcustom py-smart-indentation t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
164 "*Should `python-mode' try to automagically set some indentation variables?
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
165 When this variable is non-nil, two things happen when a buffer is set
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
166 to `python-mode':
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
167
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
168 1. `py-indent-offset' is guessed from existing code in the buffer.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
169 Only guessed values between 2 and 8 are considered. If a valid
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
170 guess can't be made (perhaps because you are visiting a new
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
171 file), then the value in `py-indent-offset' is used.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
172
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
173 2. `indent-tabs-mode' is turned off if `py-indent-offset' does not
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
174 equal `tab-width' (`indent-tabs-mode' is never turned on by
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
175 Python mode). This means that for newly written code, tabs are
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
176 only inserted in indentation if one tab is one indentation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
177 level, otherwise only spaces are used.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
178
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
179 Note that both these settings occur *after* `python-mode-hook' is run,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
180 so if you want to defeat the automagic configuration, you must also
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
181 set `py-smart-indentation' to nil in your `python-mode-hook'."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
182 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
183 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
184
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
185 (defcustom py-align-multiline-strings-p t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
186 "*Flag describing how multi-line triple quoted strings are aligned.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
187 When this flag is non-nil, continuation lines are lined up under the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
188 preceding line's indentation. When this flag is nil, continuation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
189 lines are aligned to column zero."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
190 :type '(choice (const :tag "Align under preceding line" t)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
191 (const :tag "Align to column zero" nil))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
192 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
193
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
194 (defcustom py-block-comment-prefix "##"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
195 "*String used by \\[comment-region] to comment out a block of code.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
196 This should follow the convention for non-indenting comment lines so
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
197 that the indentation commands won't get confused (i.e., the string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
198 should be of the form `#x...' where `x' is not a blank or a tab, and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
199 `...' is arbitrary). However, this string should not end in whitespace."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
200 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
201 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
202
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
203 (defcustom py-honor-comment-indentation t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
204 "*Controls how comment lines influence subsequent indentation.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
205
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
206 When nil, all comment lines are skipped for indentation purposes, and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
207 if possible, a faster algorithm is used (i.e. X/Emacs 19 and beyond).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
208
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
209 When t, lines that begin with a single `#' are a hint to subsequent
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
210 line indentation. If the previous line is such a comment line (as
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
211 opposed to one that starts with `py-block-comment-prefix'), then its
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
212 indentation is used as a hint for this line's indentation. Lines that
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
213 begin with `py-block-comment-prefix' are ignored for indentation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
214 purposes.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
215
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
216 When not nil or t, comment lines that begin with a single `#' are used
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
217 as indentation hints, unless the comment character is in column zero."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
218 :type '(choice
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
219 (const :tag "Skip all comment lines (fast)" nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
220 (const :tag "Single # `sets' indentation for next line" t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
221 (const :tag "Single # `sets' indentation except at column zero"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
222 other)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
223 )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
224 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
225
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
226 (defcustom py-temp-directory
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
227 (let ((ok '(lambda (x)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
228 (and x
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
229 (setq x (expand-file-name x)) ; always true
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
230 (file-directory-p x)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
231 (file-writable-p x)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
232 x))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
233 (or (funcall ok (getenv "TMPDIR"))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
234 (funcall ok "/usr/tmp")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
235 (funcall ok "/tmp")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
236 (funcall ok "/var/tmp")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
237 (funcall ok ".")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
238 (error
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
239 "Couldn't find a usable temp directory -- set `py-temp-directory'")))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
240 "*Directory used for temporary files created by a *Python* process.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
241 By default, the first directory from this list that exists and that you
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
242 can write into: the value (if any) of the environment variable TMPDIR,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
243 /usr/tmp, /tmp, /var/tmp, or the current directory."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
244 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
245 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
246
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
247 (defcustom py-beep-if-tab-change t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
248 "*Ring the bell if `tab-width' is changed.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
249 If a comment of the form
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
250
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
251 \t# vi:set tabsize=<number>:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
252
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
253 is found before the first code line when the file is entered, and the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
254 current value of (the general Emacs variable) `tab-width' does not
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
255 equal <number>, `tab-width' is set to <number>, a message saying so is
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
256 displayed in the echo area, and if `py-beep-if-tab-change' is non-nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
257 the Emacs bell is also rung as a warning."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
258 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
259 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
260
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
261 (defcustom py-jump-on-exception t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
262 "*Jump to innermost exception frame in *Python Output* buffer.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
263 When this variable is non-nil and an exception occurs when running
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
264 Python code synchronously in a subprocess, jump immediately to the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
265 source code of the innermost traceback frame."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
266 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
267 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
268
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
269 (defcustom py-ask-about-save t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
270 "If not nil, ask about which buffers to save before executing some code.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
271 Otherwise, all modified buffers are saved without asking."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
272 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
273 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
274
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
275 (defcustom py-backspace-function 'backward-delete-char-untabify
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
276 "*Function called by `py-electric-backspace' when deleting backwards."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
277 :type 'function
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
278 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
279
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
280 (defcustom py-delete-function 'delete-char
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
281 "*Function called by `py-electric-delete' when deleting forwards."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
282 :type 'function
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
283 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
284
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
285 (defcustom py-imenu-show-method-args-p nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
286 "*Controls echoing of arguments of functions & methods in the Imenu buffer.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
287 When non-nil, arguments are printed."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
288 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
289 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
290 (make-variable-buffer-local 'py-indent-offset)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
291
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
292 (defcustom py-pdbtrack-do-tracking-p t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
293 "*Controls whether the pdbtrack feature is enabled or not.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
294 When non-nil, pdbtrack is enabled in all comint-based buffers,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
295 e.g. shell buffers and the *Python* buffer. When using pdb to debug a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
296 Python program, pdbtrack notices the pdb prompt and displays the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
297 source file and line that the program is stopped at, much the same way
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
298 as gud-mode does for debugging C programs with gdb."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
299 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
300 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
301 (make-variable-buffer-local 'py-pdbtrack-do-tracking-p)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
302
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
303 (defcustom py-pdbtrack-minor-mode-string " PDB"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
304 "*String to use in the minor mode list when pdbtrack is enabled."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
305 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
306 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
307
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
308 (defcustom py-import-check-point-max
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
309 20000
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
310 "Maximum number of characters to search for a Java-ish import statement.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
311 When `python-mode' tries to calculate the shell to use (either a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
312 CPython or a Jython shell), it looks at the so-called `shebang' line
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
313 -- i.e. #! line. If that's not available, it looks at some of the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
314 file heading imports to see if they look Java-like."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
315 :type 'integer
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
316 :group 'python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
317 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
318
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
319 (make-obsolete-variable 'py-jpython-packages 'py-jython-packages)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
320 (defcustom py-jython-packages
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
321 '("java" "javax" "org" "com")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
322 "Imported packages that imply `jython-mode'."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
323 :type '(repeat string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
324 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
325
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
326 ;; Not customizable
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
327 (defvar py-master-file nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
328 "If non-nil, execute the named file instead of the buffer's file.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
329 The intent is to allow you to set this variable in the file's local
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
330 variable section, e.g.:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
331
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
332 # Local Variables:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
333 # py-master-file: \"master.py\"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
334 # End:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
335
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
336 so that typing \\[py-execute-buffer] in that buffer executes the named
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
337 master file instead of the buffer's file. If the file name has a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
338 relative path, the value of variable `default-directory' for the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
339 buffer is prepended to come up with a file name.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
340 (make-variable-buffer-local 'py-master-file)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
341
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
342 (defcustom py-pychecker-command "pychecker"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
343 "*Shell command used to run Pychecker."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
344 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
345 :group 'python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
346 :tag "Pychecker Command")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
347
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
348 (defcustom py-pychecker-command-args '("--stdlib")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
349 "*List of string arguments to be passed to pychecker."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
350 :type '(repeat string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
351 :group 'python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
352 :tag "Pychecker Command Args")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
353
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
354 (defvar py-shell-alist
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
355 '(("jython" . 'jython)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
356 ("python" . 'cpython))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
357 "*Alist of interpreters and python shells. Used by `py-choose-shell'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
358 to select the appropriate python interpreter mode for a file.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
359
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
360 (defcustom py-shell-input-prompt-1-regexp "^>>> "
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
361 "*A regular expression to match the input prompt of the shell."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
362 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
363 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
364
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
365 (defcustom py-shell-input-prompt-2-regexp "^[.][.][.] "
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
366 "*A regular expression to match the input prompt of the shell after the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
367 first line of input."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
368 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
369 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
370
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
371 (defcustom py-shell-switch-buffers-on-execute t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
372 "*Controls switching to the Python buffer where commands are
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
373 executed. When non-nil the buffer switches to the Python buffer, if
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
374 not no switching occurs."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
375 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
376 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
377
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
378
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
379 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
380 ;; NO USER DEFINABLE VARIABLES BEYOND THIS POINT
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
381
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
382 (defvar py-line-number-offset 0
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
383 "When an exception occurs as a result of py-execute-region, a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
384 subsequent py-up-exception needs the line number where the region
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
385 started, in order to jump to the correct file line. This variable is
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
386 set in py-execute-region and used in py-jump-to-exception.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
387
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
388 (defconst py-emacs-features
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
389 (let (features)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
390 features)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
391 "A list of features extant in the Emacs you are using.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
392 There are many flavors of Emacs out there, with different levels of
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
393 support for features needed by `python-mode'.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
394
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
395 ;; Face for None, True, False, self, and Ellipsis
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
396 (defvar py-pseudo-keyword-face 'py-pseudo-keyword-face
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
397 "Face for pseudo keywords in Python mode, like self, True, False, Ellipsis.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
398 (make-face 'py-pseudo-keyword-face)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
399
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
400 ;; PEP 318 decorators
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
401 (defvar py-decorators-face 'py-decorators-face
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
402 "Face method decorators.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
403 (make-face 'py-decorators-face)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
404
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
405 ;; Face for builtins
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
406 (defvar py-builtins-face 'py-builtins-face
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
407 "Face for builtins like TypeError, object, open, and exec.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
408 (make-face 'py-builtins-face)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
409
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
410 ;; XXX, TODO, and FIXME comments and such
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
411 (defvar py-XXX-tag-face 'py-XXX-tag-face
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
412 "Face for XXX, TODO, and FIXME tags")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
413 (make-face 'py-XXX-tag-face)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
414
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
415 (defun py-font-lock-mode-hook ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
416 (or (face-differs-from-default-p 'py-pseudo-keyword-face)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
417 (copy-face 'font-lock-keyword-face 'py-pseudo-keyword-face))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
418 (or (face-differs-from-default-p 'py-builtins-face)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
419 (copy-face 'font-lock-keyword-face 'py-builtins-face))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
420 (or (face-differs-from-default-p 'py-decorators-face)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
421 (copy-face 'py-pseudo-keyword-face 'py-decorators-face))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
422 (or (face-differs-from-default-p 'py-XXX-tag-face)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
423 (copy-face 'font-lock-comment-face 'py-XXX-tag-face))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
424 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
425 (add-hook 'font-lock-mode-hook 'py-font-lock-mode-hook)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
426
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
427 (defvar python-font-lock-keywords
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
428 (let ((kw1 (mapconcat 'identity
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
429 '("and" "assert" "break" "class"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
430 "continue" "def" "del" "elif"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
431 "else" "except" "for" "from"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
432 "global" "if" "import" "in"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
433 "is" "lambda" "not" "or"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
434 "pass" "raise" "as" "return"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
435 "while" "with" "yield"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
436 )
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
437 "\\|"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
438 (kw2 (mapconcat 'identity
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
439 '("else:" "except:" "finally:" "try:")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
440 "\\|"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
441 (kw3 (mapconcat 'identity
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
442 ;; Don't include Ellipsis in this list, since it is
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
443 ;; already defined as a pseudo keyword.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
444 '("__debug__"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
445 "__import__" "__name__" "abs" "all" "any" "apply"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
446 "basestring" "bin" "bool" "buffer" "bytearray"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
447 "callable" "chr" "classmethod" "cmp" "coerce"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
448 "compile" "complex" "copyright" "credits"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
449 "delattr" "dict" "dir" "divmod" "enumerate" "eval"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
450 "exec" "execfile" "exit" "file" "filter" "float"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
451 "format" "getattr" "globals" "hasattr" "hash" "help"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
452 "hex" "id" "input" "int" "intern" "isinstance"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
453 "issubclass" "iter" "len" "license" "list" "locals"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
454 "long" "map" "max" "memoryview" "min" "next"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
455 "object" "oct" "open" "ord" "pow" "print" "property"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
456 "quit" "range" "raw_input" "reduce" "reload" "repr"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
457 "round" "set" "setattr" "slice" "sorted"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
458 "staticmethod" "str" "sum" "super" "tuple" "type"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
459 "unichr" "unicode" "vars" "xrange" "zip")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
460 "\\|"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
461 (kw4 (mapconcat 'identity
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
462 ;; Exceptions and warnings
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
463 '("ArithmeticError" "AssertionError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
464 "AttributeError" "BaseException" "BufferError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
465 "BytesWarning" "DeprecationWarning" "EOFError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
466 "EnvironmentError" "Exception"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
467 "FloatingPointError" "FutureWarning" "GeneratorExit"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
468 "IOError" "ImportError" "ImportWarning"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
469 "IndentationError" "IndexError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
470 "KeyError" "KeyboardInterrupt" "LookupError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
471 "MemoryError" "NameError" "NotImplemented"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
472 "NotImplementedError" "OSError" "OverflowError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
473 "PendingDeprecationWarning" "ReferenceError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
474 "RuntimeError" "RuntimeWarning" "StandardError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
475 "StopIteration" "SyntaxError" "SyntaxWarning"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
476 "SystemError" "SystemExit" "TabError" "TypeError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
477 "UnboundLocalError" "UnicodeDecodeError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
478 "UnicodeEncodeError" "UnicodeError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
479 "UnicodeTranslateError" "UnicodeWarning"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
480 "UserWarning" "ValueError" "Warning"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
481 "ZeroDivisionError")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
482 "\\|"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
483 )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
484 (list
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
485 '("^[ \t]*\\(@.+\\)" 1 'py-decorators-face)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
486 ;; keywords
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
487 (cons (concat "\\<\\(" kw1 "\\)\\>[ \n\t(]") 1)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
488 ;; builtins when they don't appear as object attributes
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
489 (list (concat "\\([^. \t]\\|^\\)[ \t]*\\<\\(" kw3 "\\)\\>[ \n\t(]") 2
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
490 'py-builtins-face)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
491 ;; block introducing keywords with immediately following colons.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
492 ;; Yes "except" is in both lists.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
493 (cons (concat "\\<\\(" kw2 "\\)[ \n\t(]") 1)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
494 ;; Exceptions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
495 (list (concat "\\<\\(" kw4 "\\)[ \n\t:,(]") 1 'py-builtins-face)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
496 ;; classes
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
497 '("\\<class[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)" 1 font-lock-type-face)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
498 ;; functions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
499 '("\\<def[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
500 1 font-lock-function-name-face)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
501 ;; pseudo-keywords
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
502 '("\\<\\(self\\|Ellipsis\\|True\\|False\\|None\\)\\>"
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
503 1 py-pseudo-keyword-face)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
504 ;; XXX, TODO, and FIXME tags
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
505 '("XXX\\|TODO\\|FIXME" 0 py-XXX-tag-face t)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
506 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
507 "Additional expressions to highlight in Python mode.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
508 (put 'python-mode 'font-lock-defaults '(python-font-lock-keywords))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
509
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
510 ;; have to bind py-file-queue before installing the kill-emacs-hook
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
511 (defvar py-file-queue nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
512 "Queue of Python temp files awaiting execution.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
513 Currently-active file is at the head of the list.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
514
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
515 (defvar py-pdbtrack-is-tracking-p nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
516
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
517 (defvar py-pychecker-history nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
518
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
519
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
520
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
521 ;; Constants
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
522
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
523 (defconst py-stringlit-re
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
524 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
525 ;; These fail if backslash-quote ends the string (not worth
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
526 ;; fixing?). They precede the short versions so that the first two
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
527 ;; quotes don't look like an empty short string.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
528 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
529 ;; (maybe raw), long single quoted triple quoted strings (SQTQ),
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
530 ;; with potential embedded single quotes
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
531 "[rR]?'''[^']*\\(\\('[^']\\|''[^']\\)[^']*\\)*'''"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
532 "\\|"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
533 ;; (maybe raw), long double quoted triple quoted strings (DQTQ),
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
534 ;; with potential embedded double quotes
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
535 "[rR]?\"\"\"[^\"]*\\(\\(\"[^\"]\\|\"\"[^\"]\\)[^\"]*\\)*\"\"\""
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
536 "\\|"
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
537 "[rR]?'\\([^'\n\\]\\|\\\\.\\)*'" ; single-quoted
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
538 "\\|" ; or
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
539 "[rR]?\"\\([^\"\n\\]\\|\\\\.\\)*\"" ; double-quoted
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
540 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
541 "Regular expression matching a Python string literal.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
542
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
543 (defconst py-continued-re
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
544 ;; This is tricky because a trailing backslash does not mean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
545 ;; continuation if it's in a comment
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
546 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
547 "\\(" "[^#'\"\n\\]" "\\|" py-stringlit-re "\\)*"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
548 "\\\\$")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
549 "Regular expression matching Python backslash continuation lines.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
550
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
551 (defconst py-blank-or-comment-re "[ \t]*\\($\\|#\\)"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
552 "Regular expression matching a blank or comment line.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
553
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
554 (defconst py-outdent-re
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
555 (concat "\\(" (mapconcat 'identity
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
556 '("else:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
557 "except\\(\\s +.*\\)?:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
558 "finally:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
559 "elif\\s +.*:")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
560 "\\|")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
561 "\\)")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
562 "Regular expression matching statements to be dedented one level.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
563
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
564 (defconst py-block-closing-keywords-re
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
565 "\\(return\\|raise\\|break\\|continue\\|pass\\)"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
566 "Regular expression matching keywords which typically close a block.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
567
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
568 (defconst py-no-outdent-re
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
569 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
570 "\\("
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
571 (mapconcat 'identity
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
572 (list "try:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
573 "except\\(\\s +.*\\)?:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
574 "while\\s +.*:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
575 "for\\s +.*:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
576 "if\\s +.*:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
577 "elif\\s +.*:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
578 (concat py-block-closing-keywords-re "[ \t\n]")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
579 )
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
580 "\\|")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
581 "\\)")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
582 "Regular expression matching lines not to dedent after.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
583
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
584 (defvar py-traceback-line-re
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
585 "[ \t]+File \"\\([^\"]+\\)\", line \\([0-9]+\\)"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
586 "Regular expression that describes tracebacks.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
587
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
588 ;; pdbtrack constants
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
589 (defconst py-pdbtrack-stack-entry-regexp
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
590 ; "^> \\([^(]+\\)(\\([0-9]+\\))\\([?a-zA-Z0-9_]+\\)()"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
591 "^> \\(.*\\)(\\([0-9]+\\))\\([?a-zA-Z0-9_]+\\)()"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
592 "Regular expression pdbtrack uses to find a stack trace entry.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
593
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
594 (defconst py-pdbtrack-input-prompt "\n[(<]*[Pp]db[>)]+ "
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
595 "Regular expression pdbtrack uses to recognize a pdb prompt.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
596
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
597 (defconst py-pdbtrack-track-range 10000
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
598 "Max number of characters from end of buffer to search for stack entry.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
599
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
600
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
601
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
602 ;; Major mode boilerplate
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
603
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
604 ;; define a mode-specific abbrev table for those who use such things
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
605 (defvar python-mode-abbrev-table nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
606 "Abbrev table in use in `python-mode' buffers.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
607 (define-abbrev-table 'python-mode-abbrev-table nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
608
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
609 (defvar python-mode-hook nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
610 "*Hook called by `python-mode'.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
611
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
612 (make-obsolete-variable 'jpython-mode-hook 'jython-mode-hook)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
613 (defvar jython-mode-hook nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
614 "*Hook called by `jython-mode'. `jython-mode' also calls
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
615 `python-mode-hook'.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
616
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
617 (defvar py-shell-hook nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
618 "*Hook called by `py-shell'.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
619
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
620 ;; In previous version of python-mode.el, the hook was incorrectly
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
621 ;; called py-mode-hook, and was not defvar'd. Deprecate its use.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
622 (and (fboundp 'make-obsolete-variable)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
623 (make-obsolete-variable 'py-mode-hook 'python-mode-hook))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
624
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
625 (defvar py-mode-map ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
626 "Keymap used in `python-mode' buffers.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
627 (if py-mode-map
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
628 nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
629 (setq py-mode-map (make-sparse-keymap))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
630 ;; electric keys
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
631 (define-key py-mode-map ":" 'py-electric-colon)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
632 ;; indentation level modifiers
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
633 (define-key py-mode-map "\C-c\C-l" 'py-shift-region-left)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
634 (define-key py-mode-map "\C-c\C-r" 'py-shift-region-right)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
635 (define-key py-mode-map "\C-c<" 'py-shift-region-left)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
636 (define-key py-mode-map "\C-c>" 'py-shift-region-right)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
637 ;; subprocess commands
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
638 (define-key py-mode-map "\C-c\C-c" 'py-execute-buffer)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
639 (define-key py-mode-map "\C-c\C-m" 'py-execute-import-or-reload)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
640 (define-key py-mode-map "\C-c\C-s" 'py-execute-string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
641 (define-key py-mode-map "\C-c|" 'py-execute-region)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
642 (define-key py-mode-map "\e\C-x" 'py-execute-def-or-class)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
643 (define-key py-mode-map "\C-c!" 'py-shell)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
644 (define-key py-mode-map "\C-c\C-t" 'py-toggle-shells)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
645 ;; Caution! Enter here at your own risk. We are trying to support
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
646 ;; several behaviors and it gets disgusting. :-( This logic ripped
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
647 ;; largely from CC Mode.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
648 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
649 ;; In XEmacs 19, Emacs 19, and Emacs 20, we use this to bind
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
650 ;; backwards deletion behavior to DEL, which both Delete and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
651 ;; Backspace get translated to. There's no way to separate this
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
652 ;; behavior in a clean way, so deal with it! Besides, it's been
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
653 ;; this way since the dawn of time.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
654 (if (not (boundp 'delete-key-deletes-forward))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
655 (define-key py-mode-map "\177" 'py-electric-backspace)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
656 ;; However, XEmacs 20 actually achieved enlightenment. It is
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
657 ;; possible to sanely define both backward and forward deletion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
658 ;; behavior under X separately (TTYs are forever beyond hope, but
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
659 ;; who cares? XEmacs 20 does the right thing with these too).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
660 (define-key py-mode-map [delete] 'py-electric-delete)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
661 (define-key py-mode-map [backspace] 'py-electric-backspace))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
662 ;; Separate M-BS from C-M-h. The former should remain
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
663 ;; backward-kill-word.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
664 (define-key py-mode-map [(control meta h)] 'py-mark-def-or-class)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
665 (define-key py-mode-map "\C-c\C-k" 'py-mark-block)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
666 ;; Miscellaneous
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
667 (define-key py-mode-map "\C-c:" 'py-guess-indent-offset)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
668 (define-key py-mode-map "\C-c\t" 'py-indent-region)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
669 (define-key py-mode-map "\C-c\C-d" 'py-pdbtrack-toggle-stack-tracking)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
670 (define-key py-mode-map "\C-c\C-f" 'py-sort-imports)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
671 (define-key py-mode-map "\C-c\C-n" 'py-next-statement)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
672 (define-key py-mode-map "\C-c\C-p" 'py-previous-statement)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
673 (define-key py-mode-map "\C-c\C-u" 'py-goto-block-up)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
674 (define-key py-mode-map "\C-c#" 'py-comment-region)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
675 (define-key py-mode-map "\C-c?" 'py-describe-mode)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
676 (define-key py-mode-map "\C-c\C-h" 'py-help-at-point)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
677 (define-key py-mode-map "\e\C-a" 'py-beginning-of-def-or-class)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
678 (define-key py-mode-map "\e\C-e" 'py-end-of-def-or-class)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
679 (define-key py-mode-map "\C-c-" 'py-up-exception)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
680 (define-key py-mode-map "\C-c=" 'py-down-exception)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
681 ;; stuff that is `standard' but doesn't interface well with
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
682 ;; python-mode, which forces us to rebind to special commands
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
683 (define-key py-mode-map "\C-xnd" 'py-narrow-to-defun)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
684 ;; information
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
685 (define-key py-mode-map "\C-c\C-b" 'py-submit-bug-report)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
686 (define-key py-mode-map "\C-c\C-v" 'py-version)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
687 (define-key py-mode-map "\C-c\C-w" 'py-pychecker-run)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
688 ;; shadow global bindings for newline-and-indent w/ the py- version.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
689 ;; BAW - this is extremely bad form, but I'm not going to change it
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
690 ;; for now.
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
691 (mapc #'(lambda (key)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
692 (define-key py-mode-map key 'py-newline-and-indent))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
693 (where-is-internal 'newline-and-indent))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
694 ;; Force RET to be py-newline-and-indent even if it didn't get
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
695 ;; mapped by the above code. motivation: Emacs' default binding for
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
696 ;; RET is `newline' and C-j is `newline-and-indent'. Most Pythoneers
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
697 ;; expect RET to do a `py-newline-and-indent' and any Emacsers who
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
698 ;; dislike this are probably knowledgeable enough to do a rebind.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
699 ;; However, we do *not* change C-j since many Emacsers have already
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
700 ;; swapped RET and C-j and they don't want C-j bound to `newline' to
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
701 ;; change.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
702 (define-key py-mode-map "\C-m" 'py-newline-and-indent)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
703 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
704
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
705 (defvar py-mode-output-map nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
706 "Keymap used in *Python Output* buffers.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
707 (if py-mode-output-map
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
708 nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
709 (setq py-mode-output-map (make-sparse-keymap))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
710 (define-key py-mode-output-map [button2] 'py-mouseto-exception)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
711 (define-key py-mode-output-map "\C-c\C-c" 'py-goto-exception)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
712 ;; TBD: Disable all self-inserting keys. This is bogus, we should
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
713 ;; really implement this as *Python Output* buffer being read-only
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
714 (mapc #' (lambda (key)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
715 (define-key py-mode-output-map key
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
716 #'(lambda () (interactive) (beep))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
717 (where-is-internal 'self-insert-command))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
718 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
719
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
720 (defvar py-shell-map nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
721 "Keymap used in *Python* shell buffers.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
722 (if py-shell-map
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
723 nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
724 (setq py-shell-map (copy-keymap comint-mode-map))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
725 (define-key py-shell-map [tab] 'tab-to-tab-stop)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
726 (define-key py-shell-map "\C-c-" 'py-up-exception)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
727 (define-key py-shell-map "\C-c=" 'py-down-exception)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
728 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
729
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
730 (defvar py-mode-syntax-table nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
731 "Syntax table used in `python-mode' buffers.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
732 (when (not py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
733 (setq py-mode-syntax-table (make-syntax-table))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
734 (modify-syntax-entry ?\( "()" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
735 (modify-syntax-entry ?\) ")(" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
736 (modify-syntax-entry ?\[ "(]" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
737 (modify-syntax-entry ?\] ")[" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
738 (modify-syntax-entry ?\{ "(}" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
739 (modify-syntax-entry ?\} "){" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
740 ;; Add operator symbols misassigned in the std table
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
741 (modify-syntax-entry ?\$ "." py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
742 (modify-syntax-entry ?\% "." py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
743 (modify-syntax-entry ?\& "." py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
744 (modify-syntax-entry ?\* "." py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
745 (modify-syntax-entry ?\+ "." py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
746 (modify-syntax-entry ?\- "." py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
747 (modify-syntax-entry ?\/ "." py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
748 (modify-syntax-entry ?\< "." py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
749 (modify-syntax-entry ?\= "." py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
750 (modify-syntax-entry ?\> "." py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
751 (modify-syntax-entry ?\| "." py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
752 ;; For historical reasons, underscore is word class instead of
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
753 ;; symbol class. GNU conventions say it should be symbol class, but
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
754 ;; there's a natural conflict between what major mode authors want
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
755 ;; and what users expect from `forward-word' and `backward-word'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
756 ;; Guido and I have hashed this out and have decided to keep
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
757 ;; underscore in word class. If you're tempted to change it, try
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
758 ;; binding M-f and M-b to py-forward-into-nomenclature and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
759 ;; py-backward-into-nomenclature instead. This doesn't help in all
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
760 ;; situations where you'd want the different behavior
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
761 ;; (e.g. backward-kill-word).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
762 (modify-syntax-entry ?\_ "w" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
763 ;; Both single quote and double quote are string delimiters
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
764 (modify-syntax-entry ?\' "\"" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
765 (modify-syntax-entry ?\" "\"" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
766 ;; backquote is open and close paren
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
767 (modify-syntax-entry ?\` "$" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
768 ;; comment delimiters
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
769 (modify-syntax-entry ?\# "<" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
770 (modify-syntax-entry ?\n ">" py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
771 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
772
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
773 ;; An auxiliary syntax table which places underscore and dot in the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
774 ;; symbol class for simplicity
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
775 (defvar py-dotted-expression-syntax-table nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
776 "Syntax table used to identify Python dotted expressions.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
777 (when (not py-dotted-expression-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
778 (setq py-dotted-expression-syntax-table
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
779 (copy-syntax-table py-mode-syntax-table))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
780 (modify-syntax-entry ?_ "_" py-dotted-expression-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
781 (modify-syntax-entry ?. "_" py-dotted-expression-syntax-table))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
782
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
783
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
784
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
785 ;; Utilities
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
786 (defmacro py-safe (&rest body)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
787 "Safely execute BODY, return nil if an error occurred."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
788 `(condition-case nil
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
789 (progn ,@ body)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
790 (error nil)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
791
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
792 (defsubst py-keep-region-active ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
793 "Keep the region active in XEmacs."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
794 ;; Ignore byte-compiler warnings you might see. Also note that
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
795 ;; FSF's Emacs 19 does it differently; its policy doesn't require us
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
796 ;; to take explicit action.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
797 (and (boundp 'zmacs-region-stays)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
798 (setq zmacs-region-stays t)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
799
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
800 (defsubst py-point (position)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
801 "Returns the value of point at certain commonly referenced POSITIONs.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
802 POSITION can be one of the following symbols:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
803
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
804 bol -- beginning of line
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
805 eol -- end of line
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
806 bod -- beginning of def or class
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
807 eod -- end of def or class
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
808 bob -- beginning of buffer
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
809 eob -- end of buffer
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
810 boi -- back to indentation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
811 bos -- beginning of statement
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
812
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
813 This function does not modify point or mark."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
814 (let ((here (point)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
815 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
816 ((eq position 'bol) (beginning-of-line))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
817 ((eq position 'eol) (end-of-line))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
818 ((eq position 'bod) (py-beginning-of-def-or-class 'either))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
819 ((eq position 'eod) (py-end-of-def-or-class 'either))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
820 ;; Kind of funny, I know, but useful for py-up-exception.
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
821 ((eq position 'bob) (goto-char (point-min)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
822 ((eq position 'eob) (goto-char (point-max)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
823 ((eq position 'boi) (back-to-indentation))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
824 ((eq position 'bos) (py-goto-initial-line))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
825 (t (error "Unknown buffer position requested: %s" position))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
826 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
827 (prog1
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
828 (point)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
829 (goto-char here))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
830
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
831 (defsubst py-highlight-line (from to file line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
832 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
833 ((fboundp 'make-extent)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
834 ;; XEmacs
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
835 (let ((e (make-extent from to)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
836 (set-extent-property e 'mouse-face 'highlight)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
837 (set-extent-property e 'py-exc-info (cons file line))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
838 (set-extent-property e 'keymap py-mode-output-map)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
839 (t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
840 ;; Emacs -- Please port this!
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
841 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
842 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
843
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
844 (defun py-in-literal (&optional lim)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
845 "Return non-nil if point is in a Python literal (a comment or string).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
846 Optional argument LIM indicates the beginning of the containing form,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
847 i.e. the limit on how far back to scan."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
848 ;; This is the version used for non-XEmacs, which has a nicer
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
849 ;; interface.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
850 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
851 ;; WARNING: Watch out for infinite recursion.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
852 (let* ((lim (or lim (py-point 'bod)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
853 (state (parse-partial-sexp lim (point))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
854 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
855 ((nth 3 state) 'string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
856 ((nth 4 state) 'comment)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
857 (t nil))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
858
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
859 ;; XEmacs has a built-in function that should make this much quicker.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
860 ;; In this case, lim is ignored
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
861 (defun py-fast-in-literal (&optional lim)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
862 "Fast version of `py-in-literal', used only by XEmacs.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
863 Optional LIM is ignored."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
864 ;; don't have to worry about context == 'block-comment
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
865 (buffer-syntactic-context))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
866
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
867 (if (fboundp 'buffer-syntactic-context)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
868 (defalias 'py-in-literal 'py-fast-in-literal))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
869
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
870
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
871
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
872 ;; Menu definitions, only relevent if you have the easymenu.el package
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
873 ;; (standard in the latest Emacs 19 and XEmacs 19 distributions).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
874 (defvar py-menu nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
875 "Menu for Python Mode.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
876 This menu will get created automatically if you have the `easymenu'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
877 package. Note that the latest X/Emacs releases contain this package.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
878
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
879 (and (py-safe (require 'easymenu) t)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
880 (easy-menu-define
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
881 py-menu py-mode-map "Python Mode menu"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
882 '("Python"
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
883 ["Comment Out Region" py-comment-region (mark)]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
884 ["Uncomment Region" (py-comment-region (point) (mark) '(4)) (mark)]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
885 "-"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
886 ["Mark current block" py-mark-block t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
887 ["Mark current def" py-mark-def-or-class t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
888 ["Mark current class" (py-mark-def-or-class t) t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
889 "-"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
890 ["Shift region left" py-shift-region-left (mark)]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
891 ["Shift region right" py-shift-region-right (mark)]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
892 "-"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
893 ["Import/reload file" py-execute-import-or-reload t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
894 ["Execute buffer" py-execute-buffer t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
895 ["Execute region" py-execute-region (mark)]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
896 ["Execute def or class" py-execute-def-or-class (mark)]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
897 ["Execute string" py-execute-string t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
898 ["Start interpreter..." py-shell t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
899 "-"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
900 ["Go to start of block" py-goto-block-up t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
901 ["Go to start of class" (py-beginning-of-def-or-class t) t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
902 ["Move to end of class" (py-end-of-def-or-class t) t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
903 ["Move to start of def" py-beginning-of-def-or-class t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
904 ["Move to end of def" py-end-of-def-or-class t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
905 "-"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
906 ["Describe mode" py-describe-mode t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
907 )))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
908
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
909
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
910
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
911 ;; Imenu definitions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
912 (defvar py-imenu-class-regexp
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
913 (concat ; <<classes>>
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
914 "\\(" ;
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
915 "^[ \t]*" ; newline and maybe whitespace
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
916 "\\(class[ \t]+[a-zA-Z0-9_]+\\)" ; class name
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
917 ; possibly multiple superclasses
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
918 "\\([ \t]*\\((\\([a-zA-Z0-9_,. \t\n]\\)*)\\)?\\)"
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
919 "[ \t]*:" ; and the final :
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
920 "\\)" ; >>classes<<
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
921 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
922 "Regexp for Python classes for use with the Imenu package."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
923 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
924
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
925 (defvar py-imenu-method-regexp
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
926 (concat ; <<methods and functions>>
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
927 "\\(" ;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
928 "^[ \t]*" ; new line and maybe whitespace
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
929 "\\(def[ \t]+" ; function definitions start with def
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
930 "\\([a-zA-Z0-9_]+\\)" ; name is here
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
931 ; function arguments...
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
932 ;; "[ \t]*(\\([-+/a-zA-Z0-9_=,\* \t\n.()\"'#]*\\))"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
933 "[ \t]*(\\([^:#]*\\))"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
934 "\\)" ; end of def
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
935 "[ \t]*:" ; and then the :
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
936 "\\)" ; >>methods and functions<<
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
937 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
938 "Regexp for Python methods/functions for use with the Imenu package."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
939 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
940
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
941 (defvar py-imenu-method-no-arg-parens '(2 8)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
942 "Indices into groups of the Python regexp for use with Imenu.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
943
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
944 Using these values will result in smaller Imenu lists, as arguments to
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
945 functions are not listed.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
946
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
947 See the variable `py-imenu-show-method-args-p' for more
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
948 information.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
949
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
950 (defvar py-imenu-method-arg-parens '(2 7)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
951 "Indices into groups of the Python regexp for use with imenu.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
952 Using these values will result in large Imenu lists, as arguments to
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
953 functions are listed.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
954
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
955 See the variable `py-imenu-show-method-args-p' for more
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
956 information.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
957
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
958 ;; Note that in this format, this variable can still be used with the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
959 ;; imenu--generic-function. Otherwise, there is no real reason to have
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
960 ;; it.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
961 (defvar py-imenu-generic-expression
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
962 (cons
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
963 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
964 py-imenu-class-regexp
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
965 "\\|" ; or...
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
966 py-imenu-method-regexp
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
967 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
968 py-imenu-method-no-arg-parens)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
969 "Generic Python expression which may be used directly with Imenu.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
970 Used by setting the variable `imenu-generic-expression' to this value.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
971 Also, see the function \\[py-imenu-create-index] for a better
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
972 alternative for finding the index.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
973
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
974 ;; These next two variables are used when searching for the Python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
975 ;; class/definitions. Just saving some time in accessing the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
976 ;; generic-python-expression, really.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
977 (defvar py-imenu-generic-regexp nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
978 (defvar py-imenu-generic-parens nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
979
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
980
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
981 (defun py-imenu-create-index-function ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
982 "Python interface function for the Imenu package.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
983 Finds all Python classes and functions/methods. Calls function
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
984 \\[py-imenu-create-index-engine]. See that function for the details
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
985 of how this works."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
986 (setq py-imenu-generic-regexp (car py-imenu-generic-expression)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
987 py-imenu-generic-parens (if py-imenu-show-method-args-p
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
988 py-imenu-method-arg-parens
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
989 py-imenu-method-no-arg-parens))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
990 (goto-char (point-min))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
991 ;; Warning: When the buffer has no classes or functions, this will
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
992 ;; return nil, which seems proper according to the Imenu API, but
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
993 ;; causes an error in the XEmacs port of Imenu. Sigh.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
994 (py-imenu-create-index-engine nil))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
995
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
996 (defun py-imenu-create-index-engine (&optional start-indent)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
997 "Function for finding Imenu definitions in Python.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
998
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
999 Finds all definitions (classes, methods, or functions) in a Python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1000 file for the Imenu package.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1001
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1002 Returns a possibly nested alist of the form
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1003
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1004 (INDEX-NAME . INDEX-POSITION)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1005
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1006 The second element of the alist may be an alist, producing a nested
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1007 list as in
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1008
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1009 (INDEX-NAME . INDEX-ALIST)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1010
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1011 This function should not be called directly, as it calls itself
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1012 recursively and requires some setup. Rather this is the engine for
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1013 the function \\[py-imenu-create-index-function].
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1014
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1015 It works recursively by looking for all definitions at the current
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1016 indention level. When it finds one, it adds it to the alist. If it
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1017 finds a definition at a greater indentation level, it removes the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1018 previous definition from the alist. In its place it adds all
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1019 definitions found at the next indentation level. When it finds a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1020 definition that is less indented then the current level, it returns
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1021 the alist it has created thus far.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1022
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1023 The optional argument START-INDENT indicates the starting indentation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1024 at which to continue looking for Python classes, methods, or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1025 functions. If this is not supplied, the function uses the indentation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1026 of the first definition found."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1027 (let (index-alist
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1028 sub-method-alist
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1029 looking-p
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1030 def-name prev-name
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1031 cur-indent def-pos
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1032 (class-paren (first py-imenu-generic-parens))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1033 (def-paren (second py-imenu-generic-parens)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1034 (setq looking-p
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1035 (re-search-forward py-imenu-generic-regexp (point-max) t))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1036 (while looking-p
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1037 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1038 ;; used to set def-name to this value but generic-extract-name
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1039 ;; is new to imenu-1.14. this way it still works with
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1040 ;; imenu-1.11
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1041 ;;(imenu--generic-extract-name py-imenu-generic-parens))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1042 (let ((cur-paren (if (match-beginning class-paren)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1043 class-paren def-paren)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1044 (setq def-name
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1045 (buffer-substring-no-properties (match-beginning cur-paren)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1046 (match-end cur-paren))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1047 (save-match-data
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1048 (py-beginning-of-def-or-class 'either))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1049 (beginning-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1050 (setq cur-indent (current-indentation)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1051 ;; HACK: want to go to the next correct definition location. We
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1052 ;; explicitly list them here but it would be better to have them
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1053 ;; in a list.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1054 (setq def-pos
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1055 (or (match-beginning class-paren)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1056 (match-beginning def-paren)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1057 ;; if we don't have a starting indent level, take this one
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1058 (or start-indent
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1059 (setq start-indent cur-indent))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1060 ;; if we don't have class name yet, take this one
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1061 (or prev-name
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1062 (setq prev-name def-name))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1063 ;; what level is the next definition on? must be same, deeper
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1064 ;; or shallower indentation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1065 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1066 ;; Skip code in comments and strings
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1067 ((py-in-literal))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1068 ;; at the same indent level, add it to the list...
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1069 ((= start-indent cur-indent)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1070 (push (cons def-name def-pos) index-alist))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1071 ;; deeper indented expression, recurse
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1072 ((< start-indent cur-indent)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1073 ;; the point is currently on the expression we're supposed to
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1074 ;; start on, so go back to the last expression. The recursive
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1075 ;; call will find this place again and add it to the correct
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1076 ;; list
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1077 (re-search-backward py-imenu-generic-regexp (point-min) 'move)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1078 (setq sub-method-alist (py-imenu-create-index-engine cur-indent))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1079 (if sub-method-alist
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1080 ;; we put the last element on the index-alist on the start
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1081 ;; of the submethod alist so the user can still get to it.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1082 (let ((save-elmt (pop index-alist)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1083 (push (cons prev-name
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1084 (cons save-elmt sub-method-alist))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1085 index-alist))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1086 ;; found less indented expression, we're done.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1087 (t
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1088 (setq looking-p nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1089 (re-search-backward py-imenu-generic-regexp (point-min) t)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1090 ;; end-cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1091 (setq prev-name def-name)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1092 (and looking-p
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1093 (setq looking-p
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1094 (re-search-forward py-imenu-generic-regexp
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1095 (point-max) 'move))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1096 (nreverse index-alist)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1097
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1098
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1099
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1100 (defun py-choose-shell-by-shebang ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1101 "Choose CPython or Jython mode by looking at #! on the first line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1102 Returns the appropriate mode function.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1103 Used by `py-choose-shell', and similar to but distinct from
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1104 `set-auto-mode', though it uses `auto-mode-interpreter-regexp' (if available)."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1105 ;; look for an interpreter specified in the first line
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1106 ;; similar to set-auto-mode (files.el)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1107 (let* ((re (if (boundp 'auto-mode-interpreter-regexp)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1108 auto-mode-interpreter-regexp
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1109 ;; stolen from Emacs 21.2
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1110 "#![ \t]?\\([^ \t\n]*/bin/env[ \t]\\)?\\([^ \t\n]+\\)"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1111 (interpreter (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1112 (goto-char (point-min))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1113 (if (looking-at re)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1114 (match-string 2)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1115 "")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1116 elt)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1117 ;; Map interpreter name to a mode.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1118 (setq elt (assoc (file-name-nondirectory interpreter)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1119 py-shell-alist))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1120 (and elt (caddr elt))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1121
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1122
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1123
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1124 (defun py-choose-shell-by-import ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1125 "Choose CPython or Jython mode based imports.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1126 If a file imports any packages in `py-jython-packages', within
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1127 `py-import-check-point-max' characters from the start of the file,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1128 return `jython', otherwise return nil."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1129 (let (mode)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1130 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1131 (goto-char (point-min))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1132 (while (and (not mode)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1133 (search-forward-regexp
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1134 "^\\(\\(from\\)\\|\\(import\\)\\) \\([^ \t\n.]+\\)"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1135 py-import-check-point-max t))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1136 (setq mode (and (member (match-string 4) py-jython-packages)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1137 'jython
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1138 ))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1139 mode))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1140
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1141
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1142 (defun py-choose-shell ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1143 "Choose CPython or Jython mode. Returns the appropriate mode function.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1144 This does the following:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1145 - look for an interpreter with `py-choose-shell-by-shebang'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1146 - examine imports using `py-choose-shell-by-import'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1147 - default to the variable `py-default-interpreter'"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1148 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1149 (or (py-choose-shell-by-shebang)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1150 (py-choose-shell-by-import)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1151 py-default-interpreter
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1152 ; 'cpython ;; don't use to py-default-interpreter, because default
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1153 ; ;; is only way to choose CPython
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1154 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1155
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1156
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1157 ;;;###autoload
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1158 (defun python-mode ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1159 "Major mode for editing Python files.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1160 To submit a problem report, enter `\\[py-submit-bug-report]' from a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1161 `python-mode' buffer. Do `\\[py-describe-mode]' for detailed
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1162 documentation. To see what version of `python-mode' you are running,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1163 enter `\\[py-version]'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1164
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1165 This mode knows about Python indentation, tokens, comments and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1166 continuation lines. Paragraphs are separated by blank lines only.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1167
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1168 COMMANDS
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1169 \\{py-mode-map}
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1170 VARIABLES
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1171
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1172 py-indent-offset\t\tindentation increment
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1173 py-block-comment-prefix\t\tcomment string used by `comment-region'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1174 py-python-command\t\tshell command to invoke Python interpreter
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1175 py-temp-directory\t\tdirectory used for temp files (if needed)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1176 py-beep-if-tab-change\t\tring the bell if `tab-width' is changed"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1177 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1178 ;; set up local variables
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1179 (kill-all-local-variables)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1180 (make-local-variable 'font-lock-defaults)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1181 (make-local-variable 'paragraph-separate)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1182 (make-local-variable 'paragraph-start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1183 (make-local-variable 'require-final-newline)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1184 (make-local-variable 'comment-start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1185 (make-local-variable 'comment-end)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1186 (make-local-variable 'comment-start-skip)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1187 (make-local-variable 'comment-column)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1188 (make-local-variable 'comment-indent-function)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1189 (make-local-variable 'indent-region-function)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1190 (make-local-variable 'indent-line-function)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1191 (make-local-variable 'add-log-current-defun-function)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1192 (make-local-variable 'fill-paragraph-function)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1193 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1194 (set-syntax-table py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1195 (setq major-mode 'python-mode
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1196 mode-name "Python"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1197 local-abbrev-table python-mode-abbrev-table
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1198 font-lock-defaults '(python-font-lock-keywords)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1199 paragraph-separate "^[ \t]*$"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1200 paragraph-start "^[ \t]*$"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1201 require-final-newline t
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1202 comment-start "# "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1203 comment-end ""
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1204 comment-start-skip "# *"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1205 comment-column 40
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1206 comment-indent-function 'py-comment-indent-function
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1207 indent-region-function 'py-indent-region
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1208 indent-line-function 'py-indent-line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1209 ;; tell add-log.el how to find the current function/method/variable
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1210 add-log-current-defun-function 'py-current-defun
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1211
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1212 fill-paragraph-function 'py-fill-paragraph
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1213 )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1214 (use-local-map py-mode-map)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1215 ;; add the menu
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1216 (if py-menu
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1217 (easy-menu-add py-menu))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1218 ;; Emacs 19 requires this
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1219 (if (boundp 'comment-multi-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1220 (setq comment-multi-line nil))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1221 ;; Install Imenu if available
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1222 (when (py-safe (require 'imenu))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1223 (setq imenu-create-index-function #'py-imenu-create-index-function)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1224 (setq imenu-generic-expression py-imenu-generic-expression)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1225 (if (fboundp 'imenu-add-to-menubar)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1226 (imenu-add-to-menubar (format "%s-%s" "IM" mode-name)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1227 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1228 ;; Run the mode hook. Note that py-mode-hook is deprecated.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1229 (if python-mode-hook
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1230 (run-hooks 'python-mode-hook)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1231 (run-hooks 'py-mode-hook))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1232 ;; Now do the automagical guessing
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1233 (if py-smart-indentation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1234 (let ((offset py-indent-offset))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1235 ;; It's okay if this fails to guess a good value
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1236 (if (and (py-safe (py-guess-indent-offset))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1237 (<= py-indent-offset 8)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1238 (>= py-indent-offset 2))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1239 (setq offset py-indent-offset))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1240 (setq py-indent-offset offset)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1241 ;; Only turn indent-tabs-mode off if tab-width !=
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1242 ;; py-indent-offset. Never turn it on, because the user must
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1243 ;; have explicitly turned it off.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1244 (if (/= tab-width py-indent-offset)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1245 (setq indent-tabs-mode nil))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1246 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1247 ;; Set the default shell if not already set
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1248 (when (null py-which-shell)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1249 (py-toggle-shells (py-choose-shell))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1250
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1251
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1252 (make-obsolete 'jpython-mode 'jython-mode)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1253 (defun jython-mode ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1254 "Major mode for editing Jython/Jython files.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1255 This is a simple wrapper around `python-mode'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1256 It runs `jython-mode-hook' then calls `python-mode.'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1257 It is added to `interpreter-mode-alist' and `py-choose-shell'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1258 "
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1259 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1260 (python-mode)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1261 (py-toggle-shells 'jython)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1262 (when jython-mode-hook
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1263 (run-hooks 'jython-mode-hook)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1264
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1265
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1266 ;; It's handy to add recognition of Python files to the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1267 ;; interpreter-mode-alist and to auto-mode-alist. With the former, we
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1268 ;; can specify different `derived-modes' based on the #! line, but
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1269 ;; with the latter, we can't. So we just won't add them if they're
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1270 ;; already added.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1271 ;;;###autoload
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1272 (let ((modes '(("jython" . jython-mode)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1273 ("python" . python-mode))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1274 (while modes
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1275 (when (not (assoc (car modes) interpreter-mode-alist))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1276 (push (car modes) interpreter-mode-alist))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1277 (setq modes (cdr modes))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1278 ;;;###autoload
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1279 (when (not (or (rassq 'python-mode auto-mode-alist)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1280 (rassq 'jython-mode auto-mode-alist)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1281 (push '("\\.py$" . python-mode) auto-mode-alist))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1282
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1283
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1284
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1285 ;; electric characters
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1286 (defun py-outdent-p ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1287 "Returns non-nil if the current line should dedent one level."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1288 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1289 (and (progn (back-to-indentation)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1290 (looking-at py-outdent-re))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1291 ;; short circuit infloop on illegal construct
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1292 (not (bobp))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1293 (progn (forward-line -1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1294 (py-goto-initial-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1295 (back-to-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1296 (while (or (looking-at py-blank-or-comment-re)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1297 (bobp))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1298 (backward-to-indentation 1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1299 (not (looking-at py-no-outdent-re)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1300 )))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1301
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1302 (defun py-electric-colon (arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1303 "Insert a colon.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1304 In certain cases the line is dedented appropriately. If a numeric
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1305 argument ARG is provided, that many colons are inserted
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1306 non-electrically. Electric behavior is inhibited inside a string or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1307 comment."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1308 (interactive "*P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1309 (self-insert-command (prefix-numeric-value arg))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1310 ;; are we in a string or comment?
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1311 (if (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1312 (let ((pps (parse-partial-sexp (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1313 (py-beginning-of-def-or-class)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1314 (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1315 (point))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1316 (not (or (nth 3 pps) (nth 4 pps)))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1317 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1318 (let ((here (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1319 (outdent 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1320 (indent (py-compute-indentation t)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1321 (if (and (not arg)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1322 (py-outdent-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1323 (= indent (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1324 (py-next-statement -1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1325 (py-compute-indentation t)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1326 )
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1327 (setq outdent py-indent-offset))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1328 ;; Don't indent, only dedent. This assumes that any lines
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1329 ;; that are already dedented relative to
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1330 ;; py-compute-indentation were put there on purpose. It's
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1331 ;; highly annoying to have `:' indent for you. Use TAB, C-c
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1332 ;; C-l or C-c C-r to adjust. TBD: Is there a better way to
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1333 ;; determine this???
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1334 (if (< (current-indentation) indent) nil
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1335 (goto-char here)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1336 (beginning-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1337 (delete-horizontal-space)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1338 (indent-to (- indent outdent))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1339 )))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1340
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1341
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1342 ;; Python subprocess utilities and filters
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1343 (defun py-execute-file (proc filename)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1344 "Send to Python interpreter process PROC \"execfile('FILENAME')\".
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1345 Make that process's buffer visible and force display. Also make
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1346 comint believe the user typed this string so that
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1347 `kill-output-from-shell' does The Right Thing."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1348 (let ((curbuf (current-buffer))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1349 (procbuf (process-buffer proc))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1350 ; (comint-scroll-to-bottom-on-output t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1351 (msg (format "## working on region in file %s...\n" filename))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1352 ;; add some comment, so that we can filter it out of history
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1353 (cmd (format "execfile(r'%s') # PYTHON-MODE\n" filename)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1354 (unwind-protect
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1355 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1356 (set-buffer procbuf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1357 (goto-char (point-max))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1358 (move-marker (process-mark proc) (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1359 (funcall (process-filter proc) proc msg))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1360 (set-buffer curbuf))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1361 (process-send-string proc cmd)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1362
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1363 (defun py-comint-output-filter-function (string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1364 "Watch output for Python prompt and exec next file waiting in queue.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1365 This function is appropriate for `comint-output-filter-functions'."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1366 ;;remove ansi terminal escape sequences from string, not sure why they are
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1367 ;;still around...
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1368 (setq string (ansi-color-filter-apply string))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1369 (when (and (string-match py-shell-input-prompt-1-regexp string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1370 py-file-queue)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1371 (if py-shell-switch-buffers-on-execute
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1372 (pop-to-buffer (current-buffer)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1373 (py-safe (delete-file (car py-file-queue)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1374 (setq py-file-queue (cdr py-file-queue))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1375 (if py-file-queue
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1376 (let ((pyproc (get-buffer-process (current-buffer))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1377 (py-execute-file pyproc (car py-file-queue))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1378 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1379
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1380 (defun py-pdbtrack-overlay-arrow (activation)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1381 "Activate or de arrow at beginning-of-line in current buffer."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1382 ;; This was derived/simplified from edebug-overlay-arrow
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1383 (cond (activation
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1384 (setq overlay-arrow-position (make-marker))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1385 (setq overlay-arrow-string "=>")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1386 (set-marker overlay-arrow-position (py-point 'bol) (current-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1387 (setq py-pdbtrack-is-tracking-p t))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1388 (overlay-arrow-position
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1389 (setq overlay-arrow-position nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1390 (setq py-pdbtrack-is-tracking-p nil))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1391 ))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1392
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1393 (defun py-pdbtrack-track-stack-file (text)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1394 "Show the file indicated by the pdb stack entry line, in a separate window.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1395
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1396 Activity is disabled if the buffer-local variable
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1397 `py-pdbtrack-do-tracking-p' is nil.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1398
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1399 We depend on the pdb input prompt matching `py-pdbtrack-input-prompt'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1400 at the beginning of the line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1401
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1402 If the traceback target file path is invalid, we look for the most
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1403 recently visited python-mode buffer which either has the name of the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1404 current function \(or class) or which defines the function \(or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1405 class). This is to provide for remote scripts, eg, Zope's 'Script
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1406 (Python)' - put a _copy_ of the script in a buffer named for the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1407 script, and set to python-mode, and pdbtrack will find it.)"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1408 ;; Instead of trying to piece things together from partial text
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1409 ;; (which can be almost useless depending on Emacs version), we
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1410 ;; monitor to the point where we have the next pdb prompt, and then
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1411 ;; check all text from comint-last-input-end to process-mark.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1412 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1413 ;; Also, we're very conservative about clearing the overlay arrow,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1414 ;; to minimize residue. This means, for instance, that executing
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1415 ;; other pdb commands wipe out the highlight. You can always do a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1416 ;; 'where' (aka 'w') command to reveal the overlay arrow.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1417 (let* ((origbuf (current-buffer))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1418 (currproc (get-buffer-process origbuf)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1419
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1420 (if (not (and currproc py-pdbtrack-do-tracking-p))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1421 (py-pdbtrack-overlay-arrow nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1422
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1423 (let* ((procmark (process-mark currproc))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1424 (block (buffer-substring (max comint-last-input-end
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1425 (- procmark
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1426 py-pdbtrack-track-range))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1427 procmark))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1428 target target_fname target_lineno target_buffer)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1429
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1430 (if (not (string-match (concat py-pdbtrack-input-prompt "$") block))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1431 (py-pdbtrack-overlay-arrow nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1432
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1433 (setq target (py-pdbtrack-get-source-buffer block))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1434
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1435 (if (stringp target)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1436 (message "pdbtrack: %s" target)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1437
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1438 (setq target_lineno (car target))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1439 (setq target_buffer (cadr target))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1440 (setq target_fname (buffer-file-name target_buffer))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1441 (switch-to-buffer-other-window target_buffer)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1442 (goto-line target_lineno)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1443 (message "pdbtrack: line %s, file %s" target_lineno target_fname)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1444 (py-pdbtrack-overlay-arrow t)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1445 (pop-to-buffer origbuf t)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1446
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1447 )))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1448 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1449
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1450 (defun py-pdbtrack-get-source-buffer (block)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1451 "Return line number and buffer of code indicated by block's traceback text.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1452
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1453 We look first to visit the file indicated in the trace.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1454
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1455 Failing that, we look for the most recently visited python-mode buffer
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1456 with the same name or having the named function.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1457
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1458 If we're unable find the source code we return a string describing the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1459 problem as best as we can determine."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1460
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1461 (if (not (string-match py-pdbtrack-stack-entry-regexp block))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1462
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1463 "Traceback cue not found"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1464
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1465 (let* ((filename (match-string 1 block))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1466 (lineno (string-to-number (match-string 2 block)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1467 (funcname (match-string 3 block))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1468 funcbuffer)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1469
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1470 (cond ((file-exists-p filename)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1471 (list lineno (find-file-noselect filename)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1472
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1473 ((setq funcbuffer (py-pdbtrack-grub-for-buffer funcname lineno))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1474 (if (string-match "/Script (Python)$" filename)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1475 ;; Add in number of lines for leading '##' comments:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1476 (setq lineno
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1477 (+ lineno
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1478 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1479 (set-buffer funcbuffer)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1480 (count-lines
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1481 (point-min)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1482 (max (point-min)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1483 (string-match "^\\([^#]\\|#[^#]\\|#$\\)"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1484 (buffer-substring (point-min)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1485 (point-max)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1486 ))))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1487 (list lineno funcbuffer))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1488
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1489 ((= (elt filename 0) ?\<)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1490 (format "(Non-file source: '%s')" filename))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1491
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1492 (t (format "Not found: %s(), %s" funcname filename)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1493 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1494 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1495 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1496
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1497 (defun py-pdbtrack-grub-for-buffer (funcname lineno)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1498 "Find most recent buffer itself named or having function funcname.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1499
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1500 We walk the buffer-list history for python-mode buffers that are
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1501 named for funcname or define a function funcname."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1502 (let ((buffers (buffer-list))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1503 buf
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1504 got)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1505 (while (and buffers (not got))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1506 (setq buf (car buffers)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1507 buffers (cdr buffers))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1508 (if (and (save-excursion (set-buffer buf)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1509 (string= major-mode "python-mode"))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1510 (or (string-match funcname (buffer-name buf))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1511 (string-match (concat "^\\s-*\\(def\\|class\\)\\s-+"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1512 funcname "\\s-*(")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1513 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1514 (set-buffer buf)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1515 (buffer-substring (point-min)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1516 (point-max))))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1517 (setq got buf)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1518 got))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1519
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1520 (defun py-postprocess-output-buffer (buf)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1521 "Highlight exceptions found in BUF.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1522 If an exception occurred return t, otherwise return nil. BUF must exist."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1523 (let (line file bol err-p)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1524 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1525 (set-buffer buf)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1526 (goto-char (point-min))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1527 (while (re-search-forward py-traceback-line-re nil t)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1528 (setq file (match-string 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1529 line (string-to-number (match-string 2))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1530 bol (py-point 'bol))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1531 (py-highlight-line bol (py-point 'eol) file line)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1532 (when (and py-jump-on-exception line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1533 (beep)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1534 (py-jump-to-exception file line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1535 (setq err-p t))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1536 err-p))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1537
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1538
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1539
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1540 ;;; Subprocess commands
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1541
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1542 ;; only used when (memq 'broken-temp-names py-emacs-features)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1543 (defvar py-serial-number 0)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1544 (defvar py-exception-buffer nil)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1545 (defvar py-output-buffer "*Python Output*")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1546 (make-variable-buffer-local 'py-output-buffer)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1547
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1548 ;; for toggling between CPython and Jython
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1549 (defvar py-which-shell nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1550 (defvar py-which-args py-python-command-args)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1551 (defvar py-which-bufname "Python")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1552 (make-variable-buffer-local 'py-which-shell)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1553 (make-variable-buffer-local 'py-which-args)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1554 (make-variable-buffer-local 'py-which-bufname)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1555
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1556 (defun py-toggle-shells (arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1557 "Toggles between the CPython and Jython shells.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1558
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1559 With positive argument ARG (interactively \\[universal-argument]),
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1560 uses the CPython shell, with negative ARG uses the Jython shell, and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1561 with a zero argument, toggles the shell.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1562
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1563 Programmatically, ARG can also be one of the symbols `cpython' or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1564 `jython', equivalent to positive arg and negative arg respectively."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1565 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1566 ;; default is to toggle
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1567 (if (null arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1568 (setq arg 0))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1569 ;; preprocess arg
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1570 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1571 ((equal arg 0)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1572 ;; toggle
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1573 (if (string-equal py-which-bufname "Python")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1574 (setq arg -1)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1575 (setq arg 1)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1576 ((equal arg 'cpython) (setq arg 1))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1577 ((equal arg 'jython) (setq arg -1)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1578 (let (msg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1579 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1580 ((< 0 arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1581 ;; set to CPython
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1582 (setq py-which-shell py-python-command
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1583 py-which-args py-python-command-args
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1584 py-which-bufname "Python"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1585 msg "CPython")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1586 (if (string-equal py-which-bufname "Jython")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1587 (setq mode-name "Python")))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1588 ((> 0 arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1589 (setq py-which-shell py-jython-command
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1590 py-which-args py-jython-command-args
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1591 py-which-bufname "Jython"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1592 msg "Jython")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1593 (if (string-equal py-which-bufname "Python")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1594 (setq mode-name "Jython")))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1595 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1596 (message "Using the %s shell" msg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1597 (setq py-output-buffer (format "*%s Output*" py-which-bufname))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1598
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1599 ;;;###autoload
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1600 (defun py-shell (&optional argprompt)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1601 "Start an interactive Python interpreter in another window.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1602 This is like Shell mode, except that Python is running in the window
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1603 instead of a shell. See the `Interactive Shell' and `Shell Mode'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1604 sections of the Emacs manual for details, especially for the key
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1605 bindings active in the `*Python*' buffer.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1606
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1607 With optional \\[universal-argument], the user is prompted for the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1608 flags to pass to the Python interpreter. This has no effect when this
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1609 command is used to switch to an existing process, only when a new
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1610 process is started. If you use this, you will probably want to ensure
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1611 that the current arguments are retained (they will be included in the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1612 prompt). This argument is ignored when this function is called
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1613 programmatically, or when running in Emacs 19.34 or older.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1614
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1615 Note: You can toggle between using the CPython interpreter and the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1616 Jython interpreter by hitting \\[py-toggle-shells]. This toggles
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1617 buffer local variables which control whether all your subshell
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1618 interactions happen to the `*Jython*' or `*Python*' buffers (the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1619 latter is the name used for the CPython buffer).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1620
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1621 Warning: Don't use an interactive Python if you change sys.ps1 or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1622 sys.ps2 from their default values, or if you're running code that
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1623 prints `>>> ' or `... ' at the start of a line. `python-mode' can't
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1624 distinguish your output from Python's output, and assumes that `>>> '
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1625 at the start of a line is a prompt from Python. Similarly, the Emacs
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1626 Shell mode code assumes that both `>>> ' and `... ' at the start of a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1627 line are Python prompts. Bad things can happen if you fool either
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1628 mode.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1629
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1630 Warning: If you do any editing *in* the process buffer *while* the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1631 buffer is accepting output from Python, do NOT attempt to `undo' the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1632 changes. Some of the output (nowhere near the parts you changed!) may
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1633 be lost if you do. This appears to be an Emacs bug, an unfortunate
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1634 interaction between undo and process filters; the same problem exists in
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1635 non-Python process buffers using the default (Emacs-supplied) process
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1636 filter."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1637 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1638 ;; Set the default shell if not already set
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1639 (when (null py-which-shell)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1640 (py-toggle-shells py-default-interpreter))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1641 (let ((args py-which-args))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1642 (when (and argprompt
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1643 (interactive-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1644 (fboundp 'split-string))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1645 ;; TBD: Perhaps force "-i" in the final list?
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1646 (setq args (split-string
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1647 (read-string (concat py-which-bufname
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1648 " arguments: ")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1649 (concat
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1650 (mapconcat 'identity py-which-args " ") " ")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1651 ))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1652 (if (not (equal (buffer-name) "*Python*"))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1653 (switch-to-buffer-other-window
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1654 (apply 'make-comint py-which-bufname py-which-shell nil args))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1655 (apply 'make-comint py-which-bufname py-which-shell nil args))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1656 (make-local-variable 'comint-prompt-regexp)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1657 (setq comint-prompt-regexp (concat py-shell-input-prompt-1-regexp "\\|"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1658 py-shell-input-prompt-2-regexp "\\|"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1659 "^([Pp]db) "))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1660 (add-hook 'comint-output-filter-functions
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1661 'py-comint-output-filter-function)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1662 ;; pdbtrack
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1663 (add-hook 'comint-output-filter-functions 'py-pdbtrack-track-stack-file)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1664 (setq py-pdbtrack-do-tracking-p t)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1665 (set-syntax-table py-mode-syntax-table)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1666 (use-local-map py-shell-map)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1667 (run-hooks 'py-shell-hook)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1668 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1669
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1670 (defun py-clear-queue ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1671 "Clear the queue of temporary files waiting to execute."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1672 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1673 (let ((n (length py-file-queue)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1674 (mapc 'delete-file py-file-queue)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1675 (setq py-file-queue nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1676 (message "%d pending files de-queued." n)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1677
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1678
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1679 (defun py-execute-region (start end &optional async)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1680 "Execute the region in a Python interpreter.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1681
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1682 The region is first copied into a temporary file (in the directory
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1683 `py-temp-directory'). If there is no Python interpreter shell
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1684 running, this file is executed synchronously using
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1685 `shell-command-on-region'. If the program is long running, use
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1686 \\[universal-argument] to run the command asynchronously in its own
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1687 buffer.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1688
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1689 When this function is used programmatically, arguments START and END
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1690 specify the region to execute, and optional third argument ASYNC, if
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1691 non-nil, specifies to run the command asynchronously in its own
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1692 buffer.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1693
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1694 If the Python interpreter shell is running, the region is execfile()'d
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1695 in that shell. If you try to execute regions too quickly,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1696 `python-mode' will queue them up and execute them one at a time when
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1697 it sees a `>>> ' prompt from Python. Each time this happens, the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1698 process buffer is popped into a window (if it's not already in some
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1699 window) so you can see it, and a comment of the form
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1700
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1701 \t## working on region in file <name>...
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1702
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1703 is inserted at the end. See also the command `py-clear-queue'."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1704 (interactive "r\nP")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1705 ;; Skip ahead to the first non-blank line
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1706 (let* ((proc (get-process py-which-bufname))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1707 (temp (if (memq 'broken-temp-names py-emacs-features)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1708 (let
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1709 ((sn py-serial-number)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1710 (pid (and (fboundp 'emacs-pid) (emacs-pid))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1711 (setq py-serial-number (1+ py-serial-number))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1712 (if pid
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1713 (format "python-%d-%d" sn pid)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1714 (format "python-%d" sn)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1715 (make-temp-name "python-")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1716 (file (concat (expand-file-name temp py-temp-directory) ".py"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1717 (cur (current-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1718 (buf (get-buffer-create file))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1719 shell)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1720 ;; Write the contents of the buffer, watching out for indented regions.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1721 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1722 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1723 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1724 (while (and (looking-at "\\s *$")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1725 (< (point) end))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1726 (forward-line 1))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1727 (setq start (point))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1728 (or (< start end)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1729 (error "Region is empty"))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1730 (setq py-line-number-offset (count-lines 1 start))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1731 (let ((needs-if (/= (py-point 'bol) (py-point 'boi))))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1732 (set-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1733 (python-mode)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1734 (when needs-if
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1735 (insert "if 1:\n")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1736 (setq py-line-number-offset (- py-line-number-offset 1)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1737 (insert-buffer-substring cur start end)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1738 ;; Set the shell either to the #! line command, or to the
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1739 ;; py-which-shell buffer local variable.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1740 (setq shell (or (py-choose-shell-by-shebang)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1741 (py-choose-shell-by-import)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1742 py-which-shell))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1743 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1744 ;; always run the code in its own asynchronous subprocess
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1745 (async
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1746 ;; User explicitly wants this to run in its own async subprocess
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1747 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1748 (set-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1749 (write-region (point-min) (point-max) file nil 'nomsg))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1750 (let* ((buf (generate-new-buffer-name py-output-buffer))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1751 ;; TBD: a horrible hack, but why create new Custom variables?
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1752 (arg (if (string-equal py-which-bufname "Python")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1753 "-u" "")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1754 (start-process py-which-bufname buf shell arg file)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1755 (pop-to-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1756 (py-postprocess-output-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1757 ;; TBD: clean up the temporary file!
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1758 ))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1759 ;; if the Python interpreter shell is running, queue it up for
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1760 ;; execution there.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1761 (proc
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1762 ;; use the existing python shell
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1763 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1764 (set-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1765 (write-region (point-min) (point-max) file nil 'nomsg))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1766 (if (not py-file-queue)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1767 (py-execute-file proc file)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1768 (message "File %s queued for execution" file))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1769 (setq py-file-queue (append py-file-queue (list file)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1770 (setq py-exception-buffer (cons file (current-buffer))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1771 (t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1772 ;; TBD: a horrible hack, but why create new Custom variables?
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1773 (let ((cmd (concat py-which-shell (if (string-equal py-which-bufname
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1774 "Jython")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1775 " -" ""))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1776 ;; otherwise either run it synchronously in a subprocess
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1777 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1778 (set-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1779 (shell-command-on-region (point-min) (point-max)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1780 cmd py-output-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1781 ;; shell-command-on-region kills the output buffer if it never
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1782 ;; existed and there's no output from the command
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1783 (if (not (get-buffer py-output-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1784 (message "No output.")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1785 (setq py-exception-buffer (current-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1786 (let ((err-p (py-postprocess-output-buffer py-output-buffer)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1787 (pop-to-buffer py-output-buffer)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1788 (if err-p
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1789 (pop-to-buffer py-exception-buffer)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1790 ))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1791 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1792 ;; Clean up after ourselves.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1793 (kill-buffer buf)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1794
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1795
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1796 ;; Code execution commands
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1797 (defun py-execute-buffer (&optional async)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1798 "Send the contents of the buffer to a Python interpreter.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1799 If the file local variable `py-master-file' is non-nil, execute the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1800 named file instead of the buffer's file.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1801
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1802 If there is a *Python* process buffer it is used. If a clipping
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1803 restriction is in effect, only the accessible portion of the buffer is
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1804 sent. A trailing newline will be supplied if needed.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1805
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1806 See the `\\[py-execute-region]' docs for an account of some
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1807 subtleties, including the use of the optional ASYNC argument."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1808 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1809 (let ((old-buffer (current-buffer)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1810 (if py-master-file
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1811 (let* ((filename (expand-file-name py-master-file))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1812 (buffer (or (get-file-buffer filename)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1813 (find-file-noselect filename))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1814 (set-buffer buffer)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1815 (py-execute-region (point-min) (point-max) async)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1816 (pop-to-buffer old-buffer)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1817
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1818 (defun py-execute-import-or-reload (&optional async)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1819 "Import the current buffer's file in a Python interpreter.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1820
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1821 If the file has already been imported, then do reload instead to get
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1822 the latest version.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1823
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1824 If the file's name does not end in \".py\", then do execfile instead.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1825
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1826 If the current buffer is not visiting a file, do `py-execute-buffer'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1827 instead.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1828
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1829 If the file local variable `py-master-file' is non-nil, import or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1830 reload the named file instead of the buffer's file. The file may be
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1831 saved based on the value of `py-execute-import-or-reload-save-p'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1832
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1833 See the `\\[py-execute-region]' docs for an account of some
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1834 subtleties, including the use of the optional ASYNC argument.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1835
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1836 This may be preferable to `\\[py-execute-buffer]' because:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1837
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1838 - Definitions stay in their module rather than appearing at top
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1839 level, where they would clutter the global namespace and not affect
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1840 uses of qualified names (MODULE.NAME).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1841
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1842 - The Python debugger gets line number information about the functions."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1843 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1844 ;; Check file local variable py-master-file
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1845 (if py-master-file
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1846 (let* ((filename (expand-file-name py-master-file))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1847 (buffer (or (get-file-buffer filename)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1848 (find-file-noselect filename))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1849 (set-buffer buffer)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1850 (let ((file (buffer-file-name (current-buffer))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1851 (if file
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1852 (progn
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1853 ;; Maybe save some buffers
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1854 (save-some-buffers (not py-ask-about-save) nil)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1855 (py-execute-string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1856 (if (string-match "\\.py$" file)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1857 (let ((f (file-name-sans-extension
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1858 (file-name-nondirectory file))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1859 (format "if globals().has_key('%s'):\n reload(%s)\nelse:\n import %s\n"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1860 f f f))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1861 (format "execfile(r'%s')\n" file))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1862 async))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1863 ;; else
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1864 (py-execute-buffer async))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1865
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1866
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1867 (defun py-execute-def-or-class (&optional async)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1868 "Send the current function or class definition to a Python interpreter.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1869
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1870 If there is a *Python* process buffer it is used.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1871
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1872 See the `\\[py-execute-region]' docs for an account of some
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1873 subtleties, including the use of the optional ASYNC argument."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1874 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1875 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1876 (py-mark-def-or-class)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1877 ;; mark is before point
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1878 (py-execute-region (mark) (point) async)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1879
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1880
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1881 (defun py-execute-string (string &optional async)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1882 "Send the argument STRING to a Python interpreter.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1883
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1884 If there is a *Python* process buffer it is used.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1885
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1886 See the `\\[py-execute-region]' docs for an account of some
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1887 subtleties, including the use of the optional ASYNC argument."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1888 (interactive "sExecute Python command: ")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1889 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1890 (set-buffer (get-buffer-create
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1891 (generate-new-buffer-name " *Python Command*")))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1892 (insert string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1893 (py-execute-region (point-min) (point-max) async)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1894
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1895
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1896
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1897 (defun py-jump-to-exception (file line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1898 "Jump to the Python code in FILE at LINE."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1899 (let ((buffer (cond ((string-equal file "<stdin>")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1900 (if (consp py-exception-buffer)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1901 (cdr py-exception-buffer)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1902 py-exception-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1903 ((and (consp py-exception-buffer)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1904 (string-equal file (car py-exception-buffer)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1905 (cdr py-exception-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1906 ((py-safe (find-file-noselect file)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1907 ;; could not figure out what file the exception
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1908 ;; is pointing to, so prompt for it
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1909 (t (find-file (read-file-name "Exception file: "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1910 nil
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1911 file t))))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1912 ;; Fiddle about with line number
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1913 (setq line (+ py-line-number-offset line))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1914
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1915 (pop-to-buffer buffer)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1916 ;; Force Python mode
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1917 (if (not (eq major-mode 'python-mode))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1918 (python-mode))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1919 (goto-line line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1920 (message "Jumping to exception in file %s on line %d" file line)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1921
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1922 (defun py-mouseto-exception (event)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1923 "Jump to the code which caused the Python exception at EVENT.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1924 EVENT is usually a mouse click."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1925 (interactive "e")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1926 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1927 ((fboundp 'event-point)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1928 ;; XEmacs
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1929 (let* ((point (event-point event))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1930 (buffer (event-buffer event))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1931 (e (and point buffer (extent-at point buffer 'py-exc-info)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1932 (info (and e (extent-property e 'py-exc-info))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1933 (message "Event point: %d, info: %s" point info)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1934 (and info
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1935 (py-jump-to-exception (car info) (cdr info)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1936 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1937 ;; Emacs -- Please port this!
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1938 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1939
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1940 (defun py-goto-exception ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1941 "Go to the line indicated by the traceback."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1942 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1943 (let (file line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1944 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1945 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1946 (if (looking-at py-traceback-line-re)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1947 (setq file (match-string 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1948 line (string-to-number (match-string 2)))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1949 (if (not file)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1950 (error "Not on a traceback line"))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1951 (py-jump-to-exception file line)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1952
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1953 (defun py-find-next-exception (start buffer searchdir errwhere)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1954 "Find the next Python exception and jump to the code that caused it.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1955 START is the buffer position in BUFFER from which to begin searching
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1956 for an exception. SEARCHDIR is a function, either
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1957 `re-search-backward' or `re-search-forward' indicating the direction
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1958 to search. ERRWHERE is used in an error message if the limit (top or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1959 bottom) of the trackback stack is encountered."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1960 (let (file line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1961 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1962 (set-buffer buffer)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1963 (goto-char (py-point start))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1964 (if (funcall searchdir py-traceback-line-re nil t)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1965 (setq file (match-string 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1966 line (string-to-number (match-string 2)))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1967 (if (and file line)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1968 (py-jump-to-exception file line)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1969 (error "%s of traceback" errwhere))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1970
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1971 (defun py-down-exception (&optional bottom)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1972 "Go to the next line down in the traceback.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1973 With \\[univeral-argument] (programmatically, optional argument
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1974 BOTTOM), jump to the bottom (innermost) exception in the exception
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1975 stack."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1976 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1977 (let* ((proc (get-process "Python"))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1978 (buffer (if proc "*Python*" py-output-buffer)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1979 (if bottom
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1980 (py-find-next-exception 'eob buffer 're-search-backward "Bottom")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1981 (py-find-next-exception 'eol buffer 're-search-forward "Bottom"))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1982
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1983 (defun py-up-exception (&optional top)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1984 "Go to the previous line up in the traceback.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1985 With \\[universal-argument] (programmatically, optional argument TOP)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1986 jump to the top (outermost) exception in the exception stack."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1987 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1988 (let* ((proc (get-process "Python"))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1989 (buffer (if proc "*Python*" py-output-buffer)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1990 (if top
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1991 (py-find-next-exception 'bob buffer 're-search-forward "Top")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1992 (py-find-next-exception 'bol buffer 're-search-backward "Top"))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1993
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1994
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1995 ;; Electric deletion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1996 (defun py-electric-backspace (arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1997 "Delete preceding character or levels of indentation.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1998 Deletion is performed by calling the function in `py-backspace-function'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1999 with a single argument (the number of characters to delete).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2000
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2001 If point is at the leftmost column, delete the preceding newline.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2002
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2003 Otherwise, if point is at the leftmost non-whitespace character of a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2004 line that is neither a continuation line nor a non-indenting comment
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2005 line, or if point is at the end of a blank line, this command reduces
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2006 the indentation to match that of the line that opened the current
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2007 block of code. The line that opened the block is displayed in the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2008 echo area to help you keep track of where you are. With
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2009 \\[universal-argument] dedents that many blocks (but not past column
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2010 zero).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2011
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2012 Otherwise the preceding character is deleted, converting a tab to
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2013 spaces if needed so that only a single column position is deleted.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2014 \\[universal-argument] specifies how many characters to delete;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2015 default is 1.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2016
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2017 When used programmatically, argument ARG specifies the number of
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2018 blocks to dedent, or the number of characters to delete, as indicated
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2019 above."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2020 (interactive "*p")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2021 (if (or (/= (current-indentation) (current-column))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2022 (bolp)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2023 (py-continuation-line-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2024 ; (not py-honor-comment-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2025 ; (looking-at "#[^ \t\n]") ; non-indenting #
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2026 )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2027 (funcall py-backspace-function arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2028 ;; else indent the same as the colon line that opened the block
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2029 ;; force non-blank so py-goto-block-up doesn't ignore it
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2030 (insert-char ?* 1)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2031 (backward-char)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2032 (let ((base-indent 0) ; indentation of base line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2033 (base-text "") ; and text of base line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2034 (base-found-p nil))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2035 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2036 (while (< 0 arg)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2037 (condition-case nil ; in case no enclosing block
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2038 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2039 (py-goto-block-up 'no-mark)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2040 (setq base-indent (current-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2041 base-text (py-suck-up-leading-text)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2042 base-found-p t))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2043 (error nil))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2044 (setq arg (1- arg))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2045 (delete-char 1) ; toss the dummy character
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2046 (delete-horizontal-space)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2047 (indent-to base-indent)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2048 (if base-found-p
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2049 (message "Closes block: %s" base-text)))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2050
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2051
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2052 (defun py-electric-delete (arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2053 "Delete preceding or following character or levels of whitespace.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2054
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2055 The behavior of this function depends on the variable
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2056 `delete-key-deletes-forward'. If this variable is nil (or does not
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2057 exist, as in older Emacsen and non-XEmacs versions), then this
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2058 function behaves identically to \\[c-electric-backspace].
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2059
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2060 If `delete-key-deletes-forward' is non-nil and is supported in your
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2061 Emacs, then deletion occurs in the forward direction, by calling the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2062 function in `py-delete-function'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2063
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2064 \\[universal-argument] (programmatically, argument ARG) specifies the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2065 number of characters to delete (default is 1)."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2066 (interactive "*p")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2067 (if (or (and (fboundp 'delete-forward-p) ;XEmacs 21
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2068 (delete-forward-p))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2069 (and (boundp 'delete-key-deletes-forward) ;XEmacs 20
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2070 delete-key-deletes-forward))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2071 (funcall py-delete-function arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2072 (py-electric-backspace arg)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2073
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2074 ;; required for pending-del and delsel modes
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2075 (put 'py-electric-colon 'delete-selection t) ;delsel
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2076 (put 'py-electric-colon 'pending-delete t) ;pending-del
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2077 (put 'py-electric-backspace 'delete-selection 'supersede) ;delsel
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2078 (put 'py-electric-backspace 'pending-delete 'supersede) ;pending-del
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2079 (put 'py-electric-delete 'delete-selection 'supersede) ;delsel
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2080 (put 'py-electric-delete 'pending-delete 'supersede) ;pending-del
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2081
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2082
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2083
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2084 (defun py-indent-line (&optional arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2085 "Fix the indentation of the current line according to Python rules.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2086 With \\[universal-argument] (programmatically, the optional argument
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2087 ARG non-nil), ignore dedenting rules for block closing statements
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2088 (e.g. return, raise, break, continue, pass)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2089
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2090 This function is normally bound to `indent-line-function' so
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2091 \\[indent-for-tab-command] will call it."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2092 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2093 (let* ((ci (current-indentation))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2094 (move-to-indentation-p (<= (current-column) ci))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2095 (need (py-compute-indentation (not arg)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2096 (cc (current-column)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2097 ;; dedent out a level if previous command was the same unless we're in
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2098 ;; column 1
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2099 (if (and (equal last-command this-command)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2100 (/= cc 0))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2101 (progn
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2102 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2103 (delete-horizontal-space)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2104 (indent-to (* (/ (- cc 1) py-indent-offset) py-indent-offset)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2105 (progn
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2106 ;; see if we need to dedent
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2107 (if (py-outdent-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2108 (setq need (- need py-indent-offset)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2109 (if (or py-tab-always-indent
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2110 move-to-indentation-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2111 (progn (if (/= ci need)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2112 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2113 (beginning-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2114 (delete-horizontal-space)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2115 (indent-to need)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2116 (if move-to-indentation-p (back-to-indentation)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2117 (insert-tab))))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2118
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2119 (defun py-newline-and-indent ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2120 "Strives to act like the Emacs `newline-and-indent'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2121 This is just `strives to' because correct indentation can't be computed
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2122 from scratch for Python code. In general, deletes the whitespace before
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2123 point, inserts a newline, and takes an educated guess as to how you want
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2124 the new line indented."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2125 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2126 (let ((ci (current-indentation)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2127 (if (< ci (current-column)) ; if point beyond indentation
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2128 (newline-and-indent)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2129 ;; else try to act like newline-and-indent "normally" acts
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2130 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2131 (insert-char ?\n 1)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2132 (move-to-column ci))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2133
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2134 (defun py-compute-indentation (honor-block-close-p)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2135 "Compute Python indentation.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2136 When HONOR-BLOCK-CLOSE-P is non-nil, statements such as `return',
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2137 `raise', `break', `continue', and `pass' force one level of
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2138 dedenting."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2139 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2140 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2141 (let* ((bod (py-point 'bod))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2142 (pps (parse-partial-sexp bod (point)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2143 (boipps (parse-partial-sexp bod (py-point 'boi)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2144 placeholder)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2145 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2146 ;; are we inside a multi-line string or comment?
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2147 ((or (and (nth 3 pps) (nth 3 boipps))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2148 (and (nth 4 pps) (nth 4 boipps)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2149 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2150 (if (not py-align-multiline-strings-p) 0
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2151 ;; skip back over blank & non-indenting comment lines
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2152 ;; note: will skip a blank or non-indenting comment line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2153 ;; that happens to be a continuation line too
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2154 (re-search-backward "^[ \t]*\\([^ \t\n#]\\|#[ \t\n]\\)" nil 'move)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2155 (back-to-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2156 (current-column))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2157 ;; are we on a continuation line?
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2158 ((py-continuation-line-p)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2159 (let ((startpos (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2160 (open-bracket-pos (py-nesting-level))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2161 endpos searching found state cind cline)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2162 (if open-bracket-pos
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2163 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2164 (setq endpos (py-point 'bol))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2165 (py-goto-initial-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2166 (setq cind (current-indentation))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2167 (setq cline cind)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2168 (dolist (bp
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2169 (nth 9 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2170 (parse-partial-sexp (point) endpos)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2171 cind)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2172 (if (search-forward "\n" bp t) (setq cline cind))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2173 (goto-char (1+ bp))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2174 (skip-chars-forward " \t")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2175 (setq cind (if (memq (following-char) '(?\n ?# ?\\))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2176 (+ cline py-indent-offset)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2177 (current-column)))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2178 ;; else on backslash continuation line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2179 (forward-line -1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2180 (if (py-continuation-line-p) ; on at least 3rd line in block
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2181 (current-indentation) ; so just continue the pattern
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2182 ;; else started on 2nd line in block, so indent more.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2183 ;; if base line is an assignment with a start on a RHS,
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2184 ;; indent to 2 beyond the leftmost "="; else skip first
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2185 ;; chunk of non-whitespace characters on base line, + 1 more
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2186 ;; column
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2187 (end-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2188 (setq endpos (point)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2189 searching t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2190 (back-to-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2191 (setq startpos (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2192 ;; look at all "=" from left to right, stopping at first
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2193 ;; one not nested in a list or string
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2194 (while searching
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2195 (skip-chars-forward "^=" endpos)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2196 (if (= (point) endpos)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2197 (setq searching nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2198 (forward-char 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2199 (setq state (parse-partial-sexp startpos (point)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2200 (if (and (zerop (car state)) ; not in a bracket
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2201 (null (nth 3 state))) ; & not in a string
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2202 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2203 (setq searching nil) ; done searching in any case
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2204 (setq found
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2205 (not (or
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2206 (eq (following-char) ?=)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2207 (memq (char-after (- (point) 2))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2208 '(?< ?> ?!)))))))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2209 (if (or (not found) ; not an assignment
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2210 (looking-at "[ \t]*\\\\")) ; <=><spaces><backslash>
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2211 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2212 (goto-char startpos)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2213 (skip-chars-forward "^ \t\n")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2214 ;; if this is a continuation for a block opening
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2215 ;; statement, add some extra offset.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2216 (+ (current-column) (if (py-statement-opens-block-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2217 py-continuation-offset 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2218 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2219 ))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2220
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2221 ;; not on a continuation line
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2222 ((bobp) (current-indentation))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2223
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2224 ;; Dfn: "Indenting comment line". A line containing only a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2225 ;; comment, but which is treated like a statement for
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2226 ;; indentation calculation purposes. Such lines are only
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2227 ;; treated specially by the mode; they are not treated
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2228 ;; specially by the Python interpreter.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2229
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2230 ;; The rules for indenting comment lines are a line where:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2231 ;; - the first non-whitespace character is `#', and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2232 ;; - the character following the `#' is whitespace, and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2233 ;; - the line is dedented with respect to (i.e. to the left
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2234 ;; of) the indentation of the preceding non-blank line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2235
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2236 ;; The first non-blank line following an indenting comment
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2237 ;; line is given the same amount of indentation as the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2238 ;; indenting comment line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2239
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2240 ;; All other comment-only lines are ignored for indentation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2241 ;; purposes.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2242
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2243 ;; Are we looking at a comment-only line which is *not* an
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2244 ;; indenting comment line? If so, we assume that it's been
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2245 ;; placed at the desired indentation, so leave it alone.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2246 ;; Indenting comment lines are aligned as statements down
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2247 ;; below.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2248 ((and (looking-at "[ \t]*#[^ \t\n]")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2249 ;; NOTE: this test will not be performed in older Emacsen
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2250 (fboundp 'forward-comment)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2251 (<= (current-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2252 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2253 (forward-comment (- (point-max)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2254 (current-indentation))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2255 (current-indentation))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2256
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2257 ;; else indentation based on that of the statement that
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2258 ;; precedes us; use the first line of that statement to
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2259 ;; establish the base, in case the user forced a non-std
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2260 ;; indentation for the continuation lines (if any)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2261 (t
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2262 ;; skip back over blank & non-indenting comment lines note:
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2263 ;; will skip a blank or non-indenting comment line that
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2264 ;; happens to be a continuation line too. use fast Emacs 19
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2265 ;; function if it's there.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2266 (if (and (eq py-honor-comment-indentation nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2267 (fboundp 'forward-comment))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2268 (forward-comment (- (point-max)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2269 (let ((prefix-re (concat py-block-comment-prefix "[ \t]*"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2270 done)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2271 (while (not done)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2272 (re-search-backward "^[ \t]*\\([^ \t\n#]\\|#\\)" nil 'move)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2273 (setq done (or (bobp)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2274 (and (eq py-honor-comment-indentation t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2275 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2276 (back-to-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2277 (not (looking-at prefix-re))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2278 ))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2279 (and (not (eq py-honor-comment-indentation t))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2280 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2281 (back-to-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2282 (and (not (looking-at prefix-re))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2283 (or (looking-at "[^#]")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2284 (not (zerop (current-column)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2285 ))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2286 ))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2287 ))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2288 )))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2289 ;; if we landed inside a string, go to the beginning of that
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2290 ;; string. this handles triple quoted, multi-line spanning
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2291 ;; strings.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2292 (py-goto-beginning-of-tqs (nth 3 (parse-partial-sexp bod (point))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2293 ;; now skip backward over continued lines
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2294 (setq placeholder (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2295 (py-goto-initial-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2296 ;; we may *now* have landed in a TQS, so find the beginning of
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2297 ;; this string.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2298 (py-goto-beginning-of-tqs
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2299 (save-excursion (nth 3 (parse-partial-sexp
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2300 placeholder (point)))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2301 (+ (current-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2302 (if (py-statement-opens-block-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2303 py-indent-offset
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2304 (if (and honor-block-close-p (py-statement-closes-block-p))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2305 (- py-indent-offset)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2306 0)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2307 )))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2308
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2309 (defun py-guess-indent-offset (&optional global)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2310 "Guess a good value for, and change, `py-indent-offset'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2311
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2312 By default, make a buffer-local copy of `py-indent-offset' with the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2313 new value, so that other Python buffers are not affected. With
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2314 \\[universal-argument] (programmatically, optional argument GLOBAL),
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2315 change the global value of `py-indent-offset'. This affects all
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2316 Python buffers (that don't have their own buffer-local copy), both
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2317 those currently existing and those created later in the Emacs session.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2318
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2319 Some people use a different value for `py-indent-offset' than you use.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2320 There's no excuse for such foolishness, but sometimes you have to deal
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2321 with their ugly code anyway. This function examines the file and sets
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2322 `py-indent-offset' to what it thinks it was when they created the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2323 mess.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2324
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2325 Specifically, it searches forward from the statement containing point,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2326 looking for a line that opens a block of code. `py-indent-offset' is
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2327 set to the difference in indentation between that line and the Python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2328 statement following it. If the search doesn't succeed going forward,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2329 it's tried again going backward."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2330 (interactive "P") ; raw prefix arg
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2331 (let (new-value
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2332 (start (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2333 (restart (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2334 (found nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2335 colon-indent)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2336 (py-goto-initial-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2337 (while (not (or found (eobp)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2338 (when (and (re-search-forward ":[ \t]*\\($\\|[#\\]\\)" nil 'move)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2339 (not (py-in-literal restart)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2340 (setq restart (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2341 (py-goto-initial-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2342 (if (py-statement-opens-block-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2343 (setq found t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2344 (goto-char restart))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2345 (unless found
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2346 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2347 (py-goto-initial-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2348 (while (not (or found (bobp)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2349 (setq found (and
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2350 (re-search-backward ":[ \t]*\\($\\|[#\\]\\)" nil 'move)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2351 (or (py-goto-initial-line) t) ; always true -- side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2352 (py-statement-opens-block-p)))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2353 (setq colon-indent (current-indentation)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2354 found (and found (zerop (py-next-statement 1)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2355 new-value (- (current-indentation) colon-indent))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2356 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2357 (if (not found)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2358 (error "Sorry, couldn't guess a value for py-indent-offset")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2359 (funcall (if global 'kill-local-variable 'make-local-variable)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2360 'py-indent-offset)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2361 (setq py-indent-offset new-value)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2362 (or noninteractive
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2363 (message "%s value of py-indent-offset set to %d"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2364 (if global "Global" "Local")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2365 py-indent-offset)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2366 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2367
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2368 (defun py-comment-indent-function ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2369 "Python version of `comment-indent-function'."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2370 ;; This is required when filladapt is turned off. Without it, when
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2371 ;; filladapt is not used, comments which start in column zero
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2372 ;; cascade one character to the right
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2373 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2374 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2375 (let ((eol (py-point 'eol)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2376 (and comment-start-skip
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2377 (re-search-forward comment-start-skip eol t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2378 (setq eol (match-beginning 0)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2379 (goto-char eol)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2380 (skip-chars-backward " \t")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2381 (max comment-column (+ (current-column) (if (bolp) 0 1)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2382 )))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2383
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2384 (defun py-narrow-to-defun (&optional class)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2385 "Make text outside current defun invisible.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2386 The defun visible is the one that contains point or follows point.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2387 Optional CLASS is passed directly to `py-beginning-of-def-or-class'."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2388 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2389 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2390 (widen)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2391 (py-end-of-def-or-class class)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2392 (let ((end (point)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2393 (py-beginning-of-def-or-class class)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2394 (narrow-to-region (point) end))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2395
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2396
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2397 (defun py-shift-region (start end count)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2398 "Indent lines from START to END by COUNT spaces."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2399 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2400 (goto-char end)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2401 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2402 (setq end (point))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2403 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2404 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2405 (setq start (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2406 (let (deactivate-mark)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2407 (indent-rigidly start end count))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2408
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2409 (defun py-shift-region-left (start end &optional count)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2410 "Shift region of Python code to the left.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2411 The lines from the line containing the start of the current region up
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2412 to (but not including) the line containing the end of the region are
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2413 shifted to the left, by `py-indent-offset' columns.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2414
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2415 If a prefix argument is given, the region is instead shifted by that
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2416 many columns. With no active region, dedent only the current line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2417 You cannot dedent the region if any line is already at column zero."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2418 (interactive
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2419 (let ((p (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2420 (m (condition-case nil (mark) (mark-inactive nil)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2421 (arg current-prefix-arg))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2422 (if m
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2423 (list (min p m) (max p m) arg)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2424 (list p (save-excursion (forward-line 1) (point)) arg))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2425 ;; if any line is at column zero, don't shift the region
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2426 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2427 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2428 (while (< (point) end)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2429 (back-to-indentation)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2430 (if (and (zerop (current-column))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2431 (not (looking-at "\\s *$")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2432 (error "Region is at left edge"))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2433 (forward-line 1)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2434 (py-shift-region start end (- (prefix-numeric-value
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2435 (or count py-indent-offset))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2436 (py-keep-region-active))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2437
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2438 (defun py-shift-region-right (start end &optional count)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2439 "Shift region of Python code to the right.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2440 The lines from the line containing the start of the current region up
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2441 to (but not including) the line containing the end of the region are
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2442 shifted to the right, by `py-indent-offset' columns.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2443
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2444 If a prefix argument is given, the region is instead shifted by that
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2445 many columns. With no active region, indent only the current line."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2446 (interactive
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2447 (let ((p (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2448 (m (condition-case nil (mark) (mark-inactive nil)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2449 (arg current-prefix-arg))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2450 (if m
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2451 (list (min p m) (max p m) arg)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2452 (list p (save-excursion (forward-line 1) (point)) arg))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2453 (py-shift-region start end (prefix-numeric-value
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2454 (or count py-indent-offset)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2455 (py-keep-region-active))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2456
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2457 (defun py-indent-region (start end &optional indent-offset)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2458 "Reindent a region of Python code.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2459
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2460 The lines from the line containing the start of the current region up
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2461 to (but not including) the line containing the end of the region are
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2462 reindented. If the first line of the region has a non-whitespace
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2463 character in the first column, the first line is left alone and the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2464 rest of the region is reindented with respect to it. Else the entire
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2465 region is reindented with respect to the (closest code or indenting
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2466 comment) statement immediately preceding the region.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2467
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2468 This is useful when code blocks are moved or yanked, when enclosing
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2469 control structures are introduced or removed, or to reformat code
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2470 using a new value for the indentation offset.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2471
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2472 If a numeric prefix argument is given, it will be used as the value of
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2473 the indentation offset. Else the value of `py-indent-offset' will be
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2474 used.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2475
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2476 Warning: The region must be consistently indented before this function
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2477 is called! This function does not compute proper indentation from
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2478 scratch (that's impossible in Python), it merely adjusts the existing
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2479 indentation to be correct in context.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2480
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2481 Warning: This function really has no idea what to do with
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2482 non-indenting comment lines, and shifts them as if they were indenting
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2483 comment lines. Fixing this appears to require telepathy.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2484
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2485 Special cases: whitespace is deleted from blank lines; continuation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2486 lines are shifted by the same amount their initial line was shifted,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2487 in order to preserve their relative indentation with respect to their
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2488 initial line; and comment lines beginning in column 1 are ignored."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2489 (interactive "*r\nP") ; region; raw prefix arg
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2490 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2491 (goto-char end) (beginning-of-line) (setq end (point-marker))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2492 (goto-char start) (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2493 (let ((py-indent-offset (prefix-numeric-value
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2494 (or indent-offset py-indent-offset)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2495 (indents '(-1)) ; stack of active indent levels
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2496 (target-column 0) ; column to which to indent
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2497 (base-shifted-by 0) ; amount last base line was shifted
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2498 (indent-base (if (looking-at "[ \t\n]")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2499 (py-compute-indentation t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2500 0))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2501 ci)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2502 (while (< (point) end)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2503 (setq ci (current-indentation))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2504 ;; figure out appropriate target column
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2505 (cond
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2506 ((or (eq (following-char) ?#) ; comment in column 1
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2507 (looking-at "[ \t]*$")) ; entirely blank
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2508 (setq target-column 0))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2509 ((py-continuation-line-p) ; shift relative to base line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2510 (setq target-column (+ ci base-shifted-by)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2511 (t ; new base line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2512 (if (> ci (car indents)) ; going deeper; push it
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2513 (setq indents (cons ci indents))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2514 ;; else we should have seen this indent before
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2515 (setq indents (memq ci indents)) ; pop deeper indents
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2516 (if (null indents)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2517 (error "Bad indentation in region, at line %d"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2518 (save-restriction
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2519 (widen)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2520 (1+ (count-lines 1 (point)))))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2521 (setq target-column (+ indent-base
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2522 (* py-indent-offset
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2523 (- (length indents) 2))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2524 (setq base-shifted-by (- target-column ci))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2525 ;; shift as needed
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2526 (if (/= ci target-column)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2527 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2528 (delete-horizontal-space)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2529 (indent-to target-column)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2530 (forward-line 1))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2531 (set-marker end nil))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2532
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2533 (defun py-comment-region (beg end &optional arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2534 "Like `comment-region' but uses double hash (`#') comment starter."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2535 (interactive "r\nP")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2536 (let ((comment-start py-block-comment-prefix))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2537 (comment-region beg end arg)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2538
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2539 (defun py-join-words-wrapping (words separator line-prefix line-length)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2540 (let ((lines ())
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2541 (current-line line-prefix))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2542 (while words
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2543 (let* ((word (car words))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2544 (maybe-line (concat current-line word separator)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2545 (if (> (length maybe-line) line-length)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2546 (setq lines (cons (substring current-line 0 -1) lines)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2547 current-line (concat line-prefix word separator " "))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2548 (setq current-line (concat maybe-line " "))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2549 (setq words (cdr words)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2550 (setq lines (cons (substring
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2551 current-line 0 (- 0 (length separator) 1)) lines))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2552 (mapconcat 'identity (nreverse lines) "\n")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2553
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2554 (defun py-sort-imports ()
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2555 "Sort multiline imports.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2556 Put point inside the parentheses of a multiline import and hit
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2557 \\[py-sort-imports] to sort the imports lexicographically"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2558 (interactive)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2559 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2560 (let ((open-paren (save-excursion (progn (up-list -1) (point))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2561 (close-paren (save-excursion (progn (up-list 1) (point))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2562 sorted-imports)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2563 (goto-char (1+ open-paren))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2564 (skip-chars-forward " \n\t")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2565 (setq sorted-imports
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2566 (sort
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2567 (delete-dups
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2568 (split-string (buffer-substring
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2569 (point)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2570 (save-excursion (goto-char (1- close-paren))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2571 (skip-chars-backward " \n\t")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2572 (point)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2573 ", *\\(\n *\\)?"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2574 ;; XXX Should this sort case insensitively?
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2575 'string-lessp))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2576 ;; Remove empty strings.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2577 (delete-region open-paren close-paren)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2578 (goto-char open-paren)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2579 (insert "(\n")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2580 (insert (py-join-words-wrapping (remove "" sorted-imports) "," " " 78))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2581 (insert ")")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2582 )))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2583
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2584
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2585
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2586 ;; Functions for moving point
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2587 (defun py-previous-statement (count)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2588 "Go to the start of the COUNTth preceding Python statement.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2589 By default, goes to the previous statement. If there is no such
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2590 statement, goes to the first statement. Return count of statements
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2591 left to move. `Statements' do not include blank, comment, or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2592 continuation lines."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2593 (interactive "p") ; numeric prefix arg
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2594 (if (< count 0) (py-next-statement (- count))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2595 (py-goto-initial-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2596 (let (start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2597 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2598 (setq start (point)) ; always true -- side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2599 (> count 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2600 (zerop (forward-line -1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2601 (py-goto-statement-at-or-above))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2602 (setq count (1- count)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2603 (if (> count 0) (goto-char start)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2604 count))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2605
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2606 (defun py-next-statement (count)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2607 "Go to the start of next Python statement.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2608 If the statement at point is the i'th Python statement, goes to the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2609 start of statement i+COUNT. If there is no such statement, goes to the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2610 last statement. Returns count of statements left to move. `Statements'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2611 do not include blank, comment, or continuation lines."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2612 (interactive "p") ; numeric prefix arg
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2613 (if (< count 0) (py-previous-statement (- count))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2614 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2615 (let (start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2616 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2617 (setq start (point)) ; always true -- side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2618 (> count 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2619 (py-goto-statement-below))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2620 (setq count (1- count)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2621 (if (> count 0) (goto-char start)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2622 count))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2623
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2624 (defun py-goto-block-up (&optional nomark)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2625 "Move up to start of current block.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2626 Go to the statement that starts the smallest enclosing block; roughly
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2627 speaking, this will be the closest preceding statement that ends with a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2628 colon and is indented less than the statement you started on. If
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2629 successful, also sets the mark to the starting point.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2630
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2631 `\\[py-mark-block]' can be used afterward to mark the whole code
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2632 block, if desired.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2633
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2634 If called from a program, the mark will not be set if optional argument
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2635 NOMARK is not nil."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2636 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2637 (let ((start (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2638 (found nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2639 initial-indent)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2640 (py-goto-initial-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2641 ;; if on blank or non-indenting comment line, use the preceding stmt
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2642 (if (looking-at "[ \t]*\\($\\|#[^ \t\n]\\)")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2643 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2644 (py-goto-statement-at-or-above)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2645 (setq found (py-statement-opens-block-p))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2646 ;; search back for colon line indented less
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2647 (setq initial-indent (current-indentation))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2648 (if (zerop initial-indent)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2649 ;; force fast exit
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2650 (goto-char (point-min)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2651 (while (not (or found (bobp)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2652 (setq found
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2653 (and
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2654 (re-search-backward ":[ \t]*\\($\\|[#\\]\\)" nil 'move)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2655 (or (py-goto-initial-line) t) ; always true -- side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2656 (< (current-indentation) initial-indent)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2657 (py-statement-opens-block-p))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2658 (if found
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2659 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2660 (or nomark (push-mark start))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2661 (back-to-indentation))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2662 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2663 (error "Enclosing block not found"))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2664
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2665 (defun py-beginning-of-def-or-class (&optional class count)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2666 "Move point to start of `def' or `class'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2667
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2668 Searches back for the closest preceding `def'. If you supply a prefix
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2669 arg, looks for a `class' instead. The docs below assume the `def'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2670 case; just substitute `class' for `def' for the other case.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2671 Programmatically, if CLASS is `either', then moves to either `class'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2672 or `def'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2673
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2674 When second optional argument is given programmatically, move to the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2675 COUNTth start of `def'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2676
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2677 If point is in a `def' statement already, and after the `d', simply
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2678 moves point to the start of the statement.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2679
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2680 Otherwise (i.e. when point is not in a `def' statement, or at or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2681 before the `d' of a `def' statement), searches for the closest
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2682 preceding `def' statement, and leaves point at its start. If no such
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2683 statement can be found, leaves point at the start of the buffer.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2684
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2685 Returns t iff a `def' statement is found by these rules.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2686
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2687 Note that doing this command repeatedly will take you closer to the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2688 start of the buffer each time.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2689
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2690 To mark the current `def', see `\\[py-mark-def-or-class]'."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2691 (interactive "P") ; raw prefix arg
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2692 (setq count (or count 1))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2693 (let ((at-or-before-p (<= (current-column) (current-indentation)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2694 (start-of-line (goto-char (py-point 'bol)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2695 (start-of-stmt (goto-char (py-point 'bos)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2696 (start-re (cond ((eq class 'either) "^[ \t]*\\(class\\|def\\)\\>")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2697 (class "^[ \t]*class\\>")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2698 (t "^[ \t]*def\\>")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2699 )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2700 ;; searching backward
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2701 (if (and (< 0 count)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2702 (or (/= start-of-stmt start-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2703 (not at-or-before-p)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2704 (end-of-line))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2705 ;; search forward
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2706 (if (and (> 0 count)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2707 (zerop (current-column))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2708 (looking-at start-re))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2709 (end-of-line))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2710 (if (re-search-backward start-re nil 'move count)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2711 (goto-char (match-beginning 0)))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2712
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2713 ;; Backwards compatibility
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2714 (defalias 'beginning-of-python-def-or-class 'py-beginning-of-def-or-class)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2715
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2716 (defun py-end-of-def-or-class (&optional class count)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2717 "Move point beyond end of `def' or `class' body.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2718
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2719 By default, looks for an appropriate `def'. If you supply a prefix
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2720 arg, looks for a `class' instead. The docs below assume the `def'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2721 case; just substitute `class' for `def' for the other case.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2722 Programmatically, if CLASS is `either', then moves to either `class'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2723 or `def'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2724
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2725 When second optional argument is given programmatically, move to the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2726 COUNTth end of `def'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2727
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2728 If point is in a `def' statement already, this is the `def' we use.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2729
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2730 Else, if the `def' found by `\\[py-beginning-of-def-or-class]'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2731 contains the statement you started on, that's the `def' we use.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2732
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2733 Otherwise, we search forward for the closest following `def', and use that.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2734
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2735 If a `def' can be found by these rules, point is moved to the start of
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2736 the line immediately following the `def' block, and the position of the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2737 start of the `def' is returned.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2738
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2739 Else point is moved to the end of the buffer, and nil is returned.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2740
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2741 Note that doing this command repeatedly will take you closer to the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2742 end of the buffer each time.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2743
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2744 To mark the current `def', see `\\[py-mark-def-or-class]'."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2745 (interactive "P") ; raw prefix arg
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2746 (if (and count (/= count 1))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2747 (py-beginning-of-def-or-class (- 1 count)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2748 (let ((start (progn (py-goto-initial-line) (point)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2749 (which (cond ((eq class 'either) "\\(class\\|def\\)")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2750 (class "class")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2751 (t "def")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2752 (state 'not-found))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2753 ;; move point to start of appropriate def/class
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2754 (if (looking-at (concat "[ \t]*" which "\\>")) ; already on one
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2755 (setq state 'at-beginning)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2756 ;; else see if py-beginning-of-def-or-class hits container
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2757 (if (and (py-beginning-of-def-or-class class)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2758 (progn (py-goto-beyond-block)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2759 (> (point) start)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2760 (setq state 'at-end)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2761 ;; else search forward
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2762 (goto-char start)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2763 (if (re-search-forward (concat "^[ \t]*" which "\\>") nil 'move)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2764 (progn (setq state 'at-beginning)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2765 (beginning-of-line)))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2766 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2767 ((eq state 'at-beginning) (py-goto-beyond-block) t)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2768 ((eq state 'at-end) t)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2769 ((eq state 'not-found) nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2770 (t (error "Internal error in `py-end-of-def-or-class'")))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2771
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2772 ;; Backwards compabitility
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2773 (defalias 'end-of-python-def-or-class 'py-end-of-def-or-class)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2774
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2775
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2776 ;; Functions for marking regions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2777 (defun py-mark-block (&optional extend just-move)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2778 "Mark following block of lines. With prefix arg, mark structure.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2779 Easier to use than explain. It sets the region to an `interesting'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2780 block of succeeding lines. If point is on a blank line, it goes down to
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2781 the next non-blank line. That will be the start of the region. The end
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2782 of the region depends on the kind of line at the start:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2783
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2784 - If a comment, the region will include all succeeding comment lines up
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2785 to (but not including) the next non-comment line (if any).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2786
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2787 - Else if a prefix arg is given, and the line begins one of these
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2788 structures:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2789
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2790 if elif else try except finally for while def class
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2791
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2792 the region will be set to the body of the structure, including
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2793 following blocks that `belong' to it, but excluding trailing blank
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2794 and comment lines. E.g., if on a `try' statement, the `try' block
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2795 and all (if any) of the following `except' and `finally' blocks
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2796 that belong to the `try' structure will be in the region. Ditto
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2797 for if/elif/else, for/else and while/else structures, and (a bit
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2798 degenerate, since they're always one-block structures) def and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2799 class blocks.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2800
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2801 - Else if no prefix argument is given, and the line begins a Python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2802 block (see list above), and the block is not a `one-liner' (i.e.,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2803 the statement ends with a colon, not with code), the region will
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2804 include all succeeding lines up to (but not including) the next
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2805 code statement (if any) that's indented no more than the starting
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2806 line, except that trailing blank and comment lines are excluded.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2807 E.g., if the starting line begins a multi-statement `def'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2808 structure, the region will be set to the full function definition,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2809 but without any trailing `noise' lines.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2810
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2811 - Else the region will include all succeeding lines up to (but not
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2812 including) the next blank line, or code or indenting-comment line
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2813 indented strictly less than the starting line. Trailing indenting
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2814 comment lines are included in this case, but not trailing blank
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2815 lines.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2816
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2817 A msg identifying the location of the mark is displayed in the echo
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2818 area; or do `\\[exchange-point-and-mark]' to flip down to the end.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2819
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2820 If called from a program, optional argument EXTEND plays the role of
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2821 the prefix arg, and if optional argument JUST-MOVE is not nil, just
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2822 moves to the end of the block (& does not set mark or display a msg)."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2823 (interactive "P") ; raw prefix arg
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2824 (py-goto-initial-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2825 ;; skip over blank lines
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2826 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2827 (looking-at "[ \t]*$") ; while blank line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2828 (not (eobp))) ; & somewhere to go
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2829 (forward-line 1))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2830 (if (eobp)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2831 (error "Hit end of buffer without finding a non-blank stmt"))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2832 (let ((initial-pos (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2833 (initial-indent (current-indentation))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2834 last-pos ; position of last stmt in region
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2835 (followers
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2836 '((if elif else) (elif elif else) (else)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2837 (try except finally) (except except) (finally)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2838 (for else) (while else)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2839 (def) (class) ) )
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2840 first-symbol next-symbol)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2841
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2842 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2843 ;; if comment line, suck up the following comment lines
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2844 ((looking-at "[ \t]*#")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2845 (re-search-forward "^[ \t]*[^ \t#]" nil 'move) ; look for non-comment
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2846 (re-search-backward "^[ \t]*#") ; and back to last comment in block
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2847 (setq last-pos (point)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2848
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2849 ;; else if line is a block line and EXTEND given, suck up
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2850 ;; the whole structure
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2851 ((and extend
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2852 (setq first-symbol (py-suck-up-first-keyword) )
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2853 (assq first-symbol followers))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2854 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2855 (or (py-goto-beyond-block) t) ; side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2856 (forward-line -1) ; side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2857 (setq last-pos (point)) ; side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2858 (py-goto-statement-below)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2859 (= (current-indentation) initial-indent)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2860 (setq next-symbol (py-suck-up-first-keyword))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2861 (memq next-symbol (cdr (assq first-symbol followers))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2862 (setq first-symbol next-symbol)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2863
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2864 ;; else if line *opens* a block, search for next stmt indented <=
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2865 ((py-statement-opens-block-p)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2866 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2867 (setq last-pos (point)) ; always true -- side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2868 (py-goto-statement-below)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2869 (> (current-indentation) initial-indent)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2870 )))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2871
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2872 ;; else plain code line; stop at next blank line, or stmt or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2873 ;; indenting comment line indented <
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2874 (t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2875 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2876 (setq last-pos (point)) ; always true -- side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2877 (or (py-goto-beyond-final-line) t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2878 (not (looking-at "[ \t]*$")) ; stop at blank line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2879 (or
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2880 (>= (current-indentation) initial-indent)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2881 (looking-at "[ \t]*#[^ \t\n]"))) ; ignore non-indenting #
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2882 nil)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2883
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2884 ;; skip to end of last stmt
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2885 (goto-char last-pos)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2886 (py-goto-beyond-final-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2887
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2888 ;; set mark & display
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2889 (if just-move
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2890 () ; just return
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2891 (push-mark (point) 'no-msg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2892 (forward-line -1)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2893 (message "Mark set after: %s" (py-suck-up-leading-text))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2894 (goto-char initial-pos))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2895
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2896 (defun py-mark-def-or-class (&optional class)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2897 "Set region to body of def (or class, with prefix arg) enclosing point.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2898 Pushes the current mark, then point, on the mark ring (all language
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2899 modes do this, but although it's handy it's never documented ...).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2900
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2901 In most Emacs language modes, this function bears at least a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2902 hallucinogenic resemblance to `\\[py-end-of-def-or-class]' and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2903 `\\[py-beginning-of-def-or-class]'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2904
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2905 And in earlier versions of Python mode, all 3 were tightly connected.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2906 Turned out that was more confusing than useful: the `goto start' and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2907 `goto end' commands are usually used to search through a file, and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2908 people expect them to act a lot like `search backward' and `search
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2909 forward' string-search commands. But because Python `def' and `class'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2910 can nest to arbitrary levels, finding the smallest def containing
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2911 point cannot be done via a simple backward search: the def containing
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2912 point may not be the closest preceding def, or even the closest
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2913 preceding def that's indented less. The fancy algorithm required is
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2914 appropriate for the usual uses of this `mark' command, but not for the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2915 `goto' variations.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2916
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2917 So the def marked by this command may not be the one either of the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2918 `goto' commands find: If point is on a blank or non-indenting comment
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2919 line, moves back to start of the closest preceding code statement or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2920 indenting comment line. If this is a `def' statement, that's the def
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2921 we use. Else searches for the smallest enclosing `def' block and uses
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2922 that. Else signals an error.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2923
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2924 When an enclosing def is found: The mark is left immediately beyond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2925 the last line of the def block. Point is left at the start of the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2926 def, except that: if the def is preceded by a number of comment lines
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2927 followed by (at most) one optional blank line, point is left at the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2928 start of the comments; else if the def is preceded by a blank line,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2929 point is left at its start.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2930
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2931 The intent is to mark the containing def/class and its associated
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2932 documentation, to make moving and duplicating functions and classes
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2933 pleasant."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2934 (interactive "P") ; raw prefix arg
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2935 (let ((start (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2936 (which (cond ((eq class 'either) "\\(class\\|def\\)")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2937 (class "class")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2938 (t "def"))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2939 (push-mark start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2940 (if (not (py-go-up-tree-to-keyword which))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2941 (progn (goto-char start)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2942 (error "Enclosing %s not found"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2943 (if (eq class 'either)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2944 "def or class"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2945 which)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2946 ;; else enclosing def/class found
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2947 (setq start (point))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2948 (py-goto-beyond-block)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2949 (push-mark (point))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2950 (goto-char start)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2951 (if (zerop (forward-line -1)) ; if there is a preceding line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2952 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2953 (if (looking-at "[ \t]*$") ; it's blank
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2954 (setq start (point)) ; so reset start point
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2955 (goto-char start)) ; else try again
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2956 (if (zerop (forward-line -1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2957 (if (looking-at "[ \t]*#") ; a comment
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2958 ;; look back for non-comment line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2959 ;; tricky: note that the regexp matches a blank
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2960 ;; line, cuz \n is in the 2nd character class
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2961 (and
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2962 (re-search-backward "^[ \t]*[^ \t#]" nil 'move)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2963 (forward-line 1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2964 ;; no comment, so go back
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2965 (goto-char start)))))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2966 (exchange-point-and-mark)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2967 (py-keep-region-active))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2968
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2969 ;; ripped from cc-mode
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2970 (defun py-forward-into-nomenclature (&optional arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2971 "Move forward to end of a nomenclature section or word.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2972 With \\[universal-argument] (programmatically, optional argument ARG),
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2973 do it that many times.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2974
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2975 A `nomenclature' is a fancy way of saying AWordWithMixedCaseNotUnderscores."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2976 (interactive "p")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2977 (let ((case-fold-search nil))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2978 (if (> arg 0)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2979 (re-search-forward
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2980 "\\(\\W\\|[_]\\)*\\([A-Z]*[a-z0-9]*\\)"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2981 (point-max) t arg)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2982 (while (and (< arg 0)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2983 (re-search-backward
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2984 "\\(\\W\\|[a-z0-9]\\)[A-Z]+\\|\\(\\W\\|[_]\\)\\w+"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2985 (point-min) 0))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2986 (forward-char 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2987 (setq arg (1+ arg)))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2988 (py-keep-region-active))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2989
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2990 (defun py-backward-into-nomenclature (&optional arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2991 "Move backward to beginning of a nomenclature section or word.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2992 With optional ARG, move that many times. If ARG is negative, move
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2993 forward.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2994
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2995 A `nomenclature' is a fancy way of saying AWordWithMixedCaseNotUnderscores."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2996 (interactive "p")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2997 (py-forward-into-nomenclature (- arg))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2998 (py-keep-region-active))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2999
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3000
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3001
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3002 ;; pdbtrack functions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3003 (defun py-pdbtrack-toggle-stack-tracking (arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3004 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3005 (if (not (get-buffer-process (current-buffer)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3006 (error "No process associated with buffer '%s'" (current-buffer)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3007 ;; missing or 0 is toggle, >0 turn on, <0 turn off
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3008 (if (or (not arg)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3009 (zerop (setq arg (prefix-numeric-value arg))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3010 (setq py-pdbtrack-do-tracking-p (not py-pdbtrack-do-tracking-p))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3011 (setq py-pdbtrack-do-tracking-p (> arg 0)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3012 (message "%sabled Python's pdbtrack"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3013 (if py-pdbtrack-do-tracking-p "En" "Dis")))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3014
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3015 (defun turn-on-pdbtrack ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3016 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3017 (py-pdbtrack-toggle-stack-tracking 1))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3018
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3019 (defun turn-off-pdbtrack ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3020 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3021 (py-pdbtrack-toggle-stack-tracking 0))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3022
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3023
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3024
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3025 ;; Pychecker
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3026
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3027 ;; hack for FSF Emacs
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3028 (unless (fboundp 'read-shell-command)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3029 (defalias 'read-shell-command 'read-string))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3030
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3031 (defun py-pychecker-run (command)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3032 "*Run pychecker (default on the file currently visited)."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3033 (interactive
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3034 (let ((default
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3035 (format "%s %s %s" py-pychecker-command
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3036 (mapconcat 'identity py-pychecker-command-args " ")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3037 (buffer-file-name)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3038 (last (when py-pychecker-history
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3039 (let* ((lastcmd (car py-pychecker-history))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3040 (cmd (cdr (reverse (split-string lastcmd))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3041 (newcmd (reverse (cons (buffer-file-name) cmd))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3042 (mapconcat 'identity newcmd " ")))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3043
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3044 (list
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3045 (if (fboundp 'read-shell-command)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3046 (read-shell-command "Run pychecker like this: "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3047 (if last
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3048 last
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3049 default)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3050 'py-pychecker-history)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3051 (read-string "Run pychecker like this: "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3052 (if last
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3053 last
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3054 default)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3055 'py-pychecker-history))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3056 )))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3057 (save-some-buffers (not py-ask-about-save) nil)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3058 (if (fboundp 'compilation-start)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3059 ;; Emacs.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3060 (compilation-start command)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3061 ;; XEmacs.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3062 (compile-internal command "No more errors")))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3063
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3064
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3065
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3066 ;; pydoc commands. The guts of this function is stolen from XEmacs's
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3067 ;; symbol-near-point, but without the useless regexp-quote call on the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3068 ;; results, nor the interactive bit. Also, we've added the temporary
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3069 ;; syntax table setting, which Skip originally had broken out into a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3070 ;; separate function. Note that Emacs doesn't have the original
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3071 ;; function.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3072 (defun py-symbol-near-point ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3073 "Return the first textual item to the nearest point."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3074 ;; alg stolen from etag.el
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3075 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3076 (with-syntax-table py-dotted-expression-syntax-table
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3077 (if (or (bobp) (not (memq (char-syntax (char-before)) '(?w ?_))))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3078 (while (not (looking-at "\\sw\\|\\s_\\|\\'"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3079 (forward-char 1)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3080 (while (looking-at "\\sw\\|\\s_")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3081 (forward-char 1))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3082 (if (re-search-backward "\\sw\\|\\s_" nil t)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3083 (progn (forward-char 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3084 (buffer-substring (point)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3085 (progn (forward-sexp -1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3086 (while (looking-at "\\s'")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3087 (forward-char 1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3088 (point))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3089 nil))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3090
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3091 (defun py-help-at-point ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3092 "Get help from Python based on the symbol nearest point."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3093 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3094 (let* ((sym (py-symbol-near-point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3095 (base (substring sym 0 (or (search "." sym :from-end t) 0)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3096 cmd)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3097 (if (not (equal base ""))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3098 (setq cmd (concat "import " base "\n")))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3099 (setq cmd (concat "import pydoc\n"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3100 cmd
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3101 "try: pydoc.help('" sym "')\n"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3102 "except: print 'No help available on:', \"" sym "\""))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3103 (message cmd)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3104 (py-execute-string cmd)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3105 (set-buffer "*Python Output*")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3106 ;; BAW: Should we really be leaving the output buffer in help-mode?
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3107 (help-mode)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3108
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3109
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3110
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3111 ;; Documentation functions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3112
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3113 ;; dump the long form of the mode blurb; does the usual doc escapes,
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3114 ;; plus lines of the form ^[vc]:name$ to suck variable & command docs
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3115 ;; out of the right places, along with the keys they're on & current
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3116 ;; values
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3117 (defun py-dump-help-string (str)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3118 (with-output-to-temp-buffer "*Help*"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3119 (let ((locals (buffer-local-variables))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3120 funckind funcname func funcdoc
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3121 (start 0) mstart end
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3122 keys )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3123 (while (string-match "^%\\([vc]\\):\\(.+\\)\n" str start)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3124 (setq mstart (match-beginning 0) end (match-end 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3125 funckind (substring str (match-beginning 1) (match-end 1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3126 funcname (substring str (match-beginning 2) (match-end 2))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3127 func (intern funcname))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3128 (princ (substitute-command-keys (substring str start mstart)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3129 (cond
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3130 ((equal funckind "c") ; command
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3131 (setq funcdoc (documentation func)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3132 keys (concat
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3133 "Key(s): "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3134 (mapconcat 'key-description
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3135 (where-is-internal func py-mode-map)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3136 ", "))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3137 ((equal funckind "v") ; variable
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3138 (setq funcdoc (documentation-property func 'variable-documentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3139 keys (if (assq func locals)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3140 (concat
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3141 "Local/Global values: "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3142 (prin1-to-string (symbol-value func))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3143 " / "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3144 (prin1-to-string (default-value func)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3145 (concat
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3146 "Value: "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3147 (prin1-to-string (symbol-value func))))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3148 (t ; unexpected
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3149 (error "Error in py-dump-help-string, tag `%s'" funckind)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3150 (princ (format "\n-> %s:\t%s\t%s\n\n"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3151 (if (equal funckind "c") "Command" "Variable")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3152 funcname keys))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3153 (princ funcdoc)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3154 (terpri)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3155 (setq start end))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3156 (princ (substitute-command-keys (substring str start))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3157 (print-help-return-message)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3158
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3159 (defun py-describe-mode ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3160 "Dump long form of Python-mode docs."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3161 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3162 (py-dump-help-string "Major mode for editing Python files.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3163 Knows about Python indentation, tokens, comments and continuation lines.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3164 Paragraphs are separated by blank lines only.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3165
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3166 Major sections below begin with the string `@'; specific function and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3167 variable docs begin with `->'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3168
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3169 @EXECUTING PYTHON CODE
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3170
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3171 \\[py-execute-import-or-reload]\timports or reloads the file in the Python interpreter
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3172 \\[py-execute-buffer]\tsends the entire buffer to the Python interpreter
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3173 \\[py-execute-region]\tsends the current region
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3174 \\[py-execute-def-or-class]\tsends the current function or class definition
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3175 \\[py-execute-string]\tsends an arbitrary string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3176 \\[py-shell]\tstarts a Python interpreter window; this will be used by
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3177 \tsubsequent Python execution commands
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3178 %c:py-execute-import-or-reload
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3179 %c:py-execute-buffer
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3180 %c:py-execute-region
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3181 %c:py-execute-def-or-class
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3182 %c:py-execute-string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3183 %c:py-shell
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3184
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3185 @VARIABLES
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3186
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3187 py-indent-offset\tindentation increment
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3188 py-block-comment-prefix\tcomment string used by comment-region
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3189
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3190 py-python-command\tshell command to invoke Python interpreter
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3191 py-temp-directory\tdirectory used for temp files (if needed)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3192
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3193 py-beep-if-tab-change\tring the bell if tab-width is changed
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3194 %v:py-indent-offset
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3195 %v:py-block-comment-prefix
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3196 %v:py-python-command
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3197 %v:py-temp-directory
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3198 %v:py-beep-if-tab-change
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3199
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3200 @KINDS OF LINES
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3201
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3202 Each physical line in the file is either a `continuation line' (the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3203 preceding line ends with a backslash that's not part of a comment, or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3204 the paren/bracket/brace nesting level at the start of the line is
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3205 non-zero, or both) or an `initial line' (everything else).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3206
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3207 An initial line is in turn a `blank line' (contains nothing except
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3208 possibly blanks or tabs), a `comment line' (leftmost non-blank
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3209 character is `#'), or a `code line' (everything else).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3210
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3211 Comment Lines
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3212
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3213 Although all comment lines are treated alike by Python, Python mode
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3214 recognizes two kinds that act differently with respect to indentation.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3215
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3216 An `indenting comment line' is a comment line with a blank, tab or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3217 nothing after the initial `#'. The indentation commands (see below)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3218 treat these exactly as if they were code lines: a line following an
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3219 indenting comment line will be indented like the comment line. All
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3220 other comment lines (those with a non-whitespace character immediately
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3221 following the initial `#') are `non-indenting comment lines', and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3222 their indentation is ignored by the indentation commands.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3223
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3224 Indenting comment lines are by far the usual case, and should be used
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3225 whenever possible. Non-indenting comment lines are useful in cases
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3226 like these:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3227
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3228 \ta = b # a very wordy single-line comment that ends up being
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3229 \t #... continued onto another line
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3230
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3231 \tif a == b:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3232 ##\t\tprint 'panic!' # old code we've `commented out'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3233 \t\treturn a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3234
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3235 Since the `#...' and `##' comment lines have a non-whitespace
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3236 character following the initial `#', Python mode ignores them when
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3237 computing the proper indentation for the next line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3238
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3239 Continuation Lines and Statements
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3240
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3241 The Python-mode commands generally work on statements instead of on
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3242 individual lines, where a `statement' is a comment or blank line, or a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3243 code line and all of its following continuation lines (if any)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3244 considered as a single logical unit. The commands in this mode
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3245 generally (when it makes sense) automatically move to the start of the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3246 statement containing point, even if point happens to be in the middle
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3247 of some continuation line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3248
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3249
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3250 @INDENTATION
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3251
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3252 Primarily for entering new code:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3253 \t\\[indent-for-tab-command]\t indent line appropriately
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3254 \t\\[py-newline-and-indent]\t insert newline, then indent
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3255 \t\\[py-electric-backspace]\t reduce indentation, or delete single character
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3256
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3257 Primarily for reindenting existing code:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3258 \t\\[py-guess-indent-offset]\t guess py-indent-offset from file content; change locally
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3259 \t\\[universal-argument] \\[py-guess-indent-offset]\t ditto, but change globally
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3260
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3261 \t\\[py-indent-region]\t reindent region to match its context
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3262 \t\\[py-shift-region-left]\t shift region left by py-indent-offset
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3263 \t\\[py-shift-region-right]\t shift region right by py-indent-offset
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3264
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3265 Unlike most programming languages, Python uses indentation, and only
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3266 indentation, to specify block structure. Hence the indentation supplied
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3267 automatically by Python-mode is just an educated guess: only you know
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3268 the block structure you intend, so only you can supply correct
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3269 indentation.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3270
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3271 The \\[indent-for-tab-command] and \\[py-newline-and-indent] keys try to suggest plausible indentation, based on
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3272 the indentation of preceding statements. E.g., assuming
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3273 py-indent-offset is 4, after you enter
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3274 \tif a > 0: \\[py-newline-and-indent]
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3275 the cursor will be moved to the position of the `_' (_ is not a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3276 character in the file, it's just used here to indicate the location of
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3277 the cursor):
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3278 \tif a > 0:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3279 \t _
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3280 If you then enter `c = d' \\[py-newline-and-indent], the cursor will move
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3281 to
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3282 \tif a > 0:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3283 \t c = d
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3284 \t _
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3285 Python-mode cannot know whether that's what you intended, or whether
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3286 \tif a > 0:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3287 \t c = d
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3288 \t_
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3289 was your intent. In general, Python-mode either reproduces the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3290 indentation of the (closest code or indenting-comment) preceding
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3291 statement, or adds an extra py-indent-offset blanks if the preceding
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3292 statement has `:' as its last significant (non-whitespace and non-
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3293 comment) character. If the suggested indentation is too much, use
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3294 \\[py-electric-backspace] to reduce it.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3295
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3296 Continuation lines are given extra indentation. If you don't like the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3297 suggested indentation, change it to something you do like, and Python-
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3298 mode will strive to indent later lines of the statement in the same way.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3299
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3300 If a line is a continuation line by virtue of being in an unclosed
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3301 paren/bracket/brace structure (`list', for short), the suggested
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3302 indentation depends on whether the current line contains the first item
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3303 in the list. If it does, it's indented py-indent-offset columns beyond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3304 the indentation of the line containing the open bracket. If you don't
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3305 like that, change it by hand. The remaining items in the list will mimic
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3306 whatever indentation you give to the first item.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3307
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3308 If a line is a continuation line because the line preceding it ends with
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3309 a backslash, the third and following lines of the statement inherit their
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3310 indentation from the line preceding them. The indentation of the second
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3311 line in the statement depends on the form of the first (base) line: if
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3312 the base line is an assignment statement with anything more interesting
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3313 than the backslash following the leftmost assigning `=', the second line
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3314 is indented two columns beyond that `='. Else it's indented to two
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3315 columns beyond the leftmost solid chunk of non-whitespace characters on
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3316 the base line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3317
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3318 Warning: indent-region should not normally be used! It calls \\[indent-for-tab-command]
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3319 repeatedly, and as explained above, \\[indent-for-tab-command] can't guess the block
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3320 structure you intend.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3321 %c:indent-for-tab-command
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3322 %c:py-newline-and-indent
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3323 %c:py-electric-backspace
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3324
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3325
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3326 The next function may be handy when editing code you didn't write:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3327 %c:py-guess-indent-offset
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3328
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3329
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3330 The remaining `indent' functions apply to a region of Python code. They
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3331 assume the block structure (equals indentation, in Python) of the region
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3332 is correct, and alter the indentation in various ways while preserving
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3333 the block structure:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3334 %c:py-indent-region
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3335 %c:py-shift-region-left
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3336 %c:py-shift-region-right
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3337
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3338 @MARKING & MANIPULATING REGIONS OF CODE
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3339
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3340 \\[py-mark-block]\t mark block of lines
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3341 \\[py-mark-def-or-class]\t mark smallest enclosing def
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3342 \\[universal-argument] \\[py-mark-def-or-class]\t mark smallest enclosing class
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3343 \\[comment-region]\t comment out region of code
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3344 \\[universal-argument] \\[comment-region]\t uncomment region of code
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3345 %c:py-mark-block
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3346 %c:py-mark-def-or-class
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3347 %c:comment-region
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3348
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3349 @MOVING POINT
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3350
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3351 \\[py-previous-statement]\t move to statement preceding point
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3352 \\[py-next-statement]\t move to statement following point
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3353 \\[py-goto-block-up]\t move up to start of current block
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3354 \\[py-beginning-of-def-or-class]\t move to start of def
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3355 \\[universal-argument] \\[py-beginning-of-def-or-class]\t move to start of class
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3356 \\[py-end-of-def-or-class]\t move to end of def
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3357 \\[universal-argument] \\[py-end-of-def-or-class]\t move to end of class
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3358
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3359 The first two move to one statement beyond the statement that contains
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3360 point. A numeric prefix argument tells them to move that many
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3361 statements instead. Blank lines, comment lines, and continuation lines
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3362 do not count as `statements' for these commands. So, e.g., you can go
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3363 to the first code statement in a file by entering
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3364 \t\\[beginning-of-buffer]\t to move to the top of the file
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3365 \t\\[py-next-statement]\t to skip over initial comments and blank lines
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3366 Or do `\\[py-previous-statement]' with a huge prefix argument.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3367 %c:py-previous-statement
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3368 %c:py-next-statement
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3369 %c:py-goto-block-up
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3370 %c:py-beginning-of-def-or-class
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3371 %c:py-end-of-def-or-class
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3372
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3373 @LITTLE-KNOWN EMACS COMMANDS PARTICULARLY USEFUL IN PYTHON MODE
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3374
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3375 `\\[indent-new-comment-line]' is handy for entering a multi-line comment.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3376
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3377 `\\[set-selective-display]' with a `small' prefix arg is ideally suited for viewing the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3378 overall class and def structure of a module.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3379
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3380 `\\[back-to-indentation]' moves point to a line's first non-blank character.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3381
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3382 `\\[indent-relative]' is handy for creating odd indentation.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3383
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3384 @OTHER EMACS HINTS
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3385
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3386 If you don't like the default value of a variable, change its value to
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3387 whatever you do like by putting a `setq' line in your .emacs file.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3388 E.g., to set the indentation increment to 4, put this line in your
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3389 .emacs:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3390 \t(setq py-indent-offset 4)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3391 To see the value of a variable, do `\\[describe-variable]' and enter the variable
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3392 name at the prompt.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3393
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3394 When entering a key sequence like `C-c C-n', it is not necessary to
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3395 release the CONTROL key after doing the `C-c' part -- it suffices to
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3396 press the CONTROL key, press and release `c' (while still holding down
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3397 CONTROL), press and release `n' (while still holding down CONTROL), &
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3398 then release CONTROL.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3399
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3400 Entering Python mode calls with no arguments the value of the variable
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3401 `python-mode-hook', if that value exists and is not nil; for backward
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3402 compatibility it also tries `py-mode-hook'; see the `Hooks' section of
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3403 the Elisp manual for details.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3404
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3405 Obscure: When python-mode is first loaded, it looks for all bindings
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3406 to newline-and-indent in the global keymap, and shadows them with
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3407 local bindings to py-newline-and-indent."))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3408
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3409 (require 'info-look)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3410 ;; The info-look package does not always provide this function (it
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3411 ;; appears this is the case with XEmacs 21.1)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3412 (when (fboundp 'info-lookup-maybe-add-help)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3413 (info-lookup-maybe-add-help
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3414 :mode 'python-mode
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3415 :regexp "[a-zA-Z0-9_]+"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3416 :doc-spec '(("(python-lib)Module Index")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3417 ("(python-lib)Class-Exception-Object Index")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3418 ("(python-lib)Function-Method-Variable Index")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3419 ("(python-lib)Miscellaneous Index")))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3420 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3421
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3422
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3423 ;; Helper functions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3424 (defvar py-parse-state-re
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3425 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3426 "^[ \t]*\\(elif\\|else\\|while\\|def\\|class\\)\\>"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3427 "\\|"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3428 "^[^ #\t\n]"))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3429
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3430 (defun py-parse-state ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3431 "Return the parse state at point (see `parse-partial-sexp' docs)."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3432 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3433 (let ((here (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3434 pps done)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3435 (while (not done)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3436 ;; back up to the first preceding line (if any; else start of
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3437 ;; buffer) that begins with a popular Python keyword, or a
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3438 ;; non- whitespace and non-comment character. These are good
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3439 ;; places to start parsing to see whether where we started is
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3440 ;; at a non-zero nesting level. It may be slow for people who
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3441 ;; write huge code blocks or huge lists ... tough beans.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3442 (re-search-backward py-parse-state-re nil 'move)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3443 (beginning-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3444 ;; In XEmacs, we have a much better way to test for whether
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3445 ;; we're in a triple-quoted string or not. Emacs does not
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3446 ;; have this built-in function, which is its loss because
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3447 ;; without scanning from the beginning of the buffer, there's
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3448 ;; no accurate way to determine this otherwise.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3449 (save-excursion (setq pps (parse-partial-sexp (point) here)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3450 ;; make sure we don't land inside a triple-quoted string
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3451 (setq done (or (not (nth 3 pps))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3452 (bobp)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3453 ;; Just go ahead and short circuit the test back to the
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3454 ;; beginning of the buffer. This will be slow, but not
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3455 ;; nearly as slow as looping through many
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3456 ;; re-search-backwards.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3457 (if (not done)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3458 (goto-char (point-min))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3459 pps)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3460
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3461 (defun py-nesting-level ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3462 "Return the buffer position of the last unclosed enclosing list.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3463 If nesting level is zero, return nil."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3464 (let ((status (py-parse-state)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3465 (if (zerop (car status))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3466 nil ; not in a nest
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3467 (car (cdr status))))) ; char# of open bracket
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3468
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3469 (defun py-backslash-continuation-line-p ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3470 "Return t iff preceding line ends with backslash that is not in a comment."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3471 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3472 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3473 (and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3474 ;; use a cheap test first to avoid the regexp if possible
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3475 ;; use 'eq' because char-after may return nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3476 (eq (char-after (- (point) 2)) ?\\ )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3477 ;; make sure; since eq test passed, there is a preceding line
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3478 (forward-line -1) ; always true -- side effect
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3479 (looking-at py-continued-re))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3480
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3481 (defun py-continuation-line-p ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3482 "Return t iff current line is a continuation line."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3483 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3484 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3485 (or (py-backslash-continuation-line-p)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3486 (py-nesting-level))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3487
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3488 (defun py-goto-beginning-of-tqs (delim)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3489 "Go to the beginning of the triple quoted string we find ourselves in.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3490 DELIM is the TQS string delimiter character we're searching backwards
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3491 for."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3492 (let ((skip (and delim (make-string 1 delim)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3493 (continue t))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3494 (when skip
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3495 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3496 (while continue
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3497 (py-safe (search-backward skip))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3498 (setq continue (and (not (bobp))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3499 (= (char-before) ?\\))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3500 (if (and (= (char-before) delim)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3501 (= (char-before (1- (point))) delim))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3502 (setq skip (make-string 3 delim))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3503 ;; we're looking at a triple-quoted string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3504 (py-safe (search-backward skip)))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3505
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3506 (defun py-goto-initial-line ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3507 "Go to the initial line of the current statement.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3508 Usually this is the line we're on, but if we're on the 2nd or
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3509 following lines of a continuation block, we need to go up to the first
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3510 line of the block."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3511 ;; Tricky: We want to avoid quadratic-time behavior for long
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3512 ;; continued blocks, whether of the backslash or open-bracket
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3513 ;; varieties, or a mix of the two. The following manages to do that
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3514 ;; in the usual cases.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3515 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3516 ;; Also, if we're sitting inside a triple quoted string, this will
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3517 ;; drop us at the line that begins the string.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3518 (let (open-bracket-pos)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3519 (while (py-continuation-line-p)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3520 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3521 (if (py-backslash-continuation-line-p)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3522 (while (py-backslash-continuation-line-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3523 (forward-line -1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3524 ;; else zip out of nested brackets/braces/parens
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3525 (while (setq open-bracket-pos (py-nesting-level))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3526 (goto-char open-bracket-pos)))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3527 (beginning-of-line))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3528
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3529 (defun py-goto-beyond-final-line ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3530 "Go to the point just beyond the fine line of the current statement.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3531 Usually this is the start of the next line, but if this is a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3532 multi-line statement we need to skip over the continuation lines."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3533 ;; Tricky: Again we need to be clever to avoid quadratic time
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3534 ;; behavior.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3535 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3536 ;; XXX: Not quite the right solution, but deals with multi-line doc
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3537 ;; strings
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3538 (if (looking-at (concat "[ \t]*\\(" py-stringlit-re "\\)"))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3539 (goto-char (match-end 0)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3540 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3541 (forward-line 1)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3542 (let (state)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3543 (while (and (py-continuation-line-p)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3544 (not (eobp)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3545 ;; skip over the backslash flavor
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3546 (while (and (py-backslash-continuation-line-p)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3547 (not (eobp)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3548 (forward-line 1))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3549 ;; if in nest, zip to the end of the nest
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3550 (setq state (py-parse-state))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3551 (if (and (not (zerop (car state)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3552 (not (eobp)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3553 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3554 (parse-partial-sexp (point) (point-max) 0 nil state)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3555 (forward-line 1))))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3556
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3557 (defun py-statement-opens-block-p ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3558 "Return t iff the current statement opens a block.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3559 I.e., iff it ends with a colon that is not in a comment. Point should
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3560 be at the start of a statement."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3561 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3562 (let ((start (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3563 (finish (progn (py-goto-beyond-final-line) (1- (point))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3564 (searching t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3565 (answer nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3566 state)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3567 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3568 (while searching
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3569 ;; look for a colon with nothing after it except whitespace, and
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3570 ;; maybe a comment
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3571 (if (re-search-forward ":\\([ \t]\\|\\\\\n\\)*\\(#.*\\)?$"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3572 finish t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3573 (if (eq (point) finish) ; note: no `else' clause; just
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3574 ; keep searching if we're not at
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3575 ; the end yet
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3576 ;; sure looks like it opens a block -- but it might
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3577 ;; be in a comment
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3578 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3579 (setq searching nil) ; search is done either way
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3580 (setq state (parse-partial-sexp start
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3581 (match-beginning 0)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3582 (setq answer (not (nth 4 state)))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3583 ;; search failed: couldn't find another interesting colon
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3584 (setq searching nil)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3585 answer)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3586
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3587 (defun py-statement-closes-block-p ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3588 "Return t iff the current statement closes a block.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3589 I.e., if the line starts with `return', `raise', `break', `continue',
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3590 and `pass'. This doesn't catch embedded statements."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3591 (let ((here (point)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3592 (py-goto-initial-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3593 (back-to-indentation)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3594 (prog1
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3595 (looking-at (concat py-block-closing-keywords-re "\\>"))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3596 (goto-char here))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3597
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3598 (defun py-goto-beyond-block ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3599 "Go to point just beyond the final line of block begun by the current line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3600 This is the same as where `py-goto-beyond-final-line' goes unless
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3601 we're on colon line, in which case we go to the end of the block.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3602 Assumes point is at the beginning of the line."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3603 (if (py-statement-opens-block-p)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3604 (py-mark-block nil 'just-move)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3605 (py-goto-beyond-final-line)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3606
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3607 (defun py-goto-statement-at-or-above ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3608 "Go to the start of the first statement at or preceding point.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3609 Return t if there is such a statement, otherwise nil. `Statement'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3610 does not include blank lines, comments, or continuation lines."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3611 (py-goto-initial-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3612 (if (looking-at py-blank-or-comment-re)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3613 ;; skip back over blank & comment lines
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3614 ;; note: will skip a blank or comment line that happens to be
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3615 ;; a continuation line too
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3616 (if (re-search-backward "^[ \t]*[^ \t#\n]" nil t)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3617 (progn (py-goto-initial-line) t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3618 nil)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3619 t))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3620
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3621 (defun py-goto-statement-below ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3622 "Go to start of the first statement following the statement containing point.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3623 Return t if there is such a statement, otherwise nil. `Statement'
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3624 does not include blank lines, comments, or continuation lines."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3625 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3626 (let ((start (point)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3627 (py-goto-beyond-final-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3628 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3629 (or (looking-at py-blank-or-comment-re)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3630 (py-in-literal))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3631 (not (eobp)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3632 (forward-line 1))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3633 (if (eobp)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3634 (progn (goto-char start) nil)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3635 t)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3636
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3637 (defun py-go-up-tree-to-keyword (key)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3638 "Go to begining of statement starting with KEY, at or preceding point.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3639
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3640 KEY is a regular expression describing a Python keyword. Skip blank
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3641 lines and non-indenting comments. If the statement found starts with
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3642 KEY, then stop, otherwise go back to first enclosing block starting
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3643 with KEY. If successful, leave point at the start of the KEY line and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3644 return t. Otherwise, leave point at an undefined place and return nil."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3645 ;; skip blanks and non-indenting #
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3646 (py-goto-initial-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3647 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3648 (looking-at "[ \t]*\\($\\|#[^ \t\n]\\)")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3649 (zerop (forward-line -1))) ; go back
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3650 nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3651 (py-goto-initial-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3652 (let* ((re (concat "[ \t]*" key "\\>"))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3653 (case-fold-search nil) ; let* so looking-at sees this
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3654 (found (looking-at re))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3655 (dead nil))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3656 (while (not (or found dead))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3657 (condition-case nil ; in case no enclosing block
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3658 (py-goto-block-up 'no-mark)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3659 (error (setq dead t)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3660 (or dead (setq found (looking-at re))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3661 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3662 found))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3663
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3664 (defun py-suck-up-leading-text ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3665 "Return string in buffer from start of indentation to end of line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3666 Prefix with \"...\" if leading whitespace was skipped."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3667 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3668 (back-to-indentation)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3669 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3670 (if (bolp) "" "...")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3671 (buffer-substring (point) (progn (end-of-line) (point))))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3672
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3673 (defun py-suck-up-first-keyword ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3674 "Return first keyword on the line as a Lisp symbol.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3675 `Keyword' is defined (essentially) as the regular expression
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3676 ([a-z]+). Returns nil if none was found."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3677 (let ((case-fold-search nil))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3678 (if (looking-at "[ \t]*\\([a-z]+\\)\\>")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3679 (intern (buffer-substring (match-beginning 1) (match-end 1)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3680 nil)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3681
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3682 (defun py-current-defun ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3683 "Python value for `add-log-current-defun-function'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3684 This tells add-log.el how to find the current function/method/variable."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3685 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3686
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3687 ;; Move back to start of the current statement.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3688
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3689 (py-goto-initial-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3690 (back-to-indentation)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3691 (while (and (or (looking-at py-blank-or-comment-re)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3692 (py-in-literal))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3693 (not (bobp)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3694 (backward-to-indentation 1))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3695 (py-goto-initial-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3696
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3697 (let ((scopes "")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3698 (sep "")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3699 dead assignment)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3700
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3701 ;; Check for an assignment. If this assignment exists inside a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3702 ;; def, it will be overwritten inside the while loop. If it
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3703 ;; exists at top lever or inside a class, it will be preserved.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3704
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3705 (when (looking-at "[ \t]*\\([a-zA-Z0-9_]+\\)[ \t]*=")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3706 (setq scopes (buffer-substring (match-beginning 1) (match-end 1)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3707 (setq assignment t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3708 (setq sep "."))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3709
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3710 ;; Prepend the name of each outer socpe (def or class).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3711
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3712 (while (not dead)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3713 (if (and (py-go-up-tree-to-keyword "\\(class\\|def\\)")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3714 (looking-at
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3715 "[ \t]*\\(class\\|def\\)[ \t]*\\([a-zA-Z0-9_]+\\)[ \t]*"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3716 (let ((name (buffer-substring (match-beginning 2) (match-end 2))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3717 (if (and assignment (looking-at "[ \t]*def"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3718 (setq scopes name)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3719 (setq scopes (concat name sep scopes))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3720 (setq sep "."))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3721 (setq assignment nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3722 (condition-case nil ; Terminate nicely at top level.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3723 (py-goto-block-up 'no-mark)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3724 (error (setq dead t))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3725 (if (string= scopes "")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3726 nil
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3727 scopes))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3728
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3729
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3730
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3731 (defconst py-help-address "python-mode@python.org"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3732 "Address accepting submission of bug reports.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3733
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3734 (defun py-version ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3735 "Echo the current version of `python-mode' in the minibuffer."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3736 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3737 (message "Using `python-mode' version %s" py-version)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3738 (py-keep-region-active))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3739
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3740 ;; only works under Emacs 19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3741 ;(eval-when-compile
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3742 ; (require 'reporter))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3743
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3744 (defun py-submit-bug-report (enhancement-p)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3745 "Submit via mail a bug report on `python-mode'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3746 With \\[universal-argument] (programmatically, argument ENHANCEMENT-P
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3747 non-nil) just submit an enhancement request."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3748 (interactive
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3749 (list (not (y-or-n-p
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3750 "Is this a bug report (hit `n' to send other comments)? "))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3751 (let ((reporter-prompt-for-summary-p (if enhancement-p
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3752 "(Very) brief summary: "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3753 t)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3754 (require 'reporter)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3755 (reporter-submit-bug-report
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3756 py-help-address ;address
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3757 (concat "python-mode " py-version) ;pkgname
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3758 ;; varlist
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3759 (if enhancement-p nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3760 '(py-python-command
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3761 py-indent-offset
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3762 py-block-comment-prefix
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3763 py-temp-directory
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3764 py-beep-if-tab-change))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3765 nil ;pre-hooks
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3766 nil ;post-hooks
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3767 "Dear Barry,") ;salutation
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3768 (if enhancement-p nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3769 (set-mark (point))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3770 (insert
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3771 "Please replace this text with a sufficiently large code sample\n\
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3772 and an exact recipe so that I can reproduce your problem. Failure\n\
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3773 to do so may mean a greater delay in fixing your bug.\n\n")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3774 (exchange-point-and-mark)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3775 (py-keep-region-active))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3776
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3777
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3778 (defun py-kill-emacs-hook ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3779 "Delete files in `py-file-queue'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3780 These are Python temporary files awaiting execution."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3781 (mapc #'(lambda (filename)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3782 (py-safe (delete-file filename)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3783 py-file-queue))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3784
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3785 ;; arrange to kill temp files when Emacs exists
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3786 (add-hook 'kill-emacs-hook 'py-kill-emacs-hook)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3787 (add-hook 'comint-output-filter-functions 'py-pdbtrack-track-stack-file)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3788
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3789 ;; Add a designator to the minor mode strings
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3790 (or (assq 'py-pdbtrack-is-tracking-p minor-mode-alist)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3791 (push '(py-pdbtrack-is-tracking-p py-pdbtrack-minor-mode-string)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3792 minor-mode-alist))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3793
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3794
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3795
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3796 ;;; paragraph and string filling code from Bernhard Herzog
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3797 ;;; see http://mail.python.org/pipermail/python-list/2002-May/103189.html
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3798
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3799 (defun py-fill-comment (&optional justify)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3800 "Fill the comment paragraph around point"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3801 (let (;; Non-nil if the current line contains a comment.
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3802 has-comment
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3803
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3804 ;; If has-comment, the appropriate fill-prefix for the comment.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3805 comment-fill-prefix)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3806
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3807 ;; Figure out what kind of comment we are looking at.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3808 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3809 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3810 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3811 ;; A line with nothing but a comment on it?
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3812 ((looking-at "[ \t]*#[# \t]*")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3813 (setq has-comment t
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3814 comment-fill-prefix (buffer-substring (match-beginning 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3815 (match-end 0))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3816
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3817 ;; A line with some code, followed by a comment? Remember that the hash
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3818 ;; which starts the comment shouldn't be part of a string or character.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3819 ((progn
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3820 (while (not (looking-at "#\\|$"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3821 (skip-chars-forward "^#\n\"'\\")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3822 (cond
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3823 ((eq (char-after (point)) ?\\) (forward-char 2))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3824 ((memq (char-after (point)) '(?\" ?')) (forward-sexp 1))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3825 (looking-at "#+[\t ]*"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3826 (setq has-comment t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3827 (setq comment-fill-prefix
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3828 (concat (make-string (current-column) ? )
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3829 (buffer-substring (match-beginning 0) (match-end 0)))))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3830
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3831 (if (not has-comment)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3832 (fill-paragraph justify)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3833
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3834 ;; Narrow to include only the comment, and then fill the region.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3835 (save-restriction
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3836 (narrow-to-region
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3837
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3838 ;; Find the first line we should include in the region to fill.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3839 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3840 (while (and (zerop (forward-line -1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3841 (looking-at "^[ \t]*#")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3842
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3843 ;; We may have gone to far. Go forward again.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3844 (or (looking-at "^[ \t]*#")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3845 (forward-line 1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3846 (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3847
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3848 ;; Find the beginning of the first line past the region to fill.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3849 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3850 (while (progn (forward-line 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3851 (looking-at "^[ \t]*#")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3852 (point)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3853
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3854 ;; Lines with only hashes on them can be paragraph boundaries.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3855 (let ((paragraph-start (concat paragraph-start "\\|[ \t#]*$"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3856 (paragraph-separate (concat paragraph-separate "\\|[ \t#]*$"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3857 (fill-prefix comment-fill-prefix))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3858 ;;(message "paragraph-start %S paragraph-separate %S"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3859 ;;paragraph-start paragraph-separate)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3860 (fill-paragraph justify))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3861 t))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3862
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3863
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3864 (defun py-fill-string (start &optional justify)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3865 "Fill the paragraph around (point) in the string starting at start"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3866 ;; basic strategy: narrow to the string and call the default
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3867 ;; implementation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3868 (let (;; the start of the string's contents
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3869 string-start
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3870 ;; the end of the string's contents
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3871 string-end
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3872 ;; length of the string's delimiter
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3873 delim-length
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3874 ;; The string delimiter
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3875 delim
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3876 )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3877
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3878 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3879 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3880 (if (looking-at "\\('''\\|\"\"\"\\|'\\|\"\\)\\\\?\n?")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3881 (setq string-start (match-end 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3882 delim-length (- (match-end 1) (match-beginning 1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3883 delim (buffer-substring-no-properties (match-beginning 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3884 (match-end 1)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3885 (error "The parameter start is not the beginning of a python string"))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3886
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3887 ;; if the string is the first token on a line and doesn't start with
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3888 ;; a newline, fill as if the string starts at the beginning of the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3889 ;; line. this helps with one line docstrings
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3890 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3891 (beginning-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3892 (and (/= (char-before string-start) ?\n)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3893 (looking-at (concat "[ \t]*" delim))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3894 (setq string-start (point))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3895
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3896 (forward-sexp (if (= delim-length 3) 2 1))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3897
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3898 ;; with both triple quoted strings and single/double quoted strings
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3899 ;; we're now directly behind the first char of the end delimiter
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3900 ;; (this doesn't work correctly when the triple quoted string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3901 ;; contains the quote mark itself). The end of the string's contents
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3902 ;; is one less than point
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3903 (setq string-end (1- (point))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3904
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3905 ;; Narrow to the string's contents and fill the current paragraph
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3906 (save-restriction
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3907 (narrow-to-region string-start string-end)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3908 (let ((ends-with-newline (= (char-before (point-max)) ?\n)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3909 (fill-paragraph justify)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3910 (if (and (not ends-with-newline)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3911 (= (char-before (point-max)) ?\n))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3912 ;; the default fill-paragraph implementation has inserted a
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3913 ;; newline at the end. Remove it again.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3914 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3915 (goto-char (point-max))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3916 (delete-char -1)))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3917
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3918 ;; return t to indicate that we've done our work
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3919 t))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3920
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3921 (defun py-fill-paragraph (&optional justify)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3922 "Like \\[fill-paragraph], but handle Python comments and strings.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3923 If any of the current line is a comment, fill the comment or the
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3924 paragraph of it that point is in, preserving the comment's indentation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3925 and initial `#'s.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3926 If point is inside a string, narrow to that string and fill.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3927 "
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3928 (interactive "P")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3929 ;; fill-paragraph will narrow incorrectly
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3930 (save-restriction
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3931 (widen)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3932 (let* ((bod (py-point 'bod))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3933 (pps (parse-partial-sexp bod (point))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3934 (cond
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3935 ;; are we inside a comment or on a line with only whitespace before
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3936 ;; the comment start?
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3937 ((or (nth 4 pps)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3938 (save-excursion (beginning-of-line) (looking-at "[ \t]*#")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3939 (py-fill-comment justify))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3940 ;; are we inside a string?
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3941 ((nth 3 pps)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3942 (py-fill-string (nth 8 pps)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3943 ;; are we at the opening quote of a string, or in the indentation?
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3944 ((save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3945 (forward-word 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3946 (eq (py-in-literal) 'string))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3947 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3948 (py-fill-string (py-point 'boi))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3949 ;; are we at or after the closing quote of a string?
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3950 ((save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3951 (backward-word 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3952 (eq (py-in-literal) 'string))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3953 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3954 (py-fill-string (py-point 'boi))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3955 ;; otherwise use the default
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3956 (t
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3957 (fill-paragraph justify))))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3958
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3959
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3960
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3961 (provide 'python-mode)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3962 ;;; python-mode.el ends here