Files
.emacs.d/lisp/init-edit.el
Zelong Kuang a416bffb54 Update
2026-04-02 13:27:43 +11:00

148 lines
4.6 KiB
EmacsLisp

;; -*- lexical-binding: t -*-
(use-package delsel
:hook (after-init . delete-selection-mode))
(use-package smartparens
:diminish
:hook (after-init . smartparens-global-mode)
:init (sp-use-paredit-bindings)
:config
;; Autopair quotes more conservatively; if I'm next to a word/before another
;; quote, I don't want to open a new pair or it would unbalance them.
(let ((unless-list '(sp-point-before-word-p
sp-point-after-word-p
sp-point-before-same-p)))
(sp-pair "'" nil :unless unless-list)
(sp-pair "\"" nil :unless unless-list))
(dolist (brace '("(" "{" "["))
(sp-pair brace nil
:post-handlers '(("||\n[i]" "RET") ("| " "SPC"))
;; Don't autopair opening braces if before a word character or
;; other opening brace. The rationale: it interferes with manual
;; balancing of braces, and is odd form to have s-exps with no
;; whitespace in between, e.g. ()()(). Insert whitespace if
;; genuinely want to start a new form in the middle of a word.
:unless '(sp-point-before-word-p sp-point-before-same-p)))
(sp-local-pair sp-lisp-modes "(" ")" :unless '(:rem sp-point-before-same-p))
;; Don't do square-bracket space-expansion where it doesn't make sense to
(sp-local-pair '(emacs-lisp-mode org-mode markdown-mode markdown-ts-mode gfm-mode)
"[" nil :post-handlers '(:rem ("| " "SPC"))))
;; ;; Hungry deletion
;; (use-package hungry-delete
;; :diminish
;; :hook (after-init . global-hungry-delete-mode)
;; :init (setq hungry-delete-chars-to-skip " \t\f\v"
;; hungry-delete-except-modes
;; '(help-mode minibuffer-mode minibuffer-inactive-mode calc-mode)))
(use-package abbrev
:straight nil
:diminish
:config
(setq-default abbrev-mode t)
(setq abbrev-file-name (expand-file-name "abbrev.el" user-emacs-directory)))
(use-package autorevert
:straight nil
:diminish
:hook (after-init . global-auto-revert-mode))
(use-package goto-addr
:straight nil
:hook ((text-mode . goto-address-mode)
(prog-mode . goto-address-prog-mode)))
(use-package multiple-cursors
:hook prog-mode
:bind (("C-S-c C-S-c" . mc/edit-lines)
("C->" . mc/mark-next-like-this)
("C-<" . mc/mark-previous-like-this)
("C-c C-<" . mc/mark-all-like-this)
("C-M->" . mc/skip-to-next-like-this)
("C-M-<" . mc/skip-to-previous-like-this)
("s-<mouse-1>" . mc/add-cursor-on-click)
("C-S-<mouse-1>" . mc/add-cursor-on-click)
:map mc/keymap
("C-|" . mc/vertical-align-with-space)))
(use-package expand-region
:bind ("C-=" . er/expand-region))
(use-package mwim
:bind (([remap move-beginning-of-line] . mwim-beginning)
([remap move-end-of-line] . mwim-end)))
(use-package avy
:bind
(("C-'" . avy-goto-char-timer))
:config
(setq avy-all-windows nil
avy-all-windows-alt t
avy-background t
avy-style 'pre))
;; Kill text between cursor and char
(use-package avy-zap
:bind (("M-z" . avy-zap-to-char-dwim)
("M-Z" . avy-zap-up-to-char-dwim)))
(use-package ace-pinyin
:diminish
:hook (after-init . ace-pinyin-global-mode))
;; show number of matches
(use-package anzu
:diminish
:bind (([remap query-replace] . anzu-query-replace)
([remap query-replace-regexp] . anzu-query-replace-regexp)
:map isearch-mode-map
([remap isearch-query-replace] . anzu-isearch-query-replace)
([remap isearch-query-replace-regexp] . anzu-isearch-query-replace-regexp))
:hook (after-init . global-anzu-mode))
;; Goto last change
(use-package goto-chg
:bind ("C-," . goto-last-change))
;; Treat undo history as a tree
(use-package vundo
:bind ("C-x u" . vundo)
:config (setq vundo-glyph-alist vundo-unicode-symbols))
;; Remember undo history
(use-package undo-fu-session
:hook (after-init . undo-fu-session-global-mode))
;; Process
(use-package proced
:straight nil
:init
(setq-default proced-format 'verbose)
(setq proced-auto-update-flag t
proced-auto-update-interval 3
proced-enable-color-flag t))
(use-package olivetti
:hook org-mode
:diminish
:bind ("<f7>" . olivetti-mode)
:custom
(olivetti-style 'fancy)
(olivetti-margin-width 5)
(olivetti-body-width 90))
(setq-default bidi-display-reordering 'left-to-right
bidi-paragraph-direction 'left-to-right
bidi-display-reordering nil)
(setq bidi-inhibit-bpa t
long-line-threshold 1000
large-hscroll-threshold 1000
syntax-wholeline-max 1000)
(provide 'init-edit)