Emacs Tip of the Day

Getting NEWS

Emacs, as I’m sure you know, has a fantastic culture of documentation and self discovery. Every release is accompanied with a NEWS file describing every meaningful change, only a C-h n away.

That means there is a function to open the latest news file view-emacs-news.

If you look at the definition, you will see you can even view the NEWS for previous Emacs versions, going all the way back to v18. Even Emacs “pre-history” is documented in an aggregated NEWS.1-17 file! You will also notice however, that the logic for getting the filepath to the NEWS file is embedded within the same function that calls find-file on it, so there’s no way to get one without the other.

Or is there? *cue VSauce music*…

emacs lisp/alc-dashboard.el
(defun alc-dashboard--get-news-buffer (&optional version)
  "Return the Emacs news buffer for the given VERSION"
  (let ((display-buffer-overriding-action
           '((display-buffer-no-window)
             (allow-no-window . t))))
    (view-emacs-news version)
    (buffer-name)))

By setting display-buffer-overriding-action we can suppress the default find-file behaviour and force the file to be opened in the background.

Broadcasting NEWS

From here we can play all sorts of tunes, just to name a few

  • Pull random items from a random Emacs version (uniformly)

  • Pull random items from a random Emacs version (weighted by release date)

  • Pull items from NEWS sections we really care about (e.g. Emacs has N irc clients, you’re likely to use only one).

  • Add options to mark items as read so they are not repeated.

  • Favourite items

  • and so on…

However, writing a fully comprehensive tip of the day package is not what I’m looking to do right now, I just want a prompt to nudge me in the direction of something potentially interesting.

You may have noticed I named the module for this code alc-dashboard.el, and while it may grow into a fancy dashboard, like those you see in Doom Emacs or similar I don’t even want to do that yet. Emacs already comes with an minimally viable dashboard

You mean about-emacs (C-h C-a)?

No, not even that, the *scratch* buffer!

You can customize the initial-scratch-message variable so why not set it to display a random news item? Let’s write one more function to format the news item as a single string

emacs lisp/alc-dashboard.el
(require 's)

(defun alc-dashboard-news-item-to-string (item)
  "Format the given news item as a string"
  (concat ";; "
    (s-join "\n;; "
      (s-split "\n"
        (format "%s\n-- %s" (car item) (cadr item))))))

Perhaps there’s a nicer way to format the news item (perhaps somehow filling with a given fill-prefix?) but this is what my current elisp skills can do.

Anyway it seems to do the job and we can use it to set the initial scratch message each time Emacs starts up.

emacs init.el
(use-package alc-dashboard
  :ensure nil
  :config (setq initial-scratch-message
                (alc-dashboard-news-item-to-string (alc-dashboard-get-news-item))))
tmux 33 |*scratch* x| +                                                                       |*scratch* x| +                                                                           1 ;; *** ’completion-category-overrides’ supports more metadata.     1 ;; *** Eshell now uses ’field’ properties in its output.      2 ;; The new supported completion properties are ’cycle-sort-function’,     2 ;; In particular, this means that pressing the ’<home>’ key moves the      3 ;; ’display-sort-function’, ’annotation-function’, ’affixation-function’,     3 ;; point to the beginning of your input, not the beginning of the whole      4 ;; and ’group-function’.  You can now customize them for any category in     4 ;; line.  If you want to go back to the old behavior, add something like      5 ;; ’completion-category-overrides’ that will override the properties     5 ;; this to your configuration:      6 ;; defined in completion metadata.     6 ;;     7 ;;    7 ;;     (keymap-set eshell-mode-map "<home>" #’eshell-bol-ignoring-prompt)      8 ;; -- ** Minibuffer and Completions     8 ;;     9 ;;    9 ;; This also means you no longer need to adjust ’eshell-prompt-regexp’    10 ;; when customizing your Eshell prompt.     11 ;;    12 ;; -- ** Eshell     13 ;;  -  (lisp-interaction-mode)*scratch* 3:3                                             -  (lisp-interaction-mode)*scratch* 13:3                                                                                         │ [1] 0:emacs*                                                                                                                                   "emacs -nw ~" 12:43 11-Sep-26

And for about 50 lines of elisp I’m happy with that! 😁