feat: add dashboard and enhance completion

- Add startup dashboard with recent files and bookmarks
- Enhance corfu with icons and minibuffer transfer
- Add avy-zap, markdown-mode, consult-dir
- Optimize GC settings and editor config
This commit is contained in:
trogloxene
2026-04-02 14:56:29 +08:00
parent 9ecad315b5
commit c7352d0460
10 changed files with 311 additions and 76 deletions

View File

@@ -22,6 +22,7 @@
(require 'init-window)
(require 'init-kbd)
(require 'init-ui)
(require 'init-dashboard)
(require 'init-segmentation)
;;; init.el ends here

View File

@@ -13,23 +13,49 @@
;; corfu
(use-package corfu
:init
(global-corfu-mode)
(corfu-history-mode)
(corfu-popupinfo-mode)
(corfu-echo-mode)
:autoload (corfu-quit consult-completion-in-region)
:functions (persistent-scratch-save corfu-move-to-minibuffer)
:custom
(corfu-auto t)
(corfu-cycle t)
(corfu-auto-delay 0.1)
(corfu-popupinfo-delay 0.2)
(corfu-preview-current nil)
(corfu-auto-prefix 2)
(corfu-count 12)
(corfu-preview-current nil)
(corfu-on-exact-match nil)
(corfu-auto-delay 0.2)
(corfu-popupinfo-delay '(0.4 . 0.2))
(global-corfu-modes '((not erc-mode
circe-mode
help-mode
gud-mode
vterm-mode)
t))
:hook ((after-init . global-corfu-mode)
(global-corfu-mode . corfu-popupinfo-mode)
(global-corfu-mode . corfu-history-mode))
:bind
(:map corfu-map
("RET" . nil)))
:config
;;Quit completion before saving
(add-hook 'before-save-hook #'corfu-quit)
(advice-add #'persistent-scratch-save :before #'corfu-quit)
;; Move completions to minibuffer
(defun corfu-move-to-minibuffer ()
(interactive)
(pcase completion-in-region--data
(`(,beg ,end ,table ,pred ,extras)
(let ((completion-extra-properties extras)
completion-cycle-threshold completion-cycling)
(consult-completion-in-region beg end table pred)))))
(keymap-set corfu-map "M-m" #'corfu-move-to-minibuffer)
(add-to-list 'corfu-continue-commands #'corfu-move-to-minibuffer)
:bind (:map corfu-map
("RET" . nil)))
(unless (or (display-graphic-p)
(featurep 'tty-child-frames))
(use-package corfu-terminal
:hook (global-corfu-mode . corfu-terminal-mode)))
;; 在eshell中使用tab打开补全
(add-hook 'eshell-mode-hook
@@ -37,6 +63,9 @@
(setq-local corfu-auto nil)
(local-set-key (kbd "TAB") 'completion-at-point)))
(use-package nerd-icons-completion
:hook (marginalia-mode . nerd-icons-completion-marginalia-setup))
(use-package emacs
:custom
(tab-always-indent 'complete)
@@ -52,10 +81,23 @@
;; cape
(use-package cape
:commands (cape-file cape-elisp-block cape-keyword)
:autoload (cape-wrap-noninterruptible cape-wrap-nonexclusive cape-wrap-buster)
:autoload (cape-wrap-silent)
:init
(add-to-list 'completion-at-point-functions #'cape-file) ;; 文件补全
(setq-local completion-at-point-functions
(list (cape-capf-super #'cape-dabbrev)))) ;; 启用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-elisp-block)
(add-to-list 'completion-at-point-functions #'cape-keyword)
;; (add-to-list 'completion-at-point-functions #'cape-abbrev)
;; 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))
;; lua
(use-package lua-ts-mode

34
lisp/init-dashboard.el Normal file
View File

@@ -0,0 +1,34 @@
;;; init-dashboard.el --- dashboard -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(use-package dashboard
:demand t
:config
(dashboard-setup-startup-hook)
(setq dashboard-banner-logo-title (format "%s" emacs-version))
(setq dashboard-banner-ascii " ##### # # # # ####### # # # ##### ##### \n# # ## # # # # ## ## # # # # # # \n# # # # # # # # # # # # # # # \n# #### # # # # # ##### # # # # # # ##### \n# # # # # # # # # # ####### # # \n# # # ## # # # # # # # # # # # \n ##### # # ##### ####### # # # # ##### ##### ")
(setq dashboard-startup-banner 'ascii)
(setq dashboard-center-content t)
(setq dashboard-navigation-cycle t)
(setq dashboard-items '((recents . 10)
(bookmarks . 5)
(projects . 5)))
(add-hook 'emacs-startup-hook
(lambda()
(setq my-emacs-startup-time (format-time-string "%Y-%m-%d %H:%M:%S"))))
(defun my/dashboard-insert-copyright ()
"Insert copyright in the footer."
(dashboard-insert-center
(propertize (format "\n\nEmacs started at %s" my-emacs-startup-time)
'face 'font-lock-comment-face)))
(advice-add #'dashboard-insert-footer :after #'my/dashboard-insert-copyright)
(setq dashboard-footer-messages '(
"Hello."
"Hi."
)))
(provide 'init-dashboard)
;;; init-dashboard.el ends here

View File

@@ -286,6 +286,10 @@ Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise tog
(list "d"
(lambda (buffer) (diff-buffer-with-file (buffer-file-name buffer)))
"show diff between the buffer and its file"))
;; markdown
(with-eval-after-load 'markdown-mode
(define-key markdown-mode-map (kbd "M-p") nil)
(define-key markdown-mode-map (kbd "M-n") nil))
;; org-mode相关
;; cycle当前subtree
@@ -359,6 +363,9 @@ Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise tog
(global-set-key (kbd "C-c m d") 'my-emms-play-directory)
;; dashboard
(global-set-key (kbd "C-c <ESC>") 'dashboard-open)
(provide 'init-kbd)
;;; init-kbd.el ends here

View File

@@ -43,7 +43,7 @@
(format-time-string "%a" time)
(format-time-string "%Y-%m-%d %a" time)))
org-journal-carryover-items "TODO=\"TODO\"|TODO=\"STARTED\"|TODO=\"WAITING\"|TODO=\"SOMEDAY\"")
(when *is-windows*
(setq org-journal-dir "D:/emacs/my-org-daily/"))
@@ -60,14 +60,14 @@
(goto-char day-end)
(insert "\n\n** daily\n\n\n")
(insert "** tasks\n")))))
(add-hook 'org-journal-after-header-create-hook #'my/journal-setup-new-day)
(defun my/journal-position-cursor-after-time ()
(when (derived-mode-p 'org-journal-mode)
(org-back-to-heading)
(end-of-line)))
(add-hook 'org-journal-after-entry-create-hook #'my/journal-position-cursor-after-time)
(defun org-journal-open-entry-for-editing (&optional event)
@@ -109,7 +109,7 @@
(add-hook 'org-journal-mode-hook
(lambda ()
(global-cns-mode-enable-in-buffer)))
;; 一些随org-mode加载的基础配置
(add-hook 'org-mode-hook
(lambda ()
@@ -156,8 +156,7 @@
(when *is-windows*
(with-eval-after-load 'org
(setq org-agenda-files '("d:/emacs/hugo/this-is-my-blog/all-blog.org"
"d:/emacs/my-org-daily/"
"d:/emacs/my-org-daily/"))))
"d:/emacs/my-org-daily/"))))
(when *is-mac*
(with-eval-after-load 'org
(setq org-agenda-files '("~/org/my-org-daily"))))
@@ -271,18 +270,18 @@ See `org-capture-templates' for more information."
(let* ((blog-dir "d:/emacs/hugo/this-is-my-blog/")
(timestamp (format-time-string "%Y-%m-%d %H:%M:%S"))
(default-directory blog-dir))
;; save buffer
(save-buffer)
;; git add
(message "Adding files...")
(eshell-command "git add .")
;; git commit with timestamp
(message "Committing: %s" timestamp)
(eshell-command (format "git commit -m \"Update: %s\"" timestamp))
;; git push
(message "Pushing to remote...")
(let ((exit-code (eshell-command "git push")))

View File

@@ -8,12 +8,53 @@
;; 安装gcmh用于管理内存回收
(use-package gcmh
:demand t
:init
(setq gcmh-idle-delay 5 ; 空闲 5 秒后 GC
gcmh-high-cons-threshold (* 16 1024 1024)) ; 高阈值 16MB
(setq gcmh-idle-delay 'auto
gcmh-auto-idle-delay-factor 10
gcmh-high-cons-threshold #x4000000)
:config
(gcmh-mode 1))
(use-package emacs
:hook (((prog-mode markdown-mode conf-mode) . enable-trailing-whitespace))
:init
(setq kill-whole-line t ; Kill line including '\n'
line-move-visual nil
track-eol t ; Keep cursor at end of lines. Require line-move-visual is nil.
set-mark-command-repeat-pop t) ; Repeating C-SPC after popping mark pops it again
;; Visualize TAB, (HARD) SPACE, NEWLINE
(setq-default show-trailing-whitespace nil) ; Don't show trailing whitespace by default
(defun enable-trailing-whitespace ()
"Show trailing spaces and delete on saving."
(setq show-trailing-whitespace t)
(add-hook 'before-save-hook #'delete-trailing-whitespace nil t))
;; Prettify the process list
(with-no-warnings
(defun my/list-processes--prettify ()
"Prettify process list."
(when-let* ((entries tabulated-list-entries))
(setq tabulated-list-entries nil)
(dolist (p (process-list))
(when-let* ((val (cadr (assoc p entries)))
(name (aref val 0))
(pid (aref val 1))
(status (aref val 2))
(status (list status
'face
(if (memq status '(stop exit closed failed))
'error
'success)))
(buf-label (aref val 3))
(tty (list (aref val 4) 'face 'font-lock-doc-face))
(thread (list (aref val 5) 'face 'font-lock-doc-face))
(cmd (list (aref val 6) 'face 'completions-annotations)))
(push (list p (vector name pid status buf-label tty thread cmd))
tabulated-list-entries)))))
(advice-add #'list-processes--refresh :after #'my/list-processes--prettify)))
(use-package restart-emacs)
;; 安装multiple-cursors
@@ -49,7 +90,7 @@
;; 安装consult增强搜索和其他菜单
(use-package consult
:config
(defun consult-fd-global ()
"Search for all files use fd"
(interactive)
@@ -65,9 +106,69 @@
(when *is-mac*
(setopt consult-locate-args "mdfind -name")))
;; 安装embark一个菜单用用就明白了
(use-package consult-dir
:bind (("C-x C-d" . consult-dir)
:map minibuffer-local-completion-map
("C-x C-d" . consult-dir)
("C-x C-j" . consult-dir-jump-file)))
;; embark
(use-package embark
:config (setq prefix-help-command 'embark-prefix-help-command))
:config (setq prefix-help-command 'embark-prefix-help-command)
:init
(defun my/embark-preview ()
"Previews candidate in vertico buffer, unless it's a consult command."
(interactive)
(unless (bound-and-true-p consult--preview-function)
(save-selected-window
(let ((embark-quit-after-action nil))
(embark-dwim)))))
;; 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))))
(with-no-warnings
(with-eval-after-load 'which-key
(defun embark-which-key-indicator ()
"An embark indicator that displays keymaps using which-key.
The which-key help message will show the type and value of the
current target followed by an ellipsis if there are further
targets."
(lambda (&optional keymap targets prefix)
(if (null keymap)
(which-key--hide-popup-ignore-command)
(which-key--show-keymap
(if (eq (plist-get (car targets) :type) 'embark-become)
"Become"
(format "Act on %s '%s'%s"
(plist-get (car targets) :type)
(embark--truncate-target (plist-get (car targets) :target))
(if (cdr targets) "" "")))
(if prefix
(pcase (lookup-key keymap prefix 'accept-default)
((and (pred keymapp) km) km)
(_ (key-binding prefix 'accept-default)))
keymap)
nil nil t (lambda (binding)
(not (string-suffix-p "-argument" (cdr binding))))))))
(setq embark-indicators
'(embark-which-key-indicator
embark-highlight-indicator
embark-isearch-highlight-indicator))
(defun embark-hide-which-key-indicator (fn &rest args)
"Hide the which-key indicator immediately when using the completing-read prompter."
(which-key--hide-popup-ignore-command)
(let ((embark-indicators
(remq #'embark-which-key-indicator embark-indicators)))
(apply fn args)))
(advice-add #'embark-completing-read-prompter
:around #'embark-hide-which-key-indicator))))
;; 安装embark-consult和wgrep
(use-package embark-consult)
@@ -83,6 +184,9 @@
'embark-collect-mode-hook
#'consult-preview-at-point-mode))))
;; nerd-icon
(use-package nerd-icons)
;; 启用savehist保存命令顺序
(use-package savehist
:hook (after-init . savehist-mode)
@@ -116,16 +220,36 @@
;; ibuffer-projectile
(use-package ibuffer-projectile
:init (add-hook 'ibuffer-hook
(lambda ()
(ibuffer-projectile-set-filter-groups)
(unless (eq ibuffer-sorting-mode 'alphabetic)
(ibuffer-do-sort-by-alphabetic)))))
:config (add-hook 'ibuffer-hook
(lambda ()
(ibuffer-projectile-set-filter-groups)
(unless (eq ibuffer-sorting-mode 'alphabetic)
(ibuffer-do-sort-by-alphabetic))))
(when (centaur-treesit-available-p)
(defun treesit-mark-bigger-node ()
"Use tree-sitter to mark regions."
(let* ((root (treesit-buffer-root-node))
(node (treesit-node-descendant-for-range root (region-beginning) (region-end)))
(node-start (treesit-node-start node))
(node-end (treesit-node-end node)))
;; Node fits the region exactly. Try its parent node instead.
(when (and (= (region-beginning) node-start) (= (region-end) node-end))
(when-let* ((node (treesit-node-parent node)))
(setq node-start (treesit-node-start node)
node-end (treesit-node-end node))))
(set-mark node-end)
(goto-char node-start)))
(add-to-list 'er/try-expand-list 'treesit-mark-bigger-node)))
;; avy中文支持
(use-package ace-pinyin
:init (ace-pinyin-global-mode +1))
;; avy-zap
(use-package avy-zap
:bind (("M-z" . avy-zap-to-char-dwim)
("M-Z" . avy-zap-up-to-char-dwim)))
;; jinx拼写检查
(unless *is-windows*
(use-package jinx
@@ -153,22 +277,29 @@
;; consult-flycheck
(use-package consult-flycheck)
;; markdown
(use-package markdown-mode
:mode ("README\\.md\\'" . gfm-mode)
:init (setq markdown-command "multimarkdown")
:bind (:map markdown-mode-map
("C-c C-e" . markdown-do)))
;; 安装emms
(use-package emms
:init
;; 设置音乐文件默认目录
(when *is-windows*
(setq emms-source-file-default-directory "F:/luping26-1-11/"))
:config
;; --- 基础设置 ---
(require 'emms-setup)
(emms-all) ; 加载所有稳定功能
;; 使用简单模式的 mpv 播放器
;; 移除默认的 emms-player-mpv
(require 'emms-player-simple)
;; 定义简单的 mpv 播放器
(define-emms-simple-player mpv-simple '(file url streamlist playlist)
(concat "\\.\\("
@@ -186,41 +317,41 @@
"--keep-open=yes"
"--fs=no"
"--quiet")
;; 设置播放器列表
(setq emms-player-list '(emms-player-mpv-simple
emms-player-vlc
emms-player-mplayer))
(setq emms-playlist-default-playlist-name "*EMMS Playlist*")
(setq emms-playlist-buffer-name "*EMMS Playlist*")
;; 使用更快的文件查找方法(windows上需要使用internal)
;; (setq emms-source-file-directory-tree-function 'emms-source-file-directory-tree-find)
(setq emms-source-file-directory-tree-function 'emms-source-file-directory-tree-internal)
;; 使用原生 Elisp 元数据读取器
(setq emms-info-functions '(emms-info-native))
;; 异步读取元数据
(setq emms-info-asynchronously t)
;; 使用更详细的曲目描述
(setq emms-track-description-function #'emms-info-track-description)
;; 模式行设置
(require 'emms-mode-line)
(emms-mode-line-mode 1)
(emms-mode-line-blank) ; 初始为空
;; 自定义模式行格式
(setq emms-mode-line-format " [%s] ")
(setq emms-mode-line-length-limit 60)
;; 播放时间显示
(require 'emms-playing-time)
(emms-playing-time-mode 1)
;; 歌词设置
(require 'emms-lyrics)
(setq emms-lyrics-display-on-modeline t) ; 在模式行显示歌词
@@ -231,60 +362,60 @@
(setq emms-lyrics-dir "~/Music/lyrics") ; 歌词文件目录
(setq emms-lyrics-display-format " %s ") ; 歌词显示格式
(emms-lyrics 1) ; 启用歌词显示
;; 浏览器设置
(require 'emms-browser)
(setq emms-browser-default-browse-type 'artist)
(setq emms-browser-covers nil) ; 禁用封面
;; 浏览器显示格式
(setq emms-browser-info-title-format "%i%n")
(setq emms-browser-playlist-info-title-format "%i%n")
;; 添加浏览器快捷键
(define-key emms-browser-mode-map (kbd "SPC") 'emms-browser-add-tracks-and-play)
;; 缓存设置
(require 'emms-cache)
(emms-cache 1) ; 启用缓存
;; 历史记录
(require 'emms-history)
(add-hook 'emms-player-started-hook #'emms-last-played-update-current)
;; 音量控制
(require 'emms-volume)
;; 在播放列表中使用 +/- 控制音量
(define-key emms-playlist-mode-map (kbd "+") #'emms-volume-raise)
(define-key emms-playlist-mode-map (kbd "-") #'emms-volume-lower)
;; 添加(playlist中的)快捷键
(define-key emms-playlist-mode-map (kbd "SPC") 'emms-pause)
(define-key emms-playlist-mode-map (kbd "N") 'emms-next)
(define-key emms-playlist-mode-map (kbd "P") 'emms-previous)
(define-key emms-playlist-mode-map (kbd "R") 'emms-random)
(define-key emms-playlist-mode-map (kbd "/") 'emms-playlist-limit)
;; 启用标记功能
(require 'emms-mark)
;; 启用播放列表排序
(require 'emms-playlist-sort)
(define-key emms-playlist-mode-map (kbd "S s") 'emms-playlist-sort-map)
;; 启用播放列表限制/过滤
(require 'emms-playlist-limit)
;; 启用标签编辑器
(require 'emms-tag-editor)
;; 启用评分系统
(require 'emms-score)
(emms-score 1)
;; 启动后自动恢复播放列表
;; (add-hook 'after-init-hook 'emms-history-load)
;; 显示加载完成消息
(message "EMMS loaded")

View File

@@ -56,7 +56,7 @@
;; 自定义scratch
(setq initial-scratch-message
";; SCRATCH SCRATCH SCRATCH\n\n")
"")
;; 开启server mode
(server-start)
@@ -68,6 +68,28 @@
(add-hook 'emacs-lisp-mode-hook 'electric-pair-mode)
(add-hook 'org-mode-hook 'electric-pair-mode)
;; short anwser
(if (boundp 'use-short-answers)
(setq use-short-answers t)
(fset 'yes-or-no-p 'y-or-n-p))
(setq-default major-mode 'text-mode
fill-column 100
tab-width 4
indent-tabs-mode nil)
(setq visible-bell t
inhibit-compacting-font-caches t ; Dont compact font caches during GC
delete-by-moving-to-trash t ; Deleting files go to OS's trash folder
make-backup-files nil ; Forbide to make backup files
auto-save-default nil ; Disable auto save
uniquify-buffer-name-style 'post-forward-angle-brackets ; Show path if names are same
adaptive-fill-regexp "[ t]+|[ t]*([0-9]+.|*+)[ t]*"
adaptive-fill-first-line-regexp "^* *$"
sentence-end "\\([。!?]\\|……\\|[.?!][]\"')}]*\\($\\|[ \t]\\)\\)[ \t\n]*"
sentence-end-double-space nil
word-wrap-by-category t)
(provide 'init-startup)
;;; init-startup.el ends here

View File

@@ -27,7 +27,7 @@
(choice (completing-read
"Color: "
(mapcar (lambda (c)
(propertize
(propertize
(format "%-20s %s" c "████")
'face `(:foreground ,c)))
colors))))
@@ -76,7 +76,7 @@
(setenv "COLORTERM" "truecolor")
(add-to-list 'eshell-output-filter-functions 'eshell-handle-ansi-color t)
(setq-local eshell-prefer-lisp-functions nil)
(setenv "LS_COLORS"
(setenv "LS_COLORS"
"di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46")
(setenv "GIT_CONFIG_GLOBAL" (expand-file-name "~/.emacs.d/.gitconfig-eshell"))))

View File

@@ -18,13 +18,12 @@
my-base16-dark-core-palette
'((custom-theme-set-faces
theme-name
`(org-level-2 ((,class (:foreground ,blue :height 1.05))))
`(org-level-3 ((,class (:foreground ,green))))
`(org-level-6 ((,class (:foreground ,blue))))
`(org-level-8 ((,class (:foreground ,green))))
`(org-priority ((,class (:foreground ,blue :weight bold))))
`(org-done ((,class (:foreground ,blue :weight bold))))
`(org-headline-done ((,class (:foreground ,blue))))
`(org-priority ((,class (:foreground ,green :weight bold))))
`(font-lock-keyword-face ((,class (:foreground ,cyan :weight bold))))
`(font-lock-doc-face ((,class (:foreground ,green :slant normal))))
`(font-lock-string-face ((,class (:foreground ,green))))
`(dashboard-footer-face ((,class (:foreground ,blue))))
`(dashboard-text-banner ((,class (:foreground ,green))))
`(vertico-current ((,class (:background ,base02 :extend t :underline nil)))))))
(provide-theme 'my-base16-dark)

View File

@@ -14,8 +14,8 @@
"#d33682" ; magenta: 品红
"#6c71c4" ; violet: 紫罗兰
"#2570CD" ; blue: 蓝色
"#3A9C36" ; cyan: 青色
"#01928D")) ; green: 绿色
"#01928D" ; cyan: 青色
"#3A9C36")) ; green: 绿色
(provide 'my-base16-palette)