Colourful Emacs messages
When displaying a little message to help understand why my code doesn't work, a little colour can go a long way to breaking up a lengthy line.
Yesterday, I shared a tiny snippet I use to display processes I run inside Emacs.
start-file-process
will return an error if it can’t find a process we’re
trying to start, but the same can’t be said for this alternative version where I
send individual keys to libvterm.
;;;###autoload
(defun +vterm/devenv-up ()
"Run \"devenv up\" in the current project using vterm."
(interactive)
(projectile-with-default-dir (projectile-ensure-project (projectile-project-root))
(if (executable-find "devenv")
(progn
(require 'vterm)
(defvar vterm-buffer-name "*devenv-up*")
(vterm)
(with-current-buffer vterm-buffer-name
(mapcar (lambda (c) (vterm-send-key (char-to-string c))) "devenv up")
(vterm-send-return)))
(message "%s %s"
(propertize "+vterm/devenv-up:" 'face '(:inherit font-lock-constant-face))
"devenv not found"))))
The trick I’m sharing today, is use of propertize
to format the message
returned when the devenv
executable can’t be found by Emacs (before we type in
the command and simulate hitting return).
One can inherit styles or set their own and attach those styles to the string using properties.
(propertize "Some string" 'face '(:inherit font-lock-constant-face))