Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7461 > unrolled thread

Emacs Python indention

Started byBastian Ballmann <balle@chaostal.de>
First post2011-06-11 22:43 +0200
Last post2011-06-11 22:43 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Emacs Python indention Bastian Ballmann <balle@chaostal.de> - 2011-06-11 22:43 +0200

#7461 — Emacs Python indention

FromBastian Ballmann <balle@chaostal.de>
Date2011-06-11 22:43 +0200
SubjectEmacs Python indention
Message-ID<mailman.138.1307825044.11593.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

Hi Emacs / Python coders,

moving a region of python code for more than one indention in Emacs is
quite annoying, cause the python-shift-left and -right functions always
loose the mark and one has to reactivate it with \C-x \C-x or
guess how many indentions one want to make and do a \C-u <nr> \C-c >

That were the only solutions I found on the net and well both are
not very comfortable so here's a fix for that. With the following code
you can use \C-c left and right to move your Python code to the left
and to the right :)
HF

Basti


(defun balle-python-shift-left ()
  (interactive)
  (let (start end bds)
    (if (and transient-mark-mode
           mark-active)
	(setq start (region-beginning) end (region-end))
      (progn
	(setq bds (bounds-of-thing-at-point 'line))
	(setq start (car bds) end (cdr bds))))
  (python-shift-left start end))
  (setq deactivate-mark nil)
)                                                                                                                                     
(defun balle-python-shift-right ()
  (interactive)
  (let (start end bds)
    (if (and transient-mark-mode
           mark-active)
	(setq start (region-beginning) end (region-end))
      (progn
	(setq bds (bounds-of-thing-at-point 'line))
	(setq start (car bds) end (cdr bds))))
  (python-shift-right start end))
  (setq deactivate-mark nil)
)                                                                                                                                     

(add-hook 'python-mode-hook 
	  (lambda ()
	    (define-key python-mode-map (kbd "C-c <right>")
	    'balle-python-shift-right) 
            (define-key python-mode-map (kbd "C-c <left>")
            'balle-python-shift-left)
          )
)

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web