473,946 Members | 12,844 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 2778
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
2162
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
2913
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
1859
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
1245
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
1682
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
1971
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
7635
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
1697
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
2122
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
9981
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,...
0
11566
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10688
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
9886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8253
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6331
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4941
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
4533
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3541
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.