help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs newbie - Syntax Highlighting and Indentation


From: Artur Hefczyc
Subject: Re: Emacs newbie - Syntax Highlighting and Indentation
Date: Sat, 15 Nov 2003 19:38:47 +0430
User-agent: Gnus/5.1002 (Gnus v5.10.2) Emacs/21.3.50 (gnu/linux)

David Rasmussen <david.rasmussen@gmx.net> writes:
> Artur Hefczyc wrote:
>> The shortest answer to your question is:
>> Put to your .emacs file following code:
>> (setq c-basic-offset 2)
> Where exactly in .emacs do I put this? Just at the bottom 
> after everything else?

It doesn't matter where you put it in file, it does matter in what
context.
I think you can put following code in any place in your .emacs file:

(defun my-java-mode-hook ()
  "Hook for running Java file..."
  (message "Loading my-java-hook...")
  (setq c-block-comment-prefix "* "
        indent-tabs-mode nil
        c-basic-offset 2)
  (message "my-java-mode-hook function executed")
)
(add-hook 'java-mode-hook 'my-java-mode-hook)

As you can see I defined very simple elisp function: 'my-java-mode-hook'
which will be executed every time you switch to Java file. You can put
there some more actions or settings. I suggest to look in my .emacs file
(mentioned in another post) and look for function: 'my-jde-mode-hook'.

Above code presents one advantage over configuring emacs from menu or
customization package. You can define any (even simple) function which
is executed in certain cases. And you have a little more control.

>> Other setting you might find useful for Java coding are:
>> (setq tab-width 4
>>       indent-tabs-mode nil)

Well, it's a shame! These 2 settings together doesn't make sense,
almost.
'tab-width' variable controls 'visual' width of table character, so it
can appear as 4 spaces if put in file.
'indent-tabs-mode' when set to 'nil' means: don't use tab character for
indentation. Set value to 't' if you want to use tab characters.

So you can blame me that I set tab-width for some value and then I
order emacs to not use tabs at all! However it can be useful if you
don't use tabs yourself but from time to time you load other files -
not your own, containing tabs.

On another side using tabs can be very useful. Lets assume you are
working on some code with more developers. Each of them prefer
different indentation depth. If you start using tabs each of them can
set different 'tab-width' so the same file can be displayed differently!

By the way, if you want to learn about some variable under emacs, place
cursor on variable name and press:
C-h v <Enter>  (Control-'h' and 'v')
if you want function description
C-h f <Enter>

If you place cursor on symbol name it is taken as default symbol but
you can change symbol name if you want description for another. And
remember with <tab> key you have symbol completing feature available.
Don't ask what does it mean, just try it!

Artur
-- 
Artur Hefczyc, Open Source Developer:
http://www.geotools.org/
http://generguide.sourceforge.net/
http://wttools.sourceforge.net/
http://maven-plugins.sourceforge.net/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]