Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle for endless animation and more control for wavy trail #54

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 38 additions & 4 deletions nyan-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,26 @@ Intended to be called when customizations were changed, to reapply them immediat
(nyan-refresh))
:group 'nyan)

(defcustom nyan-animation-endless-loop t
"If non-nil then the progress bar animation never stops.
If nil then the animation loops a few time only when Nyan Cat moves."
:type 'boolean
:group 'nyan)

(defvar nyan-animation-timer nil)

(defvar nyan-animation-loop-count 0
"Count the number of loops since the animation started.")

(defvar nyan-animation-loop-max 1
"Maximum number of loops. When the max is reached the animation stops.")

(defvar nyan-nyan-wavy-trail-enabled nil
"Internal toggle to display a wavy trail.")

(defvar nyan-prev-outerspaces nil
"Keeps track of the trail length to detect when animation should start.")

(defun nyan--is-animating-p ()
"T if animating, NIL otherwise."
(timerp nyan-animation-timer))
Expand Down Expand Up @@ -122,9 +140,13 @@ This is important because nyan-mode will push out all informations from small wi
(defcustom nyan-wavy-trail nil
"If enabled, Nyan Cat's rainbow trail will be wavy."
:type '(choice (const :tag "Enabled" t)
(const :tag "Only during animation" 'animation-only)
(const :tag "Disabled" nil))
:set (lambda (sym val)
(set-default sym val)
(if sym
(setq nyan-nyan-wavy-trail-enabled t)
(setq nyan-nyan-wavy-trail-enabled nil))
(nyan-refresh))
:group 'nyan)

Expand Down Expand Up @@ -185,11 +207,16 @@ This can be t or nil."
(defun nyan-toggle-wavy-trail ()
"Toggle the trail to look more like the original Nyan Cat animation."
(interactive)
(setq nyan-wavy-trail (not nyan-wavy-trail)))
(setq nyan-nyan-wavy-trail-enabled (not nyan-nyan-wavy-trail-enabled)))

(defun nyan-swich-anim-frame ()
(setq nyan-current-frame (% (+ 1 nyan-current-frame) 6))
(redraw-modeline))
(when (<= nyan-animation-loop-count nyan-animation-loop-max)
(when (member nyan-wavy-trail '(t animation-only))
(setq nyan-nyan-wavy-trail-enabled t))
(setq nyan-current-frame (% (+ 1 nyan-current-frame) 6))
(when (equal nyan-current-frame 5)
(setq nyan-animation-loop-count (1+ nyan-animation-loop-count)))
(redraw-modeline)))

(defun nyan-get-anim-frame ()
(if (nyan--is-animating-p)
Expand Down Expand Up @@ -237,6 +264,9 @@ This can be t or nil."

(defun nyan-create ()
"Return the Nyan Cat indicator to be inserted into mode line."
(when (and (eq nyan-wavy-trail 'animation-only)
(> nyan-animation-loop-count nyan-animation-loop-max))
(setq nyan-nyan-wavy-trail-enabled nil))
(if (< (window-width) nyan-minimum-window-width)
"" ; disabled for too small windows
(let* ((rainbows (nyan-number-of-rainbows))
Expand All @@ -253,11 +283,15 @@ This can be t or nil."
(nyan-add-scroll-handler
(if xpm-support
(propertize "|"
'display (create-image +nyan-rainbow-image+ 'xpm nil :ascent (or (and nyan-wavy-trail
'display (create-image +nyan-rainbow-image+ 'xpm nil :ascent (or (and nyan-nyan-wavy-trail-enabled
(nyan-wavy-rainbow-ascent number))
(if (nyan--is-animating-p) 95 'center))))
"|")
(/ (float number) nyan-bar-length) buffer))))
(when (or nyan-animation-endless-loop
(not (equal outerspaces nyan-prev-outerspaces)))
(setq nyan-animation-loop-count 0
nyan-prev-outerspaces outerspaces))
(dotimes (number outerspaces)
(setq outerspace-string (concat outerspace-string
(nyan-add-scroll-handler
Expand Down