-
-
Save tsuu32/abbe09a7aea09bcfff397c5bb313854b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require 'cl-lib) | |
(defvar-local sushi-bar--conveyor-belt "") | |
(defvar sushi-bar--update-timer nil) | |
(defvar sushi-bar--buffers 0) | |
(defun sushi-bar--sushi-is-ready-p () | |
(eq (random 15) 1)) | |
(defun sushi-bar--conveyor-update () | |
(when (and sushi-bar-mode (null (window-minibuffer-p))) | |
(let* ((current-belt | |
(substring-no-properties sushi-bar--conveyor-belt | |
1)) ;; Conveyor moved to left | |
(padding-right (- (window-width) | |
(length current-belt)))) | |
(setq current-belt | |
(cond | |
((> padding-right 1) | |
(concat current-belt (make-string (1- padding-right) ? ))) | |
((< padding-right 1) | |
(substring-no-properties current-belt 0 (1- padding-right))) | |
(t current-belt))) | |
(setq sushi-bar--conveyor-belt | |
(concat current-belt | |
(if (sushi-bar--sushi-is-ready-p) "🍣" " ")))) | |
(force-mode-line-update))) | |
(defun sushi-bar--mode-enable () | |
(unless sushi-bar--update-timer | |
(setq sushi-bar--update-timer | |
(run-at-time t 0.045 'sushi-bar--conveyor-update))) | |
(cl-incf sushi-bar--buffers) | |
(setq sushi-bar--conveyor-belt (make-string (window-width) ? )) | |
(setq mode-line-format '(:eval sushi-bar--conveyor-belt))) | |
(defun sushi-bar--mode-disable () | |
(cl-decf sushi-bar--buffers) | |
(when (eq sushi-bar--buffers 0) | |
(cancel-timer sushi-bar--update-timer) | |
(setq sushi-bar--update-timer nil)) | |
(setq sushi-bar--conveyor-belt "") | |
(setq mode-line-format (default-value 'mode-line-format))) | |
(define-minor-mode sushi-bar-mode () | |
:global nil | |
(if sushi-bar-mode | |
(sushi-bar--mode-enable) | |
(sushi-bar--mode-disable))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
簡単な説明
M-x sushi-bar-mode
したバッファでmode lineに🍣が流れる。(他のバッファのmode lineは変わらない)
sushi-bar--buffers
は現在sushi-bar-modeなバッファがいくつあるかを示す。(sushi-bar-modeなバッファの数が0になったらcancel-timerする用)