Emacs Python indention
Bastian Ballmann
balle at chaostal.de
Sat Jun 11 16:43:11 EDT 2011
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)
)
)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20110611/f30e41d8/attachment.sig>
More information about the Python-list
mailing list