By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,532 Members | 1,483 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,532 IT Pros & Developers. It's quick & easy.

how to indent/dedent a region in emacs?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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.