10

I set up an org-timer indicator in the mode line with this.

(setq-default
 mode-line-format
 (quote
  (
   ;; org-timer
   (:eval
    (unless (not org-timer-countdown-timer)
      (propertize (let* ((rtime (decode-time
                                 (time-subtract
                                  (timer--time org-timer-countdown-timer)
                                  (current-time))))
                         (rmins (nth 1 rtime))
                         (rsecs (nth 0 rtime)))
                    (format "🕔 %d:%d" rmins rsecs))
                  'face '(:foreground "cyan" :weight bold)
                  'help-echo "org-timer")))

   )))

I want this org-timer indicator to be shown in the active mode line only, instead of all mode lines. How to do it?

  • See: emacs.stackexchange.com/a/22682/2287 – lawlist Aug 12 '16 at 14:25
  • @lawlist Can't understand your code. Don't know how to apply on my case. – stardiviner Aug 13 '16 at 1:14
  • 1
    The redisplay engine is able to check each window under certain circumstances (e.g., when the mode-line is refreshed naturally, or when it is forced to refresh). When the mode-line-format contains the function (selected-window), a different window will be returned as redisplay visits the various windows. That value can be compared with a pre-recorded value -- e.g., the post-command-hook can be used to record the last known selected-window and that value can later be compared with a function inside the mode-line-format. So, I use the PCH to record/store the selected-window. – lawlist Aug 13 '16 at 4:02
  • @lawlist I have checked out your code, but have not found general usage for my case. If I change to other thing instead of org-timer. What should I do? I hope a more general way. Even it did inspired me. Can you give me more exactly code example? Because I found it set different 'face, But I need to change the display string. – stardiviner Aug 17 '16 at 11:23
  • I haven't tried this, but this question looks similar to this one: emacs.stackexchange.com/q/13842/115 – Kaushal Modi Aug 17 '16 at 15:39
7
+50

In the following example, the word “ACTIVE” will appear in the mode-line of the window that is active, and all other windows will display the word “INACTIVE” in the mode-line.

Be sure to try this example with emacs -Q to verify that it works as advertised. Thereafter, customize it as needed.

Add additional hooks as needed to call ml-update-all.

(defvar ml-selected-window nil)

(defun ml-record-selected-window ()
  (setq ml-selected-window (selected-window)))

(defun ml-update-all ()
  (force-mode-line-update t))

(add-hook 'post-command-hook 'ml-record-selected-window)

(add-hook 'buffer-list-update-hook 'ml-update-all)

(setq-default mode-line-format
  '(:eval
      (if (eq ml-selected-window (selected-window))
        "ACTIVE"
        "INACTIVE")))

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.