I'd like to completely disable all automatic indentation in c, c++, and java. I do want to keep the syntax highlighting, however. What is the simplest way to do this? I do not, under any circumstances, want emacs to second-guess my own indentation, whether I type an electric character, or if I go back and add a comment later on. I use both GNU emacs and xemacs on Solaris and Linux, and GNU emacs on Windows, and I'd like (if possible) to do this with one .emacs per OS. Thanks in advance for any help anyone can provide.
On Mon Jun 25, jlangtonREMOVETORE...@sandiego.edu wrote:
> Hi, all.
> I'd like to completely disable all automatic indentation in c, c++, and > java. I do want to keep the syntax highlighting, however. What is the > simplest way to do this? I do not, under any circumstances, want emacs to > second-guess my own indentation, whether I type an electric character, or > if I go back and add a comment later on. I use both GNU emacs and xemacs > on Solaris and Linux, and GNU emacs on Windows, and I'd like (if > possible) to do this with one .emacs per OS. Thanks in advance for any > help anyone can provide.
Hmm, this seems to pop up every once in a while. I really can't understand why. `cc-mode' can be made to indent pretty much anyway one pleases.
Anyway, I've put some code that seems to do the right thing here:
On Mon, 25 Jun 2001 00:08:04 GMT, jlangtonREMOVETORE...@sandiego.edu wrote: > I'd like to completely disable all automatic indentation in c, c++, and > java. I do want to keep the syntax highlighting, however. What is the > simplest way to do this? I do not, under any circumstances, want emacs to > second-guess my own indentation, whether I type an electric character, or > if I go back and add a comment later on. I use both GNU emacs and xemacs > on Solaris and Linux, and GNU emacs on Windows, and I'd like (if > possible) to do this with one .emacs per OS. Thanks in advance for any > help anyone can provide.
Does (setq c-syntactic-indentation nil) work?
-- "I have received your new book against the human race, and thank you for it. Never was such a cleverness used in the design of making us all stupid. One longs, in reading your book, to walk on all fours." - Voltaire, on The Social Contract, in a letter of Rousseau
> I'd like to completely disable all automatic indentation in c, c++, and > java. I do want to keep the syntax highlighting, however. What is the > simplest way to do this? I do not, under any circumstances, want emacs to > second-guess my own indentation, whether I type an electric character, or > if I go back and add a comment later on. I use both GNU emacs and xemacs > on Solaris and Linux, and GNU emacs on Windows, and I'd like (if > possible) to do this with one .emacs per OS. Thanks in advance for any > help anyone can provide.
Does (setq c-syntactic-indentation nil) work?
-- "I have received your new book against the human race, and thank you for it. Never was such a cleverness used in the design of making us all stupid. One longs, in reading your book, to walk on all fours." - Voltaire, on The Social Contract, in a letter of Rousseau
>> I'd like to completely disable all automatic indentation in c, c++, and >> java. I do want to keep the syntax highlighting, however. What is the >> simplest way to do this? >Does (setq c-syntactic-indentation nil) work?
which you have to do in c-mode-common-hook, and which only works in version 5.27 or later.
also, according to the (raw) docstring ...
,---- | If nil, every line is just indented to the same level as the previous | one, and the \\[c-indent-command] command adjusts the indentation in steps | specified by `c-basic-offset'. The indentation style have no effect | in this mode, nor any of the indentation associated variables, | e.g. `c-special-indent-hook'. `----
On Mon, 25 Jun 2001, jlangtonREMOVETORE...@sandiego.edu wrote: > I'd like to completely disable all automatic indentation in c, c++, > and java. I do want to keep the syntax highlighting, however.
I strongly suggest that you investigate whether you can customize the indentation such that it matches what you would normally do. I find that being able to say C-x h C-M-\ on any piece of code to nicely indent it is an extremely useful feature. What's more, wrong indentation tells me that I've made a typo somewhere, such as forgot a `;' or `}'. In fact, for me automatic indentation is so useful that I sometimes (slightly!) modify my coding style so that automatic indentation works better.
Many things can be customized.
But if you must, you can just redefine all the keys that would normally indent:
You need to add more local-set-key statements for the other keys that might do indentation, such as `:' and `/'. And you need to add more add-hook statement for Java mode and maybe other modes.
In my experience indentation is an extremly personal thing. I never felt familiar with EMACS automatic indentation because it is totally different from what I want. You can customize almost everything but it is not possible to get indentation work correctly if you just want to have only real tab characters at the left side. This is how I indent. And I don't know why tabs are not really supported in indentation.
In some cases EMACS automatic indentation is generally not useful, especially if you edit a text coming originally from another development tool. So you get parts of the text indented in EMACS style, other parts in another style.
So I found it always absolutely frustrating if the editor modified the text I just typed in very exactly. Many thanks to the development team for the introduction of the customization variable "c-syntactic-indentation" in cc-mode 5.27. Now we can finally turn off this dreadful and time-consuming feature.
> On Mon, 25 Jun 2001, jlangtonREMOVETORE...@sandiego.edu wrote:
> > I'd like to completely disable all automatic indentation in c, c++, > > and java. I do want to keep the syntax highlighting, however.
> I strongly suggest that you investigate whether you can customize the > indentation such that it matches what you would normally do. I find > that being able to say C-x h C-M-\ on any piece of code to nicely > indent it is an extremely useful feature. What's more, wrong > indentation tells me that I've made a typo somewhere, such as forgot a > `;' or `}'. In fact, for me automatic indentation is so useful that I > sometimes (slightly!) modify my coding style so that automatic > indentation works better.
> Many things can be customized.
> But if you must, you can just redefine all the keys that would > normally indent:
> You need to add more local-set-key statements for the other keys that > might do indentation, such as `:' and `/'. And you need to add more > add-hook statement for Java mode and maybe other modes.
> kai > -- > ~/.signature: No such file or directory
Well, you can embed the default style in a eval block so things work as expected. Using tabs alone is evil, which you may discover when someone else's editor uses a different tab spacing than yours.
"Extremely personal" indentation doesn't cut the mustard in a large corporation. It doesn't even cut the mustard for small groups. But, since you've been in indentation purgatory the past few years, I'm glad that you are finally able to turn it off. I personally couldn't live without it turned on, but that's me.
If you ever were to send me source code for review, you'd get it back indented my way. :-)
On Tue, 26 Jun 2001, Torsten Müller wrote: > In my experience indentation is an extremly personal thing. I never > felt familiar with EMACS automatic indentation because it is totally > different from what I want. You can customize almost everything but > it is not possible to get indentation work correctly if you just > want to have only real tab characters at the left side. This is how > I indent. And I don't know why tabs are not really supported in > indentation.
You can easily tell Emacs to refrain from spaces in most cases. For example, if you set c-basic-offset to 4 and tab-width to 4 and indent-tabs-mode to t, then you'll get tabs (and no spaces) in most cases.
Emacs will still uses spaces in cases like this:
function_name(argument_1, argument_2);
Clearly, the second line might need spaces for indentation to the open paren -- consider what happens when you make the function name longer by one char.
But even in this case, it is possible to tell Emacs to indent like this:
function_name(argument_1, argument_2);
So what is the problem?
Fwiw, I sometimes use something like this in CPerl mode:
function_name (argument_1, argument_2);
This is useful when the function name and each argument are very very long. Note how I put the paren on the second line. I think moving the paren to the second line is a good compromise for getting automatic, good-looking indentation.
> In some cases EMACS automatic indentation is generally not useful, > especially if you edit a text coming originally from another > development tool. So you get parts of the text indented in EMACS > style, other parts in another style.
C-h x C-M-\ should take care of that -- afterwards everything is indented in Emacs style.
>Well, you can embed the default style in a eval block so things work as >expected.
this does work quite well, provided the cc-mode indentation engine is capable of doing it.
>Using tabs alone is evil, which you may discover when someone >else's editor uses a different tab spacing than yours.
and yet it is almost always completely correctable with a single command, e.g., vi's ``set ts=n''.
>"Extremely personal" indentation doesn't cut the mustard in a large >corporation. It doesn't even cut the mustard for small groups.
i've been involved in several collaborations where (usually one) loud-mouthed emacs user forced a style on the group simply because emacs could not do what had otherwise been discussed. generally i've quit such groups -- not alone due to that issue, but because any group that caves in to an individual will surely cave on other issues (often the schedule). when i head groups that type of tyranny isn't allowed.
when the group consists mostly of emacs users it's not usually an issue. heck the fsf mythos is usually so strong that gnu style is assumed rather than explicit.
when the group selects a style that emacs can attain i've been happy to let it do the work. when indent can handle it i go for something that is close in emacs and have indent make it conform -- though any tweaking is done with vi lest emacs re-indented wrongly. when neither works well enough a nil c-syntactic-indentation saves me from having to write it all in vi.
>If you ever were to send me source code for review, you'd get it back >indented my way. :-)
also not usually acceptable -- review does not imply update. it would be understandable of you to return it, un-reviewed, if it weren't sufficiently close to a style you are comfortable reading.
Tried it, but had no entire success. Even "setq c-syntactic-indentation nil" leads to indentation.
What I really want (and this was also the starting point of this discussion) is to avoid **every** EMACS manipulation on the text. Is this too much? Look, it's fine to have an automatic mechanism. In many cases you can produce some nice output with it. But I want just the possibility to turn this off. I want the possibility to control everything myself. Nobody would have a car that drives itself straight on while the driver wanted to turn right but forgot to switch on the right direction indicator. And nobody would have a car that switches on the direction indicator itself in every curve. Think about this.
(Beside this "mis-feature" of automatic indentation EMACS is a great program and I use it all the day.)
> > In my experience indentation is an extremly personal thing. I never > > felt familiar with EMACS automatic indentation because it is totally > > different from what I want. You can customize almost everything but > > it is not possible to get indentation work correctly if you just > > want to have only real tab characters at the left side. This is how > > I indent. And I don't know why tabs are not really supported in > > indentation.
> You can easily tell Emacs to refrain from spaces in most cases. For > example, if you set c-basic-offset to 4 and tab-width to 4 and > indent-tabs-mode to t, then you'll get tabs (and no spaces) in most > cases.
> Emacs will still uses spaces in cases like this:
> function_name(argument_1, > argument_2);
> Clearly, the second line might need spaces for indentation to the open > paren -- consider what happens when you make the function name longer > by one char.
> But even in this case, it is possible to tell Emacs to indent like > this:
> function_name(argument_1, > argument_2);
> So what is the problem?
> Fwiw, I sometimes use something like this in CPerl mode:
> function_name > (argument_1, > argument_2);
> This is useful when the function name and each argument are very very > long. Note how I put the paren on the second line. I think moving > the paren to the second line is a good compromise for getting > automatic, good-looking indentation.
> > In some cases EMACS automatic indentation is generally not useful, > > especially if you edit a text coming originally from another > > development tool. So you get parts of the text indented in EMACS > > style, other parts in another style.
> C-h x C-M-\ should take care of that -- afterwards everything is > indented in Emacs style.
> kai > -- > ~/.signature: No such file or directory
I don't understand that logic (no offense intended). Why choose an indentation style that is difficult to maintain? If you have an indentation engine that makes it simple to change the indentation style to something that *you* can read and understand, why do you care how other people indent their code? Why would you care if they reindent your code to some other style?
Note that the indentation engine does not have to be emacs; there are several indentation engines out there can modify the file prior to modification.
> I don't understand that logic (no offense intended). Why choose an > indentation style that is difficult to maintain?
It does not make sense to change the indentation style of a file where you only change a couple of lines. When developing in a team, this situation (edit a foreign file where you only need to change a little bit) might arise quite often.
I tried two methods on several GNU EMACS versions (20.4, 20.7.1).
1) c-syntactic-indentation nil (requires cc-mode 5.27) This is documented as "indents every line like the previous one". A beautiful construct like ...
switch (x) { case 1: { x++; break; } case 2: { for (int i=0; i<10; i++) { } break; } default: break;
}
... looks like ...
switch (x) { case 1: { x++; break;
}
case 2: { for (int i=0; i<10; i++) {
} break; }
default: break;
}
... depending on how I type this. I could understand that there are people who like the case under the switch (I don't). But why is the for-loop indented on typing { while the break is not indented? And if the case keywords are under the switch why is the default keyword not indented in the same manner? This is not usable in sources of a programming language, because it hinders user made indentaion. The real problem is the inconsequence in this mode. It doesn't even work as documented.
2) customizing many variables I know all of the cc-mode variables now. And I notice again that they are insufficient to avoid **every** EMACS specific indentation. In general I could not turn off the behaviour on typing characters like { : and //. Therefor I modified (one by one) all the "hanging" variables, c-indent-comments-syntactically and c-comment-only-line-offset, c-offsets-alist, saved the changes to .emacs and inspected what happened. Not much, really. I did not detect any difference between the "c-default-style"s. What are these styles good for? Why isn't there a plain style, a do-never-anything-style?
Normally a user does configuration to cause the application to do something. How can I do some configuration to cause EMACS something **not** to do? I want just a fundamental-mode with syntax coloring.
On Wed, 27 Jun 2001, Torsten Müller wrote: > 1) c-syntactic-indentation nil (requires cc-mode 5.27) > This is documented as "indents every line like the previous one". A > beautiful construct like ...
It appears that `{' is still electric. Hm. But c-syntactic-indentation says that the current line should not be reindented when that variable is nil. Looks like a bug.