branch: elpa/editorconfig
commit 906b78e04220705f076e7de5db58c31a394d02f3
Author: 10sr <8.slas...@gmail.com>
Commit: GitHub <nore...@github.com>

    Scratch/editorconfig (#346)
    
    * Rename test files to `<foo>-tests.el`
    
    This follows the convention used in Emacs's own test suite and works around
    annoying circular `require`s when `ert-tests` happens to be in `load-path`.
    Also adjust the Makefile not to get confused by generated files.
    
    * Makefile (SRCS): Filter out ELPA-generated files.
    
    * (editorconfig--should-set): Eliminate `lisp-indent-offset` special case
    
    Instead of treating `lisp-indent-offset` specially in
    `editorconfig--should-set` (to obey `editorconfig-lisp-use-default-indent`),
    use a new function `editorconfig-set-indentation-lisp-mode`
    for Lisp modes.
    
    * lisp/editorconfig.el (editorconfig--should-set): Remove `size` argument.
    (editorconfig-set-indentation): Adjust calls accordingly.
    (editorconfig-set-indentation-lisp-mode): New function.
    (editorconfig-indentation-alist): Use it.
    
    * Fix minor cosmetic issues
    
    Mostly fix compiler warnings and prefer #' to quote function names.
    
    * editorconfig.el: Remove dependency on `nadvice` since we require
    Emacs-26 which includes `nadvice` already.
    Remove redundant `require`s.  Remove redundant `:group` arguments.
    Move `defvar`s outside of `eval-when-compile`.
    Remove "post-end trailer".
    * .dir-locals.el: New file, to replace the "post-end trailer".
    
    * ert-tests/editorconfig-core-handle-tests.el (editorconfig--fixtures):
    Rename from `fixtures`.  Change all uses.
    
    * ert-tests/editorconfig-tests.el (test-editorconfig)
    (test-local-variables, test-hack-properties-functions):
    Use `bound-and-true-p` when it's not guaranteed that the var will
    be defined.
    
    * Don't hook into `read-only-mode-hook`
    
    Don't re-set variables just because `read-only-mode` is (de)activated,
    and with Emacs-30's hooks it would be even less natural to do.
    Also `buffer-read-only` can change without calling `read-only-mode`,
    so better test it dynamically when we try to trim whitespace.
    
    * lisp/editorconfig.el (editorconfig--delete-trailing-whitespace):
    New function.
    (editorconfig-set-trailing-ws): Use it.  Use `pcase`.
    Also prefer `before-save-hook` and use `add/remove-hook` to
    manipulate hooks, like god intended.
    Don't test `buffer-read-only` any more.
    (editorconfig-mode): Don't hook into `read-only-mode-hook` any more.
    
    * ert-tests/editorconfig-tests.el (test-trim-trailing-ws): Adjust the
    test accordingly.
    
    * editorconfig-core-handle.el: Don't use file names as glob pattern
    
    Match relative file names against the glob pattern instead of
    trying to construct a glob pattern that matches the absolute
    file name (where the code failed to escape the possible
    special chars).
    
    * lisp/editorconfig-core-handle.el
    (editorconfig-core-handle-section-get-properties): Delete `dir` arg.
    (editorconfig-core-handle-get-properties-hash)
    (editorconfig-core-handle-get-properties): Adjust call accordingly.
    Use `declare` to mark it obsolete.
    (editorconfig-core-handle--fnmatch-p): Delete `dir` arg.
    
    ---------
    
    Co-authored-by: Stefan Monnier <monn...@iro.umontreal.ca>
---
 .dir-locals.el                                     |   4 +
 Makefile                                           |   2 +-
 editorconfig-core-handle.el                        |  42 ++++---
 editorconfig-fnmatch.el                            |   2 +-
 editorconfig-tools.el                              |   2 +-
 editorconfig.el                                    | 139 +++++++++------------
 ...handle.el => editorconfig-core-handle-tests.el} |  20 +--
 ...orconfig-core.el => editorconfig-core-tests.el} |   0
 ...ig-fnmatch.el => editorconfig-fnmatch-tests.el} |   0
 .../{editorconfig.el => editorconfig-tests.el}     |  28 +++--
 10 files changed, 112 insertions(+), 127 deletions(-)

