LoginSignup
7
7

More than 5 years have passed since last update.

editorconfig on emacs

Last updated at Posted at 2016-05-27

こんにちは。 editorconfig 使っていますか? とっても便利です!

が、何回かつまづいたところがあるので、ここにまとめておきます。私の環境での話なので、もしかしたら再現性ないかもです。その折はすみません。

.editorconfig はこう書く

[*.php]
indent_style = tab
indent_size = 2
tab_width = 2

indent_sizetab_width も整数で設定します。公式 ( http://editorconfig.org/#file-format-details ) には

indent_size: a whole number defining the number of columns used for each indentation level and the width of soft tabs (when supported). When set to tab, the value of tab_width (if specified) will be used.
tab_width: a whole number defining the number of columns used to represent a tab character. This defaults to the value of indent_size and doesn't usually need to be specified.

と書いてあるので

[*.php]
indent_style = tab
indent_size = tab

で良いと読めますが、これではだめでした。また、

[*.php]
indent_style = tab
indent_size = 4
tab_width = 2

もだめでした。「だめ」とは、タブとスペース混合でインデントされてしまう、の意味です。

php-mode.eltab-width が設定されているので、これと衝突しているのかもしれません。あるいは、 whitespace-mode を使ってタブを »- と表示しているので、これと衝突しているのかもしれません。正確な原因はまだわかりません。

editorconfig-core は elisp 版がおすすめ

editorconfig-core には外部プログラム版と elisp 版があります。 elisp 版がおすすめです。外部プログラム版は tramp 先で使えないという制約 ( http://stackoverflow.com/questions/35957195/editorconfig-does-not-work-over-tramp-in-emacs) がありますが、 elisp 版にはありません。

elisp 版については、 http://qiita.com/10sr/items/5e5d9519874ea3602d96#comment-d15a9b728c842dfb4cf8 に詳しく載っています。現在、elisp 版 editorconfig-core は MELPA では editorconfig の依存として追加されています。このため、 elisp 版 editorconfig-core を明示的にインストールする必要はありません。

init.el 等に

(setq editorconfig-get-properties-function
      'editorconfig-core-get-properties-hash)

と書けば、外部プログラム版ではなく elisp 版の editorconfig-core が使われるようになります。

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7