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.
 
 
 
Christopher James Hayward ca7d3bb64c Init desktop module 4 years ago
LICENSE Initial commit 4 years ago
README.org Init desktop module 4 years ago
init.el Init desktop module 4 years ago

README.org

Dotfiles

           ^^                   @@@@@@@@@
      ^^       ^^            @@@@@@@@@@@@@@@
                           @@@@@@@@@@@@@@@@@@              ^^
                          @@@@@@@@@@@@@@@@@@@@
~~~~ ~~ ~~~~~ ~~~~~~~~ ~~ &&&&&&&&&&&&&&&&&&&& ~~~~~~~ ~~~~~~~~~~~ ~~~
~         ~~   ~  ~       ~~~~~~~~~~~~~~~~~~~~ ~       ~~     ~~ ~
  ~      ~~      ~~ ~~ ~~  ~~~~~~~~~~~~~ ~~~~  ~     ~~~    ~ ~~~  ~ ~~ 
  ~  ~~     ~         ~      ~~~~~~  ~~ ~~~       ~~ ~ ~~  ~~ ~ 
~  ~       ~ ~      ~           ~~ ~~~~~~  ~      ~~  ~             ~~
      ~             ~        ~      ~      ~~   ~             ~

Immutable GNU Emacs dotfiles, inspired by Doom, built for Liberty.

  • 100% Literate

  • 100% Immutable

  • 100% Reproducible

(defun dotfiles/tangle (dir)
  "Recursively tangle the Org files within a directory."
  (interactive)
  (let ((org-files (directory-files-recursively dir "org")))
    (dolist (f org-files)
      (org-babel-tangle-file f))))

Core

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.

(defvar dotfiles/home user-emacs-directory)

How can we solve this issue?

(defvar dotfiles/cache "~/.cache/emacs")

Shortly after initialization, before most packages are loaded, we change the value to dotfiles/cache. I elaborate more on the technique in my post Immutable Emacs.

(setq user-emacs-directory dotfiles/cache)

Because this project uses version-control, we can disable more unwanted features:

  • Lock files

  • Backup files

(setq create-lockfiles nil
      make-backup-files nil)

Packages

Download and install packages using straight.el, a functional package manager that integrates with use-package, giving us more control over where packages are sourced from.

  • Use the development branch

  • Integrate with use-package

Apply the configurations prior to bootstrapping the package manager, by setting (writing) to the variables that straight will ultimately read from.

(setq straight-repository-branch "develop"
      straight-use-package-by-default t)

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.

