branch: scratch/editorconfig-cc
commit 18ccad3beb9cdf2e0e7a258f8684820a5791d127
Author: 10sr <8.slas...@gmail.com>
Commit: Stefan Monnier <monn...@iro.umontreal.ca>

    Separate some utility commands to new file (#330)
    
    * Remove switch to use legacy version
    
    Remove `editorconfig--lagacy-version` variable.
    
    * Create editorconfig-tools.el and move some functions into it
    
    * Fix merge
    
    * Update commentary
    
    * Update CHANGELOG
    
    * Update text
---
 CHANGELOG.md          |   8 ++++
 editorconfig-tools.el | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++
 editorconfig.el       |  83 ----------------------------------
 3 files changed, 130 insertions(+), 83 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 69fd964461..088486902e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,14 @@ and this project adheres to [Semantic 
Versioning](https://semver.org/spec/v2.0.0
 
 - Remove editorconfig-mode legacy version ([#304])
   - Remove flag `editorconfig--legacy-version`, which was defined in [#263]
+- Separate some utility commands to new file ([#330])
+  - Following commands are now defined in `editoroconfig-tools.el`, not 
`editorconfig.el`
+    - editorconfig-apply
+    - editorconfig-mode-apply
+    - editorconfig-find-current-editorconfig
+    - editorconfig-display-current-properties (and its alias 
describe-editorconfig-properties)
+    - editorconfig-format-buffer
+  - These commands are configured to be autoloaded functions, except for 
`editorconfig-mode-apply`
 
 ### Deprecated
 
diff --git a/editorconfig-tools.el b/editorconfig-tools.el
new file mode 100644
index 0000000000..2084bf72e6
--- /dev/null
+++ b/editorconfig-tools.el
@@ -0,0 +1,122 @@
+;;; editorconfig-tools.el --- Editorconfig tools   -*- lexical-binding: t -*-
+
+;; Copyright (C) 2011-2023 EditorConfig Team
+
+;; Author: EditorConfig Team <editorcon...@googlegroups.com>
+
+;; See
+;; https://github.com/editorconfig/editorconfig-emacs/graphs/contributors
+;; or the CONTRIBUTORS file for the list of contributors.
+
+;; This file is part of EditorConfig Emacs Plugin.
+
+;; EditorConfig Emacs Plugin is free software: you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or (at your
+;; option) any later version.
+
+;; EditorConfig Emacs Plugin is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
+;; Public License for more details.
+
+;; You should have received a copy of the GNU General Public License along with
+;; EditorConfig Emacs Plugin. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Some utility commands for users, not used from editorconfig-mode.
+
+;;; Code:
+
+(require 'cl-lib)
+
+(eval-when-compile
+  (require 'subr-x))
+
+
+(require 'editorconfig)
+
+;;;###autoload
+(defun editorconfig-apply ()
+  "Get and apply EditorConfig properties to current buffer.
+
+This function does not respect the values of `editorconfig-exclude-modes' and
+`editorconfig-exclude-regexps' and always applies available properties.
+Use `editorconfig-mode-apply' instead to make use of these variables."
+  (interactive)
+  (when buffer-file-name
+    (condition-case err
+        (progn
+          (let ((props (editorconfig-call-get-properties-function 
buffer-file-name)))
+            (condition-case err
+                (run-hook-with-args 'editorconfig-hack-properties-functions 
props)
+              (error
+               (display-warning '(editorconfig 
editorconfig-hack-properties-functions)
+                                (format "Error while running 
editorconfig-hack-properties-functions, abort running hook: %S"
+                                        err)
+                                :warning)))
+            (setq editorconfig-properties-hash props)
+            (editorconfig-set-local-variables props)
+            (editorconfig-set-coding-system-revert
+             (gethash 'end_of_line props)
+             (gethash 'charset props))
+            (condition-case err
+                (run-hook-with-args 'editorconfig-after-apply-functions props)
+              (error
+               (display-warning '(editorconfig 
editorconfig-after-apply-functions)
+                                (format "Error while running 
editorconfig-after-apply-functions, abort running hook: %S"
+                                        err)
+                                :warning)))))
+      (error
+       (display-warning '(editorconfig editorconfig-apply)
+                        (format "Error in editorconfig-apply, styles will not 
be applied: %S" err)
+                        :error)))))
+
+(defun editorconfig-mode-apply ()
+  "Get and apply EditorConfig properties to current buffer.
+
+This function does nothing when the major mode is listed in
+`editorconfig-exclude-modes', or variable `buffer-file-name' matches
+any of regexps in `editorconfig-exclude-regexps'."
+  (interactive)
+  (when (and major-mode
+             (not (editorconfig--disabled-for-majormode major-mode))
+             buffer-file-name
+             (not (editorconfig--disabled-for-filename buffer-file-name)))
+    (editorconfig-apply)))
+
+
+;;;###autoload
+(defun editorconfig-find-current-editorconfig ()
+  "Find the closest .editorconfig file for current file."
+  (interactive)
+  (eval-and-compile (require 'editorconfig-core))
+  (when-let* ((file (editorconfig-core-get-nearest-editorconfig
+                    default-directory)))
+    (find-file file)))
+
+;;;###autoload
+(defun editorconfig-display-current-properties ()
+  "Display EditorConfig properties extracted for current buffer."
+  (interactive)
+  (if editorconfig-properties-hash
+      (let ((buf (get-buffer-create "*EditorConfig Properties*"))
+            (file buffer-file-name)
+            (props editorconfig-properties-hash))
+        (with-current-buffer buf
+          (erase-buffer)
+          (insert (format "# EditorConfig for %s\n" file))
+          (maphash (lambda (k v)
+                     (insert (format "%S = %s\n" k v)))
+                   props))
+        (display-buffer buf))
+    (message "Properties are not applied to current buffer yet.")
+    nil))
+;;;###autoload
+(defalias 'describe-editorconfig-properties
+  'editorconfig-display-current-properties)
+
+
+(provide 'editorconfig-tools)
+;;; editorconfig-tools.el ends here
diff --git a/editorconfig.el b/editorconfig.el
index 76c0fd9a3e..c0f0596dd6 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -573,54 +573,6 @@ This function also removes `unset' properties and calls
   (editorconfig-set-trailing-ws (gethash 'trim_trailing_whitespace props))
   (editorconfig-set-line-length (gethash 'max_line_length props)))
 
-;;;###autoload
-(defun editorconfig-apply ()
-  "Get and apply EditorConfig properties to current buffer.
-
-This function does not respect the values of `editorconfig-exclude-modes' and
-`editorconfig-exclude-regexps' and always applies available properties.
-Use `editorconfig-mode-apply' instead to make use of these variables."
-  (interactive)
-  (when buffer-file-name
-    (condition-case err
-        (progn
-          (let ((props (editorconfig-call-get-properties-function 
buffer-file-name)))
-            (condition-case err
-                (run-hook-with-args 'editorconfig-hack-properties-functions 
props)
-              (error
-               (display-warning '(editorconfig 
editorconfig-hack-properties-functions)
-                                (format "Error while running 
editorconfig-hack-properties-functions, abort running hook: %S"
-                                        err)
-                                :warning)))
-            (setq editorconfig-properties-hash props)
-            (editorconfig-set-local-variables props)
-            (editorconfig-set-coding-system-revert
-             (gethash 'end_of_line props)
-             (gethash 'charset props))
-            (condition-case err
-                (run-hook-with-args 'editorconfig-after-apply-functions props)
-              (error
-               (display-warning '(editorconfig 
editorconfig-after-apply-functions)
-                                (format "Error while running 
editorconfig-after-apply-functions, abort running hook: %S"
-                                        err)
-                                :warning)))))
-      (error
-       (display-warning '(editorconfig editorconfig-apply)
-                        (format "Error in editorconfig-apply, styles will not 
be applied: %S" err)
-                        :error)))))
-
-(defun editorconfig-mode-apply ()
-  "Get and apply EditorConfig properties to current buffer.
-
-This function does nothing when the major mode is listed in
-`editorconfig-exclude-modes', or variable `buffer-file-name' matches
-any of regexps in `editorconfig-exclude-regexps'."
-  (interactive)
-  (when (and major-mode
-             (not (editorconfig--disabled-for-majormode major-mode))
-             buffer-file-name
-             (not (editorconfig--disabled-for-filename buffer-file-name)))
-    (editorconfig-apply)))
 
 (defun editorconfig-major-mode-hook ()
   "Function to run when `major-mode' has been changed.
@@ -779,41 +731,6 @@ To disable EditorConfig in some buffers, modify
         (remove-hook hook 'editorconfig-major-mode-hook)))))
 
 
-;; Tools
-;; Some useful commands for users, not required for EditorConfig to work
-
-;;;###autoload
-(defun editorconfig-find-current-editorconfig ()
-  "Find the closest .editorconfig file for current file."
-  (interactive)
-  (eval-and-compile (require 'editorconfig-core))
-  (when-let* ((file (editorconfig-core-get-nearest-editorconfig
-                    default-directory)))
-    (find-file file)))
-
-;;;###autoload
-(defun editorconfig-display-current-properties ()
-  "Display EditorConfig properties extracted for current buffer."
-  (interactive)
-  (if editorconfig-properties-hash
-      (let ((buf (get-buffer-create "*EditorConfig Properties*"))
-            (file buffer-file-name)
-            (props editorconfig-properties-hash))
-        (with-current-buffer buf
-          (erase-buffer)
-          (insert (format "# EditorConfig for %s\n" file))
-          (maphash (lambda (k v)
-                     (insert (format "%S = %s\n" k v)))
-                   props))
-        (display-buffer buf))
-    (message "Properties are not applied to current buffer yet.")
-    nil))
-;;;###autoload
-(defalias 'describe-editorconfig-properties
-  'editorconfig-display-current-properties)
-
-
-
 ;; (defconst editorconfig--version
 ;;   (eval-when-compile
 ;;     (require 'lisp-mnt)

Reply via email to