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.

1207 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
  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. ,#+ROAM_KEY: https://chrishayward.xyz/posts/${slug}/
  516. ,#+HUGO_BASE_DIR: ~/.local/source/website
  517. ,#+HUGO_AUTO_SET_LASTMOD: t
  518. ,#+HUGO_SECTION: posts
  519. ")
  520. ("n" "Notes" plain (function org-roam-capture--get-point)
  521. "%?"
  522. :file-name "docs/notes/${slug}"
  523. :unnarrowed t
  524. :head
  525. "
  526. ,#+TITLE: ${title}
  527. ,#+AUTHOR: Christopher James Hayward
  528. ,#+ROAM_KEY: https://chrishayward.xyz/notes/${slug}/
  529. ,#+HUGO_BASE_DIR: ~/.local/source/website
  530. ,#+HUGO_AUTO_SET_LASTMOD: t
  531. ,#+HUGO_SECTION: notes
  532. ")
  533. ("s" "Slides" plain (function org-roam-capture--get-point)
  534. "%?"
  535. :file-name "docs/slides/${slug}"
  536. :unnarrowed t
  537. :head
  538. "
  539. ,#+TITLE: ${title}
  540. ,#+AUTHOR: Christopher James Hayward
  541. ,#+REVEAL_ROOT: https://cdn.jsdelivr.net/npm/reveal.js
  542. ")))
  543. #+end_src
  544. By default I want my daily notes to live in ~daily/~ relative to my dotfiles.
  545. #+begin_src emacs-lisp
  546. (setq org-roam-dailies-capture-templates
  547. '(("d" "Default" entry (function org-roam-capture--get-point)
  548. "* %?"
  549. :file-name "docs/daily/%<%Y-%m-%d>"
  550. :head
  551. "
  552. ,#+TITLE: %<%Y-%m-%d>
  553. ,#+AUTHOR: Christopher James Hayward
  554. ")))
  555. #+end_src
  556. *** Email
  557. 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.
  558. #+begin_src conf :tangle ~/.local/source/dotfiles/config/mbsyncrc
  559. IMAPStore xyz-remote
  560. Host mail.chrishayward.xyz
  561. User chris@chrishayward.xyz
  562. PassCmd "pass chrishayward.xyz/chris"
  563. SSLType IMAPS
  564. MaildirStore xyz-local
  565. Path ~/.cache/mail/
  566. Inbox ~/.cache/mail/inbox
  567. SubFolders Verbatim
  568. Channel xyz
  569. Master :xyz-remote:
  570. Slave :xyz-local:
  571. Patterns * !Archives
  572. Create Both
  573. Expunge Both
  574. SyncState *
  575. #+end_src
  576. 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.
  577. #+begin_src shell :tangle no
  578. mbsync -a
  579. mu index --maildir="~/.cache/mail"
  580. #+end_src
  581. Once the mail is being synchronized, and the mail has been indexed with =mu=, it's time to install the required packages for Emacs.
  582. #+begin_src emacs-lisp
  583. (use-package mu4e
  584. :load-path "/usr/share/emacs/site-lisp/mu4e"
  585. :config
  586. (setq mu4e-change-filenames-when-moving t
  587. mu4e-update-interval (* 5 60) ;; Every 5 minutes.
  588. mu4e-get-mail-command "mbsync -a"
  589. mu4e-maildir "~/.cache/mail"
  590. mu4e-compose-signature
  591. (concat "Chris Hayward\n"
  592. "https://chrishayward.xyz\n"))
  593. ;; Ensure plain text scales for all devices.
  594. (setq mu4e-compose-format-flowed t)
  595. ;; GPG signing key for outbound mail.
  596. (setq mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  597. (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)
  598. (setq message-send-mail-function 'smtpmail-send-it)
  599. ;; Configure mail account(s).
  600. (setq mu4e-contexts
  601. (list
  602. ;; Main
  603. ;; chris@chrishayward.xyz
  604. (make-mu4e-context
  605. :name "Main"
  606. :match-func
  607. (lambda (msg)
  608. (when msg
  609. (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
  610. :vars
  611. '((user-full-name . "Christopher James Hayward")
  612. (user-mail-address . "chris@chrishayward.xyz")
  613. (smtpmail-smtp-server . "mail.chrishayward.xyz")
  614. (smtpmail-smtp-service . 587)
  615. (smtpmail-stream-type . starttls))))))
  616. #+end_src
  617. Use [[https://github.com/iqbalansari/mu4e-alert][mu4e-alert]] to give us desktop notifications about incoming mail.
  618. #+begin_src emacs-lisp
  619. (use-package mu4e-alert
  620. :custom
  621. (mu4e-alert-set-default-style 'libnotify)
  622. :config
  623. (mu4e-alert-enable-notifications)
  624. (mu4e-alert-enable-mode-line-display))
  625. #+end_src
  626. Create a keybinding to open the mail dashboard with =SPC m=.
  627. #+begin_src emacs-lisp
  628. (dotfiles/leader
  629. "m" '(mu4e :which-key "Mail"))
  630. #+end_src
  631. *** Agenda
  632. Override ~org-agenda-file-regexp~ to include =.org.gpg= files.
  633. #+begin_src emacs-lisp
  634. (unless (string-match-p "\\.gpg" org-agenda-file-regexp)
  635. (setq org-agenda-file-regexp
  636. (replace-regexp-in-string "\\\\\\.org" "\\\\.org\\\\(\\\\.gpg\\\\)?"
  637. org-agenda-file-regexp)))
  638. #+end_src
  639. Configure agenda sources.
  640. #+begin_src emacs-lisp
  641. (setq org-agenda-files '("~/.local/source/secrets/org/"
  642. "~/.local/source/dotfiles/docs/daily/"))
  643. #+end_src
  644. Open an agenda buffer with =SPC a=.
  645. #+begin_src emacs-lisp
  646. (dotfiles/leader
  647. "a" '(org-agenda :which-key "Agenda"))
  648. #+end_src
  649. *** Images
  650. Create screencasts with =one-frame-per-action= GIF recording via [[https://github.com/takaxp/emacs-gif-screencast][emacs-gif-screencast]].
  651. + Can be paused / resumed
  652. + High quality images
  653. + Optimized size
  654. It requires the installation of ~scrot~, ~gifsicle~, and ~convert~ from the =ImageMagick= library.
  655. #+begin_src emacs-lisp
  656. (use-package gif-screencast
  657. :custom
  658. (gif-screencast-output-directory (concat dotfiles/home "docs/images/")))
  659. #+end_src
  660. Screencast controls behind =SPC s=.
  661. + Start / stop with =s=
  662. + Pause with =t=
  663. #+begin_src emacs-lisp
  664. (dotfiles/leader
  665. "s" '(:ignore t :which-key "Screencast")
  666. "ss" '(gif-screencast-start-or-stop :which-key "Start / Stop")
  667. "sp" '(gif-screencast-toggle-pause :which-key "Pause"))
  668. #+end_src
  669. ** Projects
  670. :PROPERTIES:
  671. :header-args: :tangle ~/.local/source/dotfiles/modules/projects.el :results silent
  672. :END:
  673. An IDE like experience (or better) can be achieved in Emacs using two *Microsoft* open source initiatives.
  674. 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.
  675. [[https://emacs-lsp.github.io/lsp-mode/][Lsp-mode]] brings support for language servers into Emacs.
  676. #+begin_src emacs-lisp
  677. (use-package lsp-mode
  678. :custom (gc-cons-threshold 1000000000)
  679. (lsp-idle-delay 0.500))
  680. #+end_src
  681. https://emacs-lsp.github.io/lsp-ui/
  682. + UI improvements for =lsp-mode=
  683. #+begin_src emacs-lisp
  684. (use-package lsp-ui
  685. :custom (lsp-ui-doc-position 'at-point)
  686. (lsp-ui-doc-delay 0.500))
  687. #+end_src
  688. *** Management
  689. 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.
  690. #+begin_src emacs-lisp
  691. (use-package projectile
  692. :config
  693. (setq projectile-project-search-path '("~/.local/source"))
  694. (projectile-mode))
  695. #+end_src
  696. *** Passwords
  697. 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.
  698. #+begin_src emacs-lisp
  699. (use-package password-store
  700. :custom (password-store-dir dotfiles/passwords))
  701. #+end_src
  702. Configure keybindings behind =SPC p=.
  703. + Copy with =p=
  704. + Rename with =r=
  705. + Generate with =g=
  706. #+begin_src emacs-lisp
  707. (dotfiles/leader
  708. "p" '(:ignore t :which-key "Passwords")
  709. "pp" '(password-store-copy :which-key "Copy")
  710. "pr" '(password-store-rename :which-key "Rename")
  711. "pg" '(password-store-generate :which-key "Generate"))
  712. #+end_src
  713. *** Debugging
  714. Handled through the [[https://microsoft.github.io/debug-adapter-protocol/][Debug Adapter Protocol]], an open source initiative from *Microsoft* for the *VSCode* editor.
  715. [[https://emacs-lsp.github.io/dap-mode/][Dap-mode]] adds support for the protocol to Emacs.
  716. #+begin_src emacs-lisp
  717. (use-package dap-mode)
  718. #+end_src
  719. *** Completion
  720. Text completion framework via =company= aka *Complete Anything*.
  721. http://company-mode.github.io/
  722. + Integrate with =lsp-mode=
  723. #+begin_src emacs-lisp
  724. (use-package company)
  725. (use-package company-lsp)
  726. #+end_src
  727. *** Languages
  728. Support for individual languages are implemented here.
  729. **** C/C++
  730. Install the [[https://github.com/MaskRay/ccls][ccls]] language server.
  731. #+begin_src emacs-lisp
  732. (use-package ccls
  733. :hook ((c-mode c++-mode objc-mode cuda-mode) .
  734. (lambda () (require 'ccls) (lsp))))
  735. #+end_src
  736. **** Python
  737. Install the =pyls= language server.
  738. #+begin_src shell :tangle no
  739. pip install --user "python-language-server[all]"
  740. #+end_src
  741. [[https://www.emacswiki.org/emacs/PythonProgrammingInEmacs][python-mode]] is an Emacs built in mode.
  742. #+begin_src emacs-lisp
  743. (use-package python-mode
  744. :hook (python-mode . lsp)
  745. :config (require 'dap-python)
  746. :custom (python-shell-interpreter "python3") ;; Required if "python" is not python 3.
  747. (dap-python-executable "python3") ;; Same as above.
  748. (dap-python-debugger 'debugpy))
  749. #+end_src
  750. **** Go
  751. Install the =gopls= language server.
  752. #+begin_src sh :tangle no
  753. GO111MODULE=on go get golang.org/x/tools/gopls@latest
  754. #+end_src
  755. Set the ~GOPATH~ environment variable prior to loading, this allows us to change the default value of ~$HOME/go~ to ~$HOME/.go~.
  756. #+begin_src emacs-lisp
  757. (setenv "GOPATH" (concat (getenv "HOME") "/.go/"))
  758. #+end_src
  759. Additionally, include the =bin= subdirectory of the ~$GOPATH~ in the ~$PATH~ variable, adding compiled golang programs.
  760. #+begin_src emacs-lisp
  761. (setenv "PATH" (concat (getenv "GOPATH") "bin:" (getenv "PATH")))
  762. #+end_src
  763. Finally we can include the =go-mode= package, integrating it with =lsp=.
  764. #+begin_src emacs-lisp
  765. (use-package go-mode
  766. :hook (go-mode . lsp))
  767. #+end_src
  768. Apply some custom behaviour before saving:
  769. + Format buffer
  770. + Organize imports
  771. #+begin_src emacs-lisp
  772. (defun dotfiles/go-hook ()
  773. (add-hook 'before-save-hook #'lsp-format-buffer t t)
  774. (add-hook 'before-save-hook #'lsp-organize-imports t t))
  775. #+end_src
  776. #+begin_src emacs-lisp
  777. (add-hook 'go-mode-hook #'dotfiles/go-hook)
  778. #+end_src
  779. ** Interface
  780. :PROPERTIES:
  781. :header-args: :tangle ~/.local/source/dotfiles/modules/interface.el :results silent
  782. :END:
  783. *Bring Emacs out of the eighties*
  784. *** Fonts
  785. 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.
  786. #+begin_src emacs-lisp
  787. (defvar dotfiles/font "Fira Code")
  788. (defvar dotfiles/font-size 96)
  789. #+end_src
  790. Write out to all *3* of Emacs' default font faces.
  791. #+begin_src emacs-lisp
  792. (set-face-attribute 'default nil :font dotfiles/font :height dotfiles/font-size)
  793. (set-face-attribute 'fixed-pitch nil :font dotfiles/font :height dotfiles/font-size)
  794. (set-face-attribute 'variable-pitch nil :font dotfiles/font :height dotfiles/font-size)
  795. #+end_src
  796. Define a transient keybinding for scaling the text.
  797. #+begin_src emacs-lisp
  798. (defhydra hydra-text-scale (:timeout 4)
  799. "Scale"
  800. ("j" text-scale-increase "Increase")
  801. ("k" text-scale-decrease "Decrease")
  802. ("f" nil "Finished" :exit t))
  803. #+end_src
  804. Increase the font size in buffers with =SPC t f=.
  805. + Increase =j=
  806. + Decrease =k=
  807. + Finish =f=
  808. #+begin_src emacs-lisp
  809. (dotfiles/leader
  810. "tf" '(hydra-text-scale/body :which-key "Font"))
  811. #+end_src
  812. *** Lines
  813. 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.
  814. #+begin_example
  815. 5:
  816. 4:
  817. 3:
  818. 2:
  819. 1:
  820. 156: << CURRENT LINE >>
  821. 1:
  822. 2:
  823. 3:
  824. 4:
  825. 5:
  826. #+end_example
  827. https://github.com/emacsmirror/linum-relative
  828. + Integrate with ~display-line-numbers-mode~ for performance
  829. #+begin_src emacs-lisp
  830. (use-package linum-relative
  831. :init (setq linum-relative-backend
  832. 'display-line-numbers-mode)
  833. :config (linum-relative-global-mode))
  834. #+end_src
  835. Add line numbers to the toggles behind =SPC t l=.
  836. #+begin_src emacs-lisp
  837. (dotfiles/leader
  838. "tl" '(linum-relative-global-mode :which-key "Lines"))
  839. #+end_src
  840. https://github.com/Fanael/rainbow-delimiters
  841. + Colourize nested parenthesis
  842. #+begin_src emacs-lisp
  843. (use-package rainbow-delimiters
  844. :hook (prog-mode . rainbow-delimiters-mode))
  845. #+end_src
  846. *** Themes
  847. 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.
  848. #+begin_src emacs-lisp
  849. (use-package doom-themes
  850. :init (load-theme 'doom-moonlight t))
  851. #+end_src
  852. [[https://github.com/seagle0128/doom-modeline][doom-modeline]] provides an elegant status bar / modeline.
  853. #+begin_src emacs-lisp
  854. (use-package doom-modeline
  855. :init (doom-modeline-mode 1)
  856. :custom ((doom-modeline-height 16)))
  857. #+end_src
  858. Load a theme with =SPC t t=.
  859. #+begin_src emacs-lisp
  860. (dotfiles/leader
  861. "tt" '(load-theme t t :which-key "Theme"))
  862. #+end_src
  863. *** Ligatures
  864. 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.
  865. #+begin_src emacs-lisp
  866. (use-package fira-code-mode
  867. :hook (prog-mode org-mode))
  868. #+end_src
  869. Toggle global ligature mode with =SPC t g=.
  870. #+begin_src emacs-lisp
  871. (dotfiles/leader
  872. "tg" '(global-fira-code-mode :which-key "Ligatures"))
  873. #+end_src
  874. *** Dashboard
  875. Present a dashboard when first launching Emacs.
  876. #+begin_src emacs-lisp
  877. (use-package dashboard
  878. :config
  879. (setq dashboard-center-content t
  880. dashboard-set-init-info t
  881. dashboard-set-file-icons t
  882. dashboard-set-heading-icons t
  883. dashboard-set-navigator t
  884. dashboard-startup-banner 'logo
  885. dashboard-projects-backend 'projectile
  886. dashboard-items '((projects . 5)
  887. (recents . 5)
  888. (agenda . 5 )))
  889. (dashboard-setup-startup-hook))
  890. #+end_src
  891. Customize the buttons of the navigator:
  892. +  Brain @ http://localhost:8080
  893. +  Homepage @ https://chrishayward.xyz
  894. +  Athabasca @ https://login.athabascau.ca/cas/login
  895. #+begin_src emacs-lisp
  896. (setq dashboard-navigator-buttons
  897. `(;; First row.
  898. ((,(all-the-icons-fileicon "brain" :height 1.1 :v-adjust 0.0)
  899. "Brain"
  900. "Knowledge base"
  901. (lambda (&rest _) (browse-url "http://localhost:8080"))))
  902. ;; Second row.
  903. ((,(all-the-icons-material "public" :height 1.1 :v-adjust 0.0)
  904. "Homepage"
  905. "Personal website"
  906. (lambda (&rest _) (browse-url "https://chrishayward.xyz"))))
  907. ;; Third row.
  908. ((,(all-the-icons-faicon "university" :height 1.1 :v-adjust 0.0)
  909. "Athabasca"
  910. "Univeristy login"
  911. (lambda (&rest _) (browse-url "https://login.athabascau.ca/cas/login"))))))
  912. #+end_src
  913. When running in *daemon* mode, ensure that the dashboard is the initial buffer.
  914. #+begin_src emacs-lisp
  915. (setq initial-buffer-choice
  916. (lambda ()
  917. (get-buffer "*dashboard*")))
  918. #+end_src