Use -style=<string>
of clang-format
:
Coding style, currently supports: LLVM, Google, Chromium, Mozilla,
WebKit.
Use -style=file to load style configuration from .clang-format
file located in one of the parent directories of the source file (or
current directory for stdin).
Use -style="{key: value, ...}" to set
specific parameters, e.g.: -style="{BasedOnStyle: llvm, IndentWidth:
8}"
Define a function with a style
forwarded to clang-format-region
. Then, bind it to a key:
(defun clang-format-region-mozilla (s e)
(interactive
(if (use-region-p)
(list (region-beginning) (region-end))
(list (point) (point))))
(clang-format-region s e "Mozilla"))
(define-key c++-mode-map (kbd "C-<f10>") #'clang-format-region-mozilla)
(defun clang-format-region-llvm (s e)
(interactive
(if (use-region-p)
(list (region-beginning) (region-end))
(list (point) (point))))
(clang-format-region s e "LLVM"))
(define-key c++-mode-map (kbd "C-<f11>") #'clang-format-region-llvm)
The upper example maps:
- C-F10 to
clang-format-region
with the "Mozilla"
style
- C-F11 to
clang-format-region
with the "LLVM"
style
Change the keys and the styles as it suits you.