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.

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