emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master e7fe308: Spinner version 1.7


From: Artur Malabarba
Subject: [elpa] master e7fe308: Spinner version 1.7
Date: Mon, 08 Feb 2016 11:54:54 +0000

branch: master
commit e7fe3082a33acea035c0766c6a1f0221724bfb62
Author: Artur Malabarba <address@hidden>
Commit: Artur Malabarba <address@hidden>

    Spinner version 1.7
    
    Offer a spinner-make-progress-bar function.
    Make spinner-stop never signal.
    Allow floating-point delays.
---
 packages/spinner/spinner.el |   35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)

diff --git a/packages/spinner/spinner.el b/packages/spinner/spinner.el
index ec0a64f..63ead1e 100644
--- a/packages/spinner/spinner.el
+++ b/packages/spinner/spinner.el
@@ -3,7 +3,7 @@
 ;; Copyright (C) 2015 Free Software Foundation, Inc.
 
 ;; Author: Artur Malabarba <address@hidden>
-;; Version: 1.5
+;; Version: 1.7
 ;; URL: https://github.com/Malabarba/spinner.el
 ;; Keywords: processes mode-line
 
@@ -123,6 +123,18 @@
 Each car is a symbol identifying the spinner, and each cdr is a
 vector, the spinner itself.")
 
+(defun spinner-make-progress-bar (width &optional char)
+  "Return a vector of strings of the given WIDTH.
+The vector is a valid spinner type and is similar to the
+`progress-bar' spinner, except without the sorrounding brackets.
+CHAR is the character to use for the moving bar (defaults to =)."
+  (let ((whole-string (concat (make-string (1- width) ?\s)
+                              (make-string 4 (or char ?=))
+                              (make-string width ?\s))))
+    (thread-last (mapcar (lambda (n) (substring whole-string n (+ n width)))
+                         (number-sequence (+ width 3) 0 -1))
+      (apply #'vector))))
+
 (defvar spinner-current nil
   "Spinner curently being displayed on the `mode-line-process'.")
 (make-variable-buffer-local 'spinner-current)
@@ -243,8 +255,8 @@ stop the SPINNER's timer."
 
     (unless (ignore-errors (> (spinner--fps spinner) 0))
       (error "A spinner's FPS must be a positive number"))
-    (setf (spinner--counter spinner) (- (* (or (spinner--delay spinner) 0)
-                                    (spinner--fps spinner))))
+    (setf (spinner--counter spinner) (round (- (* (or (spinner--delay spinner) 
0)
+                                           (spinner--fps spinner)))))
     ;; Create timer.
     (let* ((repeat (/ 1.0 (spinner--fps spinner)))
            (time (timer-next-integral-multiple-of-time (current-time) repeat))
@@ -307,13 +319,16 @@ this time, in which case it won't display at all."
   (spinner-print spinner))
 
 (defun spinner-stop (&optional spinner)
-  "Stop the current buffer's spinner."
-  (let* ((spinner (or spinner spinner-current))
-         (timer (spinner--timer spinner)))
-    (when (timerp timer)
-      (cancel-timer timer))
-    (setf (spinner--active-p spinner) nil)
-    (force-mode-line-update)))
+  "Stop SPINNER, defaulting to the current buffer's spinner.
+It is always safe to call this function, even if there is no
+active spinner."
+  (let ((spinner (or spinner spinner-current)))
+    (when (spinner-p spinner)
+      (let ((timer (spinner--timer spinner)))
+        (when (timerp timer)
+          (cancel-timer timer)))
+      (setf (spinner--active-p spinner) nil)
+      (force-mode-line-update))))
 
 (provide 'spinner)
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]