LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-12-2007, 10:06 AM   #1
jcubed
LQ Newbie
 
Registered: Apr 2004
Location: Minneapolis, MN
Posts: 18

Rep: Reputation: 0
emacs / xemacs ingnoring tab-width in init.el


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.)
 
Old 12-12-2007, 05:55 PM   #2
jcubed
LQ Newbie
 
Registered: Apr 2004
Location: Minneapolis, MN
Posts: 18

Original Poster
Rep: Reputation: 0
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))

; Associate common shell-script extensions with shell-script-mode.
(setq auto-mode-alist (append '(("\\.bash$" . shell-script-mode)) auto-mode-alist))
(setq auto-mode-alist (append '(("\\.sh$" . shell-script-mode)) auto-mode-alist))
(setq auto-mode-alist (append '(("\\.scr$" . shell-script-mode)) auto-mode-alist))
(setq auto-mode-alist (append '(("\\*rc$" . shell-script-mode)) auto-mode-alist))
;(setq auto-mode-alist (append '(("\\.*rc$" . shell-script-mode)) auto-mode-alist))


(load-library "pc-select") ; a package which enables text selection ...

(pc-select-mode) ; ... with the shift and arrow keys

(custom-set-variables
'(paren-mode (quote sexp) nil (paren))
'(default-input-method "rfc1345")
'(delete-key-deletes-forward t)
'(load-home-init-file t t)
'(c-hanging-comment-starter-p nil)
'(column-number-mode t)
'(parens-require-spaces nil)
'(c-hanging-comment-ender-p nil)
'(c-indent-comments-syntactically-p nil)
'(case-fold-search t)
'(tab-width 4)
'(global-font-lock-mode t nil (font-lock))
'(show-paren-mode t nil (paren))
'(line-number-mode t)
'(current-language-environment "UTF-8")
'(transient-mark-mode t)
'(user-mail-address "")
'(query-user-mail-address nil)
'(indent-tabs-mode nil)
'(font-lock-mode t nil (font-lock)))

(require 'font-lock) ; enable syntax highlighting

(custom-set-faces
'(default ((t (:foreground "white" :background "black" :size "12pt" :family "Courier"))) t)
'(text-cursor ((t (:foreground "black" :background "green"))) t)
'(secondary-selection ((t (:foreground "white" :background "red"))) t)
'(widget-field-face ((((class grayscale color) (background light)) (:foreground "gray10" :background "gray85"))))
'(cperl-nonoverridable-face ((t (:foreground "orange" :bold t))))
'(cperl-array-face ((t (:foreground "orangered" :bold t))))
'(font-lock-string-face ((t (:foreground "green3"))))
'(paren-mismatch ((t (:background "DeepPink" :bold t))) t)
'(dired-face-permissions ((t (:foreground "green"))))
'(font-lock-reference-face ((t (:foreground "orangered"))))
'(isearch-secondary ((t (:foreground "darkblue" :background "darkgreen" :bold t))) t)
'(custom-group-tag-face ((t (:underline t :foreground "blue"))))
'(cperl-hash-face ((t (:foreground "Red" :bold t))))
'(font-lock-doc-string-face ((t (:foreground "Wheat3"))))
'(font-lock-preprocessor-face ((t (:foreground "maroon" :background "lightgreen" :bold t))))
'(custom-comment-face ((((class grayscale color) (background light)) (:foreground "cyan"))))
'(font-lock-variable-name-face ((t (:foreground "yellow" :bold t))))
'(font-latex-bold-face ((((class color) (background light)) (:bold t))))
'(paren-match ((t (:background "darkgreen" :bold t))) t)
'(custom-state-face ((t (:foreground "green3"))))
'(font-lock-warning-face ((t (:foreground "Violetred" :background "yellow" :bold t))))
'(font-lock-keyword-face ((t (:foreground "gold"))))
'(custom-saved-face ((t (:underline t :foreground "orange"))))
'(font-lock-type-face ((t (:foreground "#886fff" :bold t))))
'(message-cited-text ((t (:bold t :italic nil))))
'(font-latex-italic-face ((((class color) (background light)) (:italic t))))
'(font-latex-math-face ((((class color) (background light)) (:foreground "green3"))))
'(primary-selection ((t (:background "gray55"))) t)
'(custom-button-face ((t (:bold t :foreground "#3fdfcf"))))
'(list-mode-item-selected ((t (:foreground "darkgreen"))) t)
'(custom-variable-button-face ((t (:bold t :underline t :foreground "white"))))
'(font-lock-comment-face ((t (:foreground "cyan"))))
'(font-latex-sedate-face ((((class color) (background light)) (:foreground "gold"))))
'(font-lock-function-name-face ((t (:foreground "blue" :bold t))))
'(isearch ((t (:foreground "blue" :background "green" :bold t))) t)
'(highlight ((t (:foreground "red3" :background "white"))) t)
'(zmacs-region ((t (:background "RoyalBlue"))) t))
(defun my-c-mode-common-hook ()
(c-set-offset 'substatement-open 0)
)

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

(setq c-label-offset 0)

(setq frame-title-format '("emacs: %b"))




(Thanks again in advance to anyone who looks into this!)
 
Old 12-12-2007, 06:04 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
I don't do xemacs at all, but in emacs those things may well be over-ridden
by your language specific modes. What I have here looks like so:
Code:
(defun my-perl-indent-setup ()
  (setq tab-width 2)
  (setq cperl-indent-level 2)
  (setq cperl-brace-offset -2)
  (setq indent-tabs-mode nil))
(add-hook 'cperl-mode-hook 'my-perl-indent-setup)
That fixes SOME problems. Mostly I use vim these days, anyway ;}


Cheers,
Tink
 
Old 12-12-2007, 09:44 PM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
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:
Code:
(eval-after-load "cc-mode"
  '(progn
     (setq-default c-basic-offset 2)))

Last edited by ntubski; 12-12-2007 at 10:04 PM.
 
Old 12-13-2007, 08:47 AM   #5
jcubed
LQ Newbie
 
Registered: Apr 2004
Location: Minneapolis, MN
Posts: 18

Original Poster
Rep: Reputation: 0
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?

Thanks again for getting me this far!
- JJJ

Last edited by jcubed; 12-13-2007 at 08:48 AM.
 
Old 12-13-2007, 12:37 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,780

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
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???

Last edited by ntubski; 12-13-2007 at 12:38 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to make a tab is 4 spaces width in vim? ICO SUSE / openSUSE 8 03-05-2013 10:24 AM
Tab width in Bash - how do I set it benr77 Linux - General 8 12-04-2012 10:53 AM
emacs width line jrdioko Linux - Software 14 07-10-2009 11:48 AM
emacs and xemacs darknails Linux - Software 1 01-16-2005 07:42 AM
emacs or Xemacs saurya_s Linux - Software 1 02-05-2004 02:44 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration