unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Emacs Python indention
@ 2011-06-11 20:43 Bastian Ballmann
  2011-06-12 10:59 ` Andrea Crotti
  0 siblings, 1 reply; 2+ messages in thread
From: Bastian Ballmann @ 2011-06-11 20:43 UTC (permalink / raw)
  To: python-list; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1782 bytes --]

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)
          )
)

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Emacs Python indention
  2011-06-11 20:43 Emacs Python indention Bastian Ballmann
@ 2011-06-12 10:59 ` Andrea Crotti
  0 siblings, 0 replies; 2+ messages in thread
From: Andrea Crotti @ 2011-06-12 10:59 UTC (permalink / raw)
  To: Bastian Ballmann; +Cc: python-list, help-gnu-emacs

Bastian Ballmann <balle@chaostal.de> writes:

> 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

[...]


Nice functions...
But actually I use python-mode.el from the bzr trunk and the indentation
works really nicely, with C-c > or C-c <, and doesn't lose the mark.

Another nice thing is that often TAB does also the right thing,
indenting or unindenting if for example we add remove one level.



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-06-12 10:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-11 20:43 Emacs Python indention Bastian Ballmann
2011-06-12 10:59 ` Andrea Crotti

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).