unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
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: Mon, 25 Jun 2007 22:36:17 +0200	[thread overview]
Message-ID: <867ipr4vr2.fsf@gmx.at> (raw)
In-Reply-To: <200706252344.54496.pogonyshev@gmx.net> (Paul Pogonyshev's message of "Mon\, 25 Jun 2007 23\:44\:54 +0300")

Paul Pogonyshev <pogonyshev@gmx.net> writes:

> doesn't work at all

Sorry, I meant:

2007-06-25  Markus Triska  <markus.triska@gmx.at>

	* 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-dir


*** python.el	24 Jun 2007 22:43:05 +0200	1.62
--- python.el	25 Jun 2007 22:34:10 +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))
! 	(python-indent-line-1)
! 	(setq python-indent-index (1- python-indent-list-length))))))
! 
! (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.

  reply	other threads:[~2007-06-25 20:36 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
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 [this message]
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=867ipr4vr2.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).