unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Using the same custom file in two different OSes
@ 2013-01-13 22:00 Dani Moncayo
  2013-01-13 22:18 ` Drew Adams
  2013-01-15 13:27 ` Stefan Monnier
  0 siblings, 2 replies; 28+ messages in thread
From: Dani Moncayo @ 2013-01-13 22:00 UTC (permalink / raw)
  To: help-gnu-emacs

Hi folks,

I'd like to use the same Emacs custom file in two different OSes:
MS-Windows and Ubuntu, but I have one problem: I want to define the
:family property of the `default' and `variable-pitch' faces based on
the `system-type' (because my favorite family on MS-Windows isn't
available on Ubuntu and vice-versa), but without having to duplicate
my custom file (one for each system-type), so that I can tweak my
customization at any time, in any OS, and get an updated custom file
that is still valid for both OSes.

Is there a way to achieve that goal?  If so, how?

TIA.

-- 
Dani Moncayo



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

* RE: Using the same custom file in two different OSes
  2013-01-13 22:00 Using the same custom file in two different OSes Dani Moncayo
@ 2013-01-13 22:18 ` Drew Adams
  2013-01-14 18:46   ` Dani Moncayo
  2013-01-15 13:27 ` Stefan Monnier
  1 sibling, 1 reply; 28+ messages in thread
From: Drew Adams @ 2013-01-13 22:18 UTC (permalink / raw)
  To: 'Dani Moncayo', help-gnu-emacs

> I'd like to use the same Emacs custom file in two different OSes:
> MS-Windows and Ubuntu, but I have one problem: I want to define the
> :family property of the `default' and `variable-pitch' faces based on
> the `system-type' (because my favorite family on MS-Windows isn't
> available on Ubuntu and vice-versa), but without having to duplicate
> my custom file (one for each system-type), so that I can tweak my
> customization at any time, in any OS, and get an updated custom file
> that is still valid for both OSes.
> 
> Is there a way to achieve that goal?  If so, how?

With a single `custom-file', using Customize, no, I don't think so.

