7

When I maximize the Emacs frame, it uses the full width of the screen, no background showing. But if I e.g. snap-to-edge (in XFCE), it shows a little "margin" of background outside the frame. And if I drag to resize, it always over- or undershoots the edge – it looks like it wants to always resize by whole lines/characters. Is there a way to have a 50% size Emacs frame that aligns with the edge of the screen?

(I'm using 20170203:93058-ce88155-emacs-25.1~ubuntu16.04.1)

Mousepad can take exactly 50% width and 100%height, with height from the top of the screen down to the panel: mousepad can take exactly 50% width and 100%height

Emacs seems to overshoot/undershoot: emacs overshoots

emacs overshoots on the right too

When I "snap" Emacs to the edges with XFCE, it fits the width on my laptop, but not on my external monitor. It never matches the full height.

4
  • 2
    Have a look at display-pixel-width and display-pixel-height, set-frame-height, set-frame-width, set-frame-size, set-frame-position -- including the optional PIXELWISE argument for some of the functions : gnu.org/software/emacs/manual/html_node/elisp/… And, of course, the division / function -- i.e., just like a divorce (divide by two). If you want to set this at the outset, have a look at default-frame-alist, initial-frame-alist, and also certain paramaters that can be passed to the make-frame function. Emacs 25 handles this better.
    – lawlist
    Commented Feb 3, 2017 at 16:25
  • Based on your edit, it appears that you will need to get the bounds in exact pixels of your other windows (e.g., Mousepad) -- and then subtract that pixel width from the Emacs display-pixel-width in the answer below to come up with the exact Emacs frame size -- that assumes the Mousepad is flush right. Or you will need to get the left pixel bound of Mousepad and calculate accordingly. Emacs does not have any function that I am aware of that could search the screen for all other application windows that are present and attempt to adjust its size based on something like Mousepad.
    – lawlist
    Commented Feb 4, 2017 at 8:08
  • You could also just run a few tests by trial and error subtracting or adding a few pixels to the width value used by set-frame-width to come up with your perfect setting.
    – lawlist
    Commented Feb 4, 2017 at 8:11
  • I did, and did find the right width, but only after setting frame-resize-pixelwise, which solved the problem in general too :-)
    – unhammer
    Commented Feb 4, 2017 at 8:26

3 Answers 3

7

Reading C-h f set-frame-width as mentioned by user @lawlist, I saw a mention of frame-resize-pixelwise. Putting this in .emacs.d/init.el

(setq frame-resize-pixelwise t)

makes the window "snap" to the right height in XFCE (haven't tried on my external monitor yet, so don't know if it gets the exact right width too); it also snaps to the right height when I set the height with my wmctrl scripts.

1
  • 1
    Being the first Google answer for this question, I must add that I needed to restart emacs after inserting it to my init.el. Activating it inside the session was not enough.
    – Lalylulelo
    Commented Oct 19 at 7:47
2

Here is an example using some of the functions mentioned in the comment and link underneath the original question hereinabove:

(let ((frame (selected-frame))
      (one-half-display-pixel-width (/ (display-pixel-width) 2)))
  (set-frame-width frame one-half-display-pixel-width nil 'pixelwise)
  (set-frame-position frame 0 0))

FYI:  Feature request #21415 was incorporated into Emacs 25 -- frame creation may now include a pixel specification -- this includes items such as the initial-frame-alist, default-frame-alist, and the make-frame function.

Example of usage for the width parameter: '(width . (text-pixels . 1900))

Example of usage for the height parameter: '(height . (text-pixels . 1054))

1

Functions moom-fill-left and moom-fill-right in moom package resizes the frame to exactly half of the screen: https://github.com/takaxp/moom

4
  • Please clarify in which way this package answers the question. Link-only answers are not very valuable since the link may go stale.
    – Stefan
    Commented May 3, 2020 at 4:38
  • In addition to explaining your answer in more detail, please do not post duplicate answers to multiple questions.
    – Dan
    Commented May 3, 2020 at 9:32
  • 1
    Modified the answer to reply the question.
    – AhLeung
    Commented May 4, 2020 at 5:27
  • However, moom also resizes the fonts (which on my 4k monitor makes them "huge"). Moom-fill-left also resizes the screen height, which means on WSL the windows task bar covers the emacs echo area. Commented Jul 19, 2021 at 14:19

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.