4

How to create a toggle button in the modeline, like a play / pause button ? for now, I've got the following :

(setq-default mode-line-format
      '(
    (:eval
      (propertize
      " ⏸ "
        'local-map (make-mode-line-mouse-map 'mouse-1 'helm-spotify-plus-toggle-play-pause)
      )
    )

))

And I would like to toggle play and pause unicode characters.

3

I don't have much experience customizing the mode line, but the following seems working from here. It displays the status of column-number-mode using ON and OFF, when you click the text, the mode will be toggled and the text will be updated as well.

(defvar mode-line-column-number-map
  (let ((map (make-sparse-keymap)))
    (define-key map [mode-line mouse-1]
      (lambda (_e)
        (interactive "e")
        (column-number-mode 'toggle)))
    map))

(setq mode-line-format
      '((:eval (propertize (if column-number-mode "On" "Off")
                           'local-map mode-line-column-number-map))
        (column-number-mode "  %c")))
  • I've just tested it, it works, thanks, I'll also post my own solution and I'd like you or other people to review / criticize it because I'm new to lisp and I don't know if it's a good way to do the thing. – boehm_s Aug 23 '18 at 13:15
1

This is a solution I found, don't know if it's the right way, but it works :

(defvar music-paused nil)

(setq-default mode-line-format '(
  (:eval (if (eq music-paused t)
    (propertize " ⏸ " 'local-map (make-mode-line-mouse-map 'mouse-1 '(lambda () (setq music-paused nil)) ))
    (propertize " ⏵ " 'local-map (make-mode-line-mouse-map 'mouse-1 '(lambda () (setq music-paused t)) ))
  ))
))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.