From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Markus Triska Newsgroups: gmane.emacs.devel Subject: Re: dedent in Python-mode Date: Sun, 24 Jun 2007 23:30:43 +0200 Message-ID: <86ir9doxa4.fsf@gmx.at> References: <200706242344.06799.pogonyshev@gmx.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1182720667 24129 80.91.229.12 (24 Jun 2007 21:31:07 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Sun, 24 Jun 2007 21:31:07 +0000 (UTC) Cc: emacs-devel@gnu.org To: Paul Pogonyshev Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Jun 24 23:31:04 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1I2Zfk-0004Xu-Gg for ged-emacs-devel@m.gmane.org; Sun, 24 Jun 2007 23:31:04 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I2Zfj-0004Fc-Sj for ged-emacs-devel@m.gmane.org; Sun, 24 Jun 2007 17:31:03 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1I2Zfg-0004FI-M7 for emacs-devel@gnu.org; Sun, 24 Jun 2007 17:31:00 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1I2Zfe-0004Ev-TK for emacs-devel@gnu.org; Sun, 24 Jun 2007 17:31:00 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1I2Zfe-0004Es-Nc for emacs-devel@gnu.org; Sun, 24 Jun 2007 17:30:58 -0400 Original-Received: from mail.gmx.net ([213.165.64.20]) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1I2Zfe-0007ty-4Z for emacs-devel@gnu.org; Sun, 24 Jun 2007 17:30:58 -0400 Original-Received: (qmail invoked by alias); 24 Jun 2007 21:30:56 -0000 Original-Received: from chello062178240212.3.14.tuwien.teleweb.at (EHLO siduxbox) [62.178.240.212] by mail.gmx.net (mp023) with SMTP; 24 Jun 2007 23:30:56 +0200 X-Authenticated: #4064391 X-Provags-ID: V01U2FsdGVkX19sReUGrxdsTYcLeRn3mbjgRBHoQm6AmFM0LobS+q aJTo7vR/T7Qibh In-Reply-To: <200706242344.06799.pogonyshev@gmx.net> (Paul Pogonyshev's message of "Sun\, 24 Jun 2007 23\:44\:06 +0300") X-Y-GMX-Trusted: 0 X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:73771 Archived-At: Paul Pogonyshev 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 * 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.