.emacs.d

the most bloated Emacs config on this planet
git clone https://git.trogloxene.org/.emacs.d.git
Log | Files | Refs

init-edit.el (5810B)


      1 ;;; init-edit.el --- edit and navigate -*- lexical-binding: t -*-
      2 
      3 ;;; Commentary:
      4 
      5 ;;; Code:
      6 
      7 ;; delete select
      8 (my-use-package delsel
      9   :straight nil
     10   :hook
     11   (after-init . delete-selection-mode))
     12 
     13 ;; insert pairs
     14 (my-use-package elec-pair
     15   :straight nil
     16   :config
     17   (setq electric-pair-inhibit-predicate 'electric-pair-conservative-inhibit))
     18 
     19 ;; ediff
     20 (my-use-package ediff
     21   :straight nil
     22   :hook
     23   ((ediff-prepare-buffer . outline-show-all)
     24    (ediff-quit . winner-undo))
     25   :config
     26   (setq ediff-window-setup-function 'ediff-setup-windows-plain
     27         ediff-split-window-function 'split-window-horizontally))
     28 
     29 ;; diff
     30 (my-use-package diff-mode
     31   :straight nil
     32   :init
     33   (defun my-diff-kill-ring-save-hack (fun &rest args)
     34     (let ((major-mode 'diff-mode))
     35       (apply fun args)))
     36   (advice-add #'diff-kill-ring-save :around #'my-diff-kill-ring-save-hack))
     37 
     38 ;; isearch
     39 (my-use-package isearch
     40   :straight nil
     41   :hook
     42   (isearch-mode-end . my-goto-match-beginning)
     43   (lazy-count-update . force-mode-line-update)
     44   :init
     45   (defun my-goto-match-beginning ()
     46     (when (and isearch-forward (not isearch-mode-end-hook-quit))
     47       (goto-char isearch-other-end)))
     48 
     49   ;; move lazy count numbers to mode-line
     50   (setq isearch-lazy-count t
     51         lazy-count-prefix-format nil)
     52 
     53   (defface my-isearch-count
     54     '((t (:inherit font-lock-type-face :weight bold)))
     55     "Face for the isearch match count in the mode-line."
     56     :group 'isearch)
     57 
     58   (defconst my-isearch-count--mode-line-construct
     59     '(:eval (my-isearch-count-format)))
     60 
     61   (defun my-isearch-count-format ()
     62     "Like `isearch-lazy-count-format' but use custom format."
     63     (when (and isearch-mode
     64                isearch-lazy-count
     65                isearch-lazy-count-current
     66                (not isearch-error)
     67                (not isearch-suspended))
     68       (propertize
     69        (format "(%s/%s) "
     70                (if isearch-lazy-highlight-forward
     71                    isearch-lazy-count-current
     72                  (if (eq isearch-lazy-count-current 0)
     73                      0
     74                    (- isearch-lazy-count-total
     75                       isearch-lazy-count-current
     76                       -1)))
     77                (if (and isearch-lazy-count-invisible
     78                         lazy-count-invisible-format)
     79                    (concat (format "%s" (or isearch-lazy-count-total "?"))
     80                            (format lazy-count-invisible-format
     81                                    isearch-lazy-count-invisible))
     82                  (or isearch-lazy-count-total "?")))
     83        'face 'my-isearch-count)))
     84 
     85   (unless (member my-isearch-count--mode-line-construct
     86                   (default-value 'mode-line-format))
     87     (setq-default mode-line-format
     88                   (cons my-isearch-count--mode-line-construct
     89                         (default-value 'mode-line-format)))))
     90 
     91 ;; repeat
     92 (my-use-package repeat
     93   :straight nil
     94   :config
     95   (setq eshell-prompt-repeat-map nil
     96         eshell-command-repeat-map nil
     97         comint-repeat-map nil
     98         shell-repeat-map nil
     99         other-window-repeat-map nil
    100         rotate-windows-repeat-map nil
    101         window-layout-rotate-repeat-map nil
    102         ghostel-prompt-repeat-map nil
    103         jinx-repeat-map nil)
    104   (with-eval-after-load 'org-keys
    105     (setq org-navigation-repeat-map nil))
    106   (with-eval-after-load 'outline
    107     (setq outline-navigation-repeat-map nil)))
    108 
    109 ;; show where your are
    110 (my-use-package which-func
    111   :straight nil
    112   :autoload which-function)
    113 
    114 ;; vcursor
    115 (my-use-package vcursor
    116   :straight nil
    117   :commands vcursor-use-vcursor-map)
    118 
    119 ;; hungry-delete
    120 (my-use-package hungry-delete)
    121 
    122 ;; drag-stuff
    123 (my-use-package drag-stuff)
    124 
    125 ;; save undo history across sessions
    126 (my-use-package undo-fu-session
    127   :hook
    128   (after-init . undo-fu-session-global-mode))
    129 
    130 ;; undo tree
    131 (my-use-package vundo
    132   :init
    133   (setq undo-limit 67108864
    134         undo-strong-limit 100663296
    135         undo-outer-limit 1006632960))
    136 
    137 ;; kmacro enhancement (and multiple cursors)
    138 (my-use-package kmacro-x
    139   :straight
    140   (kmacro-x :fork (:type git :host nil :repo "https://git.trogloxene.org/kmacro-x.git"))
    141   :delight
    142   (kmacro-x-atomic-undo-mode nil)
    143   :hook
    144   (after-init . kmacro-x-atomic-undo-mode)
    145   (kmacro-x-mc-mode . kmacro-x-mc-atomic-undo-mode)
    146   :config
    147   (setq kmacro-x-mc-live-preview t))
    148 
    149 ;; pinyinlib
    150 (my-use-package pinyinlib
    151   :autoload pinyinlib-build-regexp-string
    152   :init
    153   (with-eval-after-load 'orderless
    154     (defun my/orderless-pinyin (component)
    155       (orderless-regexp
    156        (pinyinlib-build-regexp-string component)))
    157     (add-to-list 'orderless-matching-styles #'my/orderless-pinyin)))
    158 
    159 ;; Chinese support for avy
    160 (my-use-package ace-pinyin
    161   :delight
    162   :after avy
    163   :demand t
    164   :config
    165   (ace-pinyin-global-mode))
    166 
    167 ;; avy-zap
    168 (my-use-package avy-zap)
    169 
    170 ;; faster replacement
    171 (my-use-package substitute
    172   :config
    173   (setq substitute-ignore-narrowing nil))
    174 
    175 ;; modal editing
    176 (my-use-package god-mode
    177   :hook
    178   (after-init-hook . which-key-enable-god-mode-support)
    179   (post-command-hook . my-sync-line-numbers-with-god-mode)
    180   :init
    181   (if *is-android* (add-hook 'after-init-hook 'god-mode-all))
    182 
    183   (defun my-sync-line-numbers-with-god-mode ()
    184     (let ((desired (if (and (bound-and-true-p god-local-mode)
    185                             display-line-numbers-mode)
    186                        'relative
    187                      display-line-numbers-type)))
    188       (unless (or (eq display-line-numbers desired) (not display-line-numbers-mode))
    189         (setq display-line-numbers desired))))
    190 
    191   :config
    192   (setq god-mode-enable-function-key-translation nil
    193         god-exempt-major-modes
    194         (cl-union '(diff-mode exwm-mode) god-exempt-major-modes :test 'equal)
    195         god-mode-lighter-string "THANK-GOD-MODE")
    196 
    197   (custom-set-faces '(god-mode-lighter ((t (:inherit error :weight bold))))))
    198 
    199 (provide 'init-edit)
    200 ;;; init-edit.el ends here