diff options
| author | Mike Vink <ivi@vinkies.net> | 2025-12-16 17:47:19 +0100 |
|---|---|---|
| committer | Mike Vink <ivi@vinkies.net> | 2025-12-16 17:47:19 +0100 |
| commit | 20681162fb2fd22ca3892168efbc5695bec25bd8 (patch) | |
| tree | 5fee7589c4f5245dc59daa54a3f1dd7614e91fa1 | |
| parent | e7c98e63190e2d8a329f9dba445cc529ddba717f (diff) | |
initel
| -rw-r--r-- | .config/emacs/init.el | 304 |
1 files changed, 194 insertions, 110 deletions
diff --git a/.config/emacs/init.el b/.config/emacs/init.el index 39a248d..405e292 100644 --- a/.config/emacs/init.el +++ b/.config/emacs/init.el @@ -14,22 +14,26 @@ ;; This overrides the default mark-in-region with a prettier-looking one, ;; and provides a couple extra commands -(use-package visual-regexp) +(use-package visual-regexp + :ensure t) ;; Emacs incremental search doesn't work with multiple cursors, but this fixes that (use-package phi-search + :ensure t :bind (("C-s" . phi-search) - ("C-r" . phi-search-backward))) + ("C-r" . phi-search-backward))) ;; Probably the first thing you'd miss is undo and redo, which requires an extra package ;; to work like it does in kakoune (and almost every other editor). (use-package undo-tree + :ensure t :config (setq undo-tree-auto-save-history nil) (global-undo-tree-mode)) ;; Enable Vertico. (use-package vertico + :ensure t :custom ;; (vertico-scroll-margin 0) ;; Different scroll margin (vertico-count 20) ;; Show more candidates @@ -40,11 +44,13 @@ ;; Persist history over Emacs restarts. Vertico sorts by history position. (use-package savehist + :ensure t :init (savehist-mode)) ;; Emacs minibuffer configurations. (use-package emacs + :ensure t :custom ;; TAB cycle if there are only few candidates ;; (completion-cycle-threshold 3) @@ -73,10 +79,11 @@ (read-extended-command-predicate #'command-completion-default-include-p) ;; Do not allow the cursor in the minibuffer prompt (minibuffer-prompt-properties - '(read-only t cursor-intangible t face minibuffer-prompt))) + '(read-only t cursor-intangible t face minibuffer-prompt))) ;; Optionally use the `orderless' completion style. (use-package orderless + :ensure t :custom ;; Configure a custom style dispatcher (see the Consult wiki) ;; (orderless-style-dispatchers '(+orderless-consult-dispatch orderless-affix-dispatch)) @@ -87,6 +94,7 @@ (completion-pcm-leading-wildcard t)) ;; Emacs 31: partial-completion behaves like substring (use-package corfu + :ensure t ;; TAB-and-Go customizations :custom (corfu-cycle t) ;; Enable cycling for `corfu-next/previous' @@ -99,8 +107,8 @@ (define-key corfu-map [remap previous-line] nil)) (setq corfu-auto t - corfu-auto-delay 0 ;; TOO SMALL - NOT RECOMMENDED! - corfu-auto-prefix 0) ;; TOO SMALL - NOT RECOMMENDED! + corfu-auto-delay 0 ;; TOO SMALL - NOT RECOMMENDED! + corfu-auto-prefix 0) ;; TOO SMALL - NOT RECOMMENDED! (add-hook 'corfu-mode-hook @@ -114,15 +122,16 @@ (defun my-capf-prepend-cape-dabbrev () "Make `cape-dabbrev` the first CAPF in this buffer." (setq-local completion-at-point-functions - (cons #'cape-dabbrev - (remove #'cape-dabbrev completion-at-point-functions)))) + (cons #'cape-dabbrev + (remove #'cape-dabbrev completion-at-point-functions)))) (add-hook 'after-change-major-mode-hook #'my-capf-prepend-cape-dabbrev) ;; Use Dabbrev with Corfu! (use-package dabbrev + :ensure t ;; Swap M-/ and C-M-/ :bind (("M-/" . dabbrev-completion) - ("C-M-/" . dabbrev-expand)) + ("C-M-/" . dabbrev-expand)) :config (add-to-list 'dabbrev-ignored-buffer-regexps "\\` ") (add-to-list 'dabbrev-ignored-buffer-modes 'authinfo-mode) @@ -143,60 +152,61 @@ ;; Example configuration for Consult (use-package consult + :ensure t ;; 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 r" . consult-grep-match) - ("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) - ;; M-s bindings in `search-map' - ("M-s d" . consult-find) ;; Alternative: consult-fd - ("M-s c" . consult-locate) - ("M-s g" . consult-grep) - ("M-s G" . consult-git-grep) - ("M-s r" . consult-ripgrep) - ("M-s l" . consult-line) - ("M-s L" . consult-line-multi) - ("M-s k" . consult-keep-lines) - ("M-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 + ("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 r" . consult-grep-match) + ("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) + ;; M-s bindings in `search-map' + ("M-s d" . consult-find) ;; Alternative: consult-fd + ("M-s c" . consult-locate) + ("M-s g" . consult-grep) + ("M-s G" . consult-git-grep) + ("M-s r" . consult-ripgrep) + ("M-s l" . consult-line) + ("M-s L" . consult-line-multi) + ("M-s k" . consult-keep-lines) + ("M-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. @@ -214,7 +224,7 @@ ;; Use Consult to select xref locations with preview (setq xref-show-xrefs-function #'consult-xref - xref-show-definitions-function #'consult-xref) + xref-show-definitions-function #'consult-xref) ;; Configure other variables and modes in the :config section, ;; after lazily loading the package. @@ -228,13 +238,13 @@ ;; 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-man - 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)) + consult-theme :preview-key '(:debounce 0.2 any) + consult-ripgrep consult-git-grep consult-grep consult-man + 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. @@ -243,46 +253,46 @@ ;; 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) -) + ) (unless (display-graphic-p) (add-hook 'after-make-frame-functions - '(lambda - ;; Take advantage of iterm2's CSI u support (https://gitlab.com/gnachman/iterm2/-/issues/8382). - (xterm--init-modify-other-keys) - - ;; Courtesy https://emacs.stackexchange.com/a/13957, modified per - ;; https://gitlab.com/gnachman/iterm2/-/issues/8382#note_365264207 - (defun character-apply-modifiers (c &rest modifiers) - "Apply modifiers to the character C. + '(lambda + ;; Take advantage of iterm2's CSI u support (https://gitlab.com/gnachman/iterm2/-/issues/8382). + (xterm--init-modify-other-keys) + + ;; Courtesy https://emacs.stackexchange.com/a/13957, modified per + ;; https://gitlab.com/gnachman/iterm2/-/issues/8382#note_365264207 + (defun character-apply-modifiers (c &rest modifiers) + "Apply modifiers to the character C. MODIFIERS must be a list of symbols amongst (meta control shift). Return an event vector." - (if (memq 'control modifiers) (setq c (if (and (<= ?a c) (<= c ?z)) + (if (memq 'control modifiers) (setq c (if (and (<= ?a c) (<= c ?z)) (logand c ?\x1f) - (logior (lsh 1 26) c)))) - (if (memq 'meta modifiers) (setq c (logior (lsh 1 27) c))) - (if (memq 'shift modifiers) (setq c (logior (lsh 1 25) c))) - (vector c)) - (when (and (boundp 'xterm-extra-capabilities) (boundp 'xterm-function-map)) - (let ((c 32)) - (while (<= c 126) - (mapc (lambda (x) - (define-key xterm-function-map (format (car x) c) - (apply 'character-apply-modifiers c (cdr x)))) - '(;; with ?.VT100.formatOtherKeys: 0 - ("\e\[27;3;%d~" meta) - ("\e\[27;5;%d~" control) - ("\e\[27;6;%d~" control shift) - ("\e\[27;7;%d~" control meta) - ("\e\[27;8;%d~" control meta shift) - ;; with ?.VT100.formatOtherKeys: 1 - ("\e\[%d;3u" meta) - ("\e\[%d;5u" control) - ("\e\[%d;6u" control shift) - ("\e\[%d;7u" control meta) - ("\e\[%d;8u" control meta shift))) - (setq c (1+ c))))) - ))) + (logior (lsh 1 26) c)))) + (if (memq 'meta modifiers) (setq c (logior (lsh 1 27) c))) + (if (memq 'shift modifiers) (setq c (logior (lsh 1 25) c))) + (vector c)) + (when (and (boundp 'xterm-extra-capabilities) (boundp 'xterm-function-map)) + (let ((c 32)) + (while (<= c 126) + (mapc (lambda (x) + (define-key xterm-function-map (format (car x) c) + (apply 'character-apply-modifiers c (cdr x)))) + '(;; with ?.VT100.formatOtherKeys: 0 + ("\e\[27;3;%d~" meta) + ("\e\[27;5;%d~" control) + ("\e\[27;6;%d~" control shift) + ("\e\[27;7;%d~" control meta) + ("\e\[27;8;%d~" control meta shift) + ;; with ?.VT100.formatOtherKeys: 1 + ("\e\[%d;3u" meta) + ("\e\[%d;5u" control) + ("\e\[%d;6u" control shift) + ("\e\[%d;7u" control meta) + ("\e\[%d;8u" control meta shift))) + (setq c (1+ c))))) + ))) (keymap-global-set "C-\\" 'undo-tree-undo) (keymap-global-set "C-|" 'undo-tree-redo) @@ -304,6 +314,76 @@ Return an event vector." :env nil))) +(add-hook 'multiple-cursors-mode-hook (lambda() (corfu-mode -1))) + +(global-set-key (kbd "M-n") 'mc/mark-next-like-this) +(global-set-key (kbd "M-p") 'mc/mark-previous-like-this) +(global-set-key (kbd "M-N") 'mc/skip-to-next-like-this) +(global-set-key (kbd "M-P") 'mc/skip-to-previous-like-this) +(global-set-key (kbd "C-S-c C-S-c") 'mc/edit-lines) +(global-set-key (kbd "C-c s") 'vr/mc-mark) +(global-set-key (kbd "C-c C-,") 'mc/remove-current-cursor) + +(keymap-set yaml-pro-ts-mode-map "C-M-n" #'yaml-pro-ts-next-subtree) +(keymap-set yaml-pro-ts-mode-map "C-M-p" #'yaml-pro-ts-prev-subtree) +(keymap-set yaml-pro-ts-mode-map "C-M-u" #'yaml-pro-ts-up-level) +(keymap-set yaml-pro-ts-mode-map "C-M-d" #'yaml-pro-ts-down-level) +(keymap-set yaml-pro-ts-mode-map "C-M-k" #'yaml-pro-ts-kill-subtree) +(keymap-set yaml-pro-ts-mode-map "C-M-<backspace>" #'yaml-pro-ts-kill-subtree) +(keymap-set yaml-pro-ts-mode-map "C-M-a" #'yaml-pro-ts-first-sibling) +(keymap-set yaml-pro-ts-mode-map "C-M-e" #'yaml-pro-ts-last-sibling) + +(defvar-keymap my/yaml-pro/tree-repeat-map + :repeat t + "n" #'yaml-pro-ts-next-subtree + "p" #'yaml-pro-ts-prev-subtree + "u" #'yaml-pro-ts-up-level + "d" #'yaml-pro-ts-down-level + "m" #'yaml-pro-ts-mark-subtree + "k" #'yaml-pro-ts-kill-subtree + "a" #'yaml-pro-ts-first-sibling + "e" #'yaml-pro-ts-last-sibling + "SPC" #'my/yaml-pro/set-mark) + +(defun my/yaml-pro/set-mark () + (interactive) + (my/region/set-mark 'my/yaml-pro/set-mark)) + +(defun my/region/set-mark (command-name) + (if (eq last-command command-name) + (if (region-active-p) + (progn + (deactivate-mark) + (message "Mark deactivated")) + (activate-mark) + (message "Mark activated")) + (set-mark-command nil))) + + +(defun my/pick-line-from-shell (command) + "Run COMMAND, prompt user to pick one output line, return the chosen line." + (let* ((out (string-trim-right (shell-command-to-string command))) + (lines (split-string out "\n" t))) + (completing-read "Pick: " lines nil t))) + +(defun my/issue-commit () + "Make a commit with a message starting with ISSUE-ID." + + (interactive) + (let* + ((issue (my/pick-line-from-shell "gh issue list --assignee='ivi-vink'")) + (id (save-match-data (when (string-match "\\([0-9]+\\).*" issue) (match-string 1 issue))))) + (magit-commit-create + (append + (list "-e" (format "--trailer=issue:#%s" id)) + (magit-commit-arguments))) + )) + +(use-package magit + :ensure t + :config + (transient-append-suffix 'magit-commit "c" '("I" "Issue commit" my/issue-commit))) + (custom-set-variables ;; custom-set-variables was added by Custom. @@ -311,20 +391,24 @@ Return an event vector." ;; Your init file should contain only one such instance. ;; If there is more than one, they won't work right. '(custom-safe-themes - '("c5975101a4597094704ee78f89fb9ad872f965a84fb52d3e01b9102168e8dc40" + '("0325a6b5eea7e5febae709dab35ec8648908af12cf2d2b569bedc8da0a3a81c1" + "4990532659bb6a285fee01ede3dfa1b1bdf302c5c3c8de9fad9b6bc63a9252f7" + "f1e8339b04aef8f145dd4782d03499d9d716fdc0361319411ac2efc603249326" + "c5975101a4597094704ee78f89fb9ad872f965a84fb52d3e01b9102168e8dc40" "6bf350570e023cd6e5b4337a6571c0325cec3f575963ac7de6832803df4d210a" "0adcffc4894e2dd21283672da7c3d1025b5586bcef770fdc3e2616bdb2a771cd" "5e39e95c703e17a743fb05a132d727aa1d69d9d2c9cde9353f5350e545c793d4" "01a9797244146bbae39b18ef37e6f2ca5bebded90d9fe3a2f342a9e863aaa4fd" default)) '(package-selected-packages - '(## async auctex cape consult corfu counsel dap-mode dash-functional - direnv eat embark embark-consult go-mode gruber-darker-theme - helm ido-completing-read+ ivy kakoune lsp-mode magit marginalia - meow modus-themes multiple-cursors nix-mode orderless - phi-search rust-mode smex spacious-padding terraform-mode - treemacs undo-tree vertico visual-regexp visual-regexp-steroids - vterm yaml-mode yaml-pro))) + '(## async auctex cape consult corfu counsel dap-dlv-go dap-mode + dash-functional direnv doom-themes eat embark embark-consult + flycheck go-mode gruber-darker-theme helm ido-completing-read+ + ivy kakoune lsp-mode magit marginalia mc-extras meow + modus-themes multiple-cursors nix-mode orderless phi-search + rust-mode smex spacious-padding terraform-mode treemacs + undo-tree vertico visual-regexp visual-regexp-steroids vterm + yaml-mode yaml-pro))) (custom-set-faces ;; custom-set-faces was added by Custom. ;; If you edit it by hand, you could mess it up, so be careful. |
