feat(config): Improve dired, keybindings, terminal UI and add packages

- Add dired buffer killing and custom dirvish layout toggle
- Replace ido with fido-mode in terminal config
- Add custom terminal color theme with 24-bit color support
- Add new packages: tokei, helpful, gptel-magit
- Refactor project keybindings under C-x p prefix
- Add mwim navigation bindings globally
- Improve ibuffer filter groups and consult buffer filters
- Add diff-mode keybindings and refine magit diff display
This commit is contained in:
2026-06-03 20:29:01 +08:00
parent 35fd3dfd27
commit 8db37d1c6d
13 changed files with 235 additions and 83 deletions

View File

@@ -4,7 +4,6 @@
;;; Code:
(use-package dired
:straight nil
:config
@@ -18,7 +17,9 @@
dired-recursive-copies 'always
dired-mouse-drag-files t
mouse-drag-and-drop-region-cross-program t
dired-compress-file-default-suffix ".zip")
dired-compress-file-default-suffix ".zip"
dired-kill-when-opening-new-buffer t
dired-kill-when-opening-new-dired-buffer t)
(put 'dired-find-alternate-file 'disabled nil))
;; dirvish
@@ -42,7 +43,8 @@
(if *is-android*
(setq dirvish-default-layout '(1 0.6))
(setq dirvish-default-layout '(1 0.15 0.45)))
(setq dirvish-default-layout nil
dirvish-layout-recipes '((1 0.15 0.45))))
(with-eval-after-load 'dirvish
(add-hook 'dired-mode-hook #'dired-hide-details-mode))

View File

@@ -131,6 +131,8 @@
(my-desktop-init)))
(use-package xdg-launcher
:demand t
:after exwm
:straight
(xdg-launcher :type git
:host github

View File

@@ -119,6 +119,10 @@ from the last 1500 characters of the buffer."
(gptel-agent-update))
(use-package gptel-magit
:straight
(gptel-magit :type git
:host github
:repo "ArthurHeymans/gptel-magit")
:hook
(magit-mode . gptel-magit-install)

View File

@@ -108,12 +108,21 @@ Disable jinx-mode if it's enable and global-jinx-mode is disable , otherwise tog
(interactive)
(align-regexp (region-beginning) (region-end) "\\(\\s-*\\)::" 1 1 nil))
(defun my/dired-next-line()
(defun my-dired-next-line()
"Move to forward line in dired buffer"
(interactive)
(forward-line 1)
(dired-move-to-filename))
(defun my-dirvish-layout-toggle ()
"Toggle layout using first recipe in `dirvish-layout-recipes' instead of fallback."
(interactive)
(let ((dv (dirvish-curr)))
(unless dv (user-error "Not a dirvish buffer"))
(unless (dv-curr-layout dv)
(setf (dv-ff-layout dv) (car dirvish-layout-recipes)))
(dirvish-layout-toggle)))
(defun my-magit-toggle-parent-section ()
"Toggle parent magit section."
(interactive)

View File

@@ -33,7 +33,8 @@
"t" 'gptel-tools)
(general-def gptel-mode-map
"C-c C-s" 'my-gptel-save-session)
"C-c C-s" 'my-gptel-save-session
"C-c C-k" 'gptel-abort)
;; u for ui
(general-def
@@ -64,6 +65,16 @@
"o" 'consult-outline
"i" 'consult-info)
;; p for project
(general-def
:prefix "C-x p"
"b" 'consult-project-buffer
"E" 'eat-project
"r" 'consult-ripgrep-project
"R" 'project-query-replace-regexp
"v" 'magit-project-status
"V" 'project-vc-dir)
;; t for modes toggle
(general-def
:prefix "C-c t"
@@ -132,15 +143,15 @@
"M-." 'scroll-other-window
"<mouse-2>" 'emms-play-dired
"C-c m a" 'emms-add-dired
"<down>" 'my/dired-next-line
"C-n" 'my/dired-next-line
"n" 'my/dired-next-line
"<down>" 'my-dired-next-line
"C-n" 'my-dired-next-line
"n" 'my-dired-next-line
"b" 'dired-up-directory
"C-b" 'dired-up-directory
"<right>" 'dired-find-file
"<left>" 'dired-up-directory
"C-f" 'dired-find-file
"<SPC>" 'dirvish-layout-toggle
"<SPC>" 'my-dirvish-layout-toggle
"C-s" 'consult-line
"C-r" 'consult-line)
@@ -154,7 +165,7 @@
"y" 'dirvish-yank-menu)
;; magit
(general-def magit-mode-map
(general-def (magit-mode-map tokei-mode-map)
"C-<tab>" 'my-magit-toggle-parent-section
"p" 'magit-section-backward-sibling
"M-p" 'magit-section-backward
@@ -212,7 +223,9 @@
"C-c o l" 'denote-link
"C-c o L" 'denote-org-link-to-heading
"C-c o b" 'denote-backlinks
"C-c o B" 'denote-org-backlinks-for-heading)
"C-c o B" 'denote-org-backlinks-for-heading
"C-a" 'mwim-beginning
"C-e" 'mwim-end)
;; hs-hide-mode
(general-def hs-minor-mode-map
@@ -250,6 +263,10 @@
(general-def Info-mode-map
"M-n" 'forward-paragraph)
;; diff
(general-def diff-mode-map
"M-o" 'other-window)
;; discomfort
(general-def discomfort-mode-map
"p" 'previous-line
@@ -314,6 +331,8 @@
"C-x u" 'vundo
;; navigate
"C-a" 'mwim-beginning
"C-e" 'mwim-end
"M-p" 'backward-paragraph
"M-n" 'forward-paragraph
"<mouse-2>" 'xref-find-definitions-at-mouse
@@ -336,10 +355,7 @@
;; other
"C-x r b" 'consult-bookmark
"C-x p b" 'consult-project-buffer
"C-x p E" 'eat-project
"C-x p r" 'consult-ripgrep-project
"C-x p R" 'project-query-replace-regexp
"C-x v =" 'magit-diff-buffer-file
"C-;" 'embark-act)
(when *is-android*

View File

@@ -32,11 +32,7 @@
(use-package drag-stuff)
;; mwim更聪明的beginning/end of line
(use-package mwim
:bind (([remap move-beginning-of-line] . mwim-beginning)
([remap move-end-of-line] . mwim-end)
([remap org-beginning-of-line] . mwim-beginning)
([remap org-end-of-line] . mwim-end)))
(use-package mwim)
;; which-key快捷键提示
(use-package which-key
@@ -66,22 +62,31 @@
;; consult搜索与导航
(use-package consult
:config
;; everything
(when *is-windows*
(setq consult-locate-args (encode-coding-string "es.exe -i -p -r" 'gbk))
(setq consult-ripgrep-args (encode-coding-string
"rg --null --line-buffered --color=never --max-columns=1000 --path-separator / --smart-case --no-heading --line-number"
'gbk))
;; set locate arguments
(cond
(*is-windows*
(setq consult-locate-args (encode-coding-string "es.exe -i -p -r" 'gbk)
consult-ripgrep-args (encode-coding-string
"rg --null --line-buffered --color=never --max-columns=1000 --path-separator / --smart-case --no-heading --line-number"
'gbk))
(add-to-list 'process-coding-system-alist '("es" gbk . gbk)))
;; mdfind
(when *is-mac*
(*is-mac*
(setq consult-locate-args "mdfind -name"))
;; plocate
(when *is-linux*
(*is-linux*
(setq consult-locate-args "plocate --basename --ignore-case")))
;; set some buffer filter
(setq consult-buffer-filter
(cl-union consult-buffer-filter
'("^\\*dirvish"
"^PREVIEW"
"^\\*helpful"
"^\\*Help"
"Diff"
"straight"
"\\*Messages\\*")
:test 'equal)))
;; embark快捷指令
(use-package embark
:config
@@ -176,7 +181,10 @@ targets."
(save-place-mode))
;; 撤回增强和跨会话历史
(use-package undo-fu)
(use-package undo-fu
:config
(setq undo-in-region t
undo-fu-allow-undo-in-region t))
(use-package undo-fu-session
:init
@@ -198,13 +206,14 @@ targets."
;; project
(use-package project
:bind
([remap project-vc-dir] . magit-project-status)
:config
(setq project-switch-commands (assq-delete-all 'project-vc-dir project-switch-commands))
(add-to-list 'project-switch-commands '(magit-project-status "Magit" ?v))
(add-to-list 'project-switch-commands '(eat-project "Eat" ?E))
(add-to-list 'project-switch-commands '(consult-ripgrep-project "Ripgrep" ?r)))
(setq project-switch-commands
(seq-uniq (append project-switch-commands
'((magit-project-status "Magit" ?v)
(eat-project "Eat" ?E)
(project-query-replace-regexp "Query Replace" ?R)
(consult-ripgrep-project "Ripgrep" ?r))))))
;; ibuffer
(use-package ibuffer
@@ -227,7 +236,8 @@ targets."
("Config" (or
(mode . conf-mode)
(mode . conf-desktop-mode)
(mode . conf-toml-mode)))
(mode . conf-toml-mode)
(mode . conf-xdefaults-mode)))
("Elisp" (mode . emacs-lisp-mode))
("Scheme" (or
(mode . scheme-mode)))
@@ -254,14 +264,9 @@ targets."
(mode . org-mode)
(mode . markdown-mode)
(name . "^\\*\\[D\\] FILE backlinks for")))
("Emacs" (or
(name . "^\\*Help\\*$")
(name . "^\\*Custom.*")
(name . "^\\*EMMS Playlist\\*")
(name . "^\\*Messages\\*$")
(name . "*Chinese-word-segmentation*")
(name . "^*Buffer List*")
(name . "\\*discomfort\\*")))
("Help" (or
(mode . help-mode)
(mode . helpful-mode)))
("Info" (or
(name . "^\\*info")))
("Magit" (or
@@ -275,7 +280,25 @@ targets."
("Directories" (or
(mode . dired-mode)
(name . "^*dirvish")))
("Diff" (name . "^*Diff")))))
("Grep" (or
(mode . grep-mode)
(mode . rg-mode)
(mode . xref--xref-buffer-mode)
(mode . xref-edit-mode)))
("Diff" (name . "^*Diff"))
("Emacs" (or
(name . "^\\*Help\\*$")
(name . "^\\*Custom.*")
(name . "^\\*EMMS Playlist\\*")
(name . "^\\*Messages\\*$")
(name . "*Chinese-word-segmentation*")
(name . "^*Buffer List*")
(name . "\\*discomfort\\*")
(mode . calendar-mode)
(mode . calc-mode)
(mode . calc-trail-mode)
(mode . grep-mode)
(mode . occur-mode))))))
(add-hook 'ibuffer-hook
(lambda () (ibuffer-switch-to-saved-filter-groups "Main")
@@ -372,7 +395,7 @@ targets."
(unless *is-android* (which-key-enable-god-mode-support))
(setq god-mode-enable-function-key-translation nil
god-exempt-major-modes
(delete-dups (append '(diff-mode exwm-mode) god-exempt-major-modes))
(cl-union '(diff-mode exwm-mode) god-exempt-major-modes :test 'equal)
god-mode-lighter-string "THANK-GOD-MODE")
(defun my-sync-god-mode-lighter-face (&rest _)
@@ -408,14 +431,17 @@ targets."
(consult-customize consult-source-buffer :hidden t :default nil)
(add-to-list 'consult-buffer-sources persp-consult-source))
(setq switch-to-prev-buffer-skip
(lambda (win buff bury-or-kill)
(not (persp-is-current-buffer buff))))
(lambda (win buff bury-or-kill)
(or (not (persp-is-current-buffer buff))
(cl-some (lambda (re) (string-match-p re (buffer-name buff)))
consult-buffer-filter))))
(setq persp-initial-frame-name "main"))
;; magit
(use-package magit
:config
(setq magit-bind-magit-project-status nil))
(setq magit-bind-magit-project-status nil
magit-diff-refine-hunk 'all))
;; git-timemachine
(use-package git-timemachine)
@@ -436,6 +462,25 @@ targets."
emms-info-functions '(emms-info-native))
(emms-history-load))
;; tokei
(use-package tokei)
;; helpful
(use-package helpful
:bind
(([remap describe-function] . helpful-callable)
([remap describe-command] . helpful-command)
([remap describe-variable] . helpful-variable)
([remap describe-key] . helpful-key)
([remap describe-symbol] . helpful-symbol)
:map emacs-lisp-mode-map
("C-c C-d C-d" . helpful-at-point)
:map lisp-interaction-mode-map
("C-c C-d C-d" . helpful-at-point)
:map helpful-mode-map
("C-x K" . helpful-kill-buffers)
("r" . remove-hook-at-point)))
(provide 'init-package)
;;; init-package.el ends here

View File

@@ -11,10 +11,9 @@
(toggle-frame-fullscreen)
(global-unset-key (kbd "<f12>"))
(global-set-key (kbd "<f12>") 'toggle-frame-fullscreen))
(*is-linux*
(toggle-frame-fullscreen))
(*is-windows*
(toggle-frame-maximized)))
(toggle-frame-maximized))
(t nil))
;; 配置备份文件和自动保存文件目录
(setq backup-directory-alist
@@ -116,6 +115,9 @@
;; kill-line删除换行符
(setq kill-whole-line t)
;; 更方便地pop mark
(setq set-mark-command-repeat-pop t)
(provide 'init-startup)
;;; init-startup.el ends here

View File

@@ -4,6 +4,9 @@
;;; Code:
;; general
(use-package general)
(defun open-init-file()
"Open user's init.el file in ~/.emacs.d ."
(interactive)
@@ -12,7 +15,12 @@
;; scratch buffer
(if *is-mac*
(general-def "C-c <f12>" 'scratch-buffer)
(general-def "C-c <delete>" 'scratch-buffer))
(general-def "C-c <delete>" 'scratch-buffer)
(general-def "C-c <deletechar>" 'scratch-buffer))
;; diff
(general-def diff-mode-map
"M-o" 'other-window)
;; global map with C-c prefix
(general-def
@@ -27,8 +35,6 @@
;; buffer, file, and window
"<f2>" 'open-init-file
"M-[" 'previous-buffer
"M-]" 'next-buffer
"C-x C-b" 'ibuffer-other-window
"C-x K" 'crux-kill-other-buffers
@@ -39,7 +45,6 @@
"C-," 'crux-duplicate-current-line-or-region
"C-k" 'crux-smart-kill-line
"C-<backspace>" 'crux-kill-line-backwards
"C-a" 'crux-move-beginning-of-line
"M-y" 'yank-from-kill-ring
"C-c DEL" 'hungry-delete-backward
"C-c C-DEL" 'hungry-delete-forward
@@ -47,12 +52,15 @@
"M-N" 'drag-stuff-down
"C-M-@" 'er/mark-symbol
"M-@" 'er/mark-word
"C-M-h" 'backward-kill-sexp
;; undo
"C-/" 'undo
"C-M-_" 'undo-redo
;; navigate
"C-a" 'mwim-beginning
"C-e" 'mwim-end
"M-p" 'backward-paragraph
"M-n" 'forward-paragraph

View File

@@ -20,32 +20,34 @@
:config
(setq expand-region-smart-cursor t))
;; mwim更聪明的beginning/end of line
(use-package mwim)
;; 启用savehist保存命令顺序
(use-package savehist
:init (setq enable-recursive-minibuffers t
history-length 50
savehist-additional-variables '(mark-ring
global-mark-ring
search-ring
regexp-search-ring
extended-command-history)
savehist-autosave-interval 300)
:init
(setq enable-recursive-minibuffers t
history-length 50
savehist-additional-variables '(mark-ring
global-mark-ring
search-ring
regexp-search-ring
extended-command-history)
savehist-autosave-interval 300)
(savehist-mode))
;; saveplace保存光标位置
(use-package saveplace
:init (save-place-mode))
;; ido补全
(use-package ido
:init
(ido-mode)
(ido-everywhere)
:config
(define-key ido-common-completion-map (kbd "SPC") 'ido-restrict-to-matches))
(save-place-mode))
;; general
(use-package general)
;; 补全
(use-package icomplete
:init
(fido-mode)
:config
(keymap-unset minibuffer-local-completion-map "TAB")
(keymap-set minibuffer-local-completion-map "TAB" 'icomplete-force-complete))
(provide 'init-terminal-package)

View File

@@ -16,15 +16,75 @@
(set-language-environment "UTF-8")
(prefer-coding-system 'utf-8)))
;; 主题
;; (load-theme 'tango-dark)
;; 显示文件大小
(size-indication-mode t)
;; 显示行号列号
(column-number-mode t)
;; 高亮
(global-hl-line-mode t)
;; 主题
(if (>= (display-color-cells) 16777216)
(progn
(defvar base03 "#062624")
(defvar base02 "#0c2b29")
(defvar base01 "#4d6967")
(defvar base00 "#728e8c")
(defvar cyan "#01928d")
(defvar blue "#2570cd")
(defvar green "#3a9c36")
(defvar magenta "#d33682")
(defvar yellow "#a87c04")
(defvar orange "#c24713")
(defvar red "#ce2825")
(custom-set-faces
`(default ((t (:foreground ,base00 :background ,base03))))
`(cursor ((t (:inverse t))))
`(region ((t (:exdend t :foreground ,base03 :background ,base00))))
`(shadow ((t (:foreground ,base01))))
`(error ((t (:foreground ,orange))))
`(font-lock-builtin-face ((t (:foreground ,base00 :weight bold :slant normal))))
`(font-lock-comment-face ((t (:foreground ,base01))))
`(font-lock-keyword-face ((t (:foreground ,cyan :weight bold))))
`(font-lock-variable-name-face ((t (:foreground ,blue))))
`(font-lock-constant-face ((t (:foreground ,blue :weight bold))))
`(font-lock-string-face ((t (:foreground ,green))))
`(font-lock-type-face ((t (:foreground ,yellow))))
`(font-lock-function-name-face ((t (:foreground ,blue))))
`(hl-line ((t (:background ,base02 :extend t))))
`(show-paren-match ((t (:foreground ,magenta :weight bold))))
`(show-paren-mismatch ((t (:foreground ,base03 :background ,red))))
`(icomplete-first-match ((t (:foreground ,yellow :weight bold))))
`(completions-common-part ((t (:foreground ,blue))))
`(minibuffer-prompt ((t (:foreground ,base01 :weight bold))))
`(line-number ((t (:foreground ,base01 :weight extra-light))))
`(button ((t (:foreground ,base00 :underline t))))
`(mode-line ((t (:background ,base00 :foreground ,base03))))
`(mode-line-inactive ((t (:background ,base02 :foreground ,base00))))
`(dired-header ((t (:foreground ,green))))
`(dired-directory ((t (:foreground ,blue))))
`(dired-ignored ((t (:foreground ,base01))))
`(isearch ((t (:background ,magenta :foreground ,base03))))
`(lazy-highlight ((t (:background ,yellow :foreground ,base03))))
`(isearch-fail ((t (:foreground ,red))))
`(org-block ((t (:inhert default))))
`(org-document-title ((t (:inhert default :weight bold))))
`(org-document-info ((t (:inhert org-document-title))))
`(eshell-prompt ((t (:foreground ,yellow :weight bold))))
`(diff-header ((t (:foreground ,base00 :background ,base02))))
`(diff-file-header ((t (:inherit: diff-header :weight bold))))
`(diff-hunk-header ((t (:foreground "#c1a059" :background "#253224"))))
`(diff-added ((t (:foreground "#73b971" :background "#103628"))))
`(diff-refine-added ((t (:foreground "#8cc78d" :background "#1d522e"))))
`(diff-removed ((t (:foreground "#e17360" :background "#2d2c25"))))
`(diff-refine-removed ((t (:foreground "#e7917f" :background "#5c3225"))))))
(progn
(global-hl-line-mode nil)))
(provide 'init-terminal-ui)
;;; init-terminal-ui.el ends here

View File

@@ -125,7 +125,7 @@
display-time-string-forms
'((propertize
(concat
(propertize (format-time-string " %H:%M") 'face 'display-time-date-and-time)
(propertize (format-time-string " %I:%M") 'face 'display-time-date-and-time)
(propertize (format-time-string "-%p") 'face 'font-lock-comment-face))
'help-echo (format-time-string "%A, %B %d, %Y"))))
(display-time-mode))

View File

@@ -84,7 +84,8 @@
`(transient-key-noop ((,class (:foreground ,base01 :inherit transient-key))))
`(keycast-key ((,class (:foreground ,green :weight bold))))
`(emms-playlist-track-face ((,class (:foreground ,cyan))))
`(emms-playlist-selected-face ((,class (:foreground ,blue :weight bold)))))))
`(emms-playlist-selected-face ((,class (:foreground ,blue :weight bold))))
`(diff-hunk-header ((,class (:foreground "#c1a059" :background "#253224")))))))
(provide-theme 'my-base16-dark)

View File

@@ -83,7 +83,8 @@
`(transient-key-noop ((,class (:foreground ,base01 :inherit transient-key))))
`(keycast-key ((,class (:foreground ,green :weight bold))))
`(emms-playlist-track-face ((,class (:foreground ,cyan))))
`(emms-playlist-selected-face ((,class (:foreground ,blue :weight bold)))))))
`(emms-playlist-selected-face ((,class (:foreground ,blue :weight bold))))
`(diff-hunk-header ((,class (:foreground "#6b561e" :background "#f0e6b8")))))))
(provide-theme 'my-base16-light)