aboutsummaryrefslogtreecommitdiff
path: root/.emacs.d/rul-emacs.org
blob: 9e5fec47647ed59616cce1e99c4f0be78853e3ee (plain)
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
210
211
212
213
214
215
216
217
This is (will be) my Emacs literate configuration file. A self
contained file with all my configuration is useful for documentation
purposes. It will be modeled using the technique described by
Protesilaos for his own Emacs config file:
<https://protesilaos.com/emacs/dotemacs>.

This method consists in generating all files /a priori/, after modifying
this file, and *not* at load time, as that would be too slow.

#+begin_src emacs-lisp :tangle no :results none
(org-babel-tangle)
#+end_src

* Directory and file structure

- =early-init.el=: quoting the [[https://www.gnu.org/software/emacs/manual/html_node/emacs/Early-Init-File.html][Emacs documentation]], this file is "loaded
  before the package system and GUI is initialized, so in it you can
  customize variables that affect the package initialization process"
- =init.el=: the skeleton of my configuration framework. It will load
  the rest of the modules.
- =rul-emacs-modules/=: a directory with Emacs modules specific to my
  configuration. Modules group code related to a topic or theme of
  configuration. For example, =rul-prog.el= contains code related to
  programming, and =rul-org.el= contains code related to org-mode. If a
  module gets too big, I can create a smaller module under the same
  topic; for example, =rul-org-agenda.el=.
- =rul-post-init.el=: this file will be loaded after =init.el=, and will
  normally live in other git repository. Here I normally add overrides
  needed in my work computer.
- =rul-emacs.org=: this file. It (will) generate the rest of the structure.

* The early init
** Graphical aspects
Customization of graphical aspects of Emacs, such as size, panels, etc.

#+begin_src emacs-lisp :tangle "early-init.el"
;; I don't use any of these
(menu-bar-mode -1)
(tool-bar-mode -1)
(scroll-bar-mode -1)

;; Avoid initial flash of light.
;; Inspired on prot-emacs-avoid-initial-flash-of-light.
(setq mode-line-format nil)
(set-face-attribute 'default nil :background "#000000" :foreground "#ffffff")
(set-face-attribute 'mode-line nil :background "#000000" :foreground "#ffffff" :box 'unspecified)
#+end_src

** Frame configuration
I like to keep a few frames open all the time. A main frame, where I
open my org files, code, etc. A frame for communication and reading,
such as email and feeds, and a frame for terminals.

Currently, the frames are all the same, but I will add configuration
to distinguish them so I can automate their placement in my desktop
environment.

#+begin_src emacs-lisp :tangle "early-init.el"
;; Do not resize when font size changes
(setq frame-resize-pixelwise t)

;; By default, start maximized
(add-to-list 'default-frame-alist '(fullscreen . maximized))

;; No need for titlebar
(modify-frame-parameters nil '((undecorated . t)))

;; Name frames to ease switching between them
(add-hook 'after-init-hook (lambda () (set-frame-name "main")))
#+end_src

** Miscellany
#+begin_src emacs-lisp :tangle "early-init.el"
;; Initialise installed packages, otherwise, basic functions are not
;; available during the initialization stage.
(setq package-enable-at-startup t)

;; Do not report warnings. It's too noisy.
(setq native-comp-async-report-warnings-errors 'silent)

;; Keep things minimal
(setq inhibit-startup-screen t)
(setq inhibit-startup-echo-area-message user-login-name)
#+end_src

* The init.el file
** Package matters

I use package from both stable and bleeding-edge Melpa.

#+begin_src emacs-lisp :tangle "init.el"
(add-to-list 'package-archives
             '("melpa-stable" . "https://stable.melpa.org/packages/") t)

(add-to-list 'package-archives
             '("melpa" . "https://melpa.org/packages/") t)
#+end_src
** Backups
Emacs tends to clutter the filesystem with backup files. A backup file is normally the filename with a =~= suffix. I rather have my filesystem clean, and centralize all backups in a single directory.

#+begin_src emacs-lisp :tangle "init.el"
(if (file-directory-p "~/.backup")
    (setq backup-directory-alist '(("." . "~/.backup")))
  (message "Directory does not exist: ~/.backup"))

(setq
 backup-by-copying t    ; Don't delink hardlinks
 delete-old-versions t  ; Clean up the backups
 kept-new-versions 3    ; keep some new versions
 kept-old-versions 2   ; and some old ones, too
 version-control t)      ; Use version numbers on backups
#+end_src
** Customizations
Customizations don't place nicely with version control, so I do them in a random file that won't get persisted.

Configurations that need persisting will be added to =custom-set-variables= and =custom-set-faces=.

#+begin_src emacs-lisp :tangle "init.el"
;; Do not persist customizations
(setq custom-file (make-temp-file "emacs-custom-"))
#+end_src
** Global keybindings
This section defines keybindings common across all modes.

#+begin_src emacs-lisp :tangle "init.el"
;; Global keybindings
(global-set-key (kbd "C-c R") 'revert-buffer)
(global-set-key (kbd "C-c w") 'whitespace-cleanup)

(defun help/insert-em-dash ()
  "Inserts an EM-DASH (not a HYPEN, not an N-DASH)"
  (interactive)
  (insert "—"))

(global-set-key (kbd "C--") #'help/insert-em-dash)
#+end_src
** Editor interface
General configurations related to text editing across all modes.

#+begin_src emacs-lisp :tangle "init.el"
(setq fill-column 79) ; Wrap lines
(setq mouse-yank-at-point t) ; Do not follow mouse curors when mouse-yanking

(setq-default indent-tabs-mode nil) ; No tabs when indenting
(setq-default tab-width 4) ; How many spaces a tab represents

(setq initial-scratch-message "")

(defalias 'yes-or-no-p 'y-or-n-p)

;; Only flash the mode line
(setq ring-bell-function
      (lambda ()
        (let ((orig-fg (face-foreground 'mode-line)))
          (set-face-foreground 'mode-line "#F2804F")
          (run-with-idle-timer 0.1 nil
                               (lambda (fg) (set-face-foreground 'mode-line fg))
                               orig-fg))))

;; Highlight parens
(setq show-paren-delay 0)
(show-paren-mode 1)

(savehist-mode 1) ; Save histories, including minibuffer

(save-place-mode 1) ; Remember and restore cursor information

(setq auto-save-no-message t) ; Do not print a message when auto-saving

(pixel-scroll-precision-mode 1) ; Precision scrolling
#+end_src
** Emacs server
I used to run Emacs as a systemd daemon, but it was not too deterministic as sometimes it would break.

  https://rbenencia.name/blog/emacs-daemon-as-a-systemd-service/

Now, I simply start it from Emacs itself. This approach works well for me.

#+begin_src emacs-lisp :tangle "init.el"
;; Server
(require 'server)
(setq server-client-instructions nil) ; Keep it quiet when opening an ec

(unless (server-running-p)
  (server-start))
#+end_src
** Modules machinery
#+begin_src emacs-lisp :tangle "init.el"
(dolist (path '("~/.emacs.d/rul-lisp/config" "~/.emacs.d/rul-lisp/packages"))
  (add-to-list 'load-path path))

(require 'rul-completion)
(require 'rul-fm)
(require 'rul-fonts)
(require 'rul-prog)
(require 'rul-elfeed)
(require 'rul-mail)
(require 'rul-modeline)
(require 'rul-media)
(require 'rul-org)
(require 'rul-wm)
(require 'rul-write)

;; Init parts (will be deprecated in favor of packages)
(load-file "~/.emacs.d/rul-init.d/hydra.el")
(load-file "~/.emacs.d/rul-init.d/ibuffer.el")
(load-file "~/.emacs.d/rul-init.d/imenu.el")
(load-file "~/.emacs.d/rul-init.d/magit.el")
(load-file "~/.emacs.d/rul-init.d/vterm.el")
(load-file "~/.emacs.d/rul-init.d/which-key.el")

(when-let* ((file (locate-user-emacs-file "rul-post-init.el"))
            ((file-exists-p file)))
  (load-file file))

;; init.el ends here
#+end_src
nihil fit ex nihilo