diff --git a/bin/publish.sh b/bin/publish.sh new file mode 100755 index 0000000..0b512a9 --- /dev/null +++ b/bin/publish.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +NOTE="$(notes.sh -l | fzf --tac --with-nth="2..-1" | cut -d " " -f 1)" + +if [ ! -z "$NOTE" ]; then + SLUG="$(notes.sh -E $NOTE | grep -m1 "^X-Slug: " | sed -n "s/^X-Slug: \(.*\)$/\1/p")" + if [ -z "$SLUG" ]; then + echo "X-Slug header expected" + exit 1 + fi + DIR="/home/knazarov/dev/knazarov.com/content/posts/$SLUG" + mkdir -p "$DIR" + notes.sh -E "$NOTE" > "$DIR/note.md" +fi diff --git a/content/posts/emacs_fast_startup/note.md b/content/posts/emacs_fast_startup/note.md new file mode 100644 index 0000000..084fadb --- /dev/null +++ b/content/posts/emacs_fast_startup/note.md @@ -0,0 +1,57 @@ +X-Date: 2024-06-10T21:00:38Z +X-Note-Id: f850f802-798d-49e7-ad9b-c0d6a977d4bb +Subject: Emacs can start up almost as fast as Vim +X-Slug: emacs_fast_startup + +My own configuration which includes a number of plugins can now load in about 200ms. +With Vim modal editing emulation through [evil-mode](https://github.com/emacs-evil/evil) it is suitable +as default `$EDITOR` in the terminal. This enables convenient editing of git commit messages, or random +one-off changes where I usually resorted to plain vim. So much so that I've set `alias vim=emacs -nw`. + +The trick turned out to be quite simple: you need to lazy-load most of the packages. When you run the +editor, you're likely only using a subset of extensions like syntax highlighting for the programming language +that your initial buffer is in. So no need to spend CPU time on things that you either don't need or use +later. + +Latest versions of Emacs have `use-package` module built in that allows to succintly describe configuration +of plugins and set the rules of when they should be loaded. Here's an example of configuration for `org-roam`, +a plugin I use for note-taking: + +``` +(use-package org-roam + :ensure t + :defer t + :bind + ("C-c n l" . org-roam-buffer-toggle) + ("C-c n i" . org-roam-node-insert) + ("C-c n f" . org-roam-node-find) + ("C-c n r" . consult-org-roam-search) + ("C-c n d" . org-roam-dailies-goto-today) + ("C-c n w" . org-roam-week) + + ... + ) +``` + +Here, `:defer` flag means that the module shouldn't be eagerly loaded. The `:bind` specifies keybindings that +should trigger specific actions of this module. As soon as you type those key combinations - only then the module +will be loaded. + +Some packages like `which-key` that are not needed immediately, can be loaded with a delay: + +``` +(use-package which-key + :ensure t + :defer 2 + :config + (which-key-mode) + (which-key-setup-side-window-bottom) + ) +``` + +Here, `:defer 2` means "load this plugin 2 seconds after the startup". This allows you to open and start editing a +file and the plugin will be loaded in the background. + +Really, it all boils down to carefully using `:defer`, and most of the load time can be shaved off. With so much stuff +already in the standard package, you can probably even put emacs to your devserver, `scp` the config there, and +it should just work.