branch: elpa/editorconfig
commit 5be6d1b972197d4a398962841c1e6b6993ad5c78
Author: monnier <[email protected]>
Commit: GitHub <[email protected]>

    Use `delete-trailing-whitespace-mode` when available (#382)
    
    (editorconfig-trim-whitespaces-mode): Use `delete-trailing-whitespace-mode`
    when available.  Improve `:type`.
    (editorconfig-properties-hash): Use `defvar-local`.
    Remove misleading statement in the docstring.
    
    * ert-tests/editorconfig-tests.el (test-trim-trailing-ws): Adjust test.
    
    * editorconfig-fnmatch.el (editorconfig-fnmatch--cache-hashtable):
    Use `defconst`.
    (editorconfig-fnmatch--do-translate): Don't backslash escape `-` and `,`
    in regexps (breaks new regexp extensions).
    
    Co-authored-by: Hong Xu <[email protected]>
---
 editorconfig-fnmatch.el         | 16 +++++-----------
 editorconfig.el                 | 15 +++++++--------
 ert-tests/editorconfig-tests.el |  6 ++++--
 3 files changed, 16 insertions(+), 21 deletions(-)

diff --git a/editorconfig-fnmatch.el b/editorconfig-fnmatch.el
index aa4c052ad1f..7210ed565fd 100644
--- a/editorconfig-fnmatch.el
+++ b/editorconfig-fnmatch.el
@@ -1,6 +1,6 @@
 ;;; editorconfig-fnmatch.el --- Glob pattern matching  -*- lexical-binding: t 
-*-
 
-;; Copyright (C) 2011-2024  Free Software Foundation, Inc.
+;; Copyright (C) 2011-2025  Free Software Foundation, Inc.
 
 ;; Author: EditorConfig Team <[email protected]>
 ;; Package: editorconfig
@@ -55,13 +55,9 @@
 
 (require 'cl-lib)
 
-(defvar editorconfig-fnmatch--cache-hashtable
-  nil
+(defconst editorconfig-fnmatch--cache-hashtable ;; Clear cache on file reload.
+  (make-hash-table :test 'equal)
   "Cache of shell pattern and its translation.")
-;; Clear cache on file reload
-(setq editorconfig-fnmatch--cache-hashtable
-      (make-hash-table :test 'equal))
-
 
 (defconst editorconfig-fnmatch--left-brace-regexp
   "\\(^\\|[^\\]\\){"
@@ -147,7 +143,7 @@ translation is found for PATTERN."
 
     (while (< index length)
       (if (and (not is-escaped)
-               (string-match "[^]\\*?[{},/-]+"
+               (string-match "[^]\\*?[{},/]+"
                              ;;(string-match "[^]\\*?[{},/\\-]+" "?.a")
                              pattern
                              index)
@@ -203,8 +199,6 @@ translation is found for PATTERN."
                         "[^")
                     "[")))))
 
-           (?- (if in-brackets "-" "\\-"))
-
            (?\] (setq in-brackets nil) "]")
 
            (?\{
@@ -249,7 +243,7 @@ translation is found for PATTERN."
            (?,
             (if (and (> brace-level 0)
                      (not is-escaped))
-                "\\|" "\\,"))
+                "\\|" ","))
 
            (?\}
             (if (and (> brace-level 0)
diff --git a/editorconfig.el b/editorconfig.el
index 6300f0b6488..352a0d3f28b 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -75,7 +75,7 @@ Used by `editorconfig--execute-editorconfig-exec'."
   'editorconfig-get-properties-function
   "0.5")
 (defcustom editorconfig-get-properties-function
-  'editorconfig-core-get-properties-hash
+  #'editorconfig-core-get-properties-hash
   "A function which gets EditorConfig properties for specified file.
 
 This function will be called with one argument, full path of the target file,
@@ -363,18 +363,17 @@ When variable `buffer-file-name' matches any of the 
regexps, then
                                    (eval (file-truename (expand-file-name 
recentf-save-file))))
                              t)))
 
-(defcustom editorconfig-trim-whitespaces-mode nil
+(defcustom editorconfig-trim-whitespaces-mode
+  (when (fboundp 'delete-trailing-whitespace-mode)
+    #'delete-trailing-whitespace-mode)
   "Buffer local minor-mode to use to trim trailing whitespaces.
 
 If set, enable that mode when `trim_trailing_whitespace` is set to true.
 Otherwise, use `delete-trailing-whitespace'."
-  :type 'symbol)
+  :type 'function)
 
-(defvar editorconfig-properties-hash nil
-  "Hash object of EditorConfig properties that was enabled for current buffer.
-Set by `editorconfig-apply' and nil if that is not invoked in
-current buffer yet.")
-(make-variable-buffer-local 'editorconfig-properties-hash)
+(defvar-local editorconfig-properties-hash nil
+  "Hash object of EditorConfig properties that was enabled for current 
buffer.")
 (put 'editorconfig-properties-hash
      'permanent-local
      t)
diff --git a/ert-tests/editorconfig-tests.el b/ert-tests/editorconfig-tests.el
index 2e422af4035..8cb4a434310 100644
--- a/ert-tests/editorconfig-tests.el
+++ b/ert-tests/editorconfig-tests.el
@@ -102,8 +102,10 @@
 (ert-deftest test-trim-trailing-ws nil
   (editorconfig-mode 1)
   (with-visit-file (concat editorconfig-ert-dir "trim.txt")
-    (should (memq #'editorconfig--delete-trailing-whitespace
-                  before-save-hook)))
+    (if editorconfig-trim-whitespaces-mode
+        (should (symbol-value editorconfig-trim-whitespaces-mode))
+      (should (memq #'editorconfig--delete-trailing-whitespace
+                    before-save-hook))))
   ;; FIXME: We don't hook into `read-only-mode', so instead we should
   ;; make a more thorough test that saves the file after making the buffer
   ;; read-only and makes sure it does not trim the trailing-ws of the

Reply via email to