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

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

cc-mode: Is there a method automatically insert space between "if", "()


From: Wang Lei
Subject: cc-mode: Is there a method automatically insert space between "if", "()" and "{"
Date: Sun, 6 Sep 2009 18:45:11 +0800

Hi, all!
If the subject is not clear enough, sorry.

Could someone tell me how to insert spaces automatically as you type
in the following situation.

if () {  <---here, between if, (), {
}

while () { <--- here
}

for () {  <---here
}

But not insert in function call.

And, Could you let me see your setting about c-mode? Today, after
times' trying finally I can achieve this.
int a[] = {
        {},
        {}
};

I'm tired. Any help is appreciated. At the end, this is mine.
-------code----------------------
;; Smart compile
(require 'smart-compile+)
(add-to-list 'smart-compile-alist '("\\.c$" . "gcc -O2 %f -o %n"))
(global-set-key [?\C-c ?\C-c] 'smart-compile)
(global-set-key [?\C-c ?\C-r] 'smart-run)

;;C mode
(add-to-list 'auto-mode-alist '("\\.[ch]$" . my-c-mode))
(setq c-eldoc-includes "`pkg-config gtk+-2.0 --cflags` -I./ -I../ -I../lib/")
(defun my-c-mode ()
  (require 'c-eldoc)
  (require 'ctypes)
  (c-mode)
  (c-turn-on-eldoc-mode)
  (c-set-style "linux")
  (setq c-hanging-braces-alist
        '((brace-list-open after)
          (brace-list-intro)
          (brace-entry-open before)
          (brace-entry-close after)
          (brace-list-close after)
          (substatement-open after)
          (block-close . c-snug-do-while)
          (arglist-cont-nonempty)))
  (setq c-cleanup-list
        '(comment-close-slash
          list-close-comma
          defun-close-semi
          brace-else-brace
          brace-elseif-brace))
  (setq c-auto-newline t)
  (setq c-hungry-delete-key t)
  (setq indent-tabs-mode t)
  (setq compilation-ask-about-save nil)
  (local-unset-key [?\C-c ?\C-c])
  (define-key c-mode-base-map [return] 'newline-and-indent))
--------code--------------------------------
-- 
Regards
Lei




reply via email to

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