Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ed5354

Browse files
committed
Barry's 2.16 -- more electric colon cruft, add py-outdent-left
and py_indent-right
1 parent d97cc37 commit 2ed5354

1 file changed

Lines changed: 55 additions & 10 deletions

File tree

Misc/python-mode-old.el

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
;; 1992-1994 Tim Peters <[email protected]>
77
;; Maintainer: [email protected]
88
;; Created: Feb 1992
9-
;; Version: 2.13
10-
;; Last Modified: 1995/03/14 22:05:53
9+
;; Version: 2.16
10+
;; Last Modified: 1995/03/15 16:23:59
1111
;; Keywords: python editing language major-mode
1212

1313
;; This software is provided as-is, without express or implied
@@ -48,6 +48,7 @@
4848
;; - proper interaction with pending-del and del-sel modes.
4949
;; - New py-electric-colon (:) command for improved outdenting. Also
5050
;; py-indent-line (TAB) should handle outdented lines better.
51+
;; - New commands py-outdent-left (C-c C-l) and py-indent-right (C-c C-r)
5152

5253
;; Here's a brief to do list:
5354
;;
@@ -68,7 +69,7 @@
6869
;; LCD Archive Entry:
6970
;; python-mode|Barry A. Warsaw|[email protected]
7071
;; |Major mode for editing Python programs
71-
;; |1995/03/14 22:05:53|2.13|
72+
;; |1995/03/15 16:23:59|2.16|
7273

7374
;;; Code:
7475

@@ -247,6 +248,8 @@ Currently-active file is at the head of the list.")
247248
("\n" . py-newline-and-indent)
248249
("\C-c:" . py-guess-indent-offset)
249250
("\C-c\t" . py-indent-region)
251+
("\C-c\C-l" . py-outdent-left)
252+
("\C-c\C-r" . py-indent-right)
250253
("\C-c<" . py-shift-region-left)
251254
("\C-c>" . py-shift-region-right)
252255
("\C-c\C-n" . py-next-statement)
@@ -319,7 +322,7 @@ Currently-active file is at the head of the list.")
319322

320323
(defconst py-no-outdent-re
321324
(concat "\\(" (mapconcat 'identity
322-
'("try\\s +.*:"
325+
'("try:"
323326
"except\\(\\s +.*\\)?:"
324327
"while\\s +.*:"
325328
"for\\s +.*:"
@@ -433,11 +436,53 @@ argument is provided, that many colons are inserted non-electrically."
433436
(py-compute-indentation)))
434437
)
435438
(setq outdent py-indent-offset))
436-
(goto-char here)
437-
(beginning-of-line)
438-
(delete-horizontal-space)
439-
(indent-to (- indent outdent))
440-
)))
439+
;; electric colon won't re-indent lines that start in column
440+
;; zero. you'd have to use TAB for that. TBD: Is there a
441+
;; better way to determine this???
442+
(if (zerop (current-indentation)) nil
443+
(goto-char here)
444+
(beginning-of-line)
445+
(delete-horizontal-space)
446+
(indent-to (- indent outdent))
447+
))))
448+
449+
(defun py-indent-right (arg)
450+
"Indent the line by one `py-indent-offset' level.
451+
With numeric arg, indent by that many levels. You cannot indent
452+
farther right than the distance the line would be indented by
453+
\\[py-indent-line]."
454+
(interactive "p")
455+
(let ((col (current-indentation))
456+
(want (* arg py-indent-offset))
457+
(indent (py-compute-indentation))
458+
(pos (- (point-max) (point)))
459+
(bol (save-excursion (beginning-of-line) (point))))
460+
(if (<= (+ col want) indent)
461+
(progn
462+
(beginning-of-line)
463+
(delete-horizontal-space)
464+
(indent-to (+ col want))
465+
(if (> (- (point-max) pos) (point))
466+
(goto-char (- (point-max) pos)))
467+
))))
468+
469+
(defun py-outdent-left (arg)
470+
"Outdent the line by one `py-indent-offset' level.
471+
With numeric arg, outdent by that many levels. You cannot outdent
472+
farther left than column zero."
473+
(interactive "p")
474+
(let ((col (current-indentation))
475+
(want (* arg py-indent-offset))
476+
(pos (- (point-max) (point)))
477+
(bol (save-excursion (beginning-of-line) (point))))
478+
(if (<= 0 (- col want))
479+
(progn
480+
(beginning-of-line)
481+
(delete-horizontal-space)
482+
(indent-to (- col want))
483+
(if (> (- (point-max) pos) (point))
484+
(goto-char (- (point-max) pos)))
485+
))))
441486

442487

443488
;;; Functions that execute Python commands in a subprocess
@@ -1863,7 +1908,7 @@ local bindings to py-newline-and-indent."))
18631908
(setq zmacs-region-stays t)))
18641909

18651910

1866-
(defconst py-version "2.13"
1911+
(defconst py-version "2.16"
18671912
"`python-mode' version number.")
18681913
(defconst py-help-address "[email protected]"
18691914
"Address accepting submission of bug reports.")

0 commit comments

Comments
 (0)