;;; init-package.el --- major packages -*- lexical-binding: t -*- ;;; Commentary: ;;; Code: (setopt use-package-enable-imenu-support t) ;; restart-emacs (use-package restart-emacs) ;; async (unless *is-android* (use-package async :init (dired-async-mode) (async-bytecomp-package-mode 1) (setq async-bytecomp-allowed-packages '(all)))) ;; multiple-cursors (use-package multiple-cursors :config (setq mc/insert-numbers-default 1)) ;; crux,实用函数 (use-package crux) ;; hungry-delete,快速删除 (use-package hungry-delete) ;; drag-stuff,拖动字符 (use-package drag-stuff) ;; which-key,快捷键提示 (use-package which-key :delight :defer 0 :config (which-key-mode)) ;; ripgrep (use-package rg) ;; vertico,minibuffer补全 (use-package vertico :init (vertico-mode)) ;; orderless,模糊搜索 (use-package orderless :custom (completion-styles '(orderless basic))) ;; marginalia,命令注释 (use-package marginalia :init (marginalia-mode)) ;; 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)) (add-to-list 'process-coding-system-alist '("es" gbk . gbk))) ;; mdfind (when *is-mac* (setq consult-locate-args "mdfind -name")) ;; plocate (when *is-linux* (setq consult-locate-args "plocate --basename --ignore-case"))) ;; embark,快捷指令 (use-package embark :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))))) (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 (use-package embark-consult :config (add-hook 'embark-collect-mode-hook #'consult-preview-at-point-mode)) ;; wgrep,writable grep (use-package wgrep) ;; anzu,显示isearch匹配数字 (use-package anzu :delight :init (global-anzu-mode)) ;; 启用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-ignored-variables '(consult-notes-history) savehist-autosave-interval 300) (savehist-mode)) ;; 启用saveplace,保存光标位置 (use-package saveplace :init (save-place-mode)) ;; 撤回增强和跨会话历史 (use-package undo-fu) (use-package undo-fu-session :init (undo-fu-session-global-mode)) ;; vundo,撤回树 (use-package vundo :init (setq undo-limit 800000 undo-strong-limit 1200000 undo-outer-limit 12000000)) ;; expand-region,快速展开选中 (use-package expand-region) ;; projectile,项目管理 (use-package projectile :delight :init (projectile-mode) (projectile-known-projects) :bind (:map projectile-mode-map ("C-x p" . projectile-command-map) ("C-x p b" . consult-project-buffer)) :config (setq projectile-enable-caching 'persistent) (setq projectile-auto-discover t) (setq projectile-auto-cleanup-known-projects t)) ;; ibuffer (use-package ibuffer :config (setq ibuffer-saved-filter-groups '(("Main" ("App" (mode . exwm-mode)) ("Scratch" (or (name . "^*scratch"))) ("Shell" (or (mode . eshell-mode) (mode . eat-mode) (mode . vterm-mode))) ("Scripts" (or (mode . shell-script-mode) (mode . shell-mode) (mode . sh-mode) (mode . lua-mode) (mode . bat-mode))) ("Elisp" (mode . emacs-lisp-mode)) ("Scheme" (or (mode . scheme-mode) (name . "^*Geiser"))) ("Text" (or (mode . org-mode) (mode . markdown-mode))) ("Emacs" (or (name . "^\\*Help\\*$") (name . "^\\*Custom.*") (name . "^\\*Org Agenda\\*$") (name . "^\\*info\\*$") (name . "^\\*Backtrace\\*$") (name . "^\\*Messages\\*$") (name . "*Chinese-word-segmentation*") (name . "^*Buffer List*") (name . "*Calendar*"))) ("Magit" (or (mode . magit-blame-mode) (mode . magit-cherry-mode) (mode . magit-diff-mode) (mode . magit-log-mode) (mode . magit-process-mode) (mode . magit-status-mode))) ("Directories" (or (mode . dired-mode) (name . "^*dirvish"))) ("Diff" (name . "^*Diff"))))) (add-hook 'ibuffer-hook (lambda () (ibuffer-switch-to-saved-filter-groups "Main") (unless (eq ibuffer-sorting-mode 'alphabetic) (ibuffer-do-sort-by-alphabetic)))) (setq ibuffer-show-empty-filter-groups nil) (setq ibuffer-use-other-window t) (setq ibuffer-default-sorting-mode 'filename)) ;; avy中文支持 (use-package ace-pinyin :delight :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 :delight (jinx-mode " Jinx" jinx) :hook (org-mode-hook . jinx-mode) :bind ([remap ispell-word] . jinx-correct) :config (setq jinx-languages "en_US") (add-to-list 'jinx-exclude-regexps '(t "\\cc")) (with-eval-after-load 'jinx (dolist (range '((#x4E00 . #x9FFF) (#x3400 . #x4DBF) (#x3000 . #x303F) (#xFF00 . #xFFEF) (#x20000 . #x2A6DF))) (let ((start (car range)) (end (cdr range))) (dotimes (i (- end start)) (modify-syntax-entry (+ start i) "_" jinx--syntax-table))))) (require 'init-jinx))) ;; eat,终端 (use-package eat :straight (eat :type git :host codeberg :repo "akib/emacs-eat" :files ("*.el" ("term" "term/*.el") "*.texi" "*.ti" ("terminfo/e" "terminfo/e/*") ("terminfo/65" "terminfo/65/*") ("integration" "integration/*") (:exclude ".dir-locals.el" "*-tests.el"))) :hook ((eshell-load . eat-eshell-mode) (eshell-load . eat-eshell-visual-command-mode)) :config (setq eat-term-terminfo-directory eat--terminfo-path)) ;; general,键位绑定 (use-package general) ;; hydra (use-package hydra :defines (consult-imenu-config) :init (with-eval-after-load 'consult-imenu (setq consult-imenu-config '((emacs-lisp-mode :toplevel "Functions" :types ((?f "Functions" font-lock-function-name-face) (?h "Hydras" font-lock-constant-face) (?m "Macros" font-lock-function-name-face) (?p "Packages" font-lock-constant-face) (?t "Types" font-lock-type-face) (?v "Variables" font-lock-variable-name-face))))))) ;; god-mode,模态编辑 (use-package god-mode :init (if *is-android* (god-mode-all)) :config (unless *is-android* (which-key-enable-god-mode-support)) (setq god-mode-enable-function-key-translation nil) (defun my-sync-line-numbers-with-god-mode () (let ((desired (if (bound-and-true-p god-local-mode) 'relative t))) (unless (or (eq display-line-numbers desired) (bound-and-true-p olivetti-mode)) (setq display-line-numbers desired)))) (add-hook 'post-command-hook #'my-sync-line-numbers-with-god-mode) (setq god-exempt-major-modes (delete-dups (append '(diff-mode exwm-mode) god-exempt-major-modes)))) ;; perspective,工作区管理 (use-package perspective :bind ("C-x M-b" . persp-list-buffers) :custom (persp-mode-prefix-key (kbd "C-c p")) :init (persp-mode) :config (setq persp-switch-to-buffer-behavior 'switch) (with-eval-after-load 'consult (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)))) (setq persp-initial-frame-name "main")) ;; magit (use-package magit) (provide 'init-package) ;;; init-package.el ends here