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.

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