all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* indentation in jde/java mode
@ 2004-04-26  3:07 ad
  2004-04-26  8:30 ` Alan Mackenzie
  0 siblings, 1 reply; 7+ messages in thread
From: ad @ 2004-04-26  3:07 UTC (permalink / raw)


Hi,

I am running "GNU Emacs 21.3.1" in my debian box. I have the following
in my ".emacs" file to use 2 char indentation for my java files:

(defun my-jde-mode-hook ()
	(setq c-basic-offset 2))

(add-hook 'jde-mode-hook 'my-jde-mode-hook)
(add-hook 'java-mode-hook 'my-jde-mode-hook)


This seems to be working fine when I edit/view files with emacs, but
when I look at the files with other editors or viewers, like "less",
I see the indentation is actually 8.

It seems like when the file is saved, the indentation is changing to
8.

Am I doing something wrong within my ".emacs"?

Thank you.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: indentation in jde/java mode
  2004-04-26  3:07 indentation in jde/java mode ad
@ 2004-04-26  8:30 ` Alan Mackenzie
  2004-04-27  2:15   ` ad
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Mackenzie @ 2004-04-26  8:30 UTC (permalink / raw)


ad <as@no-span.org> wrote on Sun, 25 Apr 2004 23:07:01 -0400:
> Hi,

> I am running "GNU Emacs 21.3.1" in my debian box. I have the following
> in my ".emacs" file to use 2 char indentation for my java files:

> (defun my-jde-mode-hook ()
> 	(setq c-basic-offset 2))

> (add-hook 'jde-mode-hook 'my-jde-mode-hook)
> (add-hook 'java-mode-hook 'my-jde-mode-hook)


> This seems to be working fine when I edit/view files with emacs, but
> when I look at the files with other editors or viewers, like "less", I
> see the indentation is actually 8.

> It seems like when the file is saved, the indentation is changing to
> 8.

> Am I doing something wrong within my ".emacs"?

Quick question: are you sure that your indentation is done with two
spaces, and not with a TAB, tab-width having somehow been set to 2?

> Thank you.

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: indentation in jde/java mode
  2004-04-26  8:30 ` Alan Mackenzie
@ 2004-04-27  2:15   ` ad
  2004-04-27  6:50     ` Alan Mackenzie
  0 siblings, 1 reply; 7+ messages in thread
From: ad @ 2004-04-27  2:15 UTC (permalink / raw)


On Mon, 26 Apr 2004 08:30:36 +0000, Alan Mackenzie wrote:

> ad <as@no-span.org> wrote on Sun, 25 Apr 2004 23:07:01 -0400:
>> Hi,
> 
>> I am running "GNU Emacs 21.3.1" in my debian box. I have the following
>> in my ".emacs" file to use 2 char indentation for my java files:
> 
>> (defun my-jde-mode-hook ()
>> 	(setq c-basic-offset 2))
> 
>> (add-hook 'jde-mode-hook 'my-jde-mode-hook)
>> (add-hook 'java-mode-hook 'my-jde-mode-hook)
> 
> 
>> This seems to be working fine when I edit/view files with emacs, but
>> when I look at the files with other editors or viewers, like "less", I
>> see the indentation is actually 8.
> 
>> It seems like when the file is saved, the indentation is changing to
>> 8.
> 
>> Am I doing something wrong within my ".emacs"?
> 
> Quick question: are you sure that your indentation is done with two
> spaces, and not with a TAB, tab-width having somehow been set to 2?
> 
>> Thank you.

