4

I'm aware of and use whitespace-mode to great effect. I don't show a glyph/character for spaces because I think it's too noisy and unnecessary. I do highlight trailing spaces red which is great.

Aside from that, I was thinking that it may be useful to specify a glyph such as ·, if it were possible, for inner consecutive spaces. This means that it excludes trailing whitespace as well as indentation, for example:

print("one·····two");

instead of:

print("one     two");

But again, this wouldn't apply to leading/indentation whitespace nor trailing whitespace.

Is this possible?

EDIT: I tried setting whitespace-regexp-search as:

(setq whitespace-space-regexp "[^ ]\\( \\{2,\\}\\)[^ ]")

I have spaces and space-mark in my whitespace-style:

(setq whitespace-style
      '(face indentation trailing empty spaces space-after-tab
        space-before-tab tab-mark space-mark))

However, it seems like the whitespace-space-regexp is only for the spaces face highlighting, and isn't used for setting the space-mark. Here's the effect:

img

Notice that all other spaces are still showing the space-mark, even though what I'd like is for consecutive spaces of 2 or more to show it. The inner consecutive spaces are indeed being highlighted differently, but I only did that to show the difference between what's being matched by whitespace-space-regexp and the space-mark character.

In fact I just noticed that even the numberline is showing the space-mark.

It looks like the space-mark is simply matched based on a character, which I guess makes sense, so perhaps this isn't possible after all.

Note: As outlined in my post, I recognize that this isn't possible via whitespace itself, what I'm curious about is whether it's possible to do at all. I found some uses of font-locking such as this one which accomplish replacing pattern matches with a character. I'm wondering if it would be possible to use something like this but have it replace the spaces in the region matched with the middle dot for example.

5
  • It is possible to draw an overlay that looks like a middle dot at the desired locations, but it would not be as efficient as setting up a font-lock rule and setting up a highlight of some sort at the desired locations. The answer by JeanPierre is correct, but doesn't provide either of the above-mentioned solutions/workarounds.
    – lawlist
    May 18, 2016 at 17:15
  • Yeah I saw some people doing some things with font-lock rules where they would use compose-region to like replace one string with another, such as this one, but I can't figure out how to make it replace the region with another string or replace all spaces in the region with the middle dot with something like subst-char-in-region. Is that even possible? May 18, 2016 at 20:06
  • @lawlist So that I can enhance my answer, you mean: there's no solution provided by whitespace mode but one could use overlays to achieve that; right? What's the second solution/workaround?
    – JeanPierre
    May 19, 2016 at 7:13
  • @JeanPierre -- I've given it some thought and don't have a really good solution. I do a lot of stuff with overlays in the visible window, but I programmatically need to recalculate each command loop -- so depending on what's going on, it may not be that efficient. I have never been impressed by the composition library, perhaps because it is not 100% compatible with my preferred courier font on OSX. The easiest and most workable solution would be for the original poster to just settle on a face attribute like overline/underscore/strikethrough instead of a middle dot and use a font-lock rule.
    – lawlist
    May 19, 2016 at 14:18
  • @lawlist Fair enough, that's good to know. The reason I'm not inclined to just use a face attribute is that the point of using a dot glyph was to give an idea of how many spaces were there. Making it overline, underscore, strikethrough, or even just a background color doesn't serve that end. Thanks for the information though, I'll mark JeanPierre's answer. May 19, 2016 at 19:31

1 Answer 1

3

Indeed you can't specify different glyphs for different kinds of spaces because this feature makes use of a display table. The relevant values in variable whitespace-style are (emacs manual):

space-mark Draw space and non-breaking characters with a special glyph.

tab-mark Draw tab characters with a special glyph.

newline-mark Draw newline characters with a special glyph.

All other values specify highlights, so all other distinctions can only be made through the use of faces.

See my answer on a related question.

1
  • Thanks JeanPierre. I realized this, what I'm wondering about is if it's possible to do in emacs at all, for example via font-locking. May 19, 2016 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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