I’ve been diving/digging into the oh-so-excellent Rails Tutorial, by Michael Hartl, and am into chapter 3, where testing begins.
Imagine my surprise — go ahead, imagine it — when my Emacs mode line changed color.
Originally:
And when I ran “bundle exec rake test”, it succeeded with:
Then changing the test code to fail, after running “bundle exec rake test” again:
Tracking down this code, I found that the guard-notiffany gem was doing this behavior, sending a change to the Emacs mode line via emacsclient, with this bit of code in lib/notiffany/notifier/emacs.rb:
def notify(color, bgcolor)
elisp = <<-EOF.gsub(/\s+/, " ").strip
(set-face-attribute 'mode-line nil
:background "#{bgcolor}"
:foreground "#{color}")
EOF
emacs_eval(elisp)
end
The issue there was that it just changes the mode line “permanently”. I’d prefer that the mode line colors change for a moment, then time out and revert to their previous settings.
I wrote a bit of code to do this, and modified lib/notiffany/notifier/emacs.rb locally, but there is a pending pull request that has a better implementation.
However, my hack is:
def notify(color, bgcolor)
elisp = "(let ((orig-bg (face-attribute 'mode-line :background))"
elisp << " (orig-fg (face-attribute 'mode-line :foreground)))"
elisp << " (set-face-attribute 'mode-line nil"
elisp << " :background \"#{bgcolor}\""
elisp << " :foreground \"#{color}\")"
elisp << " (sit-for 3)"
elisp << " (set-face-attribute 'mode-line nil"
elisp << " :background orig-bg"
elisp << " :foreground orig-fg))"
emacs_eval(elisp)
end
The sit-for
keeps the mode line as red or green for 3 seconds or when there is Emacs input. I prefer that, to clear the mode line more quickly, since I find the bright color distracting.