While I am writing the code and get to the new-line and hit TAB, the
cursor does not move, but when I finished the line with ";" or having
a "." (dot) in the line (example (aClass.method), does the indentation
automatically, and it looks by 2 chars. I also tend to use "Java ->
Indent Expression" menu selection quite often which also looks like
indenting by 2 chars. All the indentation looks just fine (2-chars)
within the emacs, but opening with other editors (even "less") is
making it look like it was indented by 8 chars. Because of this, I get
some complaints from my colleagues that are using xemacs.

Thank you again

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: indentation in jde/java mode
  2004-04-27  2:15   ` ad
@ 2004-04-27  6:50     ` Alan Mackenzie
  2004-04-28  2:55       ` ad
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Mackenzie @ 2004-04-27  6:50 UTC (permalink / raw)


ad <as@no-span.org> wrote on Mon, 26 Apr 2004 22:15:51 -0400:
> On Mon, 26 Apr 2004 08:30:36 +0000, Alan Mackenzie wrote:

>> ad <as@no-span.org> wrote on Sun, 25 Apr 2004 23:07:01 -0400:
>>> Hi,

>>> I am running "GNU Emacs 21.3.1" in my debian box. I have the
>>> following in my ".emacs" file to use 2 char indentation for my java
>>> files:

>>> (defun my-jde-mode-hook ()
>>> 	(setq c-basic-offset 2))

>>> (add-hook 'jde-mode-hook 'my-jde-mode-hook)
>>> (add-hook 'java-mode-hook 'my-jde-mode-hook)


>>> This seems to be working fine when I edit/view files with emacs, but
>>> when I look at the files with other editors or viewers, like "less",
>>> I see the indentation is actually 8.

>>> It seems like when the file is saved, the indentation is changing to
>>> 8.

>>> Am I doing something wrong within my ".emacs"?

>> Quick question: are you sure that your indentation is done with two
>> spaces, and not with a TAB, tab-width having somehow been set to 2?

>>> Thank you.

> While I am writing the code and get to the new-line and hit TAB, the
> cursor does not move, but when I finished the line with ";" or having a
> "." (dot) in the line (example (aClass.method), does the indentation
> automatically, and it looks by 2 chars. I also tend to use "Java ->
> Indent Expression" menu selection quite often which also looks like
> indenting by 2 chars. All the indentation looks just fine (2-chars)
> within the emacs, but opening with other editors (even "less") is
> making it look like it was indented by 8 chars. Because of this, I get
> some complaints from my colleagues that are using xemacs.

Sorry, I should have been more explicit.  I was thinking that those 2
spaces you're seeing might really be a TAB character.  If so, it would
look like 8 spaces in less or other editors.

If you put the cursor in those 2 spaces, then do "C-x =", it will tell
you what's there.  If it is indeed a TAB character, check the value of
the Emacs variables `tab-width' and `indent-tabs-mode' (using "C-h v").

If this isn't the problem, then could you do "C-c C-b" from the java
buffer, to dump the internal state of java-mode.  Post that dump here,
and we'll probably be able to see what's going wrong.

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: indentation in jde/java mode
  2004-04-27  6:50     ` Alan Mackenzie
@ 2004-04-28  2:55       ` ad
  2004-04-28 18:02         ` Alan Mackenzie
  0 siblings, 1 reply; 7+ messages in thread
From: ad @ 2004-04-28  2:55 UTC (permalink / raw)


On Tue, 27 Apr 2004 06:50:09 +0000, Alan Mackenzie wrote:

> ad <as@no-span.org> wrote on Mon, 26 Apr 2004 22:15:51 -0400:
>> On Mon, 26 Apr 2004 08:30:36 +0000, Alan Mackenzie wrote:
> 
>>> ad <as@no-span.org> wrote on Sun, 25 Apr 2004 23:07:01 -0400:
>>>> Hi,
> 
>>>> I am running "GNU Emacs 21.3.1" in my debian box. I have the
>>>> following in my ".emacs" file to use 2 char indentation for my java
>>>> files:
> 
>>>> (defun my-jde-mode-hook ()
>>>> 	(setq c-basic-offset 2))
> 
>>>> (add-hook 'jde-mode-hook 'my-jde-mode-hook)
>>>> (add-hook 'java-mode-hook 'my-jde-mode-hook)
> 
> 
>>>> This seems to be working fine when I edit/view files with emacs, but
>>>> when I look at the files with other editors or viewers, like "less",
>>>> I see the indentation is actually 8.
> 
>>>> It seems like when the file is saved, the indentation is changing to
>>>> 8.
> 
>>>> Am I doing something wrong within my ".emacs"?
> 
>>> Quick question: are you sure that your indentation is done with two
>>> spaces, and not with a TAB, tab-width having somehow been set to 2?
> 
>>>> Thank you.
> 
>> While I am writing the code and get to the new-line and hit TAB, the
>> cursor does not move, but when I finished the line with ";" or having a
>> "." (dot) in the line (example (aClass.method), does the indentation
>> automatically, and it looks by 2 chars. I also tend to use "Java ->
>> Indent Expression" menu selection quite often which also looks like
>> indenting by 2 chars. All the indentation looks just fine (2-chars)
>> within the emacs, but opening with other editors (even "less") is
>> making it look like it was indented by 8 chars. Because of this, I get
>> some complaints from my colleagues that are using xemacs.
> 
> Sorry, I should have been more explicit.  I was thinking that those 2
> spaces you're seeing might really be a TAB character.  If so, it would
> look like 8 spaces in less or other editors.
> 
> If you put the cursor in those 2 spaces, then do "C-x =", it will tell
> you what's there.  If it is indeed a TAB character, check the value of
> the Emacs variables `tab-width' and `indent-tabs-mode' (using "C-h v").

"C-x =" says: 
Char: TAB (011, 9, 0x9) point=251 of 3560 (7%) column 0 

And tab-width's value is 2

And indent-tabs-mode's value is t



> 
> If this isn't the problem, then could you do "C-c C-b" from the java
> buffer, to dump the internal state of java-mode.  Post that dump here,
> and we'll probably be able to see what's going wrong.

"C-c C-b" Results:
====================
Emacs  : GNU Emacs 21.3.1 (i386-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
 of 2004-04-06 on raven, modified by Debian
Package: CC Mode 5.28 ()
Buffer Style: java

c-emacs-features: (1-bit)

current state:
==============
(setq
 c-basic-offset 2
 c-comment-only-line-offset '(0 . 0)
 c-block-comment-prefix "* "
 c-comment-prefix-regexp '((pike-mode . "//+!?\\|\\**") (other . "//+\\|\\**"))
 c-cleanup-list '(scope-operator)
 c-hanging-braces-alist '((brace-list-open) (brace-entry-open) (substatement-open after)
													(block-close . c-snug-do-while) (extern-lang-open after)
													(inexpr-class-open after) (inexpr-class-close before))
 c-hanging-colons-alist nil
 c-hanging-semi&comma-criteria '(c-semi&comma-inside-parenlist)
 c-backslash-column 48
 c-label-minimum-indentation 1
 c-offsets-alist '((string . c-lineup-dont-change)
		 (c . c-lineup-C-comments)
		 (defun-open . 0)
		 (defun-close . 0)
		 (defun-block-intro . +)
		 (class-open . 0)
		 (class-close . 0)
		 (inline-close . 0)
		 (knr-argdecl . 0)
		 (topmost-intro . 0)
		 (member-init-intro . +)
		 (member-init-cont . c-lineup-multi-inher)
		 (inher-intro . +)
		 (block-open . 0)
		 (block-close . 0)
		 (brace-list-open . 0)
		 (brace-list-close . 0)
		 (brace-list-intro . +)
		 (brace-list-entry . 0)
		 (brace-entry-open . 0)
		 (statement . 0)
		 (statement-case-intro . +)
		 (substatement . +)
		 (case-label . 0)
		 (do-while-closure . 0)
		 (else-clause . 0)
		 (catch-clause . 0)
		 (comment-intro . c-lineup-comment)
		 (arglist-cont . 0)
		 (arglist-cont-nonempty . c-lineup-arglist)
		 (stream-op . c-lineup-streamop)
		 (inclass . +)
		 (cpp-macro . [0])
		 (cpp-macro-cont . c-lineup-dont-change)
		 (friend . 0)
		 (objc-method-intro . [0])
		 (objc-method-args-cont . c-lineup-ObjC-method-args)
		 (objc-method-call-cont . c-lineup-ObjC-method-call)
		 (extern-lang-open . 0)
		 (extern-lang-close . 0)
		 (inextern-lang . +)
		 (namespace-open . 0)
		 (namespace-close . 0)
		 (innamespace . +)
		 (template-args-cont c-lineup-template-args +)
		 (inlambda . c-lineup-inexpr-block)
		 (lambda-intro-cont . +)
		 (inexpr-statement . 0)
		 (inexpr-class . +)
		 (inline-open . 0)
		 (topmost-intro-cont . +)
		 (statement-block-intro . +)
		 (knr-argdecl-intro . 5)
		 (substatement-open . +)
		 (label . +)
		 (statement-case-open . +)
		 (statement-cont . +)
		 (arglist-intro . c-lineup-arglist-intro-after-paren)
		 (arglist-close . c-lineup-arglist)
		 (access-label . 0)
		 (inher-cont . c-lineup-java-inher)
		 (func-decl-cont . c-lineup-java-throws)
		 )
 c-delete-function 'delete-char
 c-electric-pound-behavior nil
 c-indent-comments-syntactically-p nil
 c-tab-always-indent t
 defun-prompt-regexp nil
 tab-width 2
 comment-column 32
 parse-sexp-ignore-comments t
 auto-fill-function nil
 comment-multi-line t
 comment-start-skip "/\\*+ *\\|//+ *"
 fill-prefix nil
 paragraph-start "[ 	]*\\(//+\\|\\**\\)[ 	]*\\(@[a-zA-Z]+\\>\\|$\\)\\|^\f"
 adaptive-fill-mode t
 adaptive-fill-regexp "[ 	]*\\(//+\\|\\**\\)[ 	]*\\([ 	]*\\([-|#;>*]+[ 	]*\\|(?[0-9]+[.)][ 	]*\\)*\\)"
 )


