• Stars
    star
    724
  • Rank 62,593 (Top 2 %)
  • Language
    Emacs Lisp
  • License
    GNU General Publi...
  • Created about 13 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

EditorConfig plugin for Emacs

build MELPA MELPA Stable NonGNU ELPA

EditorConfig Emacs Plugin

This is an EditorConfig plugin for Emacs.

Getting Started

package.el

This package is available from MELPA, MELPA Stable and NonGNU ELPA. Install from these repositories and enable global minor-mode editorconfig-mode:

(editorconfig-mode 1)

Normally, enabling editorconfig-mode should be enough for this plugin to work: all other configurations are optional. This mode sets up hooks so that EditorConfig properties will be loaded and applied to the new buffers automatically when visiting files.

use-package

If you use use-package, add the following to your init.el file:

(use-package editorconfig
  :ensure t
  :config
  (editorconfig-mode 1))

Manual installation

Copy all .el files in this repository to ~/.emacs.d/lisp and add the following:

(add-to-list 'load-path "~/.emacs.d/lisp")
(require 'editorconfig)
(editorconfig-mode 1)

Supported properties

Current Emacs plugin coverage for EditorConfig's properties:

  • indent_style
  • indent_size
  • tab_width
  • end_of_line
  • charset
  • trim_trailing_whitespace
  • insert_final_newline = true is supported
  • insert_final_newline = false is not enforced (as in trailing newlines actually being removed automagically), 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) (See below)
  • file_type_emacs (Experimental) (See below)
  • root (only used by EditorConfig core)

Not yet covered properties marked with over-strike – pull requests implementing missing features warmly welcomed! Typically, you will want to tie these to native functionality, or the configuration of existing packages handling the feature.

As several packages have their own handling of, say, indentation, we might not yet cover some mode you use, but we try to add the ones that show up on our radar.

File Type (file_type_ext, file_type_emacs)

File-type feature is currently disabled, because this package is now undergoing big internal refactoring. For those who want this functionality, please consider using editorconfig-custom-majormode.

Customize

editorconfig-emacs provides some customize variables.

Here are some of these variables: for the full list of available variables, type M-x customize-group [RET] editorconfig [RET].

editorconfig-trim-whitespaces-mode

Buffer local minor-mode to use to trim trailing whitespaces.

If set, editorconfig will enable/disable this mode in accord with trim_trailing_whitespace property in .editorconfig. Otherwise, use Emacs built-in delete-trailing-whitespace function.

One possible value is ws-butler-mode, with which only lines touched get trimmed. To use it, add following to your init.el:

(setq editorconfig-trim-whitespaces-mode
      'ws-butler-mode)

editorconfig-after-apply-functions

(Formerly editorconfig-custom-hooks)

A list of functions which will be called after loading common EditorConfig settings, when you can set some custom variables.

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

(add-hook 'editorconfig-after-apply-functions
  (lambda (props) (setq web-mode-block-padding 0)))

Troubleshooting

Enabling editorconfig-mode should be enough for normal cases.

When EditorConfig properties are not effective for unknown reason, we recommend first trying M-x editorconfig-display-current-properties.

This command will open a new buffer and display the EditorConfig properties loaded for current buffer. You can check if EditorConfig properties were not read for buffers at all, or they were loaded but did not take effect for some other reasons.

Indentation for new major-modes

Because most Emacs major-modes have their own indentation settings, this plugin requires explicit support for each major-mode for indent_size property.

By default this plugin ships with settings for many major-modes, but, sorry to say, it cannot be perfect. Especially it is difficult to support brand-new major-modes. Please feel free to submit issue or pull-request for such major-mode!

Supported major-modes and their indentation configs are defined in the variable editorconfig-indentation-alist.

Not work at all for FOO-mode!

Most cases properties are loaded just after visiting files when editorconfig-mode is enabled. But it is known that there are major-modes that this mechanism does not work for and require explicit call of editorconfig-apply.

Typically it will occur when the major-mode is not defined using define-derived-mode (rpm-spec-mode is an example for this). 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

Bugs, feature requests, and other issues should be submitted to the issue tracker: https://github.com/editorconfig/editorconfig-emacs/issues

Development

To run the test locally, you will need the following tools:

If you are on Linux or macOS:

$ make check-unix

On Windows:

$ make check-dos

To start a new Emacs process with current *.el and without loading user init file, run:

$ make sandbox

License

EditorConfig Emacs Plugin is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 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/.

More Repositories

1

editorconfig-vim

EditorConfig plugin for Vim
Vim Script
3,101
star
2

editorconfig

EditorConfig universal issue tracker and wiki
3,082
star
3

editorconfig-visualstudio

EditorConfig Visual Studio Addin
C#
352
star
4

editorconfig-core-c

EditorConfig core library written in C (for use by plugins supporting EditorConfig parsing)
C
292
star
5

editorconfig-jetbrains

A JetBrains IDE plugin supporting the EditorConfig standard
Java
292
star
6

editorconfig-core-js

EditorConfig Core library and command line utility written in JavaScript
TypeScript
266
star
7

editorconfig.github.com

Configuration file format for defining coding styles in shared projects
HTML
265
star
8

editorconfig-notepad-plus-plus

EditorConfig plugin for Notepad++
C++
186
star
9

editorconfig-core-go

EditorConfig Core written in Go
Go
129
star
10

editorconfig-core-py

Clone of EditorConfig core written in Python
Python
90
star
11

specification

Specification of EditorConfig file format
Python
83
star
12

editorconfig-core-net

EditorConfig Core library and command line utility written in C# for .NET/Mono http://editorconfig.org
C#
70
star
13

editorconfig-core-java

Clone of EditorConfig core written in Java
Java
61
star
14

editorconfig-gedit

EditorConfig plugin for Gedit
Python
54
star
15

editorconfig-geany

EditorConfig plugin for Geany
C
45
star
16

editorconfig-qtcreator

EditorConfig Plugin for QtCreator
C++
40
star
17

editorconfig-core-ruby

Clone of EditorConfig core written in Ruby
Ruby
27
star
18

editorconfig-core-test

Testings for EditorConfig Core
CMake
25
star
19

editorconfig-defaults

24
star
20

editorconfig-jedit

EditorConfig plugin for jEdit
Java
16
star
21

editorconfig-plugin-tests

Tests for EditorConfig plugins
Python
16
star
22

editorconfig-core-lua

EditorConfig Core bindings for Lua
CMake
15
star
23

live-demo

Work in progress: EditorConfig in-browser live demo
JavaScript
13
star
24

editorconfig-textadept

EditorConfig plugin for Textadept
Lua
11
star
25

utilities

Utilities for EditorConfig development
Ruby
11
star
26

editorconfig-codeblocks

EditorConfig plugin for Code::Blocks
C++
11
star
27

editorconfig-core-qt

EditorConfig core written for Qt
C++
10
star
28

docs.editorconfig.org

EditorConfig C Core library documentation
JavaScript
10
star
29

editorconfig-core-java-binding

EditorConfig Core Java Binding
Java
8
star
30

editorconfig-vote

The issue tracker is for voting purpose only. Only @editorconfig/board-member members can comment.
4
star
31

javadocs.editorconfig.org

EditorConfig library Java API documentation
CSS
3
star