all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bizarre emacs indentation problem
@ 2009-04-10 23:48 luca.pamparana
  2009-04-11 21:29 ` Alan Mackenzie
  0 siblings, 1 reply; 2+ messages in thread
From: luca.pamparana @ 2009-04-10 23:48 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

I have a bizarre emacs indentation problem in the C++ mode. My C++
settings look as follows:

(defun my-c++-mode-hook ()
  (c-set-offset 'substatement-open 0)
  (setq indent-tabs-mode nil)
  (setq tab-width 4)
  (define-key c++-mode-map "\C-m" 'reindent-then-newline-and-indent)
  (define-key c++-mode-map "\C-ce" 'c-comment-edit)
  (setq c++-auto-hungry-initial-state 'none)
  (setq c++-delete-function 'backward-delete-char)
  (setq c++-tab-always-indent nil)
  (setq tab-stop-list '(4 8 12 16))
  (setq c-basic-offset 4)
  (setq c-indent-level 4)
  (setq c-continued-statement-offset 4)
  (setq c++-empty-arglist-indent 4))


;; Add all of the hooks...
(add-hook 'c++-mode-hook 'my-c++-mode-hook)
(add-hook 'c++-mode-hook 'turn-on-auto-fill)
(setq default-major-mode 'c++-mode)
(setq column-number-mode t)

As you can see, I have set the substatement open parameter to 0, so it
should not indent after the statement braces. However, it always
indents by 1. So, my sample if clause looks as follows:

if(something)
 {
 }

As you can see, the braces are indented by 1 space. This is driving me
crazy!

Does anyone have any idea why I might be getting this?

Many thanks,

Luca


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

* Re: bizarre emacs indentation problem
  2009-04-10 23:48 bizarre emacs indentation problem luca.pamparana
@ 2009-04-11 21:29 ` Alan Mackenzie
  0 siblings, 0 replies; 2+ messages in thread
From: Alan Mackenzie @ 2009-04-11 21:29 UTC (permalink / raw)
  To: luca.pamparana; +Cc: help-gnu-emacs

Hi, Luca!

On Fri, Apr 10, 2009 at 04:48:30PM -0700, luca.pamparana@gmail.com wrote:
> Hello,

> I have a bizarre emacs indentation problem in the C++ mode. My C++
> settings look as follows:

> (defun my-c++-mode-hook ()
>   (c-set-offset 'substatement-open 0)
>   (setq indent-tabs-mode nil)
>   (setq tab-width 4)
>   (define-key c++-mode-map "\C-m" 'reindent-then-newline-and-indent)
>   (define-key c++-mode-map "\C-ce" 'c-comment-edit)
>   (setq c++-auto-hungry-initial-state 'none)
>   (setq c++-delete-function 'backward-delete-char)
>   (setq c++-tab-always-indent nil)
>   (setq tab-stop-list '(4 8 12 16))
>   (setq c-basic-offset 4)
>   (setq c-indent-level 4)
>   (setq c-continued-statement-offset 4)
>   (setq c++-empty-arglist-indent 4))


> ;; Add all of the hooks...
> (add-hook 'c++-mode-hook 'my-c++-mode-hook)
> (add-hook 'c++-mode-hook 'turn-on-auto-fill)
> (setq default-major-mode 'c++-mode)
> (setq column-number-mode t)

> As you can see, I have set the substatement open parameter to 0, so it
> should not indent after the statement braces. However, it always
> indents by 1. So, my sample if clause looks as follows:

> if(something)
>  {
>  }

> As you can see, the braces are indented by 1 space. This is driving me
> crazy!

> Does anyone have any idea why I might be getting this?

Yes, indeed.  In a nutshell, "gnu" style imposes a minimum indentation of
1 from column zero.

In more detail, it's in the CC Mode manual, as follows:
(i) Your CC Mode "style" is "gnu" (the default, since you haven't changed
  it).  Styles are explained on the pages "Config Basics" and "Styles".
(ii) "gnu" style imposes a minimum indentation of 1 character FROM COLUMN
  ZERO.  This is to help source code utilities which search for things in
  column zero.  This "1 character" is in user option
  `c-label-minimum-indentation' which is on page "Other Indentation".

You can fix this either by setting the default style to something other
than "gnu" (user option `c-default-style' on manual page "Choosing a
Style"), or by setting `c-label-minimum-indentation' to zero.

As a matter of interest, why are you typing an if-statement in column
zero?  :-)

> Many thanks,

> Luca

-- 
Alan Mackenzie (Nuremberg, Germany).




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

end of thread, other threads:[~2009-04-11 21:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-04-10 23:48 bizarre emacs indentation problem luca.pamparana
2009-04-11 21:29 ` Alan Mackenzie

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.