2019-02-10 Making recover-this-file messages more prominent

When I start my Emacs, I visit all my agenda files automatically (of course, I set up the org-agenda-files variable first).

This has an annoying side effect. When I visit a file interactively, and Emacs detects that an autosave file exists for the file I’m visiting, it suggests using M-x recover-this-file. When I visit files during my init.el execution, these messages get lost in the *Messages* buffer, and it is easy to forget to check the autosave data. (This normally should not happen, since Emacs asks about saving all unsaved files before exiting. Sometimes, though, my Emacs gets killed for some reasons, and then it’s a problem.)

Of course, I could call recover-file for all the offending files automatically. Too much automation without informing the user is not necessarily the best option, however. I decided that I want to make the warnings much more prominent, and the simple method I used may be general enough to be potentially useful for other people as well. Here’s the code I have at the end of my init.el.

(defun show-initial-important-messages (regex)
  "Show all lines in *Messages* matching REGEX."
  (let* ((messages (with-current-buffer "*Messages*"
		     (buffer-string)))
	 (important
	  (with-temp-buffer
	    (insert messages)
	    (delete-non-matching-lines regex (point-min) (point-max))
	    (buffer-string))))
    (when (> (length important) 0)
      (with-output-to-temp-buffer " *Important messages from the init file*"
	(princ important)))))
(show-initial-important-messages "recover-this-file")

I guess that the code is pretty much self-explanatory; if not, check out the docstrings of all the relevant functions.

Now I can see all the messages about unsaved buffers when I start Emacs. (I can easily add other messages, too – time will tell if this is going to be useful.)

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryOrgMode