From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tim Landscheidt Newsgroups: gmane.emacs.help Subject: Making browse-url-firefox more robust? Date: Fri, 04 Feb 2022 22:51:05 +0000 Organization: http://www.tim-landscheidt.de/ Message-ID: <87fsoyutye.fsf@vagabond.tim-landscheidt.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40551"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) To: help-gnu-emacs@gnu.org Cancel-Lock: sha1:KWsF1+norpENnCZW5Dr/2BJN/Kw= Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Feb 04 23:52:20 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 1nG7RE-000ANi-La for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 04 Feb 2022 23:52:20 +0100 Original-Received: from localhost ([::1]:52852 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nG7RC-0005fk-Qx for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 04 Feb 2022 17:52:19 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:51688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nG7QF-0005fN-GT for help-gnu-emacs@gnu.org; Fri, 04 Feb 2022 17:51:19 -0500 Original-Received: from ciao.gmane.io ([116.202.254.214]:41174) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nG7Q8-0002NO-U0 for help-gnu-emacs@gnu.org; Fri, 04 Feb 2022 17:51:19 -0500 Original-Received: from list by ciao.gmane.io with local (Exim 4.92) (envelope-from ) id 1nG7Q7-0008pk-HF for help-gnu-emacs@gnu.org; Fri, 04 Feb 2022 23:51:11 +0100 X-Injected-Via-Gmane: http://gmane.org/ Received-SPF: pass client-ip=116.202.254.214; envelope-from=geh-help-gnu-emacs@m.gmane-mx.org; helo=ciao.gmane.io X-Spam_score_int: -16 X-Spam_score: -1.7 X-Spam_bar: - X-Spam_report: (-1.7 / 5.0 requ) BAYES_00=-1.9, HEADER_FROM_DIFFERENT_DOMAINS=0.249, 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-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:135766 Archived-At: Hi, I have set browse-url-browser-function to 'browse-url-firefox (and browse-url-firefox-arguments to '("-P" "default")) and it works reasonably fine: I see a link in Gnus or elsewhere in Emacs, I click on it, the link opens in a new tab in Firefox. Where it becomes a nuisance is when I don't need to open one link, but many, for example generated by some database query or generator function: | (dotimes (i 100) | (browse-url (format "https://some.url/%d" i))) In this case, each call to browse-url launches a separate, memory-hungry Firefox instance which tries to connect to the initial instance and either succeeds or fails after some time in which my system is essentially unusable. So for situations where I anticipate a large number of URLs to be browsed, I replace the calls to browse-url with accu- mulating the URLs in a list and then executing: | (apply 'call-process "firefox" nil "*firefox*" nil urls) This works, but is rather distracting for (mapc #'browse-url (generate-urls)) oneliners in *scratch* or IELM. So I came up with: | (defvar accumulated-browse-url-timer nil | "Timer used for accumulating browsing URLs.") | (defvar accumulated-browse-url-urls nil | "Accumulated URLs to browse.") | (defun accumulated-browse-url (URL &rest ARGS) | "Browse URL accumulatedly." | (if accumulated-browse-url-timer | (cancel-timer accumulated-browse-url-timer)) | (push URL accumulated-browse-url-urls) | (setq accumulated-browse-url-timer | (run-with-idle-timer 5 nil | (lambda () | (apply | 'call-process | "firefox" | nil | "*firefox*" | nil | (reverse accumulated-browse-url-urls)) | (setq accumulated-browse-url-urls nil))))) which collects all URLs to be browsed until Emacs is idling for five seconds and then launch a single Firefox instance that then can communicate with the initial Firefox instance and open a new window. This works even better, but it does not solve the underlying problem in The Right Way™: It just thinks five seconds sure- ly must be enough instead of letting Firefox open the link(s) and then waiting for it to sort itself out (or wait- ing for Firefox to be "ready" and then open the link). Also, if one just wants to open one link, one has to wait (at least) those five seconds to look at the URL in Firefox. Are there other solutions to this problem that are more robust? TIA, Tim