dottedmag created this revision.
dottedmag added a reviewer: djasper.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
This allows one to enable `clang-format-buffer` on file save and avoid
reformatting files that are outside of any project with .clang-format style.
Repository:
rC Clang
https://reviews.llvm.org/D69752
Files:
tools/clang-format/clang-format.el
Index: tools/clang-format/clang-format.el
===
--- tools/clang-format/clang-format.el
+++ tools/clang-format/clang-format.el
@@ -57,6 +57,18 @@
:safe #'stringp)
(make-variable-buffer-local 'clang-format-style)
+(defcustom clang-format-fallback-style "none"
+ "Fallback style to pass to clang-format.
+
+This style will be used if clang-format-style is set to \"file\"
+and no .clang-format is found in the directory of the buffer or
+one of parent directories. Set to \"none\" to disable formatting
+in such buffers."
+ :group 'clang-format
+ :type 'string
+ :safe #'stringp)
+(make-variable-buffer-local 'clang-format-fallback-style)
+
(defun clang-format--extract (xml-node)
"Extract replacements and cursor information from XML-NODE."
(unless (and (listp xml-node) (eq (xml-node-name xml-node) 'replacements))
@@ -162,6 +174,7 @@
,@(and assume-file-name
(list "-assume-filename"
assume-file-name))
,@(and style (list "-style" style))
+ "-fallback-style" ,clang-format-fallback-style
"-offset" ,(number-to-string file-start)
"-length" ,(number-to-string (- file-end
file-start))
"-cursor" ,(number-to-string cursor
Index: tools/clang-format/clang-format.el
===
--- tools/clang-format/clang-format.el
+++ tools/clang-format/clang-format.el
@@ -57,6 +57,18 @@
:safe #'stringp)
(make-variable-buffer-local 'clang-format-style)
+(defcustom clang-format-fallback-style "none"
+ "Fallback style to pass to clang-format.
+
+This style will be used if clang-format-style is set to \"file\"
+and no .clang-format is found in the directory of the buffer or
+one of parent directories. Set to \"none\" to disable formatting
+in such buffers."
+ :group 'clang-format
+ :type 'string
+ :safe #'stringp)
+(make-variable-buffer-local 'clang-format-fallback-style)
+
(defun clang-format--extract (xml-node)
"Extract replacements and cursor information from XML-NODE."
(unless (and (listp xml-node) (eq (xml-node-name xml-node) 'replacements))
@@ -162,6 +174,7 @@
,@(and assume-file-name
(list "-assume-filename" assume-file-name))
,@(and style (list "-style" style))
+ "-fallback-style" ,clang-format-fallback-style
"-offset" ,(number-to-string file-start)
"-length" ,(number-to-string (- file-end file-start))
"-cursor" ,(number-to-string cursor
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits