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.

1599 lines
48 KiB

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