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.

484 lines
13 KiB

4 years ago
4 years ago
4 years ago
4 years ago
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 :results silent
  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. https://github.com/abo-abo/hydra
  116. + Transient keybindings sharing a common prefix
  117. #+begin_src emacs-lisp
  118. (use-package hydra)
  119. #+end_src
  120. *** Evil
  121. 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.
  122. https://evil.readthedocs.io/en/latest/index.html
  123. + Extendable VI layer for Emacs
  124. + Disable default keybindings
  125. #+begin_src emacs-lisp
  126. (use-package evil
  127. :init (setq evil-want-integration t
  128. evil-want-keybinding nil)
  129. :config (evil-mode 1))
  130. #+end_src
  131. https://github.com/emacs-evil/evil-collection
  132. + Community keybindings for =evil-mode=
  133. #+begin_src emacs-lisp
  134. (use-package evil-collection
  135. :after evil
  136. :config (evil-collection-init))
  137. #+end_src
  138. https://github.com/redguardtoo/evil-nerd-commenter
  139. + Toggle comments with =M-;=
  140. #+begin_src emacs-lisp
  141. (use-package evil-nerd-commenter
  142. :bind ("M-;" . evilnc-comment-or-uncomment-lines))
  143. #+end_src
  144. *** Zoom
  145. Increase the font size in buffers with =SPC f=.
  146. + Increase =j=
  147. + Decrease =k=
  148. + Finish =f=
  149. #+begin_src emacs-lisp
  150. (defhydra hydra-text-scale (:timeout 4)
  151. "Scale"
  152. ("j" text-scale-increase "Increase")
  153. ("k" text-scale-decrease "Decrease")
  154. ("f" nil "Finished" :exit t))
  155. #+end_src
  156. #+begin_src emacs-lisp
  157. (dotfiles/leader
  158. "f" '(hydra-text-scale/body :which-key "Font"))
  159. #+end_src
  160. *** Shortcuts
  161. Again cherry picked from =Doom=, I want to continue utilizing the muscle memory I have developed from a year of mainlining the framework.
  162. + Find files =SPC . (period)=
  163. + Switch buffers with =SPC , (comma)=
  164. #+begin_src emacs-lisp
  165. (dotfiles/leader
  166. "," '(switch-to-buffer :which-key "Buffer")
  167. "." '(find-file :which-key "File"))
  168. #+end_src
  169. Quit emacs with =SPC q=.
  170. + Saving =q=
  171. + Without =w=
  172. #+begin_src emacs-lisp
  173. (dotfiles/leader
  174. "q" '(:ignore t :which-key "Quit")
  175. "qq" '(save-buffers-kill-emacs :which-key "Save")
  176. "qw" '(kill-emacs :which-key "Now"))
  177. #+end_src
  178. Window management with =SPC w=.
  179. + Swap with =w=
  180. + Close with =c=
  181. + Delete with =d=
  182. + Motions with =h,j,k,l=
  183. + Split with =s + <MOTION>=
  184. #+begin_src emacs-lisp
  185. (dotfiles/leader
  186. "w" '(:ignore t :which-key "Window")
  187. "ww" '(window-swap-states :which-key "Swap")
  188. "wd" '(kill-buffer-and-window :which-key "Delete")
  189. "wc" '(delete-window :which-key "Close")
  190. "wh" '(windmove-left :which-key "Left")
  191. "wj" '(windmove-down :which-key "Down")
  192. "wk" '(windmove-up :which-key "Up")
  193. "wl" '(windmove-right :which-key "Right")
  194. "ws" '(:ignore t :which-key "Split")
  195. "wsj" '(split-window-below :which-key "Down")
  196. "wsl" '(split-window-right :which-key "Right"))
  197. #+end_src
  198. ** Editor
  199. 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.
  200. #+begin_example
  201. 5:
  202. 4:
  203. 3:
  204. 2:
  205. 1:
  206. 156: << CURRENT LINE >>
  207. 1:
  208. 2:
  209. 3:
  210. 4:
  211. 5:
  212. #+end_example
  213. https://github.com/emacsmirror/linum-relative
  214. + Integrate with ~display-line-numbers-mode~ for performance
  215. #+begin_src emacs-lisp
  216. (use-package linum-relative
  217. :init (setq linum-relative-backend
  218. 'display-line-numbers-mode)
  219. :config (linum-relative-global-mode))
  220. #+end_src
  221. https://github.com/Fanael/rainbow-delimiters
  222. + Colourize nested parenthesis
  223. #+begin_src emacs-lisp
  224. (use-package rainbow-delimiters
  225. :hook (prog-mode . rainbow-delimiters-mode))
  226. #+end_src
  227. ** Files
  228. 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.
  229. https://github.com/domtronn/all-the-icons.el
  230. + Collects various icon fonts
  231. #+begin_src emacs-lisp
  232. (use-package all-the-icons)
  233. #+end_src
  234. https://github.com/jtbm37/all-the-icons-dired
  235. + Integration with dired
  236. #+begin_src emacs-lisp
  237. (use-package all-the-icons-dired
  238. :hook (dired-mode . all-the-icons-dired-mode))
  239. #+end_src
  240. 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=.
  241. #+begin_src emacs-lisp
  242. (require 'dired-x)
  243. #+end_src
  244. Open a dired buffer with =SPC d=.
  245. #+begin_src emacs-lisp
  246. (dotfiles/leader
  247. "d" '(dired-jump :which-key "Dired"))
  248. #+end_src
  249. ** Shell
  250. 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=.
  251. https://github.com/zwild/eshell-prompt-extras
  252. + Enable lambda shell prompt
  253. #+begin_src emacs-lisp
  254. (use-package eshell-prompt-extras
  255. :config (setq eshell-highlight-prompt nil
  256. eshell-prompt-function 'epe-theme-lambda))
  257. #+end_src
  258. Open an =eshell= buffer with =SPC e=.
  259. #+begin_src emacs-lisp
  260. (dotfiles/leader
  261. "e" '(eshell :which-key "Shell"))
  262. #+end_src
  263. ** Themes
  264. Bring Emacs' out of the eighties by cherry picking a few modules from =Doom=.
  265. https://github.com/hlissner/emacs-doom-themes
  266. + Modern colour themes
  267. #+begin_src emacs-lisp
  268. (use-package doom-themes
  269. :init (load-theme 'doom-moonlight t))
  270. #+end_src
  271. Load a theme with =SPC t=.
  272. #+begin_src emacs-lisp
  273. (dotfiles/leader
  274. "t" '(load-theme t nil :which-key "Theme"))
  275. #+end_src
  276. https://github.com/seagle0128/doom-modeline
  277. + Elegant status bar / modeline
  278. #+begin_src emacs-lisp
  279. (use-package doom-modeline
  280. :init (doom-modeline-mode 1)
  281. :custom ((doom-modeline-height 16)))
  282. #+end_src
  283. ** Writing
  284. *Organize your plain life in plain text*
  285. =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.
  286. + https://orgmode.org
  287. + https://orgmode.org/worg/org-contrib/babel/languages/index.html
  288. + https://orgmode.org/manual/Structure-Templates.html
  289. #+begin_src emacs-lisp
  290. (use-package org
  291. :hook
  292. (org-mode . (lambda ()
  293. (org-indent-mode)
  294. (visual-line-mode 1)
  295. (variable-pitch-mode 1)))
  296. :config
  297. (setq org-ellipsis " ▾"
  298. org-log-done 'time
  299. org-log-into-drawer t
  300. org-src-preserve-indentation t)
  301. (org-babel-do-load-languages
  302. 'org-babel-load-languages
  303. '((shell . t)
  304. (python . t)
  305. (emacs-lisp . t)))
  306. (require 'org-tempo)
  307. (add-to-list 'org-structure-template-alist '("s" . "src"))
  308. (add-to-list 'org-structure-template-alist '("q" . "quote"))
  309. (add-to-list 'org-structure-template-alist '("e" . "example"))
  310. (add-to-list 'org-structure-template-alist '("sh" . "src shell"))
  311. (add-to-list 'org-structure-template-alist '("py" . "src python"))
  312. (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")))
  313. #+end_src
  314. https://github.com/integral-dw/org-superstar-mode
  315. + Make the headline stars more *super*
  316. #+begin_src emacs-lisp
  317. (use-package org-superstar
  318. :hook (org-mode . org-superstar-mode))
  319. #+end_src
  320. * Development
  321. :PROPERTIES:
  322. :header-args: :tangle init.el :results silent
  323. :END:
  324. An IDE like experience (or better) can be achieved in Emacs using two *Microsoft* open source initiatives.
  325. + https://microsoft.github.io/language-server-protocol/
  326. + https://microsoft.github.io/debug-adapter-protocol/
  327. https://emacs-lsp.github.io/lsp-mode/
  328. + Language servers for Emacs
  329. #+begin_src emacs-lisp
  330. (use-package lsp-mode
  331. :commands lsp)
  332. #+end_src
  333. https://emacs-lsp.github.io/lsp-ui/
  334. + UI improvements for =lsp-mode=
  335. #+begin_src emacs-lisp
  336. (use-package lsp-ui
  337. :commands lsp-ui-mode
  338. :custom (lsp-ui-doc-position 'bottom))
  339. #+end_src
  340. https://emacs-lsp.github.io/dap-mode/
  341. + Debug adapters for Emacs
  342. #+begin_src emacs-lisp
  343. (use-package dap-mode)
  344. #+end_src
  345. Text completion framework via =company= aka *Complete Anything*.
  346. http://company-mode.github.io/
  347. + Integrate with =lsp-mode=
  348. #+begin_src emacs-lisp
  349. (use-package company-lsp
  350. :commands company-lsp)
  351. #+end_src
  352. ** Python
  353. Full *IDE* experience for Python within Emacs.
  354. + Completion, jumps via =lsp-mode=
  355. + Debugging via =dap-mode=
  356. Install the =pyls= language server.
  357. #+begin_src shell :tangle no
  358. pip install --user "python-language-server[all]"
  359. #+end_src
  360. https://www.emacswiki.org/emacs/PythonProgrammingInEmacs
  361. + Built in mode
  362. #+begin_src emacs-lisp
  363. (use-package python-mode
  364. :hook (python-mode . lsp)
  365. :config (require 'dap-python)
  366. :custom (python-shell-interpreter "python3") ;; Required if "python" is not python 3.
  367. (dap-python-executable "python3") ;; Same as above.
  368. (dap-python-debugger 'debugpy))
  369. #+end_src