5

I diminish my minor modes into single Unicode characters to save space. However, this obviously breaks down in a Linux TTY for instance. How can I detect if the current display method supports Unicode (or better yet, can display a specific character)?

Note: Simply detecting a graphical frame is not enough, as many graphical terminal emulators support Unicode, but emacs does not run in a graphical frame.

  • I'm not sure what you mean with your last sentence, but display-graphic-p always returns nil when Emacs is running in a terminal, whether it's “graphical” or not. – lunaryorn Jan 10 '15 at 18:51
  • @lunaryorn Exactly. display-graphic-p being nil is not strong enough to guarantee a lack of Unicode. – PythonNut Jan 10 '15 at 19:48
  • But it being non-nil almost guarantees unicode support. – lunaryorn Jan 10 '15 at 19:51
  • ... which is why I'm asking about detecting terminal Unicode coverage. – PythonNut Jan 10 '15 at 21:23
  • Ah, sorry, I misunderstood your question. I don't think that's possible, though: On TTY frames, Emacs has no influence whatsoever on the font selection, and thus on unicode support, and it can't detect which fonts the terminal emulator uses. – lunaryorn Jan 10 '15 at 21:51
2

You cannot.

If Emacs is speaking to a terminal, it only knows which coding system is spoken by the terminal. If the coding system is a locale-specific one (say, ISO 8859-1 or Shift-JIS), then it is a good bet that the terminal supports most or all of the characters in the coding system. If the coding system is Unicode-based, then there is no way to know which particular subset of Unicode the terminal is able to display.

On a Unicode terminal, char-displayable-p answers unicode for all Unicode characters.

-1

How can I detect if the current display method supports Unicode (or better yet, can display a specific character)?

You can detect if emacs can display a specific character with the char-displayable-p function.

(char-displayable-p ?☺) 

You can insert such unicode chars with C-x 8, or use their hex code preceded by a \x.

  • This returns "unicode" in both a linux TTY that doesn't support Unicode, and a GNOME terminal that does. I don't think it actually does any display detection. – PythonNut Jan 11 '15 at 3:17
  • @PythonNut I guess it works with font detection. Sorry it didn't help. – Malabarba Jan 11 '15 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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