LoginSignup
10
8

More than 5 years have passed since last update.

show-trailing-whitespaceは便利だが、見栄えが悪いこともある

Posted at

Emacsでは、この変数を有効にするだけで余分な空白が目立つようになって極めてべんりだ。

php-mode with show-trailing-whitespace

~/.emacs.d/init.elに次のような一行を足すとよい。

init.el
(setq-default show-trailing-whitespace t)

……と、ところでこのままでは若干見栄えが悪くなることもある。Eshellや対話環境を利用するときなど。

解決策

微妙な感じもするんだけど、(setq show-trailing-whitespace nil) つまり機能を無効化するだけのフックを各モードに設定する。

my/disable-trailing-modesは末尾の空白表示を無効化するモードのブラックリストなので、嫌だなと思ったらこのリストに追加してやればいい。

init.el
(defun my/disable-trailing-mode-hook ()
  "Disable show tail whitespace."
  (setq show-trailing-whitespace nil))

(defvar my/disable-trailing-modes
  '(comint-mode
    eshell-mode
    eww-mode
    term-mode
    twittering-mode))

(mapc
 (lambda (mode)
   (add-hook (intern (concat (symbol-name mode) "-hook"))
             'my/disable-trailing-mode-hook))
 my/disable-trailing-modes)

私はdash.elがだいすきなので、例によってmapcは短く書ける。

init.el
(--each my/disable-trailing-modes
  (add-hook (intern (concat (symbol-name it) "-hook"))
            'my/disable-trailing-mode-hook))
10
8
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
10
8