This answer nicely provides a way to display characters rather than tabs (in the example it suggests ">", but I confirmed it works for ".").

It uses setting the active window display table to do it.

Now my goal is to display 4 spaces as 4 dots. Using the font-face and a regular expression, I am confident that I can display it nicely. I am aware that I could have Emacs automatically use tab characters rather than whitespaces, but I always prefer to have whitespace characters in my files.

I've also looked at whitespace mode, but I tweaked many parameters and in the end I never get the simple dots (with a face that makes it a little less "jump" out).

So: how can I, rather than display tab characters as dots, display 4 spaces elegantly as dots in Emacs?

share|improve this question
1  
Let me guess: you're a Python guy, right? Talking abound 4 spaces and elegance:) – abo-abo Feb 15 '14 at 12:27
    
Haha, that made me laugh. Python is indeed the one I would need it for ! – PascalvKooten Feb 15 '14 at 12:28
    
So you want little dots for spaces only when there's 4 of them? – abo-abo Feb 15 '14 at 12:29
    
The indentation really, so yea, 4 or more spaces. – PascalvKooten Feb 15 '14 at 12:30
    
Start with this: (setq whitespace-space-regexp "\\( \\{4,\\}\\)") – abo-abo Feb 15 '14 at 12:31

OK, here's how to mark 4 or more spaces at beginning of line

(setq whitespace-space-regexp "^\\( \\{4,\\}\\)")

And here's how to get rid of the centered dot character for space:

(setq whitespace-display-mappings
  '((space-mark   ?\     [?\ ]     [?.])
    (space-mark   ?\xA0  [?\ ]     [?_])
    (newline-mark ?\n    [?$ ?\n])
    (tab-mark     ?\t    [?\u00BB ?\t] [?\\ ?\t])))

The changes take effect not immediately but when you revert-buffer or close it and open again with customizations above already set.

share|improve this answer
    
Nothing happened? I put it in init file and restarted Emacs. – PascalvKooten Feb 15 '14 at 12:51
    
Works for me with emacs -q and evaling the code above. 4+ spaces show up as light yellow in Python, while 3 spaces do not. Works on 24.3 – abo-abo Feb 15 '14 at 12:55
    
even with emacs -q it does not show up, something weird is going on? – PascalvKooten Feb 15 '14 at 12:57
    
What's your emacs version? – abo-abo Feb 15 '14 at 12:58
    
Emacs version: 24.2.1 – PascalvKooten Feb 15 '14 at 12:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.