From ab8b6a4d4d6efec5d7396e40ac58b627e7c07c49 Mon Sep 17 00:00:00 2001 From: Zelong Kuang Date: Mon, 15 Dec 2025 00:26:46 +1100 Subject: [PATCH] Beautify emacs --- lisp/init-better-default.el | 5 +- lisp/init-completion.el | 95 +++++++++++++++++++++++++++++++------ lisp/init-dired.el | 21 +++++++- lisp/init-lsp.el | 3 ++ lisp/init-ui.el | 12 +++++ recentf | 23 ++++----- 6 files changed, 129 insertions(+), 30 deletions(-) diff --git a/lisp/init-better-default.el b/lisp/init-better-default.el index 90429b3..ace4fd2 100644 --- a/lisp/init-better-default.el +++ b/lisp/init-better-default.el @@ -3,10 +3,9 @@ (add-hook 'prog-mode-hook #'display-line-numbers-mode) (add-hook 'org-mode-hook #'display-line-numbers-mode) (setq-default cursor-type 'bar) -(setq display-line-numbers 'relative) +(setq display-line-numbers-type 'relative) (show-paren-mode t) (recentf-mode 1) -(setq recentf-max-menu-item 10) (setq make-backup-files nil) (setq custom-file (expand-file-name "~/.emacs.d/custom.el")) (load custom-file 'no-error 'no-message) @@ -39,7 +38,7 @@ :init (exec-path-from-shell-initialize)) -(global-set-key (kbd "C-x C-b") 'ibuffer) +(global-set-key (kbd "C-x b") 'ibuffer) (use-package ultra-scroll :init diff --git a/lisp/init-completion.el b/lisp/init-completion.el index eba004f..6d14e1a 100644 --- a/lisp/init-completion.el +++ b/lisp/init-completion.el @@ -32,9 +32,9 @@ ;; Optionally use the `orderless' completion style. (use-package orderless :custom - (completion-styles '(orderless partial-completion basic)) + (completion-styles '(orderless basic)) (completion-category-defaults nil) - (completion-category-overrides nil) + (completion-category-overrides '((file (styles orderless partial-completion)))) (orderless-component-separator #'orderless-escapable-split-on-space)) ;; Support Pinyin @@ -58,11 +58,57 @@ :init (vertico-mode t)) +(use-package vertico-posframe + :hook (vertico-mode . vertico-posframe-mode) + :config + (add-hook 'doom-after-reload-hook #'posframe-delete-all)) + +(use-package vertico-multiform + :ensure nil + :hook (vertico-mode . vertico-multiform-mode) + :config + (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." + (when (string-suffix-p "/" file) + (add-face-text-property 0 (length file) 'marginalia-file-priv-dir 'append file)) + file) + + (defun +vertico-highlight-enabled-mode (cmd) + "If MODE is enabled, highlight it as font-lock-constant-face." + (let ((sym (intern cmd))) + (with-current-buffer (nth 1 (buffer-list)) + (if (or (eq sym major-mode) + (and + (memq sym minor-mode-list) + (boundp sym) + (symbol-value sym))) + (add-face-text-property 0 (length cmd) 'font-lock-constant-face 'append cmd))) + cmd)) + + (add-to-list 'vertico-multiform-categories + '(file + (+vertico-transform-functions . +vertico-highlight-directory))) + (add-to-list 'vertico-multiform-commands + '(execute-extended-command + (+vertico-transform-functions . +vertico-highlight-enabled-mode)))) + ;; Enrich existing commands with completion annotations (use-package marginalia + :hook (marginalia-mode . nerd-icons-completion-marginalia-setup) :init (marginalia-mode)) +;; Add icons to completion candidates +(use-package nerd-icons-completion) + ;; Consulting completing-read (use-package consult :defines (xref-show-xrefs-function xref-show-definitions-function) @@ -71,10 +117,14 @@ :autoload (consult--read consult--customize-put) :commands (consult-narrow-help) :functions (list-colors-duplicates consult-colors--web-list) - :bind (("s-f" . consult-line) + :bind (("C-c ." . consult-imenu) + ("C-c T" . consult-theme) + + ("s-f" . consult-line) ("C-c s s" . consult-line) ("C-c p f" . consult-project-buffer) ("C-c f r" . consult-recent-file) + ("C-x C-b" . consult-buffer) ("C-c s p" . consult-ripgrep))) @@ -85,6 +135,9 @@ ("C-x C-d" . consult-dir) ("C-x C-j" . consult-dir-jump-file))) +(use-package consult-yasnippet + :bind ("M-g y" . consult-yasnippet)) + (use-package embark :commands embark-prefix-help-command :bind (("C-;" . embark-act) @@ -128,6 +181,14 @@ (add-hook 'before-save-hook #'corfu-quit) (advice-add #'persistent-scratch-save :before #'corfu-quit)) +(use-package nerd-icons-corfu + :init + (with-eval-after-load 'corfu + (add-to-list 'corfu-margin-formatters #'nerd-icons-corfu-formatter))) + +(use-package wgrep + :commands wgrep-change-to-wgrep-mode + :config (setq wgrep-auto-save-buffer t)) ;; A few more useful configurations... (use-package emacs @@ -152,19 +213,23 @@ (use-package cape :init ;; Add `completion-at-point-functions', used by `completion-at-point'. - (add-to-list 'completion-at-point-functions #'cape-dabbrev) + ;; (add-to-list 'completion-at-point-functions #'cape-dabbrev) (add-to-list 'completion-at-point-functions #'cape-file) - ;;(add-to-list 'completion-at-point-functions #'cape-history) - ;;(add-to-list 'completion-at-point-functions #'cape-keyword) - ;;(add-to-list 'completion-at-point-functions #'cape-tex) - ;;(add-to-list 'completion-at-point-functions #'cape-sgml) - ;;(add-to-list 'completion-at-point-functions #'cape-rfc1345) - ;;(add-to-list 'completion-at-point-functions #'cape-abbrev) - ;;(add-to-list 'completion-at-point-functions #'cape-ispell) - ;;(add-to-list 'completion-at-point-functions #'cape-dict) - ;;(add-to-list 'completion-at-point-functions #'cape-symbol) - ;;(add-to-list 'completion-at-point-functions #'cape-line) - ) + (add-to-list 'completion-at-point-functions #'cape-elisp-block) + (add-to-list 'completion-at-point-functions #'cape-keyword) + ;; Make these capfs composable. + (advice-add 'lsp-completion-at-point :around #'cape-wrap-noninterruptible) + (advice-add 'lsp-completion-at-point :around #'cape-wrap-nonexclusive) + (advice-add 'comint-completion-at-point :around #'cape-wrap-nonexclusive) + (advice-add 'eglot-completion-at-point :around #'cape-wrap-buster) + (advice-add 'eglot-completion-at-point :around #'cape-wrap-nonexclusive) + (advice-add 'pcomplete-completions-at-point :around #'cape-wrap-nonexclusive)) + +(use-package yasnippet-capf + :after cape + :config + (add-to-list 'completion-at-point-functions #'yasnippet-capf)) + (provide 'init-completion) diff --git a/lisp/init-dired.el b/lisp/init-dired.el index 8748834..7ab6f76 100644 --- a/lisp/init-dired.el +++ b/lisp/init-dired.el @@ -11,6 +11,25 @@ ;; Show directory first ;; (setq dired-listing-switches "-alh --group-directories-first") - ) + + ;; Colorful dired + (use-package diredfl + :diminish + :hook dired-mode) + + (use-package nerd-icons-dired + :diminish + :functions (nerd-icons-icon-for-dir my-nerd-icons-icon-for-dir) + :hook dired-mode + :init + (defface nerd-icons-dired-dir-face + '((t (:inherit 'font-lock-doc-face))) + "Face for the directory icon." + :group 'nerd-icons-faces) + (defun my-nerd-icons-icon-for-dir (dir) + (nerd-icons-icon-for-dir dir :face 'nerd-icons-dired-dir-face)) + (setq nerd-icons-dired-dir-icon-function #'my-nerd-icons-icon-for-dir)) + ;; Extra Dired functionality + (use-package dired-aux :ensure nil)) (provide 'init-dired) diff --git a/lisp/init-lsp.el b/lisp/init-lsp.el index 6594639..81b1925 100644 --- a/lisp/init-lsp.el +++ b/lisp/init-lsp.el @@ -1,4 +1,7 @@ ;; -*- lexical-binding: t; -*- + +(use-package flymake) + (use-package eglot :hook ((prog-mode . (lambda () (unless (derived-mode-p diff --git a/lisp/init-ui.el b/lisp/init-ui.el index c779655..6c6358c 100644 --- a/lisp/init-ui.el +++ b/lisp/init-ui.el @@ -108,4 +108,16 @@ mouse-wheel-scroll-amount-horizontal 1 mouse-wheel-progressive-speed nil) +(use-package nerd-icons + :ensure (nerd-icons + :type git + :host github + :repo "rainstormstudio/nerd-icons.el" + :files (:defaults "data")) + :custom + ;; The Nerd Font you want to use in GUI + ;; "Symbols Nerd Font Mono" is the default and is recommended + ;; but you can use any other Nerd Font if you want + (nerd-icons-font-family "Symbols Nerd Font Mono")) + (provide 'init-ui) diff --git a/recentf b/recentf index e8736a8..cc3e5ec 100644 --- a/recentf +++ b/recentf @@ -1,18 +1,24 @@ -;;; Automatically generated by ‘recentf’ on Sun Dec 14 23:48:48 2025 -*- mode: emacs-lisp; lexical-binding: t -*- +;;; Automatically generated by ‘recentf’ on Mon Dec 15 00:26:33 2025 -*- mode: emacs-lisp; lexical-binding: t -*- (setq recentf-list '( + "~/.emacs.d/lisp/init-better-default.el" + "~/.emacs.d/lisp/init-completion.el" + "~/.emacs.d/lisp/init-dired.el" + "~/.emacs.d/lisp/init-cc.el" + "~/.emacs.d/lisp/init-lsp.el" + "~/.emacs.d/lisp/init-ui.el" + "~/org/workout.org" + "~/org/todo.org" + "~/org/notes.org" + "~/org/learn-haskell.org" + "~/.emacs.d/init.el" "~/.emacs.d/lisp/init-rust.el" "~/.emacs.d/lisp/init-dashboard.el" - "~/.emacs.d/init.el" "~/.emacs.d/lisp/init-python.el" - "~/.emacs.d/lisp/init-completion.el" - "~/.emacs.d/lisp/init-lsp.el" - "~/.emacs.d/lisp/init-cc.el" "~/programming/leetcode/test.cpp" "~/programming/leetcode/2.c" "~/.emacs.d/.gitignore" - "~/.emacs.d/lisp/init-better-default.el" "~/.emacs.d/url/cookies" "~/.config/fish/config.fish" "~/Library/Application Support/Firefox/Profiles/pq25w6ba.default-nightly/chrome/userChrome.css" @@ -21,11 +27,6 @@ "~/.emacs.d/early-init.el" "~/.emacs.d/lisp/init-typst.el" "~/build-emacs-for-macos/builds/Emacs.app/Contents/Resources/lisp/loaddefs.el.gz" - "~/.config/emacs_bak/doom/config.org" - "~/.emacs.d/lisp/init-org.el" - "~/org/roam/20251212003211-presentation_of_group.org" - "~/.emacs.d/lisp/init-tex.el" - "~/.emacs.d/lisp/init-edit.el" )) (setq recentf-filter-changer-current 'nil)