[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/moe-theme 0de97171e1 098/352: What am I doing...orz
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/moe-theme 0de97171e1 098/352: What am I doing...orz |
Date: |
Fri, 7 Jan 2022 03:59:10 -0500 (EST) |
branch: elpa/moe-theme
commit 0de97171e1a0e13698d18d4418d7b4d7a7b56e68
Author: kuanyui <azazabc123@gmail.com>
Commit: kuanyui <azazabc123@gmail.com>
What am I doing...orz
---
moe-theme-switcher.el | 138 ++++++++++++++++++++++++++++++++------------------
1 file changed, 90 insertions(+), 48 deletions(-)
diff --git a/moe-theme-switcher.el b/moe-theme-switcher.el
index 94ebd9bb4f..309d4321a3 100644
--- a/moe-theme-switcher.el
+++ b/moe-theme-switcher.el
@@ -1,19 +1,17 @@
;; 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.
(require 'moe-dark-theme)
(require 'moe-light-theme)
-(require 'solar)
-(require 'calendar)
(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 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.
@@ -23,61 +21,105 @@ Take Keelung, Taiwan(25N,121E) for example, you can set
like this:
(setq calendar-longitude +121)"
)
-(defun moe-theme-switch-at-fixed-time ()
- (let ((now (string-to-number (format-time-string "%H"))))
+(defun switch-at-fixed-time ()
+ (let ((now (string-to-int (format-time-string "%H"))))
(if (and (>= now 06) (<= now 18))
(load-theme 'moe-light t) (load-theme 'moe-dark t))
nil))
-(defun moe-theme-float-to-time-list (time)
- "Converts time represented as a float to a list
-Example:
-> (float-to-time-list 4.5)
-=> (4 30)
-> (float-to-time-list 8.633333332836628)
-=> (8 37)"
- (let* ((hours (truncate time))
- (minutes (truncate (* (- time hours) 60))))
- (list hours minutes)))
+;; (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 moe-theme-switch-by-locale ()
- (let* ((sunrise-sunset (solar-sunrise-sunset (calendar-current-date)))
- (length-of-day (mapcar
- (lambda (x) (string-to-number x))
- (split-string (car (cddr sunrise-sunset)) ":"))))
- (if (equal length-of-day '(0 0)) ; Polar night
- (load-theme 'moe-dark t)
- (if (equal length-of-day '(24 0)) ; Midnight sun
- (load-theme 'moe-light t)
- (let ((now (list (string-to-number (format-time-string "%H"))
- (string-to-number (format-time-string "%M"))))
- (sunrise (moe-theme-float-to-time-list (caar sunrise-sunset)))
- (sunset (moe-theme-float-to-time-list (car (cadr
sunrise-sunset)))))
- ;;Check that the time is between sunrise and sunset
- (if (and
- (or (> (car now) (car sunrise))
- (and (= (car now) (car sunrise))
- (>= (cdr now) (cdr sunrise))))
- (or (< (car now) (car sunset))
- (and (= (car now) (car sunset))
- (< (cdr now) (cdr sunset)))))
- (load-theme 'moe-light t)
- (load-theme 'moe-dark t)))))))
+(defun switch-by-locale ()
+ (if (equal 24h/sunrise 'polar-night) ;If polar-night...moe-dark!
+ (load-theme 'moe-dark t)
+ (if (equal 24h/sunrise 'midnight-sun) ;If midnight-sun...moe-light!
+ (load-theme 'moe-light t)
+ (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)))))
+ (load-theme 'moe-light t)
+ (load-theme 'moe-dark t)
+ ))))))
(defun moe-theme-auto-switch ()
(interactive)
- ;; Only do something if the theme is not the last applied theme
- (if (not (or (equal '(moe-light) (last custom-enabled-themes))
- (equal '(moe-dark) (last custom-enabled-themes))))
- (if (and moe-theme-switch-by-sunrise-and-sunset
- (boundp 'calendar-longitude)
- (boundp 'calendar-latitude))
- (moe-theme-switch-by-locale)
- (moe-theme-switch-at-fixed-time))))
+ (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))
+ ()
+ )
+
(moe-theme-auto-switch)
-(run-with-timer 0 (* 1 60) 'moe-theme-auto-switch)
+(run-with-timer 0 (* 1 60) 'moe-theme-auto-switch)
(provide 'moe-theme-switcher)
+
+
+
- [nongnu] elpa/moe-theme 308c42f4d3 071/352: [Fix #4] Remove faulty local variables, (continued)
- [nongnu] elpa/moe-theme 308c42f4d3 071/352: [Fix #4] Remove faulty local variables, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme f99a55d62a 072/352: Merge pull request #5 from lunaryorn/patch-1, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme bce815a9ac 074/352: More light faces for Agenda., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 250a228517 080/352: Fix wrong bg-color of "org-agenda-date" on Org-mode 8.2.3c., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 21f83424b1 089/352: Complete redone of the theme switcher., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 9373bdc918 093/352: Fixed so that the theme won't be reapplied if it was the last theme to be applied., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme ab9cb998a3 091/352: Match comint mode colours with eshell., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme ce01e0af47 094/352: Switch to gray tables in the dark theme., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 96d21bbf58 097/352: Merge pull request #15 from ToJa92/master, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 72efc3bfd3 099/352: Lighter green for arguments in js2 mode., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 0de97171e1 098/352: What am I doing...orz,
ELPA Syncer <=
- [nongnu] elpa/moe-theme 5f5d77802f 012/352: 1. Modified README and improve the themes., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 43f162a68d 013/352: 1. Fix flaw in twmode when switch moe-dark and moe-light., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme c9273d4c12 016/352: 1.Fix invisible org-special-keyword when switch from moe-dark from moe light., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme a4f9e0bbc1 017/352: 1. Add "auto-switch-theme" instructions in README.md., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 7a87892887 019/352: 1. Fix invisible secondary-selection and smerge., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme b8a0a20555 020/352: 1. Fix the parentheses of rainbow-delimiter in moe-light without bold 2. ...and set moe-dark with nil., ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 4f939a924e 023/352: Fix strange bahavior of sunrise-sunset when buffer's width is too narrow.(Thanks to letoh!), ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme ba52799d37 025/352: 1. Add .gitignore, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme 4bd084d642 027/352: 1. Change screenshots's width for GitHub's new interface...囧, ELPA Syncer, 2022/01/07
- [nongnu] elpa/moe-theme c8b33136e0 026/352: 1. fix a typo in README., ELPA Syncer, 2022/01/07