about summary refs log tree commit diff stats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/acdw.el82
1 files changed, 74 insertions, 8 deletions
diff --git a/lisp/acdw.el b/lisp/acdw.el index 69f9a7f..7b555fd 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el
@@ -22,9 +22,9 @@
22;; Utility constants 22;; Utility constants
23 23
24(defconst acdw/system (pcase system-type 24(defconst acdw/system (pcase system-type
25 ('gnu/linux :home) 25 ('gnu/linux :home)
26 ((or 'msdos 'windows-nt) :work) 26 ((or 'msdos 'windows-nt) :work)
27 (_ :other)) 27 (_ :other))
28 "Which computer system is currently being used.") 28 "Which computer system is currently being used.")
29 29
30 30
@@ -38,7 +38,7 @@ is unfocused."
38 `(progn 38 `(progn
39 (defun ,func-name () "Defined by `when-unfocused'." 39 (defun ,func-name () "Defined by `when-unfocused'."
40 (when (seq-every-p #'null 40 (when (seq-every-p #'null
41 (mapcar #'frame-focus-state (frame-list))) 41 (mapcar #'frame-focus-state (frame-list)))
42 ,@forms)) 42 ,@forms))
43 (add-function :after after-focus-change-function #',func-name)))) 43 (add-function :after after-focus-change-function #',func-name))))
44 44
@@ -52,7 +52,7 @@ each hook in HOOKS."
52 `(progn 52 `(progn
53 (defun ,func-name () "Defined by `hook-defun'." ,@forms) 53 (defun ,func-name () "Defined by `hook-defun'." ,@forms)
54 ,@(dolist (hook hook-list hook-defun-add-hook-list) 54 ,@(dolist (hook hook-list hook-defun-add-hook-list)
55 (push `(add-hook ',hook #',func-name) hook-defun-add-hook-list))))) 55 (push `(add-hook ',hook #',func-name) hook-defun-add-hook-list)))))
56 56
57(defun refresh-emacs () 57(defun refresh-emacs ()
58 "Reload Emacs's configuration files." 58 "Reload Emacs's configuration files."
@@ -73,7 +73,7 @@ if MAKE-DIRECTORY is non-nil."
73 user-emacs-directory))) 73 user-emacs-directory)))
74 (if file 74 (if file
75 (let ((file-name (expand-file-name (convert-standard-filename file) 75 (let ((file-name (expand-file-name (convert-standard-filename file)
76 dir))) 76 dir)))
77 (when make-directory 77 (when make-directory
78 (make-directory (file-name-directory file-name) 'parents)) 78 (make-directory (file-name-directory file-name) 'parents))
79 file-name) 79 file-name)
@@ -82,12 +82,33 @@ if MAKE-DIRECTORY is non-nil."
82(defun acdw/gc-enable () 82(defun acdw/gc-enable ()
83 "Enable the Garbage collector." 83 "Enable the Garbage collector."
84 (setq gc-cons-threshold (* 800 1024 1024) 84 (setq gc-cons-threshold (* 800 1024 1024)
85 gc-cons-percentage 0.1)) 85 gc-cons-percentage 0.1))
86 86
87(defun acdw/gc-disable () 87(defun acdw/gc-disable ()
88 "Functionally disable the Garbage collector." 88 "Functionally disable the Garbage collector."
89 (setq gc-cons-threshold most-positive-fixnum 89 (setq gc-cons-threshold most-positive-fixnum
90 gc-cons-percentage 0.8)) 90 gc-cons-percentage 0.8))
91
92(defun acdw/sunrise-sunset (sunrise-command sunset-command)
93 "Run commands at sunrise and sunset."
94 (let* ((times-regex (rx (* nonl)
95 (: (any ?s ?S) "unrise") " "
96 (group (repeat 1 2 digit) ":"
97 (repeat 1 2 digit)
98 (: (any ?a ?A ?p ?P) (any ?m ?M)))
99 (* nonl)
100 (: (any ?s ?S) "unset") " "
101 (group (repeat 1 2 digit) ":"
102 (repeat 1 2 digit)
103 (: (any ?a ?A ?p ?P) (any ?m ?M)))
104 (* nonl)))
105 (ss (sunrise-sunset))
106 (_m (string-match times-regex ss))
107 (sunrise-time (match-string 1 ss))
108 (sunset-time (match-string 2 ss)))
109 (run-at-time sunrise-time (* 60 60 24) sunrise-command)
110 (run-at-time sunset-time (* 60 60 24) sunset-command)
111 (run-at-time "12:00am" (* 60 60 24) sunset-command)))
91 112
92 113
93;; Make `C-z' more useful 114;; Make `C-z' more useful
@@ -98,5 +119,50 @@ if MAKE-DIRECTORY is non-nil."
98 (define-key map "\C-z" c-z) 119 (define-key map "\C-z" c-z)
99 map)) 120 map))
100 121
122
123;; `acdw/reading-mode'
124(define-minor-mode acdw/reading-mode
125 "A mode for reading."
126 :init-value nil
127 :lighter " Read"
128 (if acdw/reading-mode
129 (progn ;; turn on
130 ;; settings
131 (setq-local mode-line-format
132 '(:eval
133 (let* ((fmt " Reading %b")
134 (len (length (format-mode-line fmt))))
135 (concat
136 (propertize " "
137 'display `((space :align-to (- right
138 ,len)))
139 'face '(:inherit italic))
140 fmt)))
141 orig-indicate-empty-lines indicate-empty-lines
142 indicate-empty-lines nil
143 orig-indicate-buffer-boundaries indicate-buffer-boundaries
144 indicate-buffer-boundaries nil)
145 ;; disable modes
146 (dolist (mode '(display-fill-column-indicator-mode))
147 (when (fboundp mode)
148 (funcall mode -1)))
149 ;; enable modes
150 (dolist (mode '(iscroll-mode olivetti-mode))
151 (when (fboundp mode)
152 (funcall mode +1))))
153 ;; turn off
154 ;; settings
155 (setq-local indicate-empty-lines orig-indicate-empty-lines
156 indicate-buffer-boundaries orig-indicate-buffer-boundaries)
157 (kill-local-variable 'mode-line-format)
158 ;; enable modes
159 (dolist (mode '(display-fill-column-indicator-mode))
160 (when (fboundp mode)
161 (funcall mode +1)))
162 ;; disable modes
163 (dolist (mode '(olivetti-mode iscroll-mode))
164 (when (fboundp mode)
165 (funcall mode -1)))))
166
101(provide 'acdw) 167(provide 'acdw)
102;;; acdw.el ends here 168;;; acdw.el ends here