473,545 Members | 4,917 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4498
On 2008-06-11, Grant Edwards <gr****@visi.co mwrote:
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.co mwrites:
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.********@gma il.comwrote:
Grant Edwards <gr****@visi.co mwrites:
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
33348
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro capabilities, unfortunately. I'd like to know if it may be possible to add a powerful macro system to Python, while keeping its amazing syntax, and if it...
3
2758
by: porterboy | last post by:
CONTEXT: I am using Emacs to edit Python code and sometimes also Matlab code. When I hit <return> in a loop of some sort, Emacs usually gets the nesting indentation right, which is particularly important in Python. To ensure this I have used python-mode.el and matlab.el modes in emacs. QUESTION: If I suddenly decide I want an outer loop,...
1
3408
by: gjohannes | last post by:
Hi. I use Idle 1.1.1 on Python 2.4.1. The "Ctrl-" key bindings for indenting do not work on non-us keyboards where brackets are accessed by the "Alt Gr" key. The Tab key seem to work for indenting a selected textblock on my swedish keyboard, but Shift-tab does not dedent as you would have expected.
1
1759
by: damonwischik | last post by:
I'm using GNU Emacs 21.3.1 with python-mode 1.0alpha under Windows XP. Whenever I execute a command in an edit window (with py-execute-region), the output window steals the focus. How can I stop this happening? I don't know any lisp, but I hacked together this routine so that that when I press ctrl+return the entire current block is...
7
3261
by: Xah Lee | last post by:
Summary: when encountering ex as a unit in css, FireFox (and iCab) did not take into account the font-family. Detail: http://xahlee.org/js/ff_pre_ex.html Xah xah@xahlee.org ∑ http://xahlee.org/
0
1165
by: kevin bailey | last post by:
Hi, Using emacs21 on Debian Sarge. I've installed html-helper-mode which can be used in emacs and generates a template file when visiting a new file with .html as an extension. However, indent-region does not seem to work. Any news on this?
15
2896
by: Tom Plunket | last post by:
The documentation for dedent says, "Remove any whitespace than can be uniformly removed from the left of every line in `text`", yet I'm finding that it's also modifying the '\t' characters, which is highly undesirable in my application. Is there any way to stop it from doing this, or alternatively, to put those tabs back in? I see that...
0
1243
by: xahlee | last post by:
Here's a little tutorial that lets you write emacs commands for processing the current text selection in emacs in your favorite lang. Elisp Wrapper For Perl Scripts http://xahlee.org/emacs/elisp_perl_wrapper.html plain text version follows. ------------------------------------- Elisp Wrapper For Perl Scripts
0
816
by: Malte Helmert | last post by:
skip@pobox.com wrote: One of the two modes (if memory serves, python.el) has an annoying bug/feature where indent-region is essentially implemented as "hit tab once on every line in the region". Of course, this frequently does the wrong thing as "tab" has to guess the right indentation in cases where there are multiple possibilities. So...
0
7464
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7751
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
4943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1874
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
700
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.