unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to detect if Emacs is running in a terminal
@ 2005-04-15 15:10 Denis Bueno
  2005-04-15 22:56 ` Peter Dyballa
       [not found] ` <mailman.1688.1113606088.2895.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 10+ messages in thread
From: Denis Bueno @ 2005-04-15 15:10 UTC (permalink / raw)


Is there some emacs lisp function that I could call to detect whether
the current emacs process is running from within a terminal or not?

I'd like to be able to change my font-lock faces based on whether
emacs is running in a terminal or not. At the moment I deal with this
in the following way.

I have a .emacs-common which contains code that should be loaded
regardless of the emacs interface. My .emacs is of course loaded by
default whenever I run Emacs in a window (not in a terminal). This
contains various font settings and colors used in the windowed Emacs.
I have a .emacs-terminal which contains various font settings and
colors used in the terminal Emacs.

So, when I want to use Emacs in the terminal, I run:

    emacs -nw -q -l ~/.emacs-terminal

Is there a better way?

-- 
Denis Bueno
PGP: http://pgp.mit.edu:11371/pks/lookup?search=0xA1B51B4B&op=index

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to detect if Emacs is running in a terminal
       [not found] <mailman.1647.1113578084.2895.help-gnu-emacs@gnu.org>
@ 2005-04-15 15:32 ` David Kastrup
  2005-04-15 15:56 ` Stefan Monnier
  2005-04-15 16:11 ` Pascal Bourguignon
  2 siblings, 0 replies; 10+ messages in thread
From: David Kastrup @ 2005-04-15 15:32 UTC (permalink / raw)


Denis Bueno <dbueno@gmail.com> writes:

> Is there some emacs lisp function that I could call to detect
> whether the current emacs process is running from within a terminal
> or not?

The window-system variable.

> I'd like to be able to change my font-lock faces based on whether
> emacs is running in a terminal or not.

Why?  Face definitions can contain several different specs for
different terminals.

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to detect if Emacs is running in a terminal
       [not found] <mailman.1647.1113578084.2895.help-gnu-emacs@gnu.org>
  2005-04-15 15:32 ` How to detect if Emacs is running in a terminal David Kastrup
@ 2005-04-15 15:56 ` Stefan Monnier
  2005-04-15 16:11 ` Pascal Bourguignon
  2 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2005-04-15 15:56 UTC (permalink / raw)


> I'd like to be able to change my font-lock faces based on whether
> emacs is running in a terminal or not.

   M-x customize-face RET font-lock-<foobar>-face RET

then middle click on the "State" button and select "Show all display specs".
You can then give different face specs for different kinds of displays
(tty, grey, w32, dark-background, ...).


        Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to detect if Emacs is running in a terminal
       [not found] <mailman.1647.1113578084.2895.help-gnu-emacs@gnu.org>
  2005-04-15 15:32 ` How to detect if Emacs is running in a terminal David Kastrup
  2005-04-15 15:56 ` Stefan Monnier
@ 2005-04-15 16:11 ` Pascal Bourguignon
  2005-04-16 12:05   ` Ismael Valladolid Torres
       [not found]   ` <mailman.1726.1113653312.2895.help-gnu-emacs@gnu.org>
  2 siblings, 2 replies; 10+ messages in thread
From: Pascal Bourguignon @ 2005-04-15 16:11 UTC (permalink / raw)


Denis Bueno <dbueno@gmail.com> writes:

> Is there some emacs lisp function that I could call to detect whether
> the current emacs process is running from within a terminal or not?
> 
> I'd like to be able to change my font-lock faces based on whether
> emacs is running in a terminal or not. At the moment I deal with this
> in the following way.
> 
> I have a .emacs-common which contains code that should be loaded
> regardless of the emacs interface. My .emacs is of course loaded by
> default whenever I run Emacs in a window (not in a terminal). This
> contains various font settings and colors used in the windowed Emacs.
> I have a .emacs-terminal which contains various font settings and
> colors used in the terminal Emacs.
> 
> So, when I want to use Emacs in the terminal, I run:
> 
>     emacs -nw -q -l ~/.emacs-terminal
> 
> Is there a better way?

(list system-type system-name window-system)

;; system-type          darwin   gnu/linux  cygwin
;; system-name          "naiad.informatimago.com" "hermes.afaa.asso.fr"
;; system-configuration "i686-pc-linux-gnu" "i686-pc-cygwin"
;; window-system        nil x mac
;; emacs-major-version  18 19 20 21
;; emacs-minor-version  0 1 2 3
;; emacs-version        "20.7.2" "21.2.1"

In a terminal, (null window-system)

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

There is no worse tyranny than to force a man to pay for what he does not
want merely because you think it would be good for him. -- Robert Heinlein

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to detect if Emacs is running in a terminal
  2005-04-15 15:10 Denis Bueno
@ 2005-04-15 22:56 ` Peter Dyballa
       [not found] ` <mailman.1688.1113606088.2895.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Peter Dyballa @ 2005-04-15 22:56 UTC (permalink / raw)
  Cc: help-gnu-emacs


Am 15.04.2005 um 17:10 schrieb Denis Bueno:

> Is there a better way?

What about this?

(cond ((= 21 emacs-major-version)
   (progn
     (desktop-read)
     (cond ((string= "x" window-system)
         (message "Sind in X11")
         (load "~/.emacs_X11")
     ))  ; Ende X11
     (cond ((string= "mac" window-system)
         (message "Sind in Aqua")
         (load "~/.emacs_Carbon")
;        (require '.emacs_Carbon)
     ))  ; Ende Carbon
     (cond ((string= 'nil window-system)
         (message "Sind im Terminal")
         (load "~/.emacs_nil")
     ))  ; Ende Terminal
)));Version 21


--
Greetings

   Pete

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to detect if Emacs is running in a terminal
       [not found] ` <mailman.1688.1113606088.2895.help-gnu-emacs@gnu.org>
