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

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

Re: setting emacs variables


From: Olivier Pierrat
Subject: Re: setting emacs variables
Date: Tue, 09 Oct 2001 00:01:20 +0200
User-agent: Mozilla/5.0 (X11; U; Linux 2.2.19 i686; en-US; rv:0.9.1) Gecko/20010621

Gerald A Winters wrote:

> I am a C-programmer and am using v20.7.  I would like to
> change the default indentation level from "2" to "4" when
> in C-mode.  I have a couple manuals and both indicate to
> change the emacs varibale "c-indent-level".  However, neither
> of these works in my .emacs file:
>
> (setq c-indent-level 4)
> (setq-default c-indent-level 4)
>
> I would be *very* grateful if someone can suggest a solution.
> thanks.
>
> --jerry
>
>
> _______________________________________________
> Help-gnu-emacs mailing list
> Help-gnu-emacs@gnu.org
> http://mail.gnu.org/mailman/listinfo/help-gnu-emacs
>
>

Emacs uses the cc-mode to fontify C files, and to indent too. Indentation
is based on the 'tab-width' variable, which can be redifined for each
mode. The C structure's indentation is related to
c-basic-offset variable and an offset for the different part of the structure. In order to have more precise informations try M-x hell RET i RET C-s 'CC mode', section Customizing indentation and try this in your .emacs file :


   (setq tab-width 4)
   ;; this will make sure spaces are used instead of tabs
   (setq indent-tabs-mode nil)
   (setq c-tab-always-indent t)

   ;; Highlight matching parantheses
   (show-paren-mode 1)

   ;;--------------------------
   ;; indentation
   ;; For more information : M-x info cc-mode
   (setq c-comment-only-line-offset      0);; -1000 to have it at the
beginning of the line
   (setq c-basic-offset                  3);; general value for
indentation on wich every arg of the
   ;; c-set-offset will be based on
   ;; + mean c-basic-offset*1
   (c-set-offset   'arglist-close        0);; 0 mean c-basic-offset*0
   (c-set-offset   'arglist-intro       '+);; function parameters
   (c-set-offset   'substatement-open    0);; indentation of braces for
if, for, while
   (c-set-offset   'substatement        '+);; indentation of a statement
(each line of a function)
   (c-set-offset   'case-label          '+);; indentation for the label
in a switch-case structure
   (c-set-offset   'defun-block-intro   '+);; indentation of variable
def for a function (no tab)

   (c-set-offset   'statement            0);; indentation of the
function's body (the first line
   ;; starts at this point)
   ;;--------------------------

The wright way to do this is to mak a new hook for the c-mode. You can see the documentation about hooks : M_x help RET i -RET and look for hook description.
--
-----------------------------------------------------------------
Olivier PIERRAT                   Tel.   : +33 (0) 03 90 40 00 00
ALPLOG                            Port.  : +33 (0) 06 76 41 16 00
Immeuble le Platon                mailto : o.pierrat@alplog.fr
67400 ILLKIRCH                    mailto : o.pierrat@free.fr

-----------------------------------------------------------------






reply via email to

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