Files
.emacs.d/lisp/init-package.el

287 lines
8.6 KiB
EmacsLisp
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
;;; init-package.el --- major packages -*- lexical-binding: t -*-
;;; Commentary:
;;; Code:
(setopt use-package-enable-imenu-support t)
;; 安装gcmh用于管理内存回收
(use-package gcmh
:demand t
:init
(setq gcmh-idle-delay 'auto
gcmh-auto-idle-delay-factor 10
gcmh-high-cons-threshold #x4000000)
:config
(gcmh-mode 1))
;; restart-emacs
(use-package restart-emacs)
;; 安装multiple-cursors
(use-package multiple-cursors
:config (setq mc/insert-numbers-default 1))
;; 安装crux增强快捷键快捷键配置在init-kbd.el中
(use-package crux)
;; 安装hungry-delete
(use-package hungry-delete)
;; 安装drag-stuff拖动字符
(use-package drag-stuff)
;; 安装which-key快捷键提示
(use-package which-key
:defer 0
:config
(which-key-mode))
;; ripgrep
(use-package rg)
;; 安装vertico
(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)))))
;; 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
(use-package embark-consult
:config
(add-hook
'embark-collect-mode-hook
#'consult-preview-at-point-mode))
;; wgrep
(use-package wgrep)
;; 启用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)
(savehist-mode))
;; saveplace保存光标位置
(use-package saveplace
:init (save-place-mode))
;; undo增强
(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
:init (projectile-mode)
:bind (:map projectile-mode-map
("C-x p" . projectile-command-map)
("C-x p b" . consult-project-buffer))
:config (setq projectile-enable-caching t))
(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)))))
;; 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
: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)))
;; flycheck
(use-package flycheck)
(use-package flycheck-guile
:hook (scheme-mode . (lambda ()
(require 'flycheck-guile))))
;; consult-flycheck
(use-package consult-flycheck)
;; vterm
;; (unless *is-windows*
;; (use-package vterm))
;; 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)))))))
;; perspective
(use-package perspective
:bind
("C-x M-b" . persp-list-buffers) ; or use a nicer switcher, see below
:custom
(persp-mode-prefix-key (kbd "C-c p")) ; pick your own prefix key here
: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 "desktop"))
(provide 'init-package)
;;; init-package.el ends here