5

Q: Is there a way to (temporarily) increase the rate at which the mode line is redisplayed?

I was trying to write a package that adds a spinner to the mode line (to indicate ongoing operations), but I hit a bit of a wall. If the user is not interacting (not typing, or moving, or something), then the mode-line might stop updating for up to a minute. If that's the case then the spinner won't spin.

I started writing a solution with timers (that would periodically call redisplay), but that seems like a lot of work for something so simple.

  • 1
    I would probably do the same thing, except link the timer to force-mode-line-update; or, perhaps have the spinner function keep triggering force-mode-line-update if the spinner is going through something like a dolist or while loop -- each loop is a force-mode-line-udpate. Also, consider using a regular timer that is not necessarily an idle timer. – lawlist Mar 5 '15 at 23:08
  • @lawlist thanks for the pointer to force-mode-line-update . I don't know why I said idle-timer, I meant timer. – Malabarba Mar 5 '15 at 23:20
  • @lawlist: Looks like a complete answer and not a comment. – Meaningful Username Mar 6 '15 at 17:48
  • @Malabarba I believe you followed up on this elsewhere, and even implemented a package which needs this to work correctly. Could you please share your findings. – tarsius Mar 27 '15 at 1:22
  • @tarsius Oh yes! I'd forgotten about this. – Malabarba Mar 27 '15 at 1:30
1

Here is a simplified version of the solution I came up (had to use timers after all). For the complete solution, see spinner.el.

(let ((timer (run-at-time t 0.2 #'ignore)))
  (timer-set-function
   timer (lambda ()
           (if still-ongoing
               (force-mode-line-update)
             (ignore-errors (cancel-timer timer))))))

This creates a timer that updates the mode-line 5 times per second. When the variable still-ongoing gets set to nil, the time cancels itself.

  • Nice to see I am not the only one who indents like this, when given the opportunity :-) – tarsius Mar 27 '15 at 2:21

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.