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

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

[h-e-w] Problem with customizing open brace behavior


From: Ben Key
Subject: [h-e-w] Problem with customizing open brace behavior
Date: Tue, 29 Jan 2002 01:33:52 -0500

I have just started to familiarize myself with NT EMACS.  It is a 
very powerful programmers editor and I love it.  

There is, however, one problem I am having that I hope you all can 
help me with.

I want to customize NT EMACS so that when I type

if (condition){code}

it will be automatically reformatted to

if (condition)
  {
    code
  }
  

I have gotten most of the way there by creating my own C style and 
loading it in the c-mode-common-hook (see below).  However, I cannot 
get EMACS to position the open brace on a line by itself.  When I type

if (condition){code}

I end up with

if (condition){
  code
}

Do you have any suggestions on how I might accomplish my goal?

====

Snippet of my .EMACS file

;; -->> C++ Mode Customizations -->>
(require 'cc-mode)
(defconst my-c-style
  '(
    (c-tab-always-indent . t)
    (indent-tabs-mode . t)
    (c-basic-offset . 4)
    (c-comment-only-line-offset . (0 . 0))
    (c-hanging-braces-alist. (
        (substatement-open before after)
        (statement before after)
        (block-open before after)
        (brace-list-open before after)
        (brace-entry-open before after)
        (block-close . c-snug-do-while)
        (extern-lang-open before after)
        (inexpr-class-open before after)
        (inexpr-class-close before after)
      )
    )
    (c-offsets-alist . (
        (statement-block-intro . +)
        (knr-argdecl-intro . +)
        (substatement-open . +)
        (label . 0)
        (statement-case-open . +)
        (statement-cont . +)
        (arglist-intro . c-lineup-arglist-intro-after-paren)
        (arglist-close . c-lineup-arglist)
        (inline-open . 0)
        (brace-list-open . +)
      )
    )
    (c-echo-syntactic-information-p . t)
  )
  "My C Programming Style"
)

(defun my-c-mode-common-hook ()
  (message "my-c-mode-common-hook called")
    ;; add my personal style and set it for the current buffer
  (c-add-style "PERSONAL" my-c-style t)
    ;; other customizations
  (setq tab-width 4)
    ;; we like auto-newline and hungry-delete
  (c-toggle-auto-hungry-state 1)
  (define-key c-mode-base-map [return]  'newline-and-indent)
  (define-key c-mode-base-map [kp-enter]  'newline-and-indent)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;; <<-- C++ Mode Customizations <<--



reply via email to

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