Created
October 21, 2015 03:08
-
-
Save dakrone/0b4888de1ca142641b28 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; via http://emacs.stackexchange.com/questions/17327/how-to-have-c-offset-style-correctly-detect-a-java-constructor-and-change-indent | |
(defun my/point-in-defun-declaration-p () | |
(let ((bod (save-excursion (c-beginning-of-defun) | |
(point)))) | |
(<= bod | |
(point) | |
(save-excursion (goto-char bod) | |
(re-search-forward "{") | |
(point))))) | |
(defun my/is-string-concatenation-p () | |
"Returns true if the previous line is a string concatenation" | |
(save-excursion | |
(let ((start (point))) | |
(forward-line -1) | |
(if (re-search-forward " \\\+$" start t) t nil)))) | |
(defun my/inside-java-lambda-p () | |
"Returns true if point is the first statement inside of a lambda" | |
(save-excursion | |
(c-beginning-of-statement-1) | |
(let ((start (point))) | |
(forward-line -1) | |
(if (search-forward " -> {" start t) t nil)))) | |
(defun my/arglist-cont-nonempty-indentation (arg) | |
(if (my/inside-java-lambda-p) | |
'+ | |
(if (my/is-string-concatenation-p) | |
16 ;; TODO don't hard-code | |
(unless (my/point-in-defun-declaration-p) '++)))) | |
(defun my/statement-block-intro (arg) | |
(if (and (c-at-statement-start-p) (my/inside-java-lambda-p)) 0 '+)) | |
(defun my/block-close (arg) | |
(if (my/inside-java-lambda-p) '- 0)) | |
(defconst intellij-java-style | |
'((c-basic-offset . 4) | |
(c-comment-only-line-offset . (0 . 0)) | |
;; the following preserves Javadoc starter lines | |
(c-offsets-alist | |
. | |
((inline-open . 0) | |
(topmost-intro-cont . +) | |
(statement-block-intro . my/statement-block-intro) | |
(block-close . my/block-close) | |
(knr-argdecl-intro . +) | |
(substatement-open . +) | |
(substatement-label . +) | |
(case-label . +) | |
(label . +) | |
(statement-case-open . +) | |
(statement-cont . ++) | |
(arglist-intro . 0) | |
(arglist-cont-nonempty . (my/arglist-cont-nonempty-indentation | |
c-lineup-arglist)) | |
(arglist-close . --) | |
(inexpr-class . 0) | |
(access-label . 0) | |
(inher-intro . ++) | |
(inher-cont . ++) | |
(brace-list-intro . +) | |
(func-decl-cont . ++)))) | |
"Elasticsearch's Intellij Java Programming Style") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment