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.

1217 lines
37 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
  1. #+TITLE: Dotfiles
  2. #+AUTHOR: Christopher James Hayward
  3. #+EMAIL: chris@chrishayward.xyz
  4. #+ROAM_KEY: https://github.com/chayward1/dotfiles/
  5. #+begin_example
  6. _.-="_- _
  7. _.-=" _- | ||"""""""---._______ __..
  8. ___.===""""-.______-,,,,,,,,,,,,`-''----" """"" """"" __'
  9. __.--"" __ ,' o \ __ [__|
  10. __-""=======.--"" ""--.=================================.--"" ""--.=======:
  11. ] [w] : / \ : |========================| : / \ : [w] :
  12. V___________:| |: |========================| :| |: _-"
  13. V__________: \ / :_|=======================/_____: \ / :__-"
  14. -----------' "-____-" `-------------------------------' "-____-"
  15. #+end_example
  16. Immutable GNU Emacs dotfiles. Built for Life, Liberty, and the Open Road.
  17. + 100% Literate
  18. + 100% Immutable
  19. + 100% Reproducible
  20. * Init
  21. :PROPERTIES:
  22. :header-args: :tangle ~/.local/source/dotfiles/init.el
  23. :END:
  24. Although later versions of Emacs introduce =early-init.el=, it's not used in this configuration for two reasons:
  25. + It's not required due to the modularity
  26. + Maintaining support for older versions
  27. Assuming you have completed all of the following tasks prior to proceeding further:
  28. 1. Imported the =secrets=
  29. 2. Initialized the =passwords=
  30. 3. Defined the =host= file
  31. 4. Created all required symbolic links
  32. Launch emacs: ~emacs -mm --debug-init~
  33. #+begin_src emacs-lisp
  34. ;; Load the host configuration.
  35. (let ((host-file (concat user-emacs-directory "/hosts/" system-name ".el")))
  36. (when (file-exists-p host-file)
  37. (load-file host-file)))
  38. ;; Load the enabled modules.
  39. (dolist (m dotfiles/modules)
  40. (let ((mod-file (concat dotfiles/home "/modules/" (symbol-name m) ".el")))
  41. (when (file-exists-p mod-file)
  42. (load-file mod-file))))
  43. #+end_src
  44. * Hosts
  45. 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.
  46. ** Example (Ubuntu)
  47. :PROPERTIES:
  48. :header-args: :tangle ~/.local/source/dotfiles/hosts/ubuntu.el
  49. :END:
  50. The first configuration, which was built using the Ubuntu 20.04 LTS server edition. I decided to incorporate =flatpaks= into this build. Setting the ~$BROWSER~ variable is required in the desktop module. Set the browser to the flatpak borwser currently installed, this could change to chromium, firefox, or any other browser by changing this environment variable.
  51. #+begin_src emacs-lisp
  52. (setenv "BROWSER" "flatpak run org.mozilla.firefox")
  53. #+end_src
  54. Add the modules you want to initialize to the ~dotfiles/modules~ variable.
  55. #+begin_src emacs-lisp
  56. (defvar dotfiles/modules '(core
  57. desktop
  58. writing
  59. projects
  60. interface))
  61. #+end_src
  62. Specify the ~home~ and ~cache~ directories.
  63. #+begin_src emacs-lisp
  64. (defvar dotfiles/cache "~/.cache/emacs")
  65. (defvar dotfiles/home user-emacs-directory)
  66. #+end_src
  67. Functionality like =completion= and =hints= can be delayed to avoid popups for common manuevers. Adjust this value to your personal taste.
  68. #+begin_src emacs-lisp
  69. (defvar dotfiles/idle 0.0)
  70. #+end_src
  71. Avoid the infamous *Emacs pinky* by binding =SPC= as a leader key, utilizing the thumb instead of the weaker pinky finger. You may change this value if you want to use something else.
  72. #+begin_src emacs-lisp
  73. (defvar dotfiles/leader-key "SPC")
  74. (defvar dotfiles/leader-key-global "C-SPC")
  75. #+end_src
  76. Define where the source repositories are stored, for integration with the *Projects* module.
  77. #+begin_src emacs-lisp
  78. (defvar dotfiles/src "~/.local/source/")
  79. #+end_src
  80. Secret keys and passwords are stored in a seperate repository.
  81. #+begin_src emacs-lisp
  82. (defvar dotfiles/secrets (concat dotfiles/src "secrets/"))
  83. (defvar dotfiles/passwords (concat dotfiles/src "passwords/"))
  84. #+end_src
  85. * Modules
  86. 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 of what can be achieved.
  87. ** Core
  88. :PROPERTIES:
  89. :header-args: :tangle ~/.local/source/dotfiles/modules/core.el :results silent
  90. :END:
  91. 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.
  92. *** Cleanup
  93. 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]].
  94. #+begin_src emacs-lisp
  95. (setq user-emacs-directory dotfiles/cache)
  96. #+end_src
  97. Because this project uses version-control, we can disable more unwanted features:
  98. + Lock files
  99. + Backup files
  100. #+begin_src emacs-lisp
  101. (setq create-lockfiles nil
  102. make-backup-files nil)
  103. #+end_src
  104. *** Package management
  105. 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.
  106. + Use the development branch
  107. + Integrate with ~use-package~
  108. Apply the configurations prior to bootstrapping the package manager, by setting (writing) to the variables that =straight= will ultimately read from.
  109. #+begin_src emacs-lisp
  110. (setq straight-repository-branch "develop"
  111. straight-use-package-by-default t)
  112. #+end_src
  113. 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.
  114. #+begin_src emacs-lisp
  115. (defvar bootstrap-version)
  116. (let ((bootstrap-file
  117. (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
  118. (bootstrap-version 5))
  119. (unless (file-exists-p bootstrap-file)
  120. (with-current-buffer
  121. (url-retrieve-synchronously
  122. "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
  123. 'silent 'inhibit-cookies)
  124. (goto-char (point-max))
  125. (eval-print-last-sexp)))
  126. (load bootstrap-file nil 'nomessage))
  127. #+end_src
  128. Complete the integration with ~use-package~ by installing it with =straight=.
  129. #+begin_src emacs-lisp
  130. (straight-use-package 'use-package)
  131. #+end_src
  132. *** Hermetic evaluation
  133. Despite having our *stateful* and *immutable* configurations seperate, it's good practice to make efforts to reduce the trash created by Emacs.
  134. Install [[https://github.com/emacscollective/no-littering][no-littering]] to reduce the files created by Emacs.
  135. #+begin_src emacs-lisp
  136. (use-package no-littering)
  137. #+end_src
  138. Emacs' default user interface is horrendous, but with less than 10 lines of code we can change that.
  139. #+begin_src emacs-lisp
  140. (setq inhibit-startup-message t)
  141. (global-prettify-symbols-mode)
  142. (scroll-bar-mode -1)
  143. (menu-bar-mode -1)
  144. (tool-bar-mode -1)
  145. (tooltip-mode -1)
  146. #+end_src
  147. *** Literate programming
  148. *Organize your plain life in plain text*
  149. [[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.
  150. + [[https://orgmode.org/worg/org-contrib/babel/languages/index.html][Babel languages]]
  151. + [[https://orgmode.org/manual/Structure-Templates.html][Structure templates]]
  152. #+begin_src emacs-lisp
  153. (use-package org
  154. :hook
  155. (org-mode . (lambda ()
  156. (org-indent-mode)
  157. (visual-line-mode 1)
  158. (variable-pitch-mode 1)))
  159. :config
  160. (setq org-ellipsis " ▾"
  161. org-log-done 'time
  162. org-log-into-drawer t
  163. org-directory dotfiles/home
  164. org-src-preserve-indentation t)
  165. (org-babel-do-load-languages
  166. 'org-babel-load-languages
  167. '((shell . t)
  168. (python . t)
  169. (emacs-lisp . t)))
  170. (require 'org-tempo)
  171. (add-to-list 'org-structure-template-alist '("s" . "src"))
  172. (add-to-list 'org-structure-template-alist '("q" . "quote"))
  173. (add-to-list 'org-structure-template-alist '("e" . "example"))
  174. (add-to-list 'org-structure-template-alist '("sh" . "src shell"))
  175. (add-to-list 'org-structure-template-alist '("py" . "src python"))
  176. (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")))
  177. #+end_src
  178. #+begin_src emacs-lisp
  179. (defun dotfiles/tangle (dir)
  180. "Recursively tangle the Org files within a directory."
  181. (interactive)
  182. (let ((org-files (directory-files-recursively dir "org")))
  183. (dolist (f org-files)
  184. (org-babel-tangle-file f))))
  185. #+end_src
  186. *** Custom keybindings
  187. Make the =ESC= key quit (most) prompts, instead of the default =C-g=.
  188. #+begin_src emacs-lisp
  189. (global-set-key (kbd "<escape>") 'keyboard-escape-quit)
  190. #+end_src
  191. **** Hints
  192. 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.
  193. #+begin_src emacs-lisp
  194. (use-package which-key
  195. :diminish which-key-mode
  196. :init (which-key-mode)
  197. :config (setq which-key-idle-delay dotfiles/idle))
  198. #+end_src
  199. **** Leader
  200. 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.
  201. #+begin_src emacs-lisp
  202. (use-package general
  203. :config
  204. (general-create-definer dotfiles/leader
  205. :states '(normal motion)
  206. :keymaps 'override
  207. :prefix dotfiles/leader-key
  208. :global-prefix dotfiles/leader-key-global))
  209. #+end_src
  210. Use [[https://github.com/abo-abo/hydra][hydra]] for transient keybindings sharing a common prefix.
  211. #+begin_src emacs-lisp
  212. (use-package hydra)
  213. #+end_src
  214. **** Evil mode
  215. 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.
  216. #+begin_src emacs-lisp
  217. (use-package evil
  218. :init (setq evil-want-integration t
  219. evil-want-keybinding nil)
  220. :config (evil-mode 1))
  221. #+end_src
  222. 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.
  223. #+begin_src emacs-lisp
  224. (use-package evil-collection
  225. :after evil
  226. :config (evil-collection-init))
  227. #+end_src
  228. Surround text with functions, quotations, and any other symbols using the [[https://github.com/emacs-evil/evil-surround][evil-surround]] package.
  229. #+begin_src emacs-lisp
  230. (use-package evil-surround
  231. :config (global-evil-surround-mode 1))
  232. #+end_src
  233. https://github.com/redguardtoo/evil-nerd-commenter
  234. + Toggle comments with =M-;=
  235. #+begin_src emacs-lisp
  236. (use-package evil-nerd-commenter
  237. :bind ("M-;" . evilnc-comment-or-uncomment-lines))
  238. #+end_src
  239. **** Shortcuts
  240. Again cherry picked from =Doom=, I want to continue utilizing the muscle memory I have developed from a year of mainlining the framework.
  241. + Close buffers with =SPC c=
  242. + Find files with =SPC . (period)=
  243. + Switch buffers with =SPC , (comma)=
  244. #+begin_src emacs-lisp
  245. (dotfiles/leader
  246. "." '(find-file :which-key "Files")
  247. "," '(switch-to-buffer :which-key "Buffers")
  248. "c" '(kill-buffer-and-window :which-key "Close"))
  249. #+end_src
  250. Run helper functions with =SPC h=.
  251. + Packages =p=
  252. + Variables =v=
  253. + Functions =f=
  254. #+begin_src emacs-lisp
  255. (dotfiles/leader
  256. "h" '(:ignore t :which-key "Help")
  257. "hp" '(describe-package :which-key "Package")
  258. "hv" '(describe-variable :which-key "Variable")
  259. "hf" '(describe-function :which-key "Function"))
  260. #+end_src
  261. Quit emacs with =SPC q=.
  262. + Saving =q=
  263. + Without =w=
  264. + Frame (daemon) =f=
  265. #+begin_src emacs-lisp
  266. (dotfiles/leader
  267. "q" '(:ignore t :which-key "Quit")
  268. "qq" '(save-buffers-kill-emacs :which-key "Save")
  269. "qw" '(kill-emacs :which-key "Now")
  270. "qf" '(delete-frame :which-key "Frame"))
  271. #+end_src
  272. Window management with =SPC w=.
  273. + Swap with =w=
  274. + Close with =c=
  275. + Motions with =h,j,k,l=
  276. + Split with =s + <MOTION>=
  277. #+begin_src emacs-lisp
  278. (dotfiles/leader
  279. "w" '(:ignore t :which-key "Window")
  280. "ww" '(window-swap-states :which-key "Swap")
  281. "wc" '(delete-window :which-key "Close")
  282. "wh" '(windmove-left :which-key "Left")
  283. "wj" '(windmove-down :which-key "Down")
  284. "wk" '(windmove-up :which-key "Up")
  285. "wl" '(windmove-right :which-key "Right")
  286. "ws" '(:ignore t :which-key "Split")
  287. "wsj" '(split-window-below :which-key "Down")
  288. "wsl" '(split-window-right :which-key "Right"))
  289. #+end_src
  290. Place runtime tweaks behind =SPC t=.
  291. #+begin_src emacs-lisp
  292. (dotfiles/leader
  293. "t" '(:ignore t :which-key "Tweaks"))
  294. #+end_src
  295. *** Version control
  296. Another hallmark feature is [[https://github.com/magit/magit][Magit]], a complete git porcelain within Emacs.
  297. #+begin_src emacs-lisp
  298. (use-package magit
  299. :custom (magit-display-buffer-function
  300. #'magit-display-buffer-same-window-except-diff-v1))
  301. #+end_src
  302. Work directly with github issues / pull requests using [[https://github.com/magit/forge][Forge]].
  303. + Requires a valid ~$GITHUB_TOKEN~
  304. #+begin_src emacs-lisp
  305. (use-package forge)
  306. #+end_src
  307. Open the *status* page for the current repository with =SPC g=.
  308. #+begin_src emacs-lisp
  309. (dotfiles/leader
  310. "g" '(magit-status :which-key "Magit"))
  311. #+end_src
  312. *** Terminal emulation
  313. 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=.
  314. https://github.com/zwild/eshell-prompt-extras
  315. + Enable lambda shell prompt
  316. #+begin_src emacs-lisp
  317. (use-package eshell-prompt-extras
  318. :config (setq eshell-highlight-prompt nil
  319. eshell-prompt-function 'epe-theme-lambda))
  320. #+end_src
  321. Open an =eshell= buffer with =SPC e=.
  322. #+begin_src emacs-lisp
  323. (dotfiles/leader
  324. "e" '(eshell :which-key "Shell"))
  325. #+end_src
  326. *** File management
  327. 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.
  328. https://github.com/domtronn/all-the-icons.el
  329. + Collects various icon fonts
  330. #+begin_src emacs-lisp
  331. (use-package all-the-icons)
  332. #+end_src
  333. https://github.com/jtbm37/all-the-icons-dired
  334. + Integration with dired
  335. #+begin_src emacs-lisp
  336. (use-package all-the-icons-dired
  337. :hook (dired-mode . all-the-icons-dired-mode))
  338. #+end_src
  339. 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=.
  340. #+begin_src emacs-lisp
  341. (require 'dired-x)
  342. #+end_src
  343. 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.
  344. + Move up a directory with =h=
  345. + Open a single buffer with =l=
  346. #+begin_src emacs-lisp
  347. (use-package dired-single
  348. :config
  349. (evil-collection-define-key 'normal 'dired-mode-map
  350. "h" 'dired-single-up-directory
  351. "l" 'dired-single-buffer))
  352. #+end_src
  353. Open a dired buffer with =SPC d=.
  354. #+begin_src emacs-lisp
  355. (dotfiles/leader
  356. "d" '(dired-jump :which-key "Dired"))
  357. #+end_src
  358. ** Desktop
  359. :PROPERTIES:
  360. :header-args: :tangle ~/.local/source/dotfiles/modules/desktop.el :results silent
  361. :END:
  362. 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.
  363. *** Startup
  364. #+begin_src conf :tangle ~/.local/source/dotfiles/config/xinitrc
  365. exec dbus-launch --exit-with-session emacs -mm --debug-init
  366. #+end_src
  367. When launching into a session, if the display server is not running then =startx= should be invoked, to run the window manager.
  368. #+begin_src sh :tangle ~/.local/source/dotfiles/config/profile
  369. if [ -z "${DISPLAY}" ] && [ "${XDG_VTNR}" -eq 1 ]; then
  370. exec startx
  371. fi
  372. #+end_src
  373. *** Applications
  374. Define a method to run an external process, allowing us to launch any application on a new process without interferring with Emacs.
  375. #+begin_src emacs-lisp
  376. (defun dotfiles/run (command)
  377. "Run an external process."
  378. (interactive (list (read-shell-command "λ ")))
  379. (start-process-shell-command command nil command))
  380. #+end_src
  381. Some methods must be called and applied to the current call process in order to function correctly with Emacs hooks.
  382. #+begin_src emacs-lisp
  383. (defun dotfiles/run-in-background (command)
  384. (let ((command-parts (split-string command "[ ]+")))
  385. (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
  386. #+end_src
  387. + Run shell commands with =SPC x=
  388. + Run async shell commands with =SPC z=
  389. #+begin_src emacs-lisp
  390. (dotfiles/leader
  391. "x" '(dotfiles/run :which-key "Run")
  392. "z" '(async-shell-command :which-key "Async"))
  393. #+end_src
  394. *** Initialization
  395. When the window manager first launches the ~init-hook~ will be called, this allows us to define some custom logic when it's initialized.
  396. + Display time and date
  397. + Display battery info (if available)
  398. 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.
  399. #+begin_src emacs-lisp
  400. (defun dotfiles/init-hook ()
  401. (exwm-workspace-switch-create 1)
  402. (setq display-time-and-date t)
  403. (display-battery-mode 1)
  404. (display-time-mode 1))
  405. #+end_src
  406. *** Displays
  407. Using =autorandr= with pre configured profiles, switching screens (AKA hot plugging) is also handled through a hook.
  408. #+begin_src emacs-lisp
  409. (defun dotfiles/update-display ()
  410. (dotfiles/run-in-background "autorandr --change --force"))
  411. #+end_src
  412. *** Configuration
  413. Finally we configure the window manager.
  414. + Enable =randr= support
  415. 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.
  416. + Pass through to Emacs
  417. + =M-x= to Emacs
  418. + =C-g= to Emacs
  419. + =C-SPC= to Emacs
  420. + Bindings with =S= (Super / Win)
  421. + Reset =S-r=
  422. + Launch =S-&=
  423. + Workspace =S-[1..9]=
  424. #+begin_src emacs-lisp
  425. (use-package exwm
  426. :config
  427. (require 'exwm-randr)
  428. (exwm-randr-enable)
  429. (add-hook 'exwm-init-hook #'dotfiles/init-hook)
  430. (add-hook 'exwm-randr-screen-change-hook #'dotfiles/update-display)
  431. (dotfiles/update-display)
  432. (setq exwm-input-prefix-keys
  433. '(?\M-x
  434. ?\C-g
  435. ?\C-\ )
  436. exwm-input-global-keys
  437. `(([?\s-r] . exwm-reset)
  438. ([?\s-&] . dotfiles/run)
  439. ,@(mapcar (lambda (i)
  440. `(,(kbd (format "s-%d" i)) .
  441. (lambda ()
  442. (interactive)
  443. (exwm-workspace-switch-create ,i))))
  444. (number-sequence 1 9))))
  445. (exwm-enable))
  446. #+end_src
  447. ** Writing
  448. :PROPERTIES:
  449. :header-args: :tangle ~/.local/source/dotfiles/modules/writing.el :results silent
  450. :END:
  451. 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*.
  452. #+begin_src emacs-lisp
  453. (use-package org-superstar
  454. :hook (org-mode . org-superstar-mode))
  455. #+end_src
  456. 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.
  457. #+begin_src emacs-lisp
  458. (use-package ox-hugo
  459. :after ox)
  460. #+end_src
  461. 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=.
  462. #+begin_src emacs-lisp
  463. (use-package ox-reveal
  464. :after ox
  465. :custom (org-reveal-root "https://cdn.jsdelivr.net/npm/reveal.js"))
  466. #+end_src
  467. *** Roam
  468. Download and install [[https://orgroam.com][org-roam]], a plain text knowledge management system for Emacs.
  469. #+begin_src emacs-lisp
  470. (use-package org-roam
  471. :hook (after-init . org-roam-mode)
  472. :custom
  473. (org-roam-directory org-directory)
  474. (org-roam-encrypt-files t))
  475. #+end_src
  476. Visualize the org-roam database with the server, available when the editor is running at http://localhost:8080
  477. #+begin_src emacs-lisp
  478. (use-package org-roam-server
  479. :hook (org-roam-mode . org-roam-server-mode))
  480. #+end_src
  481. Place keybindings behind =SPC r=.
  482. + Find with =f=
  483. + Toggle buffer with =b=
  484. + Dailies with =d=
  485. + Arbitrary date with =d=
  486. + Today with =t=
  487. + Tomorrow with =m=
  488. + Yesterday with =y=
  489. #+begin_src emacs-lisp
  490. (dotfiles/leader
  491. "r" '(:ignore t :which-key "Roam")
  492. "rf" '(org-roam-find-file :which-key "Find")
  493. "rb" '(org-roam-buffer-toggle-display :which-key "Buffer")
  494. "rd" '(:ignore t :which-key "Dailies")
  495. "rdd" '(org-roam-dailies-find-date :which-key "Date")
  496. "rdt" '(org-roam-dailies-find-today :which-key "Today")
  497. "rdm" '(org-roam-dailies-find-tomorrow :which-key "Tomorrow")
  498. "rdy" '(org-roam-dailies-find-yesterday :which-key "Yesterday"))
  499. #+end_src
  500. Organize the capture templates, this allows me to quickly dictate where each new item should be placed.
  501. + ~posts/~ contains blog posts
  502. + ~notes/~ contains cited notes on others' work
  503. + ~slides/~ contains presentations / screencasts
  504. #+begin_src emacs-lisp
  505. (setq org-roam-capture-templates
  506. '(("p" "Posts" plain (function org-roam-capture--get-point)
  507. "%?"
  508. :file-name "docs/posts/${slug}"
  509. :unnarrowed t
  510. :head
  511. "
  512. ,#+TITLE: ${title}
  513. ,#+AUTHOR: Christopher James Hayward
  514. ,#+DATE: %<%Y-%m-%d>
  515. ,#+EXPORT_FILE_NAME: ${slug}
  516. ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  517. ,#+HUGO_BASE_DIR: ../../website/
  518. ,#+HUGO_AUTO_SET_LASTMOD: t
  519. ,#+HUGO_SECTION: posts
  520. ,#+HUGO_DRAFT: true
  521. ")
  522. ("n" "Notes" plain (function org-roam-capture--get-point)
  523. "%?"
  524. :file-name "docs/notes/${slug}"
  525. :unnarrowed t
  526. :head
  527. "
  528. ,#+TITLE: ${title}
  529. ,#+AUTHOR: Christopher James Hayward
  530. ,#+EXPORT_FILE_NAME: ${slug}
  531. ,#+ROAM_KEY: https://chrishayward.xyz/notes/${slug}/
  532. ,#+HUGO_BASE_DIR: ../../website
  533. ,#+HUGO_AUTO_SET_LASTMOD: t
  534. ,#+HUGO_SECTION: notes
  535. ,#+HUGO_DRAFT: true
  536. ")
  537. ("s" "Slides" plain (function org-roam-capture--get-point)
  538. "%?"
  539. :file-name "docs/slides/${slug}"
  540. :unnarrowed t
  541. :head
  542. "
  543. ,#+TITLE: ${title}
  544. ,#+AUTHOR: Christopher James Hayward
  545. ,#+REVEAL_ROOT: https://cdn.jsdelivr.net/npm/reveal.js
  546. ")))
  547. #+end_src
  548. By default I want my daily notes to live in ~daily/~ relative to my dotfiles.
  549. #+begin_src emacs-lisp
  550. (setq org-roam-dailies-capture-templates
  551. '(("d" "Default" entry (function org-roam-capture--get-point)
  552. "* %?"
  553. :file-name "docs/daily/%<%Y-%m-%d>"
  554. :head
  555. "
  556. ,#+TITLE: %<%Y-%m-%d>
  557. ,#+AUTHOR: Christopher James Hayward
  558. ")))
  559. #+end_src
  560. *** Email
  561. 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.
  562. #+begin_src conf :tangle ~/.local/source/dotfiles/config/mbsyncrc
  563. IMAPStore xyz-remote
  564. Host mail.chrishayward.xyz
  565. User chris@chrishayward.xyz
  566. PassCmd "pass chrishayward.xyz/chris"
  567. SSLType IMAPS
  568. MaildirStore xyz-local
  569. Path ~/.cache/mail/
  570. Inbox ~/.cache/mail/inbox
  571. SubFolders Verbatim
  572. Channel xyz
  573. Master :xyz-remote:
  574. Slave :xyz-local:
  575. Patterns * !Archives
  576. Create Both
  577. Expunge Both
  578. SyncState *
  579. #+end_src
  580. 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.
  581. #+begin_src shell :tangle no
  582. mbsync -a
  583. mu index --maildir="~/.cache/mail"
  584. #+end_src
  585. Once the mail is being synchronized, and the mail has been indexed with =mu=, it's time to install the required packages for Emacs.
  586. #+begin_src emacs-lisp
  587. (use-package mu4e
  588. :load-path "/usr/share/emacs/site-lisp/mu4e"
  589. :config
  590. (setq mu4e-change-filenames-when-moving t
  591. mu4e-update-interval (* 5 60) ;; Every 5 minutes.
  592. mu4e-get-mail-command "mbsync -a"
  593. mu4e-maildir "~/.cache/mail"
  594. mu4e-compose-signature
  595. (concat "Chris Hayward\n"
  596. "https://chrishayward.xyz\n"))
  597. ;; Ensure plain text scales for all devices.
  598. (setq mu4e-compose-format-flowed t)
  599. ;; GPG signing key for outbound mail.
  600. (setq mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  601. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  602. (setq message-send-mail-function 'smtpmail-send-it)
  603. ;; Configure mail account(s).
  604. (setq mu4e-contexts
  605. (list
  606. ;; Main
  607. ;; chris@chrishayward.xyz
  608. (make-mu4e-context
  609. :name "Main"
  610. :match-func
  611. (lambda (msg)
  612. (when msg
  613. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  614. :vars
  615. '((user-full-name . "Christopher James Hayward")
  616. (user-mail-address . "chris@chrishayward.xyz")
  617. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  618. (smtpmail-smtp-service . 587)
  619. (smtpmail-stream-type . starttls))))))
  620. #+end_src
  621. Use [[https://github.com/iqbalansari/mu4e-alert][mu4e-alert]] to give us desktop notifications about incoming mail.
  622. #+begin_src emacs-lisp
  623. (use-package mu4e-alert
  624. :custom
  625. (mu4e-alert-set-default-style 'libnotify)
  626. :config
  627. (mu4e-alert-enable-notifications)
  628. (mu4e-alert-enable-mode-line-display))
  629. #+end_src
  630. Create a keybinding to open the mail dashboard with =SPC m=.
  631. #+begin_src emacs-lisp
  632. (dotfiles/leader
  633. "m" '(mu4e :which-key "Mail"))
  634. #+end_src
  635. *** Agenda
  636. Override ~org-agenda-file-regexp~ to include =.org.gpg= files.
  637. #+begin_src emacs-lisp
  638. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  639. (setq org-agenda-file-regexp
  640. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  641. org-agenda-file-regexp)))
  642. #+end_src
  643. Configure agenda sources.
  644. #+begin_src emacs-lisp
  645. (setq org-agenda-files '("~/.emacs.d/docs/"
  646. "~/.emacs.d/docs/daily/"))
  647. #+end_src
  648. Open an agenda buffer with =SPC a=.
  649. #+begin_src emacs-lisp
  650. (dotfiles/leader
  651. "a" '(org-agenda :which-key "Agenda"))
  652. #+end_src
  653. *** Images
  654. Create screencasts with =one-frame-per-action= GIF recording via [[https://github.com/takaxp/emacs-gif-screencast][emacs-gif-screencast]].
  655. + Can be paused / resumed
  656. + High quality images
  657. + Optimized size
  658. It requires the installation of ~scrot~, ~gifsicle~, and ~convert~ from the =ImageMagick= library.
  659. #+begin_src emacs-lisp
  660. (use-package gif-screencast
  661. :custom
  662. (gif-screencast-output-directory (concat dotfiles/home "docs/images/")))
  663. #+end_src
  664. Screencast controls behind =SPC s=.
  665. + Start / stop with =s=
  666. + Pause with =t=
  667. #+begin_src emacs-lisp
  668. (dotfiles/leader
  669. "s" '(:ignore t :which-key "Screencast")
  670. "ss" '(gif-screencast-start-or-stop :which-key "Start / Stop")
  671. "sp" '(gif-screencast-toggle-pause :which-key "Pause"))
  672. #+end_src
  673. ** Projects
  674. :PROPERTIES:
  675. :header-args: :tangle ~/.local/source/dotfiles/modules/projects.el :results silent
  676. :END:
  677. An IDE like experience (or better) can be achieved in Emacs using two *Microsoft* open source initiatives.
  678. 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.
  679. [[https://emacs-lsp.github.io/lsp-mode/][Lsp-mode]] brings support for language servers into Emacs.
  680. #+begin_src emacs-lisp
  681. (use-package lsp-mode
  682. :custom (gc-cons-threshold 1000000000)
  683. (lsp-idle-delay 0.500))
  684. #+end_src
  685. https://emacs-lsp.github.io/lsp-ui/
  686. + UI improvements for =lsp-mode=
  687. #+begin_src emacs-lisp
  688. (use-package lsp-ui
  689. :custom (lsp-ui-doc-position 'at-point)
  690. (lsp-ui-doc-delay 0.500))
  691. #+end_src
  692. *** Management
  693. 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.
  694. #+begin_src emacs-lisp
  695. (use-package projectile
  696. :config
  697. (setq projectile-project-search-path '("~/.local/source"))
  698. (projectile-mode))
  699. #+end_src
  700. *** Passwords
  701. 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.
  702. #+begin_src emacs-lisp
  703. (use-package password-store
  704. :custom (password-store-dir dotfiles/passwords))
  705. #+end_src
  706. Configure keybindings behind =SPC p=.
  707. + Copy with =p=
  708. + Rename with =r=
  709. + Generate with =g=
  710. #+begin_src emacs-lisp
  711. (dotfiles/leader
  712. "p" '(:ignore t :which-key "Passwords")
  713. "pp" '(password-store-copy :which-key "Copy")
  714. "pr" '(password-store-rename :which-key "Rename")
  715. "pg" '(password-store-generate :which-key "Generate"))
  716. #+end_src
  717. *** Debugging
  718. Handled through the [[https://microsoft.github.io/debug-adapter-protocol/][Debug Adapter Protocol]], an open source initiative from *Microsoft* for the *VSCode* editor.
  719. [[https://emacs-lsp.github.io/dap-mode/][Dap-mode]] adds support for the protocol to Emacs.
  720. #+begin_src emacs-lisp
  721. (use-package dap-mode)
  722. #+end_src
  723. *** Completion
  724. Text completion framework via =company= aka *Complete Anything*.
  725. http://company-mode.github.io/
  726. + Integrate with =lsp-mode=
  727. #+begin_src emacs-lisp
  728. (use-package company)
  729. (use-package company-lsp)
  730. #+end_src
  731. *** Languages
  732. Support for individual languages are implemented here.
  733. **** C/C++
  734. Install the [[https://github.com/MaskRay/ccls][ccls]] language server.
  735. #+begin_src emacs-lisp
  736. (use-package ccls
  737. :hook ((c-mode c++-mode objc-mode cuda-mode) .
  738. (lambda () (require 'ccls) (lsp))))
  739. #+end_src
  740. **** Python
  741. Install the =pyls= language server.
  742. #+begin_src shell :tangle no
  743. pip install --user "python-language-server[all]"
  744. #+end_src
  745. [[https://www.emacswiki.org/emacs/PythonProgrammingInEmacs][python-mode]] is an Emacs built in mode.
  746. #+begin_src emacs-lisp
  747. (use-package python-mode
  748. :hook (python-mode . lsp)
  749. :config (require 'dap-python)
  750. :custom (python-shell-interpreter "python3") ;; Required if "python" is not python 3.
  751. (dap-python-executable "python3") ;; Same as above.
  752. (dap-python-debugger 'debugpy))
  753. #+end_src
  754. **** Go
  755. Install the =gopls= language server.
  756. #+begin_src sh :tangle no
  757. GO111MODULE=on go get golang.org/x/tools/gopls@latest
  758. #+end_src
  759. Set the ~GOPATH~ environment variable prior to loading, this allows us to change the default value of ~$HOME/go~ to ~$HOME/.go~.
  760. #+begin_src emacs-lisp
  761. (setenv "GOPATH" (concat (getenv "HOME") "/.go/"))
  762. #+end_src
  763. Additionally, include the =bin= subdirectory of the ~$GOPATH~ in the ~$PATH~ variable, adding compiled golang programs.
  764. #+begin_src emacs-lisp
  765. (setenv "PATH" (concat (getenv "GOPATH") "bin:" (getenv "PATH")))
  766. #+end_src
  767. Finally we can include the =go-mode= package, integrating it with =lsp=.
  768. #+begin_src emacs-lisp
  769. (use-package go-mode
  770. :hook (go-mode . lsp))
  771. #+end_src
  772. Apply some custom behaviour before saving:
  773. + Format buffer
  774. + Organize imports
  775. #+begin_src emacs-lisp
  776. (defun dotfiles/go-hook ()
  777. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  778. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  779. #+end_src
  780. #+begin_src emacs-lisp
  781. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  782. #+end_src
  783. ** Interface
  784. :PROPERTIES:
  785. :header-args: :tangle ~/.local/source/dotfiles/modules/interface.el :results silent
  786. :END:
  787. *Bring Emacs out of the eighties*
  788. *** Fonts
  789. 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.
  790. #+begin_src emacs-lisp
  791. (defvar dotfiles/font "Fira Code")
  792. (defvar dotfiles/font-size 96)
  793. #+end_src
  794. Write out to all *3* of Emacs' default font faces.
  795. #+begin_src emacs-lisp
  796. (set-face-attribute 'default nil :font dotfiles/font :height dotfiles/font-size)
  797. (set-face-attribute 'fixed-pitch nil :font dotfiles/font :height dotfiles/font-size)
  798. (set-face-attribute 'variable-pitch nil :font dotfiles/font :height dotfiles/font-size)
  799. #+end_src
  800. Define a transient keybinding for scaling the text.
  801. #+begin_src emacs-lisp
  802. (defhydra hydra-text-scale (:timeout 4)
  803. "Scale"
  804. ("j" text-scale-increase "Increase")
  805. ("k" text-scale-decrease "Decrease")
  806. ("f" nil "Finished" :exit t))
  807. #+end_src
  808. Increase the font size in buffers with =SPC t f=.
  809. + Increase =j=
  810. + Decrease =k=
  811. + Finish =f=
  812. #+begin_src emacs-lisp
  813. (dotfiles/leader
  814. "tf" '(hydra-text-scale/body :which-key "Font"))
  815. #+end_src
  816. *** Lines
  817. 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.
  818. #+begin_example
  819. 5:
  820. 4:
  821. 3:
  822. 2:
  823. 1:
  824. 156: << CURRENT LINE >>
  825. 1:
  826. 2:
  827. 3:
  828. 4:
  829. 5:
  830. #+end_example
  831. https://github.com/emacsmirror/linum-relative
  832. + Integrate with ~display-line-numbers-mode~ for performance
  833. #+begin_src emacs-lisp
  834. (use-package linum-relative
  835. :init (setq linum-relative-backend
  836. 'display-line-numbers-mode)
  837. :config (linum-relative-global-mode))
  838. #+end_src
  839. Add line numbers to the toggles behind =SPC t l=.
  840. #+begin_src emacs-lisp
  841. (dotfiles/leader
  842. "tl" '(linum-relative-global-mode :which-key "Lines"))
  843. #+end_src
  844. https://github.com/Fanael/rainbow-delimiters
  845. + Colourize nested parenthesis
  846. #+begin_src emacs-lisp
  847. (use-package rainbow-delimiters
  848. :hook (prog-mode . rainbow-delimiters-mode))
  849. #+end_src
  850. *** Themes
  851. 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.
  852. #+begin_src emacs-lisp
  853. (use-package doom-themes
  854. :init (load-theme 'doom-moonlight t))
  855. #+end_src
  856. [[https://github.com/seagle0128/doom-modeline][doom-modeline]] provides an elegant status bar / modeline.
  857. #+begin_src emacs-lisp
  858. (use-package doom-modeline
  859. :init (doom-modeline-mode 1)
  860. :custom ((doom-modeline-height 16)))
  861. #+end_src
  862. Load a theme with =SPC t t=.
  863. #+begin_src emacs-lisp
  864. (dotfiles/leader
  865. "tt" '(load-theme t t :which-key "Theme"))
  866. #+end_src
  867. *** Ligatures
  868. 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.
  869. #+begin_src emacs-lisp
  870. (use-package fira-code-mode
  871. :hook (prog-mode org-mode))
  872. #+end_src
  873. Toggle global ligature mode with =SPC t g=.
  874. #+begin_src emacs-lisp
  875. (dotfiles/leader
  876. "tg" '(global-fira-code-mode :which-key "Ligatures"))
  877. #+end_src
  878. *** Dashboard
  879. Present a dashboard when first launching Emacs.
  880. #+begin_src emacs-lisp
  881. (use-package dashboard
  882. :config
  883. (setq dashboard-center-content t
  884. dashboard-set-init-info t
  885. dashboard-set-file-icons t
  886. dashboard-set-heading-icons t
  887. dashboard-set-navigator t
  888. dashboard-startup-banner 'logo
  889. dashboard-projects-backend 'projectile
  890. dashboard-items '((projects . 5)
  891. (recents . 5)
  892. (agenda . 5 )))
  893. (dashboard-setup-startup-hook))
  894. #+end_src
  895. Customize the buttons of the navigator:
  896. + Brain @ http://localhost:8080
  897. + Homepage @ https://chrishayward.xyz
  898. + Athabasca @ https://login.athabascau.ca/cas/login
  899. + Bookshelf @ https://online.vitalsource.com
  900. #+begin_src emacs-lisp
  901. (setq dashboard-navigator-buttons
  902. `(;; First row.
  903. ((,(all-the-icons-fileicon "brain" :height 1.1 :v-adjust 0.0)
  904. "Brain"
  905. "Knowledge base"
  906. (lambda (&rest _) (browse-url "http://localhost:8080"))))
  907. ;; Second row.
  908. ((,(all-the-icons-material "public" :height 1.1 :v-adjust 0.0)
  909. "Homepage"
  910. "Personal website"
  911. (lambda (&rest _) (browse-url "https://chrishayward.xyz"))))
  912. ;; Third row.
  913. ((,(all-the-icons-faicon "university" :height 1.1 :v-adjust 0.0)
  914. "Athabasca"
  915. "Univeristy login"
  916. (lambda (&rest _) (browse-url "https://login.athabascau.ca/cas/login"))))
  917. ;; Fourth row.
  918. ((,(all-the-icons-faicon "book" :height 1.1 :v-adjust 0.0)
  919. "Bookshelf"
  920. "Vitalsource bookshelf"
  921. (lambda (&rest _) (browse-url "https://online.vitalsource.com"))))))
  922. #+end_src
  923. When running in *daemon* mode, ensure that the dashboard is the initial buffer.
  924. #+begin_src emacs-lisp
  925. (setq initial-buffer-choice
  926. (lambda ()
  927. (get-buffer "*dashboard*")))
  928. #+end_src