3 changes: 2 additions & 1 deletion .github/workflows/build.yaml
Expand Up @@ -21,7 +21,8 @@ jobs:
- "24.5"
- "25.3"
- "26.3"
- "27.1"
- "27.2"
- "28.2"
experimental: [false]
include:
- emacs_version: snapshot
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Expand Up @@ -20,6 +20,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Security


## [0.9.0] - 2022-10-23

### Changed

- Use new implementation by default ([#263])
- Set `(setq editorconfig--legacy-version t)` to use previous one


## [0.8.2] - 2021-08-13

### Added
Expand Down Expand Up @@ -226,7 +234,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
*Undocumented*


[Unreleased]: https://github.com/editorconfig/editorconfig-emacs/compare/v0.8.2...HEAD
[Unreleased]: https://github.com/editorconfig/editorconfig-emacs/compare/v0.9.0...HEAD
[0.9.0]: https://github.com/editorconfig/editorconfig-emacs/compare/v0.8.2...v0.9.0
[0.8.2]: https://github.com/editorconfig/editorconfig-emacs/compare/v0.8.1...v0.8.2
[0.8.1]: https://github.com/editorconfig/editorconfig-emacs/compare/v0.8.0...v0.8.1
[0.8.0]: https://github.com/editorconfig/editorconfig-emacs/compare/v0.7.14...v0.8.0
Expand All @@ -253,6 +262,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[0.3]: https://github.com/editorconfig/editorconfig-emacs/compare/v0.2...v0.3
[0.2]: https://github.com/editorconfig/editorconfig-emacs/compare/v0.1...v0.2
[0.1]: https://github.com/editorconfig/editorconfig-emacs/releases/tag/v0.1
[#263]: https://github.com/editorconfig/editorconfig-emacs/issues/263
[#260]: https://github.com/editorconfig/editorconfig-emacs/issues/260
[#258]: https://github.com/editorconfig/editorconfig-emacs/issues/258
[#255]: https://github.com/editorconfig/editorconfig-emacs/issues/255
Expand Down
31 changes: 11 additions & 20 deletions README.md
Expand Up @@ -136,26 +136,6 @@ only blocks of `web-mode` by adding following to your init.el:
```


### `editorconfig-hack-properties-functions`

A list of functions to alter property values before applying them.

These functions will be run after loading \".editorconfig\" files and before
applying them to current buffer, so that you can alter some properties from
\".editorconfig\" before they take effect.

For example, Makefile files always use tab characters for indentation: you can
overwrite \"indent_style\" property when current `major-mode` is
`makefile-mode`:

``` emacs-lisp
(add-hook 'editorconfig-hack-properties-functions
'(lambda (props)
(when (derived-mode-p 'makefile-mode)
(puthash 'indent_style "tab" props))))
```


## Troubleshooting

Expand Down Expand Up @@ -197,6 +177,16 @@ Typically it will occur when the major-mode is not defined using
Please feel free to submit issues if you find such modes!


### `editorconfig-format-buffer` does not work well with lsp-mode

By default, [lsp-mode][] configures indent-region-function so that Emacs uses
language servers' `textDocument/rangeFormatting` request to format text in
buffers.
So EditorConfig settings are ignored unless language servers
themselves support loading configs from `.editorconfig`.

To avoid this behavior ad-hocly, set `lsp-enable-indentation` to nil.



## Submitting Bugs and Feature Requests
Expand Down Expand Up @@ -246,3 +236,4 @@ with this program. If not, see <https://www.gnu.org/licenses/>.
[EditorConfig C Core]: https://github.com/editorconfig/editorconfig-core-c
[properties]: https://editorconfig.org/#supported-properties
[CMake]: https://cmake.org
[lsp-mode]: https://github.com/emacs-lsp/lsp-mode
4 changes: 2 additions & 2 deletions editorconfig-core-handle.el
Expand Up @@ -200,8 +200,8 @@ If CONF is not found return nil."
)
(while (not (eq (point) point-max))
(setq line
(buffer-substring-no-properties (point-at-bol)
(point-at-eol)))
(buffer-substring-no-properties (line-beginning-position)
(line-end-position)))
(setq line
(replace-regexp-in-string "\\(^\\| \\)\\(#\\|;\\).*$"
""
Expand Down
33 changes: 19 additions & 14 deletions editorconfig.el
Expand Up @@ -3,7 +3,7 @@
;; Copyright (C) 2011-2021 EditorConfig Team

;; Author: EditorConfig Team <editorconfig@googlegroups.com>
;; Version: 0.8.2
;; Version: 0.9.0
;; URL: https://github.com/editorconfig/editorconfig-emacs#readme
;; Package-Requires: ((cl-lib "0.5") (nadvice "0.3") (emacs "24"))

Expand Down Expand Up @@ -47,9 +47,7 @@
(defvar tex-indent-arg)
(defvar evil-shift-width))

(declare-function editorconfig-core-get-properties-hash
"editorconfig-core"
(&optional file confname confversion))
(require 'editorconfig-core)

(defgroup editorconfig nil
"EditorConfig Emacs Plugin.
Expand Down Expand Up @@ -95,13 +93,13 @@ your init.el:
Possible known values are:
* `editorconfig-core-get-properties-hash' (default)
* `editorconfig-core-get-properties-hash\\=' (default)
* Always use built-in Emacs-Lisp implementation to get properties
* `editorconfig-get-properties'
* Use `editorconfig-get-properties-from-exec' when
* Use `editorconfig-get-properties-from-exec\\=' when
`editorconfig-exec-path' executable is found, otherwise
use `editorconfig-core-get-properties-hash'
* `editorconfig-get-properties-from-exec'
use `editorconfig-core-get-properties-hash\\='
* `editorconfig-get-properties-from-exec\\='
* Get properties by executing EditorConfig executable"
:type 'function
:group 'editorconfig)
Expand Down Expand Up @@ -148,6 +146,8 @@ This hook will be run even when there are no matching sections in
These functions will be run after loading \".editorconfig\" files and before
applying them to current buffer, so that you can alter some properties from
\".editorconfig\" before they take effect.
\(Since 2021/08/30 (v0.9.0): Buffer coding-systems are set before running
this functions, so this variable cannot be used to change coding-systems.)
For example, Makefiles always use tab characters for indentation: you can
overwrite \"indent_style\" property when current `major-mode' is a
Expand All @@ -162,6 +162,11 @@ 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)
(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:
charset values will be referenced before running this hook."
"v0.9.0")

(define-obsolete-variable-alias
'edconf-indentation-alist
Expand Down Expand Up @@ -842,11 +847,11 @@ F is that function, and FILENAME and ARGS are arguments passed to F."
(format "Error while setting variables from EditorConfig: %S" err))))
ret))

(defvar editorconfig--enable-20210221-testing nil
"Enable testing version of `editorconfig-mode'.
(defvar editorconfig--legacy-version nil
"Use legacy version of editorconfig-mode.
Currently this mode is not well tested yet and can cause unexpected behaviors
like killing Emacs process or not able to visit files at all.")
As of 2021/08/30, `editorconfig-mode' uses totally new implementation by
default. This flag disables this and go back to previous version.")

;;;###autoload
(define-minor-mode editorconfig-mode
Expand All @@ -856,7 +861,7 @@ To disable EditorConfig in some buffers, modify
`editorconfig-exclude-modes' or `editorconfig-exclude-regexps'."
:global t
:lighter editorconfig-mode-lighter
(if editorconfig--enable-20210221-testing
(if (not editorconfig--legacy-version)
(let ((modehooks '(prog-mode-hook
text-mode-hook
read-only-mode-hook
Expand All @@ -880,7 +885,7 @@ To disable EditorConfig in some buffers, modify
(remove-hook hook
'editorconfig-major-mode-hook))))

;; editorconfig--enable-20210221-testing is disabled
;; editorconfig--legacy-version is enabled
;; See https://github.com/editorconfig/editorconfig-emacs/issues/141 for why
;; not `after-change-major-mode-hook'
(dolist (hook '(change-major-mode-after-body-hook
Expand Down
130 changes: 0 additions & 130 deletions ert-tests/editorconfig-2.el

This file was deleted.

2 changes: 2 additions & 0 deletions ert-tests/editorconfig-core-handle.el
Expand Up @@ -3,6 +3,8 @@
(defconst fixtures (concat (file-name-directory load-file-name)
"fixtures/"))

(set-variable 'vc-handled-backends nil)

(ert-deftest test-editorconfig-core-handle ()
;; handle.ini
(let* ((conf (concat fixtures
Expand Down
1 change: 1 addition & 0 deletions ert-tests/editorconfig-core.el
@@ -1,5 +1,6 @@
(require 'editorconfig-core)

(set-variable 'vc-handled-backends nil)

(ert-deftest test-editorconfig-core--get-handles ()
(let* ((fixtures (concat default-directory
Expand Down
1 change: 1 addition & 0 deletions ert-tests/editorconfig-fnmatch.el
@@ -1,5 +1,6 @@
(require 'editorconfig-fnmatch)

(set-variable 'vc-handled-backends nil)

(ert-deftest test-editorconfig-fnmatch-p ()
(let ((cases-t
Expand Down
2 changes: 2 additions & 0 deletions ert-tests/editorconfig.el
@@ -1,5 +1,7 @@
(require 'editorconfig)

(set-variable 'vc-handled-backends nil)

(defun display-warning (type message &optional level buffer-name)
"When testing overwrite this function to throw error when called."
(unless (eq level :debug)
Expand Down
2 changes: 2 additions & 0 deletions ert-tests/metadata.el
@@ -1,5 +1,7 @@
(require 'package)

(set-variable 'vc-handled-backends nil)

(defvar metadata-el-files nil)

(ert-deftest test-metadata ()
Expand Down