summary refs log tree commit diff
path: root/emacs.org
blob: ac4d0c4a6cdab881ee26058c5446290aafd464f6 (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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
#+TITLE:Emacs config
#+AUTHOR: Crazazy
#+PROPERTY: header-args :tangle yes :noweb yes :results silent

Welp, here it goes. This is a literal config for my emacs setup
I will prbably copy-paste what I have in my literal config, and provide small, fun explanations along the way
For now, prepare this to be not the best documented literal config you've seen.
Also, if you just stumbled accross this at random, there is an easy tangle button at [[file:readme.org][readme.org]]
* Before we start lisping
  This emacs config's dependencies are mostly managed by [[https://nixos.org][nix]], therefore we have to make a nix file before we
  do any emacs configuring by ourselves
  #+name: emacs.nix
  #+begin_src nix
    let
      sources = import ./nix/sources.nix
    in
    sources.emacs { configDir = ./emacsconfig; }
  #+end_src

  This file will load in a emacs configuration framework that will take care of all our dependencies.
  Kind of like an automatic =(setq use-package-ensure t)= without use having to set that ourselves
* Emacs configuring
  Now the real configuring begins!
  for some backwards compat purposes I have decided to but different config subjects into different files
  This won't matter too much as the nix framework is expecting multiple files anyway!
** The bases
   This is only better-defaults. It comes with ido-mode and some other defaults that I forgot to set in my
   init file that I stole from [[https://github.com/editor-bootstrap/emacs-bootstrap][emacs-bootstrap]] months ago
   #+name: emacsconfig/base.el
   #+begin_src elisp :mkdirp yes
     (use-package better-defaults)
   #+end_src
** Generally nice emacs tools
*** Magit
    Simple. Nice. default config. (almost)
    #+name emacsconfig/extras.el
    #+begin_src elisp
      (use-package magit
        :defer t
        :config
        (magit-add-section-hook 'magit-status-sections-hook
                                'magit-insert-modules
                                'magit-insert-stashes
                                'append)
        :bind
        ("C-x g" . magit-status))
      (use-package forge
        :after magit)
    #+end_src
*** IRC
    I use IRC in emacs, with ERC. There is even a small macro so that I can easily join new servers
    with my preferred nickname
    #+name: emacsconfig/extras.el
    #+begin_src elisp
      (use-package erc
        :custom
        (erc-server-reconnect-attempts 10)
        (erc-nick "crazazy")
        :config
        (defmacro irc-quickjoin (servername url &optional nick)
          "create a function to quickly join a server. Servers can be joined with M-x SERVERNAME-irc"
          `(defun ,(intern (concat (symbol-name servername) "-irc")) (password)
             (interactive (list (password-read "Password: ")))
             (erc-tls :server ,url
                      :nick ,(if nick
                                 nick
                               "crazazy")
                      :port 6697
                      :password password)))

        (irc-quickjoin tilde "eu.tilde.chat")
        (irc-quickjoin libera "irc.libera.chat"))
    #+end_src
*** Dashboard
    Gives me access to the most recent files I edited, and some other stuff that I don't really care about
    #+name: emacsconfig/extras.el
    #+begin_src elisp
      (use-package dashboard
        :config (dashboard-setup-startup-hook))
    #+end_src
*** Elfeed
    I don't use elfeed in emacs that much anymore, as I have switched to [[https://www.seamonkey-project.org/][seamonkey]] for my RSS needs.
    Here is my old config anyways. If you want to browse through some default news feel free to remove the last
    =:custom= option
    #+name: emacsconfig/extras.el
    #+begin_src elisp
      (use-package elfeed
        :bind
        ("C-x w" . elfeed)
        (:map elfeed-search-mode-map
              ("C-c a" . elfeed-add-feed)
              ("C-c u" . elfeed-update)
              ("C-c f" . elfeed-update-feed)
              ("C-c r" . elfeed-mark-all-as-read))
        :config
        (defun elfeed-mark-all-as-read ()
          (interactive)
          (mark-whole-buffer)
          (elfeed-search-untag-all-unread))
        :custom
        (elfeed-search-filter  "@6-months-ago +quality")
        (elfeed-feeds  '(("http://feeds.feedburner.com/tweakers/nieuws" NL tech exportable)
                         ("https://discourse.nixos.org/c/announcements/8.rss" nixos programming quality)
                         ("http://www.dnbradio.com/feeds" music podcasts)
                         ("https://codepen.io/spark/feed/" programming quality)
                         ("https://envs.net/~lucidiot/rsrsss/feed.xml" RSS quality)
                         ("https://falseknees.tumblr.com/rss" comics quality)
                         ("https://hackspace.raspberrypi.org/feed" tech programming)
                         ("https://lobste.rs/rss" programming)
                         ("https://news.rickcarlino.com/rss.rss" tech)
                         ("https://nu.nl/rss" NL news exportable)
                         ("https://planet.haskell.org/atom.xml" haskell programming)
                         ("https://planet.nixos.org/atom.xml" nixos programming quality)
                         ("https://reddit.com/r/dnb/.rss" reddit music)
                         ("https://reddit.com/r/programming/.rss" reddit programming)
                         ("https://reddit.com/r/realdubstep/.rss" reddit music)
                         ("https://reddit.com/r/thenetherlands/.rss" NL reddit)
                         ("https://sachachua.com/blog/category/emacs-news/feed" emacs quality programming)
                         ("https://webzine.puffy.cafe/atom.xml" openbsd tech quality programming)
                         ("https://www.fosskers.ca/en/rss" programming quality exportable)
                         ("https://xkcd.com/atom.xml" comics)))
        (elfeed-feeds nil))
    #+end_src
*** Evil mode
    I am originally a vim user, and the standard vim bindings have not left my hands yet,
    I am not a big configurer, so this is mostly just the standard configuration that [[https://github.com/emacs-evil/evil-collection#installation][evil-mode]] advices you to do
    #+begin_src elisp :tangle emacsconfig/evil.el
      (use-package evil
        :init
        (setq evil-want-integration t) ;; This is optional since it's already set to t by default.
        (setq evil-want-keybinding nil)
        :config
        (evil-define-key 'normal global-map "," 'evil-execute-in-god-state)
        (evil-mode 1))

      (use-package evil-collection
        :after evil
        :config
        (evil-collection-init))
    #+end_src
**** God-mode
     To further prove that I have no intentions at all to be busy with making evil bindings for eveything I find
     I have also installed god-mode to help me do effortless keybinding for those programs that don't have evil
     support
     #+begin_src elisp :tangle emacsconfig/evil.el
       (use-package evil-god-state
         :bind
         ("M-," . evil-god-state-bail))

       (use-package god-mode)
     #+end_src
**** Tree-sitter
     There is a pre-configured package that allows for easy tree-sitter support for a few languages. Nixos + tree-sitter
     is surprisingly painless, so I figured I'd just add it
     #+begin_src elisp :tangle emacsconfig/evil.el
       (use-package evil-tree-edit
         :hook
         (java-mode . evil-tree-edit-mode)
         (python-mode . evil-tree-edit-mode))
     #+end_src
*** Which-key
    Has god-mode support
    #+name: emacsconfig/extras.el
    #+begin_src elisp
      (use-package which-key
        :after god-mode
        :config
        (which-key-enable-god-mode-support)
        (which-key-mode))
    #+end_src
** Programming-related emacs tools
   I do computer science, so from now and then I tend to program a bit. Here are all the tools I use to accomplish
   that stuff
*** Company
    Generally nice for auto-completion anywhere. I think here is also the place to note that I am not a huge fan
    of language-servers, as I've had bad experiences with them when I was still using vim
    #+name: emacsconfig/extras.el
    #+begin_src elisp
      (use-package company
        :bind
        ("C-SPC" . company-complete))
    #+end_src
*** Matching of parentheses and other stuff
    "ERROR: Unmatched parenteses/braces/whatever" is really a thing I would prefer to never see again
    It has nix and lisp support, but other langages are fairly standards so not much configuration needed there
    #+name: emacsconfig/extras.el
    #+begin_src elisp
      (use-package smartparens
        :hook
        (emacs-lisp-mode . smartparens-mode)
        (nix-mode . smartparens-mode)
        (lisp-mode . smartparens-mode)
        :config
        (sp-with-modes '(lisp-mode emacs-lisp-mode)
          (sp-local-pair "'" nil :actions nil)
          (sp-local-pair "`" nil :actions nil))

        (sp-with-modes '(nix-mode)
          (sp-local-pair "'" nil :actions nil)
          (sp-local-pair "''" "''")))
    #+end_src
*** Languages
    Other than that, there are some language-specific setups that I want to do,which are a bit more complicated
    than just "editing a file"
**** Nix
     Nix is a fairly essential language here. Not just because I run NixOS, but also because it provides
     external packages (interpreters, compilers, tooling etc.) to the programs that need it
***** Nix mode
      This config is just part of editing nix config. It is supposed to come with company support, but
      the auto-completion backend turns out to not be that great. We'll see what I do with it
      #+name: emacsconfig/nix.el
      #+begin_src elisp
        (use-package nix-mode
          :mode "\\.nix\\'"
          :hook
          (nix-mode . company-mode)
          :config
          ;; the company-nix backend is not available in melpa, but has no new dependencies
          (unless (package-installed-p 'company-nix)
            (with-temp-buffer
              (url-insert-file-contents "https://github.com/NixOS/nix-mode/raw/master/nix-company.el")
              (eval-buffer)))
          (add-hook 'nix-mode-hook (lambda ()
                                     (set (make-local-variable 'company-backends)
                                          '((company-nix)))))
          (add-hook 'nix-mode-hook 'company-mode))
      #+end_src
***** Nix package management
      I use nix-sandbox for managing nix package for other languages.
      One of the functions doesn't work that well for me so I replaced it with something that does
      #+name: emacsconfig/nix.el
      #+begin_src elisp
        (use-package nix-sandbox
          :config
          (defun nix-executable-find (sandbox executable)
            "finds an EXECUTABLE in SANDBOX"
            (set (make-local-variable 'exec-path) (nix-exec-path sandbox))
            (executable-find executable)))
      #+end_src
      Beyond that, there is a helper function that makes it easy to quickly define environments with the required
      packages for a programming language
      #+name: emacsconfig/nix.el
      #+begin_src elisp
        (defun nix-env-from-packages (name &rest packages)
          "create a nix environment from nix packages. returns the location of the environment"
          (interactive (append
                        (list (read-string "Environment name: " nil nil "nameless"))
                        (split-string (read-string "Packages: "))))
          (with-temp-buffer
            (insert (format "
        { pkgs ? import %s {}}:
        pkgs.mkShell {
        buildInputs = with pkgs;[
        %s
        ];
        }
            " (or nix-nixpkgs-path "<nixpkgs>") (apply 'concat (intersperse "\n" packages))))
            (write-file (concat temporary-file-directory name "-env/shell.nix"))
            (nix-find-sandbox (concat temporary-file-directory name "-env"))))
      #+end_src
**** Python
     Python is a bit weird. It had no intentions at all to do things the way I wanted it to do things with
     use-package, so I had to find a weird work-arounds with add-hook and all that stuff
     #+begin_src elisp :tangle emacsconfig/python.el :padline no :noweb no-export
       (add-hook 'python-mode-hook (lambda ()
                                     <<el-python-config>>
                                     <<el-python-config-2>>))

     #+end_src
     First we set an interpreter with nix, it comes with all the python autocompletion tools we need
     #+name: el-python-config
     #+begin_src elisp
       (setq python-shell-interpreter
             (nix-executable-find
              (nix-env-from-packages "python" "(python3.withPackages (p: with p; [pygame virtualenvwrapper pip sqlite jedi flake8 yapf autopep8 black]))")
              "python"))

     #+end_src
     Then we introduce elpy with so that it can use all the tools immidiately without downloading them
     #+name: el-python-config-2
     #+begin_src elisp
       (use-package elpy
         :config
         (elpy-enable)
         (setq elpy-rpc-python-command python-shell-interpreter))

     #+end_src
**** Web stuff
     I also have made some basic webpages. I haven't gotten too deep into JS with emacs yet, so this section
     might expand later, but so far this is what I have
***** Web mode
      General xml stuff editing. Fairly standard
      #+name: emacsconfig/web.el
      #+begin_src elisp
        (use-package web-mode
          :mode (("\\.x?html?\\'" . web-mode)
                 ("\\.x[sm]l\\'"  . web-mode)
                 ("\\.css\\'"     . web-mode)
                 ("\\.jsx?\\'"    . web-mode)
                 ("\\.tsx?\\'"    . web-mode)
                 ("\\.json\\'"    . web-mode))
          :custom
          (web-mode-markup-indent-offset 2) ; HTML
          (web-mode-css-indent-offset 2)    ; CSS
          (web-mode-code-indent-offset 2)   ; JS/JSX/TS/TSX
          (web-mode-content-types-alist '(("jsx" . "\\.js[x]?\\'"))))
        (use-package elnode)

      #+end_src
***** Emmet mode
      for quickly inserting a whole XML tree
      #+name: emacsconfig/web.el
      #+begin_src elisp
        (use-package emmet-mode
          :hook
          (sgml-mode . emmet-mode)
          (web-mode . emmet-mode)
          (css-mode . emmet-mode)
          :bind
          ("TAB" . emmet-dwim)
          :config
          (defun emmet-dwim (prefix)
            (interactive "p")
            (or
             (emmet-go-to-edit-point prefix)
             (emmet-expand-line prefix)
             (evil-jump-forward prefix))))
      #+end_src