472,143 Members | 1,499 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

how to indent/dedent a region in emacs?

I've recently switched from Jed to Emacs for editing python
source, and I'm still stumped as to how one indents or dedents
a region of code. In Jed it's 'C-c <' or 'C-c >'. Google has
found several answers, but none of them work, for example I've
tried bot "C-c tab" and "C-c C-r" based on postings Google has
found, but neither appears to actually _do_ anyting.

--
Grant Edwards grante Yow! You were s'posed
at to laugh!
visi.com
Jun 27 '08 #1
3 4391
On 2008-06-11, Grant Edwards <gr****@visi.comwrote:
I've recently switched from Jed to Emacs for editing python
source, and I'm still stumped as to how one indents or dedents
a region of code. In Jed it's 'C-c <' or 'C-c >'. Google has
found several answers, but none of them work, for example I've
tried bot "C-c tab" and "C-c C-r" based on postings Google has
found, but neither appears to actually _do_ anyting.
Doh! It's 'C-c <' and 'C-c >' just like in Jed. I swear that
didn't work the first time I tried it...

--
Grant Edwards grante Yow! An air of FRENCH FRIES
at permeates my nostrils!!
visi.com
Jun 27 '08 #2
Grant Edwards <gr****@visi.comwrites:
I've recently switched from Jed to Emacs for editing python
source, and I'm still stumped as to how one indents or dedents
a region of code. In Jed it's 'C-c <' or 'C-c >'. Google has
found several answers, but none of them work, for example I've
tried bot "C-c tab" and "C-c C-r" based on postings Google has
found, but neither appears to actually _do_ anyting.
In python-mode C-c and C-c < should work as well.

(note that you have to download python-mode.el; I don't know if the above also
works with python.el which comes with emacs; C-h m will tell you which mode
you're using)

Outside python-mode, you can use string-rectangle and kill-rectangle, but
that's inconvenient, so I've globally bound the below functions to these keys
(you can just use the plain py-shift-region{-left,right} if you like them
better).
(defun my-py-shift-region-left (start end &optional count)
"Like `py-shift-region-left', but COUNT applies the command repeatedly,
instead of specifying the columns to shift."
(interactive
(let ((p (point))
(m (mark))
(arg (* py-indent-offset (or current-prefix-arg 1))))
(if m
(list (min p m) (max p m) arg)
(list p (save-excursion (forward-line 1) (point)) arg))))
;; if any line is at column zero, don't shift the region
(save-excursion
(goto-char start)
(while (< (point) end)
(back-to-indentation)
(when (and (< (current-column) count)
(not (looking-at "\\s *$")))
(error "Not enough left margin"))
(forward-line 1)))
(py-shift-region start end (- (prefix-numeric-value
(or count))))
(py-keep-region-active))
(defun my-py-shift-region-right (start end &optional count)
"Like `py-shift-region-right', but COUNT applies the command repeatedly,
instead of specifying the columns to shift."
(interactive
(let ((p (point))
(m (mark))
(arg current-prefix-arg))
(if m
(list (min p m) (max p m) arg)
(list p (save-excursion (forward-line 1) (point)) arg))))
(py-shift-region start end (prefix-numeric-value
(or count py-indent-offset)))
(py-keep-region-active))
'as
Jun 27 '08 #3
On 2008-06-11, Alexander Schmolck <a.********@gmail.comwrote:
Grant Edwards <gr****@visi.comwrites:
>I've recently switched from Jed to Emacs for editing python
source, and I'm still stumped as to how one indents or dedents
a region of code. In Jed it's 'C-c <' or 'C-c >'. Google has
found several answers, but none of them work, for example I've
tried bot "C-c tab" and "C-c C-r" based on postings Google has
found, but neither appears to actually _do_ anyting.

In python-mode C-c and C-c < should work as well.
It does. I'm still baffled as to how I initially convinced
myself it didn't...
(note that you have to download python-mode.el; I don't know
if the above also works with python.el which comes with emacs;
Yes, it does.
C-h m will tell you which mode you're using)
I don't remember installing python-mode.el, and what comes up
when I hit C-h m matches what's in /usr/share/emacs/22.2/lisp/progmodes/python.el
Outside python-mode, you can use string-rectangle and
kill-rectangle, but that's inconvenient, so I've globally
bound the below functions to these keys (you can just use the
plain py-shift-region{-left,right} if you like them better).
Thanks, I'll make a note of those...

--
Grant Edwards grante Yow! Why is everything made
at of Lycra Spandex?
visi.com
Jun 27 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

699 posts views Thread by mike420 | last post: by
3 posts views Thread by porterboy | last post: by
1 post views Thread by damonwischik | last post: by
7 posts views Thread by Xah Lee | last post: by
reply views Thread by kevin bailey | last post: by
15 posts views Thread by Tom Plunket | last post: by
reply views Thread by xahlee | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.