@ 2005-04-15 23:42   ` Pascal Bourguignon
  2005-04-16 15:30     ` Peter Dyballa
  0 siblings, 1 reply; 10+ messages in thread
From: Pascal Bourguignon @ 2005-04-15 23:42 UTC (permalink / raw)


Peter Dyballa <Peter_Dyballa@Web.DE> writes:

> Am 15.04.2005 um 17:10 schrieb Denis Bueno:
> 
> > Is there a better way?
> 
> What about this?
> 
> (cond ((= 21 emacs-major-version)
>    (progn
>      (desktop-read)
>      (cond ((string= "x" window-system)

There is this notion of a symbol in List & Intelligent Symbol Processing
language.  Perhaps you read some about it...

Try: M-x info RET m elisp RET m symbols RET

>          (message "Sind in X11")
>          (load "~/.emacs_X11")
>      ))  ; Ende X11
>      (cond ((string= "mac" window-system)
>          (message "Sind in Aqua")
>          (load "~/.emacs_Carbon")
> ;        (require '.emacs_Carbon)
>      ))  ; Ende Carbon
>      (cond ((string= 'nil window-system)
>          (message "Sind im Terminal")
>          (load "~/.emacs_nil")
>      ))  ; Ende Terminal
> )));Version 21

-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

Nobody can fix the economy.  Nobody can be trusted with their finger
on the button.  Nobody's perfect.  VOTE FOR NOBODY.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to detect if Emacs is running in a terminal
  2005-04-15 16:11 ` Pascal Bourguignon
@ 2005-04-16 12:05   ` Ismael Valladolid Torres
       [not found]   ` <mailman.1726.1113653312.2895.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 10+ messages in thread
From: Ismael Valladolid Torres @ 2005-04-16 12:05 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 1621 bytes --]

Pascal Bourguignon escribe:
> Denis Bueno <dbueno@gmail.com> writes:
> 
> > Is there some emacs lisp function that I could call to detect whether
> > the current emacs process is running from within a terminal or not?
> > 
> > I'd like to be able to change my font-lock faces based on whether
> > emacs is running in a terminal or not. At the moment I deal with this
> > in the following way.
> > 
> > I have a .emacs-common which contains code that should be loaded
> > regardless of the emacs interface. My .emacs is of course loaded by
> > default whenever I run Emacs in a window (not in a terminal). This
> > contains various font settings and colors used in the windowed Emacs.
> > I have a .emacs-terminal which contains various font settings and
> > colors used in the terminal Emacs.
> > 
> > So, when I want to use Emacs in the terminal, I run:
> > 
> >     emacs -nw -q -l ~/.emacs-terminal
> > 
> > Is there a better way?
> 
> (list system-type system-name window-system)
> 
> ;; system-type          darwin   gnu/linux  cygwin
> ;; system-name          "naiad.informatimago.com" "hermes.afaa.asso.fr"
> ;; system-configuration "i686-pc-linux-gnu" "i686-pc-cygwin"
> ;; window-system        nil x mac
> ;; emacs-major-version  18 19 20 21
> ;; emacs-minor-version  0 1 2 3
> ;; emacs-version        "20.7.2" "21.2.1"
> 
> In a terminal, (null window-system)
> 

For if it's useful for you, I use clauses like these extensively in mi
.emacs:

(when (eq system-type 'gnu/linux) ...)
(when (eq system-type 'windows-nt) ...)
(when window-system ...)

Cordially, Ismael

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
Help-gnu-emacs mailing list
Help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to detect if Emacs is running in a terminal
       [not found]   ` <mailman.1726.1113653312.2895.help-gnu-emacs@gnu.org>
@ 2005-04-16 12:18     ` Stefan Monnier
  2005-04-16 14:20       ` Reiner Steib
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2005-04-16 12:18 UTC (permalink / raw)


> (when (eq system-type 'gnu/linux) ...)
> (when (eq system-type 'windows-nt) ...)
> (when window-system ...)

In 99% of the cases, people want their Emacs to behave the same on all their
machines, so the config should be the same, no matter whether it's
GNU/Linux, w32, uses window-system, ...

What can happen, tho, is that depending on the machine some things may or
may not be available.  In that case just prepend each such customization
with a little test that ensures that feature can be used.
This test will generally not look at system-type or window-system, but will
instead check (fboundp <somefunctionIwanttouse), or (file-directory-p
"somedirectoryIwanttouse"), or even place a whole subexpression inside
a (ignore-errors ...my config...).


        Stefan

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to detect if Emacs is running in a terminal
  2005-04-16 12:18     ` Stefan Monnier
@ 2005-04-16 14:20       ` Reiner Steib
  0 siblings, 0 replies; 10+ messages in thread
From: Reiner Steib @ 2005-04-16 14:20 UTC (permalink / raw)


On Sat, Apr 16 2005, Stefan Monnier wrote:

> In 99% of the cases, people want their Emacs to behave the same on all their
> machines, so the config should be the same, no matter whether it's
> GNU/Linux, w32, uses window-system, ...
>
> What can happen, tho, is that depending on the machine some things may or
> may not be available.  In that case just prepend each such customization
> with a little test that ensures that feature can be used.
> This test will generally not look at system-type or window-system, but will
> instead check (fboundp <somefunctionIwanttouse), or (file-directory-p
> "somedirectoryIwanttouse"), or even place a whole subexpression inside
> a (ignore-errors ...my config...).

It would be nice to have something like this text in (info
"(emacs)Init Examples") along with some examples.

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: How to detect if Emacs is running in a terminal
  2005-04-15 23:42   ` Pascal Bourguignon
@ 2005-04-16 15:30     ` Peter Dyballa
  0 siblings, 0 replies; 10+ messages in thread
From: Peter Dyballa @ 2005-04-16 15:30 UTC (permalink / raw)



Am 16.04.2005 um 01:42 schrieb Pascal Bourguignon:

>> (cond ((= 21 emacs-major-version)
>>    (progn
>>      (desktop-read)
>>      (cond ((string= "x" window-system)
>
> There is this notion of a symbol in List & Intelligent Symbol 
> Processing
> language.  Perhaps you read some about it...

That might have happend. I read/browsed a few times in the Elisp info 
nodes since I am European and have to struggle like Laokoon with 
charsets and encodings and other snails, and the words you use remind 
me of things I have read or heard before ... in ads?

Is it that I compare strings? `window-system´ is documented as being, a 
bit metaphorical, a symbol. The value can be an `x´, which looks like a 
very short string. So I imagined a string comparison should be OK ...

Or is it that I do not quote the symbol?

>
> Try: M-x info RET m elisp RET m symbols RET

Today I can't find the right pointer that would help my understanding 
-- I am a bit old today too and Lisp (and other programming languages) 
are hard to decipher and even harder to write for me. I think awk, sed, 
and shell are fine for programming ...

--
Greetings

   Pete

These are my principles and if you don't like them... well, I have 
others. - Groucho Marx



--
Mit friedvollen Grüßen

   Pete

When you meet a master swordsman,
show him your sword.
When you meet a man who is not a poet,
do not show him your poem.
                 -- Rinzai, ninth century Zen master

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-04-16 15:30 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.1647.1113578084.2895.help-gnu-emacs@gnu.org>
2005-04-15 15:32 ` How to detect if Emacs is running in a terminal David Kastrup
2005-04-15 15:56 ` Stefan Monnier
2005-04-15 16:11 ` Pascal Bourguignon
2005-04-16 12:05   ` Ismael Valladolid Torres
     [not found]   ` <mailman.1726.1113653312.2895.help-gnu-emacs@gnu.org>
2005-04-16 12:18     ` Stefan Monnier
2005-04-16 14:20       ` Reiner Steib
2005-04-15 15:10 Denis Bueno
2005-04-15 22:56 ` Peter Dyballa
     [not found] ` <mailman.1688.1113606088.2895.help-gnu-emacs@gnu.org>
2005-04-15 23:42   ` Pascal Bourguignon
2005-04-16 15:30     ` Peter Dyballa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).