summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1996-08-01 15:53:09 (GMT)
committerBarry Warsaw <barry@python.org>1996-08-01 15:53:09 (GMT)
commita7891718e1293dc9afa1dacb77a59f1895611f75 (patch)
treed8c59a6a525dea9c145dd6f0027cc8a3cfb08356
parente5b7b850f70aeaeb3946b39b141464f5ec78368e (diff)
downloadcpython-a7891718e1293dc9afa1dacb77a59f1895611f75.zip
cpython-a7891718e1293dc9afa1dacb77a59f1895611f75.tar.gz
cpython-a7891718e1293dc9afa1dacb77a59f1895611f75.tar.bz2
(py-mode): comment-start is now "# " so indent-for-comment does the
right thing. (py-comment-region): let-bind comment-start to "## " so commented regions get transformed into non-indenting comment lines. (py-compute-region): Implement modification to rule for recognizing "indenting comment lines".
-rw-r--r--Misc/python-mode.el47
1 files changed, 41 insertions, 6 deletions
diff --git a/Misc/python-mode.el b/Misc/python-mode.el
index 038f417..cf5f4d6 100644
--- a/Misc/python-mode.el
+++ b/Misc/python-mode.el
@@ -300,7 +300,7 @@ Currently-active file is at the head of the list.")
("\C-c\C-p" . py-previous-statement)
("\C-c\C-u" . py-goto-block-up)
("\C-c\C-m" . py-mark-block)
- ("\C-c#" . comment-region)
+ ("\C-c#" . py-comment-region)
("\C-c?" . py-describe-mode)
("\C-c\C-hm" . py-describe-mode)
("\e\C-a" . beginning-of-python-def-or-class)
@@ -455,7 +455,7 @@ py-beep-if-tab-change\t\tring the bell if tab-width is changed"
'((paragraph-separate . "^[ \t]*$")
(paragraph-start . "^[ \t]*$")
(require-final-newline . t)
- (comment-start . "## ")
+ (comment-start . "# ")
(comment-start-skip . "# *")
(comment-column . 40)
(indent-region-function . py-indent-region)
@@ -886,10 +886,39 @@ the new line indented."
(1+ (current-column))))))
;; not on a continuation line
-
- ;; if at start of restriction, or on a non-indenting comment
- ;; line, assume they intended whatever's there
- ((or (bobp) (looking-at "[ \t]*#[^ \t\n]"))
+ ((bobp) (current-indentation))
+
+ ;; Dfn: "Indenting comment line". A line containing only a
+ ;; comment, but which is treated like a statement for
+ ;; indentation calculation purposes. Such lines are only
+ ;; treated specially by the mode; they are not treated
+ ;; specially by the Python interpreter.
+
+ ;; The rules for indenting comment lines are a line where:
+ ;; - the first non-whitespace character is `#', and
+ ;; - the character following the `#' is whitespace, and
+ ;; - the line is outdented with respect to (i.e. to the left
+ ;; of) the indentation of the preceding non-blank line.
+
+ ;; The first non-blank line following an indenting comment
+ ;; line is given the same amount of indentation as the
+ ;; indenting comment line.
+
+ ;; All other comment-only lines are ignored for indentation
+ ;; purposes.
+
+ ;; Are we looking at a comment-only line which is *not* an
+ ;; indenting comment line? If so, we assume that its been
+ ;; placed at the desired indentation, so leave it alone.
+ ;; Indenting comment lines are aligned as statements down
+ ;; below.
+ ((and (looking-at "[ \t]*#[^ \t\n]")
+ ;; NOTE: this test will not be performed in older Emacsen
+ (fboundp 'forward-comment)
+ (<= (current-indentation)
+ (save-excursion
+ (forward-comment (- (point-max)))
+ (current-indentation))))
(current-indentation))
;; else indentation based on that of the statement that
@@ -1114,6 +1143,12 @@ initial line; and comment lines beginning in column 1 are ignored."
(forward-line 1))))
(set-marker end nil))
+(defun py-comment-region (beg end &optional arg)
+ "Like `comment-region' but uses double hash (`#') comment starter."
+ (interactive "r\nP")
+ (let ((comment-start "## "))
+ (comment-region beg end arg)))
+
;; Functions for moving point
(defun py-previous-statement (count)