From: Tim Landscheidt <tim@tim-landscheidt.de>
To: help-gnu-emacs@gnu.org
Subject: Making browse-url-firefox more robust?
Date: Fri, 04 Feb 2022 22:51:05 +0000 [thread overview]
Message-ID: <87fsoyutye.fsf@vagabond.tim-landscheidt.de> (raw)
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
next reply other threads:[~2022-02-04 22:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-04 22:51 Tim Landscheidt [this message]
2022-02-05 1:41 ` Making browse-url-firefox more robust? 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
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87fsoyutye.fsf@vagabond.tim-landscheidt.de \
--to=tim@tim-landscheidt.de \
--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.
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.