TCLUG Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [TCLUG:10129] emacs indenting with the spacing I want



On Mon, Nov 15, 1999 at 11:02:16PM -0600, Bob Tanner wrote:
> Quoting Eric M. Hopper (hopper@omnifarious.mn.org):
> > On Mon, Nov 15, 1999 at 05:14:05PM -0800, Jared Sprague wrote:
> > Is there a way to keep emacs from auto indenting? 
> 
> Ok, my turn.
> 
> 
> Is there a way to make emacs autoindex to an offset of 2, instead of the
> default 4?
> 
> I have this in my ~/.emacs file:
> 
>  '(c-basic-offset 2)
> 
> But still emacs sets the offset to 4.

	This is because the offsets are stored in the c-styles-alist
variable.  The c-styles-alist variable is used to hold information about
various indentation styles.  You can set which indentation style you're
using using the c-set-style (C-c .) command once you're editing a file.

	I have a special indentation set up for just java, and here's
the snippet in my .emacs file that does it:

(add-hook 'java-mode-hook
          (lambda ()
            (setq c-basic-offset 4))))

	This adds a 'mode-hook', which is a function that's called
whenever a mode is entered.  My function is a 'lambda expression', which
is a way of declaring an anonymous function in lisp.  It has the form:

(lambda (arglist) (function body))  ; All expression in lisp have a
                                    ; return value.  The return value of
                                    ; the expression making up 'function
                                    ; body' is the return value of the
                                    ; function.

	Another snippet I have in my
/usr/share/emacs/site-lisp/default.el file is:

(c-add-style "hopper" '((c-basic-offset . 3)
                        (c-offsets-alist . ((member-init-intro . 5)
                                            (access-label . -2)
                                            (case-label . 1)
                                            (statement-case-intro . 2)
					    (substatement-open . 0)))))

(c-add-style "gmtellemtel" '("ellemtel"
			     (c-basic-offset . 4)
			     (c-offsets-alist
			      (inclass . +))))

	These two calls each add a new style to the available styles.

	And, this code snippet sets up the default style used to edit a
C++ file.

(add-hook 'c++-mode-hook
          (lambda ()
            (if (eq c-file-style nil)
                (c-set-style "hopper"))))

	I hope that answered your question.  :-)

Have fun (if at all possible),
-- 
Its name is Public Opinion.  It is held in reverence. It settles everything.
Some think it is the voice of God.  Loyalty to petrified opinion never yet
broke a chain or freed a human soul.     ---Mark Twain
-- Eric Hopper (hopper@omnifarious.mn.org
                http://ehopper-host105.dsl.visi.com/~hopper) --

PGP signature