branch: scratch/editorconfig-cc commit 5034a3ae1636ac744dfdfe5e502c2adceb4daffd Author: 10sr <8slashes+...@gmail.com> Commit: Stefan Monnier <monn...@iro.umontreal.ca>
Add function to open nearest .editorconfig file (#131) --- editorconfig-core.el | 12 +++++++++++- editorconfig.el | 10 ++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/editorconfig-core.el b/editorconfig-core.el index d4aa56d5d7..9e75707b60 100644 --- a/editorconfig-core.el +++ b/editorconfig-core.el @@ -65,6 +65,8 @@ ;;; Code: +(require 'cl-lib) + (require 'editorconfig-core-handle) @@ -109,12 +111,20 @@ RESULT is used internally and normally should not be used." dir) (and handle (editorconfig-core-handle-root-p handle))) - (cons handle result) + (cl-remove-if-not 'identity + (cons handle result)) (editorconfig-core--get-handles parent confname (cons handle result))))) +;;;###autoload +(defun editorconfig-core-get-nearest-editorconfig (directory) + "Return path to .editorconfig file that is closest to DIRECTORY." + (let ((handle (car (last (editorconfig-core--get-handles directory + ".editorconfig"))))) + (when handle + (editorconfig-core-handle-path handle)))) ;;;###autoload (defun editorconfig-core-get-properties (&optional file confname confversion) diff --git a/editorconfig.el b/editorconfig.el index de31620810..1776ad320d 100644 --- a/editorconfig.el +++ b/editorconfig.el @@ -304,6 +304,16 @@ It calls `editorconfig-get-properties-from-exec' if (require 'editorconfig-core) (editorconfig-core-get-properties-hash))) +(defun editorconfig-find-current-editorconfig () + "Find the closest .editorconfig file for current file." + (interactive) + (eval-and-compile (require 'editorconfig-core)) + (let ((file (editorconfig-core-get-nearest-editorconfig + default-directory))) + (when file + (find-file file)))) + +;;;###autoload (defun editorconfig-display-current-properties () "Display EditorConfig properties extracted for current buffer." (interactive)