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.

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