[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
problem with auto-newline in C mode
From: |
Martin Maletinsky |
Subject: |
problem with auto-newline in C mode |
Date: |
Tue, 20 Nov 2001 16:51:53 +0100 |
Hello,
When using the auto-newline minor mode while in C mode ( C/a is displayed in
the buffer's status bar), I typed in the following C code:
struct name{int a;
int b;
};
int main(void)
{
struct another_name{int a;
int b;
};
}
I got an unexpected formatting, in particular, emacs seems to handle the
structure definition inside the function differently from the structure
definition outside the
function. The following hexdump (of the code as it was formatted by the auto
newline mode) illustrates this difference:
0000000 s t r u c t n a m e { \n
0000010 i n t a ; \n i n t
0000020 b ; \n } ; \n \n i n t m a i n (
0000030 v o i d ) \n { \n s t r u
0000040 c t a n o t h e r _ n a m e \n
0000050 \t { \n \t i n t a ; \n \t
0000060 i n t b ; \n }
0000070 ; \n } \n \n \n \n \n \n
0000080 \n
0000082
You note, that a newline is added after the opening brace of the external
struct definition, while a new line is added befor and after the opening brace
of the internal
struct definition. Moreover, \t are used to indent the opening brace of the
internal struct definition, while spaces are used for the indentation in the
external
definition.
After marking all the code and re-indenting it with C-M-\, the code looked the
way I would have expected it from the beginning. After inspecting the hexdump,
I was however
still surprised to find that \t was still used for indentation within the
internal structure definition, while spaces were used in the external, as you
can see in the
hexdump below
0000000 s t r u c t n a m e { \n
0000010 i n t a ; \n i n t
0000020 b ; \n } ; \n \n i n t m a i n (
0000030 v o i d ) \n { \n s t r u
0000040 c t a n o t h e r _ n a m e \n
0000050 { \n \t i n t a ; \n \t i
0000060 n t b ; \n } ; \n } \n \n
0000070 \n \n
000007a
How can I change my configuration, to:
- have the same handling for structure definitions inside and outside of
functions
- consistently use spaces or tabs for indentation (but not a mix of both)
I am using Xemacs Version 21.1 (patch 7) [as indicated by the variable
emacs-version] and cc-mode version 5.25 [as indicated by the variable
c-version], my operating system
is Linux 2.2.13. Please refer to the attached dot.emacs file for details on my
configuration.
thank you for your help
with best regards
Martin
--
Supercomputing System AG email: maletinsky@scs.ch
Martin Maletinsky phone: +41 (0)1 445 16 05
Technoparkstrasse 1 fax: +41 (0)1 445 16 10
CH-8005 Zurich
;; Enable syntax highlighting
(add-hook 'c-mode-hook '(lambda () (font-lock-mode 1)))
;; Set the indentation to 4
(setq my-c-style
'((c-basic-offset . 4)))
(add-hook 'c-mode-hook
(function (lambda()
(c-add-style "my-style" my-c-style t))))
(add-hook 'c-mode-hook
(c-set-offset 'substatement-open 0))
;; Switch auto-newline minor mode on (in order to automatically insert
;; newlines after curly brackets
(add-hook 'c-mode-hook '(lambda () (c-toggle-auto-state t)))
;; specify when to insert newlines
;; (custom-set-variables
;; '(c-hanging-braces-alist '((brace-list-open) (brace-entry-open) (class-open
after) (class-close before))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- problem with auto-newline in C mode,
Martin Maletinsky <=