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

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

problem with auto-newline in C mode (2)


From: Martin Maletinsky
Subject: problem with auto-newline in C mode (2)
Date: Wed, 21 Nov 2001 17:12:36 +0100

Hello,

I could solve part of the problems I described in a previous mail. The 
following problem with the auto-newline minor mode however still persists. 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;
};
}

The auto-newline mode indents the opening brace in the definition of struct 
another_name, yielding the following result:

...
{
        struct another_name
                {
                        int a;
                        int b;
        };
}

When marking the region and requesting re-indentation (by hitting C-M-\), the 
code is reformatted to:
...
{
        struct another_name
        {
                int a;
                int b;
        };
}

which looks better.

Another problem is, that the insertion of newlines before/after the opening 
brace in the struct another_name definition is not affected by the value 
configured for the
class-open element in the c-hanging-braces-alist (while the insertion of 
newlines before/after the opening brace in the struct name definition is. I.e. 
the newlines are
*always* inserted before and after the opening brace of the structure 
definition  within the main() function.

Any ideas how I could change this behaviour by appropriate settings in my 
.emacs file?


Please put me on cc: in your reply, since I am not on the mailing list.

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))))


reply via email to

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