LoginSignup
5
2

More than 5 years have passed since last update.

web-mode.el のタグを自動で閉じる機能が動かない場合

Posted at

Emacs拡張のweb-mode.elは、ERBのタグ等が混在しているHTMLファイルの編集において便利になるように色々な機能が盛り込まれている。
そのひとつがタグを自動で閉じる機能である。
たとえば

<div>hogehoge

と入力した後に、 </ とだけ入力すると

<div>hogehoge</div>

といった具合に閉じタグが自動で入力される。

この機能が、一部の環境のEmacsでは動くのに、別の環境のEmacsでは全く同じ設定をしているはずなのに動かない、という困った状況になった。

原因

調べてみたところ、一部の環境のEmacsでのみタグを自動で閉じる機能が動作しないのは、そのようになるように作られているためであることがわかった。

if you work in a terminal (not in window mode), it is normal that the autoclosing does not work.
if you wan't to force it, add (setq web-mode-tag-auto-close-style 1) in your .emacs
https://github.com/fxbois/web-mode/issues/358

開発者曰く、ターミナルで動作している場合にはデフォルトで無効になるように作ってある、ということらしい。

対策

下記の設定を.emacsに追加すればよい。

(setq web-mode-auto-close-style 1)
(setq web-mode-tag-auto-close-style t)

さらに、ERBのタグ <% %> を自動で閉じてくれる機能(auto pairing)もターミナル上のEmacsではデフォルトで無効になっている。これを有効にするには次の設定を .emacs に追加すればよい。

(setq web-mode-enable-auto-pairing t)
5
2
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
5
2