Skip to content

Commit de57db5

Browse files
java-team-github-botgoogle-java-format Team
authored and
google-java-format Team
committed
Add customization for google-java-format arguments
Setting google-java-format-arguments to `'("--aosp")` makes it easy to format on Android java files. PiperOrigin-RevId: 657263779
1 parent 1296f1d commit de57db5

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

core/src/main/scripts/google-java-format.el

+18-10
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ A string containing the name or the full path of the executable."
4949
:type '(file :must-match t :match (lambda (widget file) (file-executable-p file)))
5050
:risky t)
5151

52+
(defcustom google-java-format-arguments
53+
'()
54+
"Arguments to pass into google-java-format-executable"
55+
:group 'google-java-format
56+
:type '(repeat string)
57+
:risky t)
58+
5259
;;;###autoload
5360
(defun google-java-format-region (start end)
5461
"Use google-java-format to format the code between START and END.
@@ -62,16 +69,17 @@ there is no region, then formats the current line."
6269
(temp-buffer (generate-new-buffer " *google-java-format-temp*"))
6370
(stderr-file (make-temp-file "google-java-format")))
6471
(unwind-protect
65-
(let ((status (call-process-region
66-
;; Note that emacs character positions are 1-indexed,
67-
;; and google-java-format is 0-indexed, so we have to
68-
;; subtract 1 from START to line it up correctly.
69-
(point-min) (point-max)
70-
google-java-format-executable
71-
nil (list temp-buffer stderr-file) t
72-
"--offset" (number-to-string (1- start))
73-
"--length" (number-to-string (- end start))
74-
"-"))
72+
(let ((status (apply #'call-process-region
73+
;; Note that emacs character positions are 1-indexed,
74+
;; and google-java-format is 0-indexed, so we have to
75+
;; subtract 1 from START to line it up correctly.
76+
(point-min) (point-max)
77+
google-java-format-executable
78+
nil (list temp-buffer stderr-file) t
79+
(append google-java-format-arguments
80+
`("--offset" ,(number-to-string (1- start))
81+
"--length" ,(number-to-string (- end start))
82+
"-"))))
7583
(stderr
7684
(with-temp-buffer
7785
(insert-file-contents stderr-file)

0 commit comments

Comments
 (0)