dbordak / telephone-line

A new implementation of Powerline for Emacs
GNU General Public License v3.0
556 stars 51 forks source link

Optionally don't render segments if they are empty? #114

Open Olivia5k opened 4 years ago

Olivia5k commented 4 years ago

I want to highlight when I have unread mail in the modeline. Doing so was easy;

(telephone-line-defsegment th/telephone-email-segment ()
  (let ((alert mu4e-alert-mode-line))
    (when (and (telephone-line-selected-window-active) alert)
      (propertize (format "%sm" (substring-no-properties alert 7 -2))
                  'face 'font-lock-function-name-face))))

20200505 235144-dragonisle

However, when I don't have any email (or when I don't have any un-diminished minor modes, like whitespace-mode as ws in the screenshot above) the separators for the segments are still rendered;

20200505 235202-dragonisle

This might be a bit of a fringe use case, but I'd like to not have them rendered at all if they don't contain anything. The minor mode list is fine, but the red for the email alert is literally designed to catch my eye. If it's there when I don't need it, I'll passively train my brain to not react to it, and then it's suddenly kind of pointless to have it there in the first place.

I didn't dig too much into the code yet, but I'm thinking it probably doesn't require too much wizardry to make it an optional thing to render the separators if the content inside of them is empty. Would that be possible? No biggie at all if it's not, I just wanted to check!

(Also, cheers for a neat package that I've been using for years and that has caused literally zero seconds of trouble! :+1:)

dbordak commented 4 years ago

It's intentional that the segments don't hide when they're empty, I intended it that way so that you could keep the number of supersegments symmetrical. I hadn't thought of this use case, but I'd be open to a PR to make hiding an optional feature.

However, I think it might be an easier solution to make the color of this segment depend upon the number of notifications. Much as the evil keyword allows a segment to change color depending upon evil state, you could make this segment turn red whenever you have unread mail.

To do this, you would define a function which takes one parameter, active, and returns an appropriate face depending upon this (and whatever else). Then, add a pair of (whatever-symbol . my-func) to telephone-line-faces, and use whatever-symbol as the color for this supersegment.