3

This question was originally asking for a custom progress indicator, but I've since removed the 'custom' requirement because I think the generalized case is more helpful to others.


I have added a command that takes a while to execute. Therefore I'd like to temporarily display a buffer with an animated textual progress indicator (rotating \|/-, perhaps) that updates with some frequency to show that the command is still running.

What's the best way to go about doing this?

5

Have a look at the Emacs progress reporter. See the Elisp manual (info "(elisp) Progress")

  • Thanks; this is almost exactly what I'm asking for! This is certainly the best way of displaying progress in Emacs. In this particular case I'm particularly looking for a way of accomplishing a custom indicator, however. Any ideas? – Caterpillar Nov 17 '17 at 13:22
  • 1
    Some years ago I've proposed a patch which would show the progress reporter in the modeline instead of the minibuffer. Also, the rotating characters could be customized. Somehow, it didn't find the way into Emacs. Look at <lists.gnu.org/archive/html/emacs-devel/2011-02/msg00764.html>, maybe you could make use of my patch. (And maybe I should reanimate it, and contribute as ELPA package). – Michael Albinus Nov 17 '17 at 13:39
  • Awesome, I'll have a look! Thanks! Once this question has been up for a while I'll consider accepting this answer since it'll answer the majority of those that come calling for a progress indicator. – Caterpillar Nov 17 '17 at 13:46
1

Just for fun.

(defun mode-line-progressbar-demo ()
  "Displays a progressbar in the mode-line."
  (interactive)
  (let* ((mode-line-format mode-line-format)
         (max (window-width))
         (duration 3)
         (delta (max 0 (/ (float duration) max)))
         (message "Processing"))
    (unwind-protect
        (dotimes (i max)
          (let* ((text (format "%s %.2f%%%%" message (* 100 (/ (float i) max))))
                 (fill (ceiling (/ (max 0 (- max (length text))) (float 2))))
                 (msg (concat (make-string fill ?\s) text (make-string fill ?\s))))
            (put-text-property 0 i 'face '(:background "royalblue") msg)
            (setq mode-line-format msg)
            (force-mode-line-update)
            (sit-for delta)))
      (force-mode-line-update))))

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.