Question for Emacs Users

Started by
6 comments, last by Rydinare 16 years ago
Is there any setting in emacs that would automatically untabify a file? The reason why I'm asking is because there's one user in our group who uses emacs. Lately, the files that he's been checking in, if they had tabs before, are being converted to spaces. When I asked about this he showed me how emacs automatically inserts spaces when he pushes enter, but he kind of dodged the question when I asked about the entire files being converted. My question is whether or not this is emacs-related or intentional. From my knowledge, you'd have to intentionally use untabify or astyle to do this. As a second point, on the unlikely chance that this is an emacs issue, is there a way to configure the editor to stop this behavior?
Advertisement
Pretty much all indenting supported by emacs, from M-x indent-region to simply pressing TAB or RETURN, works based on spaces. All of these simply destroy any tabs or spaces present at the beginning of the current line, then add enough spaces to place the line correctly with regard to the previous lines. This is necessary to indent things like function arguments:

void function(arg1,              arg2, // With spaces      arg3); // With 2-space tabs on my computer


I personally find tabs to be an abomination in source code, so I've never really asked myself the question of whether this can be disabled, but I suspect it would be possible to either download a different .el file or alter the behavior of the current one through configuration or rewrite.
Quote:Original post by ToohrVyk
Pretty much all indenting supported by emacs, from M-x indent-region to simply pressing TAB or RETURN, works based on spaces. All of these simply destroy any tabs or spaces present at the beginning of the current line, then add enough spaces to place the line correctly with regard to the previous lines. This is necessary to indent things like function arguments:

void function(arg1,              arg2, // With spaces      arg3); // With 2-space tabs on my computer


I personally find tabs to be an abomination in source code, so I've never really asked myself the question of whether this can be disabled, but I suspect it would be possible to either download a different .el file or alter the behavior of the current one through configuration or rewrite.


Ok. But you're saying that this would affect a single line, not the entire file, correct?
Quote:Original post by Rydinare
Is there any setting in emacs that would automatically untabify a file?

Sure. Basically, Emacs runs a series of commands whenever you open a file of a specific type based on what's in the .el file for that mode. You can modify this mode script, of course, as it's just a text file.

Quote:My question is whether or not this is emacs-related or intentional.

He may be unaware that he has untabify-buffer or untabify-region in his .el mode script. Or he may be a douchebag.

Quote:As a second point, on the unlikely chance that this is an emacs issue, is there a way to configure the editor to stop this behavior?

tabify-region, tabify-buffer. Of course, you can make this whole issue go away by running a pre-commit hook (Subversion terminology) that ensures a file is whitespace formatted according to company-wide spec. Your co-worker can continue his assault against the "spurious" and "wrong" usage of tabs in source code (does he also complain about the position of the Alt key? [smile]) and the rest of you would be none the wiser.
Quote:Original post by Oluseyi
Quote:Original post by Rydinare
Is there any setting in emacs that would automatically untabify a file?

Sure. Basically, Emacs runs a series of commands whenever you open a file of a specific type based on what's in the .el file for that mode. You can modify this mode script, of course, as it's just a text file.

Quote:My question is whether or not this is emacs-related or intentional.

He may be unaware that he has untabify-buffer or untabify-region in his .el mode script. Or he may be a douchebag.

Quote:As a second point, on the unlikely chance that this is an emacs issue, is there a way to configure the editor to stop this behavior?

tabify-region, tabify-buffer. Of course, you can make this whole issue go away by running a pre-commit hook (Subversion terminology) that ensures a file is whitespace formatted according to company-wide spec. Your co-worker can continue his assault against the "spurious" and "wrong" usage of tabs in source code (does he also complain about the position of the Alt key? [smile]) and the rest of you would be none the wiser.


I hear you and appreciate your reply. I think everything you said makes a lot of sense. Unfortunately, there is no company-wide spec, which would otherwise solve a lot of issues. Because people have been allowed to do things based on personal preference, and with no agreed-upon/upfront rules in place, things like this happen. The process is broken/non-existent. I've been fighting to have some process put in place, but it's an uphill battle.

I love the idea of hooks to solve some of these issues; unfortunately, without a company-wide spec, the desired effect would be to configure things to "keep original author's settings" -- which I'm not sure how feasible it is to create something like that. We're also using a weaker source control system than Subversion, so we don't have full trigger/hook support.

Anyway, as far as emacs goes, what would be nice is if there's a way to simply tell emacs not to reformat the files when opened. I have a feeling that my coworker made it sound like there was nothing he could do, because he liked the effect of everything being converted.
Sounds to me like he started off with indent-tabs-mode nil and RET bound to newline-and-indent, and then later added a hook to run untabify or similar.

Emacs can be easily configured to do the right thing, so don't listen to any nonsense about RET inserting spaces or "there's nothing I can do". He can and should fix the problem. Additionally it's possible to set variables to control indentation on a per file basis, if you're willing to have a special comment as the first line. This should let him configure his editor as he pleases for personal use, while respecting project formatting guidelines.
Hang on, though - if there is no company spec, then doesn't the guy have the freedom to code to whatever standard he likes? Sure, if he were breaking company guidelines, that's one thing; but no he's just breaking your guidelines, apparently. Who are you that he should take your orders?
To win one hundred victories in one hundred battles is not the acme of skill. To subdue the enemy without fighting is the acme of skill.
Quote:Original post by King of Men
Hang on, though - if there is no company spec, then doesn't the guy have the freedom to code to whatever standard he likes? Sure, if he were breaking company guidelines, that's one thing; but no he's just breaking your guidelines, apparently. Who are you that he should take your orders?


This seems like an oddly malicious post. The agreement was that we adapt to run with the original author's coding style, since we don't have a standard. Another author shouldn't have the freedom to change existing code based on personal preference, unless there's a benefit to the group as a whole. That's a no-no in any circle.

Also, I haven't ordered anyone to do anything. I posted here to see if I can get some information to see if my coworker truly was simply a victim of a not knowing how to change his editor setting or if he was overstepping his bounds and showing poor etiquette. I think we can reasonably say it's likely to be the latter. Do you disagree?

This topic is closed to new replies.

Advertisement