11

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")))))
7
  • 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
    Commented Oct 16, 2014 at 23:21
  • @Vamsi Yes, that does solve my problem. I'm using "DejaVu Sans Mono", but otherwise this does work as expected.
    – b4hand
    Commented Oct 16, 2014 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
    Commented Oct 16, 2014 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
    Commented Oct 16, 2014 at 23:45
  • In that case, an alternative would be just call emacs --font="DejaVu Sans Mono-12".
    – Vamsi
    Commented Oct 16, 2014 at 23:49

6 Answers 6

5

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"
2
  • 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
    Commented Oct 17, 2014 at 0:13
  • 1
    Oops forgot this. You need to reload your X environment. You can use xrdb ~\.Xresources at the command line.
    – Vamsi
    Commented Oct 17, 2014 at 0:15
5

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.

3
  • 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
    Commented Oct 17, 2014 at 15:17
  • 1
    It only repeats part of your answer after you edited it.
    – b4hand
    Commented Oct 17, 2014 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
    Commented Oct 17, 2014 at 20:04
3

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.

7
  • 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
    Commented Oct 17, 2014 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
    Commented Oct 17, 2014 at 18:09
  • 3
    Could I suggest a less prickly exchange, please?
    – Dan
    Commented Oct 17, 2014 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
    Commented Oct 17, 2014 at 20:23
  • 1
    @cYrus: I'm no expert on emacs -nw; sorry. Maybe check the doc, starting with Non-Window Terminals and Initial Parameters. I suggest you pose a separate question that gets to what you want to know about this case. No doubt someone will be able to help with that.
    – Drew
    Commented Jul 10, 2019 at 15: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))
1
  • 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
    Commented Oct 17, 2014 at 0:47
1

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.

0

I'm running GNU Emacs 25.1.1 on Windows 10.

This works for me:

In the ~/.emacs file, I put:

(when window-system
  (set-frame-position (selected-frame) 0 550) ;; 0 - left edge at left of monitor; 550 - top about halfway down the monitor
  (set-frame-size (selected-frame) 115 13)) ;; 115 - width full width of monitor; 13 - puts bottom at top of taskbar

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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