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


Groups > comp.lang.python > #7461

Emacs Python indention

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <balle@chaostal.de>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.016
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'subject:Python': 0.06; 'python': 0.08; 'content-type:multipart/signed': 0.09; 'reactivate': 0.09; '(lambda': 0.16; 'content-type:application /pgp-signature': 0.16; 'emacs': 0.16; 'filename:fname piece:asc': 0.16; 'filename:fname piece:signature': 0.16; 'filename:fname:signature.asc': 0.16; 'guess': 0.19; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'sfxlen:0': 0.23; 'fix': 0.23; 'skip:b 20': 0.23; 'code': 0.24; '(and': 0.25; 'moving': 0.26; 'comfortable': 0.29; 'skip:( 20': 0.30; "skip:' 10": 0.32; 'to:addr:python-list': 0.33; 'quite': 0.36; 'charset:us-ascii': 0.36; 'header:Mime-Version:1': 0.39; 'to:addr:python.org': 0.39; 'more': 0.60; 'your': 0.60; 'cause': 0.67; 'loose': 0.67; 'region': 0.67; 'received:93': 0.80; '(let': 0.84
Date Sat, 11 Jun 2011 22:43:11 +0200
From Bastian Ballmann <balle@chaostal.de>
To python-list@python.org
Subject Emacs Python indention
X-Mailer Claws Mail 3.7.9 (GTK+ 2.24.4; i686-pc-linux-gnu)
Mime-Version 1.0
Content-Type multipart/signed; micalg=PGP-SHA1; boundary="Sig_/by1cgmtcYSLGoIwBpMM0=ff"; protocol="application/pgp-signature"
X-Virus-Scanned Debian amavisd-new at lucy.chaostal.de
Cc help-gnu-emacs@gnu.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.138.1307825044.11593.python-list@python.org> (permalink)
Lines 69
NNTP-Posting-Host 82.94.164.166
X-Trace 1307825044 news.xs4all.nl 49047 [::ffff:82.94.164.166]:44963
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:7461

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web