diff --git a/.dir-locals.el b/.dir-locals.el
new file mode 100644
index 0000000000..cc741e0189
--- /dev/null
+++ b/.dir-locals.el
@@ -0,0 +1,4 @@
+;;; Directory Local Variables         -*- no-byte-compile: t; -*-
+;;; For more information see (info "(emacs) Directory Variables")
+
+((emacs-lisp-mode (sentence-end-double-space . t)))
diff --git a/Makefile b/Makefile
index 963f6de2ed..a4e5338c50 100644
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ ERT_TESTS = $(wildcard $(PROJECT_ROOT_DIR)/ert-tests/*.el)
 BATCHFLAGS = -batch -q --no-site-file -L $(PROJECT_ROOT_DIR)
 
 MAIN_SRC = editorconfig.el
-SRCS = $(wildcard $(PROJECT_ROOT_DIR)/*.el)
+SRCS = $(filter-out %-autoloads.el %-pkg.el, $(wildcard 
$(PROJECT_ROOT_DIR)/*.el))
 OBJS = $(SRCS:.el=.elc)
 
 .PHONY: check-unix check-dos \
diff --git a/editorconfig-core-handle.el b/editorconfig-core-handle.el
index d225e1456b..20f52a3b97 100644
--- a/editorconfig-core-handle.el
+++ b/editorconfig-core-handle.el
@@ -51,13 +51,14 @@ Slots:
   (name nil)
   (props nil))
 
-(defun editorconfig-core-handle-section-get-properties (section file dir)
+(defun editorconfig-core-handle-section-get-properties (section file)
   "Return properties alist when SECTION name match FILE.
 
-DIR should be the directory where .editorconfig file which has SECTION lives.
-IF not match, return nil."
+FILE should be a relative file name, relative to the directory where
+the `.editorconfig' file which has SECTION lives.
+If not match, return nil."
   (when (editorconfig-core-handle--fnmatch-p
-         file (editorconfig-core-handle-section-name section) dir)
+         file (editorconfig-core-handle-section-name section))
     (editorconfig-core-handle-section-props section)))
 
 (cl-defstruct editorconfig-core-handle
@@ -115,16 +116,14 @@ If HANDLE is nil return nil."
 The list returned will be ordered by the lines they appear.
 
 If HANDLE is nil return nil."
+  (declare (obsolete editorconfig-core-handle-get-properties-hash "0.8.0"))
   (when handle
-    (let ((dir (file-name-directory (editorconfig-core-handle-path handle))))
+    (let* ((dir (file-name-directory (editorconfig-core-handle-path handle)))
+           (file (file-relative-name file dir)))
       (cl-loop for section in (editorconfig-core-handle-sections handle)
-               for props = (editorconfig-core-handle-section-get-properties 
section
-                                                                            
file
-                                                                            
dir)
+               for props = (editorconfig-core-handle-section-get-properties
+                            section file)
                when props collect (copy-alist props)))))
-(make-obsolete 'editorconfig-core-handle-get-properties
-               'editorconfig-core-handle-get-properties-hash
-               "0.8.0")
 
 
 (defun editorconfig-core-handle-get-properties-hash (handle file)
@@ -132,24 +131,27 @@ If HANDLE is nil return nil."
 
 If HANDLE is nil return nil."
   (when handle
-    (let ((hash (make-hash-table))
-          (dir (file-name-directory (editorconfig-core-handle-path
-                                     handle))))
+    (let* ((hash (make-hash-table))
+           (dir (file-name-directory (editorconfig-core-handle-path handle)))
+           (file (file-relative-name file dir)))
       (dolist (section (editorconfig-core-handle-sections handle))
-        (cl-loop for (key . value) in 
(editorconfig-core-handle-section-get-properties section file dir)
+        (cl-loop for (key . value) in 
(editorconfig-core-handle-section-get-properties section file)
                  do (puthash (intern key) value hash)))
       hash)))
 
-(defun editorconfig-core-handle--fnmatch-p (name pattern dir)
+(defun editorconfig-core-handle--fnmatch-p (name pattern)
   "Return non-nil if NAME match PATTERN.
 If pattern has slash, pattern should be relative to DIR.
 
 This function is a fnmatch with a few modification for EditorConfig usage."
   (if (string-match-p "/" pattern)
-      (let ((pattern (replace-regexp-in-string "^/" "" pattern))
-            (dir (file-name-as-directory dir)))
-        (editorconfig-fnmatch-p name (concat dir pattern)))
-    (editorconfig-fnmatch-p name (concat "**/" pattern))))
+      (let ((pattern (replace-regexp-in-string "\\`/" "" pattern)))
+        (editorconfig-fnmatch-p name pattern))
+    ;; The match is not "anchored" so it can be either in the current dir or
+    ;; in a subdir.  Contrary to Zsh patterns, editorconfig's `**/foo' does
+    ;; not match `foo', so we need to split the problem into two matches.
+    (or (editorconfig-fnmatch-p name pattern)
+        (editorconfig-fnmatch-p name (concat "**/" pattern)))))
 
 (defsubst editorconfig-core-handle--string-trim (str)
   "Remove leading and trailing whitespaces from STR."
diff --git a/editorconfig-fnmatch.el b/editorconfig-fnmatch.el
index 25a344dc2e..520aeb16c2 100644
--- a/editorconfig-fnmatch.el
+++ b/editorconfig-fnmatch.el
@@ -234,7 +234,7 @@ translation is found for PATTERN."
                            (number-end (string-to-number (match-string 2
                                                                        
pattern-sub))))
                        (setq result `(,@result ,(concat "\\(?:"
-                                                        (mapconcat 
'number-to-string
+                                                        (mapconcat 
#'number-to-string
                                                                    (cl-loop 
for i from number-start to number-end
                                                                             
collect i)
                                                                    "\\|")
diff --git a/editorconfig-tools.el b/editorconfig-tools.el
index 12c4057714..31f7c17ba2 100644
--- a/editorconfig-tools.el
+++ b/editorconfig-tools.el
@@ -115,7 +115,7 @@ any of regexps in `editorconfig-exclude-regexps'."
     nil))
 ;;;###autoload
 (defalias 'describe-editorconfig-properties
-  'editorconfig-display-current-properties)
+  #'editorconfig-display-current-properties)
 
 ;;;###autoload
 (defun editorconfig-format-buffer()
diff --git a/editorconfig.el b/editorconfig.el
index e7bb3c90b1..029f99e148 100644
--- a/editorconfig.el
+++ b/editorconfig.el
@@ -5,7 +5,7 @@
 ;; Author: EditorConfig Team <editorcon...@googlegroups.com>
 ;; Version: 0.11.0
 ;; URL: https://github.com/editorconfig/editorconfig-emacs#readme
-;; Package-Requires: ((emacs "26.1") (nadvice "0.3"))
+;; Package-Requires: ((emacs "26.1"))
 ;; Keywords: convenience editorconfig
 
 ;; See
@@ -41,17 +41,12 @@
 ;;; Code:
 
 (require 'cl-lib)
-(require 'pcase)
 
-(require 'nadvice)
-
-(eval-when-compile
-  (require 'rx)
-  (require 'subr-x)
-  (defvar tex-indent-basic)
-  (defvar tex-indent-item)
-  (defvar tex-indent-arg)
-  (defvar evil-shift-width))
+(eval-when-compile (require 'subr-x))
+(defvar tex-indent-basic)
+(defvar tex-indent-item)
+(defvar tex-indent-arg)
+(defvar evil-shift-width)
 
 (require 'editorconfig-core)
 
@@ -73,8 +68,7 @@ coding styles between different editors and IDEs."
   "Path to EditorConfig executable.
 
 Used by `editorconfig--execute-editorconfig-exec'."
-  :type 'string
-  :group 'editorconfig)
+  :type 'string)
 
 (define-obsolete-variable-alias
   'edconf-get-properties-function
@@ -107,13 +101,11 @@ Possible known values are:
     use `editorconfig-core-get-properties-hash'
 * `editorconfig-get-properties-from-exec'
   * Get properties by executing EditorConfig executable"
-  :type 'function
-  :group 'editorconfig)
+  :type 'function)
 
 (defcustom editorconfig-mode-lighter " EditorConfig"
   "Command `editorconfig-mode' lighter string."
-  :type 'string
-  :group 'editorconfig)
+  :type 'string)
 
 (define-obsolete-variable-alias
   'edconf-custom-hooks
@@ -143,8 +135,7 @@ show line numbers on the left:
 
 This hook will be run even when there are no matching sections in
 \".editorconfig\", or no \".editorconfig\" file was found at all."
-  :type 'hook
-  :group 'editorconfig)
+  :type 'hook)
 
 (defcustom editorconfig-hack-properties-functions ()
   "A list of function to alter property values before applying them.
@@ -166,8 +157,7 @@ overwrite \"indent_style\" property when current 
`major-mode' is a
 
 This hook will be run even when there are no matching sections in
 \".editorconfig\", or no \".editorconfig\" file was found at all."
-  :type 'hook
-  :group 'editorconfig)
+  :type 'hook)
 (make-obsolete-variable 'editorconfig-hack-properties-functions
                         "Using `editorconfig-after-apply-functions' instead is 
recommended,
     because since 2021/08/30 (v0.9.0) this variable cannot support all 
properties:
@@ -204,7 +194,7 @@ This hook will be run even when there are no matching 
sections in
     (css-ts-mode css-indent-offset)
     (d-mode c-basic-offset)
     (elixir-ts-mode elixir-ts-indent-offset)
-    (emacs-lisp-mode lisp-indent-offset)
+    (emacs-lisp-mode . editorconfig-set-indentation-lisp-mode)
     (enh-ruby-mode enh-ruby-indent-level)
     (erlang-mode erlang-indent-level)
     (ess-mode ess-indent-offset)
@@ -253,7 +243,7 @@ This hook will be run even when there are no matching 
sections in
     (kotlin-mode kotlin-tab-width)
     (kotlin-ts-mode kotlin-ts-mode-indent-offset)
     (latex-mode . editorconfig-set-indentation-latex-mode)
-    (lisp-mode lisp-indent-offset)
+    (lisp-mode . editorconfig-set-indentation-lisp-mode)
     (livescript-mode livescript-tab-width)
     (lua-mode lua-indent-level)
     (lua-ts-mode lua-ts-indent-offset)
@@ -349,21 +339,18 @@ following forms:
 
 NOTE: Only the **buffer local** value of VARIABLE will be set."
   :type '(alist :key-type symbol :value-type sexp)
-  :risky t
-  :group 'editorconfig)
+  :risky t)
 
 (defcustom editorconfig-exclude-modes ()
   "Modes in which `editorconfig-mode-apply' will not run."
-  :type '(repeat (symbol :tag "Major Mode"))
-  :group 'editorconfig)
+  :type '(repeat (symbol :tag "Major Mode")))
 
 (defcustom editorconfig-exclude-regexps ()
   "List of regexp for buffer filenames `editorconfig-mode-apply' will not run.
 
 When variable `buffer-file-name' matches any of the regexps, then
 `editorconfig-mode-apply' will not do its work."
-  :type '(repeat string)
-  :group 'editorconfig)
+  :type '(repeat string))
 (with-eval-after-load 'recentf
   (add-to-list 'editorconfig-exclude-regexps
                (rx-to-string '(seq string-start
@@ -375,8 +362,7 @@ When variable `buffer-file-name' matches any of the 
regexps, then
 
 If set, enable that mode when `trim_trailing_whitespace` is set to true.
 Otherwise, use `delete-trailing-whitespace'."
-  :type 'symbol
-  :group 'editorconfig)
+  :type 'symbol)
 
 (defvar editorconfig-properties-hash nil
   "Hash object of EditorConfig properties that was enabled for current buffer.
@@ -400,13 +386,11 @@ number - `lisp-indent-offset' is not set only if 
indent_size is
 
 (defcustom editorconfig-override-file-local-variables t
   "Non-nil means editorconfig will override file local variable values."
-  :type 'boolean
-  :group 'editorconfig)
+  :type 'boolean)
 
 (defcustom editorconfig-override-dir-local-variables t
   "Non-nil means editorconfig will override values defined in dir-locals.el ."
-  :type 'boolean
-  :group 'editorconfig)
+  :type 'boolean)
 
 (define-error 'editorconfig-error
               "Error thrown from editorconfig lib")
@@ -459,15 +443,20 @@ Make a message by passing ARGS to `format-message'."
   (when (boundp 'LaTeX-item-indent)
     (setq-local LaTeX-item-indent (- size))))
 
-(cl-defun editorconfig--should-set (symbol &optional size)
-  "Determine if editorconfig should set SYMBOL.
-
-Optional arg SIZE is used when symbol is `lisp-indent-offset'.
-See `editorconfig-lisp-use-default-indent' for details."
+(defun editorconfig-set-indentation-lisp-mode (size)
+ "Set indent size to SIZE for Lisp mode(s)."
+ (when (cond ((null editorconfig-lisp-use-default-indent)  t)
+             ((eql t editorconfig-lisp-use-default-indent) nil)
+             ((numberp editorconfig-lisp-use-default-indent)
+              (not (eql size editorconfig-lisp-use-default-indent)))
+             (t t))
+   (setq-local lisp-indent-offset size)))
+
+(cl-defun editorconfig--should-set (symbol)
+  "Determine if editorconfig should set SYMBOL."
   (display-warning '(editorconfig editorconfig--should-set)
-                   (format "symbol: %S | size: %S"
-                           symbol
-                           size)
+                   (format "symbol: %S"
+                           symbol)
                    :debug)
   (when (and (not editorconfig-override-file-local-variables)
              (assq symbol file-local-variables-alist))
@@ -479,14 +468,6 @@ See `editorconfig-lisp-use-default-indent' for details."
     (cl-return-from editorconfig--should-set
       nil))
 
-  (when (eq symbol 'lisp-indent-offset)
-    (cl-return-from editorconfig--should-set
-      (cond ((null editorconfig-lisp-use-default-indent)  t)
-            ((eql t editorconfig-lisp-use-default-indent) nil)
-            ((numberp editorconfig-lisp-use-default-indent)
-             (not (eql size editorconfig-lisp-use-default-indent)))
-            (t t))))
-
   t)
 
 (defun editorconfig-set-indentation (style &optional size tab_width)
@@ -532,10 +513,10 @@ See `editorconfig-lisp-use-default-indent' for details."
                 ((listp fn-or-list)
                  (dolist (elem fn-or-list)
                    (cond ((and (symbolp elem)
-                               (editorconfig--should-set elem size))
+                               (editorconfig--should-set elem))
                           (set (make-local-variable elem) size))
                          ((and (consp elem)
-                               (editorconfig--should-set (car elem) size))
+                               (editorconfig--should-set (car elem)))
                           (let ((spec (cdr elem)))
                             (set (make-local-variable (car elem))
                                  (cond ((functionp spec) (funcall spec size))
@@ -615,24 +596,23 @@ to non-nil when FINAL-NEWLINE is true."
      (setq-local require-final-newline      nil)
      (setq-local mode-require-final-newline nil))))
 
+(defun editorconfig--delete-trailing-whitespace ()
+  "Call `delete-trailing-whitespace' unless the buffer is read-only."
+  (unless buffer-read-only (delete-trailing-whitespace)))
+
 (defun editorconfig-set-trailing-ws (trim-trailing-ws)
-  "Set up trimming of trailing whitespace at end of lines by TRIM-TRAILING-WS."
-  (make-local-variable 'write-file-functions) ;; just current buffer
-  (when (and (equal trim-trailing-ws "true")
-             (not buffer-read-only))
-    ;; when true we push delete-trailing-whitespace (emacs > 21)
-    ;; to write-file-functions
-    (if editorconfig-trim-whitespaces-mode
-        (funcall editorconfig-trim-whitespaces-mode 1)
-      (add-to-list 'write-file-functions 'delete-trailing-whitespace)))
-  (when (or (equal trim-trailing-ws "false")
-            buffer-read-only)
-    ;; when false we remove every delete-trailing-whitespace
-    ;; from write-file-functions
-    (when editorconfig-trim-whitespaces-mode
-      (funcall editorconfig-trim-whitespaces-mode 0))
-    (setq write-file-functions
-          (remove 'delete-trailing-whitespace write-file-functions))))
+  (pcase trim-trailing-ws
+    ("true"
+     (if editorconfig-trim-whitespaces-mode
+         (funcall editorconfig-trim-whitespaces-mode 1)
+       (add-hook 'before-save-hook
+                 #'editorconfig--delete-trailing-whitespace nil t)))
+    ("false"
+     (when editorconfig-trim-whitespaces-mode
+       (funcall editorconfig-trim-whitespaces-mode 0))
+     (remove-hook 'before-save-hook
+                  #'editorconfig--delete-trailing-whitespace t))))
+
 
 (defun editorconfig-set-line-length (length)
   "Set the max line length (`fill-column') to LENGTH."
@@ -679,7 +659,7 @@ to non-nil when FINAL-NEWLINE is true."
       (let ((key-val (split-string prop " *= *")))
         (when (> (length key-val) 1)
           (let ((key (intern (car key-val)))
-                (val (mapconcat 'identity (cdr key-val) "")))
+                (val (mapconcat #'identity (cdr key-val) "")))
             (puthash key val properties)))))))
 
 (defun editorconfig-get-properties-from-exec (filename)
@@ -870,7 +850,6 @@ To disable EditorConfig in some buffers, modify
   :lighter editorconfig-mode-lighter
   (let ((modehooks '(prog-mode-hook
                      text-mode-hook
-                     read-only-mode-hook
                      ;; Some modes call `kill-all-local-variables' in their 
init
                      ;; code, which clears some values set by editorconfig.
                      ;; For those modes, editorconfig-apply need to be called
@@ -878,16 +857,16 @@ To disable EditorConfig in some buffers, modify
                      rpm-spec-mode-hook)))
     (if editorconfig-mode
         (progn
-          (advice-add 'find-file-noselect :around 
'editorconfig--advice-find-file-noselect)
-          (advice-add 'insert-file-contents :around 
'editorconfig--advice-insert-file-contents)
+          (advice-add 'find-file-noselect :around 
#'editorconfig--advice-find-file-noselect)
+          (advice-add 'insert-file-contents :around 
#'editorconfig--advice-insert-file-contents)
           (dolist (hook modehooks)
             (add-hook hook
-                      'editorconfig-major-mode-hook
+                      #'editorconfig-major-mode-hook
                       t)))
-      (advice-remove 'find-file-noselect 
'editorconfig--advice-find-file-noselect)
-      (advice-remove 'insert-file-contents 
'editorconfig--advice-insert-file-contents)
+      (advice-remove 'find-file-noselect 
#'editorconfig--advice-find-file-noselect)
+      (advice-remove 'insert-file-contents 
#'editorconfig--advice-insert-file-contents)
       (dolist (hook modehooks)
-        (remove-hook hook 'editorconfig-major-mode-hook)))))
+        (remove-hook hook #'editorconfig-major-mode-hook)))))
 
 
 ;; (defconst editorconfig--version
@@ -927,7 +906,3 @@ version in the echo area and the messages buffer."
 
 (provide 'editorconfig)
 ;;; editorconfig.el ends here
-
-;; Local Variables:
-;; sentence-end-double-space: t
-;; End:
diff --git a/ert-tests/editorconfig-core-handle.el 
b/ert-tests/editorconfig-core-handle-tests.el
similarity index 88%
rename from ert-tests/editorconfig-core-handle.el
rename to ert-tests/editorconfig-core-handle-tests.el
index 2c28137394..0ebdab0c8c 100644
--- a/ert-tests/editorconfig-core-handle.el
+++ b/ert-tests/editorconfig-core-handle-tests.el
@@ -25,47 +25,47 @@
 
 (require 'editorconfig-core-handle)
 
-(defconst fixtures (concat (file-name-directory load-file-name) "fixtures/")
+(defconst editorconfig--fixtures (concat (file-name-directory load-file-name) 
"fixtures/")
   "Path to fixtures.")
 
 (set-variable 'vc-handled-backends nil)
 
 (ert-deftest test-editorconfig-core-handle ()
   ;; handle.ini
-  (let* ((conf (concat fixtures "handle.ini"))
+  (let* ((conf (concat editorconfig--fixtures "handle.ini"))
          (handle (editorconfig-core-handle conf)))
     (should (editorconfig-core-handle-root-p handle))
     (should (equal (editorconfig-core-handle-get-properties handle
-                                                            (concat fixtures
+                                                            (concat 
editorconfig--fixtures
                                                                     "b.js"))
                    '((("key2" . "value2")))))
     (should (equal (editorconfig-core-handle-get-properties handle
-                                                            (concat fixtures
+                                                            (concat 
editorconfig--fixtures
                                                                     "a.js"))
                    '((("key1" . "value1")) (("key2" . "value2"))))))
   ;; Test twice for checking cache
-  (let* ((conf (concat fixtures "handle.ini"))
+  (let* ((conf (concat editorconfig--fixtures "handle.ini"))
          (handle (editorconfig-core-handle conf)))
     (should (editorconfig-core-handle-root-p handle))
     (should (equal (editorconfig-core-handle-get-properties handle
-                                                            (concat fixtures
+                                                            (concat 
editorconfig--fixtures
                                                                     "b.js"))
                    '((("key2" . "value2")))))
     (should (equal (editorconfig-core-handle-get-properties handle
-                                                            (concat fixtures
+                                                            (concat 
editorconfig--fixtures
                                                                     "a.js"))
                    '((("key1" . "value1")) (("key2" . "value2"))))))
 
   ;; handle2.ini
-  (let* ((conf (concat fixtures "handle2.ini"))
+  (let* ((conf (concat editorconfig--fixtures "handle2.ini"))
          (handle (editorconfig-core-handle conf)))
     (should-not (editorconfig-core-handle-root-p handle))
     (should (equal (editorconfig-core-handle-get-properties handle
-                                                            (concat fixtures
+                                                            (concat 
editorconfig--fixtures
                                                                     "b.js"))
                    nil))
     (should (equal (editorconfig-core-handle-get-properties handle
-                                                            (concat fixtures
+                                                            (concat 
editorconfig--fixtures
                                                                     "a.js"))
                    '((("key" . "value"))))))
 
diff --git a/ert-tests/editorconfig-core.el 
b/ert-tests/editorconfig-core-tests.el
similarity index 100%
rename from ert-tests/editorconfig-core.el
rename to ert-tests/editorconfig-core-tests.el
diff --git a/ert-tests/editorconfig-fnmatch.el 
b/ert-tests/editorconfig-fnmatch-tests.el
similarity index 100%
rename from ert-tests/editorconfig-fnmatch.el
rename to ert-tests/editorconfig-fnmatch-tests.el
diff --git a/ert-tests/editorconfig.el b/ert-tests/editorconfig-tests.el
similarity index 86%
rename from ert-tests/editorconfig.el
rename to ert-tests/editorconfig-tests.el
index 4fcfe13f4e..82577f8518 100644
--- a/ert-tests/editorconfig.el
+++ b/ert-tests/editorconfig-tests.el
@@ -75,7 +75,7 @@
     (should (eq indent-tabs-mode nil)))
 
   (with-visit-file (concat editorconfig-ert-dir "4_space.py")
-    (should (eq python-indent-offset 4))
+    (should (eq (bound-and-true-p python-indent-offset) 4))
     (should (eq tab-width 8))
     (should (eq indent-tabs-mode nil)))
   (editorconfig-mode -1))
@@ -102,12 +102,16 @@
 (ert-deftest test-trim-trailing-ws nil
   (editorconfig-mode 1)
   (with-visit-file (concat editorconfig-ert-dir "trim.txt")
-    (should (memq 'delete-trailing-whitespace
-                  write-file-functions)))
-  (with-visit-file (concat editorconfig-ert-dir "trim.txt")
-    (read-only-mode 1)
-    (should (not (memq 'delete-trailing-whitespace
-                       write-file-functions))))
+    (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
+  ;; buffer/file.
+  ;;(with-visit-file (concat editorconfig-ert-dir "trim.txt")
+  ;;  (read-only-mode 1)
+  ;;  (should (not (memq #'editorconfig--delete-trailing-whitespace
+  ;;                     before-save-hook))))
   (editorconfig-mode -1))
 
 (ert-deftest test-charset nil
@@ -127,21 +131,21 @@
   (editorconfig-mode 1)
   (with-visit-file (concat editorconfig-local-variables-ert-dir 
"file_locals.rb")
     (should (eq tab-width 9))
-    (should (eq ruby-indent-level 7)))
+    (should (eq (bound-and-true-p ruby-indent-level) 7)))
 
   (with-visit-file (concat editorconfig-local-variables-ert-dir "dir_locals.c")
     (should (eq tab-width 9))
-    (should (eq c-basic-offset 7)))
+    (should (eq (bound-and-true-p c-basic-offset) 7)))
 
   (let ((editorconfig-override-file-local-variables nil))
     (with-visit-file (concat editorconfig-local-variables-ert-dir 
"file_locals.rb")
       (should (eq tab-width 5))
-      (should (eq ruby-indent-level 3))))
+      (should (eq (bound-and-true-p ruby-indent-level) 3))))
 
   (let ((editorconfig-override-dir-local-variables nil))
     (with-visit-file (concat editorconfig-local-variables-ert-dir 
"dir_locals.c")
       (should (eq tab-width 5))
-      (should (eq c-basic-offset 3))))
+      (should (eq (bound-and-true-p c-basic-offset) 3))))
   (editorconfig-mode -1))
 
 (ert-deftest test-file-type-emacs nil
@@ -168,7 +172,7 @@
             (lambda (props)
               (puthash 'indent_size "5" props)))
   (with-visit-file (concat editorconfig-ert-dir "4_space.py")
-    (should (eq python-indent-offset 5)))
+    (should (eq (bound-and-true-p python-indent-offset) 5)))
   (setq editorconfig-hack-properties-functions nil)
   (editorconfig-mode -1))
 

Reply via email to