Looking up .uncrustify.cfg in parent dir would allow for more contextual formatting (e.g. a project can provide its own .uncrustify.cfg).
For instance
(defun uncrustify-format-file-lookup ()
"Find .clang-format or .uncrustify.cfg in parent folder up to Git root.
Return nil if non is found or if not a Git repository."
(unless (require 'magit nil 'noerror)
(error "Magit is missing"))
(when (or (magit-get-current-branch) (magit-get-current-tag))
(let ((git-root (magit-rev-parse "--show-toplevel"))
(default-directory default-directory))
(while (and (string= (magit-rev-parse "--show-toplevel") git-root)
(not (file-exists-p ".uncrustify.cfg")))
(cd ".."))
(and (file-exists-p ".uncrustify.cfg")
(expand-file-name ".uncrustify.cfg" default-directory)))))
We can always replace the magit snippet with something else to limit the root of the project.
Looking up
.uncrustify.cfg
in parent dir would allow for more contextual formatting (e.g. a project can provide its own.uncrustify.cfg
).For instance
We can always replace the
magit
snippet with something else to limit the root of the project.