From: Markus Triska <markus.triska@gmx.at>
To: Paul Pogonyshev <pogonyshev@gmx.net>
Cc: emacs-devel@gnu.org
Subject: Re: dedent in Python-mode
Date: Sun, 24 Jun 2007 23:30:43 +0200 [thread overview]
Message-ID: <86ir9doxa4.fsf@gmx.at> (raw)
In-Reply-To: <200706242344.06799.pogonyshev@gmx.net> (Paul Pogonyshev's message of "Sun\, 24 Jun 2007 23\:44\:06 +0300")
Paul Pogonyshev <pogonyshev@gmx.net> 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 <markus.triska@gmx.at>
* 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.
next prev parent reply other threads:[~2007-06-24 21:30 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-06-24 20:44 dedent in Python-mode Paul Pogonyshev
2007-06-24 21:30 ` Markus Triska [this message]
2007-06-24 21:56 ` Paul Pogonyshev
2007-06-24 22:08 ` Markus Triska
2007-06-24 22:30 ` Paul Pogonyshev
2007-06-24 23:44 ` Markus Triska
2007-06-25 18:18 ` Paul Pogonyshev
2007-06-25 20:20 ` Markus Triska
2007-06-25 20:44 ` Paul Pogonyshev
2007-06-25 20:36 ` Markus Triska
2007-06-25 21:07 ` Paul Pogonyshev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86ir9doxa4.fsf@gmx.at \
--to=markus.triska@gmx.at \
--cc=emacs-devel@gnu.org \
--cc=pogonyshev@gmx.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).