1

Is there a way to indicate where you have an "invisible" character that's causing problems in an org-mode table?

The character's likely a TAB, but for the general case I'd like to assume it could also be other characters, e.g. a "narrow no-break space" (U+202F).

Background

I just pasted multiple lines into an org-mode table, as per Is it possible to copy /paste multiple lines of text into cells of org-mode table?.

First I created an empty table:

|   |   |
|   |   |

Then I created some lines in the org-mode buffer. Originally I'd copied text from some web page, but I've found I can reproduce the behaviour with the text below.

abcdef
abcdef7890

Then I used C-x r k and C-x r y to insert this into the table. Below is the result, after pressing C-c C-c to align the table:

|   | abcdef     |
|   | abcdef7890     |

Note that the rightmost '|' aren't correctly aligned. It seems a TAB character was added in the process at the end of the first row.

If I do e.g. ESC SPACE at the end of the first row and then C-c C-c, that row is fixed. In this case it also fixes the entire table:

|   | abcdef     |
|   | abcdef7890 |

However, in my original case I had to go and fiddle with all rows.

PS. The focus of this question is how to show the invisible/problematic characters, assuming that's the cause. Why I'm getting the problematic characters should probably go in another question.

Update: Created Why is a TAB character added when using kill-rectangle and yank-rectangle to insert multiple rows into an org-mode table?

2
  • Yes, please pose another question for the problem of why you're getting problematic chars. For that one, you'll need to specify what you're doing, so others can better provide help.
    – Drew
    Commented Jan 7, 2021 at 5:21
  • I've now created the new question emacs.stackexchange.com/q/62659/12589
    – chr
    Commented Jan 8, 2021 at 9:06

2 Answers 2

2

highlight-chars is nice and general, but whitespace-mode is better for the common case where you mostly just care about tabs and spaces. You can configure it to change the background color of inappropriate whitespace characters so that they become obvious, or you can use it to show a glyph in their place, or both.

The one annoyance that I've had with whitespace-mode is that it doesn't react immediately to configuration changes; I always had to close the buffer and reopen it to see the effects of changing the settings. I never did figure out how to fix that, but perhaps it's better these days.

2
  • This seems to do the trick for my use case. No installation required, just do M-x whitespace-mode and the TABs become visible. Also ellipsis and hard non-breaking space. Usefulness does however depend on your theme - with tango-dark, the TAB was not visible. It was also annoying with the strong yellow highlight of initial blank lines when using tango-dark. All in all, this solves my use case if I just switch the theme. (I'd just picked a random dark theme)
    – chr
    Commented Jan 8, 2021 at 9:28
  • You can customize all of the faces used by whitespace-mode so that they look however you want. You can also turn on or off individual features. Use M-x customize-group whitespace.
    – db48x
    Commented Jan 8, 2021 at 9:42
1

You can use library highlight-chars.el to highlight any characters you like.

See commands hc-highlight-chars and hc-toggle-highlight-other-chars. You can specify characters in any of these ways:

  • individually
  • using ranges
  • using character classes (e.g. [:digit:])
  • using character sets (e.g. iso-8859-1' or lao').

Download

2
  • I tested it and it seems useful with e.g. hc-toggle-highlight-tabs, although I'd have to know I'm looking for a TAB. The hc-toggle-highlight-other-char doesn't (by default) show the TAB or a non-breaking space. Is there a reason the package isn't in e.g. MELPA?
    – chr
    Commented Jan 8, 2021 at 9:23
  • 1. hc-toggle-highlight-other-char depends on your having specified the "other chars" you want highlighted - there are no default chars. See C-h f hc-highlight-other-chars 2. This speaks to your MELPA question.
    – Drew
    Commented Jan 8, 2021 at 17:41

Your Answer

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

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