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

Trouble setting default font and window size

35 views
Skip to first unread message

Ron House

unread,
Jul 28, 2016, 1:18:47 AM7/28/16
to
I am trying to set a particular font and default window size, but I run
into a problem. I get the font I want, but when emacs starts, just as it
starts, before it sets the required font, it momentarily uses a larger
font. The window size I ask for uses the entire screen height, so that
larger font causes emacs to ignore my screen size request and use a much
smaller, standard screen size.

So I am having to specify a smaller size than I want so that the larger
font only just fits the screen, but then my reduced window when the
correct font takes over is smaller than I want.

I start emacs with:

emacs -i -geometry 85x64 <<< I really want 99x60 here.

My .emacs contains the following lines related to font settings:

(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(default ((t (:inherit nil :stipple nil :inverse-video nil :box nil
:strike-through nil :overline nil :underline nil :slant normal :weight
normal :height 90 :width normal :foundry "bitstream" :family "Bitstream
Vera Sans Mono"))))
'(header-line ((((class color grayscale) (background light)) (:inherit
mode-line :background "grey90" :foreground "grey20" :box nil :height 0.5
:width condensed))))
'(mouse ((t (:background "black")))))

This is the font I want, but emacs starts up with some other font. Can
that be changed?

--
Ron House
Building Peace: http://peacelegacy.org
Australian Birds: http://wingedhearts.org
Principle of Goodness academic site: http://principleofgoodness.net

Emanuel Berg

unread,
Jul 28, 2016, 1:43:54 AM7/28/16
to
Ron House wrote:

> emacs -i -geometry 85x64

... what does -i do?

> (custom-set-faces

Try using `set-face-attribute' instead!

--
underground experts united .... http://user.it.uu.se/~embe8573
Emacs Gnus Blogomatic ......... http://user.it.uu.se/~embe8573/blogomatic
- so far: 58 Blogomatic articles -

martin rudalics

unread,
Jul 28, 2016, 4:58:53 AM7/28/16
to rho...@smartchat.net.au, help-gn...@gnu.org
This looks like the problem discussed in a thread called

"Note on e65c307 breaks font-height"

on emacs-devel. Have a look.

To handle it I currently use brute force via

(defalias 'dynamic-setting-handle-config-changed-event 'ignore)

in my .emacs.

martin

Ron House

unread,
Jul 28, 2016, 8:37:23 AM7/28/16
to
On 28/07/16 15:43, Emanuel Berg wrote:
> Ron House wrote:
>
>> emacs -i -geometry 85x64
>
> ... what does -i do?
>
>> (custom-set-faces
>
> Try using `set-face-attribute' instead!
>

Thanks Emanuel, but it doesn't work. With that change it says:

Warning (initialization): An error occurred while loading `/home/h/.emacs':

Wrong type argument: symbolp, (default ((t (:inherit nil :stipple nil
:inverse-video nil :box nil :strike-through nil :overline nil :underline
nil :slant normal :weight normal :height 90 :width normal :foundry
bitstream :family Bitstream Vera Sans Mono))))


Ron House

unread,
Jul 28, 2016, 8:47:33 AM7/28/16
to
Replying to martin rudalics, thanks for those ideas.

> (defalias 'dynamic-setting-handle-config-changed-event 'ignore)

doesn't seem to do anything.

> "Note on e65c307 breaks font-height"

Could be. The problem seems to be that the window is displayed before
.emacs is processed, so some built-in default is used and then, after
that has messed things up, .emacs is applied to the messed up display.

Emanuel Berg

unread,
Jul 28, 2016, 9:57:32 AM7/28/16
to
Ron House wrote:

>>> (custom-set-faces
>> Try using `set-face-attribute' instead!
>>
>
> Thanks Emanuel, but it doesn't work.
> With that change it says:
>
> Warning (initialization): An error occurred
> while loading `/home/h/.emacs':
>
> Wrong type argument: symbolp, (default ((t
> (:inherit nil :stipple nil :inverse-video nil
> :box nil :strike-through nil :overline nil
> :underline nil :slant normal :weight normal
> :height 90 :width normal :foundry bitstream
> :family Bitstream Vera Sans Mono))))

Yes, it doesn't work exactly like
`custom-set-faces'. But if you use the help
(`C-h f set-face-attribute RET') you can
achieve the equivalent, and perhaps circumvent
your problem.

Also `modify-face' may be of use - it is a good
start. Again, use the help to learn
the interface!

Last, you can use ~/.Xresources to move a lot
of that stuff from the Emacs init files and
also from the invocation command-line
arguments. If you do that, you need this line

xrdb ~/.Xresources

in the ~/.xinitrc file.

You can grep the web from "Xresources" and
"Emacs" for examples what it can look like.

Eli Zaretskii

unread,
Jul 28, 2016, 10:58:02 AM7/28/16
to help-gn...@gnu.org
> Date: Thu, 28 Jul 2016 22:47:25 +1000
> From: Ron House <rho...@smartchat.net.au>
>
> The problem seems to be that the window is displayed before .emacs
> is processed, so some built-in default is used and then, after that
> has messed things up, .emacs is applied to the messed up display.

I'd suggest to try 2 alternative approaches:

. Define the font in default-frame-alist
. Try to use one of the hooks provided by startup.el

One of these methods should overcome the problems related to the order
of things Emacs does at startup.

HASM

unread,
Jul 28, 2016, 11:30:34 AM7/28/16
to

> Last, you can use ~/.Xresources to move a lot of that stuff from the
> Emacs init files and also from the invocation command-line arguments.

I push this into my xrdb:
-----------------------------------------------------------------
Emacs*geometry: 100x50
Emacs.menuBar: off
Emacs.toolBar: off
Emacs.horizontalScrollBars: off
Emacs.verticalScrollBars: off
Emacs.background: #304060
Emacs.foreground: white
Emacs.Font: "-adobe-courier-medium-r-normal--20-140-100-100-m-110-iso8859-15"
-----------------------------------------------------------------

and this in my initialization:

-----------------------------------------------------------------
(defun hasm-config-frame (&optional frame)
(progn
(cond (frame (select-frame frame)))
(if (equal window-system 'x)
(progn
(set-foreground-color "white")
(set-background-color "#304060")
(set-frame-height (selected-frame) 50)
(set-frame-width (selected-frame) 100)
(set-face-attribute 'fringe nil :background "#304060" :foreground "white")
(set-frame-font "-adobe-courier-medium-r-normal--20-140-100-100-m-110-iso8859-15" nil t)
(transient-mark-mode 1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
))
(menu-bar-mode -1)))

(add-hook 'after-make-frame-functions 'hasm-config-frame)
(add-hook 'after-init-hook 'hasm-config-frame)
-----------------------------------------------------------------

and one time out of 10 or thereabout, my frame doesn't get the correct
size.

-- HASM

Emanuel Berg

unread,
Jul 28, 2016, 12:01:52 PM7/28/16
to
HASM wrote:

> I push this into my xrdb

So as to not confuse the OP, most likely you
mean ~/.Xresources.

From the command line, data (and changes to it)
can be read (updated) with

$ xrdb ~/.Xresources

A good way to have this automated every time
X is started is to put it in ~/.xinitrc, as in

http://user.it.uu.se/~embe8573/conf/.xinitrc

Note: xrdb(1) is "X server resource database
utility" but I always thought of it as
"X read database".

> -----------------------------------------------------------------
> Emacs*geometry: 100x50
> Emacs.menuBar: off
> Emacs.toolBar: off
> Emacs.horizontalScrollBars: off
> Emacs.verticalScrollBars: off
> Emacs.background: #304060
> Emacs.foreground: white
> Emacs.Font: "-adobe-courier-medium-r-normal--20-140-100-100-m-110-iso8859-15"
> -----------------------------------------------------------------

Thank you, that is what I meant. Also, for an
X user, you have good taste in options :)

> (defun hasm-config-frame (&optional frame)
> (progn
> (cond (frame (select-frame frame)))
> (if (equal window-system 'x)
> (progn
> (set-foreground-color "white")
> (set-background-color "#304060")
> (set-frame-height (selected-frame) 50)
> (set-frame-width (selected-frame) 100)
> (set-face-attribute 'fringe nil :background "#304060" :foreground "white")
> (set-frame-font "-adobe-courier-medium-r-normal--20-140-100-100-m-110-iso8859-15" nil t)
> (transient-mark-mode 1)
> (scroll-bar-mode -1)
> (tool-bar-mode -1)
> ))
> (menu-bar-mode -1)))

Again, thanks, this is what I meant with
`set-face-attribute'.

As for the Elisp, you don't need a `progn'
after `defun', and if you replace `if' with
`when', you get an implicit progn - and you can
do this safely, because you don't have an
"else" clause to your if!

> and one time out of 10 or thereabout, my
> frame doesn't get the correct size.

Hey, aren't computers supposed to
be deterministic?

OK, so it didn't circumvent the problem. But at
least it circumvented the custom interface and
tought us some Elisp in the process - WIN!

HASM

unread,
Jul 28, 2016, 5:26:52 PM7/28/16
to
Emanuel Berg <embe...@student.uu.se> writes:

>> I push this into my xrdb
> So as to not confuse the OP, most likely you
> mean ~/.Xresources.

I could further confuse the OP and claim that I have this in my
environment:
export XAPPLRESDIR=${HOME}/.x11resources/
export XENVIRONMENT=${HOME}/.Xdefaults
and have one file per X application under $XAPPLRESDIR, and a bunch of
includes in the $XENVIRONMENT file for the applications I still use,
just because that is the way I did way back when (and don't actually
call xrdb anymore) but that would be unnecessary :-)

>> -----------------------------------------------------------------
>> Emacs*geometry: 100x50
...

> Thank you, that is what I meant. Also, for an
> X user, you have good taste in options :)

Thanks!

> As for the Elisp, you don't need a `progn' after `defun', and if you
> replace `if' with `when', you get an implicit progn - and you can do
> this safely, because you don't have an "else" clause to your if!

Thanks again. My Elisp is rudimentary. I used to have a cond in there
instead of the if, with cases for other window systems, but I dropped it
when I recently switched from XEmacs back to Emacs.

-- HASM

Emanuel Berg

unread,
Jul 28, 2016, 10:34:51 PM7/28/16
to
HASM wrote:

> I could further confuse the OP and claim that
> I have this in my environment: export
> XAPPLRESDIR=${HOME}/.x11resources/ export
> XENVIRONMENT=${HOME}/.Xdefaults and have one
> file per X application under $XAPPLRESDIR,
> and a bunch of includes in the $XENVIRONMENT
> file for the applications I still use, just
> because that is the way I did way back when
> (and don't actually call xrdb anymore) but
> that would be unnecessary :-)

OK! Well hopefully you don't confuse the OP
anymore, after the explanation! Everything for
the OP :)

Yeah... Actually one file per application in
general is a good idea. And that is common
practise. One .xpdfrc, one .xbindkeysrc, and
so on.

I think the Xresources file is thought to be
the X's "look and feel", tho I don't know if
that term was popularized until the GNOMEs and
KDEs desktops?

Because with Xresources you can get that by
setting conform options for several
applications with the wildcard notation! So you
don't need yet another Linux distribution to
get it...

Personally, I never used enough of them (X
applications) to explore this further, so
I just stacked the few options I have.

> I used to have a cond in there instead of the
> if, with cases for other window systems, but
> I dropped it when I recently switched from
> XEmacs back to Emacs.

People who are coming to Lisp from other
languages, and that should be almost everyone
these days, tend to like `if' + `progn' even
when there is no "else" clause equivalent
present.

When programming, it can be natural to use if
anyway as it isn't always clear from the get-go
what is needed or what will be. When set
however I think `when' is generally preferred to
(if something something) or (if something
(progn somethings)) and likewise `unless' is
preferred to (if (not something) ...).

Another "secret" of Lisp compared to other
languages is the `or' which returns the first
non-nil value. So it isn't only for branching!
It can also be the setting of a variable to the
first other thing that is set. E.g.

(setq gear (or hook line sinker))

If all three are nil, gear will naturally
be nil! But if hook is nil but line is "hemp",
gear will be "hemp" - wonderful :)

Ron House

unread,
Jul 29, 2016, 2:09:10 AM7/29/16
to
On 29/07/16 01:30, HASM wrote:
>
>> Last, you can use ~/.Xresources to move a lot of that stuff from the
>> Emacs init files and also from the invocation command-line arguments.
>
> I push this into my xrdb:
> -----------------------------------------------------------------
> Emacs*geometry: 100x50
> Emacs.menuBar: off
> Emacs.toolBar: off
> Emacs.horizontalScrollBars: off
> Emacs.verticalScrollBars: off
> Emacs.background: #304060
> Emacs.foreground: white
> Emacs.Font: "-adobe-courier-medium-r-normal--20-140-100-100-m-110-iso8859-15"
> -----------------------------------------------------------------

I tried this, but got inexplicable errors - despite xlsfonts showing my
font, it nevertheless claimed it was a nonexistent font when I started
emacs. It's not worth spending more time on this, but I did discover one
important fact that someone working on emacs might or might not be
interested in:

My earlier speculation about the timing of the bug was wrong. All the
mis-scaling occurs in processing the single setup line:

(custom-set-faces
'(default ((t (:inherit nil :stipple nil :inverse-video nil :box nil
:strike-through nil :overline nil :underline nil :slant normal :weight
normal :height 90 :width normal :foundry "bitstream" :family "Bitstream
Vera Sans Mono"))))
...

When that default line is in, all the wrong stuff happens, without it,
none of it does. So it seems that instead of changing all the specs and
then redisplaying, emacs is changing some settings, displaying, then
changing some more and displaying again, instead of changing all
settings and displaying only once.

Pity it wasn't a simple fix, but thanks to all for your time and effort!

martin rudalics

unread,
Jul 29, 2016, 2:14:43 AM7/29/16
to rho...@smartchat.net.au, help-gn...@gnu.org
> > (defalias 'dynamic-setting-handle-config-changed-event 'ignore)
>
> doesn't seem to do anything.
>
> > "Note on e65c307 breaks font-height"
>
> Could be. The problem seems to be that the window is displayed before .emacs is processed, so some built-in default is used and then, after that has messed things up, .emacs is applied to the messed up display.

I was referring only to your earlier statement:

> (custom-set-faces
> ;; custom-set-faces was added by Custom.
> ;; If you edit it by hand, you could mess it up, so be careful.
> ;; Your init file should contain only one such instance.
> ;; If there is more than one, they won't work right.
>
> '(default ((t (:inherit nil :stipple nil :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 90 :width normal :foundry "bitstream" :family "Bitstream Vera Sans Mono")))) '(header-line ((((class color grayscale) (background light)) (:inherit mode-line :background "grey90" :foreground "grey20" :box nil :height 0.5 :width condensed))))
>
> '(mouse ((t (:background "black")))))
>
> This is the font I want, but emacs starts up with some other font. Can that be changed?

You didn't tell us which version of Emacs you're using so I can't even
tell whether ‘dynamic-setting-handle-config-changed-event’ really does
something on your system. In any case, I would start out disregarding
the window size problem and getting the right font first. Fixing the
frame/window size afterwards should be straightforward.

martin


Ron House

unread,
Aug 1, 2016, 7:19:34 AM8/1/16
to
On 29/07/16 16:09, Ron House wrote:

> Pity it wasn't a simple fix, but thanks to all for your time and effort!

And just then, a bright idea collided with the victim...

Let emacs start up, let all the nonsense happen until the font has been
chosen, THEN resize the window! So I put this at the bottom of my .emacs:

(when window-system (set-frame-size (selected-frame) 90 70))
(add-to-list 'default-frame-alist '(height . 70))
(add-to-list 'default-frame-alist '(width . 90))

The first line resizes the opening window, the next 2 resize any windows
opened with ^X-5-2.

Thanks again to all.
0 new messages