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.

1312 lines
40 KiB

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