Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to find out if you are running under X or in a tty

17 views
Skip to first unread message

ich...@ak47.algebra.com

unread,
Apr 5, 2002, 12:14:17 PM4/5/02
to
...

lawrence mitchell

unread,
Apr 5, 2002, 12:47:53 PM4/5/02
to
ich...@ak47.algebra.com wrote:
[...] Checking to see if running under X (i.e. with a window-system),
or on a tty.

Does the variable window-system help?

I use
(defconst llm-tty-flag (not window-system)) and
(defconst llm-window-flag (not llm-tty-flag))

in my .emacs, as I check them relatively often[1]

[1] ty Ted O'Connor :-)

f-up set to g.e.help
--
lawrence mitchell <we...@gmx.li>

Friedrich Dominicus

unread,
Apr 6, 2002, 1:57:57 AM4/6/02
to
lawrence mitchell <we...@gmx.li> writes:

> ich...@ak47.algebra.com wrote:
> [...] Checking to see if running under X (i.e. with a window-system),
> or on a tty.
>
> Does the variable window-system help?
>
> I use
> (defconst llm-tty-flag (not window-system)) and
> (defconst llm-window-flag (not llm-tty-flag))

I checked the docs on my version
"XEmacs 21.4 (patch 6) \"Common Lisp\" [Lucid] (i386-debian-linux) of
Mon Jan 21 2002 on eeyore"

And found this

i console-on-window-system-p - Return t if CONSOLE is on a window system.
b device-on-window-system-p - Return non-nil if DEVICE is on a window system.

besides the mentioned window-system stuff.

I would think this are the specialiced functions for such things.

Of course your suggestions are fine too.

Regards
Friedrich

Eli Zaretskii

unread,
Apr 6, 2002, 1:18:44 AM4/6/02
to
Friedrich Dominicus wrote:
>
> I would think this are the specialiced functions for such things.

There are; window-system should generally not be used. The function
display-graphic-p sounds like a much better alternative, but there are other
functions for other capabilities. See NEWS for more details.

Dan Colascione (QuoteMstr)

unread,
Apr 7, 2002, 4:49:10 PM4/7/02
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 5 Apr 2002 17:14:17 GMT, ich...@ak47.algebra.com () wrote:
> ...

Problem is, it's not necessarily one or the other. You could have
frames on ttys _and_ x systems. I occasionally do.

What you probably want is the frame-type function. With no arguments,
that'll tell you what kind of system the current frame is on.

- --
"Use what talents you possess: the woods would be very silent if no
birds sang there except those that sang best." -- Henry Van Dyke

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8sLDGDtFkzqOHwVgRAvShAKCSyZZas0lifkG5mGpoSKxTXwkV7QCbBYsV
snyDVeC09WNRYzpWEwunGwU=
=I9/G
-----END PGP SIGNATURE-----

Adrian Aichner

unread,
Apr 7, 2002, 5:26:09 PM4/7/02
to
>>>>> "Eli" == Eli Zaretskii <el...@is.elta.co.il> writes:

Eli> Friedrich Dominicus wrote:
>>
>> I would think this are the specialiced functions for such things.

Eli> There are; window-system should generally not be used. The
Eli> function display-graphic-p sounds like a much better

display-graphic-p
does not exist in XEmacs (21.5.5).

window-system is available.

Eli> alternative, but there are other functions for other
Eli> capabilities. See NEWS for more details.

--
Adrian Aichner
mailto:adr...@xemacs.org
http://www.xemacs.org/

Eli Zaretskii

unread,
Apr 7, 2002, 11:37:51 PM4/7/02
to
Adrian Aichner wrote:
>
> >>>>> "Eli" == Eli Zaretskii <el...@is.elta.co.il> writes:
>
> Eli> Friedrich Dominicus wrote:
> >>
> >> I would think this are the specialiced functions for such things.
>
> Eli> There are; window-system should generally not be used. The
> Eli> function display-graphic-p sounds like a much better
>
> display-graphic-p
> does not exist in XEmacs (21.5.5).

I hope it will be added at some point.

Peter Weiss, Sun Microsystems, Germany