Thank you so much for the help.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: indentation in jde/java mode
  2004-04-28  2:55       ` ad
@ 2004-04-28 18:02         ` Alan Mackenzie
  2004-04-28 23:08           ` ad
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Mackenzie @ 2004-04-28 18:02 UTC (permalink / raw)


ad <as@no-span.org> wrote on Tue, 27 Apr 2004 22:55:19 -0400:
> On Tue, 27 Apr 2004 06:50:09 +0000, Alan Mackenzie wrote:

>>> While I am writing the code and get to the new-line and hit TAB, the
>>> cursor does not move, but when I finished the line with ";" or having
>>> a "." (dot) in the line (example (aClass.method), does the
>>> indentation automatically, and it looks by 2 chars. I also tend to
>>> use "Java -> Indent Expression" menu selection quite often which also
>>> looks like indenting by 2 chars. All the indentation looks just fine
>>> (2-chars) within the emacs, but opening with other editors (even
>>> "less") is making it look like it was indented by 8 chars. Because of
>>> this, I get some complaints from my colleagues that are using xemacs.

[ .... ]

>> If you put the cursor in those 2 spaces, then do "C-x =", it will tell
>> you what's there.  If it is indeed a TAB character, check the value of
>> the Emacs variables `tab-width' and `indent-tabs-mode' (using "C-h v").

