Subject: Re: bug#11939: 24.1; `save-buffers-kill-emacs' loses minibuffer focuswhenit calls `list-processes'

From: martin rudalics <[email-masked]>
Date: Sun, 29 Jul 2012 15:56:04 +0200

>>  > And I think (still, so far) that that is the case because
 >>  > (somehow) the minibuffer frame got _selected_, and did not
 >>  > just have its input focus redirected to it.  And I think,
 >>  > a priori, that is not TRT.
 >>
 >> Yes.  But as long as we don't know how this happens there's
 >> not much we can do about it.
 >
 > I don't understand.  Your other message, sent at the same time as that one, said
 > that you know it is `yes-or-no-p' that does that, and that that is necessary.

I "know that `yes-or-no-p' does that, and that that is necessary" but I
do not know whether "it is `yes-or-no-p' that does that".  Only you
could find out by going through this with the debugger.

 >> Can't you try displaying in the mode-line of each
 >> window (1) that window (2) the selected window and (3) the current
 >> buffer.  So after redisplay we know which window is selected ...
 >
 > Can you tell me how to do that?

No.  I forgot that when displaying the modeline, its window is selected
and its buffer made current.  But the following unnecessarily complex
part of my setup displays the window number in the modeline.

(defun prettify (size-string pretty-string)
   "Prettify number by inserting dots."
   (if (> (length size-string) 3)
       (prettify (substring size-string 0 -3)
                 (concat "." (substring size-string -3) pretty-string))
     (concat size-string pretty-string)))

(defface mode-line-numbers
   '((t :family "Verdana"
        :weight bold))
   "Basic mode line face for selected window."
   :version "23.1"
   :group 'mode-line-faces)

(let* ((help-echo
         ;; The multi-line message doesn't work terribly well on the
         ;; bottom mode line...  Better ideas?
         ;;        "\
         ;; mouse-1: select window, mouse-2: delete others, mouse-3: delete,
         ;; drag-mouse-1: resize, C-mouse-2: split horizontally"
         "mouse-1: select (drag to resize), mouse-3: delete or split")
        (dashes (propertize "--" 'help-echo help-echo)))
   (setq-default mode-line-format
		(list
		 "%e"
		 (propertize " " 'help-echo help-echo)
		 'mode-line-mule-info
		 'mode-line-modified
		 (propertize " " 'help-echo help-echo)
		 'mode-line-buffer-identification
		 (propertize "   " 'help-echo help-echo)
		 'mode-line-position
		 '(vc-mode vc-mode)
		 (propertize "   " 'help-echo help-echo)
		 'mode-line-modes
		 `(which-func-mode ("" which-func-format ,dashes))
		 `(global-mode-string (,dashes global-mode-string))
		 (propertize " " 'help-echo help-echo)))

   (setq-default mode-line-modes
		(list
		 `(:propertize ("" mode-name)
			       help-echo "mouse-1: major mode menu   mouse-3: minor modes menu"
			       mouse-face mode-line-highlight
			       local-map ,mode-line-major-mode-keymap)
		 '("" mode-line-process)
		 `(:propertize ("" minor-mode-alist)
			       mouse-face mode-line-highlight
			       help-echo "mouse-1: minor mode menu  mouse-3: minor modes menu"
			       local-map ,mode-line-minor-mode-keymap)
		 (propertize "%n" 'help-echo "mouse-3: widen"
			     'mouse-face 'mode-line-highlight
			     'local-map (make-mode-line-mouse-map
					 'mouse-3 #'mode-line-widen))))

   (setq-default
    mode-line-position
    '(:eval (let ((help-echo "mouse-1: select (drag to resize), mouse-3: delete"))
	     `(10 ,(propertize
		    (concat "  %l  /  %c  /  "
			    (propertize
			     (prettify (format "%i" (point)) "")
			     'face 'mode-line-numbers)

			    (propertize
			     (concat		; WINDOW
			      (replace-regexp-in-string
			       ">" ""
			       (replace-regexp-in-string
				" on.+" ""
				(replace-regexp-in-string
				 "#<window " "#" (format "   %s" (selected-window)))))
			      (when (window-dedicated-p)
				"D")
			      )
			     'face 'mode-line-numbers)

			    "  ")
		    'face 'mode-line-numbers
		    'mouse-face 'mode-line-highlight
		    'help-echo help-echo))))))