mirror of
https://github.com/python/cpython.git
synced 2026-01-06 15:32:22 +00:00
Barry's 2.16 -- more electric colon cruft, add py-outdent-left
and py_indent-right
This commit is contained in:
parent
d97cc37489
commit
2ed5354792
1 changed files with 55 additions and 10 deletions
|
|
@ -6,8 +6,8 @@
|
|||
;; 1992-1994 Tim Peters <tim@ksr.com>
|
||||
;; Maintainer: bwarsaw@cnri.reston.va.us
|
||||
;; Created: Feb 1992
|
||||
;; Version: 2.13
|
||||
;; Last Modified: 1995/03/14 22:05:53
|
||||
;; Version: 2.16
|
||||
;; Last Modified: 1995/03/15 16:23:59
|
||||
;; Keywords: python editing language major-mode
|
||||
|
||||
;; This software is provided as-is, without express or implied
|
||||
|
|
@ -48,6 +48,7 @@
|
|||
;; - proper interaction with pending-del and del-sel modes.
|
||||
;; - New py-electric-colon (:) command for improved outdenting. Also
|
||||
;; py-indent-line (TAB) should handle outdented lines better.
|
||||
;; - New commands py-outdent-left (C-c C-l) and py-indent-right (C-c C-r)
|
||||
|
||||
;; Here's a brief to do list:
|
||||
;;
|
||||
|
|
@ -68,7 +69,7 @@
|
|||
;; LCD Archive Entry:
|
||||
;; python-mode|Barry A. Warsaw|bwarsaw@cnri.reston.va.us
|
||||
;; |Major mode for editing Python programs
|
||||
;; |1995/03/14 22:05:53|2.13|
|
||||
;; |1995/03/15 16:23:59|2.16|
|
||||
|
||||
;;; Code:
|
||||
|
||||
|
|
@ -247,6 +248,8 @@ Currently-active file is at the head of the list.")
|
|||
("\n" . py-newline-and-indent)
|
||||
("\C-c:" . py-guess-indent-offset)
|
||||
("\C-c\t" . py-indent-region)
|
||||
("\C-c\C-l" . py-outdent-left)
|
||||
("\C-c\C-r" . py-indent-right)
|
||||
("\C-c<" . py-shift-region-left)
|
||||
("\C-c>" . py-shift-region-right)
|
||||
("\C-c\C-n" . py-next-statement)
|
||||
|
|
@ -319,7 +322,7 @@ Currently-active file is at the head of the list.")
|
|||
|
||||
(defconst py-no-outdent-re
|
||||
(concat "\\(" (mapconcat 'identity
|
||||
'("try\\s +.*:"
|
||||
'("try:"
|
||||
"except\\(\\s +.*\\)?:"
|
||||
"while\\s +.*:"
|
||||
"for\\s +.*:"
|
||||
|
|
@ -433,11 +436,53 @@ argument is provided, that many colons are inserted non-electrically."
|
|||
(py-compute-indentation)))
|
||||
)
|
||||
(setq outdent py-indent-offset))
|
||||
(goto-char here)
|
||||
(beginning-of-line)
|
||||
(delete-horizontal-space)
|
||||
(indent-to (- indent outdent))
|
||||
)))
|
||||
;; electric colon won't re-indent lines that start in column
|
||||
;; zero. you'd have to use TAB for that. TBD: Is there a
|
||||
;; better way to determine this???
|
||||
(if (zerop (current-indentation)) nil
|
||||
(goto-char here)
|
||||
(beginning-of-line)
|
||||
(delete-horizontal-space)
|
||||
(indent-to (- indent outdent))
|
||||
))))
|
||||
|
||||
(defun py-indent-right (arg)
|
||||
"Indent the line by one `py-indent-offset' level.
|
||||
With numeric arg, indent by that many levels. You cannot indent
|
||||
farther right than the distance the line would be indented by
|
||||
\\[py-indent-line]."
|
||||
(interactive "p")
|
||||
(let ((col (current-indentation))
|
||||
(want (* arg py-indent-offset))
|
||||
(indent (py-compute-indentation))
|
||||
(pos (- (point-max) (point)))
|
||||
(bol (save-excursion (beginning-of-line) (point))))
|
||||
(if (<= (+ col want) indent)
|
||||
(progn
|
||||
(beginning-of-line)
|
||||
(delete-horizontal-space)
|
||||
(indent-to (+ col want))
|
||||
(if (> (- (point-max) pos) (point))
|
||||
(goto-char (- (point-max) pos)))
|
||||
))))
|
||||
|
||||
(defun py-outdent-left (arg)
|
||||
"Outdent the line by one `py-indent-offset' level.
|
||||
With numeric arg, outdent by that many levels. You cannot outdent
|
||||
farther left than column zero."
|
||||
(interactive "p")
|
||||
(let ((col (current-indentation))
|
||||
(want (* arg py-indent-offset))
|
||||
(pos (- (point-max) (point)))
|
||||
(bol (save-excursion (beginning-of-line) (point))))
|
||||
(if (<= 0 (- col want))
|
||||
(progn
|
||||
(beginning-of-line)
|
||||
(delete-horizontal-space)
|
||||
(indent-to (- col want))
|
||||
(if (> (- (point-max) pos) (point))
|
||||
(goto-char (- (point-max) pos)))
|
||||
))))
|
||||
|
||||
|
||||
;;; Functions that execute Python commands in a subprocess
|
||||
|
|
@ -1863,7 +1908,7 @@ local bindings to py-newline-and-indent."))
|
|||
(setq zmacs-region-stays t)))
|
||||
|
||||
|
||||
(defconst py-version "2.13"
|
||||
(defconst py-version "2.16"
|
||||
"`python-mode' version number.")
|
||||
(defconst py-help-address "bwarsaw@cnri.reston.va.us"
|
||||
"Address accepting submission of bug reports.")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue