[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7d222f4 02/10: spinner: Generalize to arbitrary variables
From: |
Artur Malabarba |
Subject: |
[elpa] master 7d222f4 02/10: spinner: Generalize to arbitrary variables |
Date: |
Tue, 11 Aug 2015 10:56:34 +0000 |
branch: master
commit 7d222f4cd526652b10894a1cdf5aa85a920ec8ce
Author: Artur Malabarba <address@hidden>
Commit: Artur Malabarba <address@hidden>
spinner: Generalize to arbitrary variables
---
spinner.el | 80 ++++++++++++++++++++++++++++++++++++------------------------
1 files changed, 48 insertions(+), 32 deletions(-)
diff --git a/spinner.el b/spinner.el
index 07d4c2e..a40005c 100644
--- a/spinner.el
+++ b/spinner.el
@@ -82,14 +82,20 @@ vector, the spinner itself.")
"Current frame of the spinner.")
(make-variable-buffer-local 'spinner--counter)
-(defconst spinner--mode-line-construct
- '((spinner-current
+(defun spinner-make-construct (spinner-var timer-var)
+ "Make a mode-line spinner construct, using symbol SPINNER-VAR.
+SPINNER-VAR is the name of the variable holding the spinner type
+to be used (one of the cdr's in `spinner-types'). To st"
+ `((,spinner-var
(" "
- (:eval (elt spinner-current
+ (:eval (elt ,spinner-var
(% spinner--counter
- (length spinner-current)))))
- (spinner--timer
- (:eval (spinner-stop)))))
+ (length ,spinner-var)))))
+ (,timer-var
+ (:eval (spinner-stop ,spinner-var ,timer-var))))))
+
+(defconst spinner--mode-line-construct
+ (spinner-make-construct 'spinner-current 'spinner--timer)
"Construct used to display the spinner.")
(put 'spinner--mode-line-construct 'risky-local-variable t)
@@ -102,7 +108,34 @@ vector, the spinner itself.")
Applications can override this value.")
-;;; The main function
+;;; The main functions
+(defun spinner-start-timer (fps spinner-var timer-var)
+ "Start a spinner timer at FPS frames per second.
+SPINNER-VAR is the name of the variable holding the spinner type,
+and TIMER-VAR is the name of the variable that will be used to
+hold the timer."
+ (let ((old-timer (symbol-value timer-var)))
+ (when (timerp old-timer)
+ (cancel-timer old-timer))
+ ;; Create timer.
+ (let ((buffer (current-buffer))
+ ;; Create the timer as a lex variable so it can cancel itself.
+ (timer (run-at-time t
+ (/ 1.0 (or fps spinner-frames-per-second))
+ #'ignore)))
+ (timer-set-function
+ timer (lambda ()
+ (if (buffer-live-p buffer)
+ (with-current-buffer buffer
+ (setq spinner--counter (1+ spinner--counter))
+ (force-mode-line-update))
+ (ignore-errors (cancel-timer timer)))))
+ (set timer-var timer)
+ ;; Return a stopping function.
+ (lambda () (when (buffer-live-p buffer)
+ (with-current-buffer buffer
+ (spinner-stop spinner-var timer-var)))))))
+
;;;###autoload
(defun spinner-start (&optional type fps noadd)
"Start a mode-line spinner of given TYPE.
@@ -150,32 +183,15 @@ is chosen as the spinner type."
'spinner--mode-line-construct)))
;; Create timer.
- (when (timerp spinner--timer)
- (cancel-timer spinner--timer))
- (let ((buffer (current-buffer))
- ;; Create the timer as a lex variable so it can cancel itself.
- (timer (run-at-time t
- (/ 1.0 (or fps spinner-frames-per-second))
- #'ignore)))
- (timer-set-function
- timer (lambda ()
- (if (buffer-live-p buffer)
- (with-current-buffer buffer
- (setq spinner--counter (1+ spinner--counter))
- (force-mode-line-update))
- (ignore-errors (cancel-timer timer)))))
- (setq spinner--timer timer)
- ;; Return a stopping function.
- (lambda () (when (buffer-live-p buffer)
- (with-current-buffer buffer
- (spinner-stop))))))
-
-(defun spinner-stop ()
+ (spinner-start-timer fps 'spinner-current 'spinner--timer))
+
+(defun spinner-stop (&optional spinner-var timer-var)
"Stop the current buffer's spinner."
- (when (timerp spinner--timer)
- (cancel-timer spinner--timer))
- (setq spinner--timer nil
- spinner-current nil))
+ (let ((timer (symbol-value timer-var)))
+ (when (timerp timer)
+ (cancel-timer timer))
+ (set (or timer-var 'spinner--timer) nil)
+ (set (or spinner-var 'spinner-current) nil)))
(provide 'spinner)
- [elpa] master updated (7695b59 -> 25a84ed), Artur Malabarba, 2015/08/11
- [elpa] master fb3fb96 01/10: 1.2, Artur Malabarba, 2015/08/11
- [elpa] master 7d222f4 02/10: spinner: Generalize to arbitrary variables,
Artur Malabarba <=
- [elpa] master 59ef469 06/10: Implement spinner-start-print, Artur Malabarba, 2015/08/11
- [elpa] master 46c545b 04/10: spinner: Iron out some kinks in the minor-mode behavior, Artur Malabarba, 2015/08/11
- [elpa] master 709295d 07/10: * spinner: Rename constructor., Artur Malabarba, 2015/08/11
- [elpa] master 8d8c459 09/10: spinner: More doc, Artur Malabarba, 2015/08/11
- [elpa] master bd2c557 08/10: spinner: Add delay feature, Artur Malabarba, 2015/08/11
- [elpa] master b6dc924 03/10: spinner: Document new functionality, Artur Malabarba, 2015/08/11
- [elpa] master 60205a4 05/10: Rewrite spinners completely., Artur Malabarba, 2015/08/11
- [elpa] master 25a84ed 10/10: Merge commit '8d8c459d7757cf5774f11be9147d7a54f5f9bbd7', Artur Malabarba, 2015/08/11