tab缩进影响了helm-gtags

下面这段配置是对代码中的tab缩进做的优化,从CSDN上抄来的,感觉挺好。 但是用上它以后,我打开.c文件后 helm-gtags-mode不会自动打开 helm-gtags 已经添加hook 到c-mode上。把下面的注释掉,打开.c .h文件后helm-gtags-mode就会自动加载。 大神帮忙瞅瞅这是什么原因。

另外,平时打开.c文件是显示的是C/l mode 加上下面的配置以后就显示C/lah mode。

(setq indent-tabs-mode nil)
(setq default-tab-width 4)
(setq tab-width 4)
(setq tab-stop-list ())
(loop for x downfrom 40 to 1 do
      (setq tab-stop-list (cons (* x 4) tab-stop-list)))

(defconst my-c-style
  '((c-tab-always-indent        . t)
    (c-comment-only-line-offset . 4)
    (c-hanging-braces-alist     . ((substatement-open after)
                                   (brace-list-open)))
    (c-hanging-colons-alist     . ((member-init-intro before)
                                   (inher-intro)
                                   (case-label after)
                                   (label after)
                                   (access-label after)))
    (c-cleanup-list             . (scope-operator
                                   empty-defun-braces
                                   defun-close-semi))
    (c-offsets-alist            . ((arglist-close . c-lineup-arglist)
                                   (substatement-open . 0)
                                   (case-label        . 4)
                                   (block-open        . 0)
                                   (knr-argdecl-intro . -)))
    (c-echo-syntactic-information-p . t)
    )
  "My C Programming Style")

;; offset customizations not in my-c-style
(setq c-offsets-alist '((member-init-intro . ++)))

;; Customizations for all modes in CC Mode.
(defun my-c-mode-common-hook ()
  ;; 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
        ;; this will make sure spaces are used instead of tabs
        indent-tabs-mode nil)
  ;; we like auto-newline and hungry-delete
  (c-toggle-auto-hungry-state 1)
  ;; key bindings for all supported languages.  We can put these in
  ;; c-mode-base-map because c-mode-map, c++-mode-map, objc-mode-map,
  ;; java-mode-map, idl-mode-map, and pike-mode-map inherit from it.
  (define-key c-mode-base-map "/C-m" 'c-context-line-break)
  )

(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)

/ 后面提示的是目前开启的特性:

l -> electric-indent-mode
a -> auto-newline
h -> hungry-delete-key

"/C-m" 不是合法的按键写法,应该用 "\C-m"[?\C-m],如果你没打算把它和 RET 区分开的话,也可以用 (kbd "RET")

1 个赞

非常感谢。能正常使用了