automatic nesting and indentation in emacs

P

porterboy

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"
 
T

Thomas Heller

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
 
C

Chris Smith

> 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.
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
 
B

Ben Barrowes

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top