5

I have the following in my .emacs file:

(when window-system
  (set-frame-position (selected-frame) 0 0)
  (set-frame-size (selected-frame) 91 63))

The value of 63 is supposed to make my initial frame take up the full vertical height of my screen.

However, the result is not actually a frame of 91x63. Instead, I get a frame of only 51. Likewise, increasing 63 to 70 doesn't get me a taller frame either. Initially, I see the frame popup with the full screen height, but then it shrinks down to a much smaller size. I believe this may be related to the fact that I have a configured font face and font size and the frame size is taking effect before the font size is set. So when the frame size is initially set, the frame is too large to fit on the screen so the size is shrunk and then later the font face and size are set, but now there is enough room to grow the frame. Do I need to some how control the order of these settings? If so, how do I do that? Currently, I have the font face and size set in the custom-set-faces block. Is there a better way to change the frame size so that it happens after the font face is set?

By the way, this code came from the Emacs wiki on Frame Size.

This is under Ubuntu Linux, and I'm using the PPA for Emacs 24. I am not using any Xresources.

For reference, here's my custom-set-faces block:

(custom-set-faces
 '(default ((t (:inherit nil :stipple nil :background "white" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 95 :width normal :foundry "unknown" :family "DejaVu Sans Mono")))))
  • 1
    Can you try emacs -q --xrm="Emacs.menuBar: 0" --xrm="Emacs.toolBar: 0" --xrm="Emacs.font: Inconsolata-16" --geometry=91x63 and see if it works. This would mean your hypothesis is correct and can be circumvented. Ofcourse replace Inconsolata with your default font. – Vamsi Oct 16 '14 at 23:21
  • @Vamsi Yes, that does solve my problem. I'm using "DejaVu Sans Mono", but otherwise this does work as expected. – b4hand Oct 16 '14 at 23:34
  • Ok I think it is more of the menu bar and toolbar which actually cause this problem. Just add all the arguments to --xrm in your ~\.Xresources file one per line. It should work. – Vamsi Oct 16 '14 at 23:41
  • @Vamsi, I don't think the menubar and toolbar are the problem as removing those options still makes it work. It's purely the fact that the font is different at startup than when the frame size is set. – b4hand Oct 16 '14 at 23:45
  • In that case, an alternative would be just call emacs --font="DejaVu Sans Mono-12". – Vamsi Oct 16 '14 at 23:49
3

Since this is being caused by changing the default font/size during init, one can avoid this problem by setting the font via X resources

Add to (creating if necessary) the file ~/.Xresources in the home directory the following line

 Emacs.font: DejaVu Sans Mono-12

Emacs will normally pick up the change once X has restarted. However, one can get X to recognize changes to .Xresources by running xrdb ~/.Xresources in a command-line.

Alternately, one can pass the same option at the command line using:

emacs --font="DejaVu Sans Mono-12"
  • So for some reason, setting the font with the command option works, but not with the .Xresources file. Note that I'm actually using a height of 95 in my init file which means that the actual desired size is 9.5. Using the command line, both --font="DejaVu Sans Mono-9.5" and --font="DejaVu Sans Mono-9" seem to work, but neither give me the same effect from within ~/.Xresources. – b4hand Oct 17 '14 at 0:13
  • 1
    Oops forgot this. You need to reload your X environment. You can use xrdb ~\.Xresources at the command line. – Vamsi Oct 17 '14 at 0:15
2

If you really mean the initial frame, then see option initial-frame-alist. In particular, see this part of the doc string:

You can specify geometry-related options for just the initial
frame by setting this variable in your init file; however, they
won't take effect until Emacs reads your init file, which happens
after creating the initial frame.  If you want the initial frame
to have the proper geometry as soon as it appears, you need to
use this three-step process:

* Specify X resources to give the geometry you want.
* Set `default-frame-alist' to override these options so that they
  don't affect subsequent frames.
* Set `initial-frame-alist' in a way that matches the X resources,
  to override what you put in `default-frame-alist'.

And this part of (elisp) Initial Parameters about the same option:

 If these settings affect the frame geometry and appearance, you'll
 see the frame appear with the wrong ones and then change to the
 specified ones.  If that bothers you, you can specify the same
 geometry and appearance with X resources; those do take effect
 before the frame is created.  *Note X Resources: (emacs)X
 Resources.

 X resource settings typically apply to all frames.  If you want to
 specify some X resources solely for the sake of the initial frame,
 and you don't want them to apply to subsequent frames, here's how
 to achieve this.  Specify parameters in `default-frame-alist' to
 override the X resources for subsequent frames; then, to prevent
 these from affecting the initial frame, specify the same
 parameters in `initial-frame-alist' with values that match the X
 resources.

If you mean only frames after the initial frame then see option default-frame-alist.

Both of these options let you configure any frame parameters, including font, so you can control the font size. (You can also customize face default.)

You can customize user options (M-x customize-option), but for these options you will need to be sure that your customizations take effect before the frame gets displayed.

  • I do mean the initial frame when emacs is first started, but this doesn't seem to answer my question at all. – b4hand Oct 16 '14 at 22:49
  • 1
    What part of this "doesn't seem to" answer your question? Did you try it? This is the method that both the Emacs and Elisp manuals prescribe for configuring the initial frame. – Drew Oct 17 '14 at 5:56
  • 1
    You dramatically edited your answer since I made that comment, and I had already read the emacs wiki related to initial-frame-alist as was mentioned in my question, so you provided no additional information. I did in fact try using initial-frame-alist and it did not solve my problem. In fact, my current solution doesn't involve modifying initial-frame-alist at all. – b4hand Oct 17 '14 at 18:09
  • 2
    Could I suggest a less prickly exchange, please? – Dan Oct 17 '14 at 19:00
  • 1
    Your Q did (& does) not mention user options. My "dramatic" editing of my answer was to add quotations from the Emacs doc that I referred you to at the outset, because you indicated that you did not understand how it related to your question ("doesn't seem to answer my question at all"). In the beginning, I expected that you might consult & learn from that doc, without my needing to quote pertinent parts from it. I added the quotations to help you understand the relation. What that doc provides is Emacs's recommendation of how to solve the problem. That does not mean it is the only approach. – Drew Oct 17 '14 at 20:23
2

This is essentially an addendum to Vamsi's answer which I have discovered after the fact.

From the documentation on initial-frame-alist, it says the following:

You can specify geometry-related options for just the initial frame by setting this variable in your init file; however, they won't take effect until Emacs reads your init file, which happens after creating the initial frame. If you want the initial frame to have the proper geometry as soon as it appears, you need to use this three-step process:

  • Specify X resources to give the geometry you want.
  • Set default-frame-alist to override these options so that they don't affect subsequent frames.
  • Set initial-frame-alist in a way that matches the X resources, to override what you put in default-frame-alist.

This implies that you must modify ~/.Xresources in order to get consistent behavior for the initial frame. Otherwise, the window bounces around on startup, which is the behavior that I'm seeing.

Just to round out my final solution.

I'm still using this in my init file:

(when window-system
  (set-frame-position (selected-frame) 0 0)
  (set-frame-size (selected-frame) 91 63))

As well as this:

(custom-set-faces
 '(default ((t (:inherit nil :stipple nil :background "white" :foreground "black" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 95 :width normal :foundry "unknown" :family "DejaVu Sans Mono")))))

But also setting this in my ~/.Xresources as pointed out by Vamsi:

Emacs.font: DejaVu Sans Mono-9.5

And being sure to run xrdb after the fact.

  • FWIW: This just repeats part of my answer. You didn't have to "discover" this "after the fact" - I pointed it out to you, before "the fact". You only commented that it "doesn't seem to answer my question at all." Sheesh. – Drew Oct 17 '14 at 15:17
  • 1
    It only repeats part of your answer after you edited it. – b4hand Oct 17 '14 at 18:15
  • 1
    My answer from the beginning was to "see option initial-frame-alist, if you want to customize the initial frame. And yes, I offered additional help. – Drew Oct 17 '14 at 20:04
1

In addition to the answers given so far, if your immediate goal is to make sure emacs opens up at the full height, you can set the fullscreen parameter of either the default-frame-alist or the initial-frame-alist, depending on whether or not you want all your frames to open at the full height, or just the first one:

(add-to-list 'initial-frame-alist '(fullscreen . fullheight))
(add-to-list 'default-frame-alist '(fullscreen . fullheight))
  • I wasn't aware of this fullheight setting, and it would be more convenient than manually finding the right value; however, one minor visual annoyance with fullheight over a specific value is that my screen height is not an even number of line heights, so it makes the minibuffer strangely sized and look funny. It also makes the frame difficult to resize manually in the window manager if I decide to change it by hand. – b4hand Oct 17 '14 at 0:47
0

The font size will affect the size of the window at startup, this problem occurred to me when I start to configure it for different screen resolution(home and work use, I put the configuration in Github) months ago. Actually, you can set the size of the window and font at the same time, here is the solution.


(defun set-frame-size-according-to-resolution ()
  (interactive)
  (if window-system
      (progn
        ;; use 120 char wide window for largish displays
        ;; and smaller 80 column windows for smaller displays
        ;; pick whatever numbers make sense for you
        (if (> (x-display-pixel-width) 1500)
            (setq default-frame-alist
                  '((top . 0)(left . 0)
                    (width . 85)(height . 48)
                    (font . "Menlo-13")
                    ))
          (setq default-frame-alist
                '((top . 0)(left . 0)
                  (width . 85)(height . 35)
                  (font . "Menlo-13")
                  )))
        ))
)
(set-frame-size-according-to-resolution)

Adjust the 1500, top/left width/height, font/font-size as you like. Remove the resolution related if you use only one (same resolution)screen, use only the setq default-frame-alist part.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.