/
leerzeichen.el
79 lines (59 loc) · 2.82 KB
/
leerzeichen.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
;;; leerzeichen.el --- Minor mode to display whitespace characters.
;; Copyright (c) 2014-2015 Felix Geller
;; Author: Felix Geller <fgeller@gmail.com>
;; Keywords: whitespace characters
;; URL: http://github.com/fgeller/leerzeichen.el
;; This file is not part of GNU Emacs.
;; This file 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, or (at your option)
;; any later version.
;; This file 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 GNU Emacs; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; leerzeichen is a minor mode to display whitespace characters. That's all it
;; does, and it imposes little overhead by using a buffer local display table
;; rather than the font-lock functionality.
;; More information: https://github.com/fgeller/leerzeichen.el/
;;; Code:
(defgroup leerzeichen nil
"Faces for highlighting whitespace characters."
:group 'leerzeichen)
(defface leerzeichen '((t (:foreground "#b8b8b8")))
"Face for `leerzeichen-mode'."
:group 'leerzeichen)
(defvar leerzeichen-saved-buffer-display-table nil
"Stored version of `buffer-display-table' before leerzeichen-mode was enabled.")
(defvar leerzeichen-line-feed-glyph (make-glyph-code ?$ 'leerzeichen))
(defvar leerzeichen-tab-glyph (make-glyph-code ?» 'leerzeichen))
(defvar leerzeichen-space-glyph (make-glyph-code ?· 'leerzeichen))
(defun leerzeichen-display-table ()
"Display table to highlight whitespace characters."
(let ((table (make-display-table)))
(aset table ?\n `[,leerzeichen-line-feed-glyph ?\n])
(aset table ?\t (vconcat `[,leerzeichen-tab-glyph] (make-vector (1- tab-width) ? )))
(aset table ?\ `[,leerzeichen-space-glyph])
table))
;;;###autoload
(define-minor-mode leerzeichen-mode
"Minor mode to highlight whitespace characters by displaying them differently."
:lighter "lz "
:keymap nil
(if leerzeichen-mode
(leerzeichen-enable)
(leerzeichen-disable)))
(defun leerzeichen-enable ()
"Installs leerzeichen's display table as (buffer local) `buffer-display-table'."
(setq leerzeichen-saved-buffer-display-table buffer-display-table)
(setq buffer-display-table (leerzeichen-display-table)))
(defun leerzeichen-disable ()
"Resets `buffer-display-table' to state before leerzeichen was enabled."
(setq buffer-display-table leerzeichen-saved-buffer-display-table))
(provide 'leerzeichen)
;;; leerzeichen.el ends here