summaryrefslogtreecommitdiff
path: root/.config/emacs/modules/mm-theme.el
blob: 3e14fe296021e209702339f0fad5496134319a86 (plain) (blame)
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
;;; mm-theme.el --- Emacs theme settings  -*- lexical-binding: t; -*-

^L
;;; Custom Theme

(load-theme 'mango :no-confirm)

^L
;;; Fonts

(defvar mm-theme-monospace-font `(,(if mm-darwin-p
                                       "Iosevka Custom"
                                     "Iosevka Smooth")
                                  :weight regular
                                  :height 162)
  "The default monospace font.
This is a plist containing a font name, -weight, and -height.")

(defvar mm-theme-proportional-font '("SF Pro" :weight regular :height 162)
  "The default proportional font.
This is a plist containing a font name, -weight, and -height.")

(defun mm-theme-set-fonts (&optional _frame)
  "Set frame font settings.
Sets the frame font settings according to the fonts specified by
`mm-theme-monospace-font' and `mm-theme-proportional-font'.

This function can be used as a hook in `after-make-frame-functions' and
_FRAME is ignored."
  (interactive)
  (let* ((mono-family (car mm-theme-monospace-font))
         (mono-props  (cdr mm-theme-monospace-font))
         (prop-family (car mm-theme-proportional-font))
         (prop-props  (cdr mm-theme-proportional-font))
         (mono-weight (plist-get mono-props :weight))
         (mono-height (plist-get mono-props :height))
         (prop-weight (plist-get prop-props :weight))
         (prop-height (plist-get prop-props :height)))
    ;; Some characters in this font are larger than usual
    (when (string= mono-family "Iosevka Smooth")
      (dolist (rune '(?… ?— ?← ?→ ?⇐ ?⇒ ?⇔))
        (set-char-table-range char-width-table rune 2)))
    (set-face-attribute 'default nil
                        :font mono-family
                        :weight mono-weight
                        :height mono-height)
    (set-face-attribute 'fixed-pitch nil
                        :font mono-family
                        :weight mono-weight
                        :height mono-height)
    (set-face-attribute 'variable-pitch nil
                        :font prop-family
                        :weight prop-weight
                        :height prop-height)))

(if (daemonp)
    (add-hook 'after-make-frame-functions #'mm-theme-set-fonts)
  (mm-theme-set-fonts))

;; Ligature Settings

(defvar mm-theme-ligatures-alist
  `(((c-mode c-ts-mode c++-mode c++-ts-mode)
     . ("->"))
    ((c++-mode c++-ts-mode)
     . ("::"))
    ((js-mode js-ts-mode typescript-ts-mode vue-ts-mode)
     . (("=" ,(rx (or ?> (** 1 2 ?=))))
        ("!" ,(rx        (** 1 2 ?=)))))
    (go-ts-mode
     . (":=" "<-"))
    ((python-mode python-ts-mode)
     . (":=" "->"))
    ((mhtml-mode html-mode html-ts-mode vue-ts-mode)
     . ("<!--" "-->" "/>"))
    (prog-mode
     . ("<=" ">=" "==" "!=" "*=" "__")))
  "Ligatures to enable in specific modes.
Elements of this alist are of the form:

  (SPEC . LIGATURES)

Where LIGATURES is a list of ligatures to enable for the set of modes
described by SPEC.

SPEC can be either a symbol, or a list of symbols.  These symbols should
correspond to modes for which the associated LIGATURES should be enabled.

A mode may also be specified in multiple entries.  To configure
`go-ts-mode' to have its set of ligatures be a super-set of the
ligatures for `c-ts-mode', the following two entries could be added:

  \\='((c-ts-mode go-ts-mode) . (\">=\" \"<=\" \"!=\" \"==\"))
  \\='(go-ts-mode             . (\":=\"))")

(defun mm-theme-update-ligatures ()
  "Update the ligature composition tables.
After running this function you may need to restart `ligature-mode'.

Also see `mm-theme-ligatures-alist'."
  (interactive)
  (setopt ligature-composition-table nil)
  (cl-loop for (spec . ligatures) in mm-theme-ligatures-alist
           do (ligature-set-ligatures spec ligatures)))

(use-package ligature
  :ensure t
  :if (or mm-darwin-p
          (seq-contains-p (split-string system-configuration-features)
                          "HARFBUZZ"))
  :hook prog-mode
  :config
  (mm-theme-update-ligatures))

^L
;;; Background Opacity

(defvar mm-theme-background-opacity 100
  "Opacity of the graphical Emacs frame.
A value of 0 is fully transparent while 100 is fully opaque.")

(defun mm-theme-background-opacity (opacity)
  "Set the current frames' background opacity.
See also the `mm-theme-background-opacity' variable."
  (interactive
   (list (mm-as-number
          (read-string
           (format-prompt "Background opacity"
                          (default-value 'mm-theme-background-opacity))
           nil nil mm-theme-background-opacity))))
  (set-frame-parameter nil 'alpha-background opacity))

(add-to-list
 'default-frame-alist (cons 'alpha-background mm-theme-background-opacity))

^L
;;; Divider Between Windows

(use-package frame
  :hook (after-init . window-divider-mode))

^L
;;; Pulse Line on Jump

(use-package pulsar
  :ensure t
  :hook (after-init . pulsar-global-mode)
  :custom
  (pulsar-pulse t)
  (pulsar-delay .05)
  (pulsar-iterations 10)
  (pulsar-face 'hl-line)
  :config
  (dolist (command #'(backward-paragraph
                      e/scroll-down
                      e/scroll-up
                      forward-paragraph
                      jump-to-register
                      pop-global-mark))
    (add-to-list 'pulsar-pulse-functions command))
  ;; Integrate with ‘compilation-mode’
  (add-hook 'next-error-hook #'pulsar-pulse-line)
  :bind
  (("C-c h l" . pulsar-highlight-dwim)))

^L
;;; Add Padding

(use-package spacious-padding
  :ensure t
  :hook after-init)

^L
;;; Pretty Page Boundaries

(use-package page-break-lines
  :ensure t
  :hook (after-init . global-page-break-lines-mode)
  :config
  (dolist (mode '(c-mode c++-mode gsp-ts-mode))
    (add-to-list 'page-break-lines-modes mode)
    (let ((ts-mode (mm-mode-to-ts-mode mode)))
      (when (fboundp ts-mode)
        (add-to-list 'page-break-lines-modes ts-mode))))
  (add-hook
   'change-major-mode-hook
   (defun mm-theme--set-page-break-max-width ()
     (setopt page-break-lines-max-width fill-column)))
  ;; Since the ‘^L’ character is replaced by a horizontal rule, the
  ;; cursor should appear below the horizontal rule.  When moving
  ;; backwards we need to account for the fact that the cursor is
  ;; actually one character ahead of hte page break and adjust
  ;; accordingly.
  (advice-add
   #'forward-page :after
   (defun mm-theme--forward-char (&rest _)
     (forward-char)))
  (advice-add
   #'backward-page :before
   (defun mm-theme--backward-char (&rest _)
     (backward-char))))

^L
;;; More Intuiative UI for Certain Modes

(use-package line-selection-mode
  :hook ((bookmark-bmenu-mode dired-mode ibuffer-mode) . line-selection-mode))

(provide 'mm-theme)