From: "Óscar Fuentes" <ofv@wanadoo.es>
To: help-gnu-emacs@gnu.org
Subject: Re: select-frame-set-input-focus operates on wrong frame
Date: Tue, 15 Oct 2024 03:25:49 +0200 [thread overview]
Message-ID: <875xpuw40y.fsf@telefonica.net> (raw)
In-Reply-To: 87a5f6wwy7.fsf@telefonica.net
Ó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)
next prev parent reply other threads:[~2024-10-15 1:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-14 15:01 select-frame-set-input-focus operates on wrong frame Óscar Fuentes
2024-10-15 1:25 ` Óscar Fuentes [this message]
2024-10-19 16:43 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-10-20 12:51 ` Óscar Fuentes
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=875xpuw40y.fsf@telefonica.net \
--to=ofv@wanadoo.es \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).