Replacing beacon.el with hl-line-flash

Table of Contents

Intro

img

  • EDIT [2021-09-27 Mon]: decreased hl-line-flash-show-period1

I learned about beacon.el2 in one of Sacha Chua’s videos3 that asted users about their favorite tweaks, and it remained one that I found useful throughout several years with emacs. However, it stopped working somewhere in version 27, with a number of glitches that were eventually recognized in the repo, but no fix was available.

Beacon candy

Beacon was nice because it didn’t highlight the whole line, but only a gradient extending from your cursor, which would gently fade away (at least, that was the idea). In a sense it was a triumph of a cool UI effect that had the actual benefit of helping locate your cursor quickly if you are shifting buffers. Unfortunately, as the emacs old-guard themselves warn in the development of emacs itself, over-much attention to visual candy can have its drawbacks. I suppose this was something else that Beacon demonstrated, as emacs core changes caused it to misbehave in several ways.

using hl-line+

It has been quite a while since I used Beacon. Today, though, I found mysely again having to spend a moment to find my cursor in my typical many-window emacs usage. Going through my options I noticed an auspiciously titled function that came along with Drew Adams’ 4hl-line+ package5. Then, with a little glimpse into the beacon code, I found which hooks I wanted and now I have the nutritional version of beacon going, satisfying the business proposition of locating my line after I’ve switched over while still getting the visual effect out of the way if I stop to read.6

Why not just highlight the line?

Previously I had been using global-hl-line-mode all the time, starting it up in my init. It uses the same color and will highlight the same area as this solution – so why bother with a blink? There are two reasons.

  1. blinking is different than a constant highlight – the fact that it uses an event other than just a constant triggers something in the brain, making it more noticeable and distinctive, but without breaking my flow.

  2. The beauty of ceasing to highlight. While the highlight itsely doesn’t paint over existing colorizations, one of the points of using colorization (eg of variables) is to be able to match them or see patterns in an area. This simply works better when you get a highlight line out of the way, since blue52 with a black background is different than blue52 with a different background. This should make sense to anyone who DOESN’T use column highlighting.

    These facts also apply to beacon, but the advantage of hl-line+ was that I already had it, and it is using simpler (= more stable, robust) mechanisms than is beacon.

The Code

using straight use-package, here:

(use-package hl-line+
  :hook
  (window-scroll-functions . hl-line-flash)
  (focus-in . hl-line-flash)
  (post-command . hl-line-flash)

  :custom
  (global-hl-line-mode nil)
  (hl-line-flash-show-period 0.5)
  (hl-line-inhibit-highlighting-for-modes '(dired-mode))
  (hl-line-overlay-priority -100) ;; sadly, seems not observed by diredfl
  )

Footnotes

1 after a day, I reazied that for me it was much more effective to have the flash duration value set at half a second instead of a full second, so it is about the same as my cursor blink. All the reasons I mention for having a flash are more strongly pronounced with a shorter flash.

2 Beacon hasn’t been updated in years, but you can find it here: https://github.com/Malabarba/beacon . Note all the issues and the stagnant pull requests, sadly. It demontstrated good use of hooks and cleaning up after itself.

3 The video was a while ago, http://youtu.be/A4uunJOltj8?t=1h21m0s as linked from the actual announcement page on her site: https://sachachua.com/blog/2015/11/2015-11-18-emacs-hangout/ .

4 All of Drew Adams’ work is fantastically valuable for upgrading the emacs experience. At least, the ones I’ve tried: bookmarks+, dired+, and highlight+. I recommend them all.

5 Acquiring Drew Adam’s stuff is sometimes an unusual effort since he doesn’t seem to maintain a Git* presence. But it is mirrored here: https://github.com/emacsmirror/hl-line-plus

6 I find the rhythm and cadence of having a responsive line that disappears to be helpful and a little comforting, not unlike the blinking of my cursor I choose to retain. It tells me that my emacs still has a pulse, and is breathing healthy.

Tory Anderson avatar
Tory Anderson
Full-time Web App Engineer, Digital Humanist, Researcher, Computer Psychologist