最近在学习emacs,记录下学习的过程,方便以后自己的查找

1.默认情况下Emacs的缩进是下面这样

if(NULL != ptr)
  {
  }

如果想要变成

if(NULL != ptr)
{
}

那么需要在.emacs中加入

;; c style K&R

(add-hook 'c++-mode-common-hook (lambda() (c-set-style "k&r")))

(add-hook 'c-mode-common-hook (lambda() (c-set-style "k&r")))

2. 括号自动补齐另一半并把光标放在中间

;;-------------------------------------------括号补全--------------------------------------
;;; 括号自动补全
(defun my-c-mode-auto-pair ()
(interactive)
(make-local-variable 'skeleton-pair-alist)
(setq skeleton-pair-alist '(
(?` ?` _ "''")
(?\( ? _ " )")
(?\[ ? _ " ]")
(?{ \n > _ \n ?} >)))
(setq skeleton-pair t)
(local-set-key (kbd "(") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "{") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "`") 'skeleton-pair-insert-maybe)
(local-set-key (kbd "[") 'skeleton-pair-insert-maybe))
(add-hook 'c-mode-hook 'my-c-mode-auto-pair)
(add-hook 'c++-mode-hook 'my-c-mode-auto-pair)
;;-------------------------------------------括号补全-----------------------------

3.显示行号

;;--------显示行号------------
(global-linum-mode t)