133 lines
3.8 KiB
EmacsLisp
133 lines
3.8 KiB
EmacsLisp
;;; ui/zen-writer/config.el --- Zen Writer -*- lexical-binding: t; -*-
|
|
|
|
;; Author: Yann Esposito <https://github.com/yogsototh>
|
|
;; Version: 0.0.1
|
|
;; Created: November 7, 2021
|
|
;; Keywords: custom themes, faces
|
|
;; Homepage: https://github.com/hlissner/emacs-doom-themes
|
|
;; Package-Requires: ((emacs "25.1") (cl-lib "0.5") (doom-themes "2.2.1") (hl-sentence "3"))
|
|
|
|
;;; Commentary:
|
|
|
|
;; This package update the theme depending of the time of the day
|
|
;;
|
|
|
|
;;; Code:
|
|
|
|
;; code goes here
|
|
|
|
(require 'doom-themes)
|
|
(require 'hl-sentence)
|
|
(defvar doom-theme)
|
|
(defvar custom-enabled-themes)
|
|
|
|
;; configuration
|
|
(defvar +zen-writer-light-theme 'doom-zen-writer
|
|
"The theme for Zen Writer in light mode.")
|
|
(defvar +zen-writer-dark-theme 'doom-zen-writer-dark
|
|
"The theme for Zen Writer in dark mode.")
|
|
(defvar +zen-writer-theme +zen-writer-light-theme
|
|
"The theme for Zen Writer when zen-auto-dark-theme is nil. By default it uses the light theme.")
|
|
(defvar +zen-writer-auto-dark-theme t
|
|
"When true put dark-mode automatically depending on the hour of the day.")
|
|
|
|
(defvar +zen-writer-morning-hour 7
|
|
"Hour (24) at which we start using light theme. By default 7.")
|
|
(defvar +zen-writer-evening-hour 18
|
|
"Hour (24) at which we start using dark theme. By default 18.")
|
|
|
|
(defvar zen-writer--pre-zen-doom-theme nil)
|
|
|
|
;; internal private state
|
|
(define-minor-mode zen-writer-mode
|
|
;; doc
|
|
nil
|
|
;; init value
|
|
nil
|
|
;; modeline indicator
|
|
nil
|
|
;; key-bindings
|
|
nil
|
|
;; body
|
|
(if zen-writer-mode
|
|
(zen-writer-on)
|
|
(zen-writer-off)))
|
|
|
|
(defun zen-writer-select-user-theme ()
|
|
"Change the theme back to the theme prior to the Zen Writer theme."
|
|
(when zen-writer--pre-zen-doom-theme
|
|
(setq doom-theme zen-writer--pre-zen-doom-theme)
|
|
(load-theme doom-theme t)))
|
|
|
|
(defun zen-writer-current-hour ()
|
|
"Retrieve current local hour."
|
|
(nth 2 (decode-time (current-time))))
|
|
|
|
(defun zen-writer-select-theme ()
|
|
"Depending on time and configuration use different theme."
|
|
(if +zen-writer-auto-dark-theme
|
|
(let* ((hour (zen-writer-current-hour))
|
|
(day? (<= +zen-writer-morning-hour
|
|
hour
|
|
+zen-writer-evening-hour))
|
|
(theme (if day? +zen-writer-light-theme +zen-writer-dark-theme)))
|
|
(unless (equal doom-theme theme)
|
|
(setq doom-theme theme)
|
|
(load-theme doom-theme t))
|
|
;; run that function again next hour
|
|
(run-at-time (format "%02d:%02d" (+ hour 1) 0) nil 'zen-writer-select-theme))
|
|
(setq doom-theme +zen-writer-theme)
|
|
(load-theme doom-theme t)))
|
|
|
|
(defun zen-writer-on ()
|
|
"Activate Zen Writer."
|
|
(unless zen-writer--pre-zen-doom-theme
|
|
;; save theme before enabling ZenWriter
|
|
(setq zen-writer--pre-zen-doom-theme
|
|
(or (when (and custom-enabled-themes (listp custom-enabled-themes))
|
|
(car custom-enabled-themes))
|
|
doom-theme)))
|
|
(zen-writer-select-theme)
|
|
(hl-sentence-mode +1))
|
|
|
|
(defun zen-writer-off ()
|
|
"Deactivate Zen Writer."
|
|
(zen-writer-select-user-theme)
|
|
(setq zen-writer--pre-zen-doom-theme nil)
|
|
(hl-sentence-mode -1))
|
|
|
|
;; Full Zen Writer
|
|
(define-minor-mode zen-writer-full-mode
|
|
;; doc
|
|
nil
|
|
;; init value
|
|
nil
|
|
;; modeline indicator
|
|
nil
|
|
;; key-bindings
|
|
nil
|
|
;; body
|
|
(if zen-writer-full-mode
|
|
(zen-writer-full-on)
|
|
(zen-writer-full-off)))
|
|
|
|
(defun zen-writer-full-on ()
|
|
"Zen Writer in fullscreen and zoomed."
|
|
(zen-writer-mode +1)
|
|
(toggle-frame-fullscreen)
|
|
(doom-big-font-mode +1))
|
|
|
|
(defun zen-writer-full-off ()
|
|
"Disable Zen Writer in fullscreen and zoomed."
|
|
(zen-writer-mode -1)
|
|
(toggle-frame-fullscreen)
|
|
(doom-big-font-mode -1))
|
|
|
|
;; mapping suggestion
|
|
;; (map! :leader
|
|
;; (:prefix ("t W" . "Zen Writer")
|
|
;; :desc "Zen Writer Fullscreen" "W" #'zen-writer-full-mode
|
|
;; :desc "Zen Writer Mode" "w" #'zen-writer-mode))
|
|
|
|
(provide 'zen-writer)
|
|
;;; zen-writer.el ends here
|