emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

scratch/emacs-editorconfig 12af7738a0a 145/364: Add function to open nea


From: Stefan Monnier
Subject: scratch/emacs-editorconfig 12af7738a0a 145/364: Add function to open nearest .editorconfig file (#131)
Date: Tue, 18 Jun 2024 01:40:50 -0400 (EDT)

branch: scratch/emacs-editorconfig
commit 12af7738a0a9e9c693e41f55a1b536e4f44030fd
Author: 10sr <8slashes+git@gmail.com>
Commit: Stefan Monnier <monnier@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 d4aa56d5d78..9e75707b609 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 ef3555de88f..176cd9b3d35 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -247,6 +247,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)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]