ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello! I am using the xemacs in Cygwin and want my code to have only 2 space for each level of indentation. I set the "tab-width" parameter in my init.el to 2. As a result, all indentation levels OTHER THAN the one immediately after my class declaration indent 2 space. The indentation after the class declaration, however, is still 4!
I cannot seem to find another option for this indentation. I recently got pinged on having inconsistant indentation because of this, so I tried resetting the tab-width to 4. After closing and re-launching xemacs on my source file, I find I still have the same behavior! Looking at init.el, I see that tab-width is indeed set to 4.
Could this be beacuse of the java-mode module that I'm using? If so, where should I look to find this module and (hopefully) correct its indentation parameters?
Thanks! I'd like to stick with xemacs if possible.
(Please do not turn this thread into an emacs vs vi flamewar.)
Incidentally, the version of Xemacs in Cygwin that I'm working with is (copied from About Xemacs): [version 21.4.20; December 2006]
While I'm giving configuraiton information, here is my init.el:
; associate the files with the .cs extension with the java mode, since C# is
; basically an extension of J++, which was M$'s version of java.
(setq auto-mode-alist (append '(("\\.cs$" . java-mode)) auto-mode-alist))
I use Emacs (not XEmacs) as well, but I assume the indentation is handled the same way.
The tab-width setting is not related to indentation settings. tab-width only defines how emacs displays tabs in a file. Note that this is buffer local, use (setq-default tab-width <number>) to change the default. (Possibly if you're using the customization system it takes care of that, I don't use it...)
Quote:
I set the "tab-width" parameter in my init.el to 2. As a result, all indentation levels OTHER THAN the one immediately after my class declaration indent 2 space. The indentation after the class declaration, however, is still 4!
I guess that what happened is that since your indentation settings are set to 4, emacs inserted tabs to do the indentation, so when you changed the tab-width the indentation appeared to change. However, if you indent some line (which you did when you added new class declaration I assume) it indents to 4 as per the settings that you have not changed (you can confirm this by reindenting the whole buffer: C-x h C-M-\).
EDIT: I just noticed you set indent-tabs-mode to nil, so probably what I wrote above is completely wrong...
If you want all your indentation set to 2 for java and other cc-mode languages, I think this will work:
Thanks, ntubski. Your reference to the c-basic-offset fixed the behavior of the indents for most of the code, except for the indent immediately following the class declaration that still seems to insist on being 4 spaces. So, at least my code can be consistant.
Now, if only I could figure out what offset is controlling that one indentation, I could reduce the indents to 2 and tighten up my code! To show what I mean:
Code:
namespace MYNAMESPACE
{
// Indentation of this comments is governed
// by c-basic-offset. Hence, indentation of 2.
public class MyClass
{
// Indentation of this comment is governed
// by something else. Hence, indent of 4.
public MyClass(void)
{
// Indentation of this comment goverened
// by c-basic-offset. Hence, indent of 2.
}
}
}
Any suggestions on what the other offset might be, or
where I can look?
You can use C-c C-s (c-show-syntactic-information) to see which offset is being used. In this case, you are mixing C++ and Java syntax:
Code:
//indented in java-mode
namespace MYNAMESPACE
{
public class MyClass // C-c C-s gives: ((defun-block-intro 23))
{
public MyClass(void)
{
}
}
}
Code:
// indented in c++-mode
namespace MYNAMESPACE
{
public class MyClass // C-c C-s gives: ((inher-cont 27))
{
public MyClass(void)
{
}
}
}
You can see in c++-mode the declaration's indentation is not changed, looking up the indentation for inher-cont in c-offset-alist gives the function c-lineup-multi-inher, here's some of the documentation from there:
Code:
Line up the classes in C++ multiple inheritance clauses and member
initializers under each other. E.g:
class Foo: Foo::Foo (int a, int b):
public Cyphr, Cyphr (a),
public Bar <-> Bar (b) <- c-lineup-multi-inher
So my only question is, what language is that code in???
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.