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.

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