domtronn / spaceline-all-the-icons.el

A Spaceline Mode Line theme using All The Icons for Emacs
MIT License
235 stars 25 forks source link

Support for mu4e alert #72

Open Sbozzolo opened 6 years ago

Sbozzolo commented 6 years ago

I couldn't find any information about whether this package supports mu4e-alert or not. In the case it doesn't, I believe it would be a nice feature to have.

Best, sbozzolo

syvanpera commented 6 years ago

I took a stab at this as I wanted this too. Here's what I came up with:

Add this to mu4e-alert package settings

(setq mu4e-alert-modeline-formatter 'ts/mu4e-alert-modeline-formatter)

And add the function referenced above somewhere:

(defun ts/mu4e-alert-modeline-formatter (mail-count)
  "Mu4e-alert modeline formatter for spaceline-all-the-icons."
  (when (not (zerop mail-count))
    (let* ((icon (all-the-icons-faicon "envelope" :v-adjust 0.0)))
      (propertize
       (concat
        (propertize icon
                    'face `(:height ,(spaceline-all-the-icons--height 0.9) :inherit)
                    'display '(raise 0.1))
        (propertize (format " %d" mail-count) 'face `(:height ,(spaceline-all-the-icons--height 0.9) :inherit) 'display '(raise 0.1)))
       'help-echo (concat (if (= mail-count 1)
                              "You have an unread email"
                            (format "You have %s unread emails" mail-count))
                          "\nClick here to view "
                          (if (= mail-count 1) "it" "them"))
       'mouse-face (spaceline-all-the-icons--highlight)))))

And finally tell spaceline-all-the-icons to use a custom segment.

(spaceline-all-the-icons-theme 'mu4e-alert-segment)

This works, but it doesn't quite look as good as I'd like. The custom segments are rendered next to some other segments which have padding around them. So it leaves quite a gap between the mail alert and the other segments. I can see if I can whip up a PR to get this into spaceline-all-the-icons proper.

syvanpera commented 6 years ago

Ah, forgot to add the mouse click stuff there. So even though it tells you to "Click here to view", that doesn't actually work yet. I'll see if I can get this cleaned up and do a PR.

syvanpera commented 6 years ago

Here's an updated formatter which opens the unread mails when clicked with mouse:

(defun ts/mu4e-alert-modeline-formatter (mail-count)
  "Mu4e-alert modeline formatter for spaceline-all-the-icons."
  (when (not (zerop mail-count))
    (let* ((icon (all-the-icons-faicon "envelope" :v-adjust 0.0)))
      (propertize
       (concat
        (propertize icon
                    'face `(:height ,(spaceline-all-the-icons--height 0.9) :inherit)
                    'display '(raise 0.1))
        (propertize (format " %d" mail-count) 'face `(:height ,(spaceline-all-the-icons--height 0.9) :inherit) 'display '(raise 0.1)))
       'help-echo (concat (if (= mail-count 1)
                              "You have an unread email"
                            (format "You have %s unread emails" mail-count))
                          "\nClick here to view "
                          (if (= mail-count 1) "it" "them"))
       'mouse-face (spaceline-all-the-icons--highlight)
       'local-map (make-mode-line-mouse-map 'mouse-1 'mu4e-alert-view-unread-mails)))))
syvanpera commented 6 years ago

Did a pull request for this https://github.com/domtronn/spaceline-all-the-icons.el/pull/87