Read Hackernews and Reddit the Emacs way
Tags: emacs, elisp, reddit, productivity
Published: 2023-05-11 21:03:29

---
title: Read Hackernews and Reddit the Emacs way
published: true
date: 2023-04-21 05:14:42 UTC
tags: emacs, elisp, reddit, productivity
canonical_url: https://blog.dornea.nu/2023/04/21/read-hackernews-and-reddit-the-emacs-way/
---

## Motivation

Usually when I consume my daily [news feeds](/2022/06/13/rss-and-atom-for-digital-minimalists/), I prefer to keep context switching to a minimum. Whether you’re a busy professional or just someone who values their time, you might want to streamline your online reading experience as much as possible. For me, this means sticking to [Emacs](https://brainfck.org/t/emacs) and using tools like [elfeed and pocket-reader](/2022/06/29/rss/atom-emacs-and-elfeed/) to stay on top of my reading list.

Unfortunately, this approach doesn’t work with content served within comments at Hackernews or Reddit, where you usually have lots of comments and discussion threads. This is where I began to struggle, as I found myself bouncing back and forth between Emacs and my browser in order to stay on top of the conversation.

Luckily, I’ve found [hnreader](https://github.com/thanhvg/emacs-hnreader) and [reddigg](https://github.com/thanhvg/emacs-reddigg) which have changed the way I consume content on these platforms. These packages are specifically designed to help you navigate and read through Hackernews and Reddit threads directly from within Emacs, saving you from the hassle of constantly switching between different apps and tabs.

In my opinion these are the most underrated packages and in this post I’d like to show you how they can help you improve your reading experience. By the end of this post, you’ll have a better understanding of how to use [hnreader](https://github.com/thanhvg/emacs-hnreader) and [reddigg](https://github.com/thanhvg/emacs-reddigg)to read and navigate through even the most complex Hackernews and Reddit threads, all without ever having to leave the comfort of [Emacs](https://brainfck.org/t/emacs).

## hnreader

Without any customizations you can use `hnreader` straightaway. Currently you have following options:

![image](https://blog.dornea.nu/posts/img/2023/hnreader-reddigg/hnreader-functions.png)

Invoking each function will return a buffer with the latest 30 posts in that category:

![image](https://blog.dornea.nu/posts/img/2023/hnreader-reddigg/hnreader-top-posts.png)

Let’s have a look how we can add customized behaviour.

### Basic functions

The easiest way to show comments for a thread ID is to use

```emacs-lisp
(hnreader-readpage-promise "https://news.ycombinator.com/item?id=34482433")
```

This will create a new buffer and load the _readpage_ for that specific HN URL

![image](https://blog.dornea.nu/posts/img/2023/hnreader-reddigg/hnreader-readpage-buffer.png)

```emacs-lisp
(hnreader-promise-comment "https://news.ycombinator.com/item?id=34482433")
```

This will create a new buffer and load all comments from this specific Hackernews thread:

![image](https://blog.dornea.nu/posts/img/2023/hnreader-reddigg/hnreader-comments-buffer.png)

### elfeed integrations

Whenever you have a Hackernews specific link inside your buffer you may want to open it using:

```
(defun my/elfeed-hn-show-comments-at-point ()
  "Show HN comments for an URL at point"
  (interactive)
  (setq-local hnreader-view-comments-in-same-window t)
  (hnreader-comment (format "%s" (url-get-url-at-point))))

```

<figcaption align = "center"><b>Show HN comments for an URL at point</b></figcaption>

You can of course call a function from the `elfeed-search` buffer to show the HN threads:

```
(defun my/elfeed-hn-show-commments (&optional link)
  (interactive)
  (let* ((entry (if (eq major-mode 'elfeed-show-mode)
                    elfeed-show-entry
                  (elfeed-search-selected :ignore-region)))
         (link (if link link (elfeed-entry-link entry))))
    (setq-local hnreader-view-comments-in-same-window nil)
    (hnreader-promise-comment (format "%s" link))))

```

<figcaption align = "center"><b>Opens new buffer when called from the elfeed-search buffer</b></figcaption>

And these are my `elfeed` related keybindings:

```
(map! :map elfeed-search-mode-map
      :after elfeed-search
      [remap kill-this-buffer] "q"
      [remap kill-buffer] "q"
      :n doom-leader-key nil
      ;; ...
      :n "H" #'my/elfeed-hn-show-commments
      ;; ...)

```

<figcaption align = "center"><b>Key bindings for elfeed-search-mode</b></figcaption>

```
(map! :map elfeed-search-mode-map
      :after elfeed-show
      [remap kill-this-buffer] "q"
      [remap kill-buffer] "q"
      :n doom-leader-key nil
      ;; ...
      :n "H" #'my/elfeed-hn-show-comments-at-point
      ;; ...)

```

<figcaption align = "center"><b>Key bindings for elfeed-show-mode</b></figcaption>

## reddigg

[reddigg](https://github.com/thanhvg/emacs-reddigg) is the similar solution for reddit. When invoked directly you have these options:

![image](https://blog.dornea.nu/posts/img/2023/hnreader-reddigg/reddigg-functions.png)

After invoking `reddigg-view-frontpage` you’ll get a new buffer with the last posts:

![image](https://blog.dornea.nu/posts/img/2023/hnreader-reddigg/reddigg-frontpage.png)

```
(defun my/elfeed-reddit-show-commments (&optional link)
  (interactive)
  (let* ((entry (if (eq major-mode 'elfeed-show-mode)
                    elfeed-show-entry
                  (elfeed-search-selected :ignore-region)))
         (link (if link link (elfeed-entry-link entry))))
    (reddigg-view-comments link)))

```

### elfeed integration

We can also use `reddigg` to show reddit threads from within an `elfeed` buffer

```
(defun my/elfeed-reddit-show-commments (&optional link)
  (interactive)
  (let* ((entry (if (eq major-mode 'elfeed-show-mode)
                    elfeed-show-entry
                  (elfeed-search-selected :ignore-region)))
         (link (if link link (elfeed-entry-link entry))))
    (reddigg-view-comments link)))

```

<figcaption align = "center"><b>Show reddit comments from within elfeed</b></figcaption>

And my related keybindings:

```
(map! :map elfeed-search-mode-map
      :after elfeed-search
      [remap kill-this-buffer] "q"
      [remap kill-buffer] "q"
      :n doom-leader-key nil
      ;; ...
      :n "R" #'my/elfeed-reddit-show-commments
      ;; ...

```

<figcaption align = "center"><b>Key bindings for reddigg</b></figcaption>

When invoked you’ll get an ORG mode styled buffer with all the comments for a specific reddit thread:

![image](https://blog.dornea.nu/posts/img/2023/hnreader-reddigg/reddigg-comments.png)

## Conclusion

I hope you’re as enthusiastic as I am. And if you have any better alternatives, please don’t hesitate to let me know in the comments.