I showed you my source code, pls respond
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

385 lines
11 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. #+TITLE: Dotfiles
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. Immutable GNU Emacs dotfiles, inspired by Doom, built for Liberty.
  5. + 100% Literate
  6. + 100% Immutable
  7. + 100% Reproducible
  8. * Configuration
  9. :PROPERTIES:
  10. :header-args: :tangle init.el
  11. :END:
  12. Define a function to build literate programming projects.
  13. #+begin_src emacs-lisp
  14. (defun dotfiles/tangle (dir)
  15. "Recursively tangle the Org files within a directory."
  16. (let ((org-files (directory-files-recursively dir "org")))
  17. (dolist (f org-files)
  18. (org-babel-tangle-file f))))
  19. #+end_src
  20. Configure the system font with a single ~font-family~ and define the size, of which variations to the font size are relative to this value.
  21. #+begin_src emacs-lisp
  22. (defvar dotfiles/font "Fira Code")
  23. (defvar dotfiles/font-size 96)
  24. #+end_src
  25. Functionality like =completion= and =hints= can be delayed to avoid popups for common manuevers. Adjust this value to your personal taste.
  26. #+begin_src emacs-lisp
  27. (defvar dotfiles/idle 0.0)
  28. #+end_src
  29. Avoid the infamous *Emacs pinky* by binding =SPC= as a leader key, utilizing the thumb instead of the weaker pinky finger. You may change this value if you want to use something else.
  30. #+begin_src emacs-lisp
  31. (defvar dotfiles/leader-key "SPC")
  32. #+end_src
  33. Emacs creates a lot of files relative to ~user-emacs-directory~, these files are not part of this immutable configuration and do not belong in the emacs directory. To solve this issue, and to retain hermetic evaluation of the Emacs directory, we it to ~~/.cache/emacs~ shortly after initialization, before most packages are loaded.
  34. #+begin_src emacs-lisp
  35. (defvar dotfiles/home user-emacs-directory)
  36. (defvar dotfiles/cache "~/.cache/emacs")
  37. (setq create-lockfiles nil
  38. make-backup-files nil
  39. user-emacs-directory dotfiles/cache)
  40. #+end_src
  41. ** Packages
  42. https://github.com/raxod502/straight.el
  43. + Use the development branch
  44. + Integrate with ~use-package~
  45. Apply the configurations prior to bootstrapping the package manager, by setting (writing) to the variables that =straight= will ultimately read from.
  46. #+begin_src emacs-lisp
  47. (setq straight-repository-branch "develop"
  48. straight-use-package-by-default t)
  49. #+end_src
  50. Bootstrap the package manager, downloading, installing, or configuring depending on the state of the configuration. All packages are downloaded and built from source, and can be pinned to specific git commit hashes.
  51. #+begin_src emacs-lisp
  52. (defvar bootstrap-version)
  53. (let ((bootstrap-file
  54. (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
  55. (bootstrap-version 5))
  56. (unless (file-exists-p bootstrap-file)
  57. (with-current-buffer
  58. (url-retrieve-synchronously
  59. "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
  60. 'silent 'inhibit-cookies)
  61. (goto-char (point-max))
  62. (eval-print-last-sexp)))
  63. (load bootstrap-file nil 'nomessage))
  64. #+end_src
  65. Complete the integration with ~use-package~ by installing it with =straight=.
  66. #+begin_src emacs-lisp
  67. (straight-use-package 'use-package)
  68. #+end_src
  69. ** Cleanup
  70. Despite having our *stateful* and *immutable* configurations seperate, it's good practice to make efforts to reduce the trash created by Emacs.
  71. https://github.com/emacscollective/no-littering
  72. + Reduce the files created by Emacs
  73. #+begin_src emacs-lisp
  74. (use-package no-littering)
  75. #+end_src
  76. Emacs' default user interface is horrendous, but with less than 10 lines of code we can change that.
  77. #+begin_src emacs-lisp
  78. (setq inhibit-startup-message t)
  79. (global-prettify-symbols-mode)
  80. (scroll-bar-mode -1)
  81. (menu-bar-mode -1)
  82. (tool-bar-mode -1)
  83. (tooltip-mode -1)
  84. #+end_src
  85. Write out to all *3* of Emacs' default font faces.
  86. #+begin_src emacs-lisp
  87. (set-face-attribute 'default nil :font dotfiles/font :height dotfiles/font-size)
  88. (set-face-attribute 'fixed-pitch nil :font dotfiles/font :height dotfiles/font-size)
  89. (set-face-attribute 'variable-pitch nil :font dotfiles/font :height dotfiles/font-size)
  90. #+end_src
  91. ** Keybindings
  92. Make the =ESC= key quit prompts, instead of the default =C-g=.
  93. #+begin_src emacs-lisp
  94. (global-set-key (kbd "<escape>") 'keyboard-escape-quit)
  95. #+end_src
  96. https://github.com/justbur/emacs-which-key
  97. + Display the currently incomplete keybinding in a mini-buffer.
  98. #+begin_src emacs-lisp
  99. (use-package which-key
  100. :diminish which-key-mode
  101. :init (which-key-mode)
  102. :config (setq which-key-idle-delay dotfiles/idle))
  103. #+end_src
  104. https://github.com/noctuid/general.el
  105. + Easily configure prefixed keybindings
  106. + Cleaner than default binding methods
  107. #+begin_src emacs-lisp
  108. (use-package general
  109. :config
  110. (general-create-definer dotfiles/leader
  111. :states '(normal motion)
  112. :keymaps 'override
  113. :prefix dotfiles/leader-key))
  114. #+end_src
  115. *** Evil
  116. After a few hour with =vim= I knew it was game over, I cannot even think of another way I would feel comfortable editing text. Luckily, there exist packages to emulate this within Emacs.
  117. https://evil.readthedocs.io/en/latest/index.html
  118. + Extendable VI layer for Emacs
  119. + Disable default keybindings
  120. #+begin_src emacs-lisp
  121. (use-package evil
  122. :init (setq evil-want-integration t
  123. evil-want-keybinding nil)
  124. :config (evil-mode 1))
  125. #+end_src
  126. https://github.com/emacs-evil/evil-collection
  127. + Community keybindings for =evil-mode=
  128. #+begin_src emacs-lisp
  129. (use-package evil-collection
  130. :after evil
  131. :config (evil-collection-init))
  132. #+end_src
  133. https://github.com/redguardtoo/evil-nerd-commenter
  134. + Toggle comments with =M-;=
  135. #+begin_src emacs-lisp
  136. (use-package evil-nerd-commenter
  137. :bind ("M-;" . evilnc-comment-or-uncomment-lines))
  138. #+end_src
  139. *** Shortcuts
  140. Again cherry picked from =Doom=, I want to continue utilizing the muscle memory I have developed from a year of mainlining the framework.
  141. + Find files =SPC . (period)=
  142. + Switch buffers with =SPC , (comma)=
  143. #+begin_src emacs-lisp
  144. (dotfiles/leader
  145. "," '(switch-to-buffer :which-key "Buffer")
  146. "." '(find-file :which-key "File"))
  147. #+end_src
  148. Quit emacs with =SPC q=.
  149. + Saving =q=
  150. + Without =w=
  151. #+begin_src emacs-lisp
  152. (dotfiles/leader
  153. "q" '(:ignore t :which-key "Quit")
  154. "qq" '(save-buffers-kill-emacs :which-key "Save")
  155. "qw" '(kill-emacs :which-key "Now"))
  156. #+end_src
  157. Window management with =SPC w=.
  158. + Swap with =w=
  159. + Close with =c=
  160. + Delete with =d=
  161. + Motions with =h,j,k,l=
  162. + Split with =s + <MOTION>=
  163. #+begin_src emacs-lisp
  164. (dotfiles/leader
  165. "w" '(:ignore t :which-key "Window")
  166. "ww" '(window-swap-states :which-key "Swap")
  167. "wd" '(kill-buffer-and-window :which-key "Delete")
  168. "wc" '(delete-window :which-key "Close")
  169. "wh" '(windmove-left :which-key "Left")
  170. "wj" '(windmove-down :which-key "Down")
  171. "wk" '(windmove-up :which-key "Up")
  172. "wl" '(windmove-right :which-key "Right")
  173. "ws" '(:ignore t :which-key "Split")
  174. "wsj" '(split-window-below :which-key "Down")
  175. "wsl" '(split-window-right :which-key "Right"))
  176. #+end_src
  177. ** Editor
  178. Relative line numbers are important when using =VI= emulation keys. You can prefix most commands with a *number*, allowing you to jump up / down by a line count.
  179. #+begin_example
  180. 5:
  181. 4:
  182. 3:
  183. 2:
  184. 1:
  185. 156: << CURRENT LINE >>
  186. 1:
  187. 2:
  188. 3:
  189. 4:
  190. 5:
  191. #+end_example
  192. https://github.com/emacsmirror/linum-relative
  193. + Integrate with ~display-line-numbers-mode~ for performance
  194. #+begin_src emacs-lisp
  195. (use-package linum-relative
  196. :init (setq linum-relative-backend
  197. 'display-line-numbers-mode)
  198. :config (linum-relative-global-mode))
  199. #+end_src
  200. https://github.com/Fanael/rainbow-delimiters
  201. + Colourize nested parenthesis
  202. #+begin_src emacs-lisp
  203. (use-package rainbow-delimiters
  204. :hook (prog-mode . rainbow-delimiters-mode))
  205. #+end_src
  206. ** Files
  207. Emacs' can feel more modern when icon-fonts are installed and prioritized. I feel that this makes navigation of folders much faster, given that file types may be quickly identified by their corresponding icons.
  208. https://github.com/domtronn/all-the-icons.el
  209. + Collects various icon fonts
  210. #+begin_src emacs-lisp
  211. (use-package all-the-icons)
  212. #+end_src
  213. https://github.com/jtbm37/all-the-icons-dired
  214. + Integration with dired
  215. #+begin_src emacs-lisp
  216. (use-package all-the-icons-dired
  217. :hook (dired-mode . all-the-icons-dired-mode))
  218. #+end_src
  219. When opening =dired=, I don't want to have to press =RET= twice to navigate to the current directory. This can be avoided with ~dired-jump~, included in the =dired-x= package shipped with =dired=.
  220. #+begin_src emacs-lisp
  221. (require 'dired-x)
  222. #+end_src
  223. Open a dired buffer with =SPC d=.
  224. #+begin_src emacs-lisp
  225. (dotfiles/leader
  226. "d" '(dired-jump :which-key "Dired"))
  227. #+end_src
  228. ** Shell
  229. While not a traditional terminal emulator, =eshell= provides me with all of the functionality I expect and require from one. Some users may be left wanting more, I would recommend they look into =vterm=.
  230. https://github.com/zwild/eshell-prompt-extras
  231. + Enable lambda shell prompt
  232. #+begin_src emacs-lisp
  233. (use-package eshell-prompt-extras
  234. :config (setq eshell-highlight-prompt nil
  235. eshell-prompt-function 'epe-theme-lambda))
  236. #+end_src
  237. Open an =eshell= buffer with =SPC e=.
  238. #+begin_src emacs-lisp
  239. (dotfiles/leader
  240. "e" '(eshell :which-key "Shell"))
  241. #+end_src
  242. ** Themes
  243. Bring Emacs' out of the eighties by cherry picking a few modules from =Doom=.
  244. https://github.com/hlissner/emacs-doom-themes
  245. + Modern colour themes
  246. #+begin_src emacs-lisp
  247. (use-package doom-themes
  248. :init (load-theme 'doom-moonlight t))
  249. #+end_src
  250. https://github.com/seagle0128/doom-modeline
  251. + Elegant status bar / modeline
  252. #+begin_src emacs-lisp
  253. (use-package doom-modeline
  254. :init (doom-modeline-mode 1)
  255. :custom ((doom-modeline-height 16)))
  256. #+end_src
  257. ** Writing
  258. *Organize your plain life in plain text*
  259. =Org-mode= is one of the hallmark features of Emacs, and provides the basis for my Literate Programming platform. It's essentially a markdown language with rich features for project management, scheduling, development, and writing. It's hard to convey everything within its capabilities.
  260. + https://orgmode.org
  261. + https://orgmode.org/worg/org-contrib/babel/languages/index.html
  262. + https://orgmode.org/manual/Structure-Templates.html
  263. #+begin_src emacs-lisp
  264. (use-package org
  265. :hook
  266. (org-mode . (lambda ()
  267. (org-indent-mode)
  268. (visual-line-mode 1)
  269. (variable-pitch-mode 1)))
  270. :config
  271. (setq org-ellipsis " ▾"
  272. org-log-done 'time
  273. org-log-into-drawer t
  274. org-src-preserve-indentation t)
  275. (org-babel-do-load-languages
  276. 'org-babel-load-languages
  277. '((shell . t)
  278. (python . t)
  279. (emacs-lisp . t)))
  280. (require 'org-tempo)
  281. (add-to-list 'org-structure-template-alist '("s" . "src"))
  282. (add-to-list 'org-structure-template-alist '("q" . "quote"))
  283. (add-to-list 'org-structure-template-alist '("e" . "example"))
  284. (add-to-list 'org-structure-template-alist '("sh" . "src shell"))
  285. (add-to-list 'org-structure-template-alist '("py" . "src python"))
  286. (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")))
  287. #+end_src
  288. https://github.com/integral-dw/org-superstar-mode
  289. + Make the headline stars more *super*
  290. #+begin_src emacs-lisp
  291. (use-package org-superstar
  292. :hook (org-mode . org-superstar-mode))
  293. #+end_src
  294. * Development