From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Sam Steingold Newsgroups: gmane.emacs.help Subject: reclaiming focus after `browse-url' Date: Wed, 29 Jun 2022 12:17:11 -0400 Message-ID: Reply-To: sds@gnu.org Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7963"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (darwin) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Jun 29 21:21:13 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o6dFO-0001oU-2m for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Jun 2022 21:21:10 +0200 Original-Received: from localhost ([::1]:49828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6dFM-0006nE-Rs for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 29 Jun 2022 15:21:08 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:45580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o6aNS-0004s2-JB for help-gnu-emacs@gnu.org; Wed, 29 Jun 2022 12:17:18 -0400 Original-Received: from mail-qv1-xf33.google.com ([2607:f8b0:4864:20::f33]:39874) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o6aNP-0004v9-Ec; Wed, 29 Jun 2022 12:17:17 -0400 Original-Received: by mail-qv1-xf33.google.com with SMTP id cs6so25527909qvb.6; Wed, 29 Jun 2022 09:17:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:from:to:subject:user-agent:return-receipt-to:reply-to:date :message-id:mime-version; bh=+w6jIGaDUNHQvu9SBoDlcj1IugZuzua0KQf1TwUnhAk=; b=qTzwoWgkZgxofhs0KXyCPR4J9+WGb4ZqfCDjYVIyNYK8XwlpGsmjDduEFgqWFfvFxE eLZlz0v0+onbTorUsPReTbwzgpRvRAKLTvUM8YPRMKlN5kRsJ10iHcE2RHFkfJouq6yk Ba6ejCspTS6FWU7WiXB46ELhr1lmibu3wj3lUj3j1RfF86NFjsSnrfTRXaA83DDNcU3/ 64Ce1+RKHgzj3El42u4BTnUeQQMsOa9+WM3Aaj9XZiRwho1SwnKX30NRM6V63x8fevTP xOLbQm0Lk+6hSyskJ0YXrbDgrprJcODuQGiAgC3B+S/G8SPCNseSVBvwgbEMu/5rQ9a5 8tuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:from:to:subject:user-agent :return-receipt-to:reply-to:date:message-id:mime-version; bh=+w6jIGaDUNHQvu9SBoDlcj1IugZuzua0KQf1TwUnhAk=; b=AdEHqLj1+zgn/EQtdxhRiTIgRsC3KZEJCwdVG+9C2SWZgV0PhGTCGDZn5uXmS+N5k+ c/kJv8l1/CdXc7QSQRDgbpzzMYCUXayBRd1uSLTtPnwvFJTBo83KgNt9t+uAnXg5bK0D VslecmEU55Vylijq7TkBVqVdRDIAbRXB/RXTEE7hr5pzYpQXhNY2JtawtVEjs6bk4Gtj haSjjShogfaa7iIngMsnESX2DbRqD28Bbm0w7ozGZrHQ7Not74KprBA8a1ocu3mrBAHo 6m1iF7gXJmi8YDW/80K0gAk7pm+poPEBTNpu6YqyfRCEf3qKFdmHeHlxXEy5uNrf7y80 aTWg== X-Gm-Message-State: AJIora8hWS11F/1g9vbfTHgoftU6m27qc4UNNr7MwJXBpnMcRdK2SP0v xejHNgJKiQF+4JMfqXXar6maqkYeYg== X-Google-Smtp-Source: AGRyM1vUqRAz+52jXDa7p80OGtcKII1NIUO/iK42URnVz+hSrWK16v3j3zdeAVdqk1ZPYyVyE1/UcQ== X-Received: by 2002:a05:6214:1c85:b0:443:8347:d7a5 with SMTP id ib5-20020a0562141c8500b004438347d7a5mr8545853qvb.11.1656519433400; Wed, 29 Jun 2022 09:17:13 -0700 (PDT) Original-Received: from 3c22fb11fdab.ant.amazon.com ([63.144.131.106]) by smtp.gmail.com with ESMTPSA id h4-20020a05620a284400b006a787380a5csm14020308qkp.67.2022.06.29.09.17.12 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 29 Jun 2022 09:17:12 -0700 (PDT) X-Attribution: Sam X-Disclaimer: You should not expect anyone to agree with me. Received-SPF: pass client-ip=2607:f8b0:4864:20::f33; envelope-from=sam.steingold@gmail.com; helo=mail-qv1-xf33.google.com X-Spam_score_int: -14 X-Spam_score: -1.5 X-Spam_bar: - X-Spam_report: (-1.5 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.249, FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Wed, 29 Jun 2022 15:14:42 -0400 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:138204 Archived-At: 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.