2

In my init.el I have the below setting for the initial frame position:

(setq default-frame-alist
    '((top . 80) (left . 300) (width . 85) (height . 45)))

When I open a file in a new frame, it overlaps the previous frame.

How do I set the position of the new frame to be, for example, x width and y height from the previous frame?

This is so that the new frame will not overlap with the previous frame and all open frames (windows) will be clearly visible.

  • Put your initial parameters in initial-frame-alist, and then put different values in default-frame-alist. The first frame created at startup will use the former, and then all others will use the latter. – Dan Apr 2 at 18:58
  • @Drew: yup, you're right. Reading comprehension fail on my part. – Dan Apr 2 at 19:13
  • @Dan, I did try your suggestion as well. What I did was have some values in initial-frame-alist and different (offset) values in default-frame-alist. The first emacs frame and next frame (on doing C-x 5 2 once) are offset, but doing C-x 5 2 again makes the second and third frame overlap, and so on. – Saurabh Apr 2 at 19:33
2
  1. Define a function that you use to create the frame, which does what you want with respect to positioning.

  2. Define whatever commands you want that make use of that function. For example, define a command that you use in place of find-file-other-frame (C-x 5 f), define a command that you use in place of make-frame-command (C-x 5 2).

The function for #1 just calls make-frame, passing the top and left values you want, in the optional second arg, PARAMETERS.

Presumably, you want those top and left values to be calculated from their values in the currently selected-frame.

For example:

(defun make-offset-frame (&optional x y)
  "..."
  (let* ((params  (frame-parameters))
         (ctop    (or (cdr (assoc 'top params))   0))
         (cleft   (or (cdr (assoc 'left params))  0)))
    (setq x  (or x  30)
          y  (or y  30))
    (make-frame (append `((top . ,(+ ctop y)) (left . ,(+ cleft x)))
                        default-frame-alist))))


(defun my-make-frame-command (&optional x y)
  "..."
  (interactive)
  (make-offset-frame x y))

(global-set-key (kbd "C-x 5 2") 'my-make-frame-command)
| improve this answer | |
  • Doing C-x 5 2 does create a new frames offset from the previous frame, but their size is not 80 by 45. Is there a way I could have the new frames the same size of the initial frame? – Saurabh Apr 2 at 19:30
  • 1
    Updated to use default-frame-alist for the other parameters, besides left and top. – Drew Apr 2 at 21:15
0

Use a tiling window manager such as i3 or StumpWM.

| improve this answer | |
  • I think OP wanted an Emacs-based solution that does not require the use of a different window manager. – Dan Apr 8 at 15:40
  • Of course you may be right, @Dan. No way of knowing unless/until Saurabh says. – Phil Hudson Apr 9 at 17:42

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.