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.

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