This is a new take on the clang-format package. It is distinguished because it provides only
a lightweight ELisp wrapper around the clang-format
binary. It is also distinct from
clang-format+, which wraps the former to offer an on-save hook. We incorporate this
functionality directly within our package.
Why clang-format-lite?
- It’s lightweight with no dependencies on other packages.
- Supports formatting of remote files, which the other packages do not.
- Integrates
clang-format
on-save functionality directly.
The package may be installed through MELPA. I recommend use-package.
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(unless (package-installed-p 'use-package)
(package-refresh-contents)
(package-install 'use-package))
(require 'use-package)
(use-package clang-format-lite
:ensure t)
There are two primary public interfaces.
- clang-format-lite-save-hook
- This buffer-local hook can be added to a mode hook
to enable
clang-format
on save. Furthermore, the variableclang-format-lite-only-if-config
determines whether or notclang-format
is actually run. - clang-format-lite-only-if-config
- This variable can be set to either
nil
ort
. Ifnil
, thenclang-format
is always run. Ift
, thenclang-format
is run only when a.clang-format
file is found.
Here is a simple example:
;; run clang-format only if the .clang-format file is found
(setq clang-format-lite-only-if-config t)
;; and we are in c++ mode
(add-hook 'c++-mode-hook #'clang-format-lite-save-hook)
;; or we are in c mode
(add-hook 'c-mode-hook #'clang-format-lite-save-hook)