Skip to content

Commit df1cb8d

Browse files
committed
Use delete-trailing-whitespace-mode when available
(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--do-translate): Don't backslash escape `-` in regexps (breaks tests with new regexp extensions).
1 parent 4af1044 commit df1cb8d

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

editorconfig-fnmatch.el

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
;;; editorconfig-fnmatch.el --- Glob pattern matching -*- lexical-binding: t -*-
22

3-
;; Copyright (C) 2011-2024 Free Software Foundation, Inc.
3+
;; Copyright (C) 2011-2025 Free Software Foundation, Inc.
44

55
;; Author: EditorConfig Team <[email protected]>
66
;; Package: editorconfig
@@ -203,7 +203,7 @@ translation is found for PATTERN."
203203
"[^")
204204
"[")))))
205205

206-
(?- (if in-brackets "-" "\\-"))
206+
(?- "-")
207207

208208
(?\] (setq in-brackets nil) "]")
209209

editorconfig.el

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Used by `editorconfig--execute-editorconfig-exec'."
7575
'editorconfig-get-properties-function
7676
"0.5")
7777
(defcustom editorconfig-get-properties-function
78-
'editorconfig-core-get-properties-hash
78+
#'editorconfig-core-get-properties-hash
7979
"A function which gets EditorConfig properties for specified file.
8080
8181
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
363363
(eval (file-truename (expand-file-name recentf-save-file))))
364364
t)))
365365

366-
(defcustom editorconfig-trim-whitespaces-mode nil
366+
(defcustom editorconfig-trim-whitespaces-mode
367+
(when (fboundp 'delete-trailing-whitespace-mode)
368+
#'delete-trailing-whitespace-mode)
367369
"Buffer local minor-mode to use to trim trailing whitespaces.
368370
369371
If set, enable that mode when `trim_trailing_whitespace` is set to true.
370372
Otherwise, use `delete-trailing-whitespace'."
371-
:type 'symbol)
373+
:type 'function)
372374

373-
(defvar editorconfig-properties-hash nil
374-
"Hash object of EditorConfig properties that was enabled for current buffer.
375-
Set by `editorconfig-apply' and nil if that is not invoked in
376-
current buffer yet.")
377-
(make-variable-buffer-local 'editorconfig-properties-hash)
375+
(defvar-local editorconfig-properties-hash nil
376+
"Hash object of EditorConfig properties that was enabled for current buffer.")
378377
(put 'editorconfig-properties-hash
379378
'permanent-local
380379
t)

ert-tests/editorconfig-tests.el

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,10 @@
102102
(ert-deftest test-trim-trailing-ws nil
103103
(editorconfig-mode 1)
104104
(with-visit-file (concat editorconfig-ert-dir "trim.txt")
105-
(should (memq #'editorconfig--delete-trailing-whitespace
106-
before-save-hook)))
105+
(if editorconfig-trim-whitespaces-mode
106+
(should (symbol-value editorconfig-trim-whitespaces-mode))
107+
(should (memq #'editorconfig--delete-trailing-whitespace
108+
before-save-hook))))
107109
;; FIXME: We don't hook into `read-only-mode', so instead we should
108110
;; make a more thorough test that saves the file after making the buffer
109111
;; read-only and makes sure it does not trim the trailing-ws of the

0 commit comments

Comments
 (0)