annotate Misc/python-mode-old.el @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents dd709ed82262
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1 ;;; python-mode.el --- Major mode for editing Python programs
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
3 ;; Copyright (C) 1992,1993,1994 Tim Peters
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
4
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
5 ;; Author: 1995-1996 Barry A. Warsaw
3020
c7671c36c725 changes by Barry, e.g. font lock & email addresses
Guido van Rossum <guido@python.org>
parents: 2590
diff changeset
6 ;; 1992-1994 Tim Peters
c7671c36c725 changes by Barry, e.g. font lock & email addresses
Guido van Rossum <guido@python.org>
parents: 2590
diff changeset
7 ;; Maintainer: python-mode@python.org
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2525
diff changeset
8 ;; Created: Feb 1992
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
9 ;; Version: 2.83
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
10 ;; Last Modified: 1996/10/23 20:44:59
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
11 ;; Keywords: python languages oop
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
12
2526
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2525
diff changeset
13 ;; This software is provided as-is, without express or implied
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2525
diff changeset
14 ;; warranty. Permission to use, copy, modify, distribute or sell this
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2525
diff changeset
15 ;; software, without fee, for any purpose and by any individual or
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2525
diff changeset
16 ;; organization, is hereby granted, provided that the above copyright
d1123b10cf23 removed GPL mumbo jumbo
Guido van Rossum <guido@python.org>
parents: 2525
diff changeset
17 ;; notice and this paragraph appear in all copies.
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
18
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
19 ;;; Commentary:
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
20
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
21 ;; This is a major mode for editing Python programs. It was developed
4070
19412305d335 Barry's 2.73
Guido van Rossum <guido@python.org>
parents: 4067
diff changeset
22 ;; by Tim Peters after an original idea by Michael A. Guravage. Tim
19412305d335 Barry's 2.73
Guido van Rossum <guido@python.org>
parents: 4067
diff changeset
23 ;; subsequently left the net; in 1995, Barry Warsaw inherited the
19412305d335 Barry's 2.73
Guido van Rossum <guido@python.org>
parents: 4067
diff changeset
24 ;; mode and is the current maintainer.
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
25
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
26 ;; At some point this mode will undergo a rewrite to bring it more in
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
27 ;; line with GNU Emacs Lisp coding standards, and to wax all the Emacs
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
28 ;; 18 support. But all in all, the mode works exceedingly well, and
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
29 ;; I've simply been tweaking it as I go along. Ain't it wonderful
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
30 ;; that Python has a much more sane syntax than C? (or <shudder> C++?!
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
31 ;; :-). I can say that; I maintain cc-mode!
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
32
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
33 ;; The following statements, placed in your .emacs file or
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
34 ;; site-init.el, will cause this file to be autoloaded, and
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
35 ;; python-mode invoked, when visiting .py files (assuming this file is
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
36 ;; in your load-path):
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 ;;
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
38 ;; (autoload 'python-mode "python-mode" "Python editing mode." t)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 ;; (setq auto-mode-alist
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 ;; (cons '("\\.py$" . python-mode) auto-mode-alist))
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
41 ;;
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
42 ;; If you want font-lock support for Python source code (a.k.a. syntax
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
43 ;; coloring, highlighting), add this to your .emacs file:
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
44 ;;
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
45 ;; (add-hook 'python-mode-hook 'turn-on-font-lock)
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
46 ;;
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
47 ;; But you better be sure you're version of Emacs supports
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
48 ;; font-lock-mode! As of this writing, the latest Emacs and XEmacs
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
49 ;; 19's do.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
50
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
51 ;; Here's a brief list of recent additions/improvements/changes:
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
52 ;;
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
53 ;; - Wrapping and indentation within triple quote strings now works.
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
54 ;; - `Standard' bug reporting mechanism (use C-c C-b)
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
55 ;; - py-mark-block was moved to C-c C-m
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
56 ;; - C-c C-v shows you the python-mode version
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
57 ;; - a basic python-font-lock-keywords has been added for (X)Emacs 19
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
58 ;; - proper interaction with pending-del and del-sel modes.
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
59 ;; - Better support for outdenting: py-electric-colon (:) and
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
60 ;; py-indent-line (TAB) improvements; one level of outdentation
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
61 ;; added after a return, raise, break, pass, or continue statement.
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
62 ;; Defeated by prefixing command with C-u.
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
63 ;; - New py-electric-colon (:) command for improved outdenting Also
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
64 ;; py-indent-line (TAB) should handle outdented lines better
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
65 ;; - improved (I think) C-c > and C-c <
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
66 ;; - py-(forward|backward)-into-nomenclature, not bound, but useful on
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
67 ;; M-f and M-b respectively.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
68 ;; - integration with imenu by Perry A. Stoll <stoll@atr-sw.atr.co.jp>
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
69 ;; - py-indent-offset now defaults to 4
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
70 ;; - new variable py-honor-comment-indentation
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
71 ;; - comment-region bound to C-c #
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
72 ;; - py-delete-char obeys numeric arguments
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
73 ;; - Small modification to rule for "indenting comment lines", such
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
74 ;; lines must now also be indented less than or equal to the
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
75 ;; indentation of the previous statement.
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
76
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
77 ;; Here's a brief to do list:
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
78 ;;
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
79 ;; - Better integration with gud-mode for debugging.
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
80 ;; - Rewrite according to GNU Emacs Lisp standards.
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
81 ;; - possibly force indent-tabs-mode == nil, and add a
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
82 ;; write-file-hooks that runs untabify on the whole buffer (to work
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
83 ;; around potential tab/space mismatch problems). In practice this
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
84 ;; hasn't been a problem... yet.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
85 ;; - have py-execute-region on indented code act as if the region is
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
86 ;; left justified. Avoids syntax errors.
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
87 ;; - Add a py-goto-error or some such that would scan an exception in
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
88 ;; the py-shell buffer, and pop you to that line in the file.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
89
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
90 ;; If you can think of more things you'd like to see, drop me a line.
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
91 ;; If you want to report bugs, use py-submit-bug-report (C-c C-b).
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
92 ;;
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
93 ;; Note that I only test things on XEmacs 19 and to some degree on
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
94 ;; Emacs 19. If you port stuff to FSF Emacs 19, or Emacs 18, please
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
95 ;; send me your patches. Byte compiler complaints can probably be
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
96 ;; safely ignored.
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
97
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
98 ;;; Code:
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
99
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
100
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
101 ;; user definable variables
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
102 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 (defvar py-python-command "python"
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
105 "*Shell command used to start Python interpreter.")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
106
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
107 (defvar py-indent-offset 4
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 "*Indentation increment.
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
109 Note that `\\[py-guess-indent-offset]' can usually guess a good value
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
110 when you're editing someone else's Python code.")
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
111
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
112 (defvar py-align-multiline-strings-p t
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
113 "*Flag describing how multiline triple quoted strings are aligned.
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
114 When this flag is non-nil, continuation lines are lined up under the
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
115 preceding line's indentation. When this flag is nil, continuation
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
116 lines are aligned to column zero.")
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
117
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
118 (defvar py-block-comment-prefix "## "
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
119 "*String used by \\[comment-region] to comment out a block of code.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 This should follow the convention for non-indenting comment lines so
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 that the indentation commands won't get confused (i.e., the string
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 should be of the form `#x...' where `x' is not a blank or a tab, and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
123 `...' is arbitrary).")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
124
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
125 (defvar py-honor-comment-indentation t
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
126 "*Controls how comment lines influence subsequent indentation.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
127
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
128 When nil, all comment lines are skipped for indentation purposes, and
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
129 in Emacs 19, a faster algorithm is used.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
130
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
131 When t, lines that begin with a single `#' are a hint to subsequent
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
132 line indentation. If the previous line is such a comment line (as
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
133 opposed to one that starts with `py-block-comment-prefix'), then it's
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
134 indentation is used as a hint for this line's indentation. Lines that
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
135 begin with `py-block-comment-prefix' are ignored for indentation
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
136 purposes.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
137
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
138 When not nil or t, comment lines that begin with a `#' are used as
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
139 indentation hints, unless the comment character is in column zero.")
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
140
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
141 (defvar py-scroll-process-buffer t
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
142 "*Scroll Python process buffer as output arrives.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
143 If nil, the Python process buffer acts, with respect to scrolling, like
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
144 Shell-mode buffers normally act. This is surprisingly complicated and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
145 so won't be explained here; in fact, you can't get the whole story
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
146 without studying the Emacs C code.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
147
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
148 If non-nil, the behavior is different in two respects (which are
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
149 slightly inaccurate in the interest of brevity):
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
150
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
151 - If the buffer is in a window, and you left point at its end, the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
152 window will scroll as new output arrives, and point will move to the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
153 buffer's end, even if the window is not the selected window (that
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
154 being the one the cursor is in). The usual behavior for shell-mode
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
155 windows is not to scroll, and to leave point where it was, if the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 buffer is in a window other than the selected window.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
157
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 - If the buffer is not visible in any window, and you left point at
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 its end, the buffer will be popped into a window as soon as more
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 output arrives. This is handy if you have a long-running
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 computation and don't want to tie up screen area waiting for the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 output. The usual behavior for a shell-mode buffer is to stay
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
163 invisible until you explicitly visit it.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
164
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
165 Note the `and if you left point at its end' clauses in both of the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
166 above: you can `turn off' the special behaviors while output is in
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
167 progress, by visiting the Python buffer and moving point to anywhere
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
168 besides the end. Then the buffer won't scroll, point will remain where
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 you leave it, and if you hide the buffer it will stay hidden until you
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 visit it again. You can enable and disable the special behaviors as
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
171 often as you like, while output is in progress, by (respectively) moving
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
172 point to, or away from, the end of the buffer.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
173
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
174 Warning: If you expect a large amount of output, you'll probably be
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
175 happier setting this option to nil.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
176
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
177 Obscure: `End of buffer' above should really say `at or beyond the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
178 process mark', but if you know what that means you didn't need to be
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
179 told <grin>.")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
180
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
181 (defvar py-temp-directory
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
182 (let ((ok '(lambda (x)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
183 (and x
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
184 (setq x (expand-file-name x)) ; always true
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
185 (file-directory-p x)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
186 (file-writable-p x)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
187 x))))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
188 (or (funcall ok (getenv "TMPDIR"))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
189 (funcall ok "/usr/tmp")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
190 (funcall ok "/tmp")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
191 (funcall ok ".")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
192 (error
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
193 "Couldn't find a usable temp directory -- set py-temp-directory")))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
194 "*Directory used for temp files created by a *Python* process.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
195 By default, the first directory from this list that exists and that you
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
196 can write into: the value (if any) of the environment variable TMPDIR,
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
197 /usr/tmp, /tmp, or the current directory.")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
198
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
199 (defvar py-beep-if-tab-change t
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
200 "*Ring the bell if tab-width is changed.
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
201 If a comment of the form
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
202
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
203 \t# vi:set tabsize=<number>:
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
204
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
205 is found before the first code line when the file is entered, and the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
206 current value of (the general Emacs variable) `tab-width' does not
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
207 equal <number>, `tab-width' is set to <number>, a message saying so is
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
208 displayed in the echo area, and if `py-beep-if-tab-change' is non-nil
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
209 the Emacs bell is also rung as a warning.")
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
210
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
211 (defconst python-font-lock-keywords
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
212 (let* ((keywords '("and" "break" "class"
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
213 "continue" "def" "del" "elif"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
214 "else:" "except" "except:" "exec"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
215 "finally:" "for" "from" "global"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
216 "if" "import" "in" "is"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
217 "lambda" "not" "or" "pass"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
218 "print" "raise" "return" "try:"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
219 "while"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
220 ))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
221 (kwregex (mapconcat 'identity keywords "\\|")))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
222 (list
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
223 ;; keywords not at beginning of line
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
224 (cons (concat "\\s-\\(" kwregex "\\)[ \n\t(]") 1)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
225 ;; keywords at beginning of line. i don't think regexps are
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
226 ;; powerful enough to handle these two cases in one regexp.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
227 ;; prove me wrong!
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
228 (cons (concat "^\\(" kwregex "\\)[ \n\t(]") 1)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
229 ;; classes
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
230 '("\\bclass[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
231 1 font-lock-type-face)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
232 ;; functions
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
233 '("\\bdef[ \t]+\\([a-zA-Z_]+[a-zA-Z0-9_]*\\)"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
234 1 font-lock-function-name-face)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
235 ))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
236 "Additional expressions to highlight in Python mode.")
3020
c7671c36c725 changes by Barry, e.g. font lock & email addresses
Guido van Rossum <guido@python.org>
parents: 2590
diff changeset
237
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
238 (defvar imenu-example--python-show-method-args-p nil
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
239 "*Controls echoing of arguments of functions & methods in the imenu buffer.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
240 When non-nil, arguments are printed.")
3020
c7671c36c725 changes by Barry, e.g. font lock & email addresses
Guido van Rossum <guido@python.org>
parents: 2590
diff changeset
241
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
242
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
243
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
244 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
245 ;; NO USER DEFINABLE VARIABLES BEYOND THIS POINT
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
246
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
247 (make-variable-buffer-local 'py-indent-offset)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
248
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
249 ;; Differentiate between Emacs 18, Lucid Emacs, and Emacs 19. This
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
250 ;; seems to be the standard way of checking this.
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
251 ;; BAW - This is *not* the right solution. When at all possible,
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
252 ;; instead of testing for the version of Emacs, use feature tests.
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
253
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
254 (setq py-this-is-lucid-emacs-p (string-match "Lucid\\|XEmacs" emacs-version))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
255 (setq py-this-is-emacs-19-p
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
256 (and
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
257 (not py-this-is-lucid-emacs-p)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
258 (string-match "^19\\." emacs-version)))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
259
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
260 ;; have to bind py-file-queue before installing the kill-emacs hook
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
261 (defvar py-file-queue nil
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
262 "Queue of Python temp files awaiting execution.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
263 Currently-active file is at the head of the list.")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
264
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
265 ;; define a mode-specific abbrev table for those who use such things
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
266 (defvar python-mode-abbrev-table nil
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
267 "Abbrev table in use in `python-mode' buffers.")
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
268 (define-abbrev-table 'python-mode-abbrev-table nil)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
269
2010
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
270 (defvar python-mode-hook nil
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
271 "*Hook called by `python-mode'.")
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
272
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
273 ;; in previous version of python-mode.el, the hook was incorrectly
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
274 ;; called py-mode-hook, and was not defvar'd. deprecate its use.
2010
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
275 (and (fboundp 'make-obsolete-variable)
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
276 (make-obsolete-variable 'py-mode-hook 'python-mode-hook))
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
277
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
278 (defvar py-mode-map ()
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
279 "Keymap used in `python-mode' buffers.")
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
280
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
281 (if py-mode-map
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
282 ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
283 (setq py-mode-map (make-sparse-keymap))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
284
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
285 ;; shadow global bindings for newline-and-indent w/ the py- version.
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
286 ;; BAW - this is extremely bad form, but I'm not going to change it
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
287 ;; for now.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
288 (mapcar (function (lambda (key)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
289 (define-key
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
290 py-mode-map key 'py-newline-and-indent)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
291 (where-is-internal 'newline-and-indent))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
292
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
293 ;; BAW - you could do it this way, but its not considered proper
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
294 ;; major-mode form.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
295 (mapcar (function
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
296 (lambda (x)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
297 (define-key py-mode-map (car x) (cdr x))))
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
298 '((":" . py-electric-colon)
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
299 ("\C-c\C-c" . py-execute-buffer)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
300 ("\C-c|" . py-execute-region)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
301 ("\C-c!" . py-shell)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
302 ("\177" . py-delete-char)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
303 ("\n" . py-newline-and-indent)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
304 ("\C-c:" . py-guess-indent-offset)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
305 ("\C-c\t" . py-indent-region)
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
306 ("\C-c\C-l" . py-shift-region-left)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
307 ("\C-c\C-r" . py-shift-region-right)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
308 ("\C-c<" . py-shift-region-left)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
309 ("\C-c>" . py-shift-region-right)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
310 ("\C-c\C-n" . py-next-statement)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
311 ("\C-c\C-p" . py-previous-statement)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
312 ("\C-c\C-u" . py-goto-block-up)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
313 ("\C-c\C-m" . py-mark-block)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
314 ("\C-c#" . py-comment-region)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
315 ("\C-c?" . py-describe-mode)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
316 ("\C-c\C-hm" . py-describe-mode)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
317 ("\e\C-a" . beginning-of-python-def-or-class)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
318 ("\e\C-e" . end-of-python-def-or-class)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
319 ( "\e\C-h" . mark-python-def-or-class)))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
320 ;; should do all keybindings this way
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
321 (define-key py-mode-map "\C-c\C-b" 'py-submit-bug-report)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
322 (define-key py-mode-map "\C-c\C-v" 'py-version)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
323 )
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
324
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
325 (defvar py-mode-syntax-table nil
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
326 "Syntax table used in `python-mode' buffers.")
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
327
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
328 (if py-mode-syntax-table
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
329 ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
330 (setq py-mode-syntax-table (make-syntax-table))
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
331 ;; BAW - again, blech.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
332 (mapcar (function
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
333 (lambda (x) (modify-syntax-entry
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
334 (car x) (cdr x) py-mode-syntax-table)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
335 '(( ?\( . "()" ) ( ?\) . ")(" )
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
336 ( ?\[ . "(]" ) ( ?\] . ")[" )
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
337 ( ?\{ . "(}" ) ( ?\} . "){" )
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
338 ;; fix operator symbols misassigned in the std table
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
339 ( ?\$ . "." ) ( ?\% . "." ) ( ?\& . "." )
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
340 ( ?\* . "." ) ( ?\+ . "." ) ( ?\- . "." )
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
341 ( ?\/ . "." ) ( ?\< . "." ) ( ?\= . "." )
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
342 ( ?\> . "." ) ( ?\| . "." )
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
343 ;; for historical reasons, underscore is word class
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
344 ;; instead of symbol class. it should be symbol class,
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
345 ;; but if you're tempted to change it, try binding M-f and
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
346 ;; M-b to py-forward-into-nomenclature and
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
347 ;; py-backward-into-nomenclature instead. -baw
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
348 ( ?\_ . "w" ) ; underscore is legit in words
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
349 ( ?\' . "\"") ; single quote is string quote
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
350 ( ?\" . "\"" ) ; double quote is string quote too
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
351 ( ?\` . "$") ; backquote is open and close paren
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
352 ( ?\# . "<") ; hash starts comment
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
353 ( ?\n . ">")))) ; newline ends comment
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
354
1589
7fdeadfa83e0 Tim Peters' version of the indentation changes (and more).
Guido van Rossum <guido@python.org>
parents: 1581
diff changeset
355 (defconst py-stringlit-re
7fdeadfa83e0 Tim Peters' version of the indentation changes (and more).
Guido van Rossum <guido@python.org>
parents: 1581
diff changeset
356 (concat
7fdeadfa83e0 Tim Peters' version of the indentation changes (and more).
Guido van Rossum <guido@python.org>
parents: 1581
diff changeset
357 "'\\([^'\n\\]\\|\\\\.\\)*'" ; single-quoted
7fdeadfa83e0 Tim Peters' version of the indentation changes (and more).
Guido van Rossum <guido@python.org>
parents: 1581
diff changeset
358 "\\|" ; or
7fdeadfa83e0 Tim Peters' version of the indentation changes (and more).
Guido van Rossum <guido@python.org>
parents: 1581
diff changeset
359 "\"\\([^\"\n\\]\\|\\\\.\\)*\"") ; double-quoted
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
360 "Regexp matching a Python string literal.")
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
361
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
362 ;; this is tricky because a trailing backslash does not mean
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
363 ;; continuation if it's in a comment
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
364 (defconst py-continued-re
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
365 (concat
1589
7fdeadfa83e0 Tim Peters' version of the indentation changes (and more).
Guido van Rossum <guido@python.org>
parents: 1581
diff changeset
366 "\\(" "[^#'\"\n\\]" "\\|" py-stringlit-re "\\)*"
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
367 "\\\\$")
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
368 "Regexp matching Python lines that are continued via backslash.")
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
369
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
370 (defconst py-blank-or-comment-re "[ \t]*\\($\\|#\\)"
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
371 "Regexp matching blank or comment lines.")
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
372
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
373 (defconst py-outdent-re
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
374 (concat "\\(" (mapconcat 'identity
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
375 '("else:"
2546
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
376 "except\\(\\s +.*\\)?:"
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
377 "finally:"
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
378 "elif\\s +.*:")
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
379 "\\|")
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
380 "\\)")
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
381 "Regexp matching clauses to be outdented one level.")
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
382
2546
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
383 (defconst py-no-outdent-re
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
384 (concat "\\(" (mapconcat 'identity
2560
787b4dd6f5f3 Barry's 2.16 -- more electric colon cruft, add py-outdent-left
Guido van Rossum <guido@python.org>
parents: 2559
diff changeset
385 '("try:"
2546
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
386 "except\\(\\s +.*\\)?:"
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
387 "while\\s +.*:"
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
388 "for\\s +.*:"
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
389 "if\\s +.*:"
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
390 "elif\\s +.*:"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
391 "\\(return\\|break\\|raise\\|continue\\)[ \t\n]"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
392 )
2546
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
393 "\\|")
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
394 "\\)")
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
395 "Regexp matching lines to not outdent after.")
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
396
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
397 (defvar py-defun-start-re
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
398 "^\\([ \t]*\\)def[ \t]+\\([a-zA-Z_0-9]+\\)\\|\\(^[a-zA-Z_0-9]+\\)[ \t]*="
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
399 "Regexp matching a function, method or variable assignment.
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
400
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
401 If you change this, you probably have to change `py-current-defun' as well.
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
402 This is only used by `py-current-defun' to find the name for add-log.el.")
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
403
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
404 (defvar py-class-start-re "^class[ \t]*\\([a-zA-Z_0-9]+\\)"
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
405 "Regexp for finding a class name.
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
406
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
407 If you change this, you probably have to change `py-current-defun' as well.
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
408 This is only used by `py-current-defun' to find the name for add-log.el.")
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
409
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
410
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
411
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
412 ;; Menu definitions, only relevent if you have the easymenu.el package
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
413 ;; (standard in the latest Emacs 19 and XEmacs 19 distributions).
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
414 (defvar py-menu nil
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
415 "Menu for Python Mode.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
416
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
417 This menu will get created automatically if you have the easymenu
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
418 package. Note that the latest XEmacs 19 and Emacs 19 versions contain
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
419 this package.")
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
420
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
421 (if (condition-case nil
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
422 (require 'easymenu)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
423 (error nil))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
424 (easy-menu-define
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
425 py-menu py-mode-map "Python Mode menu"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
426 '("Python"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
427 ["Comment Out Region" comment-region (mark)]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
428 ["Uncomment Region" (comment-region (point) (mark) '(4)) (mark)]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
429 "-"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
430 ["Mark current block" py-mark-block t]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
431 ["Mark current def" mark-python-def-or-class t]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
432 ["Mark current class" (mark-python-def-or-class t) t]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
433 "-"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
434 ["Shift region left" py-shift-region-left (mark)]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
435 ["Shift region right" py-shift-region-right (mark)]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
436 "-"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
437 ["Execute buffer" py-execute-buffer t]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
438 ["Execute region" py-execute-region (mark)]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
439 ["Start interpreter..." py-shell t]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
440 "-"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
441 ["Go to start of block" py-goto-block-up t]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
442 ["Go to start of class" (beginning-of-python-def-or-class t) t]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
443 ["Move to end of class" (end-of-python-def-or-class t) t]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
444 ["Move to start of def" beginning-of-python-def-or-class t]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
445 ["Move to end of def" end-of-python-def-or-class t]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
446 "-"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
447 ["Describe mode" py-describe-mode t]
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
448 )))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
449
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
450
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
451
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
452 ;; imenu definitions, courtesy of Perry A. Stoll <stoll@atr-sw.atr.co.jp>
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
453 (defvar imenu-example--python-class-regexp
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
454 (concat ; <<classes>>
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
455 "\\(" ;
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
456 "^[ \t]*" ; newline and maybe whitespace
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
457 "\\(class[ \t]+[a-zA-Z0-9_]+\\)" ; class name
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
458 ; possibly multiple superclasses
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
459 "\\([ \t]*\\((\\([a-zA-Z0-9_, \t\n]\\)*)\\)?\\)"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
460 "[ \t]*:" ; and the final :
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
461 "\\)" ; >>classes<<
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
462 )
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
463 "Regexp for Python classes for use with the imenu package."
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
464 )
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
465
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
466 (defvar imenu-example--python-method-regexp
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
467 (concat ; <<methods and functions>>
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
468 "\\(" ;
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
469 "^[ \t]*" ; new line and maybe whitespace
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
470 "\\(def[ \t]+" ; function definitions start with def
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
471 "\\([a-zA-Z0-9_]+\\)" ; name is here
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
472 ; function arguments...
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
473 "[ \t]*(\\([a-zA-Z0-9_=,\* \t\n]*\\))"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
474 "\\)" ; end of def
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
475 "[ \t]*:" ; and then the :
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
476 "\\)" ; >>methods and functions<<
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
477 )
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
478 "Regexp for Python methods/functions for use with the imenu package."
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
479 )
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
480
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
481 (defvar imenu-example--python-method-no-arg-parens '(2 8)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
482 "Indicies into groups of the Python regexp for use with imenu.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
483
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
484 Using these values will result in smaller imenu lists, as arguments to
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
485 functions are not listed.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
486
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
487 See the variable `imenu-example--python-show-method-args-p' for more
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
488 information.")
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
489
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
490 (defvar imenu-example--python-method-arg-parens '(2 7)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
491 "Indicies into groups of the Python regexp for use with imenu.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
492 Using these values will result in large imenu lists, as arguments to
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
493 functions are listed.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
494
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
495 See the variable `imenu-example--python-show-method-args-p' for more
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
496 information.")
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
497
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
498 ;; Note that in this format, this variable can still be used with the
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
499 ;; imenu--generic-function. Otherwise, there is no real reason to have
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
500 ;; it.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
501 (defvar imenu-example--generic-python-expression
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
502 (cons
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
503 (concat
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
504 imenu-example--python-class-regexp
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
505 "\\|" ; or...
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
506 imenu-example--python-method-regexp
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
507 )
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
508 imenu-example--python-method-no-arg-parens)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
509 "Generic Python expression which may be used directly with imenu.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
510 Used by setting the variable `imenu-generic-expression' to this value.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
511 Also, see the function \\[imenu-example--create-python-index] for a
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
512 better alternative for finding the index.")
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
513
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
514 ;; These next two variables are used when searching for the python
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
515 ;; class/definitions. Just saving some time in accessing the
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
516 ;; generic-python-expression, really.
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
517 (defvar imenu-example--python-generic-regexp nil)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
518 (defvar imenu-example--python-generic-parens nil)
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
519
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
520
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
521 ;;;###autoload
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
522 (eval-when-compile
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
523 ;; Imenu isn't used in XEmacs, so just ignore load errors
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
524 (condition-case ()
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
525 (progn
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
526 (require 'cl)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
527 (require 'imenu))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
528 (error nil)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
529
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
530 (defun imenu-example--create-python-index ()
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
531 "Python interface function for imenu package.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
532 Finds all python classes and functions/methods. Calls function
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
533 \\[imenu-example--create-python-index-engine]. See that function for
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
534 the details of how this works."
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
535 (setq imenu-example--python-generic-regexp
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
536 (car imenu-example--generic-python-expression))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
537 (setq imenu-example--python-generic-parens
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
538 (if imenu-example--python-show-method-args-p
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
539 imenu-example--python-method-arg-parens
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
540 imenu-example--python-method-no-arg-parens))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
541 (goto-char (point-min))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
542 (imenu-example--create-python-index-engine nil))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
543
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
544 (defun imenu-example--create-python-index-engine (&optional start-indent)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
545 "Function for finding imenu definitions in Python.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
546
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
547 Finds all definitions (classes, methods, or functions) in a Python
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
548 file for the imenu package.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
549
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
550 Returns a possibly nested alist of the form
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
551
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
552 (INDEX-NAME . INDEX-POSITION)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
553
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
554 The second element of the alist may be an alist, producing a nested
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
555 list as in
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
556
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
557 (INDEX-NAME . INDEX-ALIST)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
558
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
559 This function should not be called directly, as it calls itself
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
560 recursively and requires some setup. Rather this is the engine for
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
561 the function \\[imenu-example--create-python-index].
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
562
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
563 It works recursively by looking for all definitions at the current
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
564 indention level. When it finds one, it adds it to the alist. If it
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
565 finds a definition at a greater indentation level, it removes the
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
566 previous definition from the alist. In it's place it adds all
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
567 definitions found at the next indentation level. When it finds a
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
568 definition that is less indented then the current level, it retuns the
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
569 alist it has created thus far.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
570
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
571 The optional argument START-INDENT indicates the starting indentation
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
572 at which to continue looking for Python classes, methods, or
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
573 functions. If this is not supplied, the function uses the indentation
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
574 of the first definition found."
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
575 (let ((index-alist '())
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
576 (sub-method-alist '())
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
577 looking-p
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
578 def-name prev-name
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
579 cur-indent def-pos
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
580 (class-paren (first imenu-example--python-generic-parens))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
581 (def-paren (second imenu-example--python-generic-parens)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
582 (setq looking-p
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
583 (re-search-forward imenu-example--python-generic-regexp
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
584 (point-max) t))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
585 (while looking-p
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
586 (save-excursion
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
587 ;; used to set def-name to this value but generic-extract-name is
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
588 ;; new to imenu-1.14. this way it still works with imenu-1.11
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
589 ;;(imenu--generic-extract-name imenu-example--python-generic-parens))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
590 (let ((cur-paren (if (match-beginning class-paren)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
591 class-paren def-paren)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
592 (setq def-name
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
593 (buffer-substring (match-beginning cur-paren)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
594 (match-end cur-paren))))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
595 (beginning-of-line)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
596 (setq cur-indent (current-indentation)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
597
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
598 ;; HACK: want to go to the next correct definition location. we
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
599 ;; explicitly list them here. would be better to have them in a
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
600 ;; list.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
601 (setq def-pos
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
602 (or (match-beginning class-paren)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
603 (match-beginning def-paren)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
604
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
605 ;; if we don't have a starting indent level, take this one
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
606 (or start-indent
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
607 (setq start-indent cur-indent))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
608
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
609 ;; if we don't have class name yet, take this one
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
610 (or prev-name
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
611 (setq prev-name def-name))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
612
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
613 ;; what level is the next definition on? must be same, deeper
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
614 ;; or shallower indentation
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
615 (cond
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
616 ;; at the same indent level, add it to the list...
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
617 ((= start-indent cur-indent)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
618
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
619 ;; if we don't have push, use the following...
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
620 ;;(setf index-alist (cons (cons def-name def-pos) index-alist))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
621 (push (cons def-name def-pos) index-alist))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
622
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
623 ;; deeper indented expression, recur...
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
624 ((< start-indent cur-indent)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
625
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
626 ;; the point is currently on the expression we're supposed to
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
627 ;; start on, so go back to the last expression. The recursive
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
628 ;; call will find this place again and add it to the correct
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
629 ;; list
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
630 (re-search-backward imenu-example--python-generic-regexp
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
631 (point-min) 'move)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
632 (setq sub-method-alist (imenu-example--create-python-index-engine
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
633 cur-indent))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
634
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
635 (if sub-method-alist
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
636 ;; we put the last element on the index-alist on the start
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
637 ;; of the submethod alist so the user can still get to it.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
638 (let ((save-elmt (pop index-alist)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
639 (push (cons (imenu-create-submenu-name prev-name)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
640 (cons save-elmt sub-method-alist))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
641 index-alist))))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
642
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
643 ;; found less indented expression, we're done.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
644 (t
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
645 (setq looking-p nil)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
646 (re-search-backward imenu-example--python-generic-regexp
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
647 (point-min) t)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
648 (setq prev-name def-name)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
649 (and looking-p
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
650 (setq looking-p
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
651 (re-search-forward imenu-example--python-generic-regexp
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
652 (point-max) 'move))))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
653 (nreverse index-alist)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
654
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
655
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
656 ;;;###autoload
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
657 (defun python-mode ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
658 "Major mode for editing Python files.
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
659 To submit a problem report, enter `\\[py-submit-bug-report]' from a
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
660 `python-mode' buffer. Do `\\[py-describe-mode]' for detailed
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
661 documentation. To see what version of `python-mode' you are running,
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
662 enter `\\[py-version]'.
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
663
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
664 This mode knows about Python indentation, tokens, comments and
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
665 continuation lines. Paragraphs are separated by blank lines only.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
666
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
667 COMMANDS
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
668 \\{py-mode-map}
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
669 VARIABLES
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
670
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
671 py-indent-offset\t\tindentation increment
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
672 py-block-comment-prefix\t\tcomment string used by comment-region
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
673 py-python-command\t\tshell command to invoke Python interpreter
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
674 py-scroll-process-buffer\t\talways scroll Python process buffer
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
675 py-temp-directory\t\tdirectory used for temp files (if needed)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
676 py-beep-if-tab-change\t\tring the bell if tab-width is changed"
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
677 (interactive)
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
678 ;; set up local variables
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
679 (kill-all-local-variables)
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
680 (make-local-variable 'font-lock-defaults)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
681 (make-local-variable 'paragraph-separate)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
682 (make-local-variable 'paragraph-start)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
683 (make-local-variable 'require-final-newline)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
684 (make-local-variable 'comment-start)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
685 (make-local-variable 'comment-start-skip)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
686 (make-local-variable 'comment-column)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
687 (make-local-variable 'indent-region-function)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
688 (make-local-variable 'indent-line-function)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
689 (make-local-variable 'add-log-current-defun-function)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
690 ;;
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
691 (set-syntax-table py-mode-syntax-table)
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
692 (setq major-mode 'python-mode
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
693 mode-name "Python"
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
694 local-abbrev-table python-mode-abbrev-table
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
695 font-lock-defaults '(python-font-lock-keywords)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
696 paragraph-separate "^[ \t]*$"
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
697 paragraph-start "^[ \t]*$"
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
698 require-final-newline t
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
699 comment-start "# "
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
700 comment-start-skip "# *"
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
701 comment-column 40
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
702 indent-region-function 'py-indent-region
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
703 indent-line-function 'py-indent-line
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
704 ;; tell add-log.el how to find the current function/method/variable
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
705 add-log-current-defun-function 'py-current-defun
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
706 )
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
707 (use-local-map py-mode-map)
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
708 ;; add the menu
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
709 (if py-menu
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
710 (easy-menu-add py-menu))
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
711 ;; Emacs 19 requires this
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
712 (if (or py-this-is-lucid-emacs-p py-this-is-emacs-19-p)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
713 (setq comment-multi-line nil))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
714 ;; hack to allow overriding the tabsize in the file (see tokenizer.c)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
715 ;;
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
716 ;; not sure where the magic comment has to be; to save time
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
717 ;; searching for a rarity, we give up if it's not found prior to the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
718 ;; first executable statement.
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
719 ;;
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
720 ;; BAW - on first glance, this seems like complete hackery. Why was
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
721 ;; this necessary, and is it still necessary?
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
722 (let ((case-fold-search nil)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
723 (start (point))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
724 new-tab-width)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
725 (if (re-search-forward
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
726 "^[ \t]*#[ \t]*vi:set[ \t]+tabsize=\\([0-9]+\\):"
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
727 (prog2 (py-next-statement 1) (point) (goto-char 1))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
728 t)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
729 (progn
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
730 (setq new-tab-width
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
731 (string-to-int
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
732 (buffer-substring (match-beginning 1) (match-end 1))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
733 (if (= tab-width new-tab-width)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
734 nil
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
735 (setq tab-width new-tab-width)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
736 (message "Caution: tab-width changed to %d" new-tab-width)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
737 (if py-beep-if-tab-change (beep)))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
738 (goto-char start))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
739
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
740 ;; install imenu
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
741 (setq imenu-create-index-function
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
742 (function imenu-example--create-python-index))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
743 (if (fboundp 'imenu-add-to-menubar)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
744 (imenu-add-to-menubar (format "%s-%s" "IM" mode-name)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
745
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
746 ;; run the mode hook. py-mode-hook use is deprecated
2010
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
747 (if python-mode-hook
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
748 (run-hooks 'python-mode-hook)
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
749 (run-hooks 'py-mode-hook)))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
750
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
751
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
752 (defun py-keep-region-active ()
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
753 ;; do whatever is necessary to keep the region active in XEmacs.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
754 ;; Ignore byte-compiler warnings you might see. Also note that
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
755 ;; FSF's Emacs 19 does it differently and doesn't its policy doesn't
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
756 ;; require us to take explicit action.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
757 (and (boundp 'zmacs-region-stays)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
758 (setq zmacs-region-stays t)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
759
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
760
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
761 ;; electric characters
2559
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
762 (defun py-outdent-p ()
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
763 ;; returns non-nil if the current line should outdent one level
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
764 (save-excursion
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
765 (and (progn (back-to-indentation)
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
766 (looking-at py-outdent-re))
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
767 (progn (backward-to-indentation 1)
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
768 (while (or (looking-at py-blank-or-comment-re)
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
769 (bobp))
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
770 (backward-to-indentation 1))
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
771 (not (looking-at py-no-outdent-re)))
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
772 )))
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
773
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
774
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
775 (defun py-electric-colon (arg)
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
776 "Insert a colon.
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
777 In certain cases the line is outdented appropriately. If a numeric
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
778 argument is provided, that many colons are inserted non-electrically.
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
779 Electric behavior is inhibited inside a string or comment."
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
780 (interactive "P")
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
781 (self-insert-command (prefix-numeric-value arg))
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
782 ;; are we in a string or comment?
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
783 (if (save-excursion
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
784 (let ((pps (parse-partial-sexp (save-excursion
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
785 (beginning-of-python-def-or-class)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
786 (point))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
787 (point))))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
788 (not (or (nth 3 pps) (nth 4 pps)))))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
789 (save-excursion
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
790 (let ((here (point))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
791 (outdent 0)
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
792 (indent (py-compute-indentation t)))
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
793 (if (and (not arg)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
794 (py-outdent-p)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
795 (= indent (save-excursion
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
796 (py-next-statement -1)
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
797 (py-compute-indentation t)))
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
798 )
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
799 (setq outdent py-indent-offset))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
800 ;; Don't indent, only outdent. This assumes that any lines that
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
801 ;; are already outdented relative to py-compute-indentation were
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
802 ;; put there on purpose. Its highly annoying to have `:' indent
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
803 ;; for you. Use TAB, C-c C-l or C-c C-r to adjust. TBD: Is
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
804 ;; there a better way to determine this???
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
805 (if (< (current-indentation) indent) nil
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
806 (goto-char here)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
807 (beginning-of-line)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
808 (delete-horizontal-space)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
809 (indent-to (- indent outdent))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
810 )))))
2560
787b4dd6f5f3 Barry's 2.16 -- more electric colon cruft, add py-outdent-left
Guido van Rossum <guido@python.org>
parents: 2559
diff changeset
811
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
812
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
813 ;;; Functions that execute Python commands in a subprocess
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
814 ;;;###autoload
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
815 (defun py-shell ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
816 "Start an interactive Python interpreter in another window.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
817 This is like Shell mode, except that Python is running in the window
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
818 instead of a shell. See the `Interactive Shell' and `Shell Mode'
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
819 sections of the Emacs manual for details, especially for the key
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
820 bindings active in the `*Python*' buffer.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
821
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
822 See the docs for variable `py-scroll-buffer' for info on scrolling
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
823 behavior in the process window.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
824
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
825 Warning: Don't use an interactive Python if you change sys.ps1 or
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
826 sys.ps2 from their default values, or if you're running code that
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
827 prints `>>> ' or `... ' at the start of a line. `python-mode' can't
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
828 distinguish your output from Python's output, and assumes that `>>> '
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
829 at the start of a line is a prompt from Python. Similarly, the Emacs
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
830 Shell mode code assumes that both `>>> ' and `... ' at the start of a
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
831 line are Python prompts. Bad things can happen if you fool either
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
832 mode.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
833
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
834 Warning: If you do any editing *in* the process buffer *while* the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
835 buffer is accepting output from Python, do NOT attempt to `undo' the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
836 changes. Some of the output (nowhere near the parts you changed!) may
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
837 be lost if you do. This appears to be an Emacs bug, an unfortunate
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
838 interaction between undo and process filters; the same problem exists in
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
839 non-Python process buffers using the default (Emacs-supplied) process
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
840 filter."
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
841 ;; BAW - should undo be disabled in the python process buffer, if
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
842 ;; this bug still exists?
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
843 (interactive)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
844 (if py-this-is-emacs-19-p
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
845 (progn
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
846 (require 'comint)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
847 (switch-to-buffer-other-window
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
848 (make-comint "Python" py-python-command)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
849 (progn
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
850 (require 'shell)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
851 (switch-to-buffer-other-window
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
852 (apply (if (fboundp 'make-shell) 'make-shell 'make-comint)
3020
c7671c36c725 changes by Barry, e.g. font lock & email addresses
Guido van Rossum <guido@python.org>
parents: 2590
diff changeset
853 "Python" py-python-command nil))))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
854 (make-local-variable 'shell-prompt-pattern)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
855 (setq shell-prompt-pattern "^>>> \\|^\\.\\.\\. ")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
856 (set-process-filter (get-buffer-process (current-buffer))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
857 'py-process-filter)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
858 (set-syntax-table py-mode-syntax-table))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
859
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
860 (defun py-execute-region (start end)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
861 "Send the region between START and END to a Python interpreter.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
862 If there is a *Python* process it is used.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
863
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
864 Hint: If you want to execute part of a Python file several times
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
865 \(e.g., perhaps you're developing a function and want to flesh it out
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
866 a bit at a time), use `\\[narrow-to-region]' to restrict the buffer to
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
867 the region of interest, and send the code to a *Python* process via
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
868 `\\[py-execute-buffer]' instead.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
869
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
870 Following are subtleties to note when using a *Python* process:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
871
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
872 If a *Python* process is used, the region is copied into a temporary
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
873 file (in directory `py-temp-directory'), and an `execfile' command is
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
874 sent to Python naming that file. If you send regions faster than
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
875 Python can execute them, `python-mode' will save them into distinct
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
876 temp files, and execute the next one in the queue the next time it
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
877 sees a `>>> ' prompt from Python. Each time this happens, the process
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
878 buffer is popped into a window (if it's not already in some window) so
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
879 you can see it, and a comment of the form
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
880
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
881 \t## working on region in file <name> ...
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
882
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
883 is inserted at the end.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
884
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
885 Caution: No more than 26 regions can be pending at any given time.
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
886 This limit is (indirectly) inherited from libc's mktemp(3).
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
887 `python-mode' does not try to protect you from exceeding the limit.
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
888 It's extremely unlikely that you'll get anywhere close to the limit in
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
889 practice, unless you're trying to be a jerk <grin>.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
890
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
891 See the `\\[py-shell]' docs for additional warnings."
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
892 (interactive "r")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
893 (or (< start end) (error "Region is empty"))
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
894 (let ((pyproc (get-process "Python"))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
895 fname)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
896 (if (null pyproc)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
897 (shell-command-on-region start end py-python-command)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
898 ;; else feed it thru a temp file
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
899 (setq fname (py-make-temp-name))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
900 (write-region start end fname nil 'no-msg)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
901 (setq py-file-queue (append py-file-queue (list fname)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
902 (if (cdr py-file-queue)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
903 (message "File %s queued for execution" fname)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
904 ;; else
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
905 (py-execute-file pyproc fname)))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
906
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
907 (defun py-execute-file (pyproc fname)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
908 (py-append-to-process-buffer
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
909 pyproc
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
910 (format "## working on region in file %s ...\n" fname))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
911 (process-send-string pyproc (format "execfile('%s')\n" fname)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
912
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
913 (defun py-process-filter (pyproc string)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
914 (let ((curbuf (current-buffer))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
915 (pbuf (process-buffer pyproc))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
916 (pmark (process-mark pyproc))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
917 file-finished)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
918
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
919 ;; make sure we switch to a different buffer at least once. if we
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
920 ;; *don't* do this, then if the process buffer is in the selected
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
921 ;; window, and point is before the end, and lots of output is
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
922 ;; coming at a fast pace, then (a) simple cursor-movement commands
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
923 ;; like C-p, C-n, C-f, C-b, C-a, C-e take an incredibly long time
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
924 ;; to have a visible effect (the window just doesn't get updated,
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
925 ;; sometimes for minutes(!)), and (b) it takes about 5x longer to
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
926 ;; get all the process output (until the next python prompt).
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
927 ;;
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
928 ;; #b makes no sense to me at all. #a almost makes sense: unless
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
929 ;; we actually change buffers, set_buffer_internal in buffer.c
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
930 ;; doesn't set windows_or_buffers_changed to 1, & that in turn
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
931 ;; seems to make the Emacs command loop reluctant to update the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
932 ;; display. Perhaps the default process filter in process.c's
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
933 ;; read_process_output has update_mode_lines++ for a similar
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
934 ;; reason? beats me ...
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
935
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
936 (unwind-protect
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
937 ;; make sure current buffer is restored
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
938 ;; BAW - we want to check to see if this still applies
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
939 (progn
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
940 ;; mysterious ugly hack
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
941 (if (eq curbuf pbuf)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
942 (set-buffer (get-buffer-create "*scratch*")))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
943
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
944 (set-buffer pbuf)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
945 (let* ((start (point))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
946 (goback (< start pmark))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
947 (goend (and (not goback) (= start (point-max))))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
948 (buffer-read-only nil))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
949 (goto-char pmark)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
950 (insert string)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
951 (move-marker pmark (point))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
952 (setq file-finished
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
953 (and py-file-queue
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
954 (equal ">>> "
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
955 (buffer-substring
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
956 (prog2 (beginning-of-line) (point)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
957 (goto-char pmark))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
958 (point)))))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
959 (if goback (goto-char start)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
960 ;; else
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
961 (if py-scroll-process-buffer
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
962 (let* ((pop-up-windows t)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
963 (pwin (display-buffer pbuf)))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
964 (set-window-point pwin (point)))))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
965 (set-buffer curbuf)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
966 (if file-finished
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
967 (progn
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
968 (py-delete-file-silently (car py-file-queue))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
969 (setq py-file-queue (cdr py-file-queue))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
970 (if py-file-queue
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
971 (py-execute-file pyproc (car py-file-queue)))))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
972 (and goend
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
973 (progn (set-buffer pbuf)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
974 (goto-char (point-max))))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
975 ))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
976 (set-buffer curbuf))))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
977
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
978 (defun py-execute-buffer ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
979 "Send the contents of the buffer to a Python interpreter.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
980 If there is a *Python* process buffer it is used. If a clipping
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
981 restriction is in effect, only the accessible portion of the buffer is
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
982 sent. A trailing newline will be supplied if needed.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
983
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
984 See the `\\[py-execute-region]' docs for an account of some subtleties."
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
985 (interactive)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
986 (py-execute-region (point-min) (point-max)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
987
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
988
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
989
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
990 ;; Functions for Python style indentation
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
991 (defun py-delete-char (count)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
992 "Reduce indentation or delete character.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
993 If point is at the leftmost column, deletes the preceding newline.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
994
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
995 Else if point is at the leftmost non-blank character of a line that is
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
996 neither a continuation line nor a non-indenting comment line, or if
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
997 point is at the end of a blank line, reduces the indentation to match
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
998 that of the line that opened the current block of code. The line that
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
999 opened the block is displayed in the echo area to help you keep track
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1000 of where you are. With numeric count, outdents that many blocks (but
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1001 not past column zero).
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1002
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1003 Else the preceding character is deleted, converting a tab to spaces if
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1004 needed so that only a single column position is deleted. Numeric
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1005 argument delets that many characters."
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1006 (interactive "*p")
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1007 (if (or (/= (current-indentation) (current-column))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1008 (bolp)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1009 (py-continuation-line-p)
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1010 (not py-honor-comment-indentation)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1011 (looking-at "#[^ \t\n]")) ; non-indenting #
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1012 (backward-delete-char-untabify count)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1013 ;; else indent the same as the colon line that opened the block
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1014
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1015 ;; force non-blank so py-goto-block-up doesn't ignore it
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1016 (insert-char ?* 1)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1017 (backward-char)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1018 (let ((base-indent 0) ; indentation of base line
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1019 (base-text "") ; and text of base line
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1020 (base-found-p nil))
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1021 (save-excursion
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1022 (while (< 0 count)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1023 (condition-case nil ; in case no enclosing block
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1024 (progn
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1025 (py-goto-block-up 'no-mark)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1026 (setq base-indent (current-indentation)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1027 base-text (py-suck-up-leading-text)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1028 base-found-p t))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1029 (error nil))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1030 (setq count (1- count))))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1031 (delete-char 1) ; toss the dummy character
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1032 (delete-horizontal-space)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1033 (indent-to base-indent)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1034 (if base-found-p
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1035 (message "Closes block: %s" base-text)))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1036
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1037 ;; required for pending-del and delsel modes
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1038 (put 'py-delete-char 'delete-selection 'supersede)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1039 (put 'py-delete-char 'pending-delete 'supersede)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1040
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1041 (defun py-indent-line (&optional arg)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1042 "Fix the indentation of the current line according to Python rules.
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1043 With \\[universal-argument], ignore outdenting rules for block
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1044 closing statements (e.g. return, raise, break, continue, pass)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1045
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1046 This function is normally bound to `indent-line-function' so
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1047 \\[indent-for-tab-command] will call it."
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1048 (interactive "P")
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1049 (let* ((ci (current-indentation))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1050 (move-to-indentation-p (<= (current-column) ci))
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1051 (need (py-compute-indentation (not arg))))
2546
5536fcbae80a Barry's 2.12 -- fix some bugs in electric colon code
Guido van Rossum <guido@python.org>
parents: 2545
diff changeset
1052 ;; see if we need to outdent
2559
3f8c8b90158d barry's 2.13 -- minor reworking of code (added py-outdent-p)
Guido van Rossum <guido@python.org>
parents: 2546
diff changeset
1053 (if (py-outdent-p)
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
1054 (setq need (- need py-indent-offset)))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1055 (if (/= ci need)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1056 (save-excursion
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1057 (beginning-of-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1058 (delete-horizontal-space)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1059 (indent-to need)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1060 (if move-to-indentation-p (back-to-indentation))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1061
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1062 (defun py-newline-and-indent ()
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1063 "Strives to act like the Emacs `newline-and-indent'.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1064 This is just `strives to' because correct indentation can't be computed
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1065 from scratch for Python code. In general, deletes the whitespace before
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1066 point, inserts a newline, and takes an educated guess as to how you want
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1067 the new line indented."
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1068 (interactive)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1069 (let ((ci (current-indentation)))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1070 (if (< ci (current-column)) ; if point beyond indentation
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1071 (newline-and-indent)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1072 ;; else try to act like newline-and-indent "normally" acts
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1073 (beginning-of-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1074 (insert-char ?\n 1)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1075 (move-to-column ci))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1076
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1077 (defun py-compute-indentation (honor-block-close-p)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1078 ;; implements all the rules for indentation computation. when
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1079 ;; honor-block-close-p is non-nil, statements such as return, raise,
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1080 ;; break, continue, and pass force one level of outdenting.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1081 (save-excursion
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1082 (let ((pps (parse-partial-sexp (save-excursion
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1083 (beginning-of-python-def-or-class)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1084 (point))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1085 (point))))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1086 (beginning-of-line)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1087 (cond
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1088 ;; are we inside a string or comment?
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1089 ((or (nth 3 pps) (nth 4 pps))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1090 (save-excursion
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1091 (if (not py-align-multiline-strings-p) 0
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1092 ;; skip back over blank & non-indenting comment lines
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1093 ;; note: will skip a blank or non-indenting comment line
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1094 ;; that happens to be a continuation line too
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1095 (re-search-backward "^[ \t]*\\([^ \t\n#]\\|#[ \t\n]\\)" nil 'move)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1096 (back-to-indentation)
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1097 (current-column))))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1098 ;; are we on a continuation line?
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1099 ((py-continuation-line-p)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1100 (let ((startpos (point))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1101 (open-bracket-pos (py-nesting-level))
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1102 endpos searching found state)
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1103 (if open-bracket-pos
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1104 (progn
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1105 ;; align with first item in list; else a normal
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1106 ;; indent beyond the line with the open bracket
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1107 (goto-char (1+ open-bracket-pos)) ; just beyond bracket
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1108 ;; is the first list item on the same line?
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1109 (skip-chars-forward " \t")
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1110 (if (null (memq (following-char) '(?\n ?# ?\\)))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1111 ; yes, so line up with it
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1112 (current-column)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1113 ;; first list item on another line, or doesn't exist yet
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1114 (forward-line 1)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1115 (while (and (< (point) startpos)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1116 (looking-at "[ \t]*[#\n\\\\]")) ; skip noise
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1117 (forward-line 1))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1118 (if (< (point) startpos)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1119 ;; again mimic the first list item
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1120 (current-indentation)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1121 ;; else they're about to enter the first item
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1122 (goto-char open-bracket-pos)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1123 (+ (current-indentation) py-indent-offset))))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1124
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1125 ;; else on backslash continuation line
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1126 (forward-line -1)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1127 (if (py-continuation-line-p) ; on at least 3rd line in block
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1128 (current-indentation) ; so just continue the pattern
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1129 ;; else started on 2nd line in block, so indent more.
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1130 ;; if base line is an assignment with a start on a RHS,
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1131 ;; indent to 2 beyond the leftmost "="; else skip first
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1132 ;; chunk of non-whitespace characters on base line, + 1 more
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1133 ;; column
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1134 (end-of-line)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1135 (setq endpos (point) searching t)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1136 (back-to-indentation)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1137 (setq startpos (point))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1138 ;; look at all "=" from left to right, stopping at first
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1139 ;; one not nested in a list or string
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1140 (while searching
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1141 (skip-chars-forward "^=" endpos)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1142 (if (= (point) endpos)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1143 (setq searching nil)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1144 (forward-char 1)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1145 (setq state (parse-partial-sexp startpos (point)))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1146 (if (and (zerop (car state)) ; not in a bracket
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1147 (null (nth 3 state))) ; & not in a string
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1148 (progn
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1149 (setq searching nil) ; done searching in any case
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1150 (setq found
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1151 (not (or
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1152 (eq (following-char) ?=)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1153 (memq (char-after (- (point) 2))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1154 '(?< ?> ?!)))))))))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1155 (if (or (not found) ; not an assignment
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1156 (looking-at "[ \t]*\\\\")) ; <=><spaces><backslash>
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1157 (progn
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1158 (goto-char startpos)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1159 (skip-chars-forward "^ \t\n")))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1160 (1+ (current-column))))))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1161
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1162 ;; not on a continuation line
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1163 ((bobp) (current-indentation))
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1164
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1165 ;; Dfn: "Indenting comment line". A line containing only a
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1166 ;; comment, but which is treated like a statement for
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1167 ;; indentation calculation purposes. Such lines are only
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1168 ;; treated specially by the mode; they are not treated
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1169 ;; specially by the Python interpreter.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1170
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1171 ;; The rules for indenting comment lines are a line where:
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1172 ;; - the first non-whitespace character is `#', and
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1173 ;; - the character following the `#' is whitespace, and
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1174 ;; - the line is outdented with respect to (i.e. to the left
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1175 ;; of) the indentation of the preceding non-blank line.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1176
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1177 ;; The first non-blank line following an indenting comment
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1178 ;; line is given the same amount of indentation as the
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1179 ;; indenting comment line.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1180
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1181 ;; All other comment-only lines are ignored for indentation
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1182 ;; purposes.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1183
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1184 ;; Are we looking at a comment-only line which is *not* an
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1185 ;; indenting comment line? If so, we assume that its been
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1186 ;; placed at the desired indentation, so leave it alone.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1187 ;; Indenting comment lines are aligned as statements down
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1188 ;; below.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1189 ((and (looking-at "[ \t]*#[^ \t\n]")
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1190 ;; NOTE: this test will not be performed in older Emacsen
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1191 (fboundp 'forward-comment)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1192 (<= (current-indentation)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1193 (save-excursion
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1194 (forward-comment (- (point-max)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1195 (current-indentation))))
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1196 (current-indentation))
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1197
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1198 ;; else indentation based on that of the statement that
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1199 ;; precedes us; use the first line of that statement to
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1200 ;; establish the base, in case the user forced a non-std
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1201 ;; indentation for the continuation lines (if any)
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1202 (t
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1203 ;; skip back over blank & non-indenting comment lines note:
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1204 ;; will skip a blank or non-indenting comment line that
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1205 ;; happens to be a continuation line too. use fast Emacs 19
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1206 ;; function if it's there.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1207 (if (and (eq py-honor-comment-indentation nil)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1208 (fboundp 'forward-comment))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1209 (forward-comment (- (point-max)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1210 (let (done)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1211 (while (not done)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1212 (re-search-backward "^[ \t]*\\([^ \t\n#]\\|#[ \t\n]\\)"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1213 nil 'move)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1214 (setq done (or (eq py-honor-comment-indentation t)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1215 (bobp)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1216 (/= (following-char) ?#)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1217 (not (zerop (current-column)))))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1218 )))
3167
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1219 ;; if we landed inside a string, go to the beginning of that
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1220 ;; string. this handles triple quoted, multi-line spanning
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1221 ;; strings.
fe9f95b042fc Barry's version 2.30; some chages for triple quotes
Guido van Rossum <guido@python.org>
parents: 3020
diff changeset
1222 (py-goto-initial-line)
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1223 (+ (current-indentation)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1224 (if (py-statement-opens-block-p)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1225 py-indent-offset
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1226 (if (and honor-block-close-p (py-statement-closes-block-p))
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1227 (- py-indent-offset)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1228 0)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1229 )))))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1230
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1231 (defun py-guess-indent-offset (&optional global)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1232 "Guess a good value for, and change, `py-indent-offset'.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1233 By default (without a prefix arg), makes a buffer-local copy of
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1234 `py-indent-offset' with the new value. This will not affect any other
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1235 Python buffers. With a prefix arg, changes the global value of
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1236 `py-indent-offset'. This affects all Python buffers (that don't have
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1237 their own buffer-local copy), both those currently existing and those
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1238 created later in the Emacs session.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1239
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1240 Some people use a different value for `py-indent-offset' than you use.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1241 There's no excuse for such foolishness, but sometimes you have to deal
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1242 with their ugly code anyway. This function examines the file and sets
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1243 `py-indent-offset' to what it thinks it was when they created the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1244 mess.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1245
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1246 Specifically, it searches forward from the statement containing point,
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1247 looking for a line that opens a block of code. `py-indent-offset' is
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1248 set to the difference in indentation between that line and the Python
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1249 statement following it. If the search doesn't succeed going forward,
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1250 it's tried again going backward."
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1251 (interactive "P") ; raw prefix arg
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1252 (let (new-value
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1253 (start (point))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1254 restart
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1255 (found nil)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1256 colon-indent)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1257 (py-goto-initial-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1258 (while (not (or found (eobp)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1259 (if (re-search-forward ":[ \t]*\\($\\|[#\\]\\)" nil 'move)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1260 (progn
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1261 (setq restart (point))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1262 (py-goto-initial-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1263 (if (py-statement-opens-block-p)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1264 (setq found t)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1265 (goto-char restart)))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1266 (if found
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1267 ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1268 (goto-char start)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1269 (py-goto-initial-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1270 (while (not (or found (bobp)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1271 (setq found
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1272 (and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1273 (re-search-backward ":[ \t]*\\($\\|[#\\]\\)" nil 'move)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1274 (or (py-goto-initial-line) t) ; always true -- side effect
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1275 (py-statement-opens-block-p)))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1276 (setq colon-indent (current-indentation)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1277 found (and found (zerop (py-next-statement 1)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1278 new-value (- (current-indentation) colon-indent))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1279 (goto-char start)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1280 (if found
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1281 (progn
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1282 (funcall (if global 'kill-local-variable 'make-local-variable)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1283 'py-indent-offset)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1284 (setq py-indent-offset new-value)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1285 (message "%s value of py-indent-offset set to %d"
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1286 (if global "Global" "Local")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1287 py-indent-offset))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1288 (error "Sorry, couldn't guess a value for py-indent-offset"))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1289
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1290 (defun py-shift-region (start end count)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1291 (save-excursion
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1292 (goto-char end) (beginning-of-line) (setq end (point))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1293 (goto-char start) (beginning-of-line) (setq start (point))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1294 (indent-rigidly start end count)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1295
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1296 (defun py-shift-region-left (start end &optional count)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1297 "Shift region of Python code to the left.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1298 The lines from the line containing the start of the current region up
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1299 to (but not including) the line containing the end of the region are
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1300 shifted to the left, by `py-indent-offset' columns.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1301
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1302 If a prefix argument is given, the region is instead shifted by that
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1303 many columns. With no active region, outdent only the current line.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1304 You cannot outdent the region if any line is already at column zero."
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1305 (interactive
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1306 (let ((p (point))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1307 (m (mark))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1308 (arg current-prefix-arg))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1309 (if m
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1310 (list (min p m) (max p m) arg)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1311 (list p (save-excursion (forward-line 1) (point)) arg))))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1312 ;; if any line is at column zero, don't shift the region
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1313 (save-excursion
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1314 (goto-char start)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1315 (while (< (point) end)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1316 (back-to-indentation)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1317 (if (and (zerop (current-column))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1318 (not (looking-at "\\s *$")))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1319 (error "Region is at left edge."))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1320 (forward-line 1)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1321 (py-shift-region start end (- (prefix-numeric-value
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1322 (or count py-indent-offset))))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1323 (py-keep-region-active))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1324
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1325 (defun py-shift-region-right (start end &optional count)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1326 "Shift region of Python code to the right.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1327 The lines from the line containing the start of the current region up
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1328 to (but not including) the line containing the end of the region are
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1329 shifted to the right, by `py-indent-offset' columns.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1330
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1331 If a prefix argument is given, the region is instead shifted by that
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1332 many columns. With no active region, indent only the current line."
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1333 (interactive
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1334 (let ((p (point))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1335 (m (mark))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1336 (arg current-prefix-arg))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1337 (if m
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1338 (list (min p m) (max p m) arg)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1339 (list p (save-excursion (forward-line 1) (point)) arg))))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1340 (py-shift-region start end (prefix-numeric-value
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1341 (or count py-indent-offset)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1342 (py-keep-region-active))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1343
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1344 (defun py-indent-region (start end &optional indent-offset)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1345 "Reindent a region of Python code.
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1346
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1347 The lines from the line containing the start of the current region up
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1348 to (but not including) the line containing the end of the region are
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1349 reindented. If the first line of the region has a non-whitespace
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1350 character in the first column, the first line is left alone and the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1351 rest of the region is reindented with respect to it. Else the entire
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1352 region is reindented with respect to the (closest code or indenting
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1353 comment) statement immediately preceding the region.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1354
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1355 This is useful when code blocks are moved or yanked, when enclosing
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1356 control structures are introduced or removed, or to reformat code
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1357 using a new value for the indentation offset.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1358
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1359 If a numeric prefix argument is given, it will be used as the value of
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1360 the indentation offset. Else the value of `py-indent-offset' will be
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1361 used.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1362
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1363 Warning: The region must be consistently indented before this function
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1364 is called! This function does not compute proper indentation from
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1365 scratch (that's impossible in Python), it merely adjusts the existing
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1366 indentation to be correct in context.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1367
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1368 Warning: This function really has no idea what to do with
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1369 non-indenting comment lines, and shifts them as if they were indenting
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1370 comment lines. Fixing this appears to require telepathy.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1371
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1372 Special cases: whitespace is deleted from blank lines; continuation
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1373 lines are shifted by the same amount their initial line was shifted,
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1374 in order to preserve their relative indentation with respect to their
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1375 initial line; and comment lines beginning in column 1 are ignored."
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1376 (interactive "*r\nP") ; region; raw prefix arg
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1377 (save-excursion
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1378 (goto-char end) (beginning-of-line) (setq end (point-marker))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1379 (goto-char start) (beginning-of-line)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1380 (let ((py-indent-offset (prefix-numeric-value
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1381 (or indent-offset py-indent-offset)))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1382 (indents '(-1)) ; stack of active indent levels
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1383 (target-column 0) ; column to which to indent
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1384 (base-shifted-by 0) ; amount last base line was shifted
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1385 (indent-base (if (looking-at "[ \t\n]")
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1386 (py-compute-indentation t)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1387 0))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1388 ci)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1389 (while (< (point) end)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1390 (setq ci (current-indentation))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1391 ;; figure out appropriate target column
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1392 (cond
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1393 ((or (eq (following-char) ?#) ; comment in column 1
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1394 (looking-at "[ \t]*$")) ; entirely blank
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1395 (setq target-column 0))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1396 ((py-continuation-line-p) ; shift relative to base line
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1397 (setq target-column (+ ci base-shifted-by)))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1398 (t ; new base line
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1399 (if (> ci (car indents)) ; going deeper; push it
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1400 (setq indents (cons ci indents))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1401 ;; else we should have seen this indent before
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1402 (setq indents (memq ci indents)) ; pop deeper indents
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1403 (if (null indents)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1404 (error "Bad indentation in region, at line %d"
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1405 (save-restriction
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1406 (widen)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1407 (1+ (count-lines 1 (point)))))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1408 (setq target-column (+ indent-base
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1409 (* py-indent-offset
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1410 (- (length indents) 2))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1411 (setq base-shifted-by (- target-column ci))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1412 ;; shift as needed
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1413 (if (/= ci target-column)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1414 (progn
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1415 (delete-horizontal-space)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1416 (indent-to target-column)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1417 (forward-line 1))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1418 (set-marker end nil))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1419
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1420 (defun py-comment-region (beg end &optional arg)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1421 "Like `comment-region' but uses double hash (`#') comment starter."
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1422 (interactive "r\nP")
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1423 (let ((comment-start py-block-comment-prefix))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1424 (comment-region beg end arg)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1425
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1426
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1427 ;; Functions for moving point
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1428 (defun py-previous-statement (count)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1429 "Go to the start of previous Python statement.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1430 If the statement at point is the i'th Python statement, goes to the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1431 start of statement i-COUNT. If there is no such statement, goes to the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1432 first statement. Returns count of statements left to move.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1433 `Statements' do not include blank, comment, or continuation lines."
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1434 (interactive "p") ; numeric prefix arg
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1435 (if (< count 0) (py-next-statement (- count))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1436 (py-goto-initial-line)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1437 (let (start)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1438 (while (and
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1439 (setq start (point)) ; always true -- side effect
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1440 (> count 0)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1441 (zerop (forward-line -1))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1442 (py-goto-statement-at-or-above))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1443 (setq count (1- count)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1444 (if (> count 0) (goto-char start)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1445 count))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1446
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1447 (defun py-next-statement (count)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1448 "Go to the start of next Python statement.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1449 If the statement at point is the i'th Python statement, goes to the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1450 start of statement i+COUNT. If there is no such statement, goes to the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1451 last statement. Returns count of statements left to move. `Statements'
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1452 do not include blank, comment, or continuation lines."
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1453 (interactive "p") ; numeric prefix arg
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1454 (if (< count 0) (py-previous-statement (- count))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1455 (beginning-of-line)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1456 (let (start)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1457 (while (and
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1458 (setq start (point)) ; always true -- side effect
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1459 (> count 0)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1460 (py-goto-statement-below))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1461 (setq count (1- count)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1462 (if (> count 0) (goto-char start)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1463 count))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1464
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1465 (defun py-goto-block-up (&optional nomark)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1466 "Move up to start of current block.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1467 Go to the statement that starts the smallest enclosing block; roughly
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1468 speaking, this will be the closest preceding statement that ends with a
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1469 colon and is indented less than the statement you started on. If
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1470 successful, also sets the mark to the starting point.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1471
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1472 `\\[py-mark-block]' can be used afterward to mark the whole code
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1473 block, if desired.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1474
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1475 If called from a program, the mark will not be set if optional argument
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1476 NOMARK is not nil."
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1477 (interactive)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1478 (let ((start (point))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1479 (found nil)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1480 initial-indent)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1481 (py-goto-initial-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1482 ;; if on blank or non-indenting comment line, use the preceding stmt
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1483 (if (looking-at "[ \t]*\\($\\|#[^ \t\n]\\)")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1484 (progn
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1485 (py-goto-statement-at-or-above)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1486 (setq found (py-statement-opens-block-p))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1487 ;; search back for colon line indented less
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1488 (setq initial-indent (current-indentation))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1489 (if (zerop initial-indent)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1490 ;; force fast exit
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1491 (goto-char (point-min)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1492 (while (not (or found (bobp)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1493 (setq found
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1494 (and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1495 (re-search-backward ":[ \t]*\\($\\|[#\\]\\)" nil 'move)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1496 (or (py-goto-initial-line) t) ; always true -- side effect
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1497 (< (current-indentation) initial-indent)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1498 (py-statement-opens-block-p))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1499 (if found
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1500 (progn
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1501 (or nomark (push-mark start))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1502 (back-to-indentation))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1503 (goto-char start)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1504 (error "Enclosing block not found"))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1505
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1506 (defun beginning-of-python-def-or-class (&optional class)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1507 "Move point to start of def (or class, with prefix arg).
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1508
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1509 Searches back for the closest preceding `def'. If you supply a prefix
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1510 arg, looks for a `class' instead. The docs assume the `def' case;
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1511 just substitute `class' for `def' for the other case.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1512
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1513 If point is in a def statement already, and after the `d', simply
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1514 moves point to the start of the statement.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1515
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1516 Else (point is not in a def statement, or at or before the `d' of a
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1517 def statement), searches for the closest preceding def statement, and
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1518 leaves point at its start. If no such statement can be found, leaves
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1519 point at the start of the buffer.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1520
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1521 Returns t iff a def statement is found by these rules.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1522
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1523 Note that doing this command repeatedly will take you closer to the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1524 start of the buffer each time.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1525
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1526 If you want to mark the current def/class, see
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1527 `\\[mark-python-def-or-class]'."
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1528 (interactive "P") ; raw prefix arg
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1529 (let ((at-or-before-p (<= (current-column) (current-indentation)))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1530 (start-of-line (progn (beginning-of-line) (point)))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1531 (start-of-stmt (progn (py-goto-initial-line) (point))))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1532 (if (or (/= start-of-stmt start-of-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1533 (not at-or-before-p))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1534 (end-of-line)) ; OK to match on this line
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1535 (re-search-backward (if class "^[ \t]*class\\>" "^[ \t]*def\\>")
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1536 nil 'move)))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1537
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1538 (defun end-of-python-def-or-class (&optional class)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1539 "Move point beyond end of def (or class, with prefix arg) body.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1540
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1541 By default, looks for an appropriate `def'. If you supply a prefix arg,
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1542 looks for a `class' instead. The docs assume the `def' case; just
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1543 substitute `class' for `def' for the other case.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1544
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1545 If point is in a def statement already, this is the def we use.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1546
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1547 Else if the def found by `\\[beginning-of-python-def-or-class]'
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1548 contains the statement you started on, that's the def we use.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1549
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1550 Else we search forward for the closest following def, and use that.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1551
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1552 If a def can be found by these rules, point is moved to the start of
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1553 the line immediately following the def block, and the position of the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1554 start of the def is returned.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1555
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1556 Else point is moved to the end of the buffer, and nil is returned.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1557
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1558 Note that doing this command repeatedly will take you closer to the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1559 end of the buffer each time.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1560
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1561 If you want to mark the current def/class, see
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1562 `\\[mark-python-def-or-class]'."
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1563 (interactive "P") ; raw prefix arg
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1564 (let ((start (progn (py-goto-initial-line) (point)))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1565 (which (if class "class" "def"))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1566 (state 'not-found))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1567 ;; move point to start of appropriate def/class
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1568 (if (looking-at (concat "[ \t]*" which "\\>")) ; already on one
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1569 (setq state 'at-beginning)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1570 ;; else see if beginning-of-python-def-or-class hits container
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1571 (if (and (beginning-of-python-def-or-class class)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1572 (progn (py-goto-beyond-block)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1573 (> (point) start)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1574 (setq state 'at-end)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1575 ;; else search forward
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1576 (goto-char start)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1577 (if (re-search-forward (concat "^[ \t]*" which "\\>") nil 'move)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1578 (progn (setq state 'at-beginning)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1579 (beginning-of-line)))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1580 (cond
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1581 ((eq state 'at-beginning) (py-goto-beyond-block) t)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1582 ((eq state 'at-end) t)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1583 ((eq state 'not-found) nil)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1584 (t (error "internal error in end-of-python-def-or-class")))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1585
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1586
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1587 ;; Functions for marking regions
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1588 (defun py-mark-block (&optional extend just-move)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1589 "Mark following block of lines. With prefix arg, mark structure.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1590 Easier to use than explain. It sets the region to an `interesting'
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1591 block of succeeding lines. If point is on a blank line, it goes down to
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1592 the next non-blank line. That will be the start of the region. The end
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1593 of the region depends on the kind of line at the start:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1594
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1595 - If a comment, the region will include all succeeding comment lines up
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1596 to (but not including) the next non-comment line (if any).
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1597
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1598 - Else if a prefix arg is given, and the line begins one of these
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1599 structures:
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1600
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1601 if elif else try except finally for while def class
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1602
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1603 the region will be set to the body of the structure, including
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1604 following blocks that `belong' to it, but excluding trailing blank
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1605 and comment lines. E.g., if on a `try' statement, the `try' block
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1606 and all (if any) of the following `except' and `finally' blocks
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1607 that belong to the `try' structure will be in the region. Ditto
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1608 for if/elif/else, for/else and while/else structures, and (a bit
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1609 degenerate, since they're always one-block structures) def and
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1610 class blocks.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1611
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1612 - Else if no prefix argument is given, and the line begins a Python
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1613 block (see list above), and the block is not a `one-liner' (i.e.,
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1614 the statement ends with a colon, not with code), the region will
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1615 include all succeeding lines up to (but not including) the next
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1616 code statement (if any) that's indented no more than the starting
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1617 line, except that trailing blank and comment lines are excluded.
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1618 E.g., if the starting line begins a multi-statement `def'
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1619 structure, the region will be set to the full function definition,
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1620 but without any trailing `noise' lines.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1621
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1622 - Else the region will include all succeeding lines up to (but not
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1623 including) the next blank line, or code or indenting-comment line
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1624 indented strictly less than the starting line. Trailing indenting
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1625 comment lines are included in this case, but not trailing blank
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1626 lines.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1627
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1628 A msg identifying the location of the mark is displayed in the echo
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1629 area; or do `\\[exchange-point-and-mark]' to flip down to the end.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1630
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1631 If called from a program, optional argument EXTEND plays the role of
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1632 the prefix arg, and if optional argument JUST-MOVE is not nil, just
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1633 moves to the end of the block (& does not set mark or display a msg)."
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1634 (interactive "P") ; raw prefix arg
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1635 (py-goto-initial-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1636 ;; skip over blank lines
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1637 (while (and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1638 (looking-at "[ \t]*$") ; while blank line
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1639 (not (eobp))) ; & somewhere to go
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1640 (forward-line 1))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1641 (if (eobp)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1642 (error "Hit end of buffer without finding a non-blank stmt"))
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1643 (let ((initial-pos (point))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1644 (initial-indent (current-indentation))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1645 last-pos ; position of last stmt in region
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1646 (followers
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1647 '((if elif else) (elif elif else) (else)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1648 (try except finally) (except except) (finally)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1649 (for else) (while else)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1650 (def) (class) ) )
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1651 first-symbol next-symbol)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1652
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1653 (cond
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1654 ;; if comment line, suck up the following comment lines
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1655 ((looking-at "[ \t]*#")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1656 (re-search-forward "^[ \t]*[^ \t#]" nil 'move) ; look for non-comment
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1657 (re-search-backward "^[ \t]*#") ; and back to last comment in block
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1658 (setq last-pos (point)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1659
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1660 ;; else if line is a block line and EXTEND given, suck up
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1661 ;; the whole structure
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1662 ((and extend
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1663 (setq first-symbol (py-suck-up-first-keyword) )
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1664 (assq first-symbol followers))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1665 (while (and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1666 (or (py-goto-beyond-block) t) ; side effect
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1667 (forward-line -1) ; side effect
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1668 (setq last-pos (point)) ; side effect
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1669 (py-goto-statement-below)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1670 (= (current-indentation) initial-indent)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1671 (setq next-symbol (py-suck-up-first-keyword))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1672 (memq next-symbol (cdr (assq first-symbol followers))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1673 (setq first-symbol next-symbol)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1674
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1675 ;; else if line *opens* a block, search for next stmt indented <=
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1676 ((py-statement-opens-block-p)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1677 (while (and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1678 (setq last-pos (point)) ; always true -- side effect
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1679 (py-goto-statement-below)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1680 (> (current-indentation) initial-indent))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1681 nil))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1682
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1683 ;; else plain code line; stop at next blank line, or stmt or
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1684 ;; indenting comment line indented <
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1685 (t
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1686 (while (and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1687 (setq last-pos (point)) ; always true -- side effect
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1688 (or (py-goto-beyond-final-line) t)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1689 (not (looking-at "[ \t]*$")) ; stop at blank line
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1690 (or
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1691 (>= (current-indentation) initial-indent)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1692 (looking-at "[ \t]*#[^ \t\n]"))) ; ignore non-indenting #
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1693 nil)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1694
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1695 ;; skip to end of last stmt
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1696 (goto-char last-pos)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1697 (py-goto-beyond-final-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1698
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1699 ;; set mark & display
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1700 (if just-move
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1701 () ; just return
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1702 (push-mark (point) 'no-msg)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1703 (forward-line -1)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1704 (message "Mark set after: %s" (py-suck-up-leading-text))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1705 (goto-char initial-pos))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1706
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1707 (defun mark-python-def-or-class (&optional class)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1708 "Set region to body of def (or class, with prefix arg) enclosing point.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1709 Pushes the current mark, then point, on the mark ring (all language
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1710 modes do this, but although it's handy it's never documented ...).
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1711
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1712 In most Emacs language modes, this function bears at least a
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1713 hallucinogenic resemblance to `\\[end-of-python-def-or-class]' and
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1714 `\\[beginning-of-python-def-or-class]'.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1715
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1716 And in earlier versions of Python mode, all 3 were tightly connected.
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1717 Turned out that was more confusing than useful: the `goto start' and
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1718 `goto end' commands are usually used to search through a file, and
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1719 people expect them to act a lot like `search backward' and `search
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1720 forward' string-search commands. But because Python `def' and `class'
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1721 can nest to arbitrary levels, finding the smallest def containing
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1722 point cannot be done via a simple backward search: the def containing
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1723 point may not be the closest preceding def, or even the closest
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1724 preceding def that's indented less. The fancy algorithm required is
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1725 appropriate for the usual uses of this `mark' command, but not for the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1726 `goto' variations.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1727
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1728 So the def marked by this command may not be the one either of the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1729 `goto' commands find: If point is on a blank or non-indenting comment
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1730 line, moves back to start of the closest preceding code statement or
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1731 indenting comment line. If this is a `def' statement, that's the def
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1732 we use. Else searches for the smallest enclosing `def' block and uses
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1733 that. Else signals an error.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1734
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1735 When an enclosing def is found: The mark is left immediately beyond
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1736 the last line of the def block. Point is left at the start of the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1737 def, except that: if the def is preceded by a number of comment lines
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1738 followed by (at most) one optional blank line, point is left at the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1739 start of the comments; else if the def is preceded by a blank line,
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1740 point is left at its start.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1741
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1742 The intent is to mark the containing def/class and its associated
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1743 documentation, to make moving and duplicating functions and classes
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1744 pleasant."
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1745 (interactive "P") ; raw prefix arg
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1746 (let ((start (point))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1747 (which (if class "class" "def")))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1748 (push-mark start)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1749 (if (not (py-go-up-tree-to-keyword which))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1750 (progn (goto-char start)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1751 (error "Enclosing %s not found" which))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1752 ;; else enclosing def/class found
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1753 (setq start (point))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1754 (py-goto-beyond-block)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1755 (push-mark (point))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1756 (goto-char start)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1757 (if (zerop (forward-line -1)) ; if there is a preceding line
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1758 (progn
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1759 (if (looking-at "[ \t]*$") ; it's blank
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1760 (setq start (point)) ; so reset start point
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1761 (goto-char start)) ; else try again
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1762 (if (zerop (forward-line -1))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1763 (if (looking-at "[ \t]*#") ; a comment
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1764 ;; look back for non-comment line
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1765 ;; tricky: note that the regexp matches a blank
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1766 ;; line, cuz \n is in the 2nd character class
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1767 (and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1768 (re-search-backward "^[ \t]*[^ \t#]" nil 'move)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1769 (forward-line 1))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1770 ;; no comment, so go back
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1771 (goto-char start))))))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1772
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1773 ;; ripped from cc-mode
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1774 (defun py-forward-into-nomenclature (&optional arg)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1775 "Move forward to end of a nomenclature section or word.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1776 With arg, to it arg times.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1777
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1778 A `nomenclature' is a fancy way of saying AWordWithMixedCaseNotUnderscores."
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1779 (interactive "p")
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1780 (let ((case-fold-search nil))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1781 (if (> arg 0)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1782 (re-search-forward
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1783 "\\(\\W\\|[_]\\)*\\([A-Z]*[a-z0-9]*\\)"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1784 (point-max) t arg)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1785 (while (and (< arg 0)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1786 (re-search-backward
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1787 "\\(\\W\\|[a-z0-9]\\)[A-Z]+\\|\\(\\W\\|[_]\\)\\w+"
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1788 (point-min) 0))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1789 (forward-char 1)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1790 (setq arg (1+ arg)))))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1791 (py-keep-region-active))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1792
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1793 (defun py-backward-into-nomenclature (&optional arg)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1794 "Move backward to beginning of a nomenclature section or word.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1795 With optional ARG, move that many times. If ARG is negative, move
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1796 forward.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1797
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1798 A `nomenclature' is a fancy way of saying AWordWithMixedCaseNotUnderscores."
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1799 (interactive "p")
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1800 (py-forward-into-nomenclature (- arg))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1801 (py-keep-region-active))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1802
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1803
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1804
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1805 ;; Documentation functions
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1806
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1807 ;; dump the long form of the mode blurb; does the usual doc escapes,
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1808 ;; plus lines of the form ^[vc]:name$ to suck variable & command docs
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1809 ;; out of the right places, along with the keys they're on & current
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1810 ;; values
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1811 (defun py-dump-help-string (str)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1812 (with-output-to-temp-buffer "*Help*"
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1813 (let ((locals (buffer-local-variables))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1814 funckind funcname func funcdoc
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1815 (start 0) mstart end
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1816 keys )
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1817 (while (string-match "^%\\([vc]\\):\\(.+\\)\n" str start)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1818 (setq mstart (match-beginning 0) end (match-end 0)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1819 funckind (substring str (match-beginning 1) (match-end 1))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1820 funcname (substring str (match-beginning 2) (match-end 2))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1821 func (intern funcname))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1822 (princ (substitute-command-keys (substring str start mstart)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1823 (cond
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1824 ((equal funckind "c") ; command
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1825 (setq funcdoc (documentation func)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1826 keys (concat
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1827 "Key(s): "
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1828 (mapconcat 'key-description
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1829 (where-is-internal func py-mode-map)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1830 ", "))))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1831 ((equal funckind "v") ; variable
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
1832 (setq funcdoc (documentation-property func 'variable-documentation)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1833 keys (if (assq func locals)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1834 (concat
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1835 "Local/Global values: "
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1836 (prin1-to-string (symbol-value func))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1837 " / "
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1838 (prin1-to-string (default-value func)))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1839 (concat
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1840 "Value: "
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1841 (prin1-to-string (symbol-value func))))))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1842 (t ; unexpected
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1843 (error "Error in py-dump-help-string, tag `%s'" funckind)))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1844 (princ (format "\n-> %s:\t%s\t%s\n\n"
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1845 (if (equal funckind "c") "Command" "Variable")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1846 funcname keys))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1847 (princ funcdoc)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1848 (terpri)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1849 (setq start end))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1850 (princ (substitute-command-keys (substring str start))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1851 (print-help-return-message)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1852
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1853 (defun py-describe-mode ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1854 "Dump long form of Python-mode docs."
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1855 (interactive)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1856 (py-dump-help-string "Major mode for editing Python files.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1857 Knows about Python indentation, tokens, comments and continuation lines.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1858 Paragraphs are separated by blank lines only.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1859
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1860 Major sections below begin with the string `@'; specific function and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1861 variable docs begin with `->'.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1862
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1863 @EXECUTING PYTHON CODE
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1864
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1865 \\[py-execute-buffer]\tsends the entire buffer to the Python interpreter
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1866 \\[py-execute-region]\tsends the current region
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1867 \\[py-shell]\tstarts a Python interpreter window; this will be used by
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1868 \tsubsequent \\[py-execute-buffer] or \\[py-execute-region] commands
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1869 %c:py-execute-buffer
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1870 %c:py-execute-region
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1871 %c:py-shell
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1872
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1873 @VARIABLES
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1874
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1875 py-indent-offset\tindentation increment
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
1876 py-block-comment-prefix\tcomment string used by comment-region
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1877
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1878 py-python-command\tshell command to invoke Python interpreter
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1879 py-scroll-process-buffer\talways scroll Python process buffer
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1880 py-temp-directory\tdirectory used for temp files (if needed)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1881
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1882 py-beep-if-tab-change\tring the bell if tab-width is changed
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1883 %v:py-indent-offset
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1884 %v:py-block-comment-prefix
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1885 %v:py-python-command
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1886 %v:py-scroll-process-buffer
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1887 %v:py-temp-directory
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1888 %v:py-beep-if-tab-change
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1889
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1890 @KINDS OF LINES
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1891
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1892 Each physical line in the file is either a `continuation line' (the
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1893 preceding line ends with a backslash that's not part of a comment, or
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1894 the paren/bracket/brace nesting level at the start of the line is
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1895 non-zero, or both) or an `initial line' (everything else).
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1896
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1897 An initial line is in turn a `blank line' (contains nothing except
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1898 possibly blanks or tabs), a `comment line' (leftmost non-blank
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1899 character is `#'), or a `code line' (everything else).
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1900
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1901 Comment Lines
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1902
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1903 Although all comment lines are treated alike by Python, Python mode
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1904 recognizes two kinds that act differently with respect to indentation.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1905
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1906 An `indenting comment line' is a comment line with a blank, tab or
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1907 nothing after the initial `#'. The indentation commands (see below)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1908 treat these exactly as if they were code lines: a line following an
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1909 indenting comment line will be indented like the comment line. All
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1910 other comment lines (those with a non-whitespace character immediately
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1911 following the initial `#') are `non-indenting comment lines', and
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1912 their indentation is ignored by the indentation commands.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1913
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1914 Indenting comment lines are by far the usual case, and should be used
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1915 whenever possible. Non-indenting comment lines are useful in cases
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1916 like these:
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1917
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1918 \ta = b # a very wordy single-line comment that ends up being
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1919 \t #... continued onto another line
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1920
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1921 \tif a == b:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1922 ##\t\tprint 'panic!' # old code we've `commented out'
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1923 \t\treturn a
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1924
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1925 Since the `#...' and `##' comment lines have a non-whitespace
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1926 character following the initial `#', Python mode ignores them when
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1927 computing the proper indentation for the next line.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1928
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1929 Continuation Lines and Statements
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1930
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1931 The Python-mode commands generally work on statements instead of on
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1932 individual lines, where a `statement' is a comment or blank line, or a
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1933 code line and all of its following continuation lines (if any)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1934 considered as a single logical unit. The commands in this mode
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1935 generally (when it makes sense) automatically move to the start of the
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1936 statement containing point, even if point happens to be in the middle
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
1937 of some continuation line.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1938
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1939
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1940 @INDENTATION
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1941
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1942 Primarily for entering new code:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1943 \t\\[indent-for-tab-command]\t indent line appropriately
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1944 \t\\[py-newline-and-indent]\t insert newline, then indent
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1945 \t\\[py-delete-char]\t reduce indentation, or delete single character
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1946
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1947 Primarily for reindenting existing code:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1948 \t\\[py-guess-indent-offset]\t guess py-indent-offset from file content; change locally
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1949 \t\\[universal-argument] \\[py-guess-indent-offset]\t ditto, but change globally
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1950
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1951 \t\\[py-indent-region]\t reindent region to match its context
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1952 \t\\[py-shift-region-left]\t shift region left by py-indent-offset
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1953 \t\\[py-shift-region-right]\t shift region right by py-indent-offset
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1954
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1955 Unlike most programming languages, Python uses indentation, and only
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1956 indentation, to specify block structure. Hence the indentation supplied
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1957 automatically by Python-mode is just an educated guess: only you know
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1958 the block structure you intend, so only you can supply correct
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1959 indentation.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1960
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1961 The \\[indent-for-tab-command] and \\[py-newline-and-indent] keys try to suggest plausible indentation, based on
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1962 the indentation of preceding statements. E.g., assuming
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1963 py-indent-offset is 4, after you enter
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1964 \tif a > 0: \\[py-newline-and-indent]
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1965 the cursor will be moved to the position of the `_' (_ is not a
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1966 character in the file, it's just used here to indicate the location of
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1967 the cursor):
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1968 \tif a > 0:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1969 \t _
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1970 If you then enter `c = d' \\[py-newline-and-indent], the cursor will move
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1971 to
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1972 \tif a > 0:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1973 \t c = d
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1974 \t _
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1975 Python-mode cannot know whether that's what you intended, or whether
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1976 \tif a > 0:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1977 \t c = d
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1978 \t_
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1979 was your intent. In general, Python-mode either reproduces the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1980 indentation of the (closest code or indenting-comment) preceding
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1981 statement, or adds an extra py-indent-offset blanks if the preceding
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1982 statement has `:' as its last significant (non-whitespace and non-
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1983 comment) character. If the suggested indentation is too much, use
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1984 \\[py-delete-char] to reduce it.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
1985
1593
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
1986 Continuation lines are given extra indentation. If you don't like the
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
1987 suggested indentation, change it to something you do like, and Python-
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
1988 mode will strive to indent later lines of the statement in the same way.
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
1989
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
1990 If a line is a continuation line by virtue of being in an unclosed
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
1991 paren/bracket/brace structure (`list', for short), the suggested
1594
ba6ac82fcb68 Improved guesswork by Tim for continuations where the open bracket
Guido van Rossum <guido@python.org>
parents: 1593
diff changeset
1992 indentation depends on whether the current line contains the first item
ba6ac82fcb68 Improved guesswork by Tim for continuations where the open bracket
Guido van Rossum <guido@python.org>
parents: 1593
diff changeset
1993 in the list. If it does, it's indented py-indent-offset columns beyond
ba6ac82fcb68 Improved guesswork by Tim for continuations where the open bracket
Guido van Rossum <guido@python.org>
parents: 1593
diff changeset
1994 the indentation of the line containing the open bracket. If you don't
ba6ac82fcb68 Improved guesswork by Tim for continuations where the open bracket
Guido van Rossum <guido@python.org>
parents: 1593
diff changeset
1995 like that, change it by hand. The remaining items in the list will mimic
ba6ac82fcb68 Improved guesswork by Tim for continuations where the open bracket
Guido van Rossum <guido@python.org>
parents: 1593
diff changeset
1996 whatever indentation you give to the first item.
1589
7fdeadfa83e0 Tim Peters' version of the indentation changes (and more).
Guido van Rossum <guido@python.org>
parents: 1581
diff changeset
1997
7fdeadfa83e0 Tim Peters' version of the indentation changes (and more).
Guido van Rossum <guido@python.org>
parents: 1581
diff changeset
1998 If a line is a continuation line because the line preceding it ends with
1593
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
1999 a backslash, the third and following lines of the statement inherit their
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
2000 indentation from the line preceding them. The indentation of the second
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
2001 line in the statement depends on the form of the first (base) line: if
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
2002 the base line is an assignment statement with anything more interesting
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
2003 than the backslash following the leftmost assigning `=', the second line
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
2004 is indented two columns beyond that `='. Else it's indented to two
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
2005 columns beyond the leftmost solid chunk of non-whitespace characters on
88de21ef4a8a Improvements from Tim after some complaints...
Guido van Rossum <guido@python.org>
parents: 1589
diff changeset
2006 the base line.
1589
7fdeadfa83e0 Tim Peters' version of the indentation changes (and more).
Guido van Rossum <guido@python.org>
parents: 1581
diff changeset
2007
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2008 Warning: indent-region should not normally be used! It calls \\[indent-for-tab-command]
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2009 repeatedly, and as explained above, \\[indent-for-tab-command] can't guess the block
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2010 structure you intend.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2011 %c:indent-for-tab-command
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2012 %c:py-newline-and-indent
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2013 %c:py-delete-char
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2014
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2015
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2016 The next function may be handy when editing code you didn't write:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2017 %c:py-guess-indent-offset
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2018
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2019
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2020 The remaining `indent' functions apply to a region of Python code. They
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2021 assume the block structure (equals indentation, in Python) of the region
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2022 is correct, and alter the indentation in various ways while preserving
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2023 the block structure:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2024 %c:py-indent-region
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2025 %c:py-shift-region-left
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2026 %c:py-shift-region-right
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2027
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2028 @MARKING & MANIPULATING REGIONS OF CODE
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2029
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2030 \\[py-mark-block]\t mark block of lines
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2031 \\[mark-python-def-or-class]\t mark smallest enclosing def
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2032 \\[universal-argument] \\[mark-python-def-or-class]\t mark smallest enclosing class
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2033 \\[comment-region]\t comment out region of code
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2034 \\[universal-argument] \\[comment-region]\t uncomment region of code
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2035 %c:py-mark-block
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2036 %c:mark-python-def-or-class
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2037 %c:comment-region
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2038
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2039 @MOVING POINT
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2040
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2041 \\[py-previous-statement]\t move to statement preceding point
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2042 \\[py-next-statement]\t move to statement following point
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2043 \\[py-goto-block-up]\t move up to start of current block
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2044 \\[beginning-of-python-def-or-class]\t move to start of def
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2045 \\[universal-argument] \\[beginning-of-python-def-or-class]\t move to start of class
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2046 \\[end-of-python-def-or-class]\t move to end of def
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2047 \\[universal-argument] \\[end-of-python-def-or-class]\t move to end of class
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2048
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2049 The first two move to one statement beyond the statement that contains
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2050 point. A numeric prefix argument tells them to move that many
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2051 statements instead. Blank lines, comment lines, and continuation lines
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2052 do not count as `statements' for these commands. So, e.g., you can go
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2053 to the first code statement in a file by entering
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2054 \t\\[beginning-of-buffer]\t to move to the top of the file
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2055 \t\\[py-next-statement]\t to skip over initial comments and blank lines
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2056 Or do `\\[py-previous-statement]' with a huge prefix argument.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2057 %c:py-previous-statement
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2058 %c:py-next-statement
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2059 %c:py-goto-block-up
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2060 %c:beginning-of-python-def-or-class
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2061 %c:end-of-python-def-or-class
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2062
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2063 @LITTLE-KNOWN EMACS COMMANDS PARTICULARLY USEFUL IN PYTHON MODE
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2064
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2065 `\\[indent-new-comment-line]' is handy for entering a multi-line comment.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2066
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2067 `\\[set-selective-display]' with a `small' prefix arg is ideally suited for viewing the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2068 overall class and def structure of a module.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2069
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2070 `\\[back-to-indentation]' moves point to a line's first non-blank character.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2071
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2072 `\\[indent-relative]' is handy for creating odd indentation.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2073
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2074 @OTHER EMACS HINTS
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2075
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2076 If you don't like the default value of a variable, change its value to
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2077 whatever you do like by putting a `setq' line in your .emacs file.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2078 E.g., to set the indentation increment to 4, put this line in your
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2079 .emacs:
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2080 \t(setq py-indent-offset 4)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2081 To see the value of a variable, do `\\[describe-variable]' and enter the variable
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2082 name at the prompt.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2083
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2084 When entering a key sequence like `C-c C-n', it is not necessary to
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2085 release the CONTROL key after doing the `C-c' part -- it suffices to
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2086 press the CONTROL key, press and release `c' (while still holding down
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2087 CONTROL), press and release `n' (while still holding down CONTROL), &
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2088 then release CONTROL.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2089
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2090 Entering Python mode calls with no arguments the value of the variable
2010
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
2091 `python-mode-hook', if that value exists and is not nil; for backward
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
2092 compatibility it also tries `py-mode-hook'; see the `Hooks' section of
f65ec3dcc563 python-mode-hook instead of py-mode-hook
Guido van Rossum <guido@python.org>
parents: 1595
diff changeset
2093 the Elisp manual for details.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2094
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2095 Obscure: When python-mode is first loaded, it looks for all bindings
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2096 to newline-and-indent in the global keymap, and shadows them with
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2097 local bindings to py-newline-and-indent."))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2098
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2099
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2100 ;; Helper functions
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2101 (defvar py-parse-state-re
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2102 (concat
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2103 "^[ \t]*\\(if\\|elif\\|else\\|while\\|def\\|class\\)\\>"
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2104 "\\|"
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2105 "^[^ #\t\n]"))
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2106
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2107 ;; returns the parse state at point (see parse-partial-sexp docs)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2108 (defun py-parse-state ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2109 (save-excursion
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2110 (let ((here (point))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2111 pps done ci)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2112 (while (not done)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2113 ;; back up to the first preceding line (if any; else start of
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2114 ;; buffer) that begins with a popular Python keyword, or a
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2115 ;; non- whitespace and non-comment character. These are good
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2116 ;; places to start parsing to see whether where we started is
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2117 ;; at a non-zero nesting level. It may be slow for people who
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2118 ;; write huge code blocks or huge lists ... tough beans.
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2119 (re-search-backward py-parse-state-re nil 'move)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2120 (setq ci (current-indentation))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2121 (beginning-of-line)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2122 (save-excursion
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2123 (setq pps (parse-partial-sexp (point) here)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2124 ;; make sure we don't land inside a triple-quoted string
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2125 (setq done (or (zerop ci)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2126 (not (nth 3 pps))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2127 (bobp)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2128 )
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2129 pps)))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2130
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2131 ;; if point is at a non-zero nesting level, returns the number of the
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2132 ;; character that opens the smallest enclosing unclosed list; else
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2133 ;; returns nil.
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2134 (defun py-nesting-level ()
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2135 (let ((status (py-parse-state)) )
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2136 (if (zerop (car status))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2137 nil ; not in a nest
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2138 (car (cdr status))))) ; char# of open bracket
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2139
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2140 ;; t iff preceding line ends with backslash that's not in a comment
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2141 (defun py-backslash-continuation-line-p ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2142 (save-excursion
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2143 (beginning-of-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2144 (and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2145 ;; use a cheap test first to avoid the regexp if possible
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2146 ;; use 'eq' because char-after may return nil
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2147 (eq (char-after (- (point) 2)) ?\\ )
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2148 ;; make sure; since eq test passed, there is a preceding line
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2149 (forward-line -1) ; always true -- side effect
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2150 (looking-at py-continued-re))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2151
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2152 ;; t iff current line is a continuation line
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2153 (defun py-continuation-line-p ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2154 (save-excursion
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2155 (beginning-of-line)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2156 (or (py-backslash-continuation-line-p)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2157 (py-nesting-level))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2158
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2159 ;; go to initial line of current statement; usually this is the line
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2160 ;; we're on, but if we're on the 2nd or following lines of a
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2161 ;; continuation block, we need to go up to the first line of the
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2162 ;; block.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2163 ;;
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2164 ;; Tricky: We want to avoid quadratic-time behavior for long continued
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2165 ;; blocks, whether of the backslash or open-bracket varieties, or a
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2166 ;; mix of the two. The following manages to do that in the usual
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2167 ;; cases.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2168 (defun py-goto-initial-line ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2169 (let ( open-bracket-pos )
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2170 (while (py-continuation-line-p)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2171 (beginning-of-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2172 (if (py-backslash-continuation-line-p)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2173 (while (py-backslash-continuation-line-p)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2174 (forward-line -1))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2175 ;; else zip out of nested brackets/braces/parens
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2176 (while (setq open-bracket-pos (py-nesting-level))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2177 (goto-char open-bracket-pos)))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2178 (beginning-of-line))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2179
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2180 ;; go to point right beyond final line of current statement; usually
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2181 ;; this is the start of the next line, but if this is a multi-line
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2182 ;; statement we need to skip over the continuation lines. Tricky:
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2183 ;; Again we need to be clever to avoid quadratic time behavior.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2184 (defun py-goto-beyond-final-line ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2185 (forward-line 1)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2186 (let (state)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2187 (while (and (py-continuation-line-p)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2188 (not (eobp)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2189 ;; skip over the backslash flavor
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2190 (while (and (py-backslash-continuation-line-p)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2191 (not (eobp)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2192 (forward-line 1))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2193 ;; if in nest, zip to the end of the nest
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2194 (setq state (py-parse-state))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2195 (if (and (not (zerop (car state)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2196 (not (eobp)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2197 (progn
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2198 ;; BUG ALERT: I could swear, from reading the docs, that
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2199 ;; the 3rd argument should be plain 0
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2200 (parse-partial-sexp (point) (point-max) (- 0 (car state))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2201 nil state)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2202 (forward-line 1))))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2203
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2204 ;; t iff statement opens a block == iff it ends with a colon that's
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2205 ;; not in a comment. point should be at the start of a statement
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2206 (defun py-statement-opens-block-p ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2207 (save-excursion
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2208 (let ((start (point))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2209 (finish (progn (py-goto-beyond-final-line) (1- (point))))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2210 (searching t)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2211 (answer nil)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2212 state)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2213 (goto-char start)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2214 (while searching
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2215 ;; look for a colon with nothing after it except whitespace, and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2216 ;; maybe a comment
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2217 (if (re-search-forward ":\\([ \t]\\|\\\\\n\\)*\\(#.*\\)?$"
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2218 finish t)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2219 (if (eq (point) finish) ; note: no `else' clause; just
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2220 ; keep searching if we're not at
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2221 ; the end yet
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2222 ;; sure looks like it opens a block -- but it might
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2223 ;; be in a comment
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2224 (progn
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2225 (setq searching nil) ; search is done either way
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2226 (setq state (parse-partial-sexp start
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2227 (match-beginning 0)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2228 (setq answer (not (nth 4 state)))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2229 ;; search failed: couldn't find another interesting colon
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2230 (setq searching nil)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2231 answer)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2232
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2233 (defun py-statement-closes-block-p ()
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2234 ;; true iff the current statement `closes' a block == the line
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2235 ;; starts with `return', `raise', `break', `continue', and `pass'.
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2236 ;; doesn't catch embedded statements
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2237 (let ((here (point)))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2238 (back-to-indentation)
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2239 (prog1
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2240 (looking-at "\\(return\\|raise\\|break\\|continue\\|pass\\)\\>")
4067
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2241 (goto-char here))))
231a42091830 Barry's 2.72
Guido van Rossum <guido@python.org>
parents: 3167
diff changeset
2242
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2243 ;; go to point right beyond final line of block begun by the current
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2244 ;; line. This is the same as where py-goto-beyond-final-line goes
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2245 ;; unless we're on colon line, in which case we go to the end of the
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2246 ;; block. assumes point is at bolp
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2247 (defun py-goto-beyond-block ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2248 (if (py-statement-opens-block-p)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2249 (py-mark-block nil 'just-move)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2250 (py-goto-beyond-final-line)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2251
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2252 ;; go to start of first statement (not blank or comment or
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2253 ;; continuation line) at or preceding point. returns t if there is
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2254 ;; one, else nil
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2255 (defun py-goto-statement-at-or-above ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2256 (py-goto-initial-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2257 (if (looking-at py-blank-or-comment-re)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2258 ;; skip back over blank & comment lines
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2259 ;; note: will skip a blank or comment line that happens to be
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2260 ;; a continuation line too
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2261 (if (re-search-backward "^[ \t]*[^ \t#\n]" nil t)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2262 (progn (py-goto-initial-line) t)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2263 nil)
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2264 t))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2265
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2266 ;; go to start of first statement (not blank or comment or
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2267 ;; continuation line) following the statement containing point returns
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2268 ;; t if there is one, else nil
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2269 (defun py-goto-statement-below ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2270 (beginning-of-line)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2271 (let ((start (point)))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2272 (py-goto-beyond-final-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2273 (while (and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2274 (looking-at py-blank-or-comment-re)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2275 (not (eobp)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2276 (forward-line 1))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2277 (if (eobp)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2278 (progn (goto-char start) nil)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2279 t)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2280
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2281 ;; go to start of statement, at or preceding point, starting with
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2282 ;; keyword KEY. Skips blank lines and non-indenting comments upward
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2283 ;; first. If that statement starts with KEY, done, else go back to
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2284 ;; first enclosing block starting with KEY. If successful, leaves
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2285 ;; point at the start of the KEY line & returns t. Else leaves point
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2286 ;; at an undefined place & returns nil.
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2287 (defun py-go-up-tree-to-keyword (key)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2288 ;; skip blanks and non-indenting #
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2289 (py-goto-initial-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2290 (while (and
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2291 (looking-at "[ \t]*\\($\\|#[^ \t\n]\\)")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2292 (zerop (forward-line -1))) ; go back
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2293 nil)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2294 (py-goto-initial-line)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2295 (let* ((re (concat "[ \t]*" key "\\b"))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2296 (case-fold-search nil) ; let* so looking-at sees this
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2297 (found (looking-at re))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2298 (dead nil))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2299 (while (not (or found dead))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2300 (condition-case nil ; in case no enclosing block
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2301 (py-goto-block-up 'no-mark)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2302 (error (setq dead t)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2303 (or dead (setq found (looking-at re))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2304 (beginning-of-line)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2305 found))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2306
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2307 ;; return string in buffer from start of indentation to end of line;
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2308 ;; prefix "..." if leading whitespace was skipped
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2309 (defun py-suck-up-leading-text ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2310 (save-excursion
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2311 (back-to-indentation)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2312 (concat
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2313 (if (bolp) "" "...")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2314 (buffer-substring (point) (progn (end-of-line) (point))))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2315
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2316 ;; assuming point at bolp, return first keyword ([a-z]+) on the line,
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2317 ;; as a Lisp symbol; return nil if none
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2318 (defun py-suck-up-first-keyword ()
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2319 (let ((case-fold-search nil))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2320 (if (looking-at "[ \t]*\\([a-z]+\\)\\b")
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2321 (intern (buffer-substring (match-beginning 1) (match-end 1)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2322 nil)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2323
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2324 (defun py-make-temp-name ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2325 (make-temp-name
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2326 (concat (file-name-as-directory py-temp-directory) "python")))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2327
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2328 (defun py-delete-file-silently (fname)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2329 (condition-case nil
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2330 (delete-file fname)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2331 (error nil)))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2332
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2333 (defun py-kill-emacs-hook ()
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2334 ;; delete our temp files
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2335 (while py-file-queue
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2336 (py-delete-file-silently (car py-file-queue))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2337 (setq py-file-queue (cdr py-file-queue)))
1595
b3443546d6ee Now it's 1.09. Only change from 1.08az is to make kill-emacs-hook work under Lucid
Guido van Rossum <guido@python.org>
parents: 1594
diff changeset
2338 (if (not (or py-this-is-lucid-emacs-p py-this-is-emacs-19-p))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2339 ;; run the hook we inherited, if any
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2340 (and py-inherited-kill-emacs-hook
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2341 (funcall py-inherited-kill-emacs-hook))))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2342
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2343 ;; make PROCESS's buffer visible, append STRING to it, and force
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2344 ;; display; also make shell-mode believe the user typed this string,
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2345 ;; so that kill-output-from-shell and show-output-from-shell work
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2346 ;; "right"
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2347 (defun py-append-to-process-buffer (process string)
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2348 (let ((cbuf (current-buffer))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2349 (pbuf (process-buffer process))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2350 (py-scroll-process-buffer t))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2351 (set-buffer pbuf)
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2352 (goto-char (point-max))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2353 (move-marker (process-mark process) (point))
3020
c7671c36c725 changes by Barry, e.g. font lock & email addresses
Guido van Rossum <guido@python.org>
parents: 2590
diff changeset
2354 (if (not (or py-this-is-emacs-19-p
c7671c36c725 changes by Barry, e.g. font lock & email addresses
Guido van Rossum <guido@python.org>
parents: 2590
diff changeset
2355 py-this-is-lucid-emacs-p))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2356 (move-marker last-input-start (point))) ; muck w/ shell-mode
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2357 (funcall (process-filter process) process string)
3020
c7671c36c725 changes by Barry, e.g. font lock & email addresses
Guido van Rossum <guido@python.org>
parents: 2590
diff changeset
2358 (if (not (or py-this-is-emacs-19-p
c7671c36c725 changes by Barry, e.g. font lock & email addresses
Guido van Rossum <guido@python.org>
parents: 2590
diff changeset
2359 py-this-is-lucid-emacs-p))
1529
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2360 (move-marker last-input-end (point))) ; muck w/ shell-mode
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2361 (set-buffer cbuf))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2362 (sit-for 0))
c9b3f77e18ba Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2363
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2364 (defun py-current-defun ()
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2365 ;; tell add-log.el how to find the current function/method/variable
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2366 (save-excursion
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2367 (if (re-search-backward py-defun-start-re nil t)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2368 (or (match-string 3)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2369 (let ((method (match-string 2)))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2370 (if (and (not (zerop (length (match-string 1))))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2371 (re-search-backward py-class-start-re nil t))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2372 (concat (match-string 1) "." method)
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2373 method)))
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2374 nil)))
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2375
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2376
4481
dd709ed82262 Barry's latest (2.83). He likes this version particularly because
Guido van Rossum <guido@python.org>
parents: 4070
diff changeset
2377 (defconst py-version "2.83"
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2378 "`python-mode' version number.")
3020
c7671c36c725 changes by Barry, e.g. font lock & email addresses
Guido van Rossum <guido@python.org>
parents: 2590
diff changeset
2379 (defconst py-help-address "python-mode@python.org"
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2380 "Address accepting submission of bug reports.")
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2381
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2382 (defun py-version ()
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2383 "Echo the current version of `python-mode' in the minibuffer."
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2384 (interactive)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2385 (message "Using `python-mode' version %s" py-version)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2386 (py-keep-region-active))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2387
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2388 ;; only works under Emacs 19
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2389 ;(eval-when-compile
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2390 ; (require 'reporter))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2391
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2392 (defun py-submit-bug-report (enhancement-p)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2393 "Submit via mail a bug report on `python-mode'.
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2394 With \\[universal-argument] just submit an enhancement request."
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2395 (interactive
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2396 (list (not (y-or-n-p
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2397 "Is this a bug report? (hit `n' to send other comments) "))))
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
2398 (let ((reporter-prompt-for-summary-p (if enhancement-p
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
2399 "(Very) brief summary: "
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
2400 t)))
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2401 (require 'reporter)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2402 (reporter-submit-bug-report
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2403 py-help-address ;address
2545
9cc775fd6e84 Barry's version 2.11 -- electric colon
Guido van Rossum <guido@python.org>
parents: 2526
diff changeset
2404 (concat "python-mode " py-version) ;pkgname
2525
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2405 ;; varlist
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2406 (if enhancement-p nil
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2407 '(py-python-command
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2408 py-indent-offset
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2409 py-block-comment-prefix
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2410 py-scroll-process-buffer
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2411 py-temp-directory
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2412 py-beep-if-tab-change))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2413 nil ;pre-hooks
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2414 nil ;post-hooks
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2415 "Dear Barry,") ;salutation
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2416 (if enhancement-p nil
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2417 (set-mark (point))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2418 (insert
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2419 "Please replace this text with a sufficiently large code sample\n\
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2420 and an exact recipe so that I can reproduce your problem. Failure\n\
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2421 to do so may mean a greater delay in fixing your bug.\n\n")
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2422 (exchange-point-and-mark)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2423 (py-keep-region-active))))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2424
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2425
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2426 ;; arrange to kill temp files when Emacs exists
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2427 (if (or py-this-is-emacs-19-p py-this-is-lucid-emacs-p)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2428 (add-hook 'kill-emacs-hook 'py-kill-emacs-hook)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2429 ;; have to trust that other people are as respectful of our hook
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2430 ;; fiddling as we are of theirs
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2431 (if (boundp 'py-inherited-kill-emacs-hook)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2432 ;; we were loaded before -- trust others not to have screwed us
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2433 ;; in the meantime (no choice, really)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2434 nil
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2435 ;; else arrange for our hook to run theirs
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2436 (setq py-inherited-kill-emacs-hook kill-emacs-hook)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2437 (setq kill-emacs-hook 'py-kill-emacs-hook)))
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2438
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2439
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2440
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2441 (provide 'python-mode)
16ea151aeec3 Lots of formatting changes by Barry, and a few real changes.
Guido van Rossum <guido@python.org>
parents: 2512
diff changeset
2442 ;;; python-mode.el ends here