DEV Community

Victor Dorneanu
Victor Dorneanu

Posted on • Originally published at blog.dornea.nu on

Read Hackernews and Reddit the Emacs way

Motivation

Usually when I consume my daily news feeds, 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 and using tools like elfeed and pocket-reader 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 and 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 and reddiggto read and navigate through even the most complex Hackernews and Reddit threads, all without ever having to leave the comfort of Emacs.

hnreader

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

image

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

image

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

(hnreader-readpage-promise "https://news.ycombinator.com/item?id=34482433")
Enter fullscreen mode Exit fullscreen mode

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

image

(hnreader-promise-comment "https://news.ycombinator.com/item?id=34482433")
Enter fullscreen mode Exit fullscreen mode

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

image

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))))

Enter fullscreen mode Exit fullscreen mode
Show HN comments for an URL at point

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))))

Enter fullscreen mode Exit fullscreen mode
Opens new buffer when called from the elfeed-search buffer

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
      ;; ...)

Enter fullscreen mode Exit fullscreen mode
Key bindings for elfeed-search-mode
(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
      ;; ...)

Enter fullscreen mode Exit fullscreen mode
Key bindings for elfeed-show-mode

reddigg

reddigg is the similar solution for reddit. When invoked directly you have these options:

image

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

image

(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)))

Enter fullscreen mode Exit fullscreen mode

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)))

Enter fullscreen mode Exit fullscreen mode
Show reddit comments from within elfeed

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
      ;; ...

Enter fullscreen mode Exit fullscreen mode
Key bindings for reddigg

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

image

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.

Top comments (0)