Subject: 24.3.50; REGRESSION: `after-make-frame-functions' now run with wrong frame selected

From: Drew Adams <[email-masked]>
Date: Mon, 19 Aug 2013 08:01:20 -0700 (PDT)

This regression was introduced after a build from 2013-08-08.  It
appears in the build cited below, from 2013-08-18.  It makes Emacs
unusable (by me).

I have this as `after-make-frame-functions': `(fit-frame)', in order to
fit the new frame to its displayed buffer.'

When `after-make-frame-functions' is run in `make-frame' now, the
original frame, not the newly created frame, is selected when it runs.
So `fit-frame' is called with the original (wrong) frame selected.

Here is a snapshot from the debugger:

Debugger entered--entering a function:
* fit-frame(#<frame drews-lisp-20 036212e0>)
* run-hook-with-args(fit-frame #<frame drews-lisp-20 036212e0>)
* (let* ((display (cdr (assq (quote display) parameters))) (w (cond ((assq =
(quote terminal) parameters) (let ((type ...)) (cond (... nil) (... ...) (t=
 type)))) ((assq (quote window-system) parameters) (cdr (assq (quote window=
-system) parameters))) (display (or (window-system-for-display display) (er=
ror "Don't know how to interpret display \"%S\"" display))) (t window-syste=
m))) (frame-creation-function (cdr (assq w frame-creation-function-alist)))=
 (oldframe (selected-frame)) (params parameters) frame) (if frame-creation-=
function nil (error "Don't know how to create a frame on window system %s" =
w)) (if (get w (quote window-system-initialized)) nil (funcall (cdr (assq w=
 window-system-initialization-alist)) display) (setq x-display-name display=
) (put w (quote window-system-initialized) t)) (progn (let ((--dolist-tail-=
- (cdr (assq w window-system-default-frame-alist))) p) (while --dolist-tail=
-- (setq p (car --dolist-tail--)) (if (assq (car p) params) nil (setq param=
s (cons p params))) (setq --dolist-tail-- (cdr --dolist-tail--))))) (progn =
(let ((--dolist-tail-- default-frame-alist) p) (while --dolist-tail-- (setq=
 p (car --dolist-tail--)) (if (assq (car p) params) nil (setq params (cons =
p params))) (setq --dolist-tail-- (cdr --dolist-tail--))))) (run-hooks (quo=
te before-make-frame-hook)) (setq frame (funcall frame-creation-function pa=
rams)) (normal-erase-is-backspace-setup-frame frame) (progn (let ((--dolist=
-tail-- frame-inherited-parameters) param) (while --dolist-tail-- (setq par=
am (car --dolist-tail--)) (if (assq param parameters) nil (let ((val ...)) =
(if val (progn ...)))) (setq --dolist-tail-- (cdr --dolist-tail--))))) (run=
-hook-with-args (quote after-make-frame-functions) frame) frame)
* (lambda (&optional parameters) "Return a newly created frame displaying t=
he current buffer.\nOptional argument PARAMETERS is an alist of frame param=
eters for\nthe new frame.  Each element of PARAMETERS should have the\nform=
 (NAME . VALUE), for example:\n\n (name . STRING)	The frame should be named=
 STRING.\n\n (width . NUMBER)	The frame should be NUMBER characters in widt=
h.\n (height . NUMBER)	The frame should be NUMBER text lines high.\n\nYou c=
annot specify either `width' or `height', you must specify\nneither or both=
.\n\n (minibuffer . t)	The frame should have a minibuffer.\n (minibuffer . =
nil)	The frame should have no minibuffer.\n (minibuffer . only)	The frame s=
hould contain only a minibuffer.\n (minibuffer . WINDOW)	The frame should u=
se WINDOW as its minibuffer window.\n\n (window-system . nil)	The frame sho=
uld be displayed on a terminal device.\n (window-system . x)	The frame shou=
ld be displayed in an X window.\n\n (display . \":0\")     The frame should=
 appear on display :0.\n\n (terminal . TERMINAL)  The frame should use the =
terminal object TERMINAL.\n\nIn addition, any parameter specified in `defau=
lt-frame-alist',\nbut not present in PARAMETERS, is applied.\n\nBefore crea=
ting the frame (via `frame-creation-function-alist'),\nthis function runs t=
he hook `before-make-frame-hook'.  After\ncreating the frame, it runs the h=
ook `after-make-frame-functions'\nwith one arg, the newly created frame.\n\=
nIf a display parameter is supplied and a window-system is not,\nguess the =
window-system from the display.\n\nOn graphical displays, this function doe=
s not itself make the new\nframe the selected frame.  However, the window s=
ystem may select\nthe new frame according to its own rules." (interactive) =
(let* ((display (cdr (assq (quote display) parameters))) (w (cond ((assq (q=
uote terminal) parameters) (let (...) (cond ... ... ...))) ((assq (quote wi=
ndow-system) parameters) (cdr (assq ... parameters))) (display (or (window-=
system-for-display display) (error "Don't know how to interpret display \"%=
S\"" display))) (t window-system))) (frame-creation-function (cdr (assq w f=
rame-creation-function-alist))) (oldframe (selected-frame)) (params paramet=
ers) frame) (if frame-creation-function nil (error "Don't know how to creat=
e a frame on window system %s" w)) (if (get w (quote window-system-initiali=
zed)) nil (funcall (cdr (assq w window-system-initialization-alist)) displa=
y) (setq x-display-name display) (put w (quote window-system-initialized) t=
)) (progn (let ((--dolist-tail-- (cdr (assq w window-system-default-frame-a=
list))) p) (while --dolist-tail-- (setq p (car --dolist-tail--)) (if (assq =
(car p) params) nil (setq params (cons p params))) (setq --dolist-tail-- (c=
dr --dolist-tail--))))) (progn (let ((--dolist-tail-- default-frame-alist) =
p) (while --dolist-tail-- (setq p (car --dolist-tail--)) (if (assq (car p) =
params) nil (setq params (cons p params))) (setq --dolist-tail-- (cdr --dol=
ist-tail--))))) (run-hooks (quote before-make-frame-hook)) (setq frame (fun=
call frame-creation-function params)) (normal-erase-is-backspace-setup-fram=
e frame) (progn (let ((--dolist-tail-- frame-inherited-parameters) param) (=
while --dolist-tail-- (setq param (car --dolist-tail--)) (if (assq param pa=
rameters) nil (let (...) (if val ...))) (setq --dolist-tail-- (cdr --dolist=
-tail--))))) (run-hook-with-args (quote after-make-frame-functions) frame) =
frame))(nil)
* apply((lambda (&optional parameters) "Return a newly created frame displa=
ying the current buffer.\nOptional argument PARAMETERS is an alist of frame=
 parameters for\nthe new frame.  Each element of PARAMETERS should have the=
\nform (NAME . VALUE), for example:\n\n (name . STRING)	The frame should be=
 named STRING.\n\n (width . NUMBER)	The frame should be NUMBER characters i=
n width.\n (height . NUMBER)	The frame should be NUMBER text lines high.\n\=
nYou cannot specify either `width' or `height', you must specify\nneither o=
r both.\n\n (minibuffer . t)	The frame should have a minibuffer.\n (minibuf=
fer . nil)	The frame should have no minibuffer.\n (minibuffer . only)	The f=
rame should contain only a minibuffer.\n (minibuffer . WINDOW)	The frame sh=
ould use WINDOW as its minibuffer window.\n\n (window-system . nil)	The fra=
me should be displayed on a terminal device.\n (window-system . x)	The fram=
e should be displayed in an X window.\n\n (display . \":0\")     The frame =
should appear on display :0.\n\n (terminal . TERMINAL)  The frame should us=
e the terminal object TERMINAL.\n\nIn addition, any parameter specified in =
`default-frame-alist',\nbut not present in PARAMETERS, is applied.\n\nBefor=
e creating the frame (via `frame-creation-function-alist'),\nthis function =
runs the hook `before-make-frame-hook'.  After\ncreating the frame, it runs=
 the hook `after-make-frame-functions'\nwith one arg, the newly created fra=
me.\n\nIf a display parameter is supplied and a window-system is not,\ngues=
s the window-system from the display.\n\nOn graphical displays, this functi=
on does not itself make the new\nframe the selected frame.  However, the wi=
ndow system may select\nthe new frame according to its own rules." (interac=
tive) (let* ((display (cdr (assq (quote display) parameters))) (w (cond ((a=
ssq (quote terminal) parameters) (let (...) (cond ... ... ...))) ((assq (qu=
ote window-system) parameters) (cdr (assq ... parameters))) (display (or (w=
indow-system-for-display display) (error "Don't know how to interpret displ=
ay \"%S\"" display))) (t window-system))) (frame-creation-function (cdr (as=
sq w frame-creation-function-alist))) (oldframe (selected-frame)) (params p=
arameters) frame) (if frame-creation-function nil (error "Don't know how to=
 create a frame on window system %s" w)) (if (get w (quote window-system-in=
itialized)) nil (funcall (cdr (assq w window-system-initialization-alist)) =
display) (setq x-display-name display) (put w (quote window-system-initiali=
zed) t)) (progn (let ((--dolist-tail-- (cdr (assq w window-system-default-f=
rame-alist))) p) (while --dolist-tail-- (setq p (car --dolist-tail--)) (if =
(assq (car p) params) nil (setq params (cons p params))) (setq --dolist-tai=
l-- (cdr --dolist-tail--))))) (progn (let ((--dolist-tail-- default-frame-a=
list) p) (while --dolist-tail-- (setq p (car --dolist-tail--)) (if (assq (c=
ar p) params) nil (setq params (cons p params))) (setq --dolist-tail-- (cdr=
 --dolist-tail--))))) (run-hooks (quote before-make-frame-hook)) (setq fram=
e (funcall frame-creation-function params)) (normal-erase-is-backspace-setu=
p-frame frame) (progn (let ((--dolist-tail-- frame-inherited-parameters) pa=
ram) (while --dolist-tail-- (setq param (car --dolist-tail--)) (if (assq pa=
ram parameters) nil (let (...) (if val ...))) (setq --dolist-tail-- (cdr --=
dolist-tail--))))) (run-hook-with-args (quote after-make-frame-functions) f=
rame) frame)) nil)
* make-frame(nil)
  (lambda nil (make-frame pop-up-frame-alist))()
  display-buffer-pop-up-frame(#<buffer autofit-frame.el> ((inhibit-same-win=
dow . t)))
  display-buffer--maybe-pop-up-frame-or-window(#<buffer autofit-frame.el> (=
(inhibit-same-window . t)))
  display-buffer(#<buffer autofit-frame.el> t)
  pop-to-buffer(#<buffer autofit-frame.el> t nil)
  switch-to-buffer-other-window(#<buffer autofit-frame.el>)
  find-file-other-window("~/drews-lisp-20/autofit-frame.el" WILDCARDS)

In GNU Emacs 24.3.50.1 (i686-pc-mingw32)
 of 2013-08-17 on ODIEONE
Bzr revision: 113938 [email-masked]
Windowing system distributor `Microsoft Corp.', version 6.1.7601
Configured using:
 `configure --prefix=3D/c/Devel/emacs/binary --enable-checking=3Dyes,glyphs
 CFLAGS=3D-O0 -g3 LDFLAGS=3D-Lc:/Devel/emacs/lib
 CPPFLAGS=3D-Ic:/Devel/emacs/include'