3

I would like all frames to overlap at (1,1). Yet with a .emacs containing

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

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

calling C-x 5 2 results in frames in a cascade, as you see in the figure.

emacs-frames

How can I force all frames to be anchored at the same place?

I am running Emacs 23.3.1 on OS X (Mountain Lion).

itsjeyd
  • 5,070
  • 2
  • 30
  • 49
Calaf
  • 10,113
  • 15
  • 57
  • 120

1 Answers1

4

The settings are not being ignored. The reason you see the above behaviour is due to a before-make-frame-hook in ns-win.el that adds 25 to top and left.

To avoid the above effect you can add the following to your .emacs file:

(setq default-frame-alist '((left . 0) (top . 0) (width . 80) (height . 55)))
(defvar parameters)
(add-hook 'before-make-frame-hook 
  (lambda ()
    (let ((left (cdr (assq 'left (frame-parameters))))
      (top (cdr (assq 'top (frame-parameters)))))
      (setq parameters (cons (cons 'left (+ left 0))
                     (cons (cons 'top (+ top 0))
                       parameters))))))

If the above doesn't work you can try the following which is taken from ns-win.el before-make-frame-hook.

(setq default-frame-alist '((left . 0) (top . 0) (width . 80) (height . 55)))

(defvar parameters)
(add-hook 'before-make-frame-hook
  (lambda ()
    (let ((left (cdr (assq 'left (frame-parameters))))
          (top (cdr (assq 'top (frame-parameters)))))
      (if (consp left) (setq left (cadr left)))
      (if (consp top) (setq top (cadr top)))
      (cond
       ((or (assq 'top parameters) (assq 'left parameters)))
       ((or (not left) (not top)))
       (t
         (setq parameters (cons (cons 'left (+ left 0))
                   (cons (cons 'top (+ top 0))
                     parameters))))))))
xmonk
  • 535
  • 6
  • 13
  • Your second suggestion fixes it. That's all that matters. Though it's strange for this baroque code to be necessary. (Your first suggestion didn't work for me.) Thanks! – Calaf May 11 '13 at 13:53
  • The second portion is taken from ns-win.el code, the code in said file has `(+ left 25)` and `(+ top 25)` instead of 0. Which has the effect of every time you make a new frame, it adds 25 to the values of top and left. I believe this was changed in emacs24 to behave as expected. – xmonk May 11 '13 at 14:04
  • Either of your two solutions works with Emacs 23.4 and Emacs 24.3. Sadly, neither works with the candidate release for 24.4, currently 24.3.91.1. This last one does handle some other things that don't work on 23.4/24.3. Though the discrepancy is now by just a few vertical (y) pixels. – Calaf Jul 14 '14 at 17:47
  • Things has changed quite a bit for Emacs 24.4 though this works for me in 24.4: (set-frame-position (selected-frame) 0 0) I also use this to set the frame in 24.4 as I want, and works with 24.3.91 as well: https://github.com/xmonk/emacs.d/blob/master/site-lisp/frames.el#L61-L96 – xmonk Jul 23 '14 at 13:52
  • I'm not sure which 24.4 you refer to. It's released for neither OS X nor even Linux. On 24.3.91.1 using a .emacs with (set-frame-position (selected-frame) 0 0) (setq initial-frame-alist '((left-fringe . 0) (right-fringe . 0) (tool-bar-mode . nil) (top . 0) (left . 0))) (setq default-frame-alist '((left-fringe . 0) (right-fringe . 0) (tool-bar-mode . nil) (top . 0) (left . 719))) makes C-x 5 2 generate frames with a large x offset. – Calaf Jul 28 '14 at 15:17
  • Emacs 24.4 is the development version you can get the pre-tests and the latest bleeding edge for OS X here: http://emacsformacosx.com/builds – xmonk Aug 13 '14 at 15:33