1

I would like to set the frame position of the initial frame, by letting the user position the frame where he wants. I can then save the cons cell in a variable which will then be used for set-frame-position. Have started part of the implementation, but have to see how to get the two values form the cons returned by (frame-position).

(defun user-frame-position ()
  (interactive)
  (frame-position))

(defun initial-frame-position ()
  (interactive)
  (set-frame-position nil x y))

1 Answer 1

1

Just customize user option initial-frame-alist, to do whatever you want to that frame. C-h v tells me:

initial-frame-alist is a variable defined in frame.el.

Its value is ((bottom-divider-width . 2) (right-divider-width . 2))

Original value was nil

This variable can be risky when used as a file-local variable.

Documentation:

Alist of parameters for the initial X window frame.

You can set this in your init file; for example,

(setq initial-frame-alist
      '((top . 1) (left . 1) (width . 80) (height . 55)))

Parameters specified here supersede the values given in default-frame-alist.

If the value calls for a frame without a minibuffer, and you have not created a minibuffer frame on your own, a minibuffer frame is created according to minibuffer-frame-alist.

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.

You can customize this variable.

5
  • That's all and good, but I would like the user to physically set the frame to where exactly he wants without having him figure out the coordinates he wants and without him having to code any elisp. Commented Sep 15, 2022 at 4:30
  • Have noticed that when I invoke emacs again the cons obtained after the user calls user-frame-position are not stored. Commented Sep 15, 2022 at 4:57
  • Have noticed that setting fpcons after calling user-frame-position does not save value for the next invokation of emacs. (defvar fpcons (cons 8 8)) (defun user-frame-position () (setq typex-fpcons (frame-position))). Commented Sep 15, 2022 at 5:04
  • 1
    "... I would like the user to physically set the frame to where exactly he wants without having him figure out the coordinates he wants and without him having to code any elisp. ": what is stopping the user from moving/resizing the frame using the facilities provided by their DE/window manager? Commented Sep 16, 2022 at 3:10
  • It is a problem when one has multiple monitors and the user wants to always display the frame on some particular monitor without having to physically move the frame. Have made a function that allows the user to move an existing frame to a particular monitor, and the function will compute the position with which the frame is centered on the monitor. The frame then gets centered. I want it to be possible to save the position values so that for subsequent emacs sessions, the values will be used to position the frame on the same monitor for subsequent runs of emacs. Commented Sep 18, 2022 at 0:37

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.