[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: how to use graphic-display-p and window-system

From: Drew Adams
Subject: RE: how to use graphic-display-p and window-system
Date: Fri, 17 Apr 2009 13:15:36 -0700

> > In particular, I want to check whether Emacs supports keys 
> > such as S-TAB.
> That's totally unrelated to window-system or the display being
> graphic.  For example, on MS-Windows, S-TAB is supported even under
> "-nw", where window-system and display-graphic-p are both nil.

So what is it related to then?

When keys are occasionally discussed/proposed for Emacs in emacs-devel, there is
often the consideration that a given key might not be supported. I thought that
the relevant criterion was console vs window-mgr support. If not, what is it -
and how to test for it?

See also below - it seems like the Emacs source code generally uses
`window-system' to test for such keys. That's my first impression, but you say
it is "totally unrelated", so I wonder.

Perhaps there are platform-specific details or exceptions, but I'm looking for a
general test that is platform-independent, even if that means it might not be
100% reliable. I'm not going to test each platform with each
console-vs-graphics-display combination or with each possible key sequence.

> > [Excuse me if console/terminal is not the right terminology,
> > but I'm talking about Emacs with no fancy keys such as S-TAB
> > and less graphic support (colors, fonts etc.) versus Emacs
> > with no such limitations.]
> Colors nowadays are also orthogonal to window-system and
> display-graphic-p: for example, there's the 256-color xterm, where the
> number of colors is indistinguishable from a GUI display, but
> window-system is nil and so is what display-graphic-p returns.

I said "less"; I didn't say "no" color support. 256 colors is not the general
color support that Emacs has with a window mgr. Can you use more or less
arbitrary #RRRGRRBBB codes, or are you limited to, say, 256 colors? That's what
I mean.

Again, if neither `window-system' nor `display-graphic-p' addresses such a
distinction, then what does? Will `display-color-p' make this distinction?

> > `display-graphic-p' has apparently been with us since Emacs 
> > 22, but there is no mention of it in the Elisp manual, even in Emacs 23.
> ??? Are you looking at a stale ELisp manual, perhapss I typed
> "i display-graphic-p RET" and landed in a node named "Display Feature
> Testing" that documents this predicate.  This documentation exists
> since the day the predicate itself was added to Emacs (which, btw, was
> during Emacs 21 development, not since Emacs 22).

Oops. I must have typed the wrong search string; sorry.
I probably looked for `graphic-display-p' or something.

> > Could someone please summarize the differences between the 
> > two, and when to use one or the other?
> The only situation I know of where use of window-system is justified
> is when you want to distinguish between the different kinds of window
> systems, like between X and MS-Windows.  In all other cases, you are
> well advised to use the APIs documented in the above-mentioned node of
> the ELisp manual.
> As for testing whether ``fancy'' keys are supported, I don't know how
> to do that in Emacs.  Maybe someone else can suggest a way.  But
> window-system is certainly not the way of doing that in a portable
> manner.

Too bad. I hope someone has a suggestion or two.

The main two tests I need are these:

1. General colors vs no colors or limited set of colors (e.g. 256).

2. General keys vs no modifiers for keys such as TAB, insert, and prior. This
means also distinguishing between, say, C-l and C-S-l.

On a related note, in Emacs releases prior to those that have `display-mouse-p',
`display-graphic-p', etc. what are the proper tests to use for such things? Is
`window-system' as good as it gets for Emacs 20/21? I see code in the Emacs
sources such as this, for instance (in multiple places):

(if (fboundp 'display-graphic-p)

(or (and (fboundp 'display-graphic-p) ; Emacs 21
    (memq window-system '(x w32 ns))) ; Emacs 20

Grepping `window-system' in the Emacs sources, it looks like "window system" is
generally contrasted to "terminal" and "tty". Which still makes me wonder if
`window-system' isn't the best test for "fancy key" support. I think (but you
will no doubt correct me) that the tty case is what I need to distinguish, to
determine handling of keys such as, say, C-S-insert. (`window-system' seems to
be what org.el, for instance, uses to test for fancy-key handling. Likewise, for
other Emacs code.)

There might of course be some out-of-date uses of `window-system' in the Emacs
23 source code. Dunno. In any case, there are plenty of tests using
`window-system' that seem to determine handling of colors and other face
qualities, character glyphs, and fonts. I didn't analyze details, so I might be
mistaken, but that's my first impression.

There is also a comment indicating that a particular use of `window-system'
needs to be fixed to use `display-graphic-p', but that this cannot be done

;; color selection depends on the number of supported colors,
;; and all defface's are changed to look at number of colors
;; instead of (type graphic) etc.

There's also an occurrence of this, to test support for face regimes:
(or window-system (display-color-p))

These things make me wonder if we are perhaps still between two chairs wrt
color-support tests. On the other hand, this seems to be the test to use for
face support:
(or (fboundp 'tty-defined-colors) window-system)

Anyway, my main question is about facy key support and general color support.
Suggestions and enlightenment welcome. Thx.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]