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.

1592 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
  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-prefer-lisp-functions nil)
  390. (eshell-prompt-function 'epe-theme-lambda))
  391. #+end_src
  392. Open an =eshell= buffer with =SPC e=.
  393. #+begin_src emacs-lisp
  394. (dotfiles/leader
  395. "e" '(eshell :which-key "Shell"))
  396. #+end_src
  397. *** Source
  398. #+ATTR_ORG: :width 420px
  399. #+ATTR_HTML: :width 420px
  400. #+ATTR_LATEX: :width 420px
  401. [[./docs/images/2021-02-13-example-magit.gif]]
  402. Another hallmark feature is [[https://github.com/magit/magit][Magit]], a complete git porcelain within Emacs.
  403. #+begin_src emacs-lisp
  404. (use-package magit
  405. :commands magit-status
  406. :custom (magit-display-buffer-function
  407. #'magit-display-buffer-same-window-except-diff-v1))
  408. #+end_src
  409. Work directly with github issues / pull requests using [[https://github.com/magit/forge][Forge]].
  410. + Requires a valid ~$GITHUB_TOKEN~
  411. #+begin_src emacs-lisp
  412. (use-package forge
  413. :after magit)
  414. #+end_src
  415. Open the *status* page for the current repository with =SPC g=.
  416. #+begin_src emacs-lisp
  417. (dotfiles/leader
  418. "g" '(magit-status :which-key "Magit"))
  419. #+end_src
  420. *** Windows
  421. Window management with =SPC w=.
  422. + Swap with =w=
  423. + Close with =c=
  424. + Motions with =h,j,k,l=
  425. + Split with =s + <MOTION>=
  426. #+begin_src emacs-lisp
  427. (dotfiles/leader
  428. "w" '(:ignore t :which-key "Window")
  429. "ww" '(window-swap-states :which-key "Swap")
  430. "wc" '(delete-window :which-key "Close")
  431. "wh" '(windmove-left :which-key "Left")
  432. "wj" '(windmove-down :which-key "Down")
  433. "wk" '(windmove-up :which-key "Up")
  434. "wl" '(windmove-right :which-key "Right")
  435. "ws" '(:ignore t :which-key "Split")
  436. "wsj" '(split-window-below :which-key "Down")
  437. "wsl" '(split-window-right :which-key "Right"))
  438. #+end_src
  439. *** Shortcuts
  440. Implement shortcut bindings, cherry picked from Doom emacs.
  441. + Close buffers with =SPC c=
  442. + Find files with =SPC . (period)=
  443. #+begin_src emacs-lisp
  444. (dotfiles/leader
  445. "." '(find-file :which-key "Files")
  446. "c" '(kill-buffer-and-window :which-key "Close"))
  447. #+end_src
  448. Quit emacs with =SPC q=.
  449. + Saving =q=
  450. + Without =w=
  451. + Frame (daemon) =f=
  452. #+begin_src emacs-lisp
  453. (dotfiles/leader
  454. "q" '(:ignore t :which-key "Quit")
  455. "qq" '(save-buffers-kill-emacs :which-key "Save")
  456. "qw" '(kill-emacs :which-key "Now")
  457. "qf" '(delete-frame :which-key "Frame"))
  458. #+end_src
  459. Place runtime tweaks behind =SPC t=.
  460. #+begin_src emacs-lisp
  461. (dotfiles/leader
  462. "t" '(:ignore t :which-key "Tweaks"))
  463. #+end_src
  464. ** Desktop
  465. :PROPERTIES:
  466. :header-args: :tangle modules/desktop.el :results silent
  467. :END:
  468. 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.
  469. #+begin_src conf :tangle config/xinitrc
  470. exec dbus-launch --exit-with-session emacs -mm --debug-init
  471. #+end_src
  472. *** Email
  473. #+ATTR_ORG: :width 420px
  474. #+ATTR_HTML: :width 420px
  475. #+ATTR_LATEX: :width 420px
  476. [[./docs/images/2021-02-13-example-mu4e.gif]]
  477. 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.
  478. #+begin_src conf :tangle config/mbsyncrc
  479. IMAPStore xyz-remote
  480. Host mail.chrishayward.xyz
  481. User chris@chrishayward.xyz
  482. PassCmd "pass chrishayward.xyz/chris"
  483. SSLType IMAPS
  484. MaildirStore xyz-local
  485. Path ~/.cache/mail/
  486. Inbox ~/.cache/mail/inbox
  487. SubFolders Verbatim
  488. Channel xyz
  489. Master :xyz-remote:
  490. Slave :xyz-local:
  491. Patterns * !Archives
  492. Create Both
  493. Expunge Both
  494. SyncState *
  495. #+end_src
  496. 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.
  497. #+begin_src shell :tangle no
  498. mbsync -a
  499. mu index --maildir="~/.cache/mail"
  500. #+end_src
  501. Once the mail's synchronized, and has indexed with =mu=, it's time to install the required packages for Emacs.
  502. + Update every 5 minutes
  503. + Scale text for all devices
  504. + Sign outbound mail with GPG key
  505. + Configure mail account(s)
  506. #+begin_src emacs-lisp
  507. (use-package mu4e
  508. :load-path "/usr/share/emacs/site-lisp/mu4e"
  509. :custom (mu4e-maildir "~/.cache/mail")
  510. (mu4e-update-interval (* 5 60))
  511. (mu4e-get-mail-command "mbsync -a")
  512. (mu4e-compose-format-flowed t)
  513. (mu4e-change-filenames-when-moving t)
  514. (message-send-mail-function 'smtpmail-send-it)
  515. (mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  516. (mu4e-compose-signature (concat "Chris Hayward\n"
  517. "https://chrishayward.xyz\n"))
  518. :config
  519. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  520. (setq mu4e-contexts
  521. (list
  522. ;; Main
  523. ;; chris@chrishayward.xyz
  524. (make-mu4e-context
  525. :name "Main"
  526. :match-func
  527. (lambda (msg)
  528. (when msg
  529. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  530. :vars
  531. '((user-full-name . "Christopher James Hayward")
  532. (user-mail-address . "chris@chrishayward.xyz")
  533. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  534. (smtpmail-smtp-service . 587)
  535. (smtpmail-stream-type . starttls))))))
  536. #+end_src
  537. Use [[https://github.com/iqbalansari/mu4e-alert][mu4e-alert]] to give us desktop notifications about incoming mail.
  538. #+begin_src emacs-lisp
  539. (use-package mu4e-alert
  540. :after mu4e
  541. :custom (mu4e-alert-set-default-style 'libnotify)
  542. :config (mu4e-alert-enable-notifications)
  543. (mu4e-alert-enable-mode-line-display))
  544. #+end_src
  545. Create a keybinding to open the mail dashboard with =SPC m=.
  546. #+begin_src emacs-lisp
  547. (dotfiles/leader
  548. "m" '(mu4e :which-key "Mail"))
  549. #+end_src
  550. *** Browser
  551. Write out the ~$BROWSER~ environment variable.
  552. #+begin_src emacs-lisp
  553. (setenv "BROWSER" dotfiles/browser)
  554. #+end_src
  555. *** Startup
  556. :PROPERTIES:
  557. :header-args: :tangle config/profile
  558. :END:
  559. Ensure that ~/.local/bin~ is added to the path.
  560. #+begin_src sh
  561. PATH=$PATH:~/.local/bin
  562. export PATH
  563. #+end_src
  564. When launching into a session, if the display server is not running then =startx= executes to run the window manager.
  565. #+begin_src sh
  566. if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
  567. exec startx
  568. fi
  569. #+end_src
  570. *** Methods
  571. Define a method to run an external process, allowing us to launch any application on a new process without interferring with Emacs.
  572. #+begin_src emacs-lisp
  573. (defun dotfiles/run (command)
  574. "Run an external process."
  575. (interactive (list (read-shell-command "λ ")))
  576. (start-process-shell-command command nil command))
  577. #+end_src
  578. Apply methods to the current call process to avoid issues with hooks.
  579. #+begin_src emacs-lisp
  580. (defun dotfiles/run-in-background (command)
  581. (let ((command-parts (split-string command "[ ]+")))
  582. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  583. #+end_src
  584. Place keybindings for executing shell commands behind =SPC x=.
  585. + Run shell commands with =x=
  586. + Run async shell commands with =z=
  587. #+begin_src emacs-lisp
  588. (dotfiles/leader
  589. "x" '(:ignore t :which-key "Run")
  590. "xx" '(dotfiles/run :which-key "Run")
  591. "xz" '(async-shell-command :which-key "Async"))
  592. #+end_src
  593. *** Displays
  594. When the window manager first launches the ~init-hook~ executes, allowing us to define some custom logic.
  595. + Display time and date
  596. + Display battery info (if available)
  597. 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.
  598. #+begin_src emacs-lisp
  599. (defun dotfiles/init-hook ()
  600. (exwm-workspace-switch-create 1)
  601. (setq display-time-and-date t)
  602. (display-battery-mode 1)
  603. (display-time-mode 1))
  604. #+end_src
  605. Using =autorandr= with pre configured profiles, switching screens (AKA hot plugging) is also handled through a hook.
  606. #+begin_src emacs-lisp
  607. (defun dotfiles/update-display ()
  608. "Update the displays by forcing a change through autorandr."
  609. (dotfiles/run-in-background "autorandr --change --force"))
  610. #+end_src
  611. *** Configuration
  612. Connect our custom hooks and configure the input keys, a custom layer for key capture layers.
  613. + Enable =randr= support
  614. + Pass through to Emacs
  615. + =M-x= to Emacs
  616. + =C-g= to Emacs
  617. + =C-SPC= to Emacs
  618. + Bindings with =S= (Super / Win)
  619. + Reset =S-r=
  620. + Launch =S-&=
  621. + Workspace =S-[1..9]=
  622. #+begin_src emacs-lisp
  623. (use-package exwm
  624. :custom (exwm-workspace-show-all-buffers t)
  625. (exwm-input-prefix-keys
  626. '(?\M-x
  627. ?\C-c
  628. ?\C-g
  629. ?\C-\ ))
  630. (exwm-input-global-keys
  631. `(([?\s-r] . exwm-reset)
  632. ,@(mapcar (lambda (i)
  633. `(,(kbd (format "s-%d" i)) .
  634. (lambda ()
  635. (interactive)
  636. (exwm-workspace-switch-create ,i))))
  637. (number-sequence 1 9))))
  638. :config (require 'exwm-randr)
  639. (exwm-randr-enable)
  640. (add-hook 'exwm-init-hook #'dotfiles/init-hook)
  641. (add-hook 'exwm-randr-screen-change-hook #'dotfiles/update-display)
  642. (dotfiles/update-display)
  643. (exwm-enable))
  644. #+end_src
  645. ** Writing
  646. :PROPERTIES:
  647. :header-args: :tangle modules/writing.el
  648. :END:
  649. 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.
  650. #+begin_src emacs-lisp
  651. (setq epa-file-select-keys 2
  652. epa-file-cache-passphrase-for-symmetric-encryption t
  653. epa-file-encrypt-to dotfiles/public-key)
  654. #+end_src
  655. Download and install [[https://github.com/integral-dw/org-superstar-mode][org-superstar-mode]] for making headline stars more *super*.
  656. #+begin_src emacs-lisp
  657. (use-package org-superstar
  658. :after org
  659. :hook (org-mode . org-superstar-mode))
  660. #+end_src
  661. *** Roam
  662. #+ATTR_ORG: :width 420px
  663. #+ATTR_HTML: :width 420px
  664. #+ATTR_LATEX: :width 420px
  665. [[./docs/images/2021-02-13-example-roam.png]]
  666. Download and install [[https://orgroam.com][org-roam]], a plain text knowledge management system for Emacs.
  667. #+begin_src emacs-lisp
  668. (use-package org-roam
  669. :hook (after-init . org-roam-mode)
  670. :custom (org-roam-directory org-directory)
  671. (org-roam-encrypt-files t)
  672. (org-roam-capture-templates '())
  673. (org-roam-dailies-capture-templates
  674. '(("d" "Default" entry (function org-roam-capture--get-point)
  675. "* %?"
  676. :file-name "docs/daily/%<%Y-%m-%d>"
  677. :head
  678. "
  679. ,#+TITLE: %<%Y-%m-%d>
  680. ,#+AUTHOR: Christopher James Hayward
  681. "))))
  682. #+end_src
  683. Place keybindings behind =SPC r=.
  684. + Find with =f=
  685. + Toggle buffer with =b=
  686. + Dailies with =d=
  687. + Arbitrary date with =d=
  688. + Today with =t=
  689. + Tomorrow with =m=
  690. + Yesterday with =y=
  691. #+begin_src emacs-lisp
  692. (dotfiles/leader
  693. "r" '(:ignore t :which-key "Roam")
  694. "rf" '(org-roam-find-file :which-key "Find")
  695. "rb" '(org-roam-buffer-toggle-display :which-key "Buffer")
  696. "rd" '(:ignore t :which-key "Dailies")
  697. "rdd" '(org-roam-dailies-find-date :which-key "Date")
  698. "rdt" '(org-roam-dailies-find-today :which-key "Today")
  699. "rdm" '(org-roam-dailies-find-tomorrow :which-key "Tomorrow")
  700. "rdy" '(org-roam-dailies-find-yesterday :which-key "Yesterday"))
  701. #+end_src
  702. Visualize the org-roam database with the server, available when the editor is running at http://localhost:8080
  703. #+begin_src emacs-lisp
  704. (use-package org-roam-server
  705. :hook (org-roam-mode . org-roam-server-mode))
  706. #+end_src
  707. *** Hugo
  708. 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.
  709. #+begin_src emacs-lisp
  710. (use-package ox-hugo
  711. :after ox)
  712. #+end_src
  713. *** Posts
  714. Add a capture template for creating new blog posts.
  715. #+begin_src emacs-lisp
  716. (with-eval-after-load 'org-roam
  717. (add-to-list 'org-roam-capture-templates
  718. '("p" "Post" plain (function org-roam-capture--get-point)
  719. "%?"
  720. :file-name "docs/posts/${slug}"
  721. :unnarrowed t
  722. :head
  723. "
  724. ,#+TITLE: ${title}
  725. ,#+AUTHOR: Christopher James Hayward
  726. ,#+DATE: %<%Y-%m-%d>
  727. ,#+EXPORT_FILE_NAME: ${slug}
  728. ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  729. ,#+HUGO_BASE_DIR: ../
  730. ,#+HUGO_AUTO_SET_LASTMOD: t
  731. ,#+HUGO_SECTION: posts
  732. ,#+HUGO_DRAFT: true
  733. ")))
  734. #+end_src
  735. *** Notes
  736. Add a capture template for creating blog posts and notes on other peoples content / published works.
  737. #+begin_src emacs-lisp
  738. (with-eval-after-load 'org-roam
  739. (add-to-list 'org-roam-capture-templates
  740. '("n" "Notes" plain (function org-roam-capture--get-point)
  741. "%?"
  742. :file-name "docs/notes/${slug}"
  743. :unnarrowed t
  744. :head
  745. "
  746. ,#+TITLE: ${title}
  747. ,#+AUTHOR: Christopher James Hayward
  748. ,#+EXPORT_FILE_NAME: ${slug}
  749. ,#+ROAM_KEY: https://chrishayward.xyz/notes/${slug}/
  750. ,#+HUGO_BASE_DIR: ../
  751. ,#+HUGO_AUTO_SET_LASTMOD: t
  752. ,#+HUGO_SECTION: notes
  753. ,#+HUGO_DRAFT: true
  754. ")))
  755. #+end_src
  756. *** Slides
  757. 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=.
  758. #+begin_src emacs-lisp
  759. (use-package ox-reveal
  760. :after ox
  761. :custom (org-reveal-root "https://cdn.jsdelivr.net/npm/reveal.js"))
  762. #+end_src
  763. Create a capture template for creating slides quickly, with our desired configuration.
  764. #+begin_src emacs-lisp
  765. (with-eval-after-load 'org-roam
  766. (add-to-list 'org-roam-capture-templates
  767. '("s" "Slides" plain (function org-roam-capture--get-point)
  768. "%?"
  769. :file-name "docs/slides/${slug}"
  770. :unnarrowed t
  771. :head
  772. "
  773. ,#+TITLE: ${title}
  774. ,#+AUTHOR: Christopher James Hayward
  775. ,#+EXPORT_FILE_NAME: ${slug}
  776. ,#+OPTIONS: toc:nil num:nil reveal_title_slide:nil
  777. ,#+REVEAL_ROOT: https://cdn.jsdelivr.net/npm/reveal.js
  778. ,#+REVEAL_THEME: serif
  779. ")))
  780. #+end_src
  781. *** Agenda
  782. #+ATTR_ORG: :width 420px
  783. #+ATTR_HTML: :width 420px
  784. #+ATTR_LATEX: :width 420px
  785. [[./docs/images/2021-02-13-example-agenda.gif]]
  786. Override ~org-agenda-file-regexp~ to include =.org.gpg= files.
  787. #+begin_src emacs-lisp
  788. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  789. (setq org-agenda-file-regexp
  790. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  791. org-agenda-file-regexp)))
  792. #+end_src
  793. Create a capture template for courses.
  794. #+begin_src emacs-lisp
  795. (with-eval-after-load 'org-roam
  796. (add-to-list 'org-roam-capture-templates
  797. '("c" "Course" plain (function org-roam-capture--get-point)
  798. "%?"
  799. :file-name "docs/courses/${slug}"
  800. :unnarrowed t
  801. :head
  802. "
  803. ,#+TITLE: ${title}
  804. ,#+SUBTITLE:
  805. ,#+AUTHOR: Christopher James Hayward
  806. ")))
  807. #+end_src
  808. Configure agenda sources.
  809. #+begin_src emacs-lisp
  810. (setq org-agenda-files '("~/.emacs.d/docs/"
  811. "~/.emacs.d/docs/courses/"
  812. "~/.emacs.d/docs/daily/"))
  813. #+end_src
  814. Open an agenda buffer with =SPC a=.
  815. #+begin_src emacs-lisp
  816. (dotfiles/leader
  817. "a" '(org-agenda :which-key "Agenda"))
  818. #+end_src
  819. *** Images
  820. Capture screenshots with [[https://github.com/tecosaur/screenshot][screenshot.el]].
  821. #+begin_src emacs-lisp
  822. (use-package screenshot
  823. :commands (screenshot))
  824. #+end_src
  825. Create screencasts with =one-frame-per-action= GIF recording via [[https://github.com/takaxp/emacs-gif-screencast][emacs-gif-screencast]].
  826. + Pause / Resume
  827. + High Quality
  828. + Optimized
  829. It requires the installation of ~scrot~, ~gifsicle~, and ~convert~ from the =ImageMagick= library.
  830. #+begin_src emacs-lisp
  831. (use-package gif-screencast
  832. :commands (gif-screencast-start-or-stop gif-screencast-toggle-pause)
  833. :custom (gif-screencast-output-directory (concat dotfiles/home "docs/images/")))
  834. #+end_src
  835. Place keybindings behind =SPC s=.
  836. + Screenshot with =s=
  837. + Screencast with =c=
  838. #+begin_src emacs-lisp
  839. (dotfiles/leader
  840. "s" '(:ignore t :which-key "Screen")
  841. "ss" '(screenshot :which-key "Screenshot")
  842. "sc" '(gif-screencast-start-or-stop :which-key "Screencast"))
  843. #+end_src
  844. *** Grammar
  845. 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!
  846. #+begin_src emacs-lisp
  847. (use-package writegood-mode
  848. :after org
  849. :config (writegood-mode))
  850. #+end_src
  851. Toggle ~writegood~ mode with =SPC t w=.
  852. #+begin_src emacs-lisp
  853. (dotfiles/leader
  854. "tw" '(writegood-mode :which-key "Grammar"))
  855. #+end_src
  856. *** Spelling
  857. Use the built in =ispell= package to add spell checking features to buffers.
  858. #+begin_src emacs-lisp
  859. (use-package ispell
  860. :after org
  861. :custom (ispell-dictionary dotfiles/lang))
  862. #+end_src
  863. Toggle highlighting within buffers with =SPC t s=.
  864. #+begin_src emacs-lisp
  865. (dotfiles/leader
  866. "ts" '(flyspell-buffer :which-key "Spelling"))
  867. #+end_src
  868. ** Projects
  869. :PROPERTIES:
  870. :header-args: :tangle modules/projects.el
  871. :END:
  872. An IDE like experience (or better) can be achieved in Emacs using two *Microsoft* open source initiatives.
  873. + [[https://microsoft.github.io/language-server-protocol/][Language Server Protocol]]
  874. + [[https://microsoft.github.io/debug-adapter-protocol/][Debug Adapter Protocol]]
  875. Add support for language servers with [[https://emacs-lsp.github.io/lsp-mode/][lsp-mode]].
  876. #+begin_src emacs-lisp
  877. (use-package lsp-mode
  878. :commands (lsp lsp-deferred)
  879. :custom (lsp-idle-delay (* 5 dotfiles/idle)))
  880. #+end_src
  881. [[https://emacs-lsp.github.io/lsp-ui/][lsp-ui]] provides UI improvements for =lsp-mode=.
  882. #+begin_src emacs-lisp
  883. (use-package lsp-ui
  884. :after lsp
  885. :custom (lsp-ui-doc-position 'at-point)
  886. (lsp-ui-doc-delay 0.500))
  887. #+end_src
  888. [[https://emacs-lsp.github.io/dap-mode/][Dap-mode]] adds support for the debug adapter protocol to Emacs.
  889. #+begin_src emacs-lisp
  890. (use-package dap-mode
  891. :commands (dap-debug))
  892. #+end_src
  893. *** Containers
  894. Use ~docker~ for running containers. Download and install https://github.com/Silex/docker.el, allowing us to manage containers within Emacs.
  895. #+begin_src emacs-lisp
  896. (use-package docker
  897. :commands (docker))
  898. #+end_src
  899. Open the management screen with =SPC k=.
  900. #+begin_src emacs-lisp
  901. (dotfiles/leader
  902. "k" '(docker :which-key "Docker"))
  903. #+end_src
  904. *** Management
  905. 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.
  906. #+begin_src emacs-lisp
  907. (use-package projectile
  908. :custom (projectile-project-search-path '("~/.local/source"))
  909. :config (projectile-mode))
  910. #+end_src
  911. *** Completion
  912. Text completion framework via =company= aka *Complete Anything*.
  913. http://company-mode.github.io/
  914. + Integrate with =lsp-mode=
  915. #+begin_src emacs-lisp
  916. (use-package company
  917. :after lsp)
  918. (use-package company-lsp
  919. :after (lsp company)
  920. :custom (company-backend 'company-lsp))
  921. #+end_src
  922. *** Passwords
  923. 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.
  924. #+begin_src emacs-lisp
  925. (use-package password-store
  926. :custom (password-store-dir dotfiles/passwords))
  927. #+end_src
  928. Configure keybindings behind =SPC p=.
  929. + Copy with =p=
  930. + Rename with =r=
  931. + Generate with =g=
  932. #+begin_src emacs-lisp
  933. (dotfiles/leader
  934. "p" '(:ignore t :which-key "Passwords")
  935. "pp" '(password-store-copy :which-key "Copy")
  936. "pr" '(password-store-rename :which-key "Rename")
  937. "pg" '(password-store-generate :which-key "Generate"))
  938. #+end_src
  939. *** Languages
  940. Support for individual languages are implemented here.
  941. **** Go
  942. Install the =gopls= language server.
  943. #+begin_src sh :tangle no
  944. GO111MODULE=on go get golang.org/x/tools/gopls@latest
  945. #+end_src
  946. Set the ~GOPATH~ environment variable prior to loading, this allows us to change the default value of ~$HOME/go~ to ~$HOME/.go~.
  947. #+begin_src emacs-lisp
  948. (setenv "GOPATH" (concat (getenv "HOME") "/.go/"))
  949. #+end_src
  950. Additionally, include the =bin= subdirectory of the ~$GOPATH~ in the ~$PATH~ variable, adding compiled golang programs.
  951. #+begin_src emacs-lisp
  952. (setenv "PATH" (concat (getenv "GOPATH") "bin:" (getenv "PATH")))
  953. #+end_src
  954. Finally we can include the =go-mode= package, integrating it with =lsp=.
  955. #+begin_src emacs-lisp
  956. (use-package go-mode
  957. :hook (go-mode . lsp)
  958. :custom (lsp-go-gopls-server-path "~/.go/bin/gopls"))
  959. #+end_src
  960. Apply some custom behaviour before saving:
  961. + Format buffer
  962. + Organize imports
  963. #+begin_src emacs-lisp
  964. (defun dotfiles/go-hook ()
  965. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  966. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  967. #+end_src
  968. #+begin_src emacs-lisp
  969. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  970. #+end_src
  971. Add a golang source code block structure template with ~<go~:
  972. #+begin_src emacs-lisp
  973. (add-to-list 'org-structure-template-alist '("go" . "src go"))
  974. #+end_src
  975. **** HTTP
  976. Instead of the popular =restclient= package, I use [[https://github.com/zweifisch/ob-http][ob-http]] as a lightweight alternative.
  977. #+begin_src emacs-lisp
  978. (use-package ob-http
  979. :after org
  980. :config (org-babel-do-load-languages
  981. 'org-babel-load-languages
  982. '((http . t))))
  983. #+end_src
  984. **** C/C++
  985. #+ATTR_ORG: :width 420px
  986. #+ATTR_HTML: :width 420px
  987. #+ATTR_LATEX: :width 420px
  988. [[./docs/images/2021-02-13-example-ccls.gif]]
  989. Add support for C/C++ languages.
  990. + Configure the [[https://github.com/MaskRay/ccls][ccls]] language server
  991. + Load babel language modules for C/C++
  992. + Create a new structure templates for C/C++
  993. - ~<cc~ for C
  994. - ~<cpp~ for C++
  995. #+begin_src emacs-lisp
  996. (use-package ccls
  997. :hook ((c-mode c++-mode objc-mode cuda-mode) .
  998. (lambda ()
  999. (require 'ccls)
  1000. (lsp-deferred)))
  1001. :config (add-to-list 'org-structure-template-alist '("cc" . "src C"))
  1002. (add-to-list 'org-structure-template-alist '("cpp" . "src C++"))
  1003. (org-babel-do-load-languages 'org-babel-load-languages '((C . t))))
  1004. #+end_src
  1005. **** Python
  1006. Install the =pyls= language server.
  1007. #+begin_src shell :tangle no
  1008. pip3 install --user "python-language-server[all]"
  1009. #+end_src
  1010. [[https://www.emacswiki.org/emacs/PythonProgrammingInEmacs][Python-mode]] is an Emacs built in mode.
  1011. + Load the babel language module for Python
  1012. + Add a python source code block structure template with ~<py~
  1013. #+begin_src emacs-lisp
  1014. (use-package python-mode
  1015. :hook (python-mode . lsp-deferred)
  1016. :config (require 'dap-python)
  1017. (add-to-list 'org-src-lang-modes '("python" . python))
  1018. (add-to-list 'org-structure-template-alist '("py" . "src python"))
  1019. (org-babel-do-load-languages 'org-babel-load-languages '((python . t)))
  1020. :custom (python-shell-interpreter "python3") ;; Required if "python" is not python 3.
  1021. (dap-python-executable "python3") ;; Same as above.
  1022. (dap-python-debugger 'debugpy))
  1023. #+end_src
  1024. **** PlantUML
  1025. Download and install [[https://plantuml.com][PlantUML]], a text-based markup language for creating UML diagrams.
  1026. + Load the babel language module for PlantUML
  1027. + Create a structure template with ~<pl~
  1028. #+begin_src emacs-lisp
  1029. (use-package plantuml-mode
  1030. :after org
  1031. :custom (plantuml-default-exec-mode 'jar)
  1032. (plantuml-jar-path "~/.local/bin/plantuml.jar")
  1033. (org-plantuml-jar-path (expand-file-name "~/.local/bin/plantuml.jar"))
  1034. (org-startup-with-inline-images t)
  1035. :config (add-to-list 'org-src-lang-modes '("plantuml" . plantuml))
  1036. (add-to-list 'org-structure-template-alist '("pl" . "src plantuml"))
  1037. (org-babel-do-load-languages 'org-babel-load-languages '((plantuml . t))))
  1038. #+end_src
  1039. Toggle inline images with =SPC t i=.
  1040. #+begin_src emacs-lisp
  1041. (dotfiles/leader
  1042. "ti" '(org-toggle-inline-images :which-key "Images"))
  1043. #+end_src
  1044. ** Interface
  1045. :PROPERTIES:
  1046. :header-args: :tangle modules/interface.el
  1047. :END:
  1048. #+ATTR_ORG: :width 420px
  1049. #+ATTR_HTML: :width 420px
  1050. #+ATTR_LATEX: :width 420px
  1051. [[./docs/images/what-is-emacs-teaser.png]]
  1052. *Bring Emacs out of the eighties*
  1053. *** Ivy
  1054. Download and configure [[https://oremacs.com/swiper/][ivy]], a powerful selection menu for Emacs.
  1055. #+begin_src emacs-lisp
  1056. (use-package ivy
  1057. :diminish
  1058. :config (ivy-mode 1))
  1059. #+end_src
  1060. Counsel is a customized set of commands to replace built in completion buffers.
  1061. #+begin_src emacs-lisp
  1062. (use-package counsel
  1063. :after ivy
  1064. :custom (counsel-linux-app-format-function #'counsel-linux-app-format-function-name-only)
  1065. :config (counsel-mode 1))
  1066. #+end_src
  1067. Switch buffers with =SPC , (comma)=.
  1068. #+begin_src emacs-lisp
  1069. (dotfiles/leader
  1070. "," '(counsel-switch-buffer :which-key "Buffers"))
  1071. #+end_src
  1072. Provide more information about each item with [[https://github.com/Yevgnen/ivy-rich][ivy-rich]].
  1073. #+begin_src emacs-lisp
  1074. (use-package ivy-rich
  1075. :after counsel
  1076. :init (ivy-rich-mode 1))
  1077. #+end_src
  1078. *** Fonts
  1079. Write out to all *3* of Emacs' default font faces.
  1080. #+begin_src emacs-lisp
  1081. (set-face-attribute 'default nil :font dotfiles/font :height dotfiles/font-size)
  1082. (set-face-attribute 'fixed-pitch nil :font dotfiles/font :height dotfiles/font-size)
  1083. (set-face-attribute 'variable-pitch nil :font dotfiles/font :height dotfiles/font-size)
  1084. #+end_src
  1085. Define a transient keybinding for scaling the text.
  1086. #+begin_src emacs-lisp
  1087. (defhydra hydra-text-scale (:timeout 4)
  1088. "Scale"
  1089. ("j" text-scale-increase "Increase")
  1090. ("k" text-scale-decrease "Decrease")
  1091. ("f" nil "Finished" :exit t))
  1092. #+end_src
  1093. Increase the font size in buffers with =SPC t f=.
  1094. + Increase =j=
  1095. + Decrease =k=
  1096. + Finish =f=
  1097. #+begin_src emacs-lisp
  1098. (dotfiles/leader
  1099. "tf" '(hydra-text-scale/body :which-key "Font"))
  1100. #+end_src
  1101. *** Lines
  1102. 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.
  1103. #+begin_example
  1104. 5:
  1105. 4:
  1106. 3:
  1107. 2:
  1108. 1:
  1109. 156: << CURRENT LINE >>
  1110. 1:
  1111. 2:
  1112. 3:
  1113. 4:
  1114. 5:
  1115. #+end_example
  1116. https://github.com/emacsmirror/linum-relative
  1117. + Integrate with ~display-line-numbers-mode~ for performance
  1118. #+begin_src emacs-lisp
  1119. (use-package linum-relative
  1120. :commands (linum-relative-global-mode)
  1121. :custom (linum-relative-backend 'display-line-numbers-mode))
  1122. #+end_src
  1123. Add line numbers to the toggles behind =SPC t l=.
  1124. #+begin_src emacs-lisp
  1125. (dotfiles/leader
  1126. "tl" '(linum-relative-global-mode :which-key "Lines"))
  1127. #+end_src
  1128. https://github.com/Fanael/rainbow-delimiters
  1129. + Colourize nested parenthesis
  1130. #+begin_src emacs-lisp
  1131. (use-package rainbow-delimiters
  1132. :hook (prog-mode . rainbow-delimiters-mode))
  1133. #+end_src
  1134. *** Themes
  1135. #+ATTR_ORG: :width 420px
  1136. #+ATTR_HTML: :width 420px
  1137. #+ATTR_LATEX: :width 420px
  1138. [[./docs/images/what-is-emacs-customizable.gif]]
  1139. 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.
  1140. #+begin_src emacs-lisp
  1141. (use-package doom-themes
  1142. :init (load-theme 'doom-moonlight t))
  1143. #+end_src
  1144. [[https://github.com/seagle0128/doom-modeline][doom-modeline]] provides an elegant status bar / modeline.
  1145. #+begin_src emacs-lisp
  1146. (use-package doom-modeline
  1147. :custom (doom-modeline-height 16)
  1148. :config (doom-modeline-mode 1))
  1149. #+end_src
  1150. Load a theme with =SPC t t=.
  1151. #+begin_src emacs-lisp
  1152. (dotfiles/leader
  1153. "tt" '(counsel-load-theme t t :which-key "Theme"))
  1154. #+end_src
  1155. *** Pretty
  1156. Make programming buffers prettier with [[https://github.com/pretty-mode/pretty-mode][pretty-mode]], complimentary to the built in ~prettify-symbols-mode~.
  1157. #+begin_src emacs-lisp
  1158. (use-package pretty-mode
  1159. :hook (python-mode . turn-on-pretty-mode))
  1160. #+end_src
  1161. *** Ligatures
  1162. 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.
  1163. #+begin_src emacs-lisp
  1164. (when (display-graphic-p)
  1165. (use-package fira-code-mode
  1166. :hook (prog-mode org-mode)))
  1167. #+end_src
  1168. Toggle global ligature mode with =SPC t g=.
  1169. #+begin_src emacs-lisp
  1170. (dotfiles/leader
  1171. "tg" '(global-fira-code-mode :which-key "Ligatures"))
  1172. #+end_src
  1173. *** Dashboard
  1174. #+ATTR_ORG: :width 420px
  1175. #+ATTR_HTML: :width 420px
  1176. #+ATTR_LATEX: :width 420px
  1177. [[./docs/images/desktop.png]]
  1178. Present a dashboard when first launching Emacs. Customize the buttons of the navigator:
  1179. + Brain @ http://localhost:8080
  1180. + Homepage @ https://chrishayward.xyz
  1181. + Athabasca @ https://login.athabascau.ca/cas/login
  1182. + Bookshelf @ https://online.vitalsource.com
  1183. #+begin_src emacs-lisp
  1184. (use-package dashboard
  1185. :custom (dashboard-center-content t)
  1186. (dashboard-set-init-info t)
  1187. (dashboard-set-file-icons t)
  1188. (dashboard-set-heading-icons t)
  1189. (dashboard-set-navigator t)
  1190. (dashboard-startup-banner 'logo)
  1191. (dashboard-projects-backend 'projectile)
  1192. (dashboard-items '((projects . 5) (recents . 5) (agenda . 10)))
  1193. (dashboard-navigator-buttons `(((,(all-the-icons-fileicon "brain" :height 1.1 :v-adjust 0.0)
  1194. "Brain" "Knowledge base"
  1195. (lambda (&rest _) (browse-url "http://localhost:8080"))))
  1196. ((,(all-the-icons-material "public" :height 1.1 :v-adjust 0.0)
  1197. "Homepage" "Personal website"
  1198. (lambda (&rest _) (browse-url "https://chrishayward.xyz"))))
  1199. ((,(all-the-icons-faicon "university" :height 1.1 :v-adjust 0.0)
  1200. "Athabasca" "Univeristy login"
  1201. (lambda (&rest _) (browse-url "https://login.athabascau.ca/cas/login"))))
  1202. ((,(all-the-icons-faicon "book" :height 1.1 :v-adjust 0.0)
  1203. "Bookshelf" "Vitalsource bookshelf"
  1204. (lambda (&rest _) (browse-url "https://online.vitalsource.com"))))))
  1205. :config (dashboard-setup-startup-hook))
  1206. #+end_src
  1207. When running in *daemon* mode, ensure that the dashboard is the initial buffer.
  1208. #+begin_src emacs-lisp
  1209. (setq initial-buffer-choice
  1210. (lambda ()
  1211. (get-buffer "*dashboard*")))
  1212. #+end_src