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))
Dilna
  • 1,173
  • 3
  • 10

1 Answers1

0

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.

Drew
  • 75,699
  • 9
  • 109
  • 225
  • 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. – Dilna Sep 15 '22 at 04:30
  • Have noticed that when I invoke emacs again the cons obtained after the user calls `user-frame-position` are not stored. – Dilna Sep 15 '22 at 04: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)))`. – Dilna Sep 15 '22 at 05: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? – NickD Sep 16 '22 at 03: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. – Dilna Sep 18 '22 at 00:37