But you can do it using Lisp, in your init file (~/.emacs).  (Use a separate
`custom-file' for the stuff that Customize manages.  Keep your init file for
Lisp that you manage.)

Try first using Customize on each of the platforms separately, to see what
values it gives you for those faces, for the automatically generated
`custom-set-faces' sexp.

Then remove the settings for those exceptional faces from `custom-file', moving
them to your init file instead and wrapping them with (custom-set-faces ...):

(if (eq system-type 'windows-nt)
    (custom-set-faces ...)
  (custom-set-faces ...))




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

* Re: Using the same custom file in two different OSes
  2013-01-13 22:18 ` Drew Adams
@ 2013-01-14 18:46   ` Dani Moncayo
  2013-01-14 19:13     ` Drew Adams
  0 siblings, 1 reply; 28+ messages in thread
From: Dani Moncayo @ 2013-01-14 18:46 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs

> But you can do it using Lisp, in your init file (~/.emacs).  (Use a separate
> `custom-file' for the stuff that Customize manages.  Keep your init file for
> Lisp that you manage.)

Yes, that's how I have it.

> Try first using Customize on each of the platforms separately, to see what
> values it gives you for those faces, for the automatically generated
> `custom-set-faces' sexp.
>
> Then remove the settings for those exceptional faces from `custom-file', moving
> them to your init file instead and wrapping them with (custom-set-faces ...):
>
> (if (eq system-type 'windows-nt)
>     (custom-set-faces ...)
>   (custom-set-faces ...))

That works, but I've observed that each time I save any customization,
my custom file is regenerated with _all_ the customization loaded at
that time, and the platform-specific stuff that I removed from my
custom file is then reinserted.  Therefore, in my init file I must put
the platform-specific customization _after_ the loading of the custom
file:

  (setq custom-file "my-custom-file.el")
  (load custom-file)
  (if (eq system-type 'windows-nt)
      (custom-set-faces <windows-specific stuff>)
    (custom-set-faces <ubuntu-specific stuff>)

Thank you so much for your help.

-- 
Dani Moncayo



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

* RE: Using the same custom file in two different OSes
  2013-01-14 18:46   ` Dani Moncayo
@ 2013-01-14 19:13     ` Drew Adams
  2013-01-14 19:42       ` Dani Moncayo
  0 siblings, 1 reply; 28+ messages in thread
From: Drew Adams @ 2013-01-14 19:13 UTC (permalink / raw)
  To: 'Dani Moncayo'; +Cc: help-gnu-emacs

> That works, but I've observed that each time I save any customization,
> my custom file is regenerated with _all_ the customization loaded at
> that time, and the platform-specific stuff that I removed from my
> custom file is then reinserted.

That should not happen.  If that is the case then it is likely because your
custom file was restored to its original state after the session where you
modified it.  Try modifying it in a separate session - even an emacs -Q session.

Check your custom file after you have quit the Emacs session where you modified
it.  You need to have it be as you wanted it: without the stuff you removed.

You might need to fiddle a bit, to ensure that.  Once that is the case, the
stuff you removed will never be added again. 

> Therefore, in my init file I must put the platform-specific customization
> _after_ the loading of the custom file:
> 
>   (setq custom-file "my-custom-file.el")
>   (load custom-file)
>   (if (eq system-type 'windows-nt)
>       (custom-set-faces <windows-specific stuff>)
>     (custom-set-faces <ubuntu-specific stuff>)

That's OK, but you should not need that workaround.  See above.

> Thank you so much for your help.

You're welcome.  Keeping Customize stuff relegated to a separate file
(`custom-file') is something that I think everyone should consider doing.  It's
asking for trouble to mix code that you write with code that is automatically
written by Customize.

After separating out the Customize stuff, the question arises as when to load
`custom-file' in one's init file.  Often it is appropriate to load it at or near
the end, but it really depends on the libraries that your init file loads.

For instance, I load Icicles at the very end, just after loading `custom-file',
so that Icicles picks up certain option values and current key definitions.




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

* Re: Using the same custom file in two different OSes
  2013-01-14 19:13     ` Drew Adams
@ 2013-01-14 19:42       ` Dani Moncayo
  2013-01-14 21:55         ` Peter Dyballa
  2013-01-14 22:05         ` Drew Adams
  0 siblings, 2 replies; 28+ messages in thread
From: Dani Moncayo @ 2013-01-14 19:42 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs

>> That works, but I've observed that each time I save any customization,
>> my custom file is regenerated with _all_ the customization loaded at
>> that time, and the platform-specific stuff that I removed from my
>> custom file is then reinserted.
>
> That should not happen.  If that is the case then it is likely because your
> custom file was restored to its original state after the session where you
> modified it.  Try modifying it in a separate session - even an emacs -Q session.
>
> Check your custom file after you have quit the Emacs session where you modified
> it.  You need to have it be as you wanted it: without the stuff you removed.
>
> You might need to fiddle a bit, to ensure that.  Once that is the case, the
> stuff you removed will never be added again.

Mmmm I'm afraid I'm unable to keep my custom file free of my
platform-specific stuff. I've just seen this behavior:
1. I remove the `default' and `variable-pitch' lines from my custom file.
2. I exit Emacs, start it again and verify that my custom file doesn't
have the lines I removed.  Note that this session has loaded my init
file, which first loads my custom file and then makes the
platform-specific customization (in that order).
3. I do some customization (change the box-width property of the
`mode-line' face, for example), and save it (C-x C-s).
4. I reopen my custom file and see that the two lines I removed in #1
have been reinserted.

Changing the order (first do the platform-specific customization and
the load the custom file) doesn't help.  The custom file is
regenerated (when I save any customization) entirely, including the
`default' and `variable-pitch' faces.

-- 
Dani Moncayo



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

* Re: Using the same custom file in two different OSes
  2013-01-14 19:42       ` Dani Moncayo
@ 2013-01-14 21:55         ` Peter Dyballa
  2013-01-14 23:00           ` Dani Moncayo
  2013-01-14 22:05         ` Drew Adams
  1 sibling, 1 reply; 28+ messages in thread
From: Peter Dyballa @ 2013-01-14 21:55 UTC (permalink / raw)
  To: Dani Moncayo; +Cc: help-gnu-emacs@gnu.org list


Am 14.01.2013 um 20:42 schrieb Dani Moncayo:

> Mmmm I'm afraid I'm unable to keep my custom file free of my
> platform-specific stuff.

See whether custom-file (a variable) can do something for you!

One thing is sure: the custom-set-variables and custom-set-faces can only exist once. For GNU Emacs (not the file system). So I have one single body which then loads via (load custom-file) the customisations for different GNU Emacs versions. They have names à la ~/.emacs-Abrichtung-<emacs version>.el – but it could be OS specific as well.

Practical hint: move all your customisation in one version of custom-file. Copy this file to the other variants. Then edit these variants on the specific platforms via GNU Emacs' customisation interface!

--
Greetings

  Pete

There's no place like 127.0.0.1
			– origin unknown




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

* RE: Using the same custom file in two different OSes
  2013-01-14 19:42       ` Dani Moncayo
  2013-01-14 21:55         ` Peter Dyballa
@ 2013-01-14 22:05         ` Drew Adams
  2013-01-16 21:03           ` Dani Moncayo
       [not found]           ` <mailman.17633.1358371586.855.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 28+ messages in thread
From: Drew Adams @ 2013-01-14 22:05 UTC (permalink / raw)
  To: 'Dani Moncayo'; +Cc: help-gnu-emacs

> Mmmm I'm afraid I'm unable to keep my custom file free of my
> platform-specific stuff. I've just seen this behavior:
> 1. I remove the `default' and `variable-pitch' lines from my 
> custom file.
> 2. I exit Emacs, start it again and verify that my custom file doesn't
> have the lines I removed.  Note that this session has loaded my init
> file, which first loads my custom file and then makes the
> platform-specific customization (in that order).
> 3. I do some customization (change the box-width property of the
> `mode-line' face, for example), and save it (C-x C-s).
> 4. I reopen my custom file and see that the two lines I removed in #1
> have been reinserted.
> 
> Changing the order (first do the platform-specific customization and
> the load the custom file) doesn't help.  The custom file is
> regenerated (when I save any customization) entirely, including the
> `default' and `variable-pitch' faces.

Right.

It's because your init file changes the faces but does not save those changes or
cancel them.  Then, when you save changes with C-x C-s, that saves the faces you
changed.

You want to either (a) do what you do now: redefine the faces after loading your
`custom-file' each time or (b) just tell Customize that the faces have _not_
been changed (even though they have), before hitting C-x C-s.  That is, just
tell Customize to ignore your changes.

For that, you can just add those faces to option `customize-customized-ignore'
(user preferences to ignore in `customize-customized').  For that you will need
to load library cus-edit+.el.
http://www.emacswiki.org/emacs-en/download/cus-edit%2b.el

If you do not want to do that, then you can use code like this in your init
file, just after setting the faces the way you want:

(face-spec-set THE-FACE (get THE-FACE 'face-defface-spec) 'reset)

That should work.  This should also do the trick, as an alternative:

(put THE-FACE 'saved-face nil)
(put THE-FACE 'saved-face-comment nil)
(put THE-FACE 'face-comment nil)
(put THE-FACE 'customized-face-comment nil)

Here's another tip: Get in the habit of using the `State' menu for the
particular option or face that you've changed, to save its changes, instead of
using C-x C-s, which saves all changes.

If you are worried about not catching some unsaved changes, you can use `M-x
customize-unsaved' before you quit Emacs.  You can even put that on
`kill-emacs-query-functions':

(add-hook 'kill-emacs-query-functions
          (lambda () (ignore-errors (customize-unsaved))))

Then, when you exit Emacs, if you have any unsaved changes, Customize will open
to them, so you can decide whether you want to save them.  Any faces or options
listed in option `customize-customized-ignore' (cus-edit+.el) are ignored for
this - any changes to them are silently ignored.

See also: http://emacswiki.org/CustomizingAndSaving

HTH.




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

* Re: Using the same custom file in two different OSes
  2013-01-14 21:55         ` Peter Dyballa
@ 2013-01-14 23:00           ` Dani Moncayo
  2013-01-15  8:25             ` Didier Verna
  0 siblings, 1 reply; 28+ messages in thread
From: Dani Moncayo @ 2013-01-14 23:00 UTC (permalink / raw)
  To: Peter Dyballa; +Cc: help-gnu-emacs@gnu.org list

>> Mmmm I'm afraid I'm unable to keep my custom file free of my
>> platform-specific stuff.
>
> See whether custom-file (a variable) can do something for you!
>
> One thing is sure: the custom-set-variables and custom-set-faces can only exist once. For GNU Emacs (not the file system). So I have one single body which then loads via (load custom-file) the customisations for different GNU Emacs versions. They have names à la ~/.emacs-Abrichtung-<emacs version>.el – but it could be OS specific as well.
>
> Practical hint: move all your customisation in one version of custom-file. Copy this file to the other variants. Then edit these variants on the specific platforms via GNU Emacs' customisation interface!

Thanks, that would be one possible solution, but as I said in the
initial post, I don't want to have redundancy (i.e. several custom
files), because I want to be able to tweak some customization in one
machine/OS and have the resulting customization automatically applied
to the other machine/OS.

-- 
Dani Moncayo



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

* Re: Using the same custom file in two different OSes
  2013-01-14 23:00           ` Dani Moncayo
@ 2013-01-15  8:25             ` Didier Verna
  2013-01-15  8:42               ` Dani Moncayo
  0 siblings, 1 reply; 28+ messages in thread
From: Didier Verna @ 2013-01-15  8:25 UTC (permalink / raw)
  To: Dani Moncayo; +Cc: help-gnu-emacs@gnu.org list

Dani Moncayo <dmoncayo@gmail.com> wrote:

> Thanks, that would be one possible solution, but as I said in the
> initial post, I don't want to have redundancy (i.e. several custom
> files), because I want to be able to tweak some customization in one
> machine/OS and have the resulting customization automatically applied
> to the other machine/OS.

  FWIW, I do this, not for Custom only but for my whole account
  configuration with Git. I have the trunk set for general Unix state
  and an osx branch with some Mac specific modifications /
  additions. Having "the resulting customization automatically applied
  to the other machine/OS" then boils down to merging.

-- 
ELS 2013, June 3/4, Madrid, Spain:  http://els2013.european-lisp-symposium.org

Scientific site:   http://www.lrde.epita.fr/~didier
Music (Jazz) site: http://www.didierverna.com



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

* Re: Using the same custom file in two different OSes
  2013-01-15  8:25             ` Didier Verna
@ 2013-01-15  8:42               ` Dani Moncayo
  0 siblings, 0 replies; 28+ messages in thread
From: Dani Moncayo @ 2013-01-15  8:42 UTC (permalink / raw)
  To: Didier Verna; +Cc: help-gnu-emacs@gnu.org list

>> Thanks, that would be one possible solution, but as I said in the
>> initial post, I don't want to have redundancy (i.e. several custom
>> files), because I want to be able to tweak some customization in one
>> machine/OS and have the resulting customization automatically applied
>> to the other machine/OS.
>
>   FWIW, I do this, not for Custom only but for my whole account
>   configuration with Git. I have the trunk set for general Unix state
>   and an osx branch with some Mac specific modifications /
>   additions. Having "the resulting customization automatically applied
>   to the other machine/OS" then boils down to merging.

Thanks, that's another possibility, indeed.

The downside I see is that it requires another tool (git or another DVCS).

Currently, I can work with single init and custom files, and share
them between machines/OSes via Dropbox.  For now that mechanism is
simple and works for me.

Thanks for the advice.

-- 
Dani Moncayo



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

* Re: Using the same custom file in two different OSes
  2013-01-13 22:00 Using the same custom file in two different OSes Dani Moncayo
  2013-01-13 22:18 ` Drew Adams
@ 2013-01-15 13:27 ` Stefan Monnier
  2013-01-15 20:27   ` Dani Moncayo
       [not found]   ` <mailman.17532.1358281671.855.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 28+ messages in thread
From: Stefan Monnier @ 2013-01-15 13:27 UTC (permalink / raw)
  To: help-gnu-emacs

> I'd like to use the same Emacs custom file in two different OSes:
> MS-Windows and Ubuntu, but I have one problem: I want to define the
> :family property of the `default' and `variable-pitch' faces based on
> the `system-type' (because my favorite family on MS-Windows isn't
> available on Ubuntu and vice-versa), but without having to duplicate
> my custom file (one for each system-type), so that I can tweak my
> customization at any time, in any OS, and get an updated custom file
> that is still valid for both OSes.

Of course, having the power of Elisp to write your .emacs, it's easy to
use `if' and whatnot to say very precisely how you want it to behave.
But admittedly, for face customization it's more tricky because there is
no convenient and robust way to configure faces other than through
Custom and Custom does not let you use Elisp's power.

Luckily, in the specific case of wanting different families on different
systems, you can use face-font-family-alternatives: i.e. in Custom set
the "family" to "default-family" and then do

  (add-to-list 'face-font-family-alternatives
               `("default-family" ,(if (foo) "fixed" "courier")))

in my cases, I don't even need an `if': I just list the font families in
the order I prefer so Emacs picks the best one among those available.


        Stefan
        




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

* Re: Using the same custom file in two different OSes
  2013-01-15 13:27 ` Stefan Monnier
@ 2013-01-15 20:27   ` Dani Moncayo
       [not found]   ` <mailman.17532.1358281671.855.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 28+ messages in thread
From: Dani Moncayo @ 2013-01-15 20:27 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

> Luckily, in the specific case of wanting different families on different
> systems, you can use face-font-family-alternatives: i.e. in Custom set
> the "family" to "default-family" and then do
>
>   (add-to-list 'face-font-family-alternatives
>                `("default-family" ,(if (foo) "fixed" "courier")))
>
> in my cases, I don't even need an `if': I just list the font families in
> the order I prefer so Emacs picks the best one among those available.

That looks like a simple a good solution, but it doesn't work for me.

I have this fragment in my init file:

  (add-to-list 'face-font-family-alternatives
               '("Courier New" "Ubuntu Mono"))
  (setq custom-file "my-custom-file.el")
  (load custom-file)

(The family "Courier New" exists in Windows and "Ubuntu Mono" exists in Ubuntu)

And my-custom-file.el has this line (among other):
 '(default ((t (:inherit nil :stipple nil :background "gray72"
:foreground "black" :inverse-video nil :box nil :strike-through nil
:overline nil :underline nil :slant normal :weight normal :height 98
:width normal :foundry "unknown" :family "Courier New"))))

When I start Emacs, I see that the value of
`face-font-family-alternatives' looks fine:
  (("Courier New" "Ubuntu Mono")
   ("Monospace" "courier" "fixed")
   ("courier" "CMU Typewriter Text" "fixed")
   ("Sans Serif" "helv" "helvetica" "arial" "fixed")
   ("helv" "helvetica" "arial" "fixed"))


On Windows, the "Courier New" family is chosen as expected, but on
Ubuntu Emacs doesn't choose "Ubuntu Mono" as expected, but another
face (similar to Courier New, BTW).  If I do "M-x customize-face RET
default RET", the family that I see is "TlwgMono".


-- 
Dani Moncayo



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

* Re: Using the same custom file in two different OSes
       [not found]   ` <mailman.17532.1358281671.855.help-gnu-emacs@gnu.org>
@ 2013-01-16  8:58     ` Sebastien Vauban
  2013-01-16 20:35       ` Dani Moncayo
  2013-01-16 12:59     ` Jason Rumney
  1 sibling, 1 reply; 28+ messages in thread
From: Sebastien Vauban @ 2013-01-16  8:58 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Hi Dani,

Dani Moncayo wrote:
>> Luckily, in the specific case of wanting different families on different
>> systems, you can use face-font-family-alternatives: i.e. in Custom set
>> the "family" to "default-family" and then do
>>
>>   (add-to-list 'face-font-family-alternatives
>>                `("default-family" ,(if (foo) "fixed" "courier")))
>>
>> in my cases, I don't even need an `if': I just list the font families in
>> the order I prefer so Emacs picks the best one among those available.
>
> That looks like a simple a good solution, but it doesn't work for me.
>
> I have this fragment in my init file:
>
>   (add-to-list 'face-font-family-alternatives
>                '("Courier New" "Ubuntu Mono"))
>   (setq custom-file "my-custom-file.el")
>   (load custom-file)
>
> (The family "Courier New" exists in Windows and "Ubuntu Mono" exists in Ubuntu)

I would do something like this:

#+begin_src emacs-lisp
;; set default font for all frames
(when window-system
   (cond
         ((font-info "Courier New")
          (modify-all-frames-parameters '((font . "Courier New-8"))))
         ((font-info "Ubuntu Mono")
          (modify-all-frames-parameters '((font . "Ubuntu Mono-9"))))))
#+end_src

Please check the accuracy of the font names...

Best regards,
  Seb

-- 
Sebastien Vauban


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

* Re: Using the same custom file in two different OSes
       [not found]   ` <mailman.17532.1358281671.855.help-gnu-emacs@gnu.org>
  2013-01-16  8:58     ` Sebastien Vauban
@ 2013-01-16 12:59     ` Jason Rumney
  1 sibling, 0 replies; 28+ messages in thread
From: Jason Rumney @ 2013-01-16 12:59 UTC (permalink / raw)
  To: help-gnu-emacs; +Cc: help-gnu-emacs, Stefan Monnier

On Wednesday, 16 January 2013 04:27:45 UTC+8, Dani Moncayo  wrote:

> On Windows, the "Courier New" family is chosen as expected, but on
> 
> Ubuntu Emacs doesn't choose "Ubuntu Mono" as expected, but another
> 
> face (similar to Courier New, BTW).  If I do "M-x customize-face RET
> 
> default RET", the family that I see is "TlwgMono".

It's quite likely that the distribution is preconfigured to contain aliases for common Windows font names, so that the user does not get "Font not found" messages about them when they receive documents from Windows users.

Look in /etc/fonts/conf.d for files containing snippets like:

	<alias binding="same">
	  <family>TlwgMono</family>
	  <default>
	    <family>Courier New</family>
	  </default>
	</alias>

Or, reverse the order of the fonts in your .emacs, so "Ubuntu Mono" is preferred over "Courier New".


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

* Re: Using the same custom file in two different OSes
  2013-01-16  8:58     ` Sebastien Vauban
@ 2013-01-16 20:35       ` Dani Moncayo
  0 siblings, 0 replies; 28+ messages in thread
From: Dani Moncayo @ 2013-01-16 20:35 UTC (permalink / raw)
  To: Sebastien Vauban; +Cc: help-gnu-emacs

On Wed, Jan 16, 2013 at 9:58 AM, Sebastien Vauban
<wxhgmqzgwmuf@spammotel.com> wrote:

> Hi Dani,

Hi

>>> Luckily, in the specific case of wanting different families on different
>>> systems, you can use face-font-family-alternatives: i.e. in Custom set
>>> the "family" to "default-family" and then do
>>>
>>>   (add-to-list 'face-font-family-alternatives
>>>                `("default-family" ,(if (foo) "fixed" "courier")))
>>>
>>> in my cases, I don't even need an `if': I just list the font families in
>>> the order I prefer so Emacs picks the best one among those available.
>>
>> That looks like a simple a good solution, but it doesn't work for me.
>>
>> I have this fragment in my init file:
>>
>>   (add-to-list 'face-font-family-alternatives
>>                '("Courier New" "Ubuntu Mono"))
>>   (setq custom-file "my-custom-file.el")
>>   (load custom-file)
>>
>> (The family "Courier New" exists in Windows and "Ubuntu Mono" exists in Ubuntu)
>
> I would do something like this:
>
> #+begin_src emacs-lisp
> ;; set default font for all frames
> (when window-system
>    (cond
>          ((font-info "Courier New")
>           (modify-all-frames-parameters '((font . "Courier New-8"))))
>          ((font-info "Ubuntu Mono")
>           (modify-all-frames-parameters '((font . "Ubuntu Mono-9"))))))
> #+end_src
>
> Please check the accuracy of the font names...

That works, thanks, but it sets only the family and size of the font.
Would it be possible to specify other properties like the background
color?

-- 
Dani Moncayo



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

* Re: Using the same custom file in two different OSes
  2013-01-14 22:05         ` Drew Adams
@ 2013-01-16 21:03           ` Dani Moncayo
       [not found]           ` <mailman.17633.1358371586.855.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 28+ messages in thread
From: Dani Moncayo @ 2013-01-16 21:03 UTC (permalink / raw)
  To: Drew Adams; +Cc: help-gnu-emacs

On Mon, Jan 14, 2013 at 11:05 PM, Drew Adams <drew.adams@oracle.com> wrote:
>> Mmmm I'm afraid I'm unable to keep my custom file free of my
>> platform-specific stuff. I've just seen this behavior:
>> 1. I remove the `default' and `variable-pitch' lines from my
>> custom file.
>> 2. I exit Emacs, start it again and verify that my custom file doesn't
>> have the lines I removed.  Note that this session has loaded my init
>> file, which first loads my custom file and then makes the
>> platform-specific customization (in that order).
>> 3. I do some customization (change the box-width property of the
>> `mode-line' face, for example), and save it (C-x C-s).
>> 4. I reopen my custom file and see that the two lines I removed in #1
>> have been reinserted.
>>
>> Changing the order (first do the platform-specific customization and
>> the load the custom file) doesn't help.  The custom file is
>> regenerated (when I save any customization) entirely, including the
>> `default' and `variable-pitch' faces.
>
> Right.
>
> It's because your init file changes the faces but does not save those changes or
> cancel them.  Then, when you save changes with C-x C-s, that saves the faces you
> changed.
>
> You want to either (a) do what you do now: redefine the faces after loading your
> `custom-file' each time or (b) just tell Customize that the faces have _not_
> been changed (even though they have), before hitting C-x C-s.  That is, just
> tell Customize to ignore your changes.
>
> For that, you can just add those faces to option `customize-customized-ignore'
> (user preferences to ignore in `customize-customized').  For that you will need
> to load library cus-edit+.el.
> http://www.emacswiki.org/emacs-en/download/cus-edit%2b.el
>
> If you do not want to do that, then you can use code like this in your init
> file, just after setting the faces the way you want:
>
> (face-spec-set THE-FACE (get THE-FACE 'face-defface-spec) 'reset)
>
> That should work.  This should also do the trick, as an alternative:
>
> (put THE-FACE 'saved-face nil)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

That did the trick.

So, now I'm able to keep my custom file free of platform-dependent
settings, which are moved to the init file, like this:

  ;; Set the custom-file
  (setq custom-file "whatever")
  ;; Load the platform-independent customization
  (load custom-file)
  ;; Set the platform-specific customization
  (if (display-graphic-p)
    (if (eq system-type 'windows-nt)
        (custom-set-faces <Stuff specific to MS-Windows>)
      (custom-set-faces <Stuff specific to Other OSes>)))
  ;; Reset de state of the faces customized above, so that they
  ;; don't get written to the custom-file when some customization
  ;; is saved.
  (put 'default 'saved-face nil)
  (put 'variable-pitch 'saved-face nil)


Thanks Drew!

-- 
Dani Moncayo



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

* Re: Using the same custom file in two different OSes
       [not found]           ` <mailman.17633.1358371586.855.help-gnu-emacs@gnu.org>
@ 2013-01-17  8:43             ` Sebastien Vauban
  2013-01-17 14:19               ` Drew Adams
  0 siblings, 1 reply; 28+ messages in thread
From: Sebastien Vauban @ 2013-01-17  8:43 UTC (permalink / raw)
  To: help-gnu-emacs-mXXj517/zsQ

Dani,

Dani Moncayo wrote:
> So, now I'm able to keep my custom file free of platform-dependent
> settings, which are moved to the init file, like this:
>
>   ;; Set the custom-file
>   (setq custom-file "whatever")
>   ;; Load the platform-independent customization
>   (load custom-file)
>   ;; Set the platform-specific customization
>   (if (display-graphic-p) ...

FYI, I'm using:

    (if window-system ...

but that comes down to pretty much the same thing, it seems.

Best regards,
  Seb

-- 
Sebastien Vauban


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

* RE: Using the same custom file in two different OSes
  2013-01-17  8:43             ` Sebastien Vauban
@ 2013-01-17 14:19               ` Drew Adams
  2013-01-17 14:38                 ` Peter Dyballa
  2013-01-17 16:32                 ` Eli Zaretskii
  0 siblings, 2 replies; 28+ messages in thread
From: Drew Adams @ 2013-01-17 14:19 UTC (permalink / raw)
  To: 'Sebastien Vauban', help-gnu-emacs

> >   (if (display-graphic-p) ...
> 
> FYI, I'm using: (if window-system ...
> but that comes down to pretty much the same thing, it seems.

`window-system' has the advantage that it works with older Emacs releases.

But `display-graphic-p' is what is recommended for recent releases.
From the doc string of `window-system':

 "Use of this function as a predicate is deprecated.  Instead,
  use `display-graphic-p' or any of the other `display-*-p'
  predicates which report frame's specific UI-related capabilities."




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

* Re: Using the same custom file in two different OSes
  2013-01-17 14:19               ` Drew Adams
@ 2013-01-17 14:38                 ` Peter Dyballa
  2013-01-17 15:22                   ` Dani Moncayo
                                     ` (2 more replies)
  2013-01-17 16:32                 ` Eli Zaretskii
  1 sibling, 3 replies; 28+ messages in thread
From: Peter Dyballa @ 2013-01-17 14:38 UTC (permalink / raw)
  To: Drew Adams; +Cc: 'Sebastien Vauban', help-gnu-emacs


Am 17.01.2013 um 15:19 schrieb Drew Adams:

>>>  (if (display-graphic-p) ...
>> 
>> FYI, I'm using: (if window-system ...
>> but that comes down to pretty much the same thing, it seems.
> 
> `window-system' has the advantage that it works with older Emacs releases.
> 
> But `display-graphic-p' is what is recommended for recent releases.
> From the doc string of `window-system':
> 
> "Use of this function as a predicate is deprecated.  Instead,
>  use `display-graphic-p' or any of the other `display-*-p'
>  predicates which report frame's specific UI-related capabilities."
> 
> 
This looks more like a regression than progress…

The variable `window-system' at least returns a value indicating on which kind of graphic display this instance of GNU Emacs runs: x, w32, ns, pc, mac. These variants still need different set-ups. And it also makes sense to decorate the instance running in different colours to see at once in which variant I'm in.

In future one might need to parse the text returned by `emacs-version' to find this information – and might fail at first because being build for a graphic display does not exclude its use without a windowing system. So one would need a second test.

--
Greetings

  Pete

Eat the rich – the poor are tough and stringy.




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

* Re: Using the same custom file in two different OSes
  2013-01-17 14:38                 ` Peter Dyballa
@ 2013-01-17 15:22                   ` Dani Moncayo
  2013-01-17 16:38                     ` Eli Zaretskii
  2013-01-17 16:01                   ` Drew Adams
  2013-01-17 16:33                   ` Eli Zaretskii
  2 siblings, 1 reply; 28+ messages in thread
From: Dani Moncayo @ 2013-01-17 15:22 UTC (permalink / raw)
  To: Peter Dyballa; +Cc: Sebastien Vauban, help-gnu-emacs

>>>>  (if (display-graphic-p) ...
>>>
>>> FYI, I'm using: (if window-system ...
>>> but that comes down to pretty much the same thing, it seems.
>>
>> `window-system' has the advantage that it works with older Emacs releases.
>>
>> But `display-graphic-p' is what is recommended for recent releases.
>> From the doc string of `window-system':
>>
>> "Use of this function as a predicate is deprecated.  Instead,
>>  use `display-graphic-p' or any of the other `display-*-p'
>>  predicates which report frame's specific UI-related capabilities."
>>
>>
> This looks more like a regression than progress…
>
> The variable `window-system' at least returns a value indicating on which kind of graphic display this instance of GNU Emacs runs: x, w32, ns, pc, mac. These variants still need different set-ups. And it also makes sense to decorate the instance running in different colours to see at once in which variant I'm in.

Indeed, there should be a non-deprecated way of getting that information.


-- 
Dani Moncayo



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

* RE: Using the same custom file in two different OSes
  2013-01-17 14:38                 ` Peter Dyballa
  2013-01-17 15:22                   ` Dani Moncayo
@ 2013-01-17 16:01                   ` Drew Adams
  2013-01-17 16:33                   ` Eli Zaretskii
  2 siblings, 0 replies; 28+ messages in thread
From: Drew Adams @ 2013-01-17 16:01 UTC (permalink / raw)
  To: 'Peter Dyballa'; +Cc: 'Sebastien Vauban', help-gnu-emacs

> >>>  (if (display-graphic-p) ...
> >> 
> >> FYI, I'm using: (if window-system ...
> >> but that comes down to pretty much the same thing, it seems.
> > 
> > `window-system' has the advantage that it works with older 
> > Emacs releases.
> > 
> > But `display-graphic-p' is what is recommended for recent releases.
> > From the doc string of `window-system':
> > 
> > "Use of this function as a predicate is deprecated.  Instead,
                          ^^^^^^^^^^^^^^
> >  use `display-graphic-p' or any of the other `display-*-p'
> >  predicates which report frame's specific UI-related capabilities."
>
> This looks more like a regression than progress.

Feel free to report it: `M-x report-emacs-bug'.

I only relayed the message, as I understand it.

> The variable `window-system' at least returns a value 
> indicating on which kind of graphic display this instance of 
> GNU Emacs runs: x, w32, ns, pc, mac. These variants still 
> need different set-ups. And it also makes sense to decorate 
> the instance running in different colours to see at once in 
> which variant I'm in.
> 
> In future one might need to parse the text returned by 
> `emacs-version' to find this information - and might fail at 
> first because being build for a graphic display does not 
> exclude its use without a windowing system. So one would need 
> a second test.

AFAIK, `window-system' is _not_ deprecated.  It is its "use as a predicate" that
is deprecated.

IOW, Emacs Dev suggests that people use `display-graphic-p', not
`window-system', to determine whether the current Emacs session supports a
graphic display.

Again though, that's just my understanding, and I'm just relaying what I have
understood.




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

* Re: Using the same custom file in two different OSes
  2013-01-17 14:19               ` Drew Adams
  2013-01-17 14:38                 ` Peter Dyballa
@ 2013-01-17 16:32                 ` Eli Zaretskii
  2013-01-17 16:57                   ` Drew Adams
  1 sibling, 1 reply; 28+ messages in thread
From: Eli Zaretskii @ 2013-01-17 16:32 UTC (permalink / raw)
  To: help-gnu-emacs

> From: "Drew Adams" <drew.adams@oracle.com>
> Date: Thu, 17 Jan 2013 06:19:04 -0800
> 
> > >   (if (display-graphic-p) ...
> > 
> > FYI, I'm using: (if window-system ...
> > but that comes down to pretty much the same thing, it seems.
> 
> `window-system' has the advantage that it works with older Emacs releases.

Only if you want to support Emacs versions before 21.1.



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

* Re: Using the same custom file in two different OSes
  2013-01-17 14:38                 ` Peter Dyballa
  2013-01-17 15:22                   ` Dani Moncayo
  2013-01-17 16:01                   ` Drew Adams
@ 2013-01-17 16:33                   ` Eli Zaretskii
  2 siblings, 0 replies; 28+ messages in thread
From: Eli Zaretskii @ 2013-01-17 16:33 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Peter Dyballa <Peter_Dyballa@Web.DE>
> Date: Thu, 17 Jan 2013 15:38:32 +0100
> Cc: 'Sebastien Vauban' <wxhgmqzgwmuf@spammotel.com>, help-gnu-emacs@gnu.org
> 
> > `window-system' has the advantage that it works with older Emacs releases.
> > 
> > But `display-graphic-p' is what is recommended for recent releases.
> > From the doc string of `window-system':
> > 
> > "Use of this function as a predicate is deprecated.  Instead,
> >  use `display-graphic-p' or any of the other `display-*-p'
> >  predicates which report frame's specific UI-related capabilities."
> > 
> > 
> This looks more like a regression than progress…
> 
> The variable `window-system' at least returns a value indicating on which kind of graphic display this instance of GNU Emacs runs: x, w32, ns, pc, mac. These variants still need different set-ups. And it also makes sense to decorate the instance running in different colours to see at once in which variant I'm in.

Which part of "as a predicate" did you not understand?  Uses of that
function when you are interested in its value is _not_ deprecated.




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

* Re: Using the same custom file in two different OSes
  2013-01-17 15:22                   ` Dani Moncayo
@ 2013-01-17 16:38                     ` Eli Zaretskii
  0 siblings, 0 replies; 28+ messages in thread
From: Eli Zaretskii @ 2013-01-17 16:38 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Thu, 17 Jan 2013 16:22:58 +0100
> From: Dani Moncayo <dmoncayo@gmail.com>
> Cc: Sebastien Vauban <wxhgmqzgwmuf@spammotel.com>, help-gnu-emacs@gnu.org
> 
> Indeed, there should be a non-deprecated way of getting that information.

window-system is not deprecated for that kind of usage.



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

* RE: Using the same custom file in two different OSes
  2013-01-17 16:32                 ` Eli Zaretskii
@ 2013-01-17 16:57                   ` Drew Adams
  2013-01-17 17:48                     ` Eli Zaretskii
  0 siblings, 1 reply; 28+ messages in thread
From: Drew Adams @ 2013-01-17 16:57 UTC (permalink / raw)
  To: 'Eli Zaretskii', help-gnu-emacs

> > `window-system' has the advantage that it works with older 
> > Emacs releases.
> 
> Only if you want to support Emacs versions before 21.1.

Fair enough.  However, even in the final Emacs 22 release there are _many_ uses
of `window-sytem' as a predicate in the Gnu Emacs source code, even though
`display-graphic-p' was introduced two releases before that.

Heck, even in the latest Gnu Emacs development source code, to be Emacs 24.3,
there are still many such "deprecated" uses, AFAICT.

Here is a typical one, in dframe.el:

;; On a terminal, raise the frame or the user will
;; be confused.
(if (not window-system)
    (select-frame (symbol-value frame-var)))

In case you think dframe.el is a bit exotic, see the basic libraries faces.el
and frame.el, where there are also several such uses.

And frame.el is the very file where `display-graphic-p' is *defined*.  It is
called only 3 times in that file, while `window-system' seems to be used there
as a predicate 7 times.

Nobody's perfect, of course.




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

* Re: Using the same custom file in two different OSes
  2013-01-17 16:57                   ` Drew Adams
@ 2013-01-17 17:48                     ` Eli Zaretskii
  2013-01-17 18:15                       ` Drew Adams
  0 siblings, 1 reply; 28+ messages in thread
From: Eli Zaretskii @ 2013-01-17 17:48 UTC (permalink / raw)
  To: help-gnu-emacs

> From: "Drew Adams" <drew.adams@oracle.com>
> Date: Thu, 17 Jan 2013 08:57:41 -0800
> 
> > > `window-system' has the advantage that it works with older 
> > > Emacs releases.
> > 
> > Only if you want to support Emacs versions before 21.1.
> 
> Fair enough.  However, even in the final Emacs 22 release there are _many_ uses
> of `window-sytem' as a predicate in the Gnu Emacs source code, even though
> `display-graphic-p' was introduced two releases before that.

Old habits die hard.

> Heck, even in the latest Gnu Emacs development source code, to be Emacs 24.3,
> there are still many such "deprecated" uses, AFAICT.
> 
> Here is a typical one, in dframe.el:
> 
> ;; On a terminal, raise the frame or the user will
> ;; be confused.
> (if (not window-system)
>     (select-frame (symbol-value frame-var)))
> 
> In case you think dframe.el is a bit exotic, see the basic libraries faces.el
> and frame.el, where there are also several such uses.

We need a better QA, obviously.  However, at the time, the core files
were left only with uses which couldn't be easily replaced by some
display-*-p predicate, and inventing a predicate for 1 or 2 uses is
not a good idea.

> And frame.el is the very file where `display-graphic-p' is *defined*.  It is
> called only 3 times in that file, while `window-system' seems to be used there
> as a predicate 7 times.

I see only 5 instances, not 7, and it is not clear to me what
display-*-p predicate would be appropriate in their stead.

> Nobody's perfect, of course.

Emacs development certainly isn't.



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

* RE: Using the same custom file in two different OSes
  2013-01-17 17:48                     ` Eli Zaretskii
@ 2013-01-17 18:15                       ` Drew Adams
  2013-01-17 18:44                         ` Eli Zaretskii
  0 siblings, 1 reply; 28+ messages in thread
From: Drew Adams @ 2013-01-17 18:15 UTC (permalink / raw)
  To: 'Eli Zaretskii', help-gnu-emacs

> > And frame.el is the very file where `display-graphic-p' is 
> > *defined*.  It is called only 3 times in that file, while
> > `window-system' seems to be used there as a predicate 7 times.
> 
> I see only 5 instances, not 7,

These occurrences all looked to me superficially like they were just testing
whether FRAME is for graphic display:

1. (when (memq (window-system frame) '(x w32 ns))
     (x-focus-frame frame))

2. (or (window-system frame)
       (and tty-type
            (string-match "^\\(xterm\\|\\rxvt\\|dtterm\\|eterm\\)"
                          tty-type)))

3. (cond ((null (window-system frame))
          (if (tty-display-color-p frame) 'color 'mono))

4. (and (window-system frame)
        (x-get-resource "backgroundMode" "BackgroundMode"))

5 and 6 (two occurrences).

   (or window-system
       (face-set-after-frame-default (selected-frame)))

OK, these occurrences use the variable `window-system', not the function, but it
too is deprecated in favor of function `display-*-p'.

7. (not (memq window-system '(x w32 ns)))

Again, the deprecated variable.  If you don't count the variable occurrences
then 4, not 5, AFAICT.

> and it is not clear to me what display-*-p predicate would be
> appropriate in their stead.

If it's not clear to you how to replace deprecated `window-system' occurrences
here, I wonder how it should be clear to us mortals. ;-)

But which of the functions with names matching `display-*-p' correspond to what
you and the `window-system' deprecation doc mean by `display-*-p'?  All of them?

 display-color-p
 display-graphic-p
 display-grayscale-p 
 display-images-p
 display-mouse-p
 display-multi-font-p 
 display-multi-frame-p
 display-popup-menus-p
 display-selections-p 
 display-supports-face-attributes-p
 display-time-file-nonempty-p

If all of them, then there should be a comma in the `window-system' doc string
here, just before "which":

  Instead, use `display-graphic-p' or any of the other `display-*-p'
  predicates which report frame's specific UI-related capabilities.
            ^

Without a comma, the text suggests that there are some `display-*-p' predicates
that do not "report frame's...", and that those are not included as
`window-system' substitutes.

(BTW, "frame's" here should be "FRAME's", referring to the argument.  Or else it
should say "the frame's".)




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

* Re: Using the same custom file in two different OSes
  2013-01-17 18:15                       ` Drew Adams
@ 2013-01-17 18:44                         ` Eli Zaretskii
  0 siblings, 0 replies; 28+ messages in thread
From: Eli Zaretskii @ 2013-01-17 18:44 UTC (permalink / raw)
  To: help-gnu-emacs

> From: "Drew Adams" <drew.adams@oracle.com>
> Date: Thu, 17 Jan 2013 10:15:58 -0800
> 
> But which of the functions with names matching `display-*-p' correspond to what
> you and the `window-system' deprecation doc mean by `display-*-p'?  All of them?
> 
>  display-color-p
>  display-graphic-p
>  display-grayscale-p 
>  display-images-p
>  display-mouse-p
>  display-multi-font-p 
>  display-multi-frame-p
>  display-popup-menus-p
>  display-selections-p 
>  display-supports-face-attributes-p
>  display-time-file-nonempty-p

All but the last one.



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

end of thread, other threads:[~2013-01-17 18:44 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-01-13 22:00 Using the same custom file in two different OSes Dani Moncayo
2013-01-13 22:18 ` Drew Adams
2013-01-14 18:46   ` Dani Moncayo
2013-01-14 19:13     ` Drew Adams
2013-01-14 19:42       ` Dani Moncayo
2013-01-14 21:55         ` Peter Dyballa
2013-01-14 23:00           ` Dani Moncayo
2013-01-15  8:25             ` Didier Verna
2013-01-15  8:42               ` Dani Moncayo
2013-01-14 22:05         ` Drew Adams
2013-01-16 21:03           ` Dani Moncayo
     [not found]           ` <mailman.17633.1358371586.855.help-gnu-emacs@gnu.org>
2013-01-17  8:43             ` Sebastien Vauban
2013-01-17 14:19               ` Drew Adams
2013-01-17 14:38                 ` Peter Dyballa
2013-01-17 15:22                   ` Dani Moncayo
2013-01-17 16:38                     ` Eli Zaretskii
2013-01-17 16:01                   ` Drew Adams
2013-01-17 16:33                   ` Eli Zaretskii
2013-01-17 16:32                 ` Eli Zaretskii
2013-01-17 16:57                   ` Drew Adams
2013-01-17 17:48                     ` Eli Zaretskii
2013-01-17 18:15                       ` Drew Adams
2013-01-17 18:44                         ` Eli Zaretskii
2013-01-15 13:27 ` Stefan Monnier
2013-01-15 20:27   ` Dani Moncayo
     [not found]   ` <mailman.17532.1358281671.855.help-gnu-emacs@gnu.org>
2013-01-16  8:58     ` Sebastien Vauban
2013-01-16 20:35       ` Dani Moncayo
2013-01-16 12:59     ` Jason Rumney

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