diff options
author | Kjetil Orbekk <kj@orbekk.com> | 2024-04-30 21:21:26 -0400 |
---|---|---|
committer | Kjetil Orbekk <kj@orbekk.com> | 2024-04-30 21:21:26 -0400 |
commit | 56c5eece0c4beeaf43c15e9fc81c6c79e1f23f78 (patch) | |
tree | d8c7ed44c463724c009ddba49485fda56a5cc9c2 | |
parent | b9abc9025780b81713422c59206d0e30518646a6 (diff) |
Move more stuff to init.el
-rw-r--r-- | emacs/.config/emacs/init.el | 298 | ||||
-rw-r--r-- | emacs/.config/emacs/lisp/kj-init.el | 281 |
2 files changed, 295 insertions, 284 deletions
diff --git a/emacs/.config/emacs/init.el b/emacs/.config/emacs/init.el index 6435562..07f3b6f 100644 --- a/emacs/.config/emacs/init.el +++ b/emacs/.config/emacs/init.el @@ -47,6 +47,7 @@ bookmark-file (expand-file-name "boomarks" kj/cache-dir) use-short-answers t outline-minor-mode-cycle t + outline-minor-mode-highlight 'override fast-but-imprecise-scrolling t visible-bell t auto-save-list-file-prefix (expand-file-name @@ -54,17 +55,270 @@ alert-default-style 'libnotify use-dialog-box nil - display-time-24hr-format t) + display-time-24hr-format t + + next-screen-context-lines 10) (load custom-file :noerror t) -(global-hl-line-mode 1) -(global-auto-revert-mode 1) + +(use-package emacs + :elpaca nil + :defer 1 + :init + (global-hl-line-mode 1) + (global-auto-revert-mode 1)) + +;;;; Navigation + +(use-package avy + :bind + (("C-c l" . avy-goto-char) + ("C-c n" . avy-goto-line)) + :config + (setq avy-keys '(?a ?o ?e ?u ?i ?d ?h ?t ?n ?s)) + (defun avy-action-embark (pt) + (unwind-protect + (save-excursion + (goto-char pt) + (embark-act)) + (select-window + (cdr (ring-ref avy-ring 0)))) + t) + (setf (alist-get ?. avy-dispatch-alist) 'avy-action-embark) + (define-key isearch-mode-map (kbd "M-j") 'avy-isearch)) + +(winner-mode 1) + +(use-package ace-window + :bind + (("C-c e" . ace-window)) + :config + (setq aw-dispatch-always t) + (setq aw-keys '(?a ?o ?e ?u ?i ?d ?h ?t ?n ?s)) + ;; Make ace window more visible + ;; (custom-set-faces! + ;; '(aw-leading-char-face + ;; :foreground "white" :background "red" + ;; :weight bold :height 2.5 :box (:line-width 10 :color "red"))) + ) + +(defun kj/balance-main-window () + (balance-windows (window-main-window))) + +;; Prefer horizontal splits. +(setq split-height-threshold 100) + +(defun kj/split-window-below () + (interactive) + (split-window-below) + (kj/balance-main-window) + (other-window 1)) + +(defun kj/split-window-right () + (interactive) + (split-window-right) + (kj/balance-main-window) + (other-window 1)) + +(global-set-key (kbd "C-x 3") #'kj/split-window-right) +(global-set-key (kbd "C-x 2") #'kj/split-window-below) + +;;;; Completion +(use-package embark + :ensure t + + :bind + (("C-." . embark-act) + ("C-;" . embark-dwim) + ("C-h C-b" . embark-bindings)) + + :init + (setq prefix-help-command #'embark-prefix-help-command) + + :config + (defun find-file-keeping-default-directory (filename) + (let ((dir default-directory)) + (with-current-buffer (find-file filename) + (setq-local default-directory dir)))) + (define-key embark-file-map "@" 'find-file-keeping-default-directory) + + ;; Hide the mode line of the Embark live/completions buffers + (add-to-list 'display-buffer-alist + '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*" + . + (window-parameters (mode-line-format . none))))) + +(use-package vertico + :init + (vertico-mode)) + +(use-package marginalia + :bind + (:map minibuffer-local-map + ("M-n" . marginalia-cycle)) + :init + (marginalia-mode)) + +(use-package embark-consult + :ensure t + :after (embark consult) + :demand t + :hook (embark-mode . consult-preview-at-point-mode)) + +(defun kj/consult-ripgrep-here (&optional dir initial) + (interactive "P") + (unless dir + (setq dir default-directory)) + (consult-ripgrep dir initial)) + +;; Example configuration for Consult +(use-package consult + ;; Replace bindings. Lazily loaded due by `use-package'. + :bind (;; C-c bindings (mode-specific-map) + ("C-c h" . kj/consult-history) + ;;("C-c m" . consult-mode-command) + ("C-c k" . consult-kmacro) + ;; C-x bindings (ctl-x-map) + ("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command + ("C-x b" . consult-buffer) ;; orig. switch-to-buffer + ("C-x C-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 r b" . consult-bookmark) ;; orig. bookmark-jump + ("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer + ("C-c f r" . consult-recent-file) + ;; 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 + ("<help> a" . consult-apropos) ;; orig. apropos-command + ;; M-g bindings (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) + ;; M-s bindings (search-map) + ("M-s d" . consult-find) + ("M-s D" . consult-locate) + ;; ("M-s g" . consult-grep) + ("M-s G" . consult-git-grep) + ("M-s r" . consult-ripgrep) + ("M-s R" . kj/consult-ripgrep-here) + ("M-s l" . consult-line) + ("M-s L" . consult-line-multi) + ("M-s m" . consult-multi-occur) + ("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" . kj/consult-history) ;; orig. next-matching-history-element + ("M-r" . kj/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 + + ;; Use consult for completion. + (setq completion-in-region-function #'consult-completion-in-region) + + ;; Optionally configure preview. The default value + ;; is 'any, such that any key triggers the preview. + (setq consult-preview-key '(:debounce 0.3 any)) + ;; (setq consult-preview-key (kbd "M-.")) + ;; (setq consult-preview-key (list (kbd "<S-down>") (kbd "<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-recent-file + ;; consult--source-project-recent-file + ;; :preview-key (kbd "M-.")) + + ;; Optionally configure the narrowing key. + ;; Both < and C-+ work reasonably well. + (setq consult-narrow-key "<") ;; (kbd "C-+") + + (setq consult-ripgrep-args + "rg --null --line-buffered --color=never --max-columns=1000 --path-separator / --smart-case --no-heading --with-filename --line-number --search-zip --hidden") + + ;; Optionally make narrowing help available in the minibuffer. + ;; You may want to use `embark-prefix-help-command' or which-key instead. + ;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help) + + ;; By default `consult-project-function' uses `project-root' from project.el. + ;; Optionally configure a different project root function. + ;; There are multiple reasonable alternatives to chose from. + ;;;; 1. project.el (the default) + ;;(setq consult-project-function #'consult--default-project-function) + ;;;; 2. projectile.el (projectile-project-root) + (autoload 'projectile-project-root "projectile") + (setq consult-project-function (lambda (_) (projectile-project-root))) + ;;;; 3. vc.el (vc-root-dir) + ;; (setq consult-project-function (lambda (_) (vc-root-dir))) + ;;;; 4. locate-dominating-file + ;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git"))) + ) + +(use-package orderless + :init + (setq completion-styles '(orderless basic) + completion-category-defaults nil + completion-category-overrides '((file (styles partial-completion))))) + ;;;; Appearance (use-package emacs :elpaca nil :init + (column-number-mode) + (set-fringe-mode 10)) + +(use-package rainbow-delimiters + :defer t + :hook (prog-mode . rainbow-delimiters-mode)) + +(use-package emacs + :elpaca nil + :init (setq-default show-trailing-whitespace t) (dolist (mode '(calendar-mode-hook eshell-mode-hook @@ -164,6 +418,44 @@ (use-package doom-themes) +;;;; Shell and terminal +(setq shell-prompt-pattern "^[^#$%>\n]*[#$%>❯] *" + explicit-shell-file-name "zsh" + explicit-zsh-args '("--login" "--interactive") + comint-use-prompt-regexp t) +(defun kj/shell-buffer-name () + (concat "*shell:" default-directory "*")) + +(defun kj/shell-here () + (interactive) + (let ((buffer + (shell (kj/shell-buffer-name)))) + (with-current-buffer buffer + (let* ((proc (get-buffer-process (current-buffer))) + (sentinel (process-sentinel proc))) + (set-process-sentinel + proc + `(lambda (proc signal) + (funcall ',sentinel proc signal) + (and (memq (process-status proc) '(exit signal)) + (buffer-live-p (process-buffer proc)) + (message "Shell died, killing buffer %s" + (process-buffer proc)) + (kill-buffer (process-buffer proc))))))))) + +(use-package coterm + :config + (coterm-mode 1)) +(add-to-list 'comint-output-filter-functions + 'comint-osc-process-output) + +;; Update buffer name to reflect directory. +(advice-add 'cd :after + (defun kj/maybe-rename-shell (&rest args) + (and (derived-mode-p 'shell-mode) + (rename-buffer + (kj/shell-buffer-name))))) + ;;;; Include modules in lisp/ (defvar kj/module-directory (expand-file-name "lisp" user-emacs-directory)) (push kj/module-directory load-path) diff --git a/emacs/.config/emacs/lisp/kj-init.el b/emacs/.config/emacs/lisp/kj-init.el index 40dee7d..ce1f896 100644 --- a/emacs/.config/emacs/lisp/kj-init.el +++ b/emacs/.config/emacs/lisp/kj-init.el @@ -1,154 +1,11 @@ ;;; -*- lexical-binding: t; -*- -;; `M-x shell` settings -(setq shell-prompt-pattern "^[^#$%>\n]*[#$%>❯] *" - explicit-shell-file-name "zsh" - explicit-zsh-args '("--login" "--interactive") - comint-use-prompt-regexp t) -(defun kj/shell-buffer-name () - (concat "*shell:" default-directory "*")) - -(defun kj/shell-here () - (interactive) - (let ((buffer - (shell (kj/shell-buffer-name)))) - (with-current-buffer buffer - (let* ((proc (get-buffer-process (current-buffer))) - (sentinel (process-sentinel proc))) - (set-process-sentinel - proc - `(lambda (proc signal) - (funcall ',sentinel proc signal) - (and (memq (process-status proc) '(exit signal)) - (buffer-live-p (process-buffer proc)) - (message "Shell died, killing buffer %s" - (process-buffer proc)) - (kill-buffer (process-buffer proc))))))))) - -;;; Shell setup. -(use-package coterm - :config - (coterm-mode 1)) -(add-to-list 'comint-output-filter-functions - 'comint-osc-process-output) - -;; Update buffer name to reflect directory. -(advice-add 'cd :after - (defun kj/maybe-rename-shell (&rest args) - (and (derived-mode-p 'shell-mode) - (rename-buffer - (kj/shell-buffer-name))))) - -(use-package rainbow-delimiters - :defer t - :hook (prog-mode . rainbow-delimiters-mode) - ) - -(column-number-mode) -(set-fringe-mode 10) -(setq next-screen-context-lines 10) - -(use-package avy - :bind - (("C-c l" . avy-goto-char) - ("C-c n" . avy-goto-line)) - :config - (setq avy-keys '(?a ?o ?e ?u ?i ?d ?h ?t ?n ?s)) - (defun avy-action-embark (pt) - (unwind-protect - (save-excursion - (goto-char pt) - (embark-act)) - (select-window - (cdr (ring-ref avy-ring 0)))) - t) - -(setf (alist-get ?. avy-dispatch-alist) 'avy-action-embark)) -(define-key isearch-mode-map (kbd "M-j") 'avy-isearch) - -(winner-mode +1) - -(use-package ace-window - :bind - (("C-c e" . ace-window)) - :config - (setq aw-dispatch-always t) - (setq aw-keys '(?a ?o ?e ?u ?i ?d ?h ?t ?n ?s)) - ;; Make ace window more visible - ;; (custom-set-faces! - ;; '(aw-leading-char-face - ;; :foreground "white" :background "red" - ;; :weight bold :height 2.5 :box (:line-width 10 :color "red"))) - ) - -(defun kj/balance-main-window () - (balance-windows (window-main-window))) - -;; Prefer horizontal splits. -(setq split-height-threshold 100) - -(defun kj/split-window-below () - (interactive) - (split-window-below) - (kj/balance-main-window) - (other-window 1)) - -(defun kj/split-window-right () - (interactive) - (split-window-right) - (kj/balance-main-window) - (other-window 1)) - -(global-set-key (kbd "C-x 3") #'kj/split-window-right) -(global-set-key (kbd "C-x 2") #'kj/split-window-below) - -(use-package vertico - :init - (vertico-mode)) - ;; Rebind C-x? (global-set-key (kbd "C-t") 'ctrl-x-map) (define-key global-map (kbd "C-t") ctl-x-map) ;; (define-key key-translation-map "\C-t" "\C-t") ;; (define-key key-translation-map "\C-x" "\C-t") -(use-package marginalia - :bind - (:map minibuffer-local-map - ("M-n" . marginalia-cycle)) - :init - (marginalia-mode)) - -(use-package embark - :ensure t - - :bind - (("C-." . embark-act) - ("C-;" . embark-dwim) - ("C-h C-b" . embark-bindings)) - - :init - (setq prefix-help-command #'embark-prefix-help-command) - - :config - (defun find-file-keeping-default-directory (filename) - (let ((dir default-directory)) - (with-current-buffer (find-file filename) - (setq-local default-directory dir)))) - (define-key embark-file-map "@" 'find-file-keeping-default-directory) - - ;; Hide the mode line of the Embark live/completions buffers - (add-to-list 'display-buffer-alist - '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*" - . - (window-parameters (mode-line-format . none))))) - -(use-package embark-consult - :ensure t - :after (embark consult) - :demand t - :hook (embark-mode . consult-preview-at-point-mode)) - ;; For editing grep buffers. (use-package wgrep) (use-package deadgrep @@ -169,144 +26,6 @@ (setq global-mark-ring-max 500 mark-ring-max 16) -(defun kj/consult-ripgrep-here (&optional dir initial) - (interactive "P") - (unless dir - (setq dir default-directory)) - (consult-ripgrep dir initial)) - -;; Example configuration for Consult -(use-package consult - ;; Replace bindings. Lazily loaded due by `use-package'. - :bind (;; C-c bindings (mode-specific-map) - ("C-c h" . kj/consult-history) - ;;("C-c m" . consult-mode-command) - ("C-c k" . consult-kmacro) - ;; C-x bindings (ctl-x-map) - ("C-x M-:" . consult-complex-command) ;; orig. repeat-complex-command - ("C-x b" . consult-buffer) ;; orig. switch-to-buffer - ("C-x C-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 r b" . consult-bookmark) ;; orig. bookmark-jump - ("C-x p b" . consult-project-buffer) ;; orig. project-switch-to-buffer - ("C-c f r" . consult-recent-file) - ;; 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 - ("<help> a" . consult-apropos) ;; orig. apropos-command - ;; M-g bindings (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) - ;; M-s bindings (search-map) - ("M-s d" . consult-find) - ("M-s D" . consult-locate) - ;; ("M-s g" . consult-grep) - ("M-s G" . consult-git-grep) - ("M-s r" . consult-ripgrep) - ("M-s R" . kj/consult-ripgrep-here) - ("M-s l" . consult-line) - ("M-s L" . consult-line-multi) - ("M-s m" . consult-multi-occur) - ("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" . kj/consult-history) ;; orig. next-matching-history-element - ("M-r" . kj/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 - - ;; Use consult for completion. - (setq completion-in-region-function #'consult-completion-in-region) - - ;; Optionally configure preview. The default value - ;; is 'any, such that any key triggers the preview. - (setq consult-preview-key '(:debounce 0.3 any)) - ;; (setq consult-preview-key (kbd "M-.")) - ;; (setq consult-preview-key (list (kbd "<S-down>") (kbd "<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-recent-file - ;; consult--source-project-recent-file - ;; :preview-key (kbd "M-.")) - - ;; Optionally configure the narrowing key. - ;; Both < and C-+ work reasonably well. - (setq consult-narrow-key "<") ;; (kbd "C-+") - - (setq consult-ripgrep-args - "rg --null --line-buffered --color=never --max-columns=1000 --path-separator / --smart-case --no-heading --with-filename --line-number --search-zip --hidden") - - ;; Optionally make narrowing help available in the minibuffer. - ;; You may want to use `embark-prefix-help-command' or which-key instead. - ;; (define-key consult-narrow-map (vconcat consult-narrow-key "?") #'consult-narrow-help) - - ;; By default `consult-project-function' uses `project-root' from project.el. - ;; Optionally configure a different project root function. - ;; There are multiple reasonable alternatives to chose from. - ;;;; 1. project.el (the default) - ;;(setq consult-project-function #'consult--default-project-function) - ;;;; 2. projectile.el (projectile-project-root) - (autoload 'projectile-project-root "projectile") - (setq consult-project-function (lambda (_) (projectile-project-root))) - ;;;; 3. vc.el (vc-root-dir) - ;; (setq consult-project-function (lambda (_) (vc-root-dir))) - ;;;; 4. locate-dominating-file - ;; (setq consult-project-function (lambda (_) (locate-dominating-file "." ".git"))) - ) - -(use-package orderless - :init - (setq completion-styles '(orderless basic) - completion-category-defaults nil - completion-category-overrides '((file (styles partial-completion))))) - (use-package which-key :init (which-key-mode)) |