[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: |
Mon, 25 Jun 2007 22:20:05 +0200 |
Paul Pogonyshev <address@hidden> writes:
> Yeah. In principle, I could write backtab function in my .emacs as
> well. But don't you agree that if I press Shift+Tab and nothing in
> the buffer changes, not even the point position, it looks like a
> little broken?
Please try this patch instead of the previous one:
2007-06-25 Markus Triska <address@hidden>
* progmodes/python.el (python-indent-propose): new function
(python-indent-line-dir): generalise python-indent-line, cycling
in given direction
(python-indent-line-backward): new function
(python-indent-line): dispatch to python-indent-line
*** python.el 24 Jun 2007 22:43:05 +0200 1.62
--- python.el 25 Jun 2007 22:13:07 +0200
***************
*** 197,202 ****
--- 197,203 ----
;; Mostly taken from python-mode.el.
(define-key map ":" 'python-electric-colon)
(define-key map "\177" 'python-backspace)
+ (define-key map [backtab] 'python-indent-line-backward)
(define-key map "\C-c<" 'python-shift-left)
(define-key map "\C-c>" 'python-shift-right)
(define-key map "\C-c\C-k" 'python-mark-block)
***************
*** 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,751 ----
(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 cycle."
(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))
! (python-indent-propose)))
! (if (and (= dir -1)
! (= (current-indentation) (python-calculate-indentation))
! (> python-indent-list-length 1))
! (progn
! (setq python-indent-index (- python-indent-list-length 2))
! (python-indent-propose))
! (setq python-indent-index (1- python-indent-list-length))
! (python-indent-line-1)))))
!
! (defun python-indent-propose ()
! "Propose indentation alternative `python-indent-index'."
! (beginning-of-line)
! (delete-horizontal-space)
! (indent-to (car (nth python-indent-index python-indent-list)))
! (when (python-block-end-p)
! (let ((text (cdr (nth python-indent-index python-indent-list))))
! (when text
! (message "Closes: %s" text)))))
(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, 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/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 <=
- 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