2026-01-18 00:51:56 -05:00

353 lines
15 KiB
EmacsLisp

;;; ui.el --- Description -*- lexical-binding: t; -*-
;;
;; Copyright (C) 2026 Michael Chalupiak
;;
;; Author: Michael Chalupiak <mikec@archbox>
;; Maintainer: Michael Chalupiak <mikec@archbox>
;; Created: January 16, 2026
;; Modified: January 16, 2026
;; Version: 0.0.1
;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex text tools unix vc wp
;; Homepage: https://github.com/mikec/ui
;; Package-Requires: ((emacs "29.1"))
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; Description
;;
;;; Code:
(use-package corfu
;; Optional customizations
:custom
(corfu-cycle t) ;; Enable cycling for `corfu-next/previous'
;; (corfu-quit-at-boundary nil) ;; Never quit at completion boundary
;; (corfu-quit-no-match nil) ;; Never quit, even if there is no match
;; (corfu-preview-current nil) ;; Disable current candidate preview
;; (corfu-preselect 'prompt) ;; Preselect the prompt
;; (corfu-on-exact-match 'insert) ;; Configure handling of exact matches
;; Enable Corfu only for certain modes. See also `global-corfu-modes'.
;; :hook ((prog-mode . corfu-mode)
;; (shell-mode . corfu-mode)
;; (eshell-mode . corfu-mode))
:init
(setq corfu-auto t
corfu-auto-delay 0.05
corfu-auto-prefix 1
corfu-auto-trigger "." ;; Custom trigger characters
corfu-quit-no-match 'separator) ;; or t
;; Recommended: Enable Corfu globally. Recommended since many modes provide
;; Capfs and Dabbrev can be used globally (M-/). See also the customization
;; variable `global-corfu-modes' to exclude certain modes.
(global-corfu-mode)
;; Enable optional extension modes:
(corfu-history-mode)
(corfu-popupinfo-mode))
;; Add extensions
(use-package cape
;; Bind prefix keymap providing all Cape commands under a mnemonic key.
;; Press C-c p ? to for help.
:bind ("C-c p" . cape-prefix-map) ;; Alternative key: M-<tab>, M-p, M-+
;; Alternatively bind Cape commands individually.
;; :bind (("C-c p d" . cape-dabbrev)
;; ("C-c p h" . cape-history)
;; ("C-c p f" . cape-file)
;; ...)
:init
;; Add to the global default value of `completion-at-point-functions' which is
;; used by `completion-at-point'. The order of the functions matters, the
;; first function returning a result wins. Note that the list of buffer-local
;; completion functions takes precedence over the global list.
(add-hook 'prog-mode-hook
(defun +corfu-add-cape-file-h ()
(add-hook 'completion-at-point-functions #'cape-file -10 t)))
;; (add-hook 'completion-at-point-functions #'cape-dict -10 t)
;; (add-hook 'completion-at-point-functions #'cape-dabbrev -10 t)))
(add-hook 'text-mode-hook
(defun +corfu-add-cape-file-h ()
(add-hook 'completion-at-point-functions #'cape-file -10 t)))
;; (add-hook 'completion-at-point-functions #'cape-dict -10 t)
;; (add-hook 'completion-at-point-functions #'cape-dabbrev -10 t)))
(add-hook 'conf-mode-hook
(defun +corfu-add-cape-file-h ()
(add-hook 'completion-at-point-functions #'cape-file -10 t)))
;; (add-hook 'completion-at-point-functions #'cape-dict -10 t)
;; (add-hook 'completion-at-point-functions #'cape-dabbrev -10 t)))
;; (add-hook 'completion-at-point-functions #'cape-file)
;; (add-hook 'completion-at-point-functions #'cape-dabbrev)
;; (add-hook 'completion-at-point-functions #'cape-dict)
;; (add-hook 'completion-at-point-functions #'cape-emoji)
;; (add-hook 'completion-at-point-functions #'cape-elisp-block)
;; (add-hook 'completion-at-point-functions #'cape-history)
;; ...
)
(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-multiform-mode)
(vertico-mode)
(define-key vertico-map (kbd "DEL") #'vertico-directory-delete-char))
(defvar +vertico-transform-functions nil)
(cl-defmethod vertico--format-candidate :around
(cand prefix suffix index start &context ((not +vertico-transform-functions) null))
(dolist (fun (ensure-list +vertico-transform-functions))
(setq cand (funcall fun cand)))
(cl-call-next-method cand prefix suffix index start))
(defun +vertico-highlight-directory (file)
"If FILE ends with a slash, highlight it as a directory."
(if (string-suffix-p "/" file)
(propertize file 'face 'marginalia-file-priv-dir) ; or face 'dired-directory
file))
;; function to highlight enabled modes similar to counsel-M-x
(defun +vertico-highlight-enabled-mode (cmd)
"If MODE is enabled, highlight it as font-lock-constant-face."
(let ((sym (intern cmd)))
(if (or (eq sym major-mode)
(and
(memq sym minor-mode-list)
(boundp sym)))
(propertize cmd 'face 'font-lock-constant-face)
cmd)))
;; add-to-list works if 'file isn't already in the alist
;; setq can be used but will overwrite all existing values
(add-to-list 'vertico-multiform-categories
'(file
;; this is also defined in the wiki, uncomment if used
;; (vertico-sort-function . vertico-sort-directories-first)
(+vertico-transform-functions . +vertico-highlight-directory)))
(add-to-list 'vertico-multiform-commands
'(execute-extended-command
(+vertico-transform-functions . +vertico-highlight-enabled-mode)))
;; Enable rich annotations using the Marginalia package
(use-package marginalia
;; Bind `marginalia-cycle' locally in the minibuffer. To make the binding
;; available in the *Completions* buffer, add it to the
;; `completion-list-mode-map'.
:bind (:map minibuffer-local-map
("M-A" . marginalia-cycle))
;; The :init section is always executed.
:init
;; Marginalia must be activated in the :init section of use-package such that
;; the mode gets enabled right away. Note that this forces loading the
;; package.
(marginalia-mode))
;; Example configuration for 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 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
;; The :init configuration is always executed (Not lazy)
:init
;; Tweak the register preview for `consult-register-load',
;; `consult-register-store' and the built-in commands. This improves the
;; register formatting, adds thin separator lines, register sorting and hides
;; the window mode line.
(advice-add #'register-preview :override #'consult-register-window)
(setq register-preview-delay 0.5)
(setq consult-async-min-input 1)
;; 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-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.
(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 consult-eglot
:ensure t
:defer t)
(use-package marginalia
:ensure t
:config
(marginalia-mode))
(use-package embark
:ensure t
: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)
;; Add Embark to the mouse context menu. Also enable `context-menu-mode'.
;; (context-menu-mode 1)
;; (add-hook 'context-menu-functions #'embark-context-menu 100)
: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
:ensure t ; only need to install it, embark loads it after consult if found
:hook
(embark-collect-mode . consult-preview-at-point-mode))
;; Optionally use the `orderless' completion style.
(use-package orderless
:custom
;; Configure a custom style dispatcher (see the Consult wiki)
;; (orderless-style-dispatchers '(+orderless-consult-dispatch orderless-affix-dispatch))
;; (orderless-component-separator #'orderless-escapable-split-on-space)
(completion-styles '(orderless basic))
(completion-category-overrides '((file (styles partial-completion))))
(completion-category-defaults nil) ;; Disable defaults, use our settings
(completion-pcm-leading-wildcard t)) ;; Emacs 31: partial-completion behaves like substring
;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
:init
(savehist-mode))
(use-package indent-bars
:config
(setq
;; Show indent guides starting from the first column.
indent-bars-starting-column 0
;; Make indent guides subtle; the default is too distractingly colorful.
indent-bars-width-frac 0.15 ; make bitmaps thinner
indent-bars-color-by-depth nil
indent-bars-color '(font-lock-comment-face :face-bg nil :blend 0.425)
;; Don't highlight current level indentation; it's distracting and is
;; unnecessary overhead for little benefit.
indent-bars-highlight-current-depth nil)
:custom
(indent-bars-no-descend-lists t) ; no extra bars in continued func arg lists
(indent-bars-treesit-support t)
(indent-bars-treesit-ignore-blank-lines-types '("module"))
;; Add other languages as needed
;; (indent-bars-treesit-scope '((python function_definition class_definition for_statement
;; if_statement with_statement while_statement)))
;; Note: wrap may not be needed if no-descend-list is enough
;;(indent-bars-treesit-wrap '((python argument_list parameters ; for python, as an example
;; list list_comprehension
;; dictionary dictionary_comprehension
;; parenthesized_expression subscript)))
:hook ((prog-mode text-mode) . indent-bars-mode))
(use-package dashboard
:ensure t
:config
(dashboard-setup-startup-hook))
(provide 'ui)
;;; ui.el ends here