473,747 Members | 2,762 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

automatic nesting and indentation in emacs

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, do I have to manually
readjust the indentation of all the inner loops? Or can emacs do it
automatically? I know the Matlab in-built editor has a tool called
"smart-indent" which will automatically align highlighted text to have
the correct indentation. Does Emacs have something similar?

Thanks
The Porterboy - "Lovely day for a Guinness"
Jul 18 '05 #1
3 2767
po*********@yah oo.com (porterboy) writes:
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, do I have to manually
readjust the indentation of all the inner loops? Or can emacs do it
automatically? I know the Matlab in-built editor has a tool called
"smart-indent" which will automatically align highlighted text to have
the correct indentation. Does Emacs have something similar?


Mark the lines to be readjusted, then hit 'C-c >' or 'C-c <'.
Or hit 'C-h m' to get an overview for Python mode.

Thomas
Jul 18 '05 #2
>>>>> Thomas Heller <th*****@python .net> writes:
po*********@yah oo.com (porterboy) writes:
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, do I have
to manually readjust the indentation of all the inner loops? Or
can emacs do it automatically? I know the Matlab in-built
editor has a tool called "smart-indent" which will
automatically align highlighted text to have the correct
indentation. Does Emacs have something similar?
Mark the lines to be readjusted, then hit 'C-c >' or 'C-c <'.
Or hit 'C-h m' to get an overview for Python mode. Thomas

I've liked the XEmacs python mode, as it is doesn't trigger the nasty
readline dependency. Possibly fixed.
At any rate, with a region selected, "C-c >" and "C-c <" do the
obvious.
Two other killer features of the One True Editor are rectangles,
e.g. "C-x r o" with a highlighted region, align-regexp, and registers.
Three! Three killer features of TOTE are rectangles, align-regexp,
registers, and PyMacs.
Oh! I'll just give up on the feeble Spanish Inquisition reference and
send you to http://www.emacswiki.org , where these and other righteous
goodies will, indeed, sanctify you within the bosom of the only editor
that has its own house of worship.
Best,
Chris
Jul 18 '05 #3
In emacs matlab-mode, highlight a region then use indent-region:

C-M-\ runs the command indent-region
which is an interactive compiled Lisp function in `indent'.
(indent-region START END COLUMN)

Indent each nonblank line in the region.
With prefix no argument, indent each line using `indent-according-to-mode',
or use `indent-region-function' to do the whole region if that's non-nil.
If there is a fill prefix, make each line start with the fill prefix.
With argument COLUMN, indent each line to that column.

When you call this from a program, START and END specify
the region to indent, and COLUMN specifies the indentation column.
If COLUMN is nil, then indent each line according to the mode.

porterboy wrote:
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, do I have to manually
readjust the indentation of all the inner loops? Or can emacs do it
automatically? I know the Matlab in-built editor has a tool called
"smart-indent" which will automatically align highlighted text to have
the correct indentation. Does Emacs have something similar?

Thanks
The Porterboy - "Lovely day for a Guinness"

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
2141
by: Hilbert | last post by:
Hello, I'm using python to output RIB streams for Renderman. The RIB stream is a bunch of statements which describes a 3d image. The Rib standard allows for blocks which we usually indent for better visualization for example: WorldBegin Color Surface "constant"
6
2904
by: David Lees | last post by:
I have a real basic how-to question. When I decide to reuse a piece of python code at a different indentation level than the original, is there a common trick (or set of tricks) for moving the indentation correctly for the whole block? Probably this is editor dependent, so if some has a FAQ or pointer to a page please feel free to post. Typical I use PythonWin as my editor, though sometimes I use EditPadLite (an ascii editor). TIA
6
1852
by: Xah Lee | last post by:
does anyone know why the Python mode in emacs uses spaces for first level indentation but one tab for second level? i'm using emacs 21.3.50.1. Xah xah@xahlee.org http://xahlee.org/PageTwo_dir/more.html
1
1239
by: leap | last post by:
I'm very new to XML, and have only spent about 10 minutes looking for something I already know I want. Pardon me if the availability of what I want is common knowledge among XML cognoscenti. My subject line doesn't really do justice to my meaning. What I want is an editor for XML that displays XML with a lot less redundancy.
21
1660
by: Asfand Yar Qazi | last post by:
Hi, After much use of tabs worth 8 spaces, and constantly having to format my C++ code in funny ways to keep all lines within an 80 character line length limit, I'm seriously thinking of switching to using 4 spaces per tab. I feel like I'm about to lose a a long suffering faithful companion... What are your views on this? Any words of sympathy? :0)
10
1950
by: name | last post by:
When I started testing the algorithms for my wrap program, I threw together this snippet of code, which works quite well. Except that it (predictably) segfaults at the end when it tries to go beyond the file. At some point, I tried to mend that behavior using feof() but without success. The functionality is not harmed, but this has started to bug me. What am I missing here? Sometimes being a code duffer is frustrating!! lol!!! The...
135
7506
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about which is better. It has become what's known as “religious war” — a heated fight over trivia. In this essay, i like to explain what is the situation behind it, and which is proper.
1
1685
by: Eric S. Johansson | last post by:
in trying to make programming in Python more accessible to disabled programmers (specifically mobility impaired speech recognition users), and hitting a bit of a wall. The wall (for today) is indentation. I need a method of getting the "right indentation" without having to speak a bunch of unnecessary commands. For example, depth specified by the previous line. But, frequently you need to go to a more arbitrary indentation for example...
19
2104
by: Eric S. Johansson | last post by:
Almar Klein wrote: there's nothing like self interest to drive one's initiative. :-) 14 years with speech recognition and counting. I'm so looking to my 15th anniversary of being injured next year.... another initiative is exporting the speech recognition environment to the Linux context. In a nutshell, he dictated to application on Windows, it tunnels over the network to a Linux machine, and will allow you to cut and paste to and...
0
8979
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, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8818
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9307
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9223
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6067
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4588
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4860
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3296
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
2
2771
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.