我很惊讶,但是在搜索后,我找不到一个可以用来使emacs遵循Google Java Style的配置。
如果已经有这样的配置可用,我会很感激提供链接。
否则,我该如何创建这样的配置?
更新:
我想学习的最基本的东西是:我设置哪些自定义变量才能获得块缩进为2个空格和续行缩进为4个空格?
如果已经有这样的配置可用,我会很感激提供链接。
否则,我该如何创建这样的配置?
更新:
我想学习的最基本的东西是:我设置哪些自定义变量才能获得块缩进为2个空格和续行缩进为4个空格?
~/.emacs.d/
中。;; Also works for Java.
(autoload 'google-set-c-style "google-c-style")
(autoload 'google-make-newline-indent "google-c-style")
(add-hook 'c-mode-common-hook 'google-set-c-style)
(add-hook 'c-mode-common-hook 'google-make-newline-indent)
你可以定义自己的风格并使用"c-set-style"应用它。下面是我如何定义和设置自己的C风格。为Java定义风格也是一样的。请注意,Java在某种程度上被视为C的“子模式”,因此所有变量和函数都以"c-"开头。
;;; c mode configuration
(defconst lgfang-c-style
'((c-tab-always-indent . t)
(c-basic-offset . 4)
(c-ignore-auto-fill . nil)
(c-comment-only-line-offset . (0 . 0))
(c-hanging-braces-alist . ((substatement-open after before)
(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 . ((knr-argdecl-intro . 5)
(arglist-intro . +)
(arglist-close . c-lineup-close-paren)
(inclass . +)
(member-init-intro . +)
(statement-block-intro . +)
(defun-block-intro . +)
(substatement-open . 0)
(label . 0)
(statement-case-open . +)
(statement-case-intro . +)
(case-label . 0)
(statement-cont . c-lineup-math)
(inline-open . 0)
(brace-list-open . +)
(topmost-intro-cont . 0)
(c . 1) ; "c" for continue of comment, not "c
; programming language"
))
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "lgf: ")
(c-comment-prefix-regexp . ((awk-mode . "#+(lgf: )?")
(other ."lgf: \\|//+\\|\\**")))
;; go to this file and test if c block comments works
;; [[file:./patches/comments-test.c]]
(c-echo-syntactic-information-p . t))
"lgfang's C Programming Style")
(c-add-style "lgfang" lgfang-c-style nil)
(add-hook 'c-mode-common-hook
(lambda ()
(c-set-style "lgfang")
(c-toggle-hungry-state 1)
(hs-minor-mode 1)
(turn-on-cwarn-mode)
;; (eldoc-mode 1)
))
如果你下载https://github.com/google/styleguide/blob/gh-pages/google-c-style.el(如mernst建议的那样),你可以将样式直接放入你的项目中,并通过.dir-locals.el文件启用它。
((java-mode . ((eval . (progn
(add-to-list 'load-path (concat (vc-root-dir) "emacs"))
(require 'google-c-style)
(google-set-c-style)
(google-make-newline-indent))))))
java-style
,我认为这相当不典型(并且它没有其他可供选择的风格,开箱即用)。 - Drew