How to Use Emacs for RSS with Elfeed

Emacs Rss 00 Featured Image

Emacs is a very extensible piece of software. It can be your text editor, your email client and even your USENET reader. With Elfeed, you can also use Emacs as your RSS feed reader.

Also read: 5 of the Best RSS Reader Apps for macOS

What Is Elfeed?

Elfeed is a lightweight yet powerful RSS feed reader written for Emacs. It uses a simple tag-based system to sort your RSS feeds. Not only that, it also comes with a powerful “hook-based” tagging system that allows you to automatically tag feeds based on their content.

Emacs Rss 02 Elfeed Summary

This makes Elfeed useful for people who are following plenty of RSS feeds and are looking for a way to automatically sort their feeds.

Also read: How to Use Emacs to Play Music with EMMS

Why Use a Feedreader in Emacs?

Emacs works in the notion of interoperability, as Emacs takes data and allows it to be interpreted in various different ways.

Emacs Rss 03 Emacs Interoperability

While you can use Emacs to exclusively edit text, being able to access your email while editing text, for example, can allow you to seamlessly use the text you are writing in the email you are composing.

Emacs Rss 04 Emacs Email Rss

This is why incorporating your RSS feed reader into Emacs can be enticing. It would allow you to use Emacs’s powerful editing capabilities to manipulate your feeds and other functions in Emacs.

Installing Elfeed on Emacs

Installing Elfeed is really simple. It is available from the GNU ELPA repository, so you can access it without any modifications in your init.el file.

Emacs Rss 05 Elfeed Installed

To install Elfeed, press Alt + X to bring up the command buffer, then type package-install. You have to provide elfeed as the package name and press Enter. Emacs will download Elfeed’s source code and compile it immediately afterward.

Setting Up Your First RSS Feed in Emacs

With that installed, access Elfeed by pressing Alt + X and typing elfeed in the command buffer. Doing this will load an empty Elfeed buffer.

Emacs Rss 06 Elfeed Clean

There are two ways to add an RSS feed to Elfeed:

  • Manually edit your init.el file
  • Without Emacs

Adding an RSS Feed Manually in Elfeed

You can easily populate Elfeed by manually adding the feed URLs in your init.el file, as Elfeed has an “elfeed-feeds” variable it tracks. This tells Elfeed which feeds to fetch and display in its overview screen.

For example, this is a snippet from my init.el file.

(setq elfeed-feeds
       '("https://feeds.maketecheasier.com/MakeTechEasier"
        "https://solar.lowtechmagazine.com/feeds/all-en.atom.xml"
        "https://old.reddit.com/r/f1technical.rss"))

Setq is an Emacs function that sets the value of a particular variable. In this case, it is setting the elfeed-feeds variable with three feed links as values.

From there, Elfeed will automatically add those links into its internal database, then load the next time you run the program.

Emacs Rss 07 Elfeed With Feeds

Adding an RSS Feed within Emacs

Another way of populating Elfeed is by giving it feed links while it is running. This allows you to actively update your feed roster with RSS links without reloading Emacs.

To do this, press Alt + X to open the command buffer. Type elfeed-add-feed and press Enter. Elfeed will ask you to provide the URL of the feed that you want to load.

Emacs Rss 08 Url Zoom

In my case, I am providing our feed URL to Elfeed to receive daily updates on the latest technology articles.

I copy the feed URL and press Ctrl + Y in the URL prompt to paste the link to Emacs. Once pasted, I just need to press Enter to commit the feed URL to Elfeed.

Emacs Rss 09 Maketecheasier Feeds

Also read: How to Easily Rename Files in Linux

How to Automatically Tag and Filter Feeds in Emacs

Aside from listing and viewing RSS feeds, Elfeed can also perform a number of functions that will allow you to finely tune your feed list.

One of those neat functions is automatic tagging. This feature allows you to immediately tag RSS entries that came from a specific feed.

For example, if you have multiple feeds about a certain topic, you can set so that they will all have the same tag, making it easy and intuitive to sort through multiple feeds in the summary screen.

To do this, edit the RSS feeds in your init.el file. Take a look at this brief example.

(setq elfeed-feeds
 '(("https://feeds.maketecheasier.com/MakeTechEasier" tech news)
   ("https://solar.lowtechmagazine.com/feeds/all-en.atom.xml" tech)
   ("https://old.reddit.com/r/f1technical.rss" tech f1)))

To automatically tag an RSS feed, you need to do two things to your default elfeed-feeds format:

  • Enclose the feed link in parentheses. This tells elfeed-feeds that this specific entry in the variable has multiple parts.
  • Provide a word that will act as your tag for that particular link. You can include multiple tags as long as you separate each of them with a space.
Emacs Rss 10 Automatically Tagged Feeds

Filtering Your RSS Feed in Elfeed

These tags work in conjunction with Elfeed’s powerful filtering system. This allows you to group your RSS feeds based on tags alone.

For example, if you have RSS feeds tagged as “news,” “news tech” and “news gaming,” Elfeed allows you to group all of them under the “news” tag.

