[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: dedent in Python-mode
From: |
Markus Triska |
Subject: |
Re: dedent in Python-mode |
Date: |
Sun, 24 Jun 2007 23:30:43 +0200 |
Paul Pogonyshev <address@hidden> writes:
> With TAB I can indent a line in Python mode or, actually, cycle through
> possible indentations. Can Shift+TAB (backtab) be made to cycle through
> them in opposite direction?
Please try this patch:
2007-06-24 Markus Triska <address@hidden>
* progmodes/python.el (python-indent-line-dir): generalised
python-indent-line, cycling through indentations in given
direction
(python-indent-line): dispatch to python-indent-line-dir
(python-indent-line-backward): new function
*** python.el 24 Jun 2007 22:43:05 +0200 1.62
--- python.el 24 Jun 2007 23:19:44 +0200
***************
*** 208,213 ****
--- 208,214 ----
(define-key map "\C-c\C-v" 'python-check) ; a la sgml-mode
(define-key map "\C-c\C-s" 'python-send-string)
(define-key map [?\C-\M-x] 'python-send-defun)
+ (define-key map [backtab] 'python-indent-line-backward)
(define-key map "\C-c\C-r" 'python-send-region)
(define-key map "\C-c\M-r" 'python-send-region-and-go)
(define-key map "\C-c\C-c" 'python-send-buffer)
***************
*** 698,725 ****
(goto-char (- (point-max) pos))))))
(defun python-indent-line ()
! "Indent current line as Python code.
! When invoked via `indent-for-tab-command', cycle through possible
! indentations for current line. The cycle is broken by a command
! different from `indent-for-tab-command', i.e. successive TABs do
! the cycling."
(interactive)
! (if (and (eq this-command 'indent-for-tab-command)
! (eq last-command this-command))
! (if (= 1 python-indent-list-length)
! (message "Sole indentation")
! (progn (setq python-indent-index
! (% (1+ python-indent-index) python-indent-list-length))
! (beginning-of-line)
! (delete-horizontal-space)
! (indent-to (car (nth python-indent-index python-indent-list)))
! (if (python-block-end-p)
! (let ((text (cdr (nth python-indent-index
! python-indent-list))))
! (if text
! (message "Closes: %s" text))))))
! (python-indent-line-1)
! (setq python-indent-index (1- python-indent-list-length))))
(defun python-indent-region (start end)
"`indent-region-function' for Python.
--- 699,743 ----
(goto-char (- (point-max) pos))))))
(defun python-indent-line ()
! "Indent current line as Python code, cycling through
! indentations in forward direction. See `python-indent-line-dir'."
(interactive)
! (python-indent-line-dir 1))
!
! (defun python-indent-line-backward ()
! "Like `python-indent-line', cycling backwards."
! (interactive)
! (python-indent-line-dir -1))
!
! (defun python-indent-line-dir (dir)
! "Indent current line as Python code.
! When invoked via `python-indent-line-backward' or
! `indent-for-tab-command', cycle in direction DIR through possible
! indentations for the current line. The cycle is broken by a
! command different from those, i.e. successive (S-)TABs do the
! cycling."
! (interactive)
! (let ((cyclic '(python-indent-line-backward indent-for-tab-command)))
! (if (and (member this-command cyclic)
! (member last-command cyclic))
! (if (= 1 python-indent-list-length)
! (message "Sole indentation")
! (progn
! (setq python-indent-index
! ;; add python-indent-list-length to correctly handle
! ;; python-indent-index + dir < 0
! (% (+ python-indent-index dir python-indent-list-length)
! python-indent-list-length))
! (beginning-of-line)
! (delete-horizontal-space)
! (indent-to (car (nth python-indent-index python-indent-list)))
! (if (python-block-end-p)
! (let ((text (cdr (nth python-indent-index
! python-indent-list))))
! (if text
! (message "Closes: %s" text))))))
! (python-indent-line-1)
! (setq python-indent-index (1- python-indent-list-length)))))
(defun python-indent-region (start end)
"`indent-region-function' for Python.
- dedent in Python-mode, Paul Pogonyshev, 2007/06/24
- Re: dedent in Python-mode,
Markus Triska <=
- Re: dedent in Python-mode, Paul Pogonyshev, 2007/06/24
- Re: dedent in Python-mode, Markus Triska, 2007/06/24
- Re: dedent in Python-mode, Paul Pogonyshev, 2007/06/24
- Re: dedent in Python-mode, Markus Triska, 2007/06/24
- Re: dedent in Python-mode, Paul Pogonyshev, 2007/06/25
- Re: dedent in Python-mode, Markus Triska, 2007/06/25
- Re: dedent in Python-mode, Paul Pogonyshev, 2007/06/25
- Re: dedent in Python-mode, Markus Triska, 2007/06/25
- Re: dedent in Python-mode, Paul Pogonyshev, 2007/06/25