Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs show invisible symbols (\n)

Tags:

emacs

elisp

I am trying to highlight several invisible symbols in Emacs, specifically \n. I am trying the following:

(standard-display-ascii ?\n "¬\n")
(font-lock-add-keywords nil '(("¬" . font-lock-comment-face)))

Unfortunately, it looks like only typed explicitly symbols will use the specified font-face. Is there a proper way to highlight the display-ascii symbol?

One more related question: replacing nil with 'lisp-interaction-mode in the second expression makes it not working anymore. Why is that?

like image 323
egdmitry Avatar asked Nov 30 '22 11:11

egdmitry


2 Answers

I just booted up emacs, did the command M-x, and typed

whitespace-mode

Afterwards I got a $ indicator for newlines.

like image 161
merlin2011 Avatar answered Dec 06 '22 22:12

merlin2011


To only show newlines the following can be used:

(global-whitespace-newline-mode)

or an alternative:

(setq whitespace-style '(face newline-mark))
(whitespace-mode t)

And to use the custom symbol ¬ for it:

(setq whitespace-display-mappings
      '((newline-mark 10 [172 10])))

Then the whitespace-newline font-lock can be used to customize the style.

Edit:

For some reason placing this customization in .emacs config results in faces styles not applying to the symbol, I am not sure why (would be great if somebody could explain this). Using hooks works fine:

(add-hook 'prog-mode-hook
          (lambda () 
            (whitespace-newline-mode t)))
like image 36
egdmitry Avatar answered Dec 06 '22 22:12

egdmitry