From 2aae06f23408be081a451de38111dd32c1cf07e7 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 20 Mar 2026 16:38:09 +0100 Subject: emacs: Use global-completion-previde-mode --- .config/emacs/modules/mm-completion.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to '.config/emacs/modules/mm-completion.el') diff --git a/.config/emacs/modules/mm-completion.el b/.config/emacs/modules/mm-completion.el index 79da064..74740b4 100644 --- a/.config/emacs/modules/mm-completion.el +++ b/.config/emacs/modules/mm-completion.el @@ -158,4 +158,12 @@ :custom (find-library-include-other-files nil)) -(provide 'mm-completion) \ No newline at end of file + +;;; Completion at Point Live Completions + +(use-package completion-preview + :hook (after-init . global-completion-preview-mode) + :custom + (completion-preview-minimum-symbol-length 1)) + +(provide 'mm-completion) -- cgit v1.2.3 From c5797f6a1e6803a5eeff5a251c5ec7bbe91dd298 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 20 Mar 2026 16:38:50 +0100 Subject: emacs: Use cape for CAPF functions --- .config/emacs/modules/mm-completion.el | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to '.config/emacs/modules/mm-completion.el') diff --git a/.config/emacs/modules/mm-completion.el b/.config/emacs/modules/mm-completion.el index 74740b4..8ff2894 100644 --- a/.config/emacs/modules/mm-completion.el +++ b/.config/emacs/modules/mm-completion.el @@ -158,6 +158,23 @@ :custom (find-library-include-other-files nil)) + +;;; Completion at Point Functions + +(defun mm-cape-file--not-dot-path-p (cand) + (declare (ftype (function (string) boolean)) + (pure t) (side-effect-free t)) + (not (or (string= cand "./") + (string= cand "../")))) + +(use-package cape + :ensure t + :init + (add-hook 'completion-at-point-functions + (cape-capf-predicate #'cape-file #'mm-cape-file--not-dot-path-p)) + (add-hook 'completion-at-point-functions + (cape-capf-prefix-length #'cape-dabbrev 3))) + ;;; Completion at Point Live Completions -- cgit v1.2.3 From 4e0beba3438a9132eb4e049f53bd9a66d74645b2 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Fri, 20 Mar 2026 16:39:14 +0100 Subject: emacs: Support marginalia for Git branches --- .config/emacs/mango-theme.el | 6 +++ .config/emacs/modules/mm-completion.el | 72 +++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) (limited to '.config/emacs/modules/mm-completion.el') diff --git a/.config/emacs/mango-theme.el b/.config/emacs/mango-theme.el index 5fec2e0..f18f4c0 100644 --- a/.config/emacs/mango-theme.el +++ b/.config/emacs/mango-theme.el @@ -175,6 +175,12 @@ graphically, so I shouldn’t need to have multiple specs per face. (marginalia-documentation :foreground ,(mango-theme--color 'disabled) :underline nil) + (mm-diffstat-counter-added + :foreground "green" + :weight bold) + (mm-diffstat-counter-removed + :foreground "red" + :weight bold) ;; Tempel (tempel-default diff --git a/.config/emacs/modules/mm-completion.el b/.config/emacs/modules/mm-completion.el index 8ff2894..3367aa1 100644 --- a/.config/emacs/modules/mm-completion.el +++ b/.config/emacs/modules/mm-completion.el @@ -20,10 +20,80 @@ ;;; Annotate Completions -;; TODO: Show git branch descriptions! (use-package marginalia :ensure t :hook after-init + :config + (with-eval-after-load 'magit + (defvar mm-marginalia--magit-cache nil) + (add-hook 'minibuffer-setup-hook + (lambda () (setq mm-marginalia--magit-cache nil))) + + (defvar-local mm-marginalia-magit-base-branch "master") + + (defface mm-diffstat-counter-added + '((t :inherit magit-diffstat-added)) + "TODO") + (defface mm-diffstat-counter-removed + '((t :inherit magit-diffstat-removed)) + "TODO") + + (defun mm-marginalia-populate-magit-cache () + "Batch-fetch all Git branch descriptions and stats into the cache." + (setq mm-marginalia--magit-cache (make-hash-table :test #'equal)) + (when-let ((default-directory (magit-toplevel))) + (dolist (line (magit-git-lines "config" "list")) + (when (string-match "^branch\\.\\(.*?\\)\\.description=\\(.*\\)$" line) + (puthash (match-string 1 line) + (list :desc (match-string 2 line) :stats "") + mm-marginalia--magit-cache))) + (dolist (line (magit-git-lines + "for-each-ref" + (format + "--format=%%(refname:short)\x1F%%(ahead-behind:%s)" + mm-marginalia-magit-base-branch) + "refs/heads/")) + (when (string-match (rx bol (group (1+ (not #x1F))) + #x1F (group (1+ digit)) + " " (group (1+ digit)) eol) + line) + (let* ((branch (match-string 1 line)) + (ahead (+ (string-to-number (match-string 2 line)))) + (behind (- (string-to-number (match-string 3 line)))) + (ahead-str (if (zerop ahead) + "" + (propertize (format "%+d" ahead) + 'face 'mm-diffstat-counter-added))) + (behind-str (if (zerop behind) + "" + (propertize (format "%+d" behind) + 'face 'mm-diffstat-counter-removed))) + (stats-str (format "%5s %5s" ahead-str behind-str)) + (existing (gethash branch mm-marginalia--magit-cache + (list :desc "" :stats "")))) + (puthash branch (plist-put existing :stats stats-str) + mm-marginalia--magit-cache)))))) + + (defun mm-marginalia-annotate-magit-branch (cand) + "Annotate Git branch CAND with ahead/behind stats and description." + (unless mm-marginalia--magit-cache + (mm-marginalia-populate-magit-cache)) + (let* ((data (gethash cand mm-marginalia--magit-cache '(:desc "" :stats ""))) + (desc (or (plist-get data :desc) "")) + (stats (or (plist-get data :stats) ""))) + (marginalia--fields + (stats :width 10) + (desc :truncate 1.0 :face 'marginalia-documentation)))) + + (add-to-list 'marginalia-annotators + '(magit-branch mm-marginalia-annotate-magit-branch builtin none)) + (dolist (cmd '(magit-branch-and-checkout + magit-branch-checkout + magit-branch-delete + magit-checkout + magit-merge + magit-rebase-branch)) + (add-to-list 'marginalia-command-categories (cons cmd 'magit-branch)))) :custom (marginalia-field-width 50) (marginalia-max-relative-age 0)) -- cgit v1.2.3