To filter your feed list, press S while in Elfeed to bring up Elfeed’s filter prompt. By default, the prompt contains the following:

@6-months-ago +unread
  • The @ symbol indicates a date range. This could be an absolute date such as “2022-02-22” or a relative one such as “3-days-ago.”
  • The “+” symbol is a tag operator that tells Elfeed to explicitly include all feeds that have this tag.
Emacs Rss 11 Default Filter

With that in mind, consider the following RSS feed.

[0](setq elfeed-feeds
[1] '(("https://feeds.maketecheasier.com/MakeTechEasier" tech news)
[2]   ("https://solar.lowtechmagazine.com/feeds/all-en.atom.xml" tech)
[3]   ("https://old.reddit.com/r/f1technical.rss" tech f1)
[4]   ("https://www.autosport.com/rss/f1/photos/" f1)
[5]   ("https://www.philstar.com/rss/world" news)))

To filter the “tech” tag, type “+tech” in Elfeed’s filter prompt to display the first three links in Elfeed’s summary buffer. However, if you add “+news,” Elfeed will display the first and fifth tag instead.

Knowing this, you can be more specific with your filtering logic. For example, if you want to include all tech links but without “f1,” you can type the following:

+tech -f1

How to Automatically Tag Feeds Based on URL

Another way to automatically tag RSS entries in Elfeed is to sort them based on URL. This is useful if you are using Elfeed to subscribe to RSS feeds that have a similar URL structure.

Emacs Rss 12 Medium Webpage

To do that, use Elfeed’s elfeed-new-entry-hook. This is a hook function that executes a custom command based on specific conditions. This function will run a custom command every time an entry is added using the elfeed-add-feed command.

You can use the elfeed-make-tagger function within that hook. This is a general function that tags links based on options that you set. As such, combining the two functions to create automatic tagging can look something like this:

(add-hook 'elfeed-new-entry-hook
        (elfeed-make-tagger :feed-url "medium\\.com"
                            :add '(medium)))
Emacs Rss 13 Medium Feed

That function will automatically tag any link that will contain the slug “medium.com.”

You can also be more specific with the options that you set with elfeed-make-tagger. For example, you can both tag a feed based on the URL and filter out entries that are older than three months:

(add-hook 'elfeed-new-entry-hook
        (elfeed-make-tagger :feed-url "medium\\.com"
                            :before "3 months ago"
                            :add 'medium))

How to Create Custom Colors and Fonts for Tags

Aside from automatic tagging, you can also customize how Elfeed looks based on the tag it is dealing with. This is useful if you want feeds with a specific tag to stand out.

Emacs Rss 14 Custom Faces

To do that, you need to redefine the elfeed-search-face-alist function. This is the command that Elfeed uses to change the appearance of the summary buffer. As such, to redefine this function, you can use the defface and push functions:

  • The defface function creates a new “face” for Emacs. The “face” is a set of values that can contain both character fonts and background colors.
  • The push function, on the other hand, appends a definition to an existing command in Emacs.

With that in mind, you can combine these functions to create a custom “face” for Elfeed. For example, this is a custom face that highlights the f1 tag in red.

(defface elfeed-face-tag-f1
  '((t :foreground "#f00"))
  "This is a custom font face for the F1 tag in Elfeed.")
 
(push '(f1 elfeed-face-tag-f1)
      elfeed-search-face-alist)

Congratulations! You now know how to use Emacs as an RSS reader with Elfeed. Furthermore, you also now have a basic idea of how to customize and automate Elfeed to suit your RSS feeds’ needs.

If all this discussion made you think of what you can do more with Emacs, you can check out our article on the best productivity packages for Emacs.

Also read: How to Fix Can’t Type in Terminal Issue in Linux

Frequently Asked Questions

1. How can I delete a feed in Elfeed?

You can remove a feed in two ways: delete the feed’s entry in your init.el file or use Emacs’s customize function to remove it.

For the former, removing a feed is just a matter of deleting the feed URL in your elfeed-feeds variable. For the latter, however, you need to press Alt + X to open the command buffer. From here, you need to type customize. This will open the customize window for Emacs.

From there, type elfeed-feeds in the search box. This will bring all of the feeds that you are currently subscribed to.

This allows you to delete a feed by clicking on the DEL buttons beside the feed link. Once done, you can click the Apply and Save buttons below the search bar to update your feed.

2. What can I do if I add all my feeds in Elfeed and they don’t refresh?

Elfeed does not automatically refresh the feed links for you. To fetch the latest entries in your feeds, press Shift + G to initiate an update on all the currently-subscribed feeds.

Further, if you want to only update a specific RSS feed, run the elfeed-update-feed function.

3. My automatic tags don’t seem to work. How can I solve this?

This is most probably because you have conflicting tags for the same RSS feed. That can happen if you have included the same feed URL in both your manual and automatic feeds.

To solve this, you have to remove either your manual entry in your init.el file or the automatic feed entry in Emacs’s customize buffer.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Ramces Red
Ramces Red - Staff Writer

Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.