A
A
Anton2017-08-09 06:01:18
emacs
Anton, 2017-08-09 06:01:18

How to display spaces in emacs?

I added the following lines to the .emacs file as shown here :

(setq whitespace-style '(face trailing tabs spaces lines newline empty
                         space-mark tab-mark newline-mark))
(set-face-attribute 'whitespace-space nil :background nil :foreground "#00FF00")
(set-face-attribute 'whitespace-newline nil :background nil :foreground "#0000FF")

But for some reason, emacs swears at the second and third lines

Warning (initialization): An error occurred while loading `/home/milai/.emacs':
error: Invalid face, whitespace-space
To ensure normal operation, you should investigate and remove the
cause of the error in your initialization file. Start Emacs with
the `--debug-init' option to view a complete error backtrace.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Z
Zr, 2017-08-09
@Zr

> But for some reason, emacs swears at the second and third lines of
Materno, right? (I can't imagine why you were too shy to swear.)
And by turning on the telepath, I can assume that you simply whitespace.elare not loaded.

M
Maxim Dunayevsky, 2021-02-17
@dunmaksim

You need to use the whitespace-mode package . The following shows how to enable and configure it:

;; WHITESPACE MODE
;; https://www.emacswiki.org/emacs/WhiteSpace
(straight-use-package 'whitespace-mode)
(defun setup-whitespace-mode ()
  "Settings for 'whitespace-mode'."
  (interactive)
  (setq-default whitespace-display-mappings
                '(
                  (space-mark   ?\    [?\xB7]  [?.]) ; space
                  (space-mark   ?\xA0 [?\xA4]  [?_]) ; hard space
                  (newline-mark ?\n   [?¶ ?\n] [?$ ?\n]) ; end of line
                  )
                ;; Highlight lines with length bigger than 1000 chars
                whitespace-line-column 1000
                whitespace-fill-column 1000
                )

  ;; Markdown-mode hack
  (set-face-attribute 'whitespace-space nil
                      :family default-font-family
                      :foreground "#75715E")
  (set-face-attribute 'whitespace-indentation nil
                      :family default-font-family
                      :foreground "#E6DB74"))
(add-hook 'whitespace-mode-hook #'setup-whitespace-mode)

Now add a call to the activation hook for the desired mode: For example, my settings for Markdown look like this:
(whitespace-mode 1)
;; MARKDOWN MODE
;; https://github.com/jrblevin/markdown-mode
(straight-use-package 'markdown-mode)
(defun setup-markdown-mode()
  "Settings for editing markdown documents."
  (interactive)
  ;; Настройки отступов и всякое такое

  (setq
   global-hl-line-mode nil
   header-line-format " "
   left-margin-width 4
   line-spacing 3
   right-margin-width 4
   word-wrap t)

  ;; Additional modes
  (abbrev-mode 1)
  (buffer-face-mode 1)
  (company-mode 1)
  (flycheck-mode 1) ;; Turn on linters
  (linum-mode 1)
  (rainbow-delimiters-mode 1)
  (rainbow-mode 1) ;; Highlight brackets
  (visual-line-mode 1) ;; Highlight current line
  (whitespace-mode 1) ;; Show spaces, tabs and other
  (ws-butler-mode 1) ;; Delete trailing spaces on changed lines
  (cond ;; Turn on spell-checking only in Linux
   ((string-equal system-type "gnu/linux")(flyspell-mode 1)))

  (set-face-attribute 'markdown-code-face        nil :family default-font-family)
  (set-face-attribute 'markdown-inline-code-face nil :family default-font-family))
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-hook 'markdown-mode-hook #'setup-markdown-mode)

I use straight.el , a fork of use-package , as my package manager , but you can use whatever you like.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question