* System operating detection
@ 2010-08-11 9:06 Andrea Crotti
2010-08-11 9:22 ` Richard Riley
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Andrea Crotti @ 2010-08-11 9:06 UTC (permalink / raw)
To: help-gnu-emacs
Is there a way to make this ugly thing:
--8<---------------cut here---------------start------------->8---
(defconst sysop
(cond
((string-match "linux" system-configuration) "linux")
((string-match "apple" system-configuration) "mac")
((string-match "win" system-configuration) "win")
(t "other")))
(defconst linux (string= "linux" sysop))
(defconst mac (string= "mac" sysop))
(defconst win (string= "win" sysop))
(defconst other (string= "other" sysop))
--8<---------------cut here---------------end--------------->8---
looking better?
I would like to have all the constants defined (to nil or t) but
avoiding this ugly repetition.
One (small) problem is that without the "cond" also "darwin" matches
"win", so I get a wrong constant...
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System operating detection
2010-08-11 9:06 System operating detection Andrea Crotti
@ 2010-08-11 9:22 ` Richard Riley
2010-08-11 10:19 ` Andrea Crotti
2010-08-11 11:58 ` Thierry Volpiatto
2010-08-16 21:53 ` Oleksandr Gavenko
2 siblings, 1 reply; 8+ messages in thread
From: Richard Riley @ 2010-08-11 9:22 UTC (permalink / raw)
To: help-gnu-emacs
Andrea Crotti <andrea.crotti.0@gmail.com> writes:
> Is there a way to make this ugly thing:
>
>
>
>
> --8<---------------cut here---------------start------------->8---
> (defconst sysop
> (cond
> ((string-match "linux" system-configuration) "linux")
> ((string-match "apple" system-configuration) "mac")
> ((string-match "win" system-configuration) "win")
> (t "other")))
>
> (defconst linux (string= "linux" sysop))
> (defconst mac (string= "mac" sysop))
> (defconst win (string= "win" sysop))
> (defconst other (string= "other" sysop))
> --8<---------------cut here---------------end--------------->8---
>
>
>
> looking better?
> I would like to have all the constants defined (to nil or t) but
> avoiding this ugly repetition.
> One (small) problem is that without the "cond" also "darwin" matches
> "win", so I get a wrong constant...
I think you need to show your usage patterns for the variables you have
defined for a better answer. How are you using the results?
That said, maybe just define sysop and then load-library a filename stub
concat'ed with the sysop along the lines of
(load-library (concat "os-specific-" sysop))
is a better approach? And then os-specific-win etc all contain their OS
specific details.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System operating detection
2010-08-11 9:22 ` Richard Riley
@ 2010-08-11 10:19 ` Andrea Crotti
0 siblings, 0 replies; 8+ messages in thread
From: Andrea Crotti @ 2010-08-11 10:19 UTC (permalink / raw)
To: help-gnu-emacs
Richard Riley <rileyrg@gmail.com> writes:
>
> I think you need to show your usage patterns for the variables you have
> defined for a better answer. How are you using the results?
>
> That said, maybe just define sysop and then load-library a filename stub
> concat'ed with the sysop along the lines of
>
> (load-library (concat "os-specific-" sysop))
>
> is a better approach? And then os-specific-win etc all contain their OS
> specific details.
Well actually I only have some
--8<---------------cut here---------------start------------->8---
(when mac
(do something))
(when linux
(do something else))
--8<---------------cut here---------------end--------------->8---
A library with the os-specific stuff might be better, but now I have
everything in the org-file divided by "chapter" (windows, buffers,
frames etc). Doing "system" libraries like that would break a little bit
this model.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System operating detection
2010-08-11 9:06 System operating detection Andrea Crotti
2010-08-11 9:22 ` Richard Riley
@ 2010-08-11 11:58 ` Thierry Volpiatto
2010-08-11 12:58 ` Andrea Crotti
[not found] ` <mailman.1.1281531533.2853.help-gnu-emacs@gnu.org>
2010-08-16 21:53 ` Oleksandr Gavenko
2 siblings, 2 replies; 8+ messages in thread
From: Thierry Volpiatto @ 2010-08-11 11:58 UTC (permalink / raw)
To: help-gnu-emacs
Andrea Crotti <andrea.crotti.0@gmail.com> writes:
> Is there a way to make this ugly thing:
>
> (defconst sysop
> (cond
> ((string-match "linux" system-configuration) "linux")
> ((string-match "apple" system-configuration) "mac")
> ((string-match "win" system-configuration) "win")
> (t "other")))
>
> (defconst linux (string= "linux" sysop))
> (defconst mac (string= "mac" sysop))
> (defconst win (string= "win" sysop))
> (defconst other (string= "other" sysop))
>
> looking better?
> I would like to have all the constants defined (to nil or t) but
> avoiding this ugly repetition.
> One (small) problem is that without the "cond" also "darwin" matches
> "win", so I get a wrong constant...
Use case:
,----
| (case system-type
| (gnu/linux "Linux")
| (window-nt "windows")
| (darwin "mac")
| (t "other")
`----
>
>
--
Thierry Volpiatto
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System operating detection
2010-08-11 11:58 ` Thierry Volpiatto
@ 2010-08-11 12:58 ` Andrea Crotti
[not found] ` <mailman.1.1281531533.2853.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 8+ messages in thread
From: Andrea Crotti @ 2010-08-11 12:58 UTC (permalink / raw)
To: help-gnu-emacs
Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
> Andrea Crotti <andrea.crotti.0@gmail.com> writes:
>
> Use case:
>
> ,----
> | (case system-type
> | (gnu/linux "Linux")
> | (window-nt "windows")
> | (darwin "mac")
> | (t "other")
> `----
>
>
>
>>
>>
Ah great I didn't know this, so now is
--8<---------------cut here---------------start------------->8---
(defconst linux nil)
(defconst mac nil)
(defconst win nil)
(defconst other nil)
(case system-type
(gnu/linux (setq linux t))
(window-nt (setq mac t))
(darwin (setq win t))
(t (setq other t)))
--8<---------------cut here---------------end--------------->8---
But maybe could be even better, what if I create the symbol only if
really needed?
Then I could do
--8<---------------cut here---------------start------------->8---
(if (boundp linux)...
--8<---------------cut here---------------end--------------->8---
which probably becomes even longer.
Isn't there a way to automatically define functions or variables?
^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <mailman.1.1281531533.2853.help-gnu-emacs@gnu.org>]
* Re: System operating detection
[not found] ` <mailman.1.1281531533.2853.help-gnu-emacs@gnu.org>
@ 2010-08-11 14:27 ` Pascal J. Bourguignon
0 siblings, 0 replies; 8+ messages in thread
From: Pascal J. Bourguignon @ 2010-08-11 14:27 UTC (permalink / raw)
To: help-gnu-emacs
Andrea Crotti <andrea.crotti.0@gmail.com> writes:
> Thierry Volpiatto <thierry.volpiatto@gmail.com> writes:
>
>> Andrea Crotti <andrea.crotti.0@gmail.com> writes:
>>
>> Use case:
>>
>> ,----
>> | (case system-type
>> | (gnu/linux "Linux")
>> | (window-nt "windows")
>> | (darwin "mac")
>> | (t "other")
>> `----
>>
>>
>>
>>>
>>>
>
> Ah great I didn't know this, so now is
> --8<---------------cut here---------------start------------->8---
> (defconst linux nil)
> (defconst mac nil)
> (defconst win nil)
> (defconst other nil)
>
> (case system-type
> (gnu/linux (setq linux t))
> (window-nt (setq mac t))
> (darwin (setq win t))
> (t (setq other t)))
> --8<---------------cut here---------------end--------------->8---
>
> But maybe could be even better, what if I create the symbol only if
> really needed?
>
> Then I could do
> --8<---------------cut here---------------start------------->8---
> (if (boundp linux)...
> --8<---------------cut here---------------end--------------->8---
> which probably becomes even longer.
> Isn't there a way to automatically define functions or variables?
What if you write simply:
(when (eq system-type 'gnu/linux)
...)
?
or, if you have several cases:
(case system-type
((gnu/linux) (do-something-on-linux))
((mac) (do-something-on-mac))
(otherwise (do-something-standard)))
?
--
__Pascal Bourguignon__ http://www.informatimago.com/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: System operating detection
2010-08-11 9:06 System operating detection Andrea Crotti
2010-08-11 9:22 ` Richard Riley
2010-08-11 11:58 ` Thierry Volpiatto
@ 2010-08-16 21:53 ` Oleksandr Gavenko
2 siblings, 0 replies; 8+ messages in thread
From: Oleksandr Gavenko @ 2010-08-16 21:53 UTC (permalink / raw)
To: help-gnu-emacs
On 2010-08-11 12:06, Andrea Crotti wrote:
> Is there a way to make this ugly thing:
>
> --8<---------------cut here---------------start------------->8---
> (defconst sysop
> (cond
> ((string-match "linux" system-configuration) "linux")
> ((string-match "apple" system-configuration) "mac")
> ((string-match "win" system-configuration) "win")
> (t "other")))
>
> (defconst linux (string= "linux" sysop))
> (defconst mac (string= "mac" sysop))
> (defconst win (string= "win" sysop))
> (defconst other (string= "other" sysop))
> --8<---------------cut here---------------end--------------->8---
>
> looking better?
> I would like to have all the constants defined (to nil or t) but
> avoiding this ugly repetition.
> One (small) problem is that without the "cond" also "darwin" matches
> "win", so I get a wrong constant...
>
I wrote blog article about useful checks in .emacs:
http://brain-break.blogspot.com/2010/08/determining-running-environment-and.html
---
Best regards!
^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <mailman.3.1281517588.2982.help-gnu-emacs@gnu.org>]
* Re: System operating detection
[not found] <mailman.3.1281517588.2982.help-gnu-emacs@gnu.org>
@ 2010-08-11 11:13 ` TheFlyingDutchman
0 siblings, 0 replies; 8+ messages in thread
From: TheFlyingDutchman @ 2010-08-11 11:13 UTC (permalink / raw)
To: help-gnu-emacs
On Aug 11, 2:06 am, Andrea Crotti <andrea.crott...@gmail.com> wrote:
> Is there a way to make this ugly thing:
>
> --8<---------------cut here---------------start------------->8---
> (defconst sysop
> (cond
> ((string-match "linux" system-configuration) "linux")
> ((string-match "apple" system-configuration) "mac")
> ((string-match "win" system-configuration) "win")
I am using Windows 7 Home Premium and (from Help->About Emacs) "GNU
Emacs 23.2.1 (i386-mingw-nt6.1.7600) of 2010-05-08 on G41R2F1", and
the value for system-configuration is "i386-mingw-nt6.1.7600". I guess
they have changed the format of system-configuration for Windows?? For
system-type I have "windows-nt". Maybe sytem-type is a better
variable to check??
> (t "other")))
>
> (defconst linux (string= "linux" sysop))
> (defconst mac (string= "mac" sysop))
> (defconst win (string= "win" sysop))
> (defconst other (string= "other" sysop))
> --8<---------------cut here---------------end--------------->8---
>
> looking better?
> I would like to have all the constants defined (to nil or t) but
> avoiding this ugly repetition.
> One (small) problem is that without the "cond" also "darwin" matches
> "win", so I get a wrong constant...
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2010-08-16 21:53 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-11 9:06 System operating detection Andrea Crotti
2010-08-11 9:22 ` Richard Riley
2010-08-11 10:19 ` Andrea Crotti
2010-08-11 11:58 ` Thierry Volpiatto
2010-08-11 12:58 ` Andrea Crotti
[not found] ` <mailman.1.1281531533.2853.help-gnu-emacs@gnu.org>
2010-08-11 14:27 ` Pascal J. Bourguignon
2010-08-16 21:53 ` Oleksandr Gavenko
[not found] <mailman.3.1281517588.2982.help-gnu-emacs@gnu.org>
2010-08-11 11:13 ` TheFlyingDutchman
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).