In describing my move to Helm, I quickly mentioned another package from Thierry Volpiatto: psession. psession is a light session saving mechanism and it comes with built-in integration for Helm among other things, which of course renders it a valuable improvement to my setup. The installation instructions are pretty clear, so there is no need to bother you with obvious code snippets.

Instead, I want to bother you with my obsessive-compulsive disorder. You see, I am fond of how my beloved text editor looks, especially after boot. I disabled every message, toolbar, scrollbar, menu, and buffer Emacs can throw at me on startup, and the theme is applied as late as possible to ensure nothing obstructs my way to another great day of text editing.

What’s “wrong” with psession then? In order to make the previous sessions available, psession loads some compiled files when Emacs starts. This is what I expect it to do, because there would be no point in saving sessions without restoring them. My only “problem” with this behaviour is the file loading itself.

(cl-defun psession--restore-objects-from-directory
(&optional (dir psession-elisp-objects-default-directory))
(let ((file-list (directory-files dir t directory-files-no-dot-files-regexp)))
(cl-loop for file in file-list do (and file (load file)))))


The code is not hard to understand. What constitutes a rude attack at my delicate aesthetic feelings is that (load file) right before the good-looking closing parentheses. Calling load in this manner causes a bunch of messages to “interfere” with a clean Emacs boot: they show up in the echo area during the loading of my init.el and they hurt so bad!1

Let’s examine the documentation of the function load:

Signature

(load FILE &optional NOERROR NOMESSAGE NOSUFFIX MUST-SUFFIX)

Documentation

Execute a file of Lisp code named FILE.

[…]

Print messages at start and end of loading unless optional third arg NOMESSAGE is non-nil (but force-load-messages overrides that).

[…]

Perfect. Now I just have to hack psession--restore-objects-from-directory and make sure load is called with a non-nil value for NOMESSAGE. Usually when I want to silence a command I rely on inhibit-message. Let’s say I want to silence the activation of helm-adaptive-mode:

(let ((inhibit-message t))


However, psession--restore-objects-from-directory is sort of a private function, so I need something else to change it according to my plans. There are probably several good ways to patch psession--restore-objects-from-directory, but my go-to package in these situations is Radon Rosborough’s el-patch.

(el-patch-feature psession)

Note that at the moment of this writing, el-patch-cl-defun is on the develop branch of el-patch. See here to know more about this and to laugh at my poor reading skills.