Subject: RE: bug#7533: 24.0.50; `dired-mark-pop-up': delete frame afterwards if `pop-up-frames'

From: "Drew Adams" <[email-masked]>
Date: Thu, 5 Apr 2012 13:23:46 -0700

> From: Stefan Monnier Sent: Friday, December 03, 2010 12:27 PM
> > Here I have two things: A window parameter that tells for 
> > each window whether the current buffer is the first buffer
> > shown in it and a separate global variable which gives some
> > rudimentary information about what the last `display-buffer'
> > invocation did to find a suitable window.
> 
> Indeed.  We currently have display-buffer-mark-dedicated which goes in
> this direction, but uses dedicatedness, which is not always
> desired, apparently.
> 
> I think that adding a "buffer for which this window was 
> created" window parameter and always set it in display-buffer
> (regardless of display-buffer-mark-dedicated) should allow
> correct handling of such situations.

This regression is still not fixed.  There was a lot of dancing around and
singing about new ways of handling buffer display and windows (vs old-fashioned
`pop-up-frames' etc.).  But the new ways were added to Emacs and this regression
still remains.

emacs -Q

(setq special-display-regexps '("[ ]?[*][^*]+[*]"))
(setq pop-up-frame t)

C-x d whatever-dir

Mark 4 files for deletion.  Hit `x'.  Answer `yes'.

The *Deletions* frame remains displayed.

At the beginning of this thread I offered some code that at least handles this
case fine, AFAICT.  Actually, I forgot a prog1.  Here it is again...   The only
difference from what is in Emacs is the last two lines, which delete the frame
when done.  That's all I'm asking for: please delete the frame that you pop up.

(defun dired-mark-pop-up (bufname op-symbol files function &rest args)
  "..."
  (or bufname (setq bufname  " *Marked Files*"))
  (if (or (eq dired-no-confirm t)
	  (memq op-symbol dired-no-confirm)
	  ;; If FILES defaulted to the current line's file.
	  (= (length files) 1))
      (apply function args)
    (with-current-buffer (get-buffer-create bufname)
      (erase-buffer)
      ;; Handle (t FILE) just like (FILE), here.
      ;; That value is used (only in some cases), to mean just one
      ;; file that was marked, rather than the current line file.
      (dired-format-columns-of-files
        (if (eq (car files) t) (cdr files) files))
      (remove-text-properties (point-min) (point-max)
			      '(mouse-face nil help-echo nil)))
    (save-window-excursion
      (dired-pop-to-buffer bufname)
      (prog1 (apply function args)
        (if (one-window-p) (delete-frame) (delete-window))))))

Yes, it is no doubt true that `save-window-excursion' is inappropriate when used
with code displaying a buffer, as Martin pointed.  Yes, there might be other
things inappropriate or inelegant here.  But it works for the use case of the
bug report at least, and Emacs 24 -Q does not work for that case.

Again, I do not really care how this bug is fixed.  But please fix it.