annotate .elisp/python-mode.el @ 449:7f7255eb9ac3

hgignore: ignore some more directories things insist on creating
author Augie Fackler <raf@durin42.com>
date Sun, 08 Oct 2017 20:39:03 -0400
parents 4741c022c7ae
children
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
175
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
12
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
13 (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
14 "`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
15
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
16 ;; 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
17 ;;
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
18 ;; 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
19 ;; 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
20 ;; 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
21 ;; any later version.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
22 ;;
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
23 ;; 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
24 ;; 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
25 ;; 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
26 ;; for more details.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
27 ;;
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
28 ;; 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
29 ;; 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
30
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
31 ;;; Commentary:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
32
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
33 ;; 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
34 ;; 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
35 ;; 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
36 ;; 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
37 ;; 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
38 ;; 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
39 ;; 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
40 ;; 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
41 ;; list.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
42
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
43 ;; 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
44 ;; 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
45 ;; 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
46
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
47 ;; 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
48 ;; 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
49
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
50 ;; 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
51 ;;
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
52 ;; 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
53
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
54 ;; INSTALLATION:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
55
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
56 ;; 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
57 ;; 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
58 ;; ".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
59 ;; 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
60 ;; (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
61 ;; (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
62 ;; interpreter-mode-alist))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
63 ;; (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
64 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
65 ;; 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
66 ;; 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
67 ;; (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
68 ;; (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
69
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
70 ;; BUG REPORTING:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
71
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
72 ;; 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
73 ;; 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
74 ;; 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
75 ;; 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
76 ;; 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
77 ;; 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
78
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
79 ;; 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
80 ;; 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
81 ;; 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
82
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
83 ;;; Code:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
84
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
85 (require 'comint)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
86 (require 'custom)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
87 (require 'cl)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
88 (require 'compile)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
89 (require 'ansi-color)
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
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
92 ;; user definable variables
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
93 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
94
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
95 (defgroup python nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
96 "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
97 :group 'languages
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
98 :prefix "py-")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
99
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
100 (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
101 "*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
102 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
103 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
104 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
105
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
106 (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
107 "*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
108 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
109 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
110
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
111 (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
112 (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
113 "*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
114 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
115 :group 'python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
116 :tag "Jython Command")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
117
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
118 (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
119 "*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
120 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
121
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
122 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
123 `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
124 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
125
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
126 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
127 `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
128 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
129
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
130 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
131 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
132 \\[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
133 :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
134 (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
135 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
136
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
137 (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
138 "*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
139 :type '(repeat string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
140 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
141
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
142 (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
143 (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
144 "*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
145 :type '(repeat string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
146 :group 'python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
147 :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
148
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
149 (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
150 "*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
151 `\\[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
152 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
153 :type 'integer
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
154 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
155
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
156 (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
157 "*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
158 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
159 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
160 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
161 :type 'integer
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
162 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
163
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
164 (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
165 "*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
166 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
167 to `python-mode':
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
168
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
169 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
170 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
171 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
172 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
173
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
174 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
175 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
176 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
177 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
178 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
179
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
180 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
181 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
182 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
183 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
184 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
185
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
186 (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
187 "*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
188 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
189 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
190 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
191 :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
192 (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
193 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
194
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
195 (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
196 "*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
197 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
198 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
199 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
200 `...' 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
201 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
202 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
203
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
204 (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
205 "*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
206
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
207 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
208 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
209
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
210 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
211 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
212 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
213 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
214 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
215 purposes.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
216
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
217 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
218 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
219 :type '(choice
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
220 (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
221 (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
222 (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
223 other)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
224 )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
225 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
226
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
227 (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
228 (let ((ok '(lambda (x)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
229 (and x
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
230 (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
231 (file-directory-p x)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
232 (file-writable-p x)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
233 x))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
234 (or (funcall ok (getenv "TMPDIR"))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
235 (funcall ok "/usr/tmp")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
236 (funcall ok "/tmp")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
237 (funcall ok "/var/tmp")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
238 (funcall ok ".")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
239 (error
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
240 "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
241 "*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
242 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
243 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
244 /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
245 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
246 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
247
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
248 (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
249 "*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
250 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
251
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
252 \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
253
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
254 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
255 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
256 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
257 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
258 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
259 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
260 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
261
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
262 (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
263 "*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
264 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
265 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
266 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
267 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
268 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
269
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
270 (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
271 "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
272 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
273 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
274 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
275
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
276 (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
277 "*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
278 :type 'function
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
279 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
280
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
281 (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
282 "*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
283 :type 'function
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
284 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
285
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
286 (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
287 "*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
288 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
289 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
290 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
291 (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
292
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
293 (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
294 "*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
295 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
296 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
297 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
298 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
299 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
300 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
301 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
302 (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
303
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
304 (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
305 "*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
306 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
307 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
308
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
309 (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
310 20000
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
311 "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
312 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
313 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
314 -- 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
315 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
316 :type 'integer
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
317 :group 'python
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
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
320 (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
321 (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
322 '("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
323 "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
324 :type '(repeat string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
325 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
326
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
327 ;; Not customizable
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
328 (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
329 "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
330 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
331 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
332
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
333 # Local Variables:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
334 # 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
335 # End:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
336
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
337 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
338 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
339 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
340 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
341 (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
342
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
343 (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
344 "*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
345 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
346 :group 'python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
347 :tag "Pychecker Command")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
348
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
349 (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
350 "*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
351 :type '(repeat string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
352 :group 'python
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
353 :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
354
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
355 (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
356 '(("jython" . 'jython)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
357 ("python" . 'cpython))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
358 "*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
359 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
360
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
361 (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
362 "*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
363 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
364 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
365
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
366 (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
367 "*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
368 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
369 :type 'string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
370 :group 'python)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
371
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
372 (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
373 "*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
374 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
375 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
376 :type 'boolean
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
377 :group 'python)
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 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
381 ;; 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
382
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
383 (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
384 "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
385 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
386 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
387 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
388
175
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
389 ;; 2009-09-10 a.roehler@web.de changed section start
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
390 ;; from python.el, version "22.1"
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
391
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
392 (defconst python-font-lock-syntactic-keywords
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
393 ;; Make outer chars of matching triple-quote sequences into generic
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
394 ;; string delimiters. Fixme: Is there a better way?
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
395 ;; First avoid a sequence preceded by an odd number of backslashes.
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
396 `((,(rx (not (any ?\\))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
397 ?\\ (* (and ?\\ ?\\))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
398 (group (syntax string-quote))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
399 (backref 1)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
400 (group (backref 1)))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
401 (2 ,(string-to-syntax "\""))) ; dummy
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
402 (,(rx (group (optional (any "uUrR"))) ; prefix gets syntax property
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
403 (optional (any "rR")) ; possible second prefix
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
404 (group (syntax string-quote)) ; maybe gets property
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
405 (backref 2) ; per first quote
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
406 (group (backref 2))) ; maybe gets property
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
407 (1 (python-quote-syntax 1))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
408 (2 (python-quote-syntax 2))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
409 (3 (python-quote-syntax 3)))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
410 ;; This doesn't really help.
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
411 ;;; (,(rx (and ?\\ (group ?\n))) (1 " "))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
412 ))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
413
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
414 (defun python-quote-syntax (n)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
415 "Put `syntax-table' property correctly on triple quote.
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
416 Used for syntactic keywords. N is the match number (1, 2 or 3)."
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
417 ;; Given a triple quote, we have to check the context to know
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
418 ;; whether this is an opening or closing triple or whether it's
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
419 ;; quoted anyhow, and should be ignored. (For that we need to do
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
420 ;; the same job as `syntax-ppss' to be correct and it seems to be OK
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
421 ;; to use it here despite initial worries.) We also have to sort
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
422 ;; out a possible prefix -- well, we don't _have_ to, but I think it
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
423 ;; should be treated as part of the string.
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
424
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
425 ;; Test cases:
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
426 ;; ur"""ar""" x='"' # """
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
427 ;; x = ''' """ ' a
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
428 ;; '''
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
429 ;; x '"""' x """ \"""" x
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
430 (save-excursion
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
431 (goto-char (match-beginning 0))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
432 (cond
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
433 ;; Consider property for the last char if in a fenced string.
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
434 ((= n 3)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
435 (let* ((font-lock-syntactic-keywords nil)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
436 (syntax (syntax-ppss)))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
437 (when (eq t (nth 3 syntax)) ; after unclosed fence
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
438 (goto-char (nth 8 syntax)) ; fence position
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
439 (skip-chars-forward "uUrR") ; skip any prefix
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
440 ;; Is it a matching sequence?
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
441 (if (eq (char-after) (char-after (match-beginning 2)))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
442 (eval-when-compile (string-to-syntax "|"))))))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
443 ;; Consider property for initial char, accounting for prefixes.
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
444 ((or (and (= n 2) ; leading quote (not prefix)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
445 (= (match-beginning 1) (match-end 1))) ; prefix is null
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
446 (and (= n 1) ; prefix
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
447 (/= (match-beginning 1) (match-end 1)))) ; non-empty
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
448 (let ((font-lock-syntactic-keywords nil))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
449 (unless (eq 'string (syntax-ppss-context (syntax-ppss)))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
450 (eval-when-compile (string-to-syntax "|")))))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
451 ;; Otherwise (we're in a non-matching string) the property is
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
452 ;; nil, which is OK.
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
453 )))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
454
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
455
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
456 (defvar py-mode-syntax-table
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
457 (let ((table (make-syntax-table)))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
458 ;; Give punctuation syntax to ASCII that normally has symbol
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
459 ;; syntax or has word syntax and isn't a letter.
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
460 (let ((symbol (string-to-syntax "_"))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
461 (sst (standard-syntax-table)))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
462 (dotimes (i 128)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
463 (unless (= i ?_)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
464 (if (equal symbol (aref sst i))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
465 (modify-syntax-entry i "." table)))))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
466 (modify-syntax-entry ?$ "." table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
467 (modify-syntax-entry ?% "." table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
468 ;; exceptions
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
469 (modify-syntax-entry ?# "<" table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
470 (modify-syntax-entry ?\n ">" table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
471 (modify-syntax-entry ?' "\"" table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
472 (modify-syntax-entry ?` "$" table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
473 table))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
474
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
475 (defsubst python-in-string/comment ()
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
476 "Return non-nil if point is in a Python literal (a comment or string)."
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
477 ;; We don't need to save the match data.
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
478 (nth 8 (syntax-ppss)))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
479
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
480 (defconst python-space-backslash-table
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
481 (let ((table (copy-syntax-table py-mode-syntax-table)))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
482 (modify-syntax-entry ?\\ " " table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
483 table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
484 "`python-mode-syntax-table' with backslash given whitespace syntax.")
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
485
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
486 ;; 2009-09-10 a.roehler@web.de changed section end
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
487
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
488 (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
489 (let (features)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
490 features)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
491 "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
492 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
493 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
494
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
495 ;; 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
496 (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
497 "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
498 (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
499
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
500 ;; PEP 318 decorators
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
501 (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
502 "Face method decorators.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
503 (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
504
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
505 ;; Face for builtins
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
506 (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
507 "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
508 (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
509
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
510 ;; XXX, TODO, and FIXME comments and such
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
511 (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
512 "Face for XXX, TODO, and FIXME tags")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
513 (make-face 'py-XXX-tag-face)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
514
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
515 (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
516 (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
517 (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
518 (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
519 (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
520 (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
521 (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
522 (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
523 (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
524 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
525 (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
526
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
527 (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
528 (let ((kw1 (mapconcat 'identity
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
529 '("and" "assert" "break" "class"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
530 "continue" "def" "del" "elif"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
531 "else" "except" "for" "from"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
532 "global" "if" "import" "in"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
533 "is" "lambda" "not" "or"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
534 "pass" "raise" "as" "return"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
535 "while" "with" "yield"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
536 )
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
537 "\\|"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
538 (kw2 (mapconcat 'identity
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
539 '("else:" "except:" "finally:" "try:")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
540 "\\|"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
541 (kw3 (mapconcat 'identity
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
542 ;; 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
543 ;; already defined as a pseudo keyword.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
544 '("__debug__"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
545 "__import__" "__name__" "abs" "all" "any" "apply"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
546 "basestring" "bin" "bool" "buffer" "bytearray"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
547 "callable" "chr" "classmethod" "cmp" "coerce"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
548 "compile" "complex" "copyright" "credits"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
549 "delattr" "dict" "dir" "divmod" "enumerate" "eval"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
550 "exec" "execfile" "exit" "file" "filter" "float"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
551 "format" "getattr" "globals" "hasattr" "hash" "help"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
552 "hex" "id" "input" "int" "intern" "isinstance"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
553 "issubclass" "iter" "len" "license" "list" "locals"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
554 "long" "map" "max" "memoryview" "min" "next"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
555 "object" "oct" "open" "ord" "pow" "print" "property"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
556 "quit" "range" "raw_input" "reduce" "reload" "repr"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
557 "round" "set" "setattr" "slice" "sorted"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
558 "staticmethod" "str" "sum" "super" "tuple" "type"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
559 "unichr" "unicode" "vars" "xrange" "zip")
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 (kw4 (mapconcat 'identity
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
562 ;; Exceptions and warnings
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
563 '("ArithmeticError" "AssertionError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
564 "AttributeError" "BaseException" "BufferError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
565 "BytesWarning" "DeprecationWarning" "EOFError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
566 "EnvironmentError" "Exception"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
567 "FloatingPointError" "FutureWarning" "GeneratorExit"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
568 "IOError" "ImportError" "ImportWarning"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
569 "IndentationError" "IndexError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
570 "KeyError" "KeyboardInterrupt" "LookupError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
571 "MemoryError" "NameError" "NotImplemented"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
572 "NotImplementedError" "OSError" "OverflowError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
573 "PendingDeprecationWarning" "ReferenceError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
574 "RuntimeError" "RuntimeWarning" "StandardError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
575 "StopIteration" "SyntaxError" "SyntaxWarning"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
576 "SystemError" "SystemExit" "TabError" "TypeError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
577 "UnboundLocalError" "UnicodeDecodeError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
578 "UnicodeEncodeError" "UnicodeError"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
579 "UnicodeTranslateError" "UnicodeWarning"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
580 "UserWarning" "ValueError" "Warning"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
581 "ZeroDivisionError")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
582 "\\|"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
583 )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
584 (list
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
585 '("^[ \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
586 ;; keywords
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
587 (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
588 ;; 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
589 (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
590 '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
591 ;; 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
592 ;; 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
593 (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
594 ;; Exceptions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
595 (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
596 ;; classes
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
597 '("\\<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
598 ;; functions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
599 '("\\<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
600 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
601 ;; pseudo-keywords
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
602 '("\\<\\(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
603 1 py-pseudo-keyword-face)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
604 ;; XXX, TODO, and FIXME tags
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
605 '("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
606 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
607 "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
608
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
609 ;; 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
610 (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
611 "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
612 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
613
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
614 (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
615
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
616 (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
617
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
618
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 ;; Constants
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
621
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
622 (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
623 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
624 ;; 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
625 ;; 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
626 ;; 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
627 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
628 ;; (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
629 ;; 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
630 "[rR]?'''[^']*\\(\\('[^']\\|''[^']\\)[^']*\\)*'''"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
631 "\\|"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
632 ;; (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
633 ;; 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
634 "[rR]?\"\"\"[^\"]*\\(\\(\"[^\"]\\|\"\"[^\"]\\)[^\"]*\\)*\"\"\""
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
635 "\\|"
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
636 "[rR]?'\\([^'\n\\]\\|\\\\.\\)*'" ; single-quoted
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
637 "\\|" ; or
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
638 "[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
639 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
640 "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
641
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
642 (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
643 ;; 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
644 ;; 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
645 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
646 "\\(" "[^#'\"\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
647 "\\\\$")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
648 "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
649
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
650 (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
651 "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
652
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
653 (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
654 (concat "\\(" (mapconcat 'identity
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
655 '("else:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
656 "except\\(\\s +.*\\)?:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
657 "finally:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
658 "elif\\s +.*:")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
659 "\\|")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
660 "\\)")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
661 "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
662
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
663 (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
664 "\\(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
665 "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
666
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
667 (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
668 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
669 "\\("
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
670 (mapconcat 'identity
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
671 (list "try:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
672 "except\\(\\s +.*\\)?:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
673 "while\\s +.*:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
674 "for\\s +.*:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
675 "if\\s +.*:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
676 "elif\\s +.*:"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
677 (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
678 )
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
679 "\\|")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
680 "\\)")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
681 "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
682
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
683 (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
684 "[ \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
685 "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
686
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
687 ;; pdbtrack constants
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
688 (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
689 ; "^> \\([^(]+\\)(\\([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
690 "^> \\(.*\\)(\\([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
691 "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
692
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
693 (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
694 "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
695
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
696 (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
697 "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
698
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
699
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
700
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
701 ;; Major mode boilerplate
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
702
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
703 ;; 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
704 (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
705 "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
706 (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
707
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
708 (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
709 "*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
710
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
711 (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
712 (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
713 "*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
714 `python-mode-hook'.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
715
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
716 (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
717 "*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
718
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
719 ;; 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
720 ;; 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
721 (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
722 (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
723
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
724 (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
725 "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
726 (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
727 nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
728 (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
729 ;; electric keys
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
730 (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
731 ;; indentation level modifiers
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
732 (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
733 (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
734 (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
735 (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
736 ;; subprocess commands
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
737 (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
738 (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
739 (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
740 (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
741 (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
742 (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
743 (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
744 ;; 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
745 ;; 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
746 ;; 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
747 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
748 ;; 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
749 ;; 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
750 ;; 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
751 ;; 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
752 ;; 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
753 (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
754 (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
755 ;; 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
756 ;; 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
757 ;; 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
758 ;; 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
759 (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
760 (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
761 ;; 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
762 ;; backward-kill-word.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
763 (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
764 (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
765 ;; Miscellaneous
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
766 (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
767 (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
768 (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
769 (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
770 (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
771 (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
772 (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
773 (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
774 (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
775 (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
776 (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
777 (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
778 (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
779 (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
780 ;; 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
781 ;; 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
782 (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
783 ;; information
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
784 (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
785 (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
786 (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
787 ;; 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
788 ;; 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
789 ;; for now.
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
790 (mapc #'(lambda (key)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
791 (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
792 (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
793 ;; 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
794 ;; 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
795 ;; 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
796 ;; 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
797 ;; 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
798 ;; 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
799 ;; 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
800 ;; change.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
801 (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
802 )
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 (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
805 "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
806 (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
807 nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
808 (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
809 (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
810 (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
811 ;; 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
812 ;; 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
813 (mapc #' (lambda (key)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
814 (define-key py-mode-output-map key
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
815 #'(lambda () (interactive) (beep))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
816 (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
817 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
818
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
819 (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
820 "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
821 (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
822 nil
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
823 (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
824 (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
825 (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
826 (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
827 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
828
175
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
829 ;; 2009-09-09 a.roehler@web.de changed section start
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
830 ;; from python.el, version "22.1"
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
831
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
832 ;; (defvar py-mode-syntax-table nil
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
833 ;; "Syntax table used in `python-mode' buffers.")
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
834 ;; (when (not py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
835 ;; (setq py-mode-syntax-table (make-syntax-table))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
836 ;; (modify-syntax-entry ?\( "()" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
837 ;; (modify-syntax-entry ?\) ")(" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
838 ;; (modify-syntax-entry ?\[ "(]" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
839 ;; (modify-syntax-entry ?\] ")[" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
840 ;; (modify-syntax-entry ?\{ "(}" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
841 ;; (modify-syntax-entry ?\} "){" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
842 ;; ;; Add operator symbols misassigned in the std table
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
843 ;; (modify-syntax-entry ?\$ "." py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
844 ;; (modify-syntax-entry ?\% "." py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
845 ;; (modify-syntax-entry ?\& "." py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
846 ;; (modify-syntax-entry ?\* "." py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
847 ;; (modify-syntax-entry ?\+ "." py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
848 ;; (modify-syntax-entry ?\- "." py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
849 ;; (modify-syntax-entry ?\/ "." py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
850 ;; (modify-syntax-entry ?\< "." py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
851 ;; (modify-syntax-entry ?\= "." py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
852 ;; (modify-syntax-entry ?\> "." py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
853 ;; (modify-syntax-entry ?\| "." py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
854 ;; ;; For historical reasons, underscore is word class instead of
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
855 ;; ;; symbol class. GNU conventions say it should be symbol class, but
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
856 ;; ;; there's a natural conflict between what major mode authors want
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
857 ;; ;; and what users expect from `forward-word' and `backward-word'.
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
858 ;; ;; Guido and I have hashed this out and have decided to keep
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
859 ;; ;; underscore in word class. If you're tempted to change it, try
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
860 ;; ;; binding M-f and M-b to py-forward-into-nomenclature and
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
861 ;; ;; py-backward-into-nomenclature instead. This doesn't help in all
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
862 ;; ;; situations where you'd want the different behavior
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
863 ;; ;; (e.g. backward-kill-word).
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
864 ;; (modify-syntax-entry ?\_ "w" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
865 ;; ;; Both single quote and double quote are string delimiters
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
866 ;; (modify-syntax-entry ?\' "\"" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
867 ;; (modify-syntax-entry ?\" "\"" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
868 ;; ;; backquote is open and close paren
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
869 ;; (modify-syntax-entry ?\` "$" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
870 ;; ;; comment delimiters
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
871 ;; (modify-syntax-entry ?\# "<" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
872 ;; (modify-syntax-entry ?\n ">" py-mode-syntax-table)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
873 ;;
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
874 ;; )
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
875 ;; 2009-09-09 a.roehler@web.de changed section end
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
876
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
877 ;; 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
878 ;; 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
879 (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
880 "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
881 (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
882 (setq py-dotted-expression-syntax-table
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
883 (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
884 (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
885 (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
886
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
887
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
888
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
889 ;; Utilities
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
890 (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
891 "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
892 `(condition-case nil
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
893 (progn ,@ body)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
894 (error nil)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
895
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
896 (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
897 "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
898 ;; 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
899 ;; 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
900 ;; 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
901 (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
902 (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
903
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
904 (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
905 "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
906 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
907
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
908 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
909 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
910 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
911 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
912 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
913 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
914 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
915 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
916
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
917 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
918 (let ((here (point)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
919 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
920 ((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
921 ((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
922 ((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
923 ((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
924 ;; 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
925 ((eq position 'bob) (goto-char (point-min)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
926 ((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
927 ((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
928 ((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
929 (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
930 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
931 (prog1
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
932 (point)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
933 (goto-char here))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
934
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
935 (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
936 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
937 ((fboundp 'make-extent)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
938 ;; XEmacs
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
939 (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
940 (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
941 (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
942 (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
943 (t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
944 ;; 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
945 )
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
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
948 (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
949 "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
950 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
951 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
952 ;; 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
953 ;; interface.
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 ;; 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
956 (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
957 (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
958 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
959 ((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
960 ((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
961 (t nil))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
962
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
963 ;; 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
964 ;; 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
965 (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
966 "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
967 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
968 ;; 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
969 (buffer-syntactic-context))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
970
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
971 (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
972 (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
973
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
974
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
975
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
976 ;; 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
977 ;; (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
978 (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
979 "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
980 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
981 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
982
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
983 (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
984 (easy-menu-define
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
985 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
986 '("Python"
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
987 ["Comment Out Region" py-comment-region (mark)]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
988 ["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
989 "-"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
990 ["Mark current block" py-mark-block t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
991 ["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
992 ["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
993 "-"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
994 ["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
995 ["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
996 "-"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
997 ["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
998 ["Execute buffer" py-execute-buffer t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
999 ["Execute region" py-execute-region (mark)]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1000 ["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
1001 ["Execute string" py-execute-string t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1002 ["Start interpreter..." py-shell t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1003 "-"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1004 ["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
1005 ["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
1006 ["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
1007 ["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
1008 ["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
1009 "-"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1010 ["Describe mode" py-describe-mode t]
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1011 )))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1012
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1013
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 ;; Imenu definitions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1016 (defvar py-imenu-class-regexp
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1017 (concat ; <<classes>>
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1018 "\\(" ;
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1019 "^[ \t]*" ; newline and maybe whitespace
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1020 "\\(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
1021 ; 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
1022 "\\([ \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
1023 "[ \t]*:" ; and the final :
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1024 "\\)" ; >>classes<<
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1025 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1026 "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
1027 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1028
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1029 (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
1030 (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
1031 "\\(" ;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1032 "^[ \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
1033 "\\(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
1034 "\\([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
1035 ; function arguments...
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1036 ;; "[ \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
1037 "[ \t]*(\\([^:#]*\\))"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1038 "\\)" ; end of def
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1039 "[ \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
1040 "\\)" ; >>methods and functions<<
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1041 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1042 "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
1043 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1044
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1045 (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
1046 "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
1047
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1048 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
1049 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
1050
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1051 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
1052 information.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1053
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1054 (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
1055 "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
1056 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
1057 functions are listed.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1058
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1059 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
1060 information.")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1061
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1062 ;; 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
1063 ;; 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
1064 ;; it.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1065 (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
1066 (cons
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1067 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1068 py-imenu-class-regexp
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1069 "\\|" ; or...
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1070 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
1071 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1072 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
1073 "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
1074 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
1075 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
1076 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
1077
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1078 ;; 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
1079 ;; 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
1080 ;; 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
1081 (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
1082 (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
1083
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1084
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1085 (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
1086 "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
1087 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
1088 \\[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
1089 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
1090 (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
1091 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
1092 py-imenu-method-arg-parens
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1093 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
1094 (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
1095 ;; 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
1096 ;; 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
1097 ;; 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
1098 (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
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-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
1101 "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
1102
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1103 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
1104 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
1105
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1106 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
1107
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1108 (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
1109
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1110 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
1111 list as in
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1112
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1113 (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
1114
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1115 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
1116 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
1117 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
1118
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1119 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
1120 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
1121 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
1122 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
1123 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
1124 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
1125 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
1126
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1127 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
1128 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
1129 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
1130 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
1131 (let (index-alist
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1132 sub-method-alist
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1133 looking-p
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1134 def-name prev-name
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1135 cur-indent def-pos
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1136 (class-paren (first py-imenu-generic-parens))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1137 (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
1138 (setq looking-p
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1139 (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
1140 (while looking-p
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1141 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1142 ;; 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
1143 ;; 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
1144 ;; imenu-1.11
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1145 ;;(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
1146 (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
1147 class-paren def-paren)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1148 (setq def-name
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1149 (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
1150 (match-end cur-paren))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1151 (save-match-data
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1152 (py-beginning-of-def-or-class 'either))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1153 (beginning-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1154 (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
1155 ;; 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
1156 ;; 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
1157 ;; in a list.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1158 (setq def-pos
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1159 (or (match-beginning class-paren)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1160 (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
1161 ;; 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
1162 (or start-indent
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1163 (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
1164 ;; 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
1165 (or prev-name
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1166 (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
1167 ;; 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
1168 ;; or shallower indentation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1169 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1170 ;; 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
1171 ((py-in-literal))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1172 ;; 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
1173 ((= start-indent cur-indent)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1174 (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
1175 ;; 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
1176 ((< start-indent cur-indent)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1177 ;; 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
1178 ;; 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
1179 ;; 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
1180 ;; list
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1181 (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
1182 (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
1183 (if sub-method-alist
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1184 ;; 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
1185 ;; 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
1186 (let ((save-elmt (pop index-alist)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1187 (push (cons prev-name
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1188 (cons save-elmt sub-method-alist))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1189 index-alist))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1190 ;; 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
1191 (t
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1192 (setq looking-p nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1193 (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
1194 ;; end-cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1195 (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
1196 (and looking-p
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1197 (setq looking-p
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1198 (re-search-forward py-imenu-generic-regexp
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1199 (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
1200 (nreverse index-alist)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1201
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1202
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1203
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1204 (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
1205 "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
1206 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
1207 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
1208 `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
1209 ;; 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
1210 ;; 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
1211 (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
1212 auto-mode-interpreter-regexp
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1213 ;; stolen from Emacs 21.2
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1214 "#![ \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
1215 (interpreter (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1216 (goto-char (point-min))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1217 (if (looking-at re)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1218 (match-string 2)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1219 "")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1220 elt)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1221 ;; 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
1222 (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
1223 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
1224 (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
1225
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1226
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 (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
1229 "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
1230 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
1231 `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
1232 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
1233 (let (mode)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1234 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1235 (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
1236 (while (and (not mode)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1237 (search-forward-regexp
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1238 "^\\(\\(from\\)\\|\\(import\\)\\) \\([^ \t\n.]+\\)"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1239 py-import-check-point-max t))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1240 (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
1241 'jython
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1242 ))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1243 mode))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1244
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1245
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1246 (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
1247 "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
1248 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
1249 - 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
1250 - 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
1251 - 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
1252 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1253 (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
1254 (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
1255 py-default-interpreter
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1256 ; '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
1257 ; ;; 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
1258 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1259
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1260
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1261 ;;;###autoload
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1262 (defun python-mode ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1263 "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
1264 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
1265 `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
1266 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
1267 enter `\\[py-version]'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1268 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
1269 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
1270 COMMANDS
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1271 \\{py-mode-map}
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1272 VARIABLES
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1273 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
1274 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
1275 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
1276 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
1277 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
1278 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1279 ;; 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
1280 (kill-all-local-variables)
175
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1281 ;; (make-local-variable 'font-lock-defaults)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1282 (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
1283 (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
1284 (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
1285 (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
1286 (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
1287 (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
1288 (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
1289 (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
1290 (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
1291 (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
1292 (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
1293 (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
1294 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1295 (set-syntax-table py-mode-syntax-table)
175
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1296 ;; 2009-09-10 a.roehler@web.de changed section start
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1297 ;; from python.el, version "22.1"
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1298 (set (make-local-variable 'font-lock-defaults)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1299 '(python-font-lock-keywords nil nil nil nil
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1300 (font-lock-syntactic-keywords
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1301 . python-font-lock-syntactic-keywords)))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1302 ;; 2009-09-10 a.roehler@web.de changed section end
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1303 (setq major-mode 'python-mode
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1304 mode-name "Python"
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1305 local-abbrev-table python-mode-abbrev-table
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1306 ;; 2009-09-10 a.roehler@web.de changed section start
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1307 ;; font-lock-defaults ...
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1308 ;; 2009-09-10 a.roehler@web.de changed section end
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1309 paragraph-separate "^[ \t]*$"
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1310 paragraph-start "^[ \t]*$"
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1311 require-final-newline t
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1312 comment-start "# "
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1313 comment-end ""
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1314 comment-start-skip "# *"
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1315 comment-column 40
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1316 comment-indent-function 'py-comment-indent-function
175
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1317 indent-region-function 'py-indent-region
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1318 indent-line-function 'py-indent-line
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1319 ;; 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
1320 add-log-current-defun-function 'py-current-defun
175
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1321 fill-paragraph-function 'py-fill-paragraph)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1322 (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
1323 ;; add the menu
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1324 (if py-menu
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1325 (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
1326 ;; 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
1327 (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
1328 (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
1329 ;; 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
1330 (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
1331 (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
1332 (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
1333 (if (fboundp 'imenu-add-to-menubar)
175
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1334 (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
1335 ;; 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
1336 (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
1337 (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
1338 (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
1339 ;; 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
1340 (if py-smart-indentation
175
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1341 (let ((offset py-indent-offset))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1342 ;; It's okay if this fails to guess a good value
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1343 (if (and (py-safe (py-guess-indent-offset))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1344 (<= py-indent-offset 8)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1345 (>= py-indent-offset 2))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1346 (setq offset py-indent-offset))
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1347 (setq py-indent-offset offset)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1348 ;; Only turn indent-tabs-mode off if tab-width !=
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1349 ;; py-indent-offset. Never turn it on, because the user must
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1350 ;; have explicitly turned it off.
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1351 (if (/= tab-width py-indent-offset)
4741c022c7ae python-mode: apply patch from the python-mode list to fix triplequotes.
Augie Fackler <durin42@gmail.com>
parents: 174
diff changeset
1352 (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
1353 ;; 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
1354 (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
1355 (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
1356
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1357
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1358 (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
1359 (defun jython-mode ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1360 "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
1361 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
1362 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
1363 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
1364 "
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1365 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1366 (python-mode)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1367 (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
1368 (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
1369 (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
1370
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1371
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1372 ;; 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
1373 ;; 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
1374 ;; 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
1375 ;; 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
1376 ;; already added.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1377 ;;;###autoload
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1378 (let ((modes '(("jython" . jython-mode)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1379 ("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
1380 (while modes
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1381 (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
1382 (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
1383 (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
1384 ;;;###autoload
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1385 (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
1386 (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
1387 (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
1388
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1389
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1390
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1391 ;; electric characters
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1392 (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
1393 "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
1394 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1395 (and (progn (back-to-indentation)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1396 (looking-at py-outdent-re))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1397 ;; short circuit infloop on illegal construct
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1398 (not (bobp))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1399 (progn (forward-line -1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1400 (py-goto-initial-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1401 (back-to-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1402 (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
1403 (bobp))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1404 (backward-to-indentation 1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1405 (not (looking-at py-no-outdent-re)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1406 )))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1407
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1408 (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
1409 "Insert a colon.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1410 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
1411 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
1412 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
1413 comment."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1414 (interactive "*P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1415 (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
1416 ;; 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
1417 (if (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1418 (let ((pps (parse-partial-sexp (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1419 (py-beginning-of-def-or-class)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1420 (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1421 (point))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1422 (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
1423 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1424 (let ((here (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1425 (outdent 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1426 (indent (py-compute-indentation t)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1427 (if (and (not arg)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1428 (py-outdent-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1429 (= indent (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1430 (py-next-statement -1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1431 (py-compute-indentation t)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1432 )
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1433 (setq outdent py-indent-offset))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1434 ;; 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
1435 ;; that are already dedented relative to
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1436 ;; 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
1437 ;; 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
1438 ;; 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
1439 ;; determine this???
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1440 (if (< (current-indentation) indent) nil
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1441 (goto-char here)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1442 (beginning-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1443 (delete-horizontal-space)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1444 (indent-to (- indent outdent))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1445 )))))
19
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 ;; 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
1449 (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
1450 "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
1451 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
1452 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
1453 `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
1454 (let ((curbuf (current-buffer))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1455 (procbuf (process-buffer proc))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1456 ; (comint-scroll-to-bottom-on-output t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1457 (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
1458 ;; 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
1459 (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
1460 (unwind-protect
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1461 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1462 (set-buffer procbuf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1463 (goto-char (point-max))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1464 (move-marker (process-mark proc) (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1465 (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
1466 (set-buffer curbuf))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1467 (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
1468
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1469 (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
1470 "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
1471 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
1472 ;;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
1473 ;;still around...
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1474 (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
1475 (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
1476 py-file-queue)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1477 (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
1478 (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
1479 (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
1480 (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
1481 (if py-file-queue
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1482 (let ((pyproc (get-buffer-process (current-buffer))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1483 (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
1484 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1485
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1486 (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
1487 "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
1488 ;; 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
1489 (cond (activation
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1490 (setq overlay-arrow-position (make-marker))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1491 (setq overlay-arrow-string "=>")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1492 (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
1493 (setq py-pdbtrack-is-tracking-p t))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1494 (overlay-arrow-position
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1495 (setq overlay-arrow-position nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1496 (setq py-pdbtrack-is-tracking-p nil))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1497 ))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1498
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1499 (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
1500 "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
1501
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1502 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
1503 `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
1504
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1505 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
1506 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
1507
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1508 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
1509 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
1510 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
1511 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
1512 (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
1513 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
1514 ;; 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
1515 ;; (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
1516 ;; 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
1517 ;; 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
1518 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1519 ;; 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
1520 ;; 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
1521 ;; 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
1522 ;; '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
1523 (let* ((origbuf (current-buffer))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1524 (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
1525
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1526 (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
1527 (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
1528
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1529 (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
1530 (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
1531 (- procmark
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1532 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
1533 procmark))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1534 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
1535
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1536 (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
1537 (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
1538
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1539 (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
1540
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1541 (if (stringp target)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1542 (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
1543
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1544 (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
1545 (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
1546 (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
1547 (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
1548 (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
1549 (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
1550 (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
1551 (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
1552
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1553 )))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1554 )
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-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
1557 "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
1558
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1559 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
1560
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1561 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
1562 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
1563
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1564 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
1565 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
1566
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1567 (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
1568
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1569 "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
1570
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1571 (let* ((filename (match-string 1 block))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1572 (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
1573 (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
1574 funcbuffer)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1575
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1576 (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
1577 (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
1578
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1579 ((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
1580 (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
1581 ;; 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
1582 (setq lineno
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1583 (+ lineno
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1584 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1585 (set-buffer funcbuffer)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1586 (count-lines
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1587 (point-min)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1588 (max (point-min)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1589 (string-match "^\\([^#]\\|#[^#]\\|#$\\)"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1590 (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
1591 (point-max)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1592 ))))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1593 (list lineno funcbuffer))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1594
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1595 ((= (elt filename 0) ?\<)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1596 (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
1597
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1598 (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
1599 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1600 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1601 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1602
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1603 (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
1604 "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
1605
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1606 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
1607 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
1608 (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
1609 buf
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1610 got)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1611 (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
1612 (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
1613 buffers (cdr buffers))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1614 (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
1615 (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
1616 (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
1617 (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
1618 funcname "\\s-*(")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1619 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1620 (set-buffer buf)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1621 (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
1622 (point-max))))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1623 (setq got buf)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1624 got))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1625
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1626 (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
1627 "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
1628 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
1629 (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
1630 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1631 (set-buffer buf)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1632 (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
1633 (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
1634 (setq file (match-string 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1635 line (string-to-number (match-string 2))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1636 bol (py-point 'bol))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1637 (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
1638 (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
1639 (beep)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1640 (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
1641 (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
1642 err-p))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1643
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1644
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1645
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1646 ;;; Subprocess commands
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1647
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1648 ;; 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
1649 (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
1650 (defvar py-exception-buffer nil)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1651 (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
1652 (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
1653
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1654 ;; 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
1655 (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
1656 (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
1657 (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
1658 (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
1659 (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
1660 (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
1661
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1662 (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
1663 "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
1664
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1665 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
1666 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
1667 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
1668
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1669 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
1670 `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
1671 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1672 ;; 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
1673 (if (null arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1674 (setq arg 0))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1675 ;; preprocess arg
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1676 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1677 ((equal arg 0)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1678 ;; toggle
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1679 (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
1680 (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
1681 (setq arg 1)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1682 ((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
1683 ((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
1684 (let (msg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1685 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1686 ((< 0 arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1687 ;; set to CPython
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1688 (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
1689 py-which-args py-python-command-args
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1690 py-which-bufname "Python"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1691 msg "CPython")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1692 (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
1693 (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
1694 ((> 0 arg)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1695 (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
1696 py-which-args py-jython-command-args
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1697 py-which-bufname "Jython"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1698 msg "Jython")
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1699 (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
1700 (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
1701 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1702 (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
1703 (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
1704
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1705 ;;;###autoload
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1706 (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
1707 "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
1708 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
1709 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
1710 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
1711 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
1712
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1713 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
1714 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
1715 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
1716 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
1717 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
1718 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
1719 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
1720
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1721 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
1722 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
1723 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
1724 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
1725 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
1726
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1727 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
1728 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
1729 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
1730 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
1731 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
1732 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
1733 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
1734 mode.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1735
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1736 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
1737 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
1738 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
1739 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
1740 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
1741 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
1742 filter."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1743 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1744 ;; 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
1745 (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
1746 (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
1747 (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
1748 (when (and argprompt
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1749 (interactive-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1750 (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
1751 ;; 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
1752 (setq args (split-string
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1753 (read-string (concat py-which-bufname
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1754 " arguments: ")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1755 (concat
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1756 (mapconcat 'identity py-which-args " ") " ")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1757 ))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1758 (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
1759 (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
1760 (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
1761 (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
1762 (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
1763 (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
1764 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
1765 "^([Pp]db) "))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1766 (add-hook 'comint-output-filter-functions
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1767 '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
1768 ;; pdbtrack
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1769 (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
1770 (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
1771 (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
1772 (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
1773 (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
1774 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1775
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1776 (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
1777 "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
1778 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1779 (let ((n (length py-file-queue)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1780 (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
1781 (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
1782 (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
1783
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1784
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1785 (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
1786 "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
1787
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1788 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
1789 `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
1790 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
1791 `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
1792 \\[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
1793 buffer.
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 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
1796 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
1797 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
1798 buffer.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1799
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1800 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
1801 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
1802 `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
1803 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
1804 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
1805 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
1806
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1807 \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
1808
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1809 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
1810 (interactive "r\nP")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1811 ;; 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
1812 (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
1813 (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
1814 (let
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1815 ((sn py-serial-number)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1816 (pid (and (fboundp 'emacs-pid) (emacs-pid))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1817 (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
1818 (if pid
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1819 (format "python-%d-%d" sn pid)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1820 (format "python-%d" sn)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1821 (make-temp-name "python-")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1822 (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
1823 (cur (current-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1824 (buf (get-buffer-create file))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1825 shell)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1826 ;; 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
1827 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1828 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1829 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1830 (while (and (looking-at "\\s *$")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1831 (< (point) end))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1832 (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
1833 (setq start (point))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1834 (or (< start end)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1835 (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
1836 (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
1837 (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
1838 (set-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1839 (python-mode)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1840 (when needs-if
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1841 (insert "if 1:\n")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1842 (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
1843 (insert-buffer-substring cur start end)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1844 ;; 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
1845 ;; py-which-shell buffer local variable.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1846 (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
1847 (py-choose-shell-by-import)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1848 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
1849 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1850 ;; 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
1851 (async
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1852 ;; 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
1853 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1854 (set-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1855 (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
1856 (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
1857 ;; 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
1858 (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
1859 "-u" "")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1860 (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
1861 (pop-to-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1862 (py-postprocess-output-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1863 ;; TBD: clean up the temporary file!
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1864 ))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1865 ;; 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
1866 ;; execution there.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1867 (proc
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1868 ;; 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
1869 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1870 (set-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1871 (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
1872 (if (not py-file-queue)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1873 (py-execute-file proc file)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1874 (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
1875 (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
1876 (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
1877 (t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1878 ;; 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
1879 (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
1880 "Jython")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1881 " -" ""))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1882 ;; 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
1883 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1884 (set-buffer buf)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1885 (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
1886 cmd py-output-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1887 ;; 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
1888 ;; 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
1889 (if (not (get-buffer py-output-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1890 (message "No output.")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1891 (setq py-exception-buffer (current-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1892 (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
1893 (pop-to-buffer py-output-buffer)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1894 (if err-p
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1895 (pop-to-buffer py-exception-buffer)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1896 ))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1897 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1898 ;; 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
1899 (kill-buffer buf)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1900
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1901
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1902 ;; Code execution commands
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1903 (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
1904 "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
1905 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
1906 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
1907
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1908 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
1909 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
1910 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
1911
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1912 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
1913 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
1914 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1915 (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
1916 (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
1917 (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
1918 (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
1919 (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
1920 (set-buffer buffer)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1921 (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
1922 (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
1923
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1924 (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
1925 "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
1926
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1927 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
1928 the latest version.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1929
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1930 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
1931
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1932 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
1933 instead.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1934
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1935 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
1936 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
1937 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
1938
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1939 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
1940 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
1941
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1942 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
1943
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1944 - 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
1945 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
1946 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
1947
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1948 - 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
1949 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1950 ;; 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
1951 (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
1952 (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
1953 (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
1954 (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
1955 (set-buffer buffer)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1956 (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
1957 (if file
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1958 (progn
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1959 ;; Maybe save some buffers
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1960 (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
1961 (py-execute-string
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1962 (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
1963 (let ((f (file-name-sans-extension
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
1964 (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
1965 (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
1966 f f f))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1967 (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
1968 async))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1969 ;; else
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1970 (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
1971
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1972
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1973 (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
1974 "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
1975
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1976 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
1977
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1978 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
1979 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
1980 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1981 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1982 (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
1983 ;; 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
1984 (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
1985
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1986
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1987 (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
1988 "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
1989
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1990 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
1991
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1992 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
1993 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
1994 (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
1995 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1996 (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
1997 (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
1998 (insert string)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
1999 (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
2000
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2001
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 (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
2004 "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
2005 (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
2006 (if (consp py-exception-buffer)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2007 (cdr py-exception-buffer)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2008 py-exception-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2009 ((and (consp py-exception-buffer)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2010 (string-equal file (car py-exception-buffer)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2011 (cdr py-exception-buffer))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2012 ((py-safe (find-file-noselect file)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2013 ;; 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
2014 ;; is pointing to, so prompt for it
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2015 (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
2016 nil
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2017 file t))))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2018 ;; 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
2019 (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
2020
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2021 (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
2022 ;; Force Python mode
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2023 (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
2024 (python-mode))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2025 (goto-line line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2026 (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
2027
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2028 (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
2029 "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
2030 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
2031 (interactive "e")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2032 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2033 ((fboundp 'event-point)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2034 ;; XEmacs
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2035 (let* ((point (event-point event))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2036 (buffer (event-buffer event))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2037 (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
2038 (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
2039 (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
2040 (and info
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2041 (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
2042 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2043 ;; 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
2044 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2045
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2046 (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
2047 "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
2048 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2049 (let (file line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2050 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2051 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2052 (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
2053 (setq file (match-string 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2054 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
2055 (if (not file)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2056 (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
2057 (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
2058
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2059 (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
2060 "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
2061 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
2062 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
2063 `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
2064 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
2065 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
2066 (let (file line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2067 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2068 (set-buffer buffer)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2069 (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
2070 (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
2071 (setq file (match-string 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2072 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
2073 (if (and file line)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2074 (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
2075 (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
2076
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2077 (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
2078 "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
2079 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
2080 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
2081 stack."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2082 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2083 (let* ((proc (get-process "Python"))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2084 (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
2085 (if bottom
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2086 (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
2087 (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
2088
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2089 (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
2090 "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
2091 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
2092 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
2093 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2094 (let* ((proc (get-process "Python"))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2095 (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
2096 (if top
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2097 (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
2098 (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
2099
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2100
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2101 ;; Electric deletion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2102 (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
2103 "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
2104 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
2105 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
2106
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2107 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
2108
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2109 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
2110 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
2111 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
2112 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
2113 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
2114 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
2115 \\[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
2116 zero).
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2117
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2118 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
2119 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
2120 \\[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
2121 default is 1.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2122
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2123 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
2124 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
2125 above."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2126 (interactive "*p")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2127 (if (or (/= (current-indentation) (current-column))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2128 (bolp)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2129 (py-continuation-line-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2130 ; (not py-honor-comment-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2131 ; (looking-at "#[^ \t\n]") ; non-indenting #
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2132 )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2133 (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
2134 ;; 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
2135 ;; 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
2136 (insert-char ?* 1)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2137 (backward-char)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2138 (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
2139 (base-text "") ; and text of base line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2140 (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
2141 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2142 (while (< 0 arg)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2143 (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
2144 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2145 (py-goto-block-up 'no-mark)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2146 (setq base-indent (current-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2147 base-text (py-suck-up-leading-text)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2148 base-found-p t))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2149 (error nil))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2150 (setq arg (1- arg))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2151 (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
2152 (delete-horizontal-space)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2153 (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
2154 (if base-found-p
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2155 (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
2156
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2157
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2158 (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
2159 "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
2160
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2161 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
2162 `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
2163 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
2164 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
2165
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2166 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
2167 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
2168 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
2169
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2170 \\[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
2171 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
2172 (interactive "*p")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2173 (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
2174 (delete-forward-p))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2175 (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
2176 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
2177 (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
2178 (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
2179
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2180 ;; 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
2181 (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
2182 (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
2183 (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
2184 (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
2185 (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
2186 (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
2187
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2188
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2189
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2190 (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
2191 "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
2192 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
2193 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
2194 (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
2195
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2196 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
2197 \\[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
2198 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2199 (let* ((ci (current-indentation))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2200 (move-to-indentation-p (<= (current-column) ci))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2201 (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
2202 (cc (current-column)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2203 ;; 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
2204 ;; column 1
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2205 (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
2206 (/= cc 0))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2207 (progn
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2208 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2209 (delete-horizontal-space)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2210 (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
2211 (progn
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2212 ;; see if we need to dedent
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2213 (if (py-outdent-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2214 (setq need (- need py-indent-offset)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2215 (if (or py-tab-always-indent
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2216 move-to-indentation-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2217 (progn (if (/= ci need)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2218 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2219 (beginning-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2220 (delete-horizontal-space)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2221 (indent-to need)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2222 (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
2223 (insert-tab))))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2224
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2225 (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
2226 "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
2227 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
2228 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
2229 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
2230 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
2231 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2232 (let ((ci (current-indentation)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2233 (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
2234 (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
2235 ;; 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
2236 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2237 (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
2238 (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
2239
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2240 (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
2241 "Compute Python indentation.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2242 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
2243 `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
2244 dedenting."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2245 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2246 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2247 (let* ((bod (py-point 'bod))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2248 (pps (parse-partial-sexp bod (point)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2249 (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
2250 placeholder)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2251 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2252 ;; 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
2253 ((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
2254 (and (nth 4 pps) (nth 4 boipps)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2255 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2256 (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
2257 ;; 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
2258 ;; 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
2259 ;; 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
2260 (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
2261 (back-to-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2262 (current-column))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2263 ;; 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
2264 ((py-continuation-line-p)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2265 (let ((startpos (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2266 (open-bracket-pos (py-nesting-level))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2267 endpos searching found state cind cline)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2268 (if open-bracket-pos
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2269 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2270 (setq endpos (py-point 'bol))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2271 (py-goto-initial-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2272 (setq cind (current-indentation))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2273 (setq cline cind)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2274 (dolist (bp
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2275 (nth 9 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2276 (parse-partial-sexp (point) endpos)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2277 cind)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2278 (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
2279 (goto-char (1+ bp))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2280 (skip-chars-forward " \t")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2281 (setq cind (if (memq (following-char) '(?\n ?# ?\\))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2282 (+ cline py-indent-offset)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2283 (current-column)))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2284 ;; else on backslash continuation line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2285 (forward-line -1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2286 (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
2287 (current-indentation) ; so just continue the pattern
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2288 ;; 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
2289 ;; 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
2290 ;; 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
2291 ;; 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
2292 ;; column
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2293 (end-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2294 (setq endpos (point)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2295 searching t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2296 (back-to-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2297 (setq startpos (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2298 ;; 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
2299 ;; 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
2300 (while searching
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2301 (skip-chars-forward "^=" endpos)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2302 (if (= (point) endpos)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2303 (setq searching nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2304 (forward-char 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2305 (setq state (parse-partial-sexp startpos (point)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2306 (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
2307 (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
2308 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2309 (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
2310 (setq found
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2311 (not (or
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2312 (eq (following-char) ?=)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2313 (memq (char-after (- (point) 2))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2314 '(?< ?> ?!)))))))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2315 (if (or (not found) ; not an assignment
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2316 (looking-at "[ \t]*\\\\")) ; <=><spaces><backslash>
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2317 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2318 (goto-char startpos)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2319 (skip-chars-forward "^ \t\n")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2320 ;; 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
2321 ;; statement, add some extra offset.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2322 (+ (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
2323 py-continuation-offset 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2324 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2325 ))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2326
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2327 ;; 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
2328 ((bobp) (current-indentation))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2329
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2330 ;; 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
2331 ;; 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
2332 ;; 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
2333 ;; 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
2334 ;; 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
2335
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2336 ;; 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
2337 ;; - 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
2338 ;; - 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
2339 ;; - 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
2340 ;; 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
2341
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2342 ;; 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
2343 ;; 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
2344 ;; indenting comment line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2345
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2346 ;; 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
2347 ;; purposes.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2348
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2349 ;; 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
2350 ;; 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
2351 ;; 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
2352 ;; 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
2353 ;; below.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2354 ((and (looking-at "[ \t]*#[^ \t\n]")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2355 ;; 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
2356 (fboundp 'forward-comment)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2357 (<= (current-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2358 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2359 (forward-comment (- (point-max)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2360 (current-indentation))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2361 (current-indentation))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2362
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2363 ;; 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
2364 ;; 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
2365 ;; 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
2366 ;; 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
2367 (t
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2368 ;; 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
2369 ;; 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
2370 ;; 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
2371 ;; function if it's there.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2372 (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
2373 (fboundp 'forward-comment))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2374 (forward-comment (- (point-max)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2375 (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
2376 done)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2377 (while (not done)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2378 (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
2379 (setq done (or (bobp)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2380 (and (eq py-honor-comment-indentation t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2381 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2382 (back-to-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2383 (not (looking-at prefix-re))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2384 ))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2385 (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
2386 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2387 (back-to-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2388 (and (not (looking-at prefix-re))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2389 (or (looking-at "[^#]")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2390 (not (zerop (current-column)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2391 ))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2392 ))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2393 ))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2394 )))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2395 ;; 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
2396 ;; 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
2397 ;; strings.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2398 (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
2399 ;; now skip backward over continued lines
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2400 (setq placeholder (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2401 (py-goto-initial-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2402 ;; 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
2403 ;; this string.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2404 (py-goto-beginning-of-tqs
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2405 (save-excursion (nth 3 (parse-partial-sexp
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2406 placeholder (point)))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2407 (+ (current-indentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2408 (if (py-statement-opens-block-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2409 py-indent-offset
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2410 (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
2411 (- py-indent-offset)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2412 0)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2413 )))))
19
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 (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
2416 "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
2417
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2418 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
2419 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
2420 \\[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
2421 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
2422 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
2423 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
2424
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2425 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
2426 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
2427 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
2428 `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
2429 mess.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2430
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2431 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
2432 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
2433 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
2434 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
2435 it's tried again going backward."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2436 (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
2437 (let (new-value
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2438 (start (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2439 (restart (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2440 (found nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2441 colon-indent)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2442 (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
2443 (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
2444 (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
2445 (not (py-in-literal restart)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2446 (setq restart (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2447 (py-goto-initial-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2448 (if (py-statement-opens-block-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2449 (setq found t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2450 (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
2451 (unless found
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2452 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2453 (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
2454 (while (not (or found (bobp)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2455 (setq found (and
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2456 (re-search-backward ":[ \t]*\\($\\|[#\\]\\)" nil 'move)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2457 (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
2458 (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
2459 (setq colon-indent (current-indentation)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2460 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
2461 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
2462 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2463 (if (not found)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2464 (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
2465 (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
2466 '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
2467 (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
2468 (or noninteractive
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2469 (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
2470 (if global "Global" "Local")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2471 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
2472 ))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2473
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2474 (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
2475 "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
2476 ;; 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
2477 ;; 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
2478 ;; 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
2479 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2480 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2481 (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
2482 (and comment-start-skip
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2483 (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
2484 (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
2485 (goto-char eol)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2486 (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
2487 (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
2488 )))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2489
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2490 (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
2491 "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
2492 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
2493 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
2494 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2495 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2496 (widen)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2497 (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
2498 (let ((end (point)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2499 (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
2500 (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
2501
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2502
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2503 (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
2504 "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
2505 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2506 (goto-char end)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2507 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2508 (setq end (point))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2509 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2510 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2511 (setq start (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2512 (let (deactivate-mark)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2513 (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
2514
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2515 (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
2516 "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
2517 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
2518 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
2519 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
2520
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2521 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
2522 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
2523 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
2524 (interactive
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2525 (let ((p (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2526 (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
2527 (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
2528 (if m
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2529 (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
2530 (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
2531 ;; 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
2532 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2533 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2534 (while (< (point) end)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2535 (back-to-indentation)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2536 (if (and (zerop (current-column))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2537 (not (looking-at "\\s *$")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2538 (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
2539 (forward-line 1)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2540 (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
2541 (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
2542 (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
2543
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2544 (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
2545 "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
2546 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
2547 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
2548 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
2549
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2550 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
2551 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
2552 (interactive
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2553 (let ((p (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2554 (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
2555 (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
2556 (if m
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2557 (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
2558 (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
2559 (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
2560 (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
2561 (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
2562
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2563 (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
2564 "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
2565
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2566 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
2567 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
2568 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
2569 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
2570 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
2571 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
2572 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
2573
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2574 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
2575 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
2576 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
2577
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2578 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
2579 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
2580 used.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2581
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2582 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
2583 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
2584 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
2585 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
2586
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2587 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
2588 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
2589 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
2590
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2591 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
2592 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
2593 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
2594 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
2595 (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
2596 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2597 (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
2598 (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
2599 (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
2600 (or indent-offset py-indent-offset)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2601 (indents '(-1)) ; stack of active indent levels
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2602 (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
2603 (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
2604 (indent-base (if (looking-at "[ \t\n]")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2605 (py-compute-indentation t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2606 0))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2607 ci)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2608 (while (< (point) end)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2609 (setq ci (current-indentation))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2610 ;; figure out appropriate target column
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2611 (cond
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2612 ((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
2613 (looking-at "[ \t]*$")) ; entirely blank
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2614 (setq target-column 0))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2615 ((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
2616 (setq target-column (+ ci base-shifted-by)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2617 (t ; new base line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2618 (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
2619 (setq indents (cons ci indents))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2620 ;; 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
2621 (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
2622 (if (null indents)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2623 (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
2624 (save-restriction
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2625 (widen)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2626 (1+ (count-lines 1 (point)))))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2627 (setq target-column (+ indent-base
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2628 (* py-indent-offset
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2629 (- (length indents) 2))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2630 (setq base-shifted-by (- target-column ci))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2631 ;; shift as needed
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2632 (if (/= ci target-column)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2633 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2634 (delete-horizontal-space)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2635 (indent-to target-column)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2636 (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
2637 (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
2638
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2639 (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
2640 "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
2641 (interactive "r\nP")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2642 (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
2643 (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
2644
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2645 (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
2646 (let ((lines ())
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2647 (current-line line-prefix))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2648 (while words
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2649 (let* ((word (car words))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2650 (maybe-line (concat current-line word separator)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2651 (if (> (length maybe-line) line-length)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2652 (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
2653 current-line (concat line-prefix word separator " "))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2654 (setq current-line (concat maybe-line " "))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2655 (setq words (cdr words)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2656 (setq lines (cons (substring
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2657 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
2658 (mapconcat 'identity (nreverse lines) "\n")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2659
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2660 (defun py-sort-imports ()
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2661 "Sort multiline imports.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2662 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
2663 \\[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
2664 (interactive)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2665 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2666 (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
2667 (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
2668 sorted-imports)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2669 (goto-char (1+ open-paren))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2670 (skip-chars-forward " \n\t")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2671 (setq sorted-imports
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2672 (sort
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2673 (delete-dups
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2674 (split-string (buffer-substring
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2675 (point)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2676 (save-excursion (goto-char (1- close-paren))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2677 (skip-chars-backward " \n\t")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2678 (point)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2679 ", *\\(\n *\\)?"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2680 ;; XXX Should this sort case insensitively?
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2681 'string-lessp))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2682 ;; Remove empty strings.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2683 (delete-region open-paren close-paren)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2684 (goto-char open-paren)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2685 (insert "(\n")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2686 (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
2687 (insert ")")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2688 )))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2689
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2690
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2691
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2692 ;; 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
2693 (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
2694 "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
2695 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
2696 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
2697 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
2698 continuation lines."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2699 (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
2700 (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
2701 (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
2702 (let (start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2703 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2704 (setq start (point)) ; always true -- side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2705 (> count 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2706 (zerop (forward-line -1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2707 (py-goto-statement-at-or-above))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2708 (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
2709 (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
2710 count))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2711
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2712 (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
2713 "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
2714 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
2715 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
2716 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
2717 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
2718 (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
2719 (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
2720 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2721 (let (start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2722 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2723 (setq start (point)) ; always true -- side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2724 (> count 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2725 (py-goto-statement-below))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2726 (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
2727 (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
2728 count))
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 (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
2731 "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
2732 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
2733 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
2734 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
2735 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
2736
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2737 `\\[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
2738 block, if desired.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2739
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2740 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
2741 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
2742 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2743 (let ((start (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2744 (found nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2745 initial-indent)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2746 (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
2747 ;; 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
2748 (if (looking-at "[ \t]*\\($\\|#[^ \t\n]\\)")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2749 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2750 (py-goto-statement-at-or-above)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2751 (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
2752 ;; 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
2753 (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
2754 (if (zerop initial-indent)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2755 ;; force fast exit
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2756 (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
2757 (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
2758 (setq found
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2759 (and
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2760 (re-search-backward ":[ \t]*\\($\\|[#\\]\\)" nil 'move)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2761 (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
2762 (< (current-indentation) initial-indent)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2763 (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
2764 (if found
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2765 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2766 (or nomark (push-mark start))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2767 (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
2768 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2769 (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
2770
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2771 (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
2772 "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
2773
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2774 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
2775 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
2776 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
2777 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
2778 or `def'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2779
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2780 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
2781 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
2782
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2783 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
2784 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
2785
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2786 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
2787 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
2788 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
2789 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
2790
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2791 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
2792
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2793 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
2794 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
2795
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2796 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
2797 (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
2798 (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
2799 (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
2800 (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
2801 (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
2802 (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
2803 (class "^[ \t]*class\\>")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2804 (t "^[ \t]*def\\>")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2805 )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2806 ;; searching backward
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2807 (if (and (< 0 count)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2808 (or (/= start-of-stmt start-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2809 (not at-or-before-p)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2810 (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
2811 ;; search forward
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2812 (if (and (> 0 count)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2813 (zerop (current-column))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2814 (looking-at start-re))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2815 (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
2816 (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
2817 (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
2818
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2819 ;; Backwards compatibility
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2820 (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
2821
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2822 (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
2823 "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
2824
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2825 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
2826 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
2827 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
2828 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
2829 or `def'.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2830
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2831 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
2832 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
2833
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2834 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
2835
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2836 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
2837 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
2838
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2839 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
2840
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2841 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
2842 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
2843 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
2844
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2845 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
2846
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2847 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
2848 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
2849
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2850 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
2851 (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
2852 (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
2853 (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
2854 (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
2855 (which (cond ((eq class 'either) "\\(class\\|def\\)")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2856 (class "class")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2857 (t "def")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2858 (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
2859 ;; 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
2860 (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
2861 (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
2862 ;; 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
2863 (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
2864 (progn (py-goto-beyond-block)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2865 (> (point) start)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2866 (setq state 'at-end)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2867 ;; else search forward
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2868 (goto-char start)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2869 (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
2870 (progn (setq state 'at-beginning)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2871 (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
2872 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2873 ((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
2874 ((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
2875 ((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
2876 (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
2877
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2878 ;; Backwards compabitility
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2879 (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
2880
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2881
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2882 ;; 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
2883 (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
2884 "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
2885 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
2886 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
2887 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
2888 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
2889
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2890 - 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
2891 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
2892
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2893 - 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
2894 structures:
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 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
2897
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2898 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
2899 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
2900 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
2901 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
2902 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
2903 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
2904 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
2905 class blocks.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2906
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2907 - 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
2908 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
2909 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
2910 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
2911 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
2912 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
2913 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
2914 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
2915 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
2916
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2917 - 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
2918 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
2919 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
2920 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
2921 lines.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2922
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2923 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
2924 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
2925
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2926 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
2927 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
2928 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
2929 (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
2930 (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
2931 ;; 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
2932 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2933 (looking-at "[ \t]*$") ; while blank line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2934 (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
2935 (forward-line 1))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2936 (if (eobp)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2937 (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
2938 (let ((initial-pos (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2939 (initial-indent (current-indentation))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2940 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
2941 (followers
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2942 '((if elif else) (elif elif else) (else)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2943 (try except finally) (except except) (finally)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2944 (for else) (while else)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2945 (def) (class) ) )
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2946 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
2947
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2948 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2949 ;; 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
2950 ((looking-at "[ \t]*#")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2951 (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
2952 (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
2953 (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
2954
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2955 ;; 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
2956 ;; the whole structure
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2957 ((and extend
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2958 (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
2959 (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
2960 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2961 (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
2962 (forward-line -1) ; side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2963 (setq last-pos (point)) ; side effect
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2964 (py-goto-statement-below)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2965 (= (current-indentation) initial-indent)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2966 (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
2967 (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
2968 (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
2969
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2970 ;; 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
2971 ((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
2972 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2973 (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
2974 (py-goto-statement-below)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2975 (> (current-indentation) initial-indent)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2976 )))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2977
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2978 ;; 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
2979 ;; 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
2980 (t
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2981 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2982 (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
2983 (or (py-goto-beyond-final-line) t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2984 (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
2985 (or
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2986 (>= (current-indentation) initial-indent)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2987 (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
2988 nil)))
19
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 ;; 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
2991 (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
2992 (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
2993
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2994 ;; set mark & display
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2995 (if just-move
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
2996 () ; just return
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2997 (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
2998 (forward-line -1)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
2999 (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
3000 (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
3001
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3002 (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
3003 "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
3004 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
3005 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
3006
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3007 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
3008 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
3009 `\\[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
3010
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3011 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
3012 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
3013 `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
3014 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
3015 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
3016 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
3017 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
3018 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
3019 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
3020 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
3021 `goto' variations.
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 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
3024 `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
3025 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
3026 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
3027 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
3028 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
3029
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3030 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
3031 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
3032 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
3033 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
3034 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
3035 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
3036
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3037 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
3038 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
3039 pleasant."
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3040 (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
3041 (let ((start (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3042 (which (cond ((eq class 'either) "\\(class\\|def\\)")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3043 (class "class")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3044 (t "def"))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3045 (push-mark start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3046 (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
3047 (progn (goto-char start)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3048 (error "Enclosing %s not found"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3049 (if (eq class 'either)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3050 "def or class"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3051 which)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3052 ;; 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
3053 (setq start (point))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3054 (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
3055 (push-mark (point))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3056 (goto-char start)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3057 (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
3058 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3059 (if (looking-at "[ \t]*$") ; it's blank
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3060 (setq start (point)) ; so reset start point
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3061 (goto-char start)) ; else try again
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3062 (if (zerop (forward-line -1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3063 (if (looking-at "[ \t]*#") ; a comment
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3064 ;; look back for non-comment line
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3065 ;; 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
3066 ;; 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
3067 (and
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3068 (re-search-backward "^[ \t]*[^ \t#]" nil 'move)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3069 (forward-line 1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3070 ;; no comment, so go back
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3071 (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
3072 (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
3073 (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
3074
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3075 ;; 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
3076 (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
3077 "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
3078 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
3079 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
3080
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3081 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
3082 (interactive "p")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3083 (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
3084 (if (> arg 0)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3085 (re-search-forward
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3086 "\\(\\W\\|[_]\\)*\\([A-Z]*[a-z0-9]*\\)"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3087 (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
3088 (while (and (< arg 0)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3089 (re-search-backward
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3090 "\\(\\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
3091 (point-min) 0))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3092 (forward-char 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3093 (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
3094 (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
3095
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3096 (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
3097 "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
3098 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
3099 forward.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3100
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3101 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
3102 (interactive "p")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3103 (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
3104 (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
3105
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3106
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3107
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3108 ;; pdbtrack functions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3109 (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
3110 (interactive "P")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3111 (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
3112 (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
3113 ;; 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
3114 (if (or (not arg)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3115 (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
3116 (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
3117 (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
3118 (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
3119 (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
3120
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3121 (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
3122 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3123 (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
3124
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3125 (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
3126 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3127 (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
3128
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3129
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3130
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3131 ;; Pychecker
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3132
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3133 ;; 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
3134 (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
3135 (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
3136
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3137 (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
3138 "*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
3139 (interactive
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3140 (let ((default
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3141 (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
3142 (mapconcat 'identity py-pychecker-command-args " ")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3143 (buffer-file-name)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3144 (last (when py-pychecker-history
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3145 (let* ((lastcmd (car py-pychecker-history))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3146 (cmd (cdr (reverse (split-string lastcmd))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3147 (newcmd (reverse (cons (buffer-file-name) cmd))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3148 (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
3149
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3150 (list
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3151 (if (fboundp 'read-shell-command)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3152 (read-shell-command "Run pychecker like this: "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3153 (if last
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3154 last
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3155 default)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3156 'py-pychecker-history)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3157 (read-string "Run pychecker like this: "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3158 (if last
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3159 last
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3160 default)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3161 'py-pychecker-history))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3162 )))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3163 (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
3164 (if (fboundp 'compilation-start)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3165 ;; Emacs.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3166 (compilation-start command)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3167 ;; XEmacs.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3168 (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
3169
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
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3172 ;; 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
3173 ;; 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
3174 ;; 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
3175 ;; 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
3176 ;; 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
3177 ;; function.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3178 (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
3179 "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
3180 ;; 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
3181 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3182 (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
3183 (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
3184 (while (not (looking-at "\\sw\\|\\s_\\|\\'"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3185 (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
3186 (while (looking-at "\\sw\\|\\s_")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3187 (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
3188 (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
3189 (progn (forward-char 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3190 (buffer-substring (point)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3191 (progn (forward-sexp -1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3192 (while (looking-at "\\s'")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3193 (forward-char 1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3194 (point))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3195 nil))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3196
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3197 (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
3198 "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
3199 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3200 (let* ((sym (py-symbol-near-point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3201 (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
3202 cmd)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3203 (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
3204 (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
3205 (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
3206 cmd
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3207 "try: pydoc.help('" sym "')\n"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3208 "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
3209 (message cmd)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3210 (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
3211 (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
3212 ;; 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
3213 (help-mode)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3214
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
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3217 ;; Documentation functions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3218
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3219 ;; 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
3220 ;; 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
3221 ;; 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
3222 ;; values
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3223 (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
3224 (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
3225 (let ((locals (buffer-local-variables))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3226 funckind funcname func funcdoc
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3227 (start 0) mstart end
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3228 keys )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3229 (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
3230 (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
3231 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
3232 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
3233 func (intern funcname))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3234 (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
3235 (cond
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3236 ((equal funckind "c") ; command
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3237 (setq funcdoc (documentation func)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3238 keys (concat
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3239 "Key(s): "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3240 (mapconcat 'key-description
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3241 (where-is-internal func py-mode-map)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3242 ", "))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3243 ((equal funckind "v") ; variable
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3244 (setq funcdoc (documentation-property func 'variable-documentation)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3245 keys (if (assq func locals)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3246 (concat
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3247 "Local/Global values: "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3248 (prin1-to-string (symbol-value func))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3249 " / "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3250 (prin1-to-string (default-value func)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3251 (concat
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3252 "Value: "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3253 (prin1-to-string (symbol-value func))))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3254 (t ; unexpected
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3255 (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
3256 (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
3257 (if (equal funckind "c") "Command" "Variable")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3258 funcname keys))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3259 (princ funcdoc)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3260 (terpri)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3261 (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
3262 (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
3263 (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
3264
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3265 (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
3266 "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
3267 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3268 (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
3269 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
3270 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
3271
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3272 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
3273 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
3274
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3275 @EXECUTING PYTHON CODE
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3276
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3277 \\[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
3278 \\[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
3279 \\[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
3280 \\[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
3281 \\[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
3282 \\[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
3283 \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
3284 %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
3285 %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
3286 %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
3287 %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
3288 %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
3289 %c:py-shell
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3290
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3291 @VARIABLES
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3292
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3293 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
3294 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
3295
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3296 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
3297 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
3298
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3299 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
3300 %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
3301 %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
3302 %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
3303 %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
3304 %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
3305
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3306 @KINDS OF LINES
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 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
3309 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
3310 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
3311 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
3312
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3313 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
3314 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
3315 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
3316
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3317 Comment Lines
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3318
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3319 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
3320 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
3321
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3322 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
3323 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
3324 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
3325 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
3326 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
3327 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
3328 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
3329
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3330 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
3331 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
3332 like these:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3333
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3334 \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
3335 \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
3336
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3337 \tif a == b:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3338 ##\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
3339 \t\treturn a
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3340
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3341 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
3342 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
3343 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
3344
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3345 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
3346
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3347 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
3348 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
3349 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
3350 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
3351 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
3352 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
3353 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
3354
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3355
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3356 @INDENTATION
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3357
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3358 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
3359 \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
3360 \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
3361 \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
3362
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3363 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
3364 \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
3365 \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
3366
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3367 \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
3368 \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
3369 \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
3370
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3371 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
3372 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
3373 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
3374 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
3375 indentation.
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 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
3378 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
3379 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
3380 \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
3381 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
3382 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
3383 the cursor):
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3384 \tif a > 0:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3385 \t _
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3386 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
3387 to
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3388 \tif a > 0:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3389 \t c = d
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3390 \t _
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3391 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
3392 \tif a > 0:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3393 \t c = d
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3394 \t_
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3395 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
3396 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
3397 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
3398 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
3399 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
3400 \\[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
3401
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3402 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
3403 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
3404 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
3405
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3406 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
3407 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
3408 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
3409 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
3410 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
3411 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
3412 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
3413
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3414 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
3415 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
3416 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
3417 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
3418 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
3419 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
3420 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
3421 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
3422 the base line.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3423
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3424 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
3425 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
3426 structure you intend.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3427 %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
3428 %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
3429 %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
3430
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3431
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3432 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
3433 %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
3434
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3435
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3436 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
3437 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
3438 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
3439 the block structure:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3440 %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
3441 %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
3442 %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
3443
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3444 @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
3445
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3446 \\[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
3447 \\[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
3448 \\[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
3449 \\[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
3450 \\[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
3451 %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
3452 %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
3453 %c:comment-region
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3454
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3455 @MOVING POINT
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3456
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3457 \\[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
3458 \\[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
3459 \\[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
3460 \\[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
3461 \\[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
3462 \\[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
3463 \\[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
3464
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3465 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
3466 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
3467 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
3468 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
3469 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
3470 \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
3471 \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
3472 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
3473 %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
3474 %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
3475 %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
3476 %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
3477 %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
3478
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3479 @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
3480
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3481 `\\[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
3482
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3483 `\\[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
3484 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
3485
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3486 `\\[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
3487
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3488 `\\[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
3489
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3490 @OTHER EMACS HINTS
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3491
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3492 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
3493 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
3494 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
3495 .emacs:
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3496 \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
3497 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
3498 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
3499
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3500 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
3501 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
3502 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
3503 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
3504 then release CONTROL.
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 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
3507 `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
3508 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
3509 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
3510
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3511 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
3512 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
3513 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
3514
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3515 (require 'info-look)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3516 ;; 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
3517 ;; 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
3518 (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
3519 (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
3520 :mode 'python-mode
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3521 :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
3522 :doc-spec '(("(python-lib)Module Index")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3523 ("(python-lib)Class-Exception-Object Index")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3524 ("(python-lib)Function-Method-Variable Index")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3525 ("(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
3526 )
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3527
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 ;; Helper functions
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3530 (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
3531 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3532 "^[ \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
3533 "\\|"
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3534 "^[^ #\t\n]"))
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 (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
3537 "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
3538 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3539 (let ((here (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3540 pps done)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3541 (while (not done)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3542 ;; 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
3543 ;; 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
3544 ;; 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
3545 ;; 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
3546 ;; 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
3547 ;; 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
3548 (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
3549 (beginning-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3550 ;; 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
3551 ;; 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
3552 ;; 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
3553 ;; 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
3554 ;; no accurate way to determine this otherwise.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3555 (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
3556 ;; 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
3557 (setq done (or (not (nth 3 pps))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3558 (bobp)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3559 ;; 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
3560 ;; 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
3561 ;; nearly as slow as looping through many
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3562 ;; re-search-backwards.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3563 (if (not done)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3564 (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
3565 pps)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3566
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3567 (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
3568 "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
3569 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
3570 (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
3571 (if (zerop (car status))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3572 nil ; not in a nest
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3573 (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
3574
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3575 (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
3576 "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
3577 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3578 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3579 (and
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3580 ;; 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
3581 ;; 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
3582 (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
3583 ;; 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
3584 (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
3585 (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
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-continuation-line-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 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
3589 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3590 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3591 (or (py-backslash-continuation-line-p)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3592 (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
3593
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3594 (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
3595 "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
3596 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
3597 for."
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3598 (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
3599 (continue t))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3600 (when skip
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3601 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3602 (while continue
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3603 (py-safe (search-backward skip))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3604 (setq continue (and (not (bobp))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3605 (= (char-before) ?\\))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3606 (if (and (= (char-before) delim)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3607 (= (char-before (1- (point))) delim))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3608 (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
3609 ;; 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
3610 (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
3611
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3612 (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
3613 "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
3614 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
3615 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
3616 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
3617 ;; 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
3618 ;; 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
3619 ;; 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
3620 ;; 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
3621 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3622 ;; 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
3623 ;; 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
3624 (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
3625 (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
3626 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3627 (if (py-backslash-continuation-line-p)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3628 (while (py-backslash-continuation-line-p)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3629 (forward-line -1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3630 ;; 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
3631 (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
3632 (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
3633 (beginning-of-line))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3634
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3635 (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
3636 "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
3637 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
3638 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
3639 ;; 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
3640 ;; behavior.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3641 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3642 ;; 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
3643 ;; strings
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3644 (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
3645 (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
3646 ;;
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3647 (forward-line 1)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3648 (let (state)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3649 (while (and (py-continuation-line-p)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3650 (not (eobp)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3651 ;; 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
3652 (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
3653 (not (eobp)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3654 (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
3655 ;; 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
3656 (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
3657 (if (and (not (zerop (car state)))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3658 (not (eobp)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3659 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3660 (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
3661 (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
3662
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3663 (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
3664 "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
3665 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
3666 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
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 (let ((start (point))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3669 (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
3670 (searching t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3671 (answer nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3672 state)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3673 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3674 (while searching
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3675 ;; 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
3676 ;; maybe a comment
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3677 (if (re-search-forward ":\\([ \t]\\|\\\\\n\\)*\\(#.*\\)?$"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3678 finish t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3679 (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
3680 ; keep searching if we're not at
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3681 ; the end yet
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3682 ;; 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
3683 ;; be in a comment
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3684 (progn
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3685 (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
3686 (setq state (parse-partial-sexp start
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3687 (match-beginning 0)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3688 (setq answer (not (nth 4 state)))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3689 ;; 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
3690 (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
3691 answer)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3692
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3693 (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
3694 "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
3695 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
3696 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
3697 (let ((here (point)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3698 (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
3699 (back-to-indentation)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3700 (prog1
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3701 (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
3702 (goto-char here))))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3703
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3704 (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
3705 "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
3706 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
3707 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
3708 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
3709 (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
3710 (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
3711 (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
3712
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3713 (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
3714 "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
3715 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
3716 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
3717 (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
3718 (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
3719 ;; 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
3720 ;; 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
3721 ;; 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
3722 (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
3723 (progn (py-goto-initial-line) t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3724 nil)
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3725 t))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3726
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3727 (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
3728 "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
3729 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
3730 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
3731 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3732 (let ((start (point)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3733 (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
3734 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3735 (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
3736 (py-in-literal))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3737 (not (eobp)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3738 (forward-line 1))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3739 (if (eobp)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3740 (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
3741 t)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3742
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3743 (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
3744 "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
3745
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3746 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
3747 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
3748 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
3749 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
3750 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
3751 ;; 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
3752 (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
3753 (while (and
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3754 (looking-at "[ \t]*\\($\\|#[^ \t\n]\\)")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3755 (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
3756 nil)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3757 (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
3758 (let* ((re (concat "[ \t]*" key "\\>"))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3759 (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
3760 (found (looking-at re))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3761 (dead nil))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3762 (while (not (or found dead))
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3763 (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
3764 (py-goto-block-up 'no-mark)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3765 (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
3766 (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
3767 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3768 found))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3769
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3770 (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
3771 "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
3772 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
3773 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3774 (back-to-indentation)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3775 (concat
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3776 (if (bolp) "" "...")
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3777 (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
3778
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3779 (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
3780 "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
3781 `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
3782 ([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
3783 (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
3784 (if (looking-at "[ \t]*\\([a-z]+\\)\\>")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3785 (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
3786 nil)))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3787
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3788 (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
3789 "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
3790 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
3791 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3792
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3793 ;; 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
3794
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3795 (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
3796 (back-to-indentation)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3797 (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
3798 (py-in-literal))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3799 (not (bobp)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3800 (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
3801 (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
3802
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3803 (let ((scopes "")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3804 (sep "")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3805 dead assignment)
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 ;; 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
3808 ;; 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
3809 ;; 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
3810
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3811 (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
3812 (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
3813 (setq assignment t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3814 (setq sep "."))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3815
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3816 ;; 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
3817
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3818 (while (not dead)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3819 (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
3820 (looking-at
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3821 "[ \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
3822 (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
3823 (if (and assignment (looking-at "[ \t]*def"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3824 (setq scopes name)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3825 (setq scopes (concat name sep scopes))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3826 (setq sep "."))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3827 (setq assignment nil)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3828 (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
3829 (py-goto-block-up 'no-mark)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3830 (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
3831 (if (string= scopes "")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3832 nil
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3833 scopes))))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3834
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3835
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3836
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3837 (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
3838 "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
3839
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3840 (defun py-version ()
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3841 "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
3842 (interactive)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3843 (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
3844 (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
3845
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3846 ;; 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
3847 ;(eval-when-compile
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3848 ; (require 'reporter))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3849
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3850 (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
3851 "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
3852 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
3853 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
3854 (interactive
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3855 (list (not (y-or-n-p
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3856 "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
3857 (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
3858 "(Very) brief summary: "
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3859 t)))
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3860 (require 'reporter)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3861 (reporter-submit-bug-report
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3862 py-help-address ;address
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3863 (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
3864 ;; varlist
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3865 (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
3866 '(py-python-command
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3867 py-indent-offset
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3868 py-block-comment-prefix
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3869 py-temp-directory
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3870 py-beep-if-tab-change))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3871 nil ;pre-hooks
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3872 nil ;post-hooks
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3873 "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
3874 (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
3875 (set-mark (point))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3876 (insert
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3877 "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
3878 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
3879 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
3880 (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
3881 (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
3882
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3883
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3884 (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
3885 "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
3886 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
3887 (mapc #'(lambda (filename)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3888 (py-safe (delete-file filename)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3889 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
3890
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3891 ;; 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
3892 (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
3893 (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
3894
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3895 ;; 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
3896 (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
3897 (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
3898 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
3899
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3900
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3901
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3902 ;;; 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
3903 ;;; 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
3904
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3905 (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
3906 "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
3907 (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
3908 has-comment
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3909
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3910 ;; 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
3911 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
3912
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3913 ;; 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
3914 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3915 (beginning-of-line)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3916 (cond
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3917 ;; 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
3918 ((looking-at "[ \t]*#[# \t]*")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3919 (setq has-comment t
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3920 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
3921 (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
3922
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3923 ;; 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
3924 ;; 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
3925 ((progn
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3926 (while (not (looking-at "#\\|$"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3927 (skip-chars-forward "^#\n\"'\\")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3928 (cond
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3929 ((eq (char-after (point)) ?\\) (forward-char 2))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3930 ((memq (char-after (point)) '(?\" ?')) (forward-sexp 1))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3931 (looking-at "#+[\t ]*"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3932 (setq has-comment t)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3933 (setq comment-fill-prefix
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3934 (concat (make-string (current-column) ? )
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3935 (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
3936
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3937 (if (not has-comment)
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3938 (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
3939
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3940 ;; 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
3941 (save-restriction
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3942 (narrow-to-region
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3943
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3944 ;; 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
3945 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3946 (while (and (zerop (forward-line -1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3947 (looking-at "^[ \t]*#")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3948
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3949 ;; 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
3950 (or (looking-at "^[ \t]*#")
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3951 (forward-line 1))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3952 (point))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3953
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3954 ;; 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
3955 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3956 (while (progn (forward-line 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3957 (looking-at "^[ \t]*#")))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3958 (point)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3959
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3960 ;; 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
3961 (let ((paragraph-start (concat paragraph-start "\\|[ \t#]*$"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3962 (paragraph-separate (concat paragraph-separate "\\|[ \t#]*$"))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3963 (fill-prefix comment-fill-prefix))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3964 ;;(message "paragraph-start %S paragraph-separate %S"
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3965 ;;paragraph-start paragraph-separate)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3966 (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
3967 t))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3968
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3969
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3970 (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
3971 "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
3972 ;; 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
3973 ;; implementation
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3974 (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
3975 string-start
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3976 ;; the end of the string's contents
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3977 string-end
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3978 ;; length of the string's delimiter
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3979 delim-length
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3980 ;; The string delimiter
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3981 delim
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3982 )
19
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3983
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3984 (save-excursion
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3985 (goto-char start)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3986 (if (looking-at "\\('''\\|\"\"\"\\|'\\|\"\\)\\\\?\n?")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3987 (setq string-start (match-end 0)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3988 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
3989 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
3990 (match-end 1)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3991 (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
3992
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
3993 ;; 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
3994 ;; 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
3995 ;; 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
3996 (save-excursion
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3997 (beginning-of-line)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3998 (and (/= (char-before string-start) ?\n)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
3999 (looking-at (concat "[ \t]*" delim))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4000 (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
4001
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4002 (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
4003
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4004 ;; 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
4005 ;; 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
4006 ;; (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
4007 ;; 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
4008 ;; 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
4009 (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
4010
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4011 ;; 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
4012 (save-restriction
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4013 (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
4014 (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
4015 (fill-paragraph justify)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4016 (if (and (not ends-with-newline)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4017 (= (char-before (point-max)) ?\n))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4018 ;; 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
4019 ;; newline at the end. Remove it again.
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4020 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4021 (goto-char (point-max))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4022 (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
4023
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4024 ;; 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
4025 t))
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4026
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4027 (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
4028 "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
4029 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
4030 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
4031 and initial `#'s.
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4032 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
4033 "
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4034 (interactive "P")
174
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4035 ;; fill-paragraph will narrow incorrectly
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4036 (save-restriction
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4037 (widen)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4038 (let* ((bod (py-point 'bod))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4039 (pps (parse-partial-sexp bod (point))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4040 (cond
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4041 ;; 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
4042 ;; the comment start?
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4043 ((or (nth 4 pps)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4044 (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
4045 (py-fill-comment justify))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4046 ;; are we inside a string?
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4047 ((nth 3 pps)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4048 (py-fill-string (nth 8 pps)))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4049 ;; 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
4050 ((save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4051 (forward-word 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4052 (eq (py-in-literal) 'string))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4053 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4054 (py-fill-string (py-point 'boi))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4055 ;; 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
4056 ((save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4057 (backward-word 1)
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4058 (eq (py-in-literal) 'string))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4059 (save-excursion
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4060 (py-fill-string (py-point 'boi))))
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4061 ;; otherwise use the default
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4062 (t
014e745b2d04 python-mode: updating to current bzr version
Augie Fackler <durin42@gmail.com>
parents: 19
diff changeset
4063 (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
4064
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4065
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4066
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4067 (provide 'python-mode)
b5d75594b356 Add support for the ipython-mode stuff and remove vestigial pymacs code.
Augie Fackler <durin42@gmail.com>
parents:
diff changeset
4068 ;;; python-mode.el ends here