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.

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