> "C-x =" says: 
> Char: TAB (011, 9, 0x9) point=251 of 3560 (7%) column 0 

> And tab-width's value is 2

> And indent-tabs-mode's value is t

Aha!  There's the problem.  Something in your setup is setting tab-width
to 2 (by default, it's 8).  This seems to be a very small tab width
indeed.  Could it be something in your .emacs?

The question is, do you want to use TABs at all for indentation?  I
prefer not to, because different editors/display programs sometimes
disagree on how wide a TAB should be.  I suggest you change
`my-jde-mode-hook' to the following: 

(defun my-jde-mode-hook ()
  (setq c-basic-offset 2)
  (setq indent-tabs-mode nil))

That will prevent TABS being used for indentation in the future.

As for the source files which already contain TABS, (the ones your
colleagues are moaning about ;-), a good way to correct them is with the
function `untabify':  First make sure that `tab-width' is still set to 2.
Load a source file and type "C-x h" to mark the buffer, then "M-x
untabify" to convert the TABS to spaces.  Save the file again.  Violà!

> Thank you so much for the help.

My pleasure!

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: indentation in jde/java mode
  2004-04-28 18:02         ` Alan Mackenzie
@ 2004-04-28 23:08           ` ad
  0 siblings, 0 replies; 7+ messages in thread
From: ad @ 2004-04-28 23:08 UTC (permalink / raw)


On Wed, 28 Apr 2004 18:02:24 +0000, Alan Mackenzie wrote:

> ad <as@no-span.org> wrote on Tue, 27 Apr 2004 22:55:19 -0400:
>> On Tue, 27 Apr 2004 06:50:09 +0000, Alan Mackenzie wrote:
> 
>>>> While I am writing the code and get to the new-line and hit TAB, the
>>>> cursor does not move, but when I finished the line with ";" or having
>>>> a "." (dot) in the line (example (aClass.method), does the
>>>> indentation automatically, and it looks by 2 chars. I also tend to
>>>> use "Java -> Indent Expression" menu selection quite often which also
>>>> looks like indenting by 2 chars. All the indentation looks just fine
>>>> (2-chars) within the emacs, but opening with other editors (even
>>>> "less") is making it look like it was indented by 8 chars. Because of
>>>> this, I get some complaints from my colleagues that are using xemacs.
> 
> [ .... ]
> 
>>> If you put the cursor in those 2 spaces, then do "C-x =", it will tell
>>> you what's there.  If it is indeed a TAB character, check the value of
>>> the Emacs variables `tab-width' and `indent-tabs-mode' (using "C-h v").
> 
>> "C-x =" says: 
>> Char: TAB (011, 9, 0x9) point=251 of 3560 (7%) column 0 
> 
>> And tab-width's value is 2
> 
>> And indent-tabs-mode's value is t
> 
> Aha!  There's the problem.  Something in your setup is setting tab-width
> to 2 (by default, it's 8).  This seems to be a very small tab width
> indeed.  Could it be something in your .emacs?
> 
> The question is, do you want to use TABs at all for indentation?  I
> prefer not to, because different editors/display programs sometimes
> disagree on how wide a TAB should be.  I suggest you change
> `my-jde-mode-hook' to the following: 
> 
> (defun my-jde-mode-hook ()
>   (setq c-basic-offset 2)
>   (setq indent-tabs-mode nil))
> 
> That will prevent TABS being used for indentation in the future.
> 
> As for the source files which already contain TABS, (the ones your
> colleagues are moaning about ;-), a good way to correct them is with the
> function `untabify':  First make sure that `tab-width' is still set to 2.
> Load a source file and type "C-x h" to mark the buffer, then "M-x
> untabify" to convert the TABS to spaces.  Save the file again.  Violà!
> 
>> Thank you so much for the help.
> 
> My pleasure!

Thank you very much Alan. Now the indentation in java mode works great.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2004-04-28 23:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-04-26  3:07 indentation in jde/java mode ad
2004-04-26  8:30 ` Alan Mackenzie
2004-04-27  2:15   ` ad
2004-04-27  6:50     ` Alan Mackenzie
2004-04-28  2:55       ` ad
2004-04-28 18:02         ` Alan Mackenzie
2004-04-28 23:08           ` ad

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.