(defvar bootstrap-version)
(let ((bootstrap-file
       (expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
      (bootstrap-version 5))
  (unless (file-exists-p bootstrap-file)
    (with-current-buffer
        (url-retrieve-synchronously
         "https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
         'silent 'inhibit-cookies)
      (goto-char (point-max))
      (eval-print-last-sexp)))
  (load bootstrap-file nil 'nomessage))

Complete the integration with use-package by installing it with straight.

(straight-use-package 'use-package)

Cleanup

Despite having our stateful and immutable configurations seperate, it's good practice to make efforts to reduce the trash created by Emacs.

Install no-littering to reduce the files created by Emacs.

(use-package no-littering)

Emacs' default user interface is horrendous, but with less than 10 lines of code we can change that.

(setq inhibit-startup-message t)
(global-prettify-symbols-mode)
(scroll-bar-mode -1)
(menu-bar-mode -1)
(tool-bar-mode -1)
(tooltip-mode -1)

Babel

Organize your plain life in plain text

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.

(use-package org
  :hook
  (org-mode . (lambda ()
		(org-indent-mode)
		(visual-line-mode 1)
		(variable-pitch-mode 1)))
  :config
  (setq org-ellipsis " ▾"
	org-log-done 'time
	org-log-into-drawer t
	org-src-preserve-indentation t)

  (org-babel-do-load-languages
   'org-babel-load-languages
   '((shell . t)
     (python . t)
     (emacs-lisp . t)))

  (require 'org-tempo)
  (add-to-list 'org-structure-template-alist '("s" . "src"))
  (add-to-list 'org-structure-template-alist '("q" . "quote"))
  (add-to-list 'org-structure-template-alist '("e" . "example"))
  (add-to-list 'org-structure-template-alist '("sh" . "src shell"))
  (add-to-list 'org-structure-template-alist '("py" . "src python"))
  (add-to-list 'org-structure-template-alist '("el" . "src emacs-lisp")))

Keys

Make the ESC key quit (most) prompts, instead of the default C-g.

(global-set-key (kbd "<escape>") 'keyboard-escape-quit)

Functionality like completion and hints can be delayed to avoid popups for common manuevers. Adjust this value to your personal taste.

(defvar dotfiles/idle 0.0)

Download which-key, a package that displays the current incomplete keybinding input in a mini-buffer, showing available completion options.

(use-package which-key
  :diminish which-key-mode
  :init (which-key-mode)
  :config (setq which-key-idle-delay dotfiles/idle))

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.

(defvar dotfiles/leader-key "SPC")
(defvar dotfiles/leader-key-global "C-SPC")

Implement the leader key mentioned above using general.el, letting us easily configure prefixed keybindings in a much cleaner manner than the default methods.

(use-package general
  :config
  (general-create-definer dotfiles/leader
    :states '(normal motion)
    :keymaps 'override
    :prefix dotfiles/leader-key
    :global-prefix dotfiles/leader-key-global))

Use hydra for transient keybindings sharing a common prefix.

(use-package hydra)

Evil

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

  • Extendable VI layer for Emacs

  • Disable default keybindings

(use-package evil
  :init (setq evil-want-integration t
	            evil-want-keybinding nil)
  :config (evil-mode 1))

https://github.com/emacs-evil/evil-collection

  • Community keybindings for evil-mode

(use-package evil-collection
  :after evil
  :config (evil-collection-init))

https://github.com/redguardtoo/evil-nerd-commenter

  • Toggle comments with M-;

(use-package evil-nerd-commenter
  :bind ("M-;" . evilnc-comment-or-uncomment-lines))

Shortcuts

Again cherry picked from Doom, I want to continue utilizing the muscle memory I have developed from a year of mainlining the framework.

  • Close buffers with SPC c

  • Find files with SPC . (period)

  • Switch buffers with SPC , (comma)

(dotfiles/leader
  "." '(find-file :which-key "Files")
  "," '(switch-to-buffer :which-key "Buffers")
  "c" '(kill-buffer-and-window :which-key "Close"))
Quit

Quit emacs with SPC q.

  • Saving q

  • Without w

  • Frame (daemon) f

(dotfiles/leader
  "q" '(:ignore t :which-key "Quit")
  "qq" '(save-buffers-kill-emacs :which-key "Save")
  "qw" '(kill-emacs :which-key "Now")
  "qf" '(delete-frame :which-key "Frame"))
Windows

Window management with SPC w.

  • Swap with w

  • Close with c

  • Motions with h,j,k,l

  • Split with s + <MOTION>

(dotfiles/leader
  "w" '(:ignore t :which-key "Window")
  "ww" '(window-swap-states :which-key "Swap")
  "wc" '(delete-window :which-key "Close")
  "wh" '(windmove-left :which-key "Left")
  "wj" '(windmove-down :which-key "Down")
  "wk" '(windmove-up :which-key "Up")
  "wl" '(windmove-right :which-key "Right")
  "ws" '(:ignore t :which-key "Split")
  "wsj" '(split-window-below :which-key "Down")
  "wsl" '(split-window-right :which-key "Right"))

Editor

Bring Emacs out of the eighties

Git

Another hallmark feature is Magit, a complete git porcelain within Emacs.

(use-package magit
  :custom (magit-display-buffer-function
           #'magit-display-buffer-same-window-except-diff-v1))

Work directly with github issues / pull requests using Forge.

  • Requires a valid $GITHUB_TOKEN

(use-package forge)

Open the status page for the current repository with SPC g.

(dotfiles/leader
  "g" '(magit-status :which-key "Magit"))

Shell

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.

https://github.com/zwild/eshell-prompt-extras

  • Enable lambda shell prompt

(use-package eshell-prompt-extras
  :config (setq eshell-highlight-prompt nil
	            eshell-prompt-function 'epe-theme-lambda))

Open an eshell buffer with SPC e.

(dotfiles/leader
  "e" '(eshell :which-key "Shell"))

Files

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.

https://github.com/domtronn/all-the-icons.el

  • Collects various icon fonts

(use-package all-the-icons)

https://github.com/jtbm37/all-the-icons-dired

  • Integration with dired

(use-package all-the-icons-dired
  :hook (dired-mode . all-the-icons-dired-mode))

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.

(require 'dired-x)

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. Dired-single lets us reuse the same dired buffer.

  • Move up a directory with h

  • Open a single buffer with l

(use-package dired-single
  :config
  (evil-collection-define-key 'normal 'dired-mode-map
    "h" 'dired-single-up-directory
    "l" 'dired-single-buffer))

Open a dired buffer with SPC d.

(dotfiles/leader
  "d" '(dired-jump :which-key "Dired"))

Fonts

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.

(defvar dotfiles/font "Fira Code")
(defvar dotfiles/font-size 96)

Write out to all 3 of Emacs' default font faces.

(set-face-attribute 'default nil :font dotfiles/font :height dotfiles/font-size)
(set-face-attribute 'fixed-pitch nil :font dotfiles/font :height dotfiles/font-size)
(set-face-attribute 'variable-pitch nil :font dotfiles/font :height dotfiles/font-size)

Define a transient keybinding for scaling the text.

(defhydra hydra-text-scale (:timeout 4)
  "Scale"
  ("j" text-scale-increase "Increase")
  ("k" text-scale-decrease "Decrease")
  ("f" nil "Finished" :exit t))

Increase the font size in buffers with SPC f.

  • Increase j

  • Decrease k

  • Finish f

(dotfiles/leader
  "f" '(hydra-text-scale/body :which-key "Font"))

Lines

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.

  5:
  4:
  3:
  2:
  1:
156: << CURRENT LINE >>
  1:
  2:
  3:
  4:
  5:

https://github.com/emacsmirror/linum-relative

  • Integrate with display-line-numbers-mode for performance

(use-package linum-relative
  :init (setq linum-relative-backend
	      'display-line-numbers-mode)
  :config (linum-relative-global-mode))

https://github.com/Fanael/rainbow-delimiters

  • Colourize nested parenthesis

(use-package rainbow-delimiters
  :hook (prog-mode . rainbow-delimiters-mode))

Themes

Bring Emacs' out of the eighties by cherry picking a few modules from Doom.

https://github.com/hlissner/emacs-doom-themes

  • Modern colour themes

(use-package doom-themes
  :init (load-theme 'doom-moonlight t))

Load a theme with SPC t.

(dotfiles/leader
  "t" '(load-theme t nil :which-key "Theme"))

https://github.com/seagle0128/doom-modeline

  • Elegant status bar / modeline

(use-package doom-modeline
  :init (doom-modeline-mode 1)
  :custom ((doom-modeline-height 16)))

Desktop

(defun desktop/run (command)
  (let ((command-parts (split-string command "[ ]+")))
    (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))
(defun desktop/set-wallpaper (path)
  (interactive)
  (when (file-exists-p path)
    (let ((command (concat "feh --bg-scale " path)))
      (start-process-shell-command "feh" nil command))))
(defun desktop/init-hook ()
  (exwm-workspace-switch-create 1)
  (setq display-time-and-date t)
  (display-battery-mode 1)
  (display-time-mode 1))
(defun desktop/update-display ()
  (desktop/run "autorandr --change --force")
  ;; (desktop/set-wallpaper "TODO")
  (message "Display: %s"
    (string-trim
      (shell-command-to-string "autorandr --current"))))
(use-package exwm
  :config

  (require 'exwm-randr)
  (exwm-randr-enable)
  (start-process-shell-command "xrandr" nil "xrandr --output Virtual-1 --primary --mode 1920x1080 --pos 0x0 --rotate normal")

  (add-hook 'exwm-init-hook #'desktop/init-hook)
  (add-hook 'exwm-randr-screen-change-hook #'desktop/update-display)

  (desktop/update-display)

  (setq exwm-input-prefix-keys
        '(?\M-x
          ?\C-\ ) ;; C-SPC

        exwm-input-global-keys
        `(([?\s-r] . exwm-reset)
          ([?\s-&] . (lambda (command)
                       (interactive (list (read-shell-command "λ ")))
                       (start-process-shell-command command nil command)))

          ,@(mapcar (lambda (i)
                      `(,(kbd (format "s-%d" i)) .
                        (lambda ()
                          (interactive)
                          (exwm-workspace-switch-create ,i))))
                    (number-sequence 1 9))))

  (exwm-enable))

Writing

I am using Org-mode extensively for writing projects for different purposes. Improvements beyond what are required for my Literate Programming platform include:

Org-superstar-mode for making headline stars more super.

(use-package org-superstar
  :hook (org-mode . org-superstar-mode))

Mail

(add-to-list 'load-path "/usr/share/emacs/site-lisp/mu4e")
(use-package mu4e
  :config
  (setq mu4e-change-filenames-when-moving t
        mu4e-update-interval (* 5 60) ;; Every 5 minutes.
        mu4e-get-mail-command "mbsync -a"
        mu4e-maildir "~/.cache/mail"
        mu4e-compose-signature 
          (concat "Chris Hayward\n"
                  "https://chrishayward.xyz\n"))

  ;; Ensure plain text scales for all devices.
  (setq mu4e-compose-format-flowed t)

  ;; GPG signing key for outbound mail.
  (setq mml-secure-openpgp-signers '("37AB1CB72B741E478CA026D43025DCBD46F81C0F"))
  (add-hook 'message-send-hook 'mml-secure-message-sign-pgpmime)

  (setq message-send-mail-function 'smtpmail-send-it)  

  ;; Configure mail account(s).
  (setq mu4e-contexts
    (list
      ;; Main
      ;; chris@chrishayward.xyz
      (make-mu4e-context
        :name "Main"
        :match-func
          (lambda (msg)
            (when msg 
              (string-prefix-p "/Main" (mu4e-message-field msg :maildir))))
        :vars
          '((user-full-name . "Christopher James Hayward")
            (user-mail-address . "chris@chrishayward.xyz")
            (smtpmail-smtp-server . "mail.chrishayward.xyz")
            (smtpmail-smtp-service . 587)
            (smtpmail-stream-type . starttls))))))
(dotfiles/leader
  "m" '(mu4e :which-key "Mail"))

Brain

Org-roam is a rudimentary roam replica built on Org mode.

(use-package org-roam
  :hook (after-init . org-roam-mode)
  :custom (org-roam-directory "~/.local/source/brain"))

Org-roam-server is a web application that visualizes the Org roam database, available when Emacs' running at localhost:8080.

(use-package org-roam-server
  :hook (org-roam-mode . org-roam-server-mode))

Configure keybindings behind SPC r.

  • Find with f

  • Buffer with b

  • Capture with c

  • Dailies with d

(dotfiles/leader
  "r" '(:ignore t :which-key "Roam")
  "rf" '(org-roam-find-file :which-key "Find")
  "rb" '(org-roam-buffer-toggle-display :which-key "Buffer")
  "rc" '(org-roam-capture :which-key "Capture")
  "rd" '(:ignore t :which-key "Dailies")
  "rdd" '(org-roam-dailies-find-date :which-key "Date")
  "rdt" '(org-roam-dailies-find-today :which-key "Today")
  "rdm" '(org-roam-dailies-find-tomorrow :which-key "Tomorrow")
  "rdy" '(org-roam-dailies-find-yesterday :which-key "Yesterday"))

Configure the default capture template for new topics.

(setq org-roam-capture-templates
      '(("d" "Default" plain (function org-roam-capture--get-point)
         "%?"
         :file-name "${slug}"
         :head "#+TITLE: ${title}\n"
         :unnarrowed t)))

Configure the default capture template for daily entries.

(setq org-roam-dailies-capture-templates
      '(("d" "Default" entry (function org-roam-capture--get-point)
         "* %?"
         :file-name "daily/%<%Y-%m-%d>"
         :head "#+TITLE: %<%Y-%m-%d>\n")))

Blogging

I use Hugo for my personal website, which I write in Org-mode before compiling to hugo-markdown.

Ox-hugo, configured for one-post-per-file is my technique for managing my blog.

(use-package ox-hugo 
  :after ox)

Creaate a capture template for blog posts in the posts sub directory.

(add-to-list 'org-roam-capture-templates
             '("b" "Blogging" plain (function org-roam-capture--get-point)
               "%?"
               :file-name "posts/${slug}"
               :head "#+TITLE: ${title}\n#+HUGO_BASE_DIR: ~/.local/source/website\n#+HUGO_SECTION: posts\n"))

Agenda

Configure agenda sources.

  • Dailies ~/.local/source/brain/daily/

  • Secrets ~/.local/source/secrets/org/

(setq org-agenda-files '("~/.local/source/brain/daily/"
                         "~/.local/source/secrets/org/"))

Open an agenda buffer with SPC a.

(dotfiles/leader
  "a" '(org-agenda :which-key "Agenda"))

Screencasts

Create screencasts with one-frame-per-action GIF recording via emacs-gif-screencast.

  • Can be paused / resumed

  • High quality images

  • Optimized size

It requires the installation of scrot and convert from the ImageMagick library.

(use-package gif-screencast
  :custom
  (gif-screencast-output-directory "~/.local/source/brain/screen/"))

Screencast controls behind SPC p.

  • Start / stop with s

  • Pause with p

(dotfiles/leader
  "p" '(:ignore t :which-key "Screencast")
  "ps" '(gif-screencast-start-or-stop :which-key "Start / Stop")
  "pp" '(gif-screencast-toggle-pause :which-key "Pause"))

Presentations

Produce high quality presentations that work anywhere with HTML/JS and the Reveal.js package.

Ox-reveal, configured to use a cdn allows us to produce ones that are not dependent on a local version of Reveal.js.

(use-package ox-reveal
  :after ox
  :custom (org-reveal-root "https://cdn.jsdelivr.net/reveal.js/3.9.2/"))

Create a capture template for presentations stored in the slides sub directory.

(add-to-list 'org-roam-capture-templates
             '("p" "Presentation" plain (function org-roam-capture--get-point)
               "%?"
               :file-name "slides/${slug}"
               :head "#+TITLE: ${title}\n"))

Development

An IDE like experience (or better) can be achieved in Emacs using two Microsoft open source initiatives.

Turn Emacs into an IDE (or better) with the Language Server Protocol, an open source initiative from Microsoft for the VSCode editor.

Lsp-mode brings support for language servers into Emacs.

(use-package lsp-mode
  :custom (gc-cons-threshold 1000000000)
          (lsp-idle-delay 0.500))

https://emacs-lsp.github.io/lsp-ui/

  • UI improvements for lsp-mode

(use-package lsp-ui
  :custom (lsp-ui-doc-position 'at-point)
          (lsp-ui-doc-delay 0.500))

Passwords

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.

(use-package password-store
  :custom (password-store-dir "~/.local/source/passwords"))

Debugging

Handled through the Debug Adapter Protocol, an open source initiative from Microsoft for the VSCode editor.

Dap-mode adds support for the protocol to Emacs.

(use-package dap-mode)

Completion

Text completion framework via company aka Complete Anything.

http://company-mode.github.io/

  • Integrate with lsp-mode

(use-package company)
(use-package company-lsp)

Languages

Support for individual languages are implemented here.

C/C++

Full IDE experience for Python within Emacs.

  • Completion, jumps via lsp-mode

  • Debugging via dap-mode

Install the ccls language server.

(use-package ccls
  :hook ((c-mode c++-mode objc-mode cuda-mode) .
         (lambda () (require 'ccls) (lsp))))

Python

Full IDE experience for Python within Emacs.

  • Completion, jumps via lsp-mode

  • Debugging via dap-mode

Install the pyls language server.

pip install --user "python-language-server[all]"

https://www.emacswiki.org/emacs/PythonProgrammingInEmacs

  • Built in mode

(use-package python-mode
  :hook (python-mode . lsp)
  :config (require 'dap-python)
  :custom (python-shell-interpreter "python3") ;; Required if "python" is not python 3.
          (dap-python-executable "python3")    ;; Same as above.
          (dap-python-debugger 'debugpy))

Rust

Full IDE experience for Rust within Emacs.

  • Completion via lsp-mode

  • Debugging via dap-mode

https://github.com/brotzeit/rustic

  • Install via lsp-install-server

rustup default nightly
(use-package rustic)

Go

Full IDE experience for Rust within Emacs.

  • Completion via lsp-mode

  • Debugging via dap-mode

Install the gopls language server.

GO111MODULE=on go get golang.org/x/tools/gopls@latest
(use-package go-mode
  :hook (go-mode . lsp))