[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
reclaiming focus after `browse-url'
From: |
Sam Steingold |
Subject: |
reclaiming focus after `browse-url' |
Date: |
Wed, 29 Jun 2022 12:17:11 -0400 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin) |
Hi,
I wrote this code (mostly for hackernews on gnus where every article is
just 2 links):
--8<---------------cut here---------------start------------->8---
(defvar sds-reclaim-focus '(0)
"Cons cell (how-many-times . frame-to-give-focus-to).")
(defun sds-reclaim-focus ()
"Re-acquire OS input focus until `(car sds-reclaim-focus)' is 0.
Should be used, after calling 'browse-url' 5 times, as
(setq sds-reclaim-focus (cons 5 (selected-frame)))
(add-function :after after-focus-change-function #'sds-reclaim-focus)
it removes itself from 'after-focus-change-function'."
;; (message "sds-reclaim-focus %s %s" sds-reclaim-focus
;; (frame-focus-state (cdr sds-reclaim-focus)))
(unless (eq t (frame-focus-state (cdr sds-reclaim-focus)))
(x-focus-frame (cdr sds-reclaim-focus))
;; (message "focus grab %s" sds-reclaim-focus)
(if (zerop (car sds-reclaim-focus))
(remove-function after-focus-change-function #'sds-reclaim-focus)
(cl-decf (car sds-reclaim-focus)))))
(defun sds-gnus-summary-browse-all-urls ()
"Scan the current article body for links, and browse them."
(interactive)
(let ((urls (gnus-collect-urls-from-article)))
(dolist (url urls)
(browse-url url))
(setq sds-reclaim-focus (cons (length urls) (selected-frame))))
;; delete *Article* window, cf "=" bound to 'gnus-summary-expand-window'
(gnus-configure-windows 'summary 'force)
(add-function :after after-focus-change-function #'sds-reclaim-focus))
(with-eval-after-load "gnus-sum"
(define-key gnus-summary-mode-map "v" 'sds-gnus-summary-browse-all-urls))
--8<---------------cut here---------------end--------------->8---
It works when I have just _one_ frame, but with _2_ frames, the focus is
reclaimed to "the other" frame, not the `(cdr sds-reclaim-focus)`.
So, when I hit "v" in the *Summary* buffer, the 2 pages are opened in a
browser, but the OS focus goes to the 2nd frame, not to the *Summary* one.
The other one has the code above open with the point behind the
`x-focus-frame` form, so C-x C-e switches the focus to the correct frame.
(thus, `x-focus-frame' _works_).
I wonder what I am doing wrong, and, maybe, what others use for similar tasks...
Thank you very much!
--
Sam Steingold (https://youtube.com/channel/UCiW5WB6K4Fx-NhhtZscW7Og) on darwin
Ns 10.3.2113
http://childpsy.net http://calmchildstories.com http://steingoldpsychology.com
https://www.dhimmitude.org https://mideasttruth.com https://camera.org
There is a fine line between a numerator and a denominator.
- reclaiming focus after `browse-url',
Sam Steingold <=