Showing with 323 additions and 101 deletions.
  1. +2 −2 .editorconfig
  2. +5 −4 Makefile
  3. +65 −14 README.md
  4. +10 −10 bin/editorconfig-el
  5. +1 −1 core-test
  6. +56 −29 doc/editorconfig.texi
  7. +2 −0 doc/header.txt
  8. +2 −1 editorconfig-conf-mode.el
  9. +1 −1 editorconfig-core.el
  10. +121 −26 editorconfig.el
  11. +6 −9 ert-tests/editorconfig-core-handle.el
  12. +42 −4 ert-tests/editorconfig.el
  13. +10 −0 ert-tests/test_files_secondary/.editorconfig
4 changes: 2 additions & 2 deletions .editorconfig
Expand Up @@ -26,5 +26,5 @@ tab_width = 4
indent_style = space
indent_size = 2

[.editorconfig]
file_type_emacs = editorconfig-conf
[ert-tests/**/*.ini]
file_type_ext = editorconfig
9 changes: 5 additions & 4 deletions Makefile
@@ -1,9 +1,10 @@
# -*- Makefile -*-

TEXI_TOP := EditorConfig Emacs Plugin
TEXI_CHAPTER := EditorConfig Emacs Plugin

EMACS = emacs
PANDOC = pandoc
AWK = awk

PROJECT_ROOT_DIR = $(CURDIR)
ERT_TESTS = $(wildcard $(PROJECT_ROOT_DIR)/ert-tests/*.el)
Expand Down Expand Up @@ -33,9 +34,9 @@ doc: doc/editorconfig.texi
doc/editorconfig.texi: README.md doc/header.txt
mkdir -p doc
tail -n +4 $< | $(PANDOC) -s -f markdown -t texinfo -o $@.body
cat doc/header.txt $@.body >$@
sed -i.bak -e 's/^@top .*/@top ${TEXI_TOP}/' $@
rm -f $@.body $@.bak
$(AWK) 'f{print} /^@chapter $(TEXI_CHAPTER)/{f=1;print}' $@.body >$@.body2
cat doc/header.txt $@.body2 >$@
rm -f $@.body $@.body2

test: test-ert test-core test-metadata $(OBJS)
$(EMACS) $(BATCHFLAGS) -l editorconfig.el
Expand Down
79 changes: 65 additions & 14 deletions README.md
Expand Up @@ -25,7 +25,7 @@ and add the following to your `~/.emacs` file:
```

Alternatively, you can find the package available on
[MELPA](http://melpa.org/#/editorconfig) and [MELPA Stable](http://stable.melpa.org/#/editorconfig)
[MELPA](https://melpa.org/#/editorconfig) and [MELPA Stable](https://stable.melpa.org/#/editorconfig)
([The Marmalade package](http://marmalade-repo.org/packages/editorconfig) is deprecated).

Or if you use [**use-package**](https://www.emacswiki.org/emacs/UsePackage):
Expand Down Expand Up @@ -53,6 +53,7 @@ Current Emacs plugin coverage for EditorConfig's [properties][]:
we just buffer-locally override any preferences that would auto-add them
to files `.editorconfig` marks as trailing-newline-free
* `max_line_length`
* `file_type_ext` (Experimental)
* `file_type_emacs` (Experimental)
* `root` (only used by EditorConfig core)

Expand All @@ -66,35 +67,67 @@ we might not yet cover some mode you use, but we try to add the
ones that show up on our radar. Similarly, we don't yet hook
in to all different packages for whitespace trimming to inform
them about editorconfig settings, but aim for better coverage
of things like [ws-trim](ftp://ftp.lysator.liu.se/pub/emacs/ws-trim.el).
of things like
[ws-trim](ftp://ftp.lysator.liu.se/pub/emacs/ws-trim.el).

This plugin also has an experimental support for `file_type_emacs`,
which specifies "file types" for files.
As for Emacs, it means `major-mode` can be specified: for example,
when `file_type_emacs` is set to `markdown` for `a.txt`,
`markdown-mode` will be enabled when opening `a.txt`.
This property is experimental and its meaning might change in
the future updates.

### File Type

This plugin has experimental supports for `file_type_ext` and
`file_type_emacs`, which specify "file types" for files.
As for Emacs, it means `major-mode` can be set.

**file_type_ext** When it is set to `md` for `a.txt`, for example,
`major-mode` will be decided as if the file name would be `a.txt.md`
(and thus `markdown-mode` is likely to be used).

**file_type_emacs** When it is set to `markdown` for `a.txt`,
`markdown-mode` will be enabled when opening `a.txt`.

These property are experimental and their meanings might change in the
future updates. When both are specified, `file_type_ext` takes precedence.


## Customize

### `editorconfig-custom-hooks`
### `editorconfig-after-apply-functions`

(Formerly `editorconfig-custom-hooks`)

A list of custom hooks after loading common EditorConfig settings, where you can
A list of functions after loading common EditorConfig settings, where you can
set some custom variables or overwrite existing properties.

For example, `web-mode` has several variables for indentation offset size and
EditorConfig sets them at once by `indent_size`. You may want to stop indenting
only blocks of `web-mode`: it can be achieved by adding following to your init.el:

```emacs-lisp
(add-hook 'editorconfig-custom-hooks
(add-hook 'editorconfig-after-apply-functions
(lambda (hash) (setq web-mode-block-padding 0)))
```

You can also define your own custom properties and enable them here.

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

A list of function 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, Makefiles always use tab characters for indentation: you can
overwrite \"indent_style\" property when current `major-mode` is a
`makefile-mode` with following code:

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

### `editorconfig-indentation-alist`

Alist of indentation setting methods by modes.
Expand Down Expand Up @@ -143,6 +176,24 @@ Possible known values are:
* `editorconfig-core-get-properties-hash`
* Always use built-in Emacs-Lisp implementation to get properties


### `editorconfig-trim-whitespaces-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'.

One possible value is
[`ws-butler-mode`](https://github.com/lewang/ws-butler), with which
only lines touched get trimmed. To use it, add following to yo
init.el:

``` emacs-lisp
(setq editorconfig-trim-whitespaces-mode
'ws-butler-mode)
```

## Testing

Make and [CMake](https://cmake.org) must be installed to run the tests.
Expand Down Expand Up @@ -171,6 +222,6 @@ General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program. If not, see <https://www.gnu.org/licenses/>.

[EditorConfig]: http://editorconfig.org
[EditorConfig]: https://editorconfig.org
[EditorConfig C Core]: https://github.com/editorconfig/editorconfig-core-c
[properties]: http://editorconfig.org/#supported-properties
[properties]: https://editorconfig.org/#supported-properties
20 changes: 10 additions & 10 deletions bin/editorconfig-el
Expand Up @@ -80,8 +80,8 @@ with required output."
(message editorconfig-bin-help-message)
(kill-emacs 0))
((-v --version)
(message "EditorConfig-Core-EmacsLisp Version %s"
editorconfig-core-version)
(princ (format "EditorConfig-Core-EmacsLisp Version %s\n"
editorconfig-core-version))
(kill-emacs 0))

(otherwise
Expand All @@ -105,19 +105,19 @@ with required output."
(dolist (p (editorconfig-core-get-properties (caar parsed)
(nth 1 parsed)
(nth 2 parsed)))
(message "%s=%s"
(car p)
(cdr p))))
(princ (format "%s=%s\n"
(car p)
(cdr p)))))
(otherwise
(dolist (file (car parsed))
(message "[%s]"
file)
(princ (format "[%s]\n"
file))
(dolist (p (editorconfig-core-get-properties file
(nth 1 parsed)
(nth 2 parsed)))
(message "%s=%s"
(car p)
(cdr p)))))))
(princ (format "%s=%s\n"
(car p)
(cdr p))))))))
0)

