Skip to content

Instantly share code, notes, and snippets.

@reflechant
Last active October 21, 2024 07:38
Show Gist options
  • Save reflechant/2377e20a8a53d122c5412603e7fa09ea to your computer and use it in GitHub Desktop.
Save reflechant/2377e20a8a53d122c5412603e7fa09ea to your computer and use it in GitHub Desktop.
my Emacs config
;; Set package repositories
(require 'package)
(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/"))
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)
(eval-when-compile
(require 'use-package)
(require 'use-package-ensure))
(setq use-package-always-ensure t)
;; Autoupdate packages
(use-package auto-package-update
:config
(setq auto-package-update-delete-old-versions t
auto-package-update-hide-results t)
(auto-package-update-maybe))
;;;;;;;;;;;;;;;;
;; Appearance ;;
;;;;;;;;;;;;;;;;
;; Set font (Fira Code, 12pt)
(set-face-attribute 'default nil :family "Fira Code" :height 120)
;; (load-theme 'deeper-blue t) ;; Load theme
;; Font ligatures
(use-package ligature
:config
;; Enable the "www" ligature in every possible major mode
(ligature-set-ligatures 't '("www"))
;; Enable ligatures in programming modes
(ligature-set-ligatures 'prog-mode '("www" "**" "***" "**/" "*>" "*/" "\\\\" "\\\\\\" "{-" "::"
":::" ":=" "!!" "!=" "!==" "-}" "----" "-->" "->" "->>"
"-<" "-<<" "-~" "#{" "#[" "##" "###" "####" "#(" "#?" "#_"
"#_(" ".-" ".=" ".." "..<" "..." "?=" "??" ";;" "/*" "/**"
"/=" "/==" "/>" "//" "///" "&&" "||" "||=" "|=" "|>" "^=" "$>"
"++" "+++" "+>" "=:=" "==" "===" "==>" "=>" "=>>" "<="
"=<<" "=/=" ">-" ">=" ">=>" ">>" ">>-" ">>=" ">>>" "<*"
"<*>" "<|" "<|>" "<$" "<$>" "<!--" "<-" "<--" "<->" "<+"
"<+>" "<=" "<==" "<=>" "<=<" "<>" "<<" "<<-" "<<=" "<<<"
"<~" "<~~" "</" "</>" "~@" "~-" "~>" "~~" "~~>" "%%"))
(global-ligature-mode 't))
;;;;;;;;;;;;;;;;;
;; Convenience ;;
;;;;;;;;;;;;;;;;;
;; Better defaults
(use-package better-defaults)
;; SHIFT+arrow to move around windows
(windmove-default-keybindings)
;; Sets up exec-path-from shell
;; https://github.com/purcell/exec-path-from-shell
(use-package exec-path-from-shell)
(when (memq window-system '(mac ns))
(exec-path-from-shell-initialize)
(exec-path-from-shell-copy-envs
'("PATH")))
;; ;; Enable toggle-comment-on-line
;; (defun toggle-comment-on-line ()
;; "Comment or uncomment current line."
;; (interactive)
;; (comment-or-uncomment-region (line-beginning-position) (line-end-position)))
;; (global-set-key (kbd "C-;") 'toggle-comment-on-line)
;; Changes all yes/no questions to y/n type
(fset 'yes-or-no-p 'y-or-n-p)
;; No need for lock files when editing
(setq create-lockfiles nil)
(setq inhibit-startup-message t) ;; Hide the startup message
;; Remember position in files
(save-place-mode 1)
;; Remember last open files
(recentf-mode 1)
(setq recentf-max-menu-items 25
recentf-max-saved-items 25)
(global-set-key "\C-x\ \C-r" 'recentf-open-files)
;; Show line numbers in programs
;; (global-display-line-numbers-mode 1)
(add-hook 'prog-mode-hook #'display-line-numbers-mode)
;; Automatically pair parentheses
(electric-pair-mode t)
(use-package which-key
:config
(which-key-mode))
(use-package diminish)
;; Ivy, Swiper & Counsel
;; (use-package ivy
;; :diminish (ivy-mode . "")
;; :init (ivy-mode 1) ; globally at startup
;; :config
;; (setq ivy-use-virtual-buffers t)
;; (setq ivy-height 20)
;; (setq ivy-count-format "%d/%d "))
;; (use-package counsel :demand
;; :after ivy
;; :diminish (counsel-mode . "")
;; :config
;; (counsel-mode))
;; (use-package swiper
;; :after ivy
;; :bind (("C-s" . swiper)
;; ("C-r" . swiper)))
;; Vertico for completions
(use-package vertico
;; :custom
;; (vertico-scroll-margin 0) ;; Different scroll margin
;; (vertico-count 20) ;; Show more candidates
;; (vertico-resize t) ;; Grow and shrink the Vertico minibuffer
;; (vertico-cycle t) ;; Enable cycling for `vertico-next/previous'
:init
(vertico-mode))
;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
:init
(savehist-mode))
(use-package emacs
:custom
;; Hide commands in M-x which do not work in the current mode. Vertico
;; commands are hidden in normal buffers. This setting is useful beyond
;; Vertico.
(read-extended-command-predicate #'command-completion-default-include-p)
)
(use-package orderless
:custom
(completion-styles '(orderless basic))
(completion-category-overrides '((file (styles basic partial-completion)))))
;; advised by Consult
(setq lexical-binding t)
(global-unset-key (kbd "C-s"))
(global-unset-key (kbd "C-r"))
;; Consult
(use-package consult
;; Replace bindings. Lazily loaded by `use-package'.
:bind (;; C-c bindings in `mode-specific-map'
("C-c M-x" . consult-mode-command)
("C-c h" . consult-history)
("C-c k" . consult-kmacro)
("C-c m" . consult-man)
("C-c i" . consult-info)
([remap Info-search] . consult-info)
;; C-x bindings in `ctl-x-map'
("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command
("C-x b" . consult-buffer) ;; orig. switch-to-buffer
("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
("C-x 5 b" . consult-buffer-other-frame) ;; orig. switch-to-buffer-other-frame
("C-x t b" . consult-buffer-other-tab) ;; orig. switch-to-buffer-other-tab
("C-x r b" . consult-bookmark) ;; orig. bookmark-jump
("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer
;; Custom M-# bindings for fast register access
;; ("M-#" . consult-register-load)
;; ("M-'" . consult-register-store) ;; orig. abbrev-prefix-mark (unrelated)
;; ("C-M-#" . consult-register)
;; Other custom bindings
("M-y" . consult-yank-pop) ;; orig. yank-pop
;; M-g bindings in `goto-map'
("M-g e" . consult-compile-error)
("M-g f" . consult-flymake) ;; Alternative: consult-flycheck
("M-g g" . consult-goto-line) ;; orig. goto-line
("M-g M-g" . consult-goto-line) ;; orig. goto-line
("M-g o" . consult-outline) ;; Alternative: consult-org-heading
("M-g m" . consult-mark)
("M-g k" . consult-global-mark)
("M-g i" . consult-imenu)
("M-g I" . consult-imenu-multi)
;; C-s bindings in `search-map'
("C-s d" . consult-find) ;; Alternative: consult-fd
("C-s c" . consult-locate)
("C-s g" . consult-grep)
("C-s G" . consult-git-grep)
("C-s r" . consult-ripgrep)
("C-s l" . consult-line)
("C-s L" . consult-line-multi)
("C-s k" . consult-keep-lines)
("C-s u" . consult-focus-lines)
;; Isearch integration
;; ("M-s e" . consult-isearch-history)
;; :map isearch-mode-map
;; ("M-e" . consult-isearch-history) ;; orig. isearch-edit-string
;; ("M-s e" . consult-isearch-history) ;; orig. isearch-edit-string
;; ("M-s l" . consult-line) ;; needed by consult-line to detect isearch
;; ("M-s L" . consult-line-multi)
;; needed by consult-line to detect isearch
;; Minibuffer history
;; :map minibuffer-local-map
;; ("M-s" . consult-history) ;; orig. next-matching-history-element
;; ("M-r" . consult-history)
) ;; orig. previous-matching-history-element
;; Enable automatic preview at point in the *Completions* buffer. This is
;; relevant when you use the default completion UI.
:hook (completion-list-mode . consult-preview-at-point-mode)
;; The :init configuration is always executed (Not lazy)
:init
;; Optionally configure the register formatting. This improves the register
;; preview for `consult-register', `consult-register-load',
;; `consult-register-store' and the Emacs built-ins.
(setq register-preview-delay 0.5
register-preview-function #'consult-register-format)
;; Optionally tweak the register preview window.
;; This adds thin lines, sorting and hides the mode line of the window.
(advice-add #'register-preview :override #'consult-register-window)
;; Use Consult to select xref locations with preview
(setq xref-show-xrefs-function #'consult-xref
xref-show-definitions-function #'consult-xref)
;; Configure other variables and modes in the :config section,
;; after lazily loading the package.
:config
;; Optionally configure preview. The default value
;; is 'any, such that any key triggers the preview.
;; (setq consult-preview-key 'any)
;; (setq consult-preview-key "M-.")
;; (setq consult-preview-key '("S-<down>" "S-<up>"))
;; For some commands and buffer sources it is useful to configure the
;; :preview-key on a per-command basis using the `consult-customize' macro.
(consult-customize
consult-theme :preview-key '(:debounce 0.2 any)
consult-ripgrep consult-git-grep consult-grep
consult-bookmark consult-recent-file consult-xref
consult--source-bookmark consult--source-file-register
consult--source-recent-file consult--source-project-recent-file
;; :preview-key "M-."
:preview-key '(:debounce 0.4 any))
;; Optionally configure the narrowing key.
;; Both < and C-+ work reasonably well.
(setq consult-narrow-key "<") ;; "C-+"
;; Optionally make narrowing help available in the minibuffer.
;; You may want to use `embark-prefix-help-command' or which-key instead.
;; (keymap-set consult-narrow-map (concat consult-narrow-key " ?") #'consult-narrow-help)
)
(use-package marginalia
:init
(marginalia-mode))
(use-package embark
:bind
(("C-." . embark-act) ;; pick some comfortable binding
("C-;" . embark-dwim) ;; good alternative: M-.
("C-h B" . embark-bindings)) ;; alternative for `describe-bindings'
:init
;; Optionally replace the key help with a completing-read interface
(setq prefix-help-command #'embark-prefix-help-command)
;; Show the Embark target at point via Eldoc. You may adjust the
;; Eldoc strategy, if you want to see the documentation from
;; multiple providers. Beware that using this can be a little
;; jarring since the message shown in the minibuffer can be more
;; than one line, causing the modeline to move up and down:
;; (add-hook 'eldoc-documentation-functions #'embark-eldoc-first-target)
;; (setq eldoc-documentation-strategy #'eldoc-documentation-compose-eagerly)
:config
;; Hide the mode line of the Embark live/completions buffers
(add-to-list 'display-buffer-alist
'("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*"
nil
(window-parameters (mode-line-format . none)))))
;; Consult users will also want the embark-consult package.
(use-package embark-consult
:hook
(embark-collect-mode . consult-preview-at-point-mode))
;;;;;;;;;;;;;;;;;
;; Development ;;
;;;;;;;;;;;;;;;;;
(use-package markdown-mode
:commands (markdown-mode gfm-mode)
:mode (("\\.md\\'" . markdown-mode)
("README\\.md\\'" . gfm-mode)) ;GitHub Flavoured Markdown
;; :init (setq markdown-command "/usr/local/bin/multimarkdown")
)
;; popup completions
(use-package company
:diminish (company-mode . "")
:init (setq company-idle-delay 0.05)
:config (global-company-mode))
;; working with projects
(use-package projectile
:init
(projectile-mode +1)
:bind (:map projectile-mode-map
;; ("s-p" . projectile-command-map)
("C-c p" . projectile-command-map)))
;; File tree browser
;; (use-package treemacs
;; :bind
;; (:map global-map
;; ("M-0" . treemacs-select-window)
;; ("C-x t 1" . treemacs-delete-other-windows)
;; ("C-x t t" . treemacs)
;; ("C-x t d" . treemacs-select-directory)
;; ("C-x t B" . treemacs-bookmark)
;; ("C-x t C-t" . treemacs-find-file)
;; ("C-x t M-t" . treemacs-find-tag)))
;; Automate Tree-sitter grammar installation and mode remapping
(use-package treesit-auto
:custom
(treesit-auto-install 'prompt)
:config
(treesit-auto-add-to-auto-mode-alist 'all)
(global-treesit-auto-mode))
;; LSP with eglot
(use-package eglot
:hook (prog-mode . eglot-ensure)
:bind (:map eglot-mode-map
("C-c r" . eglot-rename)
("C-c o" . eglot-code-action-organize-imports)
("C-c f" . eglot-format-buffer)
("C-c h" . eldoc)))
;; https://www.emacswiki.org/emacs/RainbowDelimiters
;; (use-package rainbow-delimeters
;; :hook (prog-mode . rainbow-delimeters-mode)
(use-package flycheck
:init (global-flycheck-mode))
(use-package flycheck-eglot
:after (flycheck eglot)
:config
(global-flycheck-eglot-mode 1))
;; Git
(use-package magit)
;; Git diff
(use-package diff-hl
:config
(global-diff-hl-mode)
;; :hook (prog-mode . diff-hl-mode)
)
;; Github et al.
(use-package forge)
;; Golang
(use-package go-mode
:mode ("\\.go\\'" . go-mode))
;; :hook (go-mode . lsp-deferred)
(use-package gotest
)
;; Zig
(use-package zig-mode
:mode ("\\.zig\\'" . zig-mode))
;; Python
;; (use-package elpy
;; :init
;; (elpy-enable))
;;;;;;;;;;;;;
;; Clojure ;;
;;;;;;;;;;;;;
(use-package paredit
:init
;; :hook ((clojure-mode . paredit-mode)
;; elisp-mode . paredit-mode)
)
(use-package clojure-mode
:mode (("\\.clj\\'" . clojure-mode)
("\\.edn\\'" . clojure-mode)
("\\.cljs\\'" . clojurescript-mode)
("\\.cljc\\'" . clojurec-mode)))
;; Automatically load paredit when editing a lisp file
;; More at http://www.emacswiki.org/emacs/ParEdit
;; (autoload 'enable-paredit-mode "paredit" "Turn on pseudo-structural editing of Lisp code." t)
;; (add-hook 'emacs-lisp-mode-hook #'enable-paredit-mode)
;; (add-hook 'eval-expression-minibuffer-setup-hook #'enable-paredit-mode)
;; (add-hook 'ielm-mode-hook #'enable-paredit-mode)
;; (add-hook 'lisp-mode-hook #'enable-paredit-mode)
;; (add-hook 'lisp-interaction-mode-hook #'enable-paredit-mode)
;; (add-hook 'scheme-mode-hook #'enable-paredit-mode)
;; eldoc-mode shows documentation in the minibuffer when writing code
;; http://www.emacswiki.org/emacs/ElDoc
;; (add-hook 'emacs-lisp-mode-hook 'turn-on-eldoc-mode)
;; (add-hook 'lisp-interaction-mode-hook 'turn-on-eldoc-mode)
;; (add-hook 'ielm-mode-hook 'turn-on-eldoc-mode)
;; ;; Enable paredit for Clojure
;; (add-hook 'clojure-mode-hook 'enable-paredit-mode)
;; ;; This is useful for working with camel-case tokens, like names of
;; ;; Java classes (e.g. JavaClassName)
;; (add-hook 'clojure-mode-hook 'subword-mode)
;; ;; A little more syntax highlighting
;; (require 'clojure-mode-extra-font-locking)
;;;;;;;;;;;
;; Cider ;;
;;;;;;;;;;;
(use-package cider
:defer t
:diminish subword-mode)
;; (use-package cider
;; :hook
;; ;; enable paredit in your REPL
;; ;; provides minibuffer documentation for the code you're typing into the repl
;; ((cider-repl-mode . paredit-mode)
;; (cider-mode . eldoc-mode))
;; :config
;; (setq
;; ;; go right to the REPL buffer when it's finished connecting
;; cider-repl-pop-to-buffer-on-connect t
;; ;; When there's a cider error, show its buffer and switch to it
;; cider-show-error-buffer t
;; cider-auto-select-error-buffer t
;; )
;; )
;; ;; Use clojure mode for other extensions
;; (add-to-list 'auto-mode-alist '("\\.edn$" . clojure-mode))
;; (add-to-list 'auto-mode-alist '("\\.boot$" . clojure-mode))
;; (add-to-list 'auto-mode-alist '("\\.cljs.*$" . clojure-mode))
;; (add-to-list 'auto-mode-alist '("lein-env" . enh-ruby-mode))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment