310 lines
9.9 KiB
EmacsLisp
310 lines
9.9 KiB
EmacsLisp
;;; 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))
|
||
|
||
(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
|
||
(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))
|
||
|
||
;; 安装vertico
|
||
(use-package vertico
|
||
:init (vertico-mode t))
|
||
|
||
;; 安装orderless,用于模糊搜索
|
||
(use-package orderless
|
||
:custom (completion-styles '(orderless basic)))
|
||
|
||
;; 安装marginalia,用于命令注释
|
||
(use-package marginalia
|
||
:init (marginalia-mode))
|
||
|
||
;; 安装consult,增强搜索和其他菜单
|
||
(use-package consult
|
||
:config
|
||
|
||
(defun consult-fd-global ()
|
||
"Search for all files use fd"
|
||
(interactive)
|
||
(let ((consult-fd-args "fd -H -I -i -c never --full-path")
|
||
(default-directory "~/"))
|
||
(consult-fd)))
|
||
|
||
(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)))
|
||
|
||
(when *is-mac*
|
||
(setopt consult-locate-args "mdfind -name"))
|
||
|
||
(delete 'consult-source-recent-file consult-buffer-sources))
|
||
|
||
(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))
|
||
:config
|
||
(delete 'consult-dir--source-recentf consult-dir-sources))
|
||
|
||
(use-package consult-notes
|
||
:config
|
||
(setq consult-notes-file-dir-sources '(("Org Notes" ?n "~/org/my-org-note/")
|
||
("Org Journal" ?j "~/org/my-org-daily/" :hidden t))))
|
||
|
||
;; 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和wgrep
|
||
(use-package embark-consult)
|
||
(use-package wgrep)
|
||
|
||
(with-eval-after-load
|
||
'consult
|
||
'(with-eval-after-load
|
||
'embark
|
||
'(progn
|
||
(require 'embark-consult)
|
||
(add-hook
|
||
'embark-collect-mode-hook
|
||
#'consult-preview-at-point-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-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))
|
||
|
||
;; vundop,撤回树
|
||
(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))
|
||
: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))
|
||
|
||
;; general
|
||
(use-package general)
|
||
|
||
;; 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
|