;; car of command-line-args-left is "--"
Expand Down
85 changes: 56 additions & 29 deletions doc/editorconfig.texi
Expand Up @@ -2,23 +2,11 @@
@direntry
* EditorConfig: (editorconfig). EditorConfig Emacs Plugin.
@end direntry
\input texinfo
@documentencoding UTF-8

@ifnottex
@paragraphindent 0
@end ifnottex
@node Top
@top EditorConfig Emacs Plugin

@menu
* EditorConfig Emacs Plugin::
@end menu

@node EditorConfig Emacs Plugin
@chapter EditorConfig Emacs Plugin
@anchor{#editorconfig-emacs-plugin}
This is an @uref{http://editorconfig.org,EditorConfig} plugin for
This is an @uref{https://editorconfig.org,EditorConfig} plugin for
@uref{https://www.gnu.org/software/emacs/,Emacs}.
@menu
* Installation::
Expand Down Expand Up @@ -51,8 +39,8 @@ file:
@end verbatim

Alternatively, you can find the package available on
@uref{http://melpa.org/#/editorconfig,MELPA} and
@uref{http://stable.melpa.org/#/editorconfig,MELPA Stable}
@uref{https://melpa.org/#/editorconfig,MELPA} and
@uref{https://stable.melpa.org/#/editorconfig,MELPA Stable}
(@uref{http://marmalade-repo.org/packages/editorconfig,The Marmalade
package} is deprecated).

Expand All @@ -70,7 +58,7 @@ Or if you use
@section Supported properties
@anchor{#supported-properties}
Current Emacs plugin coverage for EditorConfig's
@uref{http://editorconfig.org/#supported-properties,properties}:
@uref{https://editorconfig.org/#supported-properties,properties}:

@itemize
@item
Expand All @@ -96,6 +84,8 @@ trailing-newline-free
@item
@code{max_line_length}
@item
@code{file_type_ext} (Experimental)
@item
@code{file_type_emacs} (Experimental)
@item
@code{root} (only used by EditorConfig core)
Expand All @@ -112,29 +102,46 @@ on our radar. Similarly, we don't yet hook in to all different packages
for whitespace trimming to inform them about editorconfig settings, but
aim for better coverage of things like
@uref{ftp://ftp.lysator.liu.se/pub/emacs/ws-trim.el,ws-trim}.
@menu
* File Type::
@end menu

@node File Type
@subsection File Type
@anchor{#file-type}
This plugin has experimental supports for @code{file_type_ext} and
@code{file_type_emacs}, which specify ``file types'' for files. As for
Emacs, it means @code{major-mode} can be set.

@strong{file_type_ext} When it is set to @code{md} for @code{a.txt}, for
example, @code{major-mode} will be decided as if the file name would be
@code{a.txt.md} (and thus @code{markdown-mode} is likely to be used).

This plugin also has an experimental support for @code{file_type_emacs},
which specifies ``file types'' for files. As for Emacs, it means
@code{major-mode} can be specified: for example, when
@code{file_type_emacs} is set to @code{markdown} for @code{a.txt},
@code{markdown-mode} will be enabled when opening @code{a.txt}. This
property is experimental and its meaning might change in the future
updates.
@strong{file_type_emacs} When it is set to @code{markdown} for
@code{a.txt}, @code{markdown-mode} will be enabled when opening
@code{a.txt}.

These property are experimental and their meanings might change in the
future updates. When both are specified, @code{file_type_ext} takes
precedence.

@node Customize
@section Customize
@anchor{#customize}
@menu
* editorconfig-custom-hooks::
* editorconfig-after-apply-functions::
* editorconfig-hack-properties-functions::
* editorconfig-indentation-alist::
* editorconfig-exec-path::
* editorconfig-get-properties-function::
@end menu

@node editorconfig-custom-hooks
@subsection @code{editorconfig-custom-hooks}
@anchor{#editorconfig-custom-hooks}
A list of custom hooks after loading common EditorConfig settings, where
@node editorconfig-after-apply-functions
@subsection @code{editorconfig-after-apply-functions}
@anchor{#editorconfig-after-apply-functions}
(Formerly @code{editorconfig-custom-hooks})

A list of functions after loading common EditorConfig settings, where
you can set some custom variables or overwrite existing properties.

For example, @code{web-mode} has several variables for indentation
Expand All @@ -143,12 +150,32 @@ You may want to stop indenting only blocks of @code{web-mode}: it can be
achieved by adding following to your init.el:

@verbatim
(add-hook 'editorconfig-custom-hooks
(add-hook 'editorconfig-after-apply-functions
(lambda (hash) (setq web-mode-block-padding 0)))
@end verbatim

You can also define your own custom properties and enable them here.

@node editorconfig-hack-properties-functions
@subsection @code{editorconfig-hack-properties-functions}
@anchor{#editorconfig-hack-properties-functions}
A list of function 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, Makefiles always use tab characters for indentation: you
can overwrite "indent_style" property when current @code{major-mode} is
a @code{makefile-mode} with following code:

@verbatim
(add-hook 'editorconfig-hack-properties-functions
'(lambda (props)
(when (derived-mode-p 'makefile-mode)
(puthash 'indent_style "tab" props))))
@end verbatim

@node editorconfig-indentation-alist
@subsection @code{editorconfig-indentation-alist}
@anchor{#editorconfig-indentation-alist}
Expand Down
2 changes: 2 additions & 0 deletions doc/header.txt
Expand Up @@ -2,3 +2,5 @@
@direntry
* EditorConfig: (editorconfig). EditorConfig Emacs Plugin.
@end direntry

@node Top
3 changes: 2 additions & 1 deletion editorconfig-conf-mode.el
Expand Up @@ -46,6 +46,7 @@
'("charset"
"end_of_line"
"file_type_emacs"
"file_type_ext"
"indent_size"
"indent_style"
"insert_final_newline"
Expand Down Expand Up @@ -88,7 +89,7 @@

;;;###autoload
(add-to-list 'auto-mode-alist
'("/\\.editorconfig\\'" . editorconfig-conf-mode))
'("\\.editorconfig\\'" . editorconfig-conf-mode))

(provide 'editorconfig-conf-mode)

Expand Down
2 changes: 1 addition & 1 deletion editorconfig-core.el
Expand Up @@ -71,7 +71,7 @@


(defconst editorconfig-core-version
"0.7.13"
"0.7.14"
"EditorConfig core version.")

(defun editorconfig-core--remove-duplicate (alist)
Expand Down