Álvaro Ramírez
Open Emacs elfeed links in the background
Christopher Wellons's elfeed is a wonderful Emacs rss reader. In Mike Zamansky's Using Emacs 72 - Customizing Elfeed video, he highlights a desire to open elfeed entries in the background. That is, open the current rss entry (or selected entries) without shifting focus from Emacs to your browser. This behaviour is somewhat analogous to ⌘-clicking/ctrl-clicking on multiple links in the browser without losing focus.
I've been wanting elfeed to open links in the background for some time. Zamansky's post was a great nudge to look into it. He points to the relevant elfeed-search-browse-url function, re-implemented to suit his needs. In a similar spirit, I wrote a function to open the current rss entry (or selected entries) in the background.
I'm running macOS, so I took a look at browse-url-default-macosx-browser to get an idea of how URLs are opened. Simple. It let's macOS handle it via the "open" command, invoked through start process. Looking at open's command-line options, we find –background which "does not bring the application to the foreground."
open --background http://xenodium.com
"b" is already bound to elfeed-search-browse-url, so in our snippet we'll bind "B" to our new background function, giving us some flexibility:
(use-package elfeed :ensure t :bind (:map elfeed-search-mode-map ("B" . ar/elfeed-search-browse-background-url)) :config (defun ar/elfeed-search-browse-background-url () "Open current `elfeed' entry (or region entries) in browser without losing focus." (interactive) (let ((entries (elfeed-search-selected))) (mapc (lambda (entry) (assert (memq system-type '(darwin)) t "open command is macOS only") (start-process (concat "open " (elfeed-entry-link entry)) nil "open" "--background" (elfeed-entry-link entry)) (elfeed-untag entry 'unread) (elfeed-search-update-entry entry)) entries) (unless (or elfeed-search-remain-on-entry (use-region-p)) (forward-line)))))
Maybe xdg-open does a similar thing on linux (I've not looked). Ping me if you have a linux solution and I can update the function.
Happy Emacsing.
ps. I noticed elfeed uses browse-url-generic if elfeed-search-browse-url's is invoked with a prefix. Setting browse-url-generic-program and browse-url-generic-args to use background options may be a more generic solution. For now, a custom function does the job.
comments on twitter.