zen-writer.el/zen-writer.el

139 lines
4.0 KiB
EmacsLisp

;;; zen-writer.el --- Zen Writer -*- lexical-binding: t; -*-
;; Copyright (C) 2021 Yann Esposito
;; 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"))
;; License: GPL v3.0
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; 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)
;; load the local themes
(add-to-list 'custom-theme-load-path
(concat (file-name-directory (or load-file-name buffer-file-name)) "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)
(defvar zen-writer--pre-zen-doom-theme doom-theme)
;; 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)
(progn
;; save theme before enabling ZenWriter
(setq zen-writer--pre-zen-doom-theme doom-theme)
(zen-writer-off))))
(defun zen-writer-select-user-theme ()
"Change the theme back to the theme prior to the Zen Writer 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))
(dark? (or (> hour 17) (< hour 7)))
(theme (if dark? zen-writer-dark-theme zen-writer-light-theme)))
(when (not (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."
(zen-writer-select-theme)
(hl-sentence-mode +1))
(defun zen-writer-off ()
"Deactivate Zen Writer."
(zen-writer-select-user-theme)
(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))
(map! :leader
(:prefix ("t W" . "Zen Writer")
:desc "Full Zen Writer" "W" #'zen-writer-full-mode
:desc "Zen Writer" "w" #'zen-writer-mode))
(provide 'zen-writer)
;;; zen-writer.el ends here