[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: select-frame-set-input-focus operates on wrong frame
From: |
Óscar Fuentes |
Subject: |
Re: select-frame-set-input-focus operates on wrong frame |
Date: |
Tue, 15 Oct 2024 03:25:49 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) |
Óscar Fuentes <ofv@wanadoo.es> writes:
> I have a frame named "pdf" to view files opened via emacsclient. This
> code shows those files on the "pdf" frame (if it exists) when
> `emacsclient -n somefile' is invoked:
>
>
> (defun ofv-display-buffer-pop-up-frame (buffer &rest alist)
> (unless (catch 'out
> (dolist (frame (frame-list))
> (when (and (equal (frame-parameter frame 'display)
> (frame-parameter nil 'display))
> (string= "pdf" (frame-parameter frame 'name)))
> (with-selected-frame frame
> (select-frame-set-input-focus frame)
> (display-buffer-full-frame buffer '())
> (throw 'out t)))))
> (display-buffer-full-frame buffer alist)))
>
> (setq server-window 'ofv-display-buffer-pop-up-frame)
>
>
> This works except select-frame-set-input-focus raises and sets focus to
> the frame that had the focus before emacsclient was invoked.
>
> I guess that the code that processes the emacsclient request in Emacs
> sets the focus after the function contained in server-window is
> invoked. How can I avoid this?
The problem consists on the semantics of with-selected-frame: it
restores the selected frame, so changing focus to the other frame inside
with-selected-frame is futile.
This version of the code works:
(defun ofv-display-buffer-pop-up-frame (buffer &rest alist)
(let ((f (cl-find-if (lambda (frame)
(and (equal (frame-parameter frame 'display)
(frame-parameter nil 'display))
(string= "pdf" (frame-parameter frame 'name))))
(frame-list))))
(when f
(select-frame-set-input-focus f))
(display-buffer-full-frame buffer '())))
(setq server-window 'ofv-display-buffer-pop-up-frame)