help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: turning off all indentation


From: Alan Mackenzie
Subject: Re: turning off all indentation
Date: Wed, 08 Dec 2010 15:08:08 -0000
User-agent: tin/1.6.2-20030910 ("Pabbay") (UNIX) (FreeBSD/4.11-RELEASE (i386))

Hi, Lynn,

Lynn Newton <lynn.newton@gmail.com> wrote:
>> (add-hook 'after-change-major-mode-hook
>> ? ? ? ? ? (lambda nil
>> ? ? ? ? ? ? (local-set-key [return] nil)
>> ? ? ? ? ? ? (local-set-key [tab] nil)))

> With this, if I start up Emacs and start to edit a file myfile.c,
> I get this far:

> main()
> {
>        int i

> Pretend there's a tab in front of int. When I add a semicolon to that
> line, it backindents it to column 2 (counting from 0), which is what I
> meant about the local modes taking over.

To configure CC Mode not to this, turn off CC Mode's "electric mode", as
described on pages "Minor Modes" and  "Getting Started" in the CC Mode
manual.  Or, if you can't be bothered with the manual, stick this in your
.emacs:

    (setq-default c-electric-flag nil)

.  By default, <CR> just inserts a new line; it doesn't put any
indentation on the new line.

> If I edit a plain text file, e.g., myfile.txt or without an extension,
> a tab indents me only four spaces. If a line is indented more spaces,
> typing a tab on the line below indents the next line to whatever column
> the previous line is indented to.

It's actually cleverer than that; it indents the new line to the
syntactically right place.

> Mind you, I think that's clever and wonderful, but what my friend wants
> is whenever he presses a TAB key, in whatever mode, and in whatever
> context, it skips to the next 8-character tab stop, regardless of the
> mode, the position of the line above, etc.

There's no way of doing this for EVERY mode, because the modes don't
invoke indentation in the same way.  It can be done for _each_ mode in a
small finite set.  To make <TAB> insert a tab in CC Mode, put this into
your .emacs:

    (eval-after-load 'cc-mode
     '(define-key c-mode-base-map ?\C-i 'tab-to-tab-stop))

(not tested).

> And whenever he hits RETURN, he wants the cursor to go to column zero
> of the next line, period, no ifs ands or buts.

This should be happening by default anyway.  Might there be something in
his .emacs which binds <CR> to `newline-and-indent'?

> And I'm pretty sure that when he hits other keys, such as semicolons,
> curly brackets, and other syntactically significant characters within
> some given mode, he wants it *not* to change the alignment of the
> current line or any other line nearby.

See above for CC Mode.

> One would think that would be pretty easy to do, but the subtleties of
> various languages and accompanying modes are so thoroughly built in
> that it's hard to escape them.  Most people consider that a Good Thing.

:-)

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]