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.

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