koko1000ban / emacs-uncrustify-mode

Minor mode to automatically uncrustify.
7 stars 3 forks source link

Automatically find .uncrustify.cfg in parent dir #4

Open Ambrevar opened 5 years ago

Ambrevar commented 5 years ago

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.

Ambrevar commented 5 years ago

@koko1000ban : Are you still maintaining this? If not, I'd be happy to take over maintenance :)