unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Functions that need X
@ 2011-01-01 19:35 Cecil Westerhof
  2011-01-01 21:32 ` Barry Margolin
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Cecil Westerhof @ 2011-01-01 19:35 UTC (permalink / raw)
  To: help-gnu-emacs

I have a lot of functionality written for my Emacs. I was asked to
maintain a server for a friend. I installed Emacs there and put my
Emacs functionality there also. But some things are depending on X.
Because of this I made those depended working with X. In the start of
my .emacs I have:
    (defconst +using-X+ (getenv "DISPLAY"))

And where I use X-functionality (not much at the moment) I have:
    (unless (not +using-X+)
      (set-scroll-bar-mode 'right)
      (tool-bar-mode -1))

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


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

* Re: Functions that need X
  2011-01-01 19:35 Functions that need X Cecil Westerhof
@ 2011-01-01 21:32 ` Barry Margolin
  2011-01-01 21:58 ` Tim X
  2011-01-11  0:24 ` Kevin Rodgers
  2 siblings, 0 replies; 11+ messages in thread
From: Barry Margolin @ 2011-01-01 21:32 UTC (permalink / raw)
  To: help-gnu-emacs

In article <87sjxcv2ld.fsf@Compaq.site>,
 Cecil Westerhof <Cecil@decebal.nl> wrote:

