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

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

Re: Indenting with 2 spaces


From: Giorgos Keramidas
Subject: Re: Indenting with 2 spaces
Date: Wed, 08 Dec 2010 15:34:20 -0000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

On Tue, 2 Nov 2010 20:15:23 -0700 (PDT), Philip <phil.ganchev@gmail.com> wrote:
> How can I set the indentation level to 2 spaces in all modes, so that
> I get (for example) when I press Tab on the second line, I get the
> following:
>
> if test "$x"; then
>   echo yes
> fi
>
> Notice there are only 2 spaces before the "echo"

The indentation step is mode specific, so you can't set its value for
*all* programming modes in one place.  You will have to add a hook to
those modes you are interested in like:

    ;;; Indentation setup for cc-mode and derivatives.

    (defun keramida/cc-mode-setup ()
      (interactive)
      (make-local-variable 'c-basic-offset)
      (setq c-basic-offset 2))

    (eval-after-load "cc-mode"
      '(add-hook 'c-mode-common-hook 'keramida/cc-mode-setup))

    ;;; Indentation setup for text-mode and derivatives.

    (defun keramida/text-mode-setup ()
      (interactive)
      (make-local-variable 'standard-indent)
      (setq standard-indent 2))

    (eval-after-load "text-mode"
      '(add-hook 'text-mode-hook 'keramida/text-mode-setup))

    ;; Indentation setup for sh-mode and derivatives.

    (defun keramida/sh-mode-setup ()
      (interactive)
      (setq sh-basic-offset 2
            sh-indentation 2))

    (eval-after-load "sh-mode"
      '(add-hook 'sh-mode-hook 'keramida/sh-mode-setup))

Note: Using `eval-after-load' to set up the mode-hooks means that your
average startup time shouldn't increase too much, and Emacs shouldn't
try to auto-load all the affected modes *every* time it launches.



reply via email to

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