all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Making browse-url-firefox more robust?
@ 2022-02-04 22:51 Tim Landscheidt
  2022-02-05  1:41 ` Emanuel Berg via Users list for the GNU Emacs text editor
  2022-04-06  0:50 ` Felix Dietrich
  0 siblings, 2 replies; 4+ messages in thread
From: Tim Landscheidt @ 2022-02-04 22:51 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-06  0:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-04 22:51 Making browse-url-firefox more robust? Tim Landscheidt
2022-02-05  1:41 ` Emanuel Berg via Users list for the GNU Emacs text editor
2022-04-05 23:07   ` TRS-80
2022-04-06  0:50 ` Felix Dietrich

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.