> I have a lot of functionality written for my Emacs. I was asked to
> maintain a server for a friend. I installed Emacs there and put my
> Emacs functionality there also. But some things are depending on X.
> Because of this I made those depended working with X. In the start of
> my .emacs I have:
>     (defconst +using-X+ (getenv "DISPLAY"))
> 
> And where I use X-functionality (not much at the moment) I have:
>     (unless (not +using-X+)

Why use "unless + not" when you can simply use "when"?

>       (set-scroll-bar-mode 'right)
>       (tool-bar-mode -1))

The idiomatic way to do this is:

(when (eq window-system 'x) ...)

Also, these things are not dependent on X, they work with any window 
system (e.g. Mac, Windows).  So you may just want to do:

(when window-system ...)

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***


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

* Re: Functions that need X
  2011-01-01 19:35 Functions that need X Cecil Westerhof
  2011-01-01 21:32 ` Barry Margolin
@ 2011-01-01 21:58 ` Tim X
  2011-01-01 23:29   ` Barry Margolin
  2011-01-03 14:46   ` Cecil Westerhof
  2011-01-11  0:24 ` Kevin Rodgers
  2 siblings, 2 replies; 11+ messages in thread
From: Tim X @ 2011-01-01 21:58 UTC (permalink / raw)
  To: help-gnu-emacs

Cecil Westerhof <Cecil@decebal.nl> writes:

> I have a lot of functionality written for my Emacs. I was asked to
> maintain a server for a friend. I installed Emacs there and put my
> Emacs functionality there also. But some things are depending on X.
> Because of this I made those depended working with X. In the start of
> my .emacs I have:
>     (defconst +using-X+ (getenv "DISPLAY"))
>

Alternatively, just use the built-in variable window-system i.e.

(unless (eq 'x window-system)
        ....)

or even better, use one of the display capability predicates, such as

(unless (display-graphic-p)
        ...)

> And where I use X-functionality (not much at the moment) I have:
>     (unless (not +using-X+)
>       (set-scroll-bar-mode 'right)
>       (tool-bar-mode -1))

Do you actually need the above? Long time since I've used emacs in a
non-graphics mode, but when I did, you didn't get things like tool-bar
unless the display could support it.

One of the reasons I no longer use emacs in console mode is because I do
almost everything on remote systems via tramp these days and very rarely
need to run a remote emacs.

Tim



-- 
tcross (at) rapttech dot com dot au


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

* Re: Functions that need X
  2011-01-01 21:58 ` Tim X
@ 2011-01-01 23:29   ` Barry Margolin
  2011-01-02 22:46     ` Tim X
  2011-01-03  4:52     ` Stefan Monnier
  2011-01-03 14:46   ` Cecil Westerhof
  1 sibling, 2 replies; 11+ messages in thread
From: Barry Margolin @ 2011-01-01 23:29 UTC (permalink / raw)
  To: help-gnu-emacs

In article <8739pcwake.fsf@puma.rapttech.com.au>,
 Tim X <timx@nospam.dev.null> wrote:

> Cecil Westerhof <Cecil@decebal.nl> writes:
> 
> > I have a lot of functionality written for my Emacs. I was asked to
> > maintain a server for a friend. I installed Emacs there and put my
> > Emacs functionality there also. But some things are depending on X.
> > Because of this I made those depended working with X. In the start of
> > my .emacs I have:
> >     (defconst +using-X+ (getenv "DISPLAY"))
> >
> 
> Alternatively, just use the built-in variable window-system i.e.
> 
> (unless (eq 'x window-system)
>         ....)
> 
> or even better, use one of the display capability predicates, such as
> 
> (unless (display-graphic-p)
>         ...)
> 
> > And where I use X-functionality (not much at the moment) I have:
> >     (unless (not +using-X+)
> >       (set-scroll-bar-mode 'right)
> >       (tool-bar-mode -1))
> 
> Do you actually need the above? Long time since I've used emacs in a
> non-graphics mode, but when I did, you didn't get things like tool-bar
> unless the display could support it.

The reason is that if the display doesn't support it these functions 
aren't even defined, so you get an error when you try to turn off the 
nonexistent tool bar.

It probably would be better if there were stub versions of all these 
functions in console Emacs, so that they would just be ignored.  But 
since there aren't, you need to check first.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***


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

* Re: Functions that need X
  2011-01-01 23:29   ` Barry Margolin
@ 2011-01-02 22:46     ` Tim X
  2011-01-03 14:34       ` Cecil Westerhof
  2011-01-03  4:52     ` Stefan Monnier
  1 sibling, 1 reply; 11+ messages in thread
From: Tim X @ 2011-01-02 22:46 UTC (permalink / raw)
  To: help-gnu-emacs

Barry Margolin <barmar@alum.mit.edu> writes:

> In article <8739pcwake.fsf@puma.rapttech.com.au>,
>  Tim X <timx@nospam.dev.null> wrote:
>
>> Cecil Westerhof <Cecil@decebal.nl> writes:
>> 
>> > I have a lot of functionality written for my Emacs. I was asked to
>> > maintain a server for a friend. I installed Emacs there and put my
>> > Emacs functionality there also. But some things are depending on X.
>> > Because of this I made those depended working with X. In the start of
>> > my .emacs I have:
>> >     (defconst +using-X+ (getenv "DISPLAY"))
>> >
>> 
>> Alternatively, just use the built-in variable window-system i.e.
>> 
>> (unless (eq 'x window-system)
>>         ....)
>> 
>> or even better, use one of the display capability predicates, such as
>> 
>> (unless (display-graphic-p)
>>         ...)
>> 
>> > And where I use X-functionality (not much at the moment) I have:
>> >     (unless (not +using-X+)
>> >       (set-scroll-bar-mode 'right)
>> >       (tool-bar-mode -1))
>> 
>> Do you actually need the above? Long time since I've used emacs in a
>> non-graphics mode, but when I did, you didn't get things like tool-bar
>> unless the display could support it.
>
> The reason is that if the display doesn't support it these functions 
> aren't even defined, so you get an error when you try to turn off the 
> nonexistent tool bar.

Actually, in emacs 24.0.50, you can call tool-bar-mode with no problems
from the console - it doesn't appear to do anything if the display
cannot handle tool-bars.

You are correct, set-scroll-bar-mode does not exist under the console. I
also find the documentation for that command a bit weak i.e. 

,----[ C-h f set-scroll-bar-mode RET ]
| set-scroll-bar-mode is a compiled Lisp function in `scroll-bar.el'.
| 
| (set-scroll-bar-mode VALUE)
| 
| Set `scroll-bar-mode' to VALUE and put the new value into effect.
`----

Documentation of that type reminds me of code comments you see like

              x := 3;      // set x to 3

100% accurate and 100% useless!

I think this one deserves a bug report. The documentation should at
least give some indication on what the allowed values for 'VALUE' are
and what they would do. 

>
> It probably would be better if there were stub versions of all these 
> functions in console Emacs, so that they would just be ignored.  But 
> since there aren't, you need to check first.

I'd not noticed this before as I use Xresources to disable much of this
sort of thing in my .emacs, but I think your correct and a stub for this
under non-scrolling environments whould be useful. I suspect the
reason it doesn't happen is to avoid namespace pollution and loading of
unnecessary packages (thinking that any stub would likely be part of
scroll-bar.el and without careful or considerable re-engineering, may be
difficul to only load sufficient code to just handle that endge case
without also loading lots of other unnecessary stuff - not a reason not
todo it, but possibly explains why it has not been done). 

I suspect this is also one of those situations where custom has an
advantage over hand crafted code in .emacs i.e. disabling scroll bars
using custom does not cause errors when run under the console. 

I think I'll log a bug report for set-scroll-bar-mode. If it is a
consistent mode and follows the norms for +/- 1 or nil etc, it should
jus say that. 

Tim


-- 
tcross (at) rapttech dot com dot au


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

* Re: Functions that need X
  2011-01-01 23:29   ` Barry Margolin
  2011-01-02 22:46     ` Tim X
@ 2011-01-03  4:52     ` Stefan Monnier
  2011-01-03  5:45       ` Tim X
  1 sibling, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2011-01-03  4:52 UTC (permalink / raw)
  To: help-gnu-emacs

> It probably would be better if there were stub versions of all these
> functions in console Emacs, so that they would just be ignored.  But
> since there aren't, you need to check first.

The general rule I'd like to follow (tho Emacs doesn't follow it yet) is
that a function that is not specific to one particular kind of display
(tty, X11, w32, you name it) should always be defined.

So if/when you bump into such a function that's only defined when used
(or compiled) with a GUI, please report it as a bug.


        Stefan


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

* Re: Functions that need X
  2011-01-03  4:52     ` Stefan Monnier
@ 2011-01-03  5:45       ` Tim X
  0 siblings, 0 replies; 11+ messages in thread
From: Tim X @ 2011-01-03  5:45 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> It probably would be better if there were stub versions of all these
>> functions in console Emacs, so that they would just be ignored.  But
>> since there aren't, you need to check first.
>
> The general rule I'd like to follow (tho Emacs doesn't follow it yet) is
> that a function that is not specific to one particular kind of display
> (tty, X11, w32, you name it) should always be defined.
>
> So if/when you bump into such a function that's only defined when used
> (or compiled) with a GUI, please report it as a bug.
>
>
OK, will do so for set-scroll-bar-mode

Tim


-- 
tcross (at) rapttech dot com dot au


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

* Re: Functions that need X
  2011-01-02 22:46     ` Tim X
@ 2011-01-03 14:34       ` Cecil Westerhof
  2011-01-03 15:55         ` Drew Adams
  0 siblings, 1 reply; 11+ messages in thread
From: Cecil Westerhof @ 2011-01-03 14:34 UTC (permalink / raw)
  To: help-gnu-emacs

Op zondag 2 jan 2011 23:46 CET schreef Tim X.:

> I suspect this is also one of those situations where custom has an
> advantage over hand crafted code in .emacs i.e. disabling scroll bars
> using custom does not cause errors when run under the console.

Not in my case. I have a generic file, which I distribute on many
computers. I would not like to do the custom bit on all of them.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


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

* Re: Functions that need X
  2011-01-01 21:58 ` Tim X
  2011-01-01 23:29   ` Barry Margolin
@ 2011-01-03 14:46   ` Cecil Westerhof
  1 sibling, 0 replies; 11+ messages in thread
From: Cecil Westerhof @ 2011-01-03 14:46 UTC (permalink / raw)
  To: help-gnu-emacs

Op zaterdag 1 jan 2011 22:58 CET schreef Tim X.:

>> I have a lot of functionality written for my Emacs. I was asked to
>> maintain a server for a friend. I installed Emacs there and put my
>> Emacs functionality there also. But some things are depending on X.
>> Because of this I made those depended working with X. In the start of
>> my .emacs I have:
>> (defconst +using-X+ (getenv "DISPLAY"))
>>
>
> Alternatively, just use the built-in variable window-system i.e.
>
> (unless (eq 'x window-system)
> ....)
>
> or even better, use one of the display capability predicates, such as
>
> (unless (display-graphic-p)
> ...)

I did not know this. Combining with another tip the code now has
become:
    (when (display-graphic-p)
      (set-scroll-bar-mode 'right)
      (tool-bar-mode -1))

> One of the reasons I no longer use emacs in console mode is because I do
> almost everything on remote systems via tramp these days and very rarely
> need to run a remote emacs.

I work with screen and emacs on this system. The problem is that
sometimes the connection goes away. And if this happens my emacs will
hang. With screen I just can continue where I left of after the
connection is restored.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


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

* RE: Functions that need X
  2011-01-03 14:34       ` Cecil Westerhof
@ 2011-01-03 15:55         ` Drew Adams
  0 siblings, 0 replies; 11+ messages in thread
From: Drew Adams @ 2011-01-03 15:55 UTC (permalink / raw)
  To: 'Cecil Westerhof', help-gnu-emacs

> > I suspect this is also one of those situations where custom has an
> > advantage over hand crafted code in .emacs i.e. disabling 
> > scroll bars using custom does not cause errors when run under the console.
> 
> Not in my case. I have a generic file, which I distribute on many
> computers. I would not like to do the custom bit on all of them.

I can't speak directly to your particular situation, no doubt, but in general
you can create once and then distribute the same `custom-file' or just part of
it (e.g. `custom-set-variables'), not necessarily assigning it as the value of
any given user's `custom-file' var.

IOW, Customize just creates Lisp code for you to load (or not).




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

* Re: Functions that need X
  2011-01-01 19:35 Functions that need X Cecil Westerhof
  2011-01-01 21:32 ` Barry Margolin
  2011-01-01 21:58 ` Tim X
@ 2011-01-11  0:24 ` Kevin Rodgers
  2 siblings, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2011-01-11  0:24 UTC (permalink / raw)
  To: help-gnu-emacs

On 1/1/11 12:35 PM, Cecil Westerhof wrote:
> I have a lot of functionality written for my Emacs. I was asked to
> maintain a server for a friend. I installed Emacs there and put my
> Emacs functionality there also. But some things are depending on X.
> Because of this I made those depended working with X. In the start of
> my .emacs I have:
>      (defconst +using-X+ (getenv "DISPLAY"))
>
> And where I use X-functionality (not much at the moment) I have:
>      (unless (not +using-X+)
>        (set-scroll-bar-mode 'right)
>        (tool-bar-mode -1))

(when (eq window-system 'x)
    ...)

or probably just

(when window-system
    ...)

-- 
Kevin Rodgers
Denver, Colorado, USA




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

end of thread, other threads:[~2011-01-11  0:24 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-01 19:35 Functions that need X Cecil Westerhof
2011-01-01 21:32 ` Barry Margolin
2011-01-01 21:58 ` Tim X
2011-01-01 23:29   ` Barry Margolin
2011-01-02 22:46     ` Tim X
2011-01-03 14:34       ` Cecil Westerhof
2011-01-03 15:55         ` Drew Adams
2011-01-03  4:52     ` Stefan Monnier
2011-01-03  5:45       ` Tim X
2011-01-03 14:46   ` Cecil Westerhof
2011-01-11  0:24 ` Kevin Rodgers

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).