unread,
Apr 8, 2002, 6:33:29 AM4/8/02
to
>>>>> On 5 Apr 2002 17:14:17 GMT, ich...@ak47.algebra.com () said:

I use the variable window-system for this purpose:

window-system's value is x

Documentation:
A symbol naming the window-system under which Emacs is running
(such as `x'), or nil if emacs is running on an ordinary terminal.


works both with emacs and xemacs latest versions.

Hth -- Peter

--
Consultant der CLASS AG http://www.class.de
Technical Services
mobil +49 (0) 172/837 91 25
mailto:Peter...@class.de

Stephen J. Turnbull

unread,
Apr 8, 2002, 1:01:30 PM4/8/02
to
>>>>> "Eli" == Eli Zaretskii <el...@is.elta.co.il> writes:

Eli> There are; window-system should generally not be used. The
Eli> function display-graphic-p sounds like a much better

Eli> Adrian Aichner wrote:

>> display-graphic-p does not exist in XEmacs (21.5.5).

Eli> I hope it will be added at some point.

According to the GNU Emacs docstring:

Return non-nil if DISPLAY is a graphic display.

Graphical displays are those which are capable of displaying several
frames and several different fonts at once.

In XEmacs, TTYs are capable of displaying several frames (although
they are always stacked so that only the top one is visible), and some
TTYs (eg xterm) are capable of displaying several fonts (actually
typographic faces such as bold; and certainly different Emacs faces,
with different colors). Presumably what is really meant here is a
bitmapped display capable of displaying images and such? (Eg, usable
by something like preview-latex.) If so, is there a reason why it
isn't defined that way? If not, does the XEmacs TTY driver then
satisfy the GNU Emacs definition of display-graphic-p?

[NB. In many cases in XEmacs customization can/should be done by
using a device tag in a specifier, rather than by conditioning on a
predicate such as display-graphic-p.

Since the OP says merely "am I under X or a TTY", I see no way to
determine what the "best" way to make the distinction is. It will
vary according to his intent.]

--
Institute of Policy and Planning Sciences http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Don't ask how you can "do" free software business;
ask what your business can "do for" free software.

David Kastrup

unread,
Apr 8, 2002, 1:24:44 PM4/8/02
to
"Stephen J. Turnbull" <ste...@xemacs.org> writes:

> >>>>> "Eli" == Eli Zaretskii <el...@is.elta.co.il> writes:
>
> Eli> There are; window-system should generally not be used. The
> Eli> function display-graphic-p sounds like a much better
>
> Eli> Adrian Aichner wrote:
>
> >> display-graphic-p does not exist in XEmacs (21.5.5).
>
> Eli> I hope it will be added at some point.
>
> According to the GNU Emacs docstring:
>
> Return non-nil if DISPLAY is a graphic display.
>
> Graphical displays are those which are capable of displaying several
> frames and several different fonts at once.
>
> In XEmacs, TTYs are capable of displaying several frames (although
> they are always stacked so that only the top one is visible), and some
> TTYs (eg xterm) are capable of displaying several fonts (actually
> typographic faces such as bold; and certainly different Emacs faces,
> with different colors). Presumably what is really meant here is a
> bitmapped display capable of displaying images and such? (Eg, usable
> by something like preview-latex.) If so, is there a reason why it
> isn't defined that way? If not, does the XEmacs TTY driver then
> satisfy the GNU Emacs definition of display-graphic-p?

If it did, then the same would hold true with GNU Emacs tty buffers
(which by now can have multiple frames and faces). Which it
doesn't. Seems like that DOC string could use some updating.

--
David Kastrup, Kriemhildstr. 15, 44793 Bochum
Email: David....@t-online.de

Eli Zaretskii

unread,
Apr 8, 2002, 2:08:25 PM4/8/02
to
"Stephen J. Turnbull" wrote:
>
> According to the GNU Emacs docstring:
>
> Return non-nil if DISPLAY is a graphic display.
>
> Graphical displays are those which are capable of displaying several
> frames and several different fonts at once.
>
> In XEmacs, TTYs are capable of displaying several frames (although
> they are always stacked so that only the top one is visible)

GNU Emacs supports this as well. However, note the ``at once'' part, which
attempts to indicate that the case of several overlapping frames doesn't
count.

> and some
> TTYs (eg xterm) are capable of displaying several fonts (actually
> typographic faces such as bold;

True. Perhaps the doc string should say ``many different fonts'' instead of
``several''. A terminal emulator only supports a small number of them, I
think (one each for normal, bold, italic, and underlined, and perhaps also
for some combinations).

> and certainly different Emacs faces, with different colors).

That's why colors aren't mentioned at all.

> Presumably what is really meant here is a
> bitmapped display capable of displaying images and such?

Yes; but note that both ``bitmapped'' and ``image support'' are no less
ambiguous. For example, the Windows port of GNU Emacs 21.1 didn't support
images, but it still counts as a graphics display. As for bitmapped, an
xterm runs on a bitmapped display as well, right?

It's hard to find the definition that is at once accurate and easy to
understand without knowing a lot about display technology. Especially if
you take into account that various GUI aspects such as mouse and menus are
supported by the MS-DOS port and by xt-mouse, which both work as character
terminals and don't count as graphics, in this context. Suggestions for
improving the doc string are welcome.

> does the XEmacs TTY driver then
> satisfy the GNU Emacs definition of display-graphic-p?

No, I don't think so.

> [NB. In many cases in XEmacs customization can/should be done by
> using a device tag in a specifier, rather than by conditioning on a
> predicate such as display-graphic-p.

display-graphic-p accepts an argument, a frame or display to which the query
pertains. Is there something that cannot be gleaned from this argument to
make the distinction correctly?

> Since the OP says merely "am I under X or a TTY", I see no way to
> determine what the "best" way to make the distinction is. It will
> vary according to his intent.]

He didn't even say if it was XEmacs or GNU Emacs, but cross-posted on both
groups. So it's indeed hard to give any specific advice.

ich...@ak47.algebra.com

unread,
Apr 8, 2002, 3:24:36 PM4/8/02
to
>-----BEGIN PGP SIGNED MESSAGE-----
>Hash: SHA1
>
>On 5 Apr 2002 17:14:17 GMT, ich...@ak47.algebra.com () wrote:
>> ...
>
>Problem is, it's not necessarily one or the other. You could have
>frames on ttys _and_ x systems. I occasionally do.

you are right, I did not think about it. I have the same situation.

>What you probably want is the frame-type function. With no arguments,
>that'll tell you what kind of system the current frame is on.

thanks.

igor

Stephen J. Turnbull

unread,
Apr 9, 2002, 5:48:49 AM4/9/02
to
FUT c.e.x

>>>>> "Eli" == Eli Zaretskii <el...@is.elta.co.il> writes:

Eli> It's hard to find the definition that is at once accurate and
Eli> easy to understand without knowing a lot about display
Eli> technology. Especially if you take into account that various
Eli> GUI aspects such as mouse and menus are supported by the
Eli> MS-DOS port and by xt-mouse, which both work as character
Eli> terminals and don't count as graphics, in this context.
Eli> Suggestions for improving the doc string are welcome.

Well, since I'm having trouble grasping when this predicate should be
used, I can't really help there. It seems to me that applications
would actually prefer to know whether there is a menu bar, GUI buttons
or text, scrollbars, etc, available in the frame rather than this
generic "display-graphic-p". And that in many cases where a specifier
value is used, it doesn't need to care.

Eli> display-graphic-p accepts an argument, a frame or display to
Eli> which the query pertains. Is there something that cannot be
Eli> gleaned from this argument to make the distinction correctly?

The specifier mechanism permits things like

(set-face-font 'bold "-adobe-courier-bold-*" nil '(x gtk))
(set-face-foreground 'bold "blue" nil '(tty))

after which the distinction is made internally to redisplay,
displaying bold as blue on TTYs but a bold font on X window systems.
(We use MS Windows syntax to express font names on Windows, I forget
how to say "-adobe-courier-bold-*" in that dialect.) Similar things
can be done with various kinds of glyphs (images vs text strings, or
text "buttons" vs window system widgets, etc). Then the Lisp code
doesn't need to know or care whether it's running graphic-display-p or
not, and in fact it can do both simultaneously in different windows
displayed on different devices.

So it's not a question of being able to distinguish, it's a difference
between a declarative syntax and a prodedural syntax.

Eli Zaretskii

unread,
Apr 9, 2002, 1:35:21 PM4/9/02
to
"Stephen J. Turnbull" wrote:
>
> Well, since I'm having trouble grasping when this predicate should be
> used, I can't really help there. It seems to me that applications
> would actually prefer to know whether there is a menu bar, GUI buttons
> or text, scrollbars, etc, available in the frame rather than this
> generic "display-graphic-p".

There are other functions to answer the more specific questions:
display-mouse-p, display-popup-menus-p, display-selections-p, etc. So
display-graphic-p is _really_ for querying about multi-frame and multi-font
versions (there are aliases display-multi-frame-p and display-multi-font-p).

> Eli> display-graphic-p accepts an argument, a frame or display to
> Eli> which the query pertains. Is there something that cannot be
> Eli> gleaned from this argument to make the distinction correctly?
>
> The specifier mechanism permits things like
>
> (set-face-font 'bold "-adobe-courier-bold-*" nil '(x gtk))
> (set-face-foreground 'bold "blue" nil '(tty))

GNU Emacs uses defface for these. I thought XEmacs supported defface as
well, no?

> Then the Lisp code
> doesn't need to know or care whether it's running graphic-display-p or
> not, and in fact it can do both simultaneously in different windows
> displayed on different devices.

For the faces, yes. But many Lisp programs need to make other decisions
based on what the display can handle. For example, Ediff has two different
operation modes, one for graphics displays such as X and Windows, the other
for character terminals.

Stephen J. Turnbull

unread,
Apr 10, 2002, 6:20:55 AM4/10/02
to
>>>>> "Eli" == Eli Zaretskii <el...@is.elta.co.il> writes:

Eli> There are other functions to answer the more specific
Eli> questions: display-mouse-p, display-popup-menus-p,
Eli> display-selections-p, etc. So display-graphic-p is _really_
Eli> for querying about multi-frame and multi-font versions (there
Eli> are aliases display-multi-frame-p and display-multi-font-p).

Oh. In that case, I'd add the words "deprecated", "obsolete", and
"ambiguous" to the docstring for `display-graphic-p'. I don't see a
good way to document that function except "`display-multi-font-p' and
`display-multi-frame-p' share an implementation, so we gave the
implementation a name." YMMV, but I think its a misleading API.

[example snipped]

Eli> GNU Emacs uses defface for these. I thought XEmacs supported
Eli> defface as well, no?

Yes. That's why I picked the example, because I figured it would be
familiar to you. But it's only an example; just as any variable can
be buffer-local, any (except for certain magic built-ins) variable can
take a specifier value.

>> Then the Lisp code doesn't need to know or care whether it's
>> running graphic-display-p or not, and in fact it can do both
>> simultaneously in different windows displayed on different
>> devices.

Eli> For the faces, yes. But many Lisp programs need to make
Eli> other decisions based on what the display can handle. For
Eli> example, Ediff has two different operation modes, one for
Eli> graphics displays such as X and Windows, the other for
Eli> character terminals.

All of which can be implemented as specifier variables, instead of
calling functions. It's not, though, because GNU Emacs doesn't have
specifier variables.

Ediff would probably not benefit much, since you'd still have to call
(or not) special code to create the popup "control" frame.

Ilya Zakharevich

unread,
Apr 10, 2002, 9:08:54 PM4/10/02
to
[A complimentary Cc of this posting was sent to
Peter Weiss, Sun Microsystems, Germany
<Peter...@Germany.Sun.com>], who wrote in article <xpxyn0we...@Germany.Sun.com>:

> >>>>> On 5 Apr 2002 17:14:17 GMT, ich...@ak47.algebra.com () said:
>
> I use the variable window-system for this purpose:
>
> window-system's value is x

Do not. Find out *why* you need to know the difference (which
*capability* you are interested in), then check for presence of this
capability.

(On older Emacsen, which cannot report capabilities, one *needs* to
check window-system... Sigh)

Ilya

0 new messages