[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/moe-theme b135f24d5a 344/352: undelete moe-theme-switcher
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/moe-theme b135f24d5a 344/352: undelete moe-theme-switcher |
Date: |
Fri, 7 Jan 2022 04:00:04 -0500 (EST) |
branch: elpa/moe-theme
commit b135f24d5ad4af171f27954b8d4cd6112e0300e0
Author: ono ono <azazabc123@gmail.com>
Commit: ono ono <azazabc123@gmail.com>
undelete moe-theme-switcher
---
moe-theme-switcher.el | 147 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 147 insertions(+)
diff --git a/moe-theme-switcher.el b/moe-theme-switcher.el
new file mode 100644
index 0000000000..c49a348208
--- /dev/null
+++ b/moe-theme-switcher.el
@@ -0,0 +1,147 @@
+;; moe-theme-switcher.el
+;; Author: kuanyui (azazabc123@gmail.com)
+;; Date: 2013/05/11 11:39
+;;
+;; This file is not a part of GNU Emacs,
+;; but this file is released under GPL v3.
+
+;; TODO: This program need to be refactored.
+(require 'moe-dark-theme)
+(require 'moe-light-theme)
+(require 'moe-theme)
+(require 'solar)
+
+(defvar moe-theme-switch-by-sunrise-and-sunset t
+"Automatically switch between dark and light moe-theme.
+
+If this value is nil, moe-theme will switch at fixed time (06:00 and 18:00).
+
+If this value is t and both calendar-latitude and calendar-longitude are set
+properly, the switching will be triggered at the sunrise and sunset time of the
+local calendar.
+
+Take Keelung, Taiwan(25N,121E) for example, you can set like this:
+
+ (setq calendar-latitude +25)
+ (setq calendar-longitude +121)"
+)
+
+(defvar moe-theme-which-enabled nil
+ "Variable indicate which theme (moe-dark or light) is being used.")
+
+(defun moe-load-theme (switch-to)
+ "Avoid unnecessary load-theme and screen flashing in GUI version Emacs"
+ (cond ((equal switch-to 'light)
+ (if (not (equal moe-theme-which-enabled 'light))
+ (progn (moe-light)
+ (setq moe-theme-which-enabled 'light)))) ;[FIXME] Maybe
unnecessary
+ ((equal switch-to 'dark)
+ (if (not (equal moe-theme-which-enabled 'dark))
+ (progn (moe-dark)
+ (setq moe-theme-which-enabled 'dark)))))) ;[FIXME] Maybe
unnecessary
+
+(defun switch-at-fixed-time ()
+ (let ((now (string-to-number (format-time-string "%H"))))
+ (if (and (>= now 06) (<= now 18))
+ (moe-load-theme 'light)
+ (moe-load-theme 'dark))
+ nil))
+
+;; (Thanks for letoh!)
+;; Fix strange bahavior of sunrise-sunset when buffer's width is too narrow.
+(defun get-sunrise-sunset-string ()
+ "get the real result from `sunrise-sunset'"
+ (save-window-excursion
+ (let ((regex "[0-9]+:[0-9]+[ap]m")
+ (s (sunrise-sunset))
+ (buf (get-buffer "*temp*")))
+ (unless (and (stringp s)
+ (string-match-p regex s))
+ (when buf
+ (with-current-buffer buf
+ (let* ((s1 (buffer-string))
+ (s2 (if (string-match-p regex s1)
+ s1 nil)))
+ (setq s s2)
+ (kill-buffer buf)))))
+ s)))
+
+;; Convert am/pm to 24hr and save to 24h/sunrise & 24h/set
+;; Excute every 24 hr
+(defun convert-time-format-of-sunrise-and-sunset ()
+ (let (rise_set a b c d e f)
+ (setq rise_set (get-sunrise-sunset-string))
+ (if (string-match "0:00 hours daylight" rise_set) ;If polar-night
+ (progn
+ (setq 24h/sunrise 'polar-night
+ 24h/sunset 'polar-night))
+ (if (string-match "24:00 hours daylight" rise_set) ;If midnight-sun
+ (progn
+ (setq 24h/sunrise 'midnight-sun
+ 24h/sunset 'midnight-sun))
+ (progn ;Convert 12hr to 24hr
+ (string-match
"\\([0-9][0-9]?\\):\\([0-9][0-9]\\)\\([ap]m\\).+\\([0-9][0-9]?\\):\\([0-9][0-9]\\)\\([ap]m\\)"
rise_set)
+ (setq a (string-to-number (match-string 1 rise_set))
+ b (string-to-number (match-string 2 rise_set))
+ c (match-string 3 rise_set)
+ d (string-to-number (match-string 4 rise_set))
+ e (string-to-number (match-string 5 rise_set))
+ f (match-string 6 rise_set))
+ (if (equal c "pm")
+ (setq 24h/sunrise (list (+ 12 a) b))
+ (setq 24h/sunrise (list a b)))
+ (if (equal f "pm")
+ (setq 24h/sunset (list (+ 12 d) e))
+ (setq 24h/sunset (list d e))))))))
+
+;; Excute every minute.
+(defun switch-by-locale ()
+ (if (equal 24h/sunrise 'polar-night) ;If polar-night...moe-dark!
+ (moe-load-theme 'dark)
+ (if (equal 24h/sunrise 'midnight-sun) ;If midnight-sun...moe-light!
+ (moe-load-theme 'light)
+ (progn
+ (let ((now (list (string-to-number (format-time-string "%H"))
+ (string-to-number (format-time-string "%M")))))
+ (if (and (or ;magic-logic [tm]
+ (> (car now) (car 24h/sunrise))
+ (and
+ (= (car now) (car 24h/sunrise))
+ (>= (second now) (second 24h/sunrise))))
+ (or
+ (< (car now) (car 24h/sunset))
+ (and
+ (= (car now) (car 24h/sunset))
+ (< (second now) (second 24h/sunset)))))
+ (moe-load-theme 'light)
+ (moe-load-theme 'dark)
+ ))))))
+
+(defun moe-theme-auto-switch ()
+ "Automatically switch between dark and light moe-theme."
+ (interactive)
+ (if (boundp '24h/sunrise)
+ (switch-by-locale)
+ (switch-at-fixed-time))
+ )
+
+(if (and
+ (boundp 'calendar-longitude)
+ (boundp 'calendar-latitude)
+ (eql moe-theme-switch-by-sunrise-and-sunset t))
+ (progn
+ (convert-time-format-of-sunrise-and-sunset)
+ (run-with-timer 0 (* 60 60 24)
'convert-time-format-of-sunrise-and-sunset))
+ ()
+ )
+
+(setq moe-timer (run-with-timer 0 (* 1 60) 'moe-theme-auto-switch))
+
+;; [FIXME] A minor-mode to enable/disable moe-theme-switcher
+(defun moe-theme-switcher-disable ()
+ (interactive)
+ (cancel-timer moe-timer))
+
+(moe-theme-auto-switch)
+
+(provide 'moe-theme-switcher)
- [nongnu] elpa/moe-theme b8f0206614 303/352: Add eldoc-highlight-function-argument, (continued)
- [nongnu] elpa/moe-theme b8f0206614 303/352: Add eldoc-highlight-function-argument, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 1267092290 306/352: Fix wrongly used with-eval-after-load, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme cf953ff7d7 305/352: defalias moe-theme-powerline powerline-moe-theme, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme e35b1bb883 307/352: Adjust mechanism for powerline, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 73eaa37f89 309/352: change color by current frame id, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 6ca4f84f3c 308/352: wtf, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 420c122295 312/352: Lots of shit, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme c36fbacfe5 334/352: [faces] improve for semantic-mode, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 962f836801 340/352: Remove background from tuareg mode operators, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 0cc3f1143c 341/352: Cherrypick README from master, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme b135f24d5a 344/352: undelete moe-theme-switcher,
ELPA Syncer <=
- [nongnu] elpa/moe-theme b23975ba57 348/352: Turn off aggressive-indent-mode only if it's actually on. (#115), ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 76116f6eeb 345/352: fix: double loading of moe-theme (#109), ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 9c40f856fc 351/352: Fix package file header for `package-buffer-info`, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 47c6cf35f7 186/352: Change color of linum-highlight to green-0., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 3109097aab 314/352: alas, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 4c3e98a922 315/352: aaaaa, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 5a7b99645d 317/352: Fix shits, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 2634eb6d92 319/352: customizable font-lock color, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 2730a51402 322/352: Fix wrong faces of tomorrow, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme ea199be564 323/352: Add monokai, ELPA Syncer, 2022/01/07