Skip to content

Instantly share code, notes, and snippets.

@axelson
Created July 2, 2023 02:00
Show Gist options
  • Save axelson/cd6583f122f6c951842bd6b6c279c05f to your computer and use it in GitHub Desktop.
Save axelson/cd6583f122f6c951842bd6b6c279c05f to your computer and use it in GitHub Desktop.
;; -*- lexical-binding: t -*-
;; This is my Emacs config
;; it is my own, there is none like it
;; How do I navigate through CamelCase words?
;; I use the built-in `winner-mode` to remember the window history
;; Setup melpa
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/"))
;; macOs stuff
(when (eq system-type 'darwin)
(setq mac-option-modifier 'meta)
(setq mac-command-modifier 'super))
(when (functionp 'treesit-install-language-grammar)
(setq treesit-language-source-alist
'((bash "https://github.com/tree-sitter/tree-sitter-bash")
(cmake "https://github.com/uyha/tree-sitter-cmake")
(css "https://github.com/tree-sitter/tree-sitter-css")
(elisp "https://github.com/Wilfred/tree-sitter-elisp")
(go "https://github.com/tree-sitter/tree-sitter-go")
(html "https://github.com/tree-sitter/tree-sitter-html")
(javascript "https://github.com/tree-sitter/tree-sitter-javascript" "master" "src")
(json "https://github.com/tree-sitter/tree-sitter-json")
(make "https://github.com/alemuller/tree-sitter-make")
(markdown "https://github.com/ikatyang/tree-sitter-markdown")
(python "https://github.com/tree-sitter/tree-sitter-python")
(toml "https://github.com/tree-sitter/tree-sitter-toml")
(tsx "https://github.com/tree-sitter/tree-sitter-typescript" "master" "tsx/src")
(typescript "https://github.com/tree-sitter/tree-sitter-typescript" "master" "typescript/src")
(yaml "https://github.com/ikatyang/tree-sitter-yaml")))
)
;; Keybindings
(global-set-key (kbd "M-j") 'windmove-down)
(global-set-key (kbd "M-k") 'windmove-up)
(global-set-key (kbd "M-h") 'windmove-left)
(global-set-key (kbd "M-l") 'windmove-right)
(global-set-key (kbd "s-J") 'move-text-down)
(global-set-key (kbd "s-K") 'move-text-up)
(global-set-key (kbd "C-z") nil)
(global-set-key (kbd "s-/") 'comment-line)
(global-set-key (kbd "s-v") 'yank)
;; General package for keybindings
(use-package general
:ensure t
:config
(general-auto-unbind-keys)
(defconst my-leader ",")
(general-create-definer jax/leader-def
:prefix ",")
(jax/leader-def
"," 'completion-at-point
"c" 'comment-line
"g" 'magit
"j" 'move-text-down
"k" 'move-text-up
"SPC" 'jax/insert-comma-space
"RET" 'jax/insert-comma-return
"t ," 'jax/repeat-last-test
"t t" 'jax/test-current-line
"t b" 'jax/test-current-file
"t TAB" 'jax/toggle-file-and-test
"C-q" 'jax/insert-comma
))
(defun jax/insert-comma ()
(interactive)
(insert ","))
(defun jax/insert-comma-space ()
(interactive)
(insert ", "))
(defun jax/insert-comma-return ()
(interactive)
(insert ",\n"))
(defun jax/test-current-line ()
(interactive)
(cond ((eq major-mode 'elixir-mode)
(exunit-verify-single))
((eq major-mode 'elixir-ts-mode)
(exunit-verify-single))
(t (message (format "Unsupported major mode %s" major-mode)))
))
(defun jax/toggle-file-and-test ()
(interactive)
(cond ((eq major-mode 'elixir-mode)
(exunit-toggle-file-and-test))
((eq major-mode 'elixir-ts-mode)
(exunit-toggle-file-and-test))
(t (message (format "Unsupported major mode %s" major-mode)))
))
(defun jax/test-current-file ()
(interactive)
(cond ((eq major-mode 'elixir-mode)
(exunit-verify))
((eq major-mode 'elixir-ts-mode)
(exunit-verify))
(t (message (format "Unsupported major mode %s" major-mode)))
))
(defun jax/repeat-last-test ()
(interactive)
(cond ((eq major-mode 'elixir-mode)
(save-buffer)
(exunit-rerun))
(t (message (format "Unsupported major mode %s" major-mode)))
))
;; Use ibuffer to switch buffers with C-x C-b
(global-set-key [remap list-buffers] 'ibuffer)
;; General emacs config
(global-auto-revert-mode)
;; Straight.el bootstrapping
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 6))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(use-package exec-path-from-shell
:ensure t
:init
(when (memq window-system '(mac ns x))
(exec-path-from-shell-initialize)))
;; Vertico
(use-package vertico
:ensure t
:bind (:map vertico-map
("C-j" . vertico-next)
("C-k" . vertico-previous)
:map minibuffer-local-map
;; TODO: This is probably not what I really want
("M-h" . backward-kill-word))
:init
(vertico-mode)
)
;; Persist vertico (only?) history over Emacs restarts
(use-package savehist
:init
(savehist-mode))
;; Adds more details about autocomplete options (such as file size and buffer mode)
;; Works well with Vertico and is written by the same author
(use-package marginalia
:after vertico
:ensure t
:bind (:map minibuffer-local-map
("M-A" . marginalia-cycle))
:custom
(marginalia-annotators '(marginalia-annotators-heavy marginalia-annotators-light nil))
:init
(marginalia-mode))
;; Corfu
(use-package corfu
:ensure t
:custom
(corfu-auto t)
(corfu-scroll-margin 5)
:init
(global-corfu-mode)
(corfu-history-mode 1)
(savehist-mode t)
(add-to-list 'savehist-additional-variables 'corfu-history)
)
;; From corfu readme, use `M-m` to move the completion into the minibuffer
(defun corfu-move-to-minibuffer ()
(interactive)
(when completion-in-region--data
(let ((completion-extra-properties corfu--extra)
completion-cycle-threshold completion-cycling)
(apply #'consult-completion-in-region completion-in-region--data))))
(keymap-set corfu-map "M-m" #'corfu-move-to-minibuffer)
(add-to-list 'corfu-continue-commands #'corfu-move-to-minibuffer)
;; Consult
(use-package consult
:ensure t
:bind (("C-c h" . consult-history)
("M-g g" . consult-goto-line)
("M-g l" . consult-line)))
;; Orderless - completion style for Vertico
(use-package orderless
:ensure t
:custom
(completion-styles '(orderless basic))
(completion-category-overrides '((file (styles basic partial-completion)))))
;; Which-key
(use-package which-key
:init
(which-key-mode))
;; Embark - https://github.com/oantolin/embark
(use-package embark
:ensure t
:bind
(("C-." . embark-act) ;; pick some comfortable binding
("M-." . embark-dwim) ;; good alternative: M-.
("C-;" . embark-export)
("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'
:init
:config
)
;; Embark + consult
(use-package embark-consult
:ensure t
:hook
(embark-collect-mode . consult-preview-at-point-mode))
;; Hydra
;; Inspired by https://www.youtube.com/watch?v=dBinYLNTvBo (https://drive.google.com/file/d/1mRE7To7MAWitxRnszv9PxWPzuOaq3s9N/view)
(defhydra hydra-jump-to-system-file
(:color amaranth)
"Jump to system file"
("s" (find-file "~/.ssh/config") "ssh config")
("i" (find-file "~/config/app-config/emacs-vanilla.d/init.el") "init.el")
("d" (find-file "~/config/app-config/doom.d/config.el") "doom config.el")
("f" (find-file "~/.config/fish/config.fish") "config.fish")
("RET" nil "Quit" :color blue)
("q" nil "Quit" :color blue))
(global-set-key (kbd "C-c 1") 'hydra-jump-to-system-file/body)
;; Magit
(use-package magit
:ensure t)
;; yasnippet
(use-package yasnippet
:ensure t
:init (yas-global-mode 1))
(use-package move-text
:ensure t)
;; combobulate (only on Emacs 29)
;; use elixir-ts-mode as a very crappy check of if we support treesitter
(when (package-installed-p 'elixir-ts-mode)
(use-package combobulate
:preface
(setq combobulate-key-prefix "C-c o")
:hook ((python-ts-mode . combobulate-mode)
(js-ts-mode . combobulate-mode)
(css-ts-mode . combobulate-mode)
(yaml-ts-mode . combobulate-mode)
(typescript-ts-mode . combobulate-mode)
(tsx-ts-mode . combobulate-mode))
:load-path ("~/dev/forks/combobulate")))
;; Elixir stuff
(if (eq system-type 'darwin)
nil
(use-package elixir-ts-mode
:ensure t)
)
(use-package elixir-mode
:ensure t)
;; exunit.el
(use-package exunit
:ensure t)
(add-hook 'elixir-mode-hook 'exunit-mode)
(use-package gist
:straight (gist
:repo "KarimAziev/gist.el"
:type git
:host github))
;; Javascript stuff
;; (use-package rjsx-mode
;; :ensure t)
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(delete-selection-mode t)
'(global-subword-mode t)
'(isearch-allow-motion t)
'(package-selected-packages
'(straight corfu exec-path-from-shell general orderless yasnippet marginalia move-text hydra markdown-mode which-key elixir-ts-mode exunit vertico))
'(recentf-max-menu-items 15)
'(recentf-max-saved-items 50)
'(recentf-mode t)
'(winner-mode t))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
(put 'narrow-to-region 'disabled nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment