-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrigpa-application-mode.el
174 lines (149 loc) · 6.77 KB
/
rigpa-application-mode.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
;;; rigpa-application-mode.el --- Self-reflective editing modes -*- lexical-binding: t -*-
;; URL: https://github.com/countvajhula/rigpa
;; This program is "part of the world," in the sense described at
;; http://drym.org. From your perspective, this is no different than
;; MIT or BSD or other such "liberal" licenses that you may be
;; familiar with, that is to say, you are free to do whatever you like
;; with this program. It is much more than BSD or MIT, however, in
;; that it isn't a license at all but an idea about the world and how
;; economic systems could be set up so that everyone wins. Learn more
;; at drym.org.
;;
;; This work transcends traditional legal and economic systems, but
;; for the purposes of any such systems within which you may need to
;; operate:
;;
;; This is free and unencumbered software released into the public domain.
;; The authors relinquish any copyright claims on this work.
;;
;;; Commentary:
;;
;; A mode to refer to the application (i.e. Emacs)
;;
;;; Code:
(require 'evil)
(require 'hydra)
(require 'chimera)
(require 'chimera-hydra)
(require 'centaur-tabs)
(require 'beacon)
(defvar rigpa-application--original-transparency 100)
(evil-define-state application
"Application state."
:tag " <A> "
:message "-- APPLICATION --"
:enable (normal))
(defun rigpa-application-toggle-alarm-bell ()
"Toggle whether the alarm bell sounds."
(interactive)
(setq ring-bell-function (if ring-bell-function
nil
'ignore)))
(defun rigpa-application-current-transparency ()
(or (nth 0
(frame-parameter (selected-frame)
'alpha))
100))
(defun rigpa-application--bound (value min-bound max-bound)
"Bound a value within the provided range."
(min (max value min-bound) max-bound))
;; Set transparency of emacs
;; From: https://www.emacswiki.org/emacs/TransparentEmacs
(defun rigpa-application-set-transparency (value)
"Sets the transparency of the frame window. 0=transparent/100=opaque"
(interactive "nTransparency Value 0 - 100 opaque:")
(set-frame-parameter (selected-frame) 'alpha (cons value value)))
(defun rigpa-application--adjust-transparency (delta)
"Adjust the transparency of the frame window by the configured delta,
in the range: 0=transparent/100=opaque"
(interactive)
(rigpa-application-set-transparency
(rigpa-application--bound (+ (rigpa-application-current-transparency)
delta)
0
100)))
(defun rigpa-application-increase-transparency (&optional superlative)
"Increase frame transparency."
(interactive)
(cond ((eq superlative nil)
(rigpa-application--adjust-transparency -1))
((eq superlative 'more)
(rigpa-application--adjust-transparency -5))
(t (rigpa-application-maximize-transparency))))
(defun rigpa-application-decrease-transparency (&optional superlative)
"Decrease frame transparency."
(interactive)
(cond ((eq superlative nil)
(rigpa-application--adjust-transparency 1))
((eq superlative 'more)
(rigpa-application--adjust-transparency 5))
(t (rigpa-application-minimize-transparency))))
(defun rigpa-application-maximize-transparency ()
"Maximize frame transparency (i.e. make transparent)"
(interactive)
(rigpa-application-set-transparency 0))
(defun rigpa-application-minimize-transparency ()
"Minimize frame transparency (i.e. make opaque)"
(interactive)
(rigpa-application-set-transparency 100))
(defun rigpa-application-return-to-original-transparency ()
"Return to original transparency prior to making changes."
(interactive)
(rigpa-application-set-transparency rigpa-application--original-transparency))
(defhydra hydra-transparency (:columns 1
:body-pre (setq rigpa-application--original-transparency
(rigpa-application-current-transparency)))
"Control frame transparency"
("+" rigpa-application-decrease-transparency "decrease transparency")
("-" rigpa-application-increase-transparency "increase transparency")
("k" rigpa-application-decrease-transparency "decrease transparency")
("C-k" (lambda ()
(interactive)
(rigpa-application-decrease-transparency 'more)) "decrease transparency more")
("j" rigpa-application-increase-transparency "increase transparency")
("C-j" (lambda ()
(interactive)
(rigpa-application-increase-transparency 'more)) "increase transparency more")
("M-k" rigpa-application-minimize-transparency "least transparent (opaque)")
("M-j" rigpa-application-maximize-transparency "most transparent")
("q" rigpa-application-return-to-original-transparency "return to original transparency" :exit t)
("<escape>" ignore "quit" :exit t))
(fset (intern "rigpa-application-load-theme")
(symbol-function
(cond ((require 'counsel nil t)
'counsel-load-theme)
((require 'consult nil t)
'consult-theme)
(t 'load-theme))))
(defhydra hydra-application (:columns 2
:exit t
:body-pre (chimera-hydra-signal-entry chimera-application-mode)
:post (chimera-hydra-portend-exit chimera-application-mode t)
:after-exit (chimera-hydra-signal-exit chimera-application-mode
#'chimera-handle-hydra-exit))
"Control application environment"
("y" hydra-transparency/body "transparency")
("t" centaur-tabs-mode "toggle tabs")
("n" display-line-numbers-mode "toggle line numbers")
("b" rigpa-application-toggle-alarm-bell "toggle alarm bell")
("B" beacon-mode "toggle beacon")
("s" scroll-bar-mode "toggle scroll bar")
("l" hl-line-mode "toggle highlight line")
("c" rigpa-application-load-theme "change color scheme")
("f" set-frame-font "change font")
("H-m" rigpa-toggle-menu "show/hide this menu" :exit nil)
("<return>" rigpa-enter-lower-level "enter lower level")
("<escape>" rigpa-enter-higher-level "escape to higher level"))
(defvar chimera-application-mode-entry-hook nil
"Entry hook for rigpa application mode.")
(defvar chimera-application-mode-exit-hook nil
"Exit hook for rigpa application mode.")
(defvar chimera-application-mode
(make-chimera-mode :name "application"
:enter #'hydra-application/body
:pre-entry-hook 'chimera-application-mode-entry-hook
:post-exit-hook 'chimera-application-mode-exit-hook
:entry-hook 'evil-application-state-entry-hook
:exit-hook 'evil-application-state-exit-hook))
(provide 'rigpa-application-mode)
;;; rigpa-application-mode.el ends here