我感到很惊讶,但在搜索之后,我找不到可用于让emacs跟随Google Java Style的emacs配置。
如果已经有这样的配置,我会很感激它的链接。
否则,我将如何创建这样的配置?
更新:
我想学习的最基本的事情:我设置哪些自定义变量来获取2 spaces for block indentation和4 spaces for continuation lines?
答案 0 :(得分:1)
将https://github.com/google/styleguide/blob/gh-pages/google-c-style.el放在您的加载路径上,例如~/.emacs.d/
。
然后,在您的Emacs init文件中,添加:
;; 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)
答案 1 :(得分:0)
您可以定义自己的样式并使用" c-set-style"来应用它。下面是我如何定义自己的C风格并进行设置。为java定义样式是一样的。请注意,java在某种程度上被视为" submode"因此,所有变量和函数都以" 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)
))
答案 2 :(得分:0)
如果您下载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))))))