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.

1580 lines
47 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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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. #+SUBTITLE: I showed you my source code, pls respond
  3. #+AUTHOR: Christopher James Hayward
  4. #+EMAIL: chris@chrishayward.xyz
  5. #+ROAM_KEY: https://github.com/chayward1/dotfiles/
  6. #+ATTR_ORG: :width 420px
  7. #+ATTR_HTML: :width 420px
  8. #+ATTR_LATEX: :width 420px
  9. [[./docs/images/desktop-alt.png]]
  10. Immutable GNU Emacs dotfiles. Built for Life, Liberty, and the Open Road.
  11. + 100% Literate
  12. + 100% Immutable
  13. + 100% Reproducible
  14. Heavily inspired by [[https://github.com/hlissner/doom-emacs][Doom Emacs]] and [[https://youtube.com/c/SystemCrafters][System Crafters]].
  15. * Init
  16. :PROPERTIES:
  17. :header-args: :tangle init.el
  18. :END:
  19. Although later versions of Emacs introduce =early-init.el=, it's not used in this configuration for two reasons:
  20. + It's not required due to the modularity
  21. + Maintaining support for older versions
  22. Assuming you have completed all of the following tasks prior to proceeding further:
  23. 1. Imported the =secrets=
  24. 2. Initialized the =passwords=
  25. 3. Defined the =host= file
  26. 4. Created all required symbolic links
  27. Launch emacs: ~emacs -mm --debug-init~
  28. ** Options
  29. Here's a complete list of all of the options configurable for each host, and their default values. If a host configuration does not exist, the default values will remain.
  30. 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.
  31. #+begin_src emacs-lisp
  32. (defvar dotfiles/font
  33. "Fira Code"
  34. "Unified system font family, used on all font faces.")
  35. #+end_src
  36. #+begin_src emacs-lisp
  37. (defvar dotfiles/font-size
  38. 96
  39. "Unified font size, of which all variations are relative to.")
  40. #+end_src
  41. Used by the desktop module to find the appropriate browser.
  42. #+begin_src emacs-lisp
  43. (defvar dotfiles/browser
  44. (getenv "BROWSER")
  45. "The default browser used by the system.")
  46. #+end_src
  47. Used by the writing module to determine the system language.
  48. #+begin_src emacs-lisp
  49. (defvar dotfiles/language
  50. (getenv "LANG")
  51. "The default system language.")
  52. #+end_src
  53. All of the available modules defined in the ~dotfiles/modules-available~ constant.
  54. #+begin_src emacs-lisp
  55. (defconst dotfiles/modules-available
  56. '(core editor desktop writing projects interface)
  57. "All of the available modules for hosts to load.")
  58. #+end_src
  59. Add the modules you want to initialize to the ~dotfiles/modules~ variable.
  60. #+begin_src emacs-lisp
  61. (defvar dotfiles/modules
  62. dotfiles/modules-available
  63. "Enabled modules, modify this in your host configuration.")
  64. #+end_src
  65. Specify the emacs home, and the cache directory.
  66. #+begin_src emacs-lisp
  67. (defvar dotfiles/home
  68. user-emacs-directory
  69. "Original value of `user-emacs-directory'.")
  70. #+end_src
  71. Used to seperate the immutable configuration from the stateful package files.
  72. #+begin_src emacs-lisp
  73. (defvar dotfiles/cache
  74. (expand-file-name "~/.cache/emacs")
  75. "Where `user-emacs-directory' redirects to.")
  76. #+end_src
  77. Functionality like =completion= and =hints= delayed to avoid popups for common manuevers.
  78. #+begin_src emacs-lisp
  79. (defvar dotfiles/idle
  80. 0.0
  81. "Length of time to wait before offering completions.")
  82. #+end_src
  83. Required for the all powerful leader key.
  84. #+begin_src emacs-lisp
  85. (defvar dotfiles/leader-key
  86. "SPC"
  87. "Custom leader key for custom actions.")
  88. #+end_src
  89. The desktop module requires the global leader key set.
  90. #+begin_src emacs-lisp
  91. (defvar dotfiles/leader-key-global
  92. (concat "C-" dotfiles/leader-key)
  93. "Global leader key available everywhere.")
  94. #+end_src
  95. Define where the source repositories exist on disk, for integration with the projects module.
  96. #+begin_src emacs-lisp
  97. (defvar dotfiles/projects
  98. (expand-file-name "~/.local/source/")
  99. "Location where source code projects exist on disk.")
  100. #+end_src
  101. Where the password store exists on disk.
  102. #+begin_src emacs-lisp
  103. (defvar dotfiles/passwords
  104. (expand-file-name "~/.password-store/")
  105. "Directory containing the password store.")
  106. #+end_src
  107. Configure the public GPG key that Emacs will encrypt files to.
  108. #+begin_src emacs-lisp
  109. (defvar dotfiles/public-key
  110. "37AB1CB72B741E478CA026D43025DCBD46F81C0F"
  111. "Public PGP key that Emacs will encrypt files to.")
  112. #+end_src
  113. ** Startup
  114. The host configuration loads (if it exist) using the systems name.
  115. #+begin_src emacs-lisp
  116. ;; Load the host configuration.
  117. (let ((host-file (concat dotfiles/home "/hosts/" system-name ".el")))
  118. (when (file-exists-p host-file)
  119. (load-file host-file)))
  120. #+end_src
  121. Load all of the enabled modules:
  122. #+begin_src emacs-lisp
  123. ;; Load the enabled modules.
  124. (dolist (m dotfiles/modules)
  125. (let ((mod-file (concat dotfiles/home "/modules/" (symbol-name m) ".el")))
  126. (when (file-exists-p mod-file)
  127. (load-file mod-file))))
  128. #+end_src
  129. * Hosts
  130. Each host system that runs Emacs has a file defined in the =hosts/= sub directory, following the pattern of ~$HOSTNAME.el~. All of the configurations definitions are in this file. Modules will read these values during initialization.
  131. ** Virtualbox
  132. :PROPERTIES:
  133. :header-args: :tangle hosts/virtualbox.el
  134. :END:
  135. The first configuration, built using the Ubuntu 20.04 LTS server edition.
  136. + Set the browser manually
  137. + Set the language to Canadian english
  138. #+begin_src emacs-lisp
  139. (setq dotfiles/browser "firefox"
  140. dotfiles/language "en_CA")
  141. #+end_src
  142. ** Acernitro
  143. :PROPERTIES:
  144. :header-args: :tangle hosts/acernitro.el
  145. :END:
  146. The first machine with real hardware to deploy this configuration to. It's an Acer Nitro AN-515 with the NVIDIA / Intel hybrid graphics card. Due to the issues I encountered with this hardware setup, I again opted to install Ubuntu 20.04, and stripped away the components I don't need.
  147. + Set the browser manually
  148. + Set the language to Canadian english
  149. + Increase font size for high DPI screen
  150. Configure the browser.
  151. #+begin_src emacs-lisp
  152. (setq dotfiles/browser "firefox"
  153. dotfiles/language "en_CA"
  154. dotfiles/font-size 132)
  155. #+end_src
  156. ** Raspberry
  157. :PROPERTIES:
  158. :header-args: :tangle hosts/raspberry.el
  159. :END:
  160. Raspberry Pi 400 personal computer, and a small fleet of Zero, Zero WH, 4, and 4Bs.
  161. + Set the browser manually
  162. + Set the language to Canadian english
  163. + Increase font size for small screens
  164. #+begin_src emacs-lisp
  165. (setq dotfiles/browser "chromium-browser"
  166. dotfiles/language "en_CA"
  167. dotfiles/font-size 132)
  168. #+end_src
  169. ** Termux
  170. :PROPERTIES:
  171. :header-args: :tangle hosts/localhost.el
  172. :END:
  173. Android devices do not use the Linux host names, so setting a custom hostname is pointless as it just changes the value of ~kernel.hostname~ and have no impact on the running system. It's recommended to leave the hostname as =localhost= in Termux. While this raises an issue with my host definition system, it's no more of an issue than the =rasberry= namespace.
  174. + Increase font size for small screen
  175. #+begin_src emacs-lisp
  176. (setq dotfiles/font-size 132)
  177. #+end_src
  178. * Modules
  179. Breaking down the project into logical units or chapters to keep the code more maintainable and organized. This is also a fundemental requirement to achieve the goal of modularity. Incorporating just the =core= module on a build server to build literate programming projects is just one example.
  180. ** Core
  181. :PROPERTIES:
  182. :header-args: :tangle modules/core.el :results silent
  183. :END:
  184. Minimal configuration to make Emacs usable for my own personal workflow. This does little in the ways of improving the visuals, only removing what's included by default and not required. Read more about my technique in my post [[file:docs/posts/immutable-emacs.org.gpg][Immutable Emacs]].
  185. *** Startup
  186. 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. How can we solve this issue? Shortly after initialization, before most packages load, we change the value to ~dotfiles/cache~. I elaborate more on the technique in my post [[https://chrishayward.xyz/posts/immutable-emacs/][Immutable Emacs]].
  187. #+begin_src emacs-lisp
  188. (setq user-emacs-directory dotfiles/cache)
  189. #+end_src
  190. Because this project uses version-control, we can disable more unwanted features:
  191. + Lock files
  192. + Backup files
  193. #+begin_src emacs-lisp
  194. (setq create-lockfiles nil
  195. make-backup-files nil)
  196. #+end_src
  197. *** Packages
  198. Download and install packages using [[https://github.com/raxod502/straight.el][straight.el]], a functional package manager that integrates with =use-package=, giving us more control over sourcing our packages.
  199. + Use the development branch
  200. + Integrate with ~use-package~
  201. Apply the configurations prior to bootstrapping the package manager, by setting (writing) to the variables that =straight= will ultimately read from.
  202. #+begin_src emacs-lisp
  203. (setq straight-repository-branch "develop"
  204. straight-use-package-by-default t)
  205. #+end_src
  206. Bootstrap the package manager, downloading, installing, or configuring depending on the state of the configuration. All packages build from source, pinned to specific git commit hashes.
  207. #+begin_src emacs-lisp
  208. (defvar bootstrap-version)
  209. (let ((bootstrap-file
  210. (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
  211. (bootstrap-version 5))
  212. (unless (file-exists-p bootstrap-file)
  213. (with-current-buffer
  214. (url-retrieve-synchronously
  215. "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
  216. 'silent 'inhibit-cookies)
  217. (goto-char (point-max))
  218. (eval-print-last-sexp)))
  219. (load bootstrap-file nil 'nomessage))
  220. #+end_src
  221. Complete the integration with ~use-package~ by installing it with =straight=.
  222. #+begin_src emacs-lisp
  223. (straight-use-package 'use-package)
  224. #+end_src
  225. *** Cleanup
  226. Despite having our *stateful* and *immutable* configurations seperate, it's good practice to make efforts to reduce the trash created by Emacs. Install [[https://github.com/emacscollective/no-littering][no-littering]] to reduce the files created by Emacs.
  227. #+begin_src emacs-lisp
  228. (use-package no-littering)
  229. #+end_src
  230. Emacs' default user interface is *horrendous*, let's do something about that.
  231. #+begin_src emacs-lisp
  232. (setq inhibit-startup-message t
  233. initial-scratch-message "")
  234. (global-prettify-symbols-mode)
  235. (when (window-system)
  236. (tooltip-mode -1)
  237. (tool-bar-mode -1)
  238. (menu-bar-mode -1)
  239. (when (fboundp 'scroll-bar-mode)
  240. (scroll-bar-mode -1)))
  241. #+end_src
  242. Emacs has a long history of running on machines without gigabytes of available memory, let it realize its full potential! Just kidding, it just smashes *CPU0*.
  243. #+begin_src emacs-lisp
  244. (setq gc-cons-treshold most-positive-fixnum
  245. gnutls-min-prime-bits 4096)
  246. #+end_src
  247. *** Babel
  248. *Organize your plain life in plain text*
  249. [[https://orgmode.org][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.
  250. + [[https://orgmode.org/worg/org-contrib/babel/languages/index.html][Babel languages]]
  251. + [[https://orgmode.org/manual/Structure-Templates.html][Structure templates]]
  252. #+begin_src emacs-lisp
  253. (use-package org
  254. :hook (org-mode . (lambda ()
  255. (org-indent-mode)
  256. (visual-line-mode 1)
  257. (variable-pitch-mode 1)))
  258. :custom (org-ellipsis " ▾")
  259. (org-log-done 'time)
  260. (org-log-into-drawer t)
  261. (org-image-actual-width nil)
  262. (org-directory dotfiles/home)
  263. (org-src-preserve-indentation t)
  264. (org-todo-keywords '((sequence "TODO" "START" "WAIT" "DONE")))
  265. :config (require 'org-tempo)
  266. (add-to-list 'org-structure-template-alist '("s" . "src"))
  267. (add-to-list 'org-structure-template-alist '("q" . "quote"))
  268. (add-to-list 'org-structure-template-alist '("e" . "example"))
  269. (add-to-list 'org-structure-template-alist '("sh" . "src shell"))
  270. (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp"))
  271. (org-babel-do-load-languages 'org-babel-load-languages '((shell . t)
  272. (emacs-lisp . t))))
  273. #+end_src
  274. Build all of the =org= files within a given directory.
  275. #+begin_src emacs-lisp
  276. (defun dotfiles/tangle (dir)
  277. "Recursively tangle the Org files within a directory."
  278. (let ((org-files (directory-files-recursively dir "org")))
  279. (dolist (f org-files)
  280. (org-babel-tangle-file f))))
  281. #+end_src
  282. ** Editor
  283. :PROPERTIES:
  284. :header-args: :tangle modules/editor.el :results silent
  285. :END:
  286. This section contains configuration for improving the editor experience within Emacs.
  287. *** Keys
  288. Make the =ESC= key quit (most) prompts, instead of the default =C-g=.
  289. #+begin_src emacs-lisp
  290. (global-set-key (kbd "<escape>") 'keyboard-escape-quit)
  291. #+end_src
  292. Download [[https://github.com/justbur/emacs-which-key][which-key]], a package that displays the current incomplete keybinding input in a mini-buffer, showing available completion options.
  293. #+begin_src emacs-lisp
  294. (use-package which-key
  295. :diminish which-key-mode
  296. :custom (which-key-idle-delay dotfiles/idle)
  297. :config (which-key-mode))
  298. #+end_src
  299. Turn Emacs into Vim with [[https://evil.readthedocs.io/en/latest/index.html][evil-mode]], the extensible VI layer for Emacs.
  300. #+begin_src emacs-lisp
  301. (use-package evil
  302. :custom (evil-want-integration t) ;; Required for `evil-collection'.
  303. (evil-want-keybinding nil) ;; Same as above
  304. :config (evil-mode 1))
  305. #+end_src
  306. Unfortunately the default keybindings are *lacking*, but there is a community curated package [[https://github.com/emacs-evil/evil-collection][evil-collection]], which does a much better job implementing keybindings you would expect to find.
  307. #+begin_src emacs-lisp
  308. (use-package evil-collection
  309. :after evil
  310. :config (evil-collection-init))
  311. #+end_src
  312. Surround text with functions, quotations, and any other symbols using the [[https://github.com/emacs-evil/evil-surround][evil-surround]] package.
  313. #+begin_src emacs-lisp
  314. (use-package evil-surround
  315. :after evil
  316. :config (global-evil-surround-mode 1))
  317. #+end_src
  318. Toggle block comments using [[https://github.com/redguardtoo/evil-nerd-commenter][evil-nerd-commentor]] and =M-;=.
  319. #+begin_src emacs-lisp
  320. (use-package evil-nerd-commenter
  321. :after evil
  322. :bind ("M-;" . evilnc-comment-or-uncomment-lines))
  323. #+end_src
  324. Implement the *leader* key using [[https://github.com/noctuid/general.el][general.el]], letting us easily configure prefixed keybindings in a much cleaner manner than the default methods.
  325. #+begin_src emacs-lisp
  326. (use-package general
  327. :after evil
  328. :config
  329. (general-create-definer dotfiles/leader
  330. :states '(normal motion)
  331. :keymaps 'override
  332. :prefix dotfiles/leader-key
  333. :global-prefix dotfiles/leader-key-global))
  334. #+end_src
  335. Use [[https://github.com/abo-abo/hydra][hydra]] for transient keybindings sharing a common prefix.
  336. #+begin_src emacs-lisp
  337. (use-package hydra
  338. :defer t)
  339. #+end_src
  340. *** Help
  341. Use the built-in ~describe-*~ functionality of Emacs to quickly access documentation for packages, variables, and functions. Run helper functions with =SPC h=.
  342. + Packages =p=
  343. + Variables =v=
  344. + Functions =f=
  345. #+begin_src emacs-lisp
  346. (dotfiles/leader
  347. "h" '(:ignore t :which-key "Help")
  348. "hp" '(describe-package :which-key "Package")
  349. "hv" '(describe-variable :which-key "Variable")
  350. "hf" '(describe-function :which-key "Function"))
  351. #+end_src
  352. *** Files
  353. For file navigation I use =dired=, included with Emacs by default. Dired feels more modern with prioritized icon fonts using [[https://github.com/domtronn/all-the-icons.el][all-the-icons]]. This makes navigation and visually parsing directories much faster, given that file types are quickly identified by their corresponding icons.
  354. #+begin_src emacs-lisp
  355. (use-package all-the-icons)
  356. #+end_src
  357. Integration with =dired= comes from the [[https://github.com/jtbm37/all-the-icons-dired][all-the-icons-dired]] package.
  358. #+begin_src emacs-lisp
  359. (use-package all-the-icons-dired
  360. :hook (dired-mode . all-the-icons-dired-mode))
  361. #+end_src
  362. When opening =dired=, I don't want to have to press =RET= twice to navigate to the current directory. Avoid this with ~dired-jump~, included in the =dired-x= package shipped with =dired= and Emacs.
  363. #+begin_src emacs-lisp
  364. (require 'dired-x)
  365. #+end_src
  366. By default =dired= will create a new buffer everytime you press =RET= over a directory. This leads to unwanted =dired= buffers needing closure. Avoid this behaviour with [[https://github.com/crocket/dired-single][dired-single]], reusing the same dired buffer.
  367. + Move up a directory with =h=
  368. + Open a single buffer with =l=
  369. #+begin_src emacs-lisp
  370. (use-package dired-single
  371. :config (evil-collection-define-key 'normal 'dired-mode-map
  372. "h" 'dired-single-up-directory
  373. "l" 'dired-single-buffer))
  374. #+end_src
  375. Open a dired buffer with =SPC d=.
  376. #+begin_src emacs-lisp
  377. (dotfiles/leader
  378. "d" '(dired-jump :which-key "Dired"))
  379. #+end_src
  380. *** Shell
  381. While not a traditional terminal emulator, =eshell= provides me with all of the functionality I expect and require from one. Some users may be wanting more, I would recommend they look into =vterm= included in the destkop module. Configure the infamous lambda prompt using [[https://github.com/zwild/eshell-prompt-extras][eshell-prompt-extras]] package.
  382. #+begin_src emacs-lisp
  383. (use-package eshell-prompt-extras
  384. :custom (eshell-highlight-prompt nil)
  385. (eshell-prompt-function 'epe-theme-lambda))
  386. #+end_src
  387. Open an =eshell= buffer with =SPC e=.
  388. #+begin_src emacs-lisp
  389. (dotfiles/leader
  390. "e" '(eshell :which-key "Shell"))
  391. #+end_src
  392. *** Source
  393. #+ATTR_ORG: :width 420px
  394. #+ATTR_HTML: :width 420px
  395. #+ATTR_LATEX: :width 420px
  396. [[./docs/images/2021-02-13-example-magit.gif]]
  397. Another hallmark feature is [[https://github.com/magit/magit][Magit]], a complete git porcelain within Emacs.
  398. #+begin_src emacs-lisp
  399. (use-package magit
  400. :commands magit-status
  401. :custom (magit-display-buffer-function
  402. #'magit-display-buffer-same-window-except-diff-v1))
  403. #+end_src
  404. Work directly with github issues / pull requests using [[https://github.com/magit/forge][Forge]].
  405. + Requires a valid ~$GITHUB_TOKEN~
  406. #+begin_src emacs-lisp
  407. (use-package forge
  408. :after magit)
  409. #+end_src
  410. Open the *status* page for the current repository with =SPC g=.
  411. #+begin_src emacs-lisp
  412. (dotfiles/leader
  413. "g" '(magit-status :which-key "Magit"))
  414. #+end_src
  415. *** Windows
  416. Window management with =SPC w=.
  417. + Swap with =w=
  418. + Close with =c=
  419. + Motions with =h,j,k,l=
  420. + Split with =s + <MOTION>=
  421. #+begin_src emacs-lisp
  422. (dotfiles/leader
  423. "w" '(:ignore t :which-key "Window")
  424. "ww" '(window-swap-states :which-key "Swap")
  425. "wc" '(delete-window :which-key "Close")
  426. "wh" '(windmove-left :which-key "Left")
  427. "wj" '(windmove-down :which-key "Down")
  428. "wk" '(windmove-up :which-key "Up")
  429. "wl" '(windmove-right :which-key "Right")
  430. "ws" '(:ignore t :which-key "Split")
  431. "wsj" '(split-window-below :which-key "Down")
  432. "wsl" '(split-window-right :which-key "Right"))
  433. #+end_src
  434. *** Shortcuts
  435. Implement shortcut bindings, cherry picked from Doom emacs.
  436. + Close buffers with =SPC c=
  437. + Find files with =SPC . (period)=
  438. #+begin_src emacs-lisp
  439. (dotfiles/leader
  440. "." '(find-file :which-key "Files")
  441. "c" '(kill-buffer-and-window :which-key "Close"))
  442. #+end_src
  443. Quit emacs with =SPC q=.
  444. + Saving =q=
  445. + Without =w=
  446. + Frame (daemon) =f=
  447. #+begin_src emacs-lisp
  448. (dotfiles/leader
  449. "q" '(:ignore t :which-key "Quit")
  450. "qq" '(save-buffers-kill-emacs :which-key "Save")
  451. "qw" '(kill-emacs :which-key "Now")
  452. "qf" '(delete-frame :which-key "Frame"))
  453. #+end_src
  454. Place runtime tweaks behind =SPC t=.
  455. #+begin_src emacs-lisp
  456. (dotfiles/leader
  457. "t" '(:ignore t :which-key "Tweaks"))
  458. #+end_src
  459. ** Desktop
  460. :PROPERTIES:
  461. :header-args: :tangle modules/desktop.el :results silent
  462. :END:
  463. I use Emacs as a Desktop Environment with the [[https://github.com/ch11ng/exwm][exwm]] package. It allows Emacs to function as a complete tiling window manager for =X11=. My workflow includes launching the window manager with =xinitrc=, without the use of a display manager, controlling *everything* within Emacs.
  464. #+begin_src conf :tangle config/xinitrc
  465. exec dbus-launch --exit-with-session emacs -mm --debug-init
  466. #+end_src
  467. *** Email
  468. #+ATTR_ORG: :width 420px
  469. #+ATTR_HTML: :width 420px
  470. #+ATTR_LATEX: :width 420px
  471. [[./docs/images/2021-02-13-example-mu4e.gif]]
  472. Plain text email delivered via mu, mu4e and mbsync. I run my own email server, so your configuration may differ from mine. This is the ~mbsyncrc~ file I use to synchronize my local mail with my server.
  473. #+begin_src conf :tangle config/mbsyncrc
  474. IMAPStore xyz-remote
  475. Host mail.chrishayward.xyz
  476. User chris@chrishayward.xyz
  477. PassCmd "pass chrishayward.xyz/chris"
  478. SSLType IMAPS
  479. MaildirStore xyz-local
  480. Path ~/.cache/mail/
  481. Inbox ~/.cache/mail/inbox
  482. SubFolders Verbatim
  483. Channel xyz
  484. Master :xyz-remote:
  485. Slave :xyz-local:
  486. Patterns * !Archives
  487. Create Both
  488. Expunge Both
  489. SyncState *
  490. #+end_src
  491. The system typically expects to find this file at ~$HOME/.mbsyncrc~, but you may also specify a custom path if launching the command using arguments. I chose to symlink the default location to my repository.
  492. #+begin_src shell :tangle no
  493. mbsync -a
  494. mu index --maildir="~/.cache/mail"
  495. #+end_src
  496. Once the mail's synchronized, and has indexed with =mu=, it's time to install the required packages for Emacs.
  497. + Update every 5 minutes
  498. + Scale text for all devices
  499. + Sign outbound mail with GPG key
  500. + Configure mail account(s)
  501. #+begin_src emacs-lisp
  502. (use-package mu4e
  503. :load-path "/usr/share/emacs/site-lisp/mu4e"
  504. :custom (mu4e-maildir "~/.cache/mail")
  505. (mu4e-update-interval (* 5 60))
  506. (mu4e-get-mail-command "mbsync -a")
  507. (mu4e-compose-format-flowed t)
  508. (mu4e-change-filenames-when-moving t)
  509. (message-send-mail-function 'smtpmail-send-it)
  510. (mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  511. (mu4e-compose-signature (concat "Chris Hayward\n"
  512. "https://chrishayward.xyz\n"))
  513. :config
  514. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  515. (setq mu4e-contexts
  516. (list
  517. ;; Main
  518. ;; chris@chrishayward.xyz
  519. (make-mu4e-context
  520. :name "Main"
  521. :match-func
  522. (lambda (msg)
  523. (when msg
  524. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  525. :vars
  526. '((user-full-name . "Christopher James Hayward")
  527. (user-mail-address . "chris@chrishayward.xyz")
  528. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  529. (smtpmail-smtp-service . 587)
  530. (smtpmail-stream-type . starttls))))))
  531. #+end_src
  532. Use [[https://github.com/iqbalansari/mu4e-alert][mu4e-alert]] to give us desktop notifications about incoming mail.
  533. #+begin_src emacs-lisp
  534. (use-package mu4e-alert
  535. :after mu4e
  536. :custom (mu4e-alert-set-default-style 'libnotify)
  537. :config (mu4e-alert-enable-notifications)
  538. (mu4e-alert-enable-mode-line-display))
  539. #+end_src
  540. Create a keybinding to open the mail dashboard with =SPC m=.
  541. #+begin_src emacs-lisp
  542. (dotfiles/leader
  543. "m" '(mu4e :which-key "Mail"))
  544. #+end_src
  545. *** Browser
  546. Write out the ~$BROWSER~ environment variable.
  547. #+begin_src emacs-lisp
  548. (setenv "BROWSER" dotfiles/browser)
  549. #+end_src
  550. *** Startup
  551. :PROPERTIES:
  552. :header-args: :tangle config/profile
  553. :END:
  554. Ensure that ~/.local/bin~ is added to the path.
  555. #+begin_src sh
  556. PATH=$PATH:~/.local/bin
  557. export PATH
  558. #+end_src
  559. When launching into a session, if the display server is not running then =startx= executes to run the window manager.
  560. #+begin_src sh
  561. if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
  562. exec startx
  563. fi
  564. #+end_src
  565. *** Methods
  566. Define a method to run an external process, allowing us to launch any application on a new process without interferring with Emacs.
  567. #+begin_src emacs-lisp
  568. (defun dotfiles/run (command)
  569. "Run an external process."
  570. (interactive (list (read-shell-command "λ ")))
  571. (start-process-shell-command command nil command))
  572. #+end_src
  573. Apply methods to the current call process to avoid issues with hooks.
  574. #+begin_src emacs-lisp
  575. (defun dotfiles/run-in-background (command)
  576. (let ((command-parts (split-string command "[ ]+")))
  577. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  578. #+end_src
  579. Place keybindings for executing shell commands behind =SPC x=.
  580. + Run shell commands with =x=
  581. + Run async shell commands with =z=
  582. #+begin_src emacs-lisp
  583. (dotfiles/leader
  584. "x" '(:ignore t :which-key "Run")
  585. "xx" '(dotfiles/run :which-key "Run")
  586. "xz" '(async-shell-command :which-key "Async"))
  587. #+end_src
  588. *** Displays
  589. When the window manager first launches the ~init-hook~ executes, allowing us to define some custom logic.
  590. + Display time and date
  591. + Display battery info (if available)
  592. In my personal configuration, I do not want the battery or time displayed within Emacs when it's not running as desktop environment because that information is typically already available.
  593. #+begin_src emacs-lisp
  594. (defun dotfiles/init-hook ()
  595. (exwm-workspace-switch-create 1)
  596. (setq display-time-and-date t)
  597. (display-battery-mode 1)
  598. (display-time-mode 1))
  599. #+end_src
  600. Using =autorandr= with pre configured profiles, switching screens (AKA hot plugging) is also handled through a hook.
  601. #+begin_src emacs-lisp
  602. (defun dotfiles/update-display ()
  603. "Update the displays by forcing a change through autorandr."
  604. (dotfiles/run-in-background "autorandr --change --force"))
  605. #+end_src
  606. *** Configuration
  607. Connect our custom hooks and configure the input keys, a custom layer for key capture layers.
  608. + Enable =randr= support
  609. + Pass through to Emacs
  610. + =M-x= to Emacs
  611. + =C-g= to Emacs
  612. + =C-SPC= to Emacs
  613. + Bindings with =S= (Super / Win)
  614. + Reset =S-r=
  615. + Launch =S-&=
  616. + Workspace =S-[1..9]=
  617. #+begin_src emacs-lisp
  618. (use-package exwm
  619. :custom (exwm-workspace-show-all-buffers t)
  620. (exwm-input-prefix-keys
  621. '(?\M-x
  622. ?\C-c
  623. ?\C-g
  624. ?\C-\ ))
  625. (exwm-input-global-keys
  626. `(([?\s-r] . exwm-reset)
  627. ,@(mapcar (lambda (i)
  628. `(,(kbd (format "s-%d" i)) .
  629. (lambda ()
  630. (interactive)
  631. (exwm-workspace-switch-create ,i))))
  632. (number-sequence 1 9))))
  633. :config (require 'exwm-randr)
  634. (exwm-randr-enable)
  635. (add-hook 'exwm-init-hook #'dotfiles/init-hook)
  636. (add-hook 'exwm-randr-screen-change-hook #'dotfiles/update-display)
  637. (dotfiles/update-display)
  638. (exwm-enable))
  639. #+end_src
  640. ** Writing
  641. :PROPERTIES:
  642. :header-args: :tangle modules/writing.el :results silent
  643. :END:
  644. I am using [[https://orgmode.org][org-mode]] extensively for writing projects for different purposes. Most of the improvements are done in the *Core* module for the Literate programming configuration. Encrypt files using symmetric key encryption via PGP. This enables my workflow of storing my personal notes anywhere. Emacs can cache the gpg password if you trust your session.
  645. #+begin_src emacs-lisp
  646. (setq epa-file-select-keys 2
  647. epa-file-cache-passphrase-for-symmetric-encryption t
  648. epa-file-encrypt-to dotfiles/public-key)
  649. #+end_src
  650. Download and install [[https://github.com/integral-dw/org-superstar-mode][org-superstar-mode]] for making headline stars more *super*.
  651. #+begin_src emacs-lisp
  652. (use-package org-superstar
  653. :after org
  654. :hook (org-mode . org-superstar-mode))
  655. #+end_src
  656. *** Roam
  657. #+ATTR_ORG: :width 420px
  658. #+ATTR_HTML: :width 420px
  659. #+ATTR_LATEX: :width 420px
  660. [[./docs/images/2021-02-13-example-roam.png]]
  661. Download and install [[https://orgroam.com][org-roam]], a plain text knowledge management system for Emacs.
  662. #+begin_src emacs-lisp
  663. (use-package org-roam
  664. :hook (after-init . org-roam-mode)
  665. :custom (org-roam-directory org-directory)
  666. (org-roam-encrypt-files t)
  667. (org-roam-capture-templates '())
  668. (org-roam-dailies-capture-templates
  669. '(("d" "Default" entry (function org-roam-capture--get-point)
  670. "* %?"
  671. :file-name "docs/daily/%<%Y-%m-%d>"
  672. :head
  673. "
  674. ,#+TITLE: %<%Y-%m-%d>
  675. ,#+AUTHOR: Christopher James Hayward
  676. "))))
  677. #+end_src
  678. Place keybindings behind =SPC r=.
  679. + Find with =f=
  680. + Toggle buffer with =b=
  681. + Dailies with =d=
  682. + Arbitrary date with =d=
  683. + Today with =t=
  684. + Tomorrow with =m=
  685. + Yesterday with =y=
  686. #+begin_src emacs-lisp
  687. (dotfiles/leader
  688. "r" '(:ignore t :which-key "Roam")
  689. "rf" '(org-roam-find-file :which-key "Find")
  690. "rb" '(org-roam-buffer-toggle-display :which-key "Buffer")
  691. "rd" '(:ignore t :which-key "Dailies")
  692. "rdd" '(org-roam-dailies-find-date :which-key "Date")
  693. "rdt" '(org-roam-dailies-find-today :which-key "Today")
  694. "rdm" '(org-roam-dailies-find-tomorrow :which-key "Tomorrow")
  695. "rdy" '(org-roam-dailies-find-yesterday :which-key "Yesterday"))
  696. #+end_src
  697. Visualize the org-roam database with the server, available when the editor is running at http://localhost:8080
  698. #+begin_src emacs-lisp
  699. (use-package org-roam-server
  700. :hook (org-roam-mode . org-roam-server-mode))
  701. #+end_src
  702. *** Hugo
  703. I use [[https://gohugo.io][Hugo]] for my personal [[https://chrishayward.xyz][website]], which I write in =org-mode= before compiling to =hugo-markdown=. [[https://github.com/kaushalmodi/ox-hugo][ox-hugo]], configured for =one-post-per-file= is my technique for managing my content.
  704. #+begin_src emacs-lisp
  705. (use-package ox-hugo
  706. :after ox)
  707. #+end_src
  708. *** Posts
  709. Add a capture template for creating new blog posts.
  710. #+begin_src emacs-lisp
  711. (with-eval-after-load 'org-roam
  712. (add-to-list 'org-roam-capture-templates
  713. '("p" "Post" plain (function org-roam-capture--get-point)
  714. "%?"
  715. :file-name "docs/posts/${slug}"
  716. :unnarrowed t
  717. :head
  718. "
  719. ,#+TITLE: ${title}
  720. ,#+AUTHOR: Christopher James Hayward
  721. ,#+DATE: %<%Y-%m-%d>
  722. ,#+EXPORT_FILE_NAME: ${slug}
  723. ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  724. ,#+HUGO_BASE_DIR: ../
  725. ,#+HUGO_AUTO_SET_LASTMOD: t
  726. ,#+HUGO_SECTION: posts
  727. ,#+HUGO_DRAFT: true
  728. ")))
  729. #+end_src
  730. *** Notes
  731. Add a capture template for creating blog posts and notes on other peoples content / published works.
  732. #+begin_src emacs-lisp
  733. (with-eval-after-load 'org-roam
  734. (add-to-list 'org-roam-capture-templates
  735. '("n" "Notes" plain (function org-roam-capture--get-point)
  736. "%?"
  737. :file-name "docs/notes/${slug}"
  738. :unnarrowed t
  739. :head
  740. "
  741. ,#+TITLE: ${title}
  742. ,#+AUTHOR: Christopher James Hayward
  743. ,#+EXPORT_FILE_NAME: ${slug}
  744. ,#+ROAM_KEY: https://chrishayward.xyz/notes/${slug}/
  745. ,#+HUGO_BASE_DIR: ../
  746. ,#+HUGO_AUTO_SET_LASTMOD: t
  747. ,#+HUGO_SECTION: notes
  748. ,#+HUGO_DRAFT: true
  749. ")))
  750. #+end_src
  751. *** Slides
  752. Produce high quality presentations that work anywhere with =HTML/JS= and the [[https://revealjs.com][reveal.js]] package. [[https://github.com/hexmode/ox-reveal][ox-reveal]], configured to use a =cdn= allows us to produce ones that are not dependent on a local version of =reveal.js=.
  753. #+begin_src emacs-lisp
  754. (use-package ox-reveal
  755. :after ox
  756. :custom (org-reveal-root "https://cdn.jsdelivr.net/npm/reveal.js"))
  757. #+end_src
  758. Create a capture template for creating slides quickly, with our desired configuration.
  759. #+begin_src emacs-lisp
  760. (with-eval-after-load 'org-roam
  761. (add-to-list 'org-roam-capture-templates
  762. '("s" "Slides" plain (function org-roam-capture--get-point)
  763. "%?"
  764. :file-name "docs/slides/${slug}"
  765. :unnarrowed t
  766. :head
  767. "
  768. ,#+TITLE: ${title}
  769. ,#+AUTHOR: Christopher James Hayward
  770. ,#+EXPORT_FILE_NAME: ${slug}
  771. ,#+OPTIONS: toc:nil num:nil reveal_title_slide:nil
  772. ,#+REVEAL_ROOT: https://cdn.jsdelivr.net/npm/reveal.js
  773. ,#+REVEAL_THEME: serif
  774. ")))
  775. #+end_src
  776. *** Agenda
  777. #+ATTR_ORG: :width 420px
  778. #+ATTR_HTML: :width 420px
  779. #+ATTR_LATEX: :width 420px
  780. [[./docs/images/2021-02-13-example-agenda.gif]]
  781. Override ~org-agenda-file-regexp~ to include =.org.gpg= files.
  782. #+begin_src emacs-lisp
  783. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  784. (setq org-agenda-file-regexp
  785. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  786. org-agenda-file-regexp)))
  787. #+end_src
  788. Create a capture template for courses.
  789. #+begin_src emacs-lisp
  790. (with-eval-after-load 'org-roam
  791. (add-to-list 'org-roam-capture-templates
  792. '("c" "Course" plain (function org-roam-capture--get-point)
  793. "%?"
  794. :file-name "docs/courses/${slug}"
  795. :unnarrowed t
  796. :head
  797. "
  798. ,#+TITLE: ${title}
  799. ,#+SUBTITLE:
  800. ,#+AUTHOR: Christopher James Hayward
  801. ")))
  802. #+end_src
  803. Configure agenda sources.
  804. #+begin_src emacs-lisp
  805. (setq org-agenda-files '("~/.emacs.d/docs/"
  806. "~/.emacs.d/docs/courses/"
  807. "~/.emacs.d/docs/daily/"))
  808. #+end_src
  809. Open an agenda buffer with =SPC a=.
  810. #+begin_src emacs-lisp
  811. (dotfiles/leader
  812. "a" '(org-agenda :which-key "Agenda"))
  813. #+end_src
  814. *** Images
  815. Capture screenshots with [[https://github.com/tecosaur/screenshot][screenshot.el]].
  816. #+begin_src emacs-lisp
  817. (use-package screenshot
  818. :commands (screenshot))
  819. #+end_src
  820. Create screencasts with =one-frame-per-action= GIF recording via [[https://github.com/takaxp/emacs-gif-screencast][emacs-gif-screencast]].
  821. + Pause / Resume
  822. + High Quality
  823. + Optimized
  824. It requires the installation of ~scrot~, ~gifsicle~, and ~convert~ from the =ImageMagick= library.
  825. #+begin_src emacs-lisp
  826. (use-package gif-screencast
  827. :commands (gif-screencast-start-or-stop gif-screencast-toggle-pause)
  828. :custom (gif-screencast-output-directory (concat dotfiles/home "docs/images/")))
  829. #+end_src
  830. Place keybindings behind =SPC s=.
  831. + Screenshot with =s=
  832. + Screencast with =c=
  833. #+begin_src emacs-lisp
  834. (dotfiles/leader
  835. "s" '(:ignore t :which-key "Screen")
  836. "ss" '(screenshot :which-key "Screenshot")
  837. "sc" '(gif-screencast-start-or-stop :which-key "Screencast"))
  838. #+end_src
  839. *** Grammar
  840. I use [[https://github.com/bnbeckwith/writegood-mode][writegood-mode]] to find common writing problems such as cliches and poor wording. Grammarly for the peons!
  841. #+begin_src emacs-lisp
  842. (use-package writegood-mode
  843. :after org
  844. :config (writegood-mode))
  845. #+end_src
  846. Toggle ~writegood~ mode with =SPC t w=.
  847. #+begin_src emacs-lisp
  848. (dotfiles/leader
  849. "tw" '(writegood-mode :which-key "Grammar"))
  850. #+end_src
  851. *** Spelling
  852. Use the built in =ispell= package to add spell checking features to buffers.
  853. #+begin_src emacs-lisp
  854. (use-package ispell
  855. :after org
  856. :custom (ispell-dictionary dotfiles/lang))
  857. #+end_src
  858. ** Projects
  859. :PROPERTIES:
  860. :header-args: :tangle modules/projects.el :results silent
  861. :END:
  862. An IDE like experience (or better) can be achieved in Emacs using two *Microsoft* open source initiatives.
  863. + [[https://microsoft.github.io/language-server-protocol/][Language Server Protocol]]
  864. + [[https://microsoft.github.io/debug-adapter-protocol/][Debug Adapter Protocol]]
  865. Add support for language servers with [[https://emacs-lsp.github.io/lsp-mode/][lsp-mode]].
  866. #+begin_src emacs-lisp
  867. (use-package lsp-mode
  868. :commands (lsp lsp-deferred)
  869. :custom (lsp-idle-delay (* 5 dotfiles/idle)))
  870. #+end_src
  871. [[https://emacs-lsp.github.io/lsp-ui/][lsp-ui]] provides UI improvements for =lsp-mode=.
  872. #+begin_src emacs-lisp
  873. (use-package lsp-ui
  874. :after lsp
  875. :custom (lsp-ui-doc-position 'at-point)
  876. (lsp-ui-doc-delay 0.500))
  877. #+end_src
  878. [[https://emacs-lsp.github.io/dap-mode/][Dap-mode]] adds support for the debug adapter protocol to Emacs.
  879. #+begin_src emacs-lisp
  880. (use-package dap-mode
  881. :commands (dap-debug))
  882. #+end_src
  883. *** Containers
  884. Use ~docker~ for running containers. Download and install https://github.com/Silex/docker.el, allowing us to manage containers within Emacs.
  885. #+begin_src emacs-lisp
  886. (use-package docker
  887. :commands (docker))
  888. #+end_src
  889. Open the management screen with =SPC k=.
  890. #+begin_src emacs-lisp
  891. (dotfiles/leader
  892. "k" '(docker :which-key "Docker"))
  893. #+end_src
  894. *** Management
  895. Configure [[https://projectile.mx][projectile]], a project interaction library for Emacs. It provides a nice set of features for operating on a project level without introducing external dependencies.
  896. #+begin_src emacs-lisp
  897. (use-package projectile
  898. :custom (projectile-project-search-path '("~/.local/source"))
  899. :config (projectile-mode))
  900. #+end_src
  901. *** Completion
  902. Text completion framework via =company= aka *Complete Anything*.
  903. http://company-mode.github.io/
  904. + Integrate with =lsp-mode=
  905. #+begin_src emacs-lisp
  906. (use-package company
  907. :after lsp)
  908. (use-package company-lsp
  909. :after (lsp company)
  910. :custom (company-backend 'company-lsp))
  911. #+end_src
  912. *** Passwords
  913. Pass makes managing passwords extremely easy, encrypring them in a file structure and providing easy commands for generating, modify, and copying passwords. =password-store.el= provides a wrapper for the functionality within Emacs.
  914. #+begin_src emacs-lisp
  915. (use-package password-store
  916. :custom (password-store-dir dotfiles/passwords))
  917. #+end_src
  918. Configure keybindings behind =SPC p=.
  919. + Copy with =p=
  920. + Rename with =r=
  921. + Generate with =g=
  922. #+begin_src emacs-lisp
  923. (dotfiles/leader
  924. "p" '(:ignore t :which-key "Passwords")
  925. "pp" '(password-store-copy :which-key "Copy")
  926. "pr" '(password-store-rename :which-key "Rename")
  927. "pg" '(password-store-generate :which-key "Generate"))
  928. #+end_src
  929. *** Languages
  930. Support for individual languages are implemented here.
  931. **** Go
  932. Install the =gopls= language server.
  933. #+begin_src sh :tangle no
  934. GO111MODULE=on go get golang.org/x/tools/gopls@latest
  935. #+end_src
  936. Set the ~GOPATH~ environment variable prior to loading, this allows us to change the default value of ~$HOME/go~ to ~$HOME/.go~.
  937. #+begin_src emacs-lisp
  938. (setenv "GOPATH" (concat (getenv "HOME") "/.go/"))
  939. #+end_src
  940. Additionally, include the =bin= subdirectory of the ~$GOPATH~ in the ~$PATH~ variable, adding compiled golang programs.
  941. #+begin_src emacs-lisp
  942. (setenv "PATH" (concat (getenv "GOPATH") "bin:" (getenv "PATH")))
  943. #+end_src
  944. Finally we can include the =go-mode= package, integrating it with =lsp=.
  945. #+begin_src emacs-lisp
  946. (use-package go-mode
  947. :hook (go-mode . lsp)
  948. :custom (lsp-go-gopls-server-path "~/.go/bin/gopls"))
  949. #+end_src
  950. Apply some custom behaviour before saving:
  951. + Format buffer
  952. + Organize imports
  953. #+begin_src emacs-lisp
  954. (defun dotfiles/go-hook ()
  955. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  956. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  957. #+end_src
  958. #+begin_src emacs-lisp
  959. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  960. #+end_src
  961. Add a golang source code block structure template with ~<go~:
  962. #+begin_src emacs-lisp
  963. (add-to-list 'org-structure-template-alist '("go" . "src go"))
  964. #+end_src
  965. **** HTTP
  966. Instead of the popular =restclient= package, I use [[https://github.com/zweifisch/ob-http][ob-http]] as a lightweight alternative.
  967. #+begin_src emacs-lisp
  968. (use-package ob-http
  969. :after org
  970. :config (org-babel-do-load-languages
  971. 'org-babel-load-languages
  972. '((http . t))))
  973. #+end_src
  974. **** C/C++
  975. #+ATTR_ORG: :width 420px
  976. #+ATTR_HTML: :width 420px
  977. #+ATTR_LATEX: :width 420px
  978. [[./docs/images/2021-02-13-example-ccls.gif]]
  979. Add support for C/C++ languages.
  980. + Configure the [[https://github.com/MaskRay/ccls][ccls]] language server
  981. + Load babel language modules for C/C++
  982. + Create a new structure templates for C/C++
  983. - ~<cc~ for C
  984. - ~<cpp~ for C++
  985. #+begin_src emacs-lisp
  986. (use-package ccls
  987. :hook ((c-mode c++-mode objc-mode cuda-mode) .
  988. (lambda ()
  989. (require 'ccls)
  990. (lsp-deferred)))
  991. :config (add-to-list 'org-structure-template-alist '("cc" . "src C"))
  992. (add-to-list 'org-structure-template-alist '("cpp" . "src C++"))
  993. (org-babel-do-load-languages 'org-babel-load-languages '((C . t))))
  994. #+end_src
  995. **** Python
  996. Install the =pyls= language server.
  997. #+begin_src shell :tangle no
  998. pip3 install --user "python-language-server[all]"
  999. #+end_src
  1000. [[https://www.emacswiki.org/emacs/PythonProgrammingInEmacs][Python-mode]] is an Emacs built in mode.
  1001. + Load the babel language module for Python
  1002. + Add a python source code block structure template with ~<py~
  1003. #+begin_src emacs-lisp
  1004. (use-package python-mode
  1005. :hook (python-mode . lsp-deferred)
  1006. :config (require 'dap-python)
  1007. (add-to-list 'org-src-lang-modes '("python" . python))
  1008. (add-to-list 'org-structure-template-alist '("py" . "src python"))
  1009. (org-babel-do-load-languages 'org-babel-load-languages '((python . t)))
  1010. :custom (python-shell-interpreter "python3") ;; Required if "python" is not python 3.
  1011. (dap-python-executable "python3") ;; Same as above.
  1012. (dap-python-debugger 'debugpy))
  1013. #+end_src
  1014. **** PlantUML
  1015. Download and install [[https://plantuml.com][PlantUML]], a text-based markup language for creating UML diagrams.
  1016. + Load the babel language module for PlantUML
  1017. + Create a structure template with ~<pl~
  1018. #+begin_src emacs-lisp
  1019. (use-package plantuml-mode
  1020. :after org
  1021. :custom (plantuml-default-exec-mode 'jar)
  1022. (plantuml-jar-path "~/.local/bin/plantuml.jar")
  1023. (org-plantuml-jar-path (expand-file-name "~/.local/bin/plantuml.jar"))
  1024. (org-startup-with-inline-images t)
  1025. :config (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  1026. (add-to-list 'org-structure-template-alist '("pl" . "src plantuml"))
  1027. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t))))
  1028. #+end_src
  1029. Toggle inline images with =SPC t i=.
  1030. #+begin_src emacs-lisp
  1031. (dotfiles/leader
  1032. "ti" '(org-toggle-inline-images :which-key "Images"))
  1033. #+end_src
  1034. ** Interface
  1035. :PROPERTIES:
  1036. :header-args: :tangle modules/interface.el :results silent
  1037. :END:
  1038. #+ATTR_ORG: :width 420px
  1039. #+ATTR_HTML: :width 420px
  1040. #+ATTR_LATEX: :width 420px
  1041. [[./docs/images/what-is-emacs-teaser.png]]
  1042. *Bring Emacs out of the eighties*
  1043. *** Ivy
  1044. Download and configure [[https://oremacs.com/swiper/][ivy]], a powerful selection menu for Emacs.
  1045. #+begin_src emacs-lisp
  1046. (use-package ivy
  1047. :diminish
  1048. :config (ivy-mode 1))
  1049. #+end_src
  1050. Counsel is a customized set of commands to replace built in completion buffers.
  1051. #+begin_src emacs-lisp
  1052. (use-package counsel
  1053. :after ivy
  1054. :custom (counsel-linux-app-format-function #'counsel-linux-app-format-function-name-only)
  1055. :config (counsel-mode 1))
  1056. #+end_src
  1057. Switch buffers with =SPC , (comma)=.
  1058. #+begin_src emacs-lisp
  1059. (dotfiles/leader
  1060. "," '(counsel-switch-buffer :which-key "Buffers"))
  1061. #+end_src
  1062. Provide more information about each item with [[https://github.com/Yevgnen/ivy-rich][ivy-rich]].
  1063. #+begin_src emacs-lisp
  1064. (use-package ivy-rich
  1065. :after counsel
  1066. :init (ivy-rich-mode 1))
  1067. #+end_src
  1068. *** Fonts
  1069. Write out to all *3* of Emacs' default font faces.
  1070. #+begin_src emacs-lisp
  1071. (set-face-attribute 'default nil :font dotfiles/font :height dotfiles/font-size)
  1072. (set-face-attribute 'fixed-pitch nil :font dotfiles/font :height dotfiles/font-size)
  1073. (set-face-attribute 'variable-pitch nil :font dotfiles/font :height dotfiles/font-size)
  1074. #+end_src
  1075. Define a transient keybinding for scaling the text.
  1076. #+begin_src emacs-lisp
  1077. (defhydra hydra-text-scale (:timeout 4)
  1078. "Scale"
  1079. ("j" text-scale-increase "Increase")
  1080. ("k" text-scale-decrease "Decrease")
  1081. ("f" nil "Finished" :exit t))
  1082. #+end_src
  1083. Increase the font size in buffers with =SPC t f=.
  1084. + Increase =j=
  1085. + Decrease =k=
  1086. + Finish =f=
  1087. #+begin_src emacs-lisp
  1088. (dotfiles/leader
  1089. "tf" '(hydra-text-scale/body :which-key "Font"))
  1090. #+end_src
  1091. *** Lines
  1092. 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.
  1093. #+begin_example
  1094. 5:
  1095. 4:
  1096. 3:
  1097. 2:
  1098. 1:
  1099. 156: << CURRENT LINE >>
  1100. 1:
  1101. 2:
  1102. 3:
  1103. 4:
  1104. 5:
  1105. #+end_example
  1106. https://github.com/emacsmirror/linum-relative
  1107. + Integrate with ~display-line-numbers-mode~ for performance
  1108. #+begin_src emacs-lisp
  1109. (use-package linum-relative
  1110. :custom (linum-relative-backend 'display-line-numbers-mode)
  1111. :config (linum-relative-global-mode))
  1112. #+end_src
  1113. Add line numbers to the toggles behind =SPC t l=.
  1114. #+begin_src emacs-lisp
  1115. (dotfiles/leader
  1116. "tl" '(linum-relative-global-mode :which-key "Lines"))
  1117. #+end_src
  1118. https://github.com/Fanael/rainbow-delimiters
  1119. + Colourize nested parenthesis
  1120. #+begin_src emacs-lisp
  1121. (use-package rainbow-delimiters
  1122. :hook (prog-mode . rainbow-delimiters-mode))
  1123. #+end_src
  1124. *** Themes
  1125. #+ATTR_ORG: :width 420px
  1126. #+ATTR_HTML: :width 420px
  1127. #+ATTR_LATEX: :width 420px
  1128. [[./docs/images/what-is-emacs-customizable.gif]]
  1129. Cherry pick a few modules from =doom-emacs=. High quality and modern colour themes are provided in the [[https://github.com/hlissner/emacs-doom-themes][doom-themes]] package.
  1130. #+begin_src emacs-lisp
  1131. (use-package doom-themes
  1132. :init (load-theme 'doom-moonlight t))
  1133. #+end_src
  1134. [[https://github.com/seagle0128/doom-modeline][doom-modeline]] provides an elegant status bar / modeline.
  1135. #+begin_src emacs-lisp
  1136. (use-package doom-modeline
  1137. :custom (doom-modeline-height 16)
  1138. :config (doom-modeline-mode 1))
  1139. #+end_src
  1140. Load a theme with =SPC t t=.
  1141. #+begin_src emacs-lisp
  1142. (dotfiles/leader
  1143. "tt" '(counsel-load-theme t t :which-key "Theme"))
  1144. #+end_src
  1145. *** Pretty
  1146. Make programming buffers prettier with [[https://github.com/pretty-mode/pretty-mode][pretty-mode]], complimentary to the built in ~prettify-symbols-mode~.
  1147. #+begin_src emacs-lisp
  1148. (use-package pretty-mode
  1149. :hook (python-mode . turn-on-pretty-mode))
  1150. #+end_src
  1151. *** Ligatures
  1152. Enable font ligatures via [[https://github.com/jming422/fira-code-mode][fira-code-mode]], perform this action *only* when ~Fira Code~ is the current font.
  1153. #+begin_src emacs-lisp
  1154. (when (display-graphic-p)
  1155. (use-package fira-code-mode
  1156. :hook (prog-mode org-mode)))
  1157. #+end_src
  1158. Toggle global ligature mode with =SPC t g=.
  1159. #+begin_src emacs-lisp
  1160. (dotfiles/leader
  1161. "tg" '(global-fira-code-mode :which-key "Ligatures"))
  1162. #+end_src
  1163. *** Dashboard
  1164. #+ATTR_ORG: :width 420px
  1165. #+ATTR_HTML: :width 420px
  1166. #+ATTR_LATEX: :width 420px
  1167. [[./docs/images/desktop.png]]
  1168. Present a dashboard when first launching Emacs. Customize the buttons of the navigator:
  1169. + Brain @ http://localhost:8080
  1170. + Homepage @ https://chrishayward.xyz
  1171. + Athabasca @ https://login.athabascau.ca/cas/login
  1172. + Bookshelf @ https://online.vitalsource.com
  1173. #+begin_src emacs-lisp
  1174. (use-package dashboard
  1175. :custom (dashboard-center-content t)
  1176. (dashboard-set-init-info t)
  1177. (dashboard-set-file-icons t)
  1178. (dashboard-set-heading-icons t)
  1179. (dashboard-set-navigator t)
  1180. (dashboard-startup-banner 'logo)
  1181. (dashboard-projects-backend 'projectile)
  1182. (dashboard-items '((projects . 5) (recents . 5) (agenda . 10)))
  1183. (dashboard-navigator-buttons `(((,(all-the-icons-fileicon "brain" :height 1.1 :v-adjust 0.0)
  1184. "Brain" "Knowledge base"
  1185. (lambda (&rest _) (browse-url "http://localhost:8080"))))
  1186. ((,(all-the-icons-material "public" :height 1.1 :v-adjust 0.0)
  1187. "Homepage" "Personal website"
  1188. (lambda (&rest _) (browse-url "https://chrishayward.xyz"))))
  1189. ((,(all-the-icons-faicon "university" :height 1.1 :v-adjust 0.0)
  1190. "Athabasca" "Univeristy login"
  1191. (lambda (&rest _) (browse-url "https://login.athabascau.ca/cas/login"))))
  1192. ((,(all-the-icons-faicon "book" :height 1.1 :v-adjust 0.0)
  1193. "Bookshelf" "Vitalsource bookshelf"
  1194. (lambda (&rest _) (browse-url "https://online.vitalsource.com"))))))
  1195. :config (dashboard-setup-startup-hook))
  1196. #+end_src
  1197. When running in *daemon* mode, ensure that the dashboard is the initial buffer.
  1198. #+begin_src emacs-lisp
  1199. (setq initial-buffer-choice
  1200. (lambda ()
  1201. (get-buffer "*dashboard*")))
  1202. #+end_src