init-editor.el 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. ;;; init-editor.el --- Editing Configuration File -*- lexical-binding: t -*-
  2. ;;; Commentary:
  3. ;; based on prelude-editor.el
  4. ;;; Code:
  5. (use-feature emacs
  6. :bind
  7. ("C-x \\" . align-regexp)
  8. ("C-+" . text-scale-increase)
  9. ("C--" . text-scale-decrease)
  10. :hook
  11. (after-save . executable-make-buffer-file-executable-if-script-p)
  12. (elpaca-after-init . (lambda ()
  13. (save-place-mode 1)
  14. (delete-selection-mode t)
  15. (global-auto-revert-mode 1)
  16. (set-terminal-coding-system 'utf-8)
  17. (set-keyboard-coding-system 'utf-8)
  18. (set-selection-coding-system 'utf-8)
  19. (prefer-coding-system 'utf-8)))
  20. ;; (text-mode . whitespace-cleanup)
  21. :config
  22. (put 'narrow-to-region 'disabled nil)
  23. (put 'narrow-to-page 'disabled nil)
  24. (put 'narrow-to-defun 'disabled nil)
  25. (put 'upcase-region 'disabled nil)
  26. (put 'downcase-region 'disabled nil)
  27. (put 'erase-buffer 'disabled nil)
  28. (setq-default indent-tabs-mode nil
  29. tab-width 4)
  30. (setq comment-auto-fill-only-comments t)
  31. (setq large-file-warning-threshold 100000000)
  32. (setq create-lockfiles nil)
  33. (setq global-auto-revert-non-file-buffers t
  34. revert-without-query (list ".")
  35. auto-revert-stop-on-user-input nil)
  36. (setq backup-by-copying t
  37. delete-old-versions t
  38. version-control t
  39. kept-new-versions 5
  40. kept-old-versions 5)
  41. (setq backup-directory-alist
  42. `((".*" . ,temporary-file-directory))
  43. auto-save-file-name-transforms
  44. `((".*" ,temporary-file-directory t))
  45. auto-save-include-big-deletions t)
  46. (setq comment-multi-line t
  47. comment-empty-lines t)
  48. (setq save-place-file (expand-file-name "saveplace" save-dir)
  49. save-place-limit 800)
  50. ;; https://git.sr.ht/~technomancy/better-defaults/tree/master/item/better-defaults.el
  51. (setq save-interprogram-paste-before-kill t
  52. apropos-do-all t
  53. mouse-yank-at-point t
  54. require-final-newline t)
  55. (setq ffap-machine-p-local 'accept
  56. ffap-machine-p-known 'reject
  57. ffap-machine-p-unkown 'reject)
  58. (setq sentence-end-double-space nil)
  59. (set-language-environment "UTF-8")
  60. ;; The previous line sets this to "rfc1345"
  61. (setq default-input-method nil)
  62. (set-default 'imenu-auto-rescan t))
  63. (use-package move-text
  64. :bind
  65. ("M-S-<up>" . move-text-up)
  66. ("M-S-<down>" . move-text-down))
  67. (use-package zop-to-char
  68. :bind
  69. ("M-z" . zop-up-to-char)
  70. ("M-Z" . zop-to-char))
  71. (use-feature savehist
  72. :custom
  73. (savehist-additional-variables '(search-ring regexp-search-ring))
  74. (savehist-autosave-interval 60)
  75. (savehist-file (expand-file-name "savehist" save-dir))
  76. (history-length 300)
  77. :hook (elpaca-after-init . savehist-mode))
  78. (use-package super-save
  79. :defer 5
  80. :diminish
  81. :custom
  82. (super-save-remote-files nil)
  83. :config
  84. (super-save-mode +1)
  85. (add-to-list 'super-save-triggers 'ace-window)
  86. (add-to-list 'super-save-hook-triggers 'find-file-hook))
  87. (use-feature recentf
  88. :config
  89. (add-to-list 'recentf-exclude (expand-file-name "elpa" user-emacs-directory))
  90. (add-to-list 'recentf-exclude (expand-file-name "straight" user-emacs-directory))
  91. :custom
  92. (recentf-save-file (expand-file-name "recentf" save-dir))
  93. (recentf-max-saved-items 300)
  94. (recentf-max-menu-items 20)
  95. (recentf-auto-cleanup (* 60 60))
  96. :hook (elpaca-after-init . recentf-mode))
  97. (use-package flycheck
  98. :config
  99. (global-flycheck-mode))
  100. (use-feature flyspell
  101. :diminish
  102. :config
  103. (when (string-suffix-p "aspell" ispell-program-name)
  104. (setq ispell-extra-args '("--sug-mode=ultra")))
  105. (unbind-key "C-," flyspell-mode-map)
  106. (unbind-key "C-." flyspell-mode-map)
  107. ;;(unbind-key "C-;" flyspell-mode-map)
  108. :custom (flyspell-auto-correct-binding (kbd "C-x C-M-;"))
  109. :bind (:map flyspell-mode-map
  110. ("C-x C-," . flyspell-goto-next-error)
  111. ("C-x C-." . flyspell-correct-word))
  112. :hook
  113. (text-mode . flyspell-mode)
  114. (prog-mode . flyspell-prog-mode))
  115. (use-feature bookmark
  116. :custom
  117. (bookmark-default-file (expand-file-name "bookmarks" save-dir))
  118. (bookmark-save-flag 1))
  119. (use-feature midnight)
  120. (use-package undo-tree
  121. :defer 5
  122. :diminish
  123. :config
  124. (global-undo-tree-mode)
  125. :custom
  126. (undo-tree-enable-undo-in-region t)
  127. (undo-tree-history-directory-alist `((".*" . ,temporary-file-directory)))
  128. (undo-tree-auto-save-history t))
  129. (use-feature abbrev
  130. :diminish
  131. :hook
  132. (text-mode . abbrev-mode)
  133. (prog-mode . abbrev-mode)
  134. (cider-repl-mode . abbrev-mode))
  135. (use-feature subword
  136. :diminish)
  137. (use-package markdown-mode
  138. :config
  139. (add-to-list 'auto-mode-alist '("\\.markdown\\'" . gfm-mode))
  140. (add-to-list 'auto-mode-alist '("\\.md\\'" . gfm-mode)))
  141. ;; (use-package adoc-mode
  142. ;; (add-to-list 'auto-mode-alist '("\\.adoc\\'" . adoc-mode))
  143. ;; (add-to-list 'auto-mode-alist '("\\.asciidoc\\'" . adoc-mode)))
  144. (use-package operate-on-number
  145. :bind
  146. ("C-c +" . operate-on-number-at-point))
  147. (defun +elpaca-unload-xref (e)
  148. (and (featurep 'xref) (unload-feature 'xref t))
  149. ;; Make sure xref-find-definitions doesn't override this embark binding (unless https://github.com/oantolin/embark/issues/732 can be fixed)
  150. (bind-key "M-." 'embark-dwim)
  151. ;; Make sure these aren't overwritten
  152. (setq xref-search-program 'ripgrep
  153. xref-show-xrefs-function #'consult-xref
  154. xref-show-definitions-function #'consult-xref)
  155. (elpaca--continue-build e))
  156. (defun +elpaca-xref-build-steps ()
  157. (append (butlast (if (file-exists-p (expand-file-name "xref" elpaca-builds-directory))
  158. elpaca--pre-built-steps elpaca-build-steps))
  159. (list '+elpaca-unload-xref 'elpaca--activate-package)))
  160. (use-package xref
  161. :ensure `(xref :build ,(+elpaca-xref-build-steps))
  162. :custom
  163. (xref-search-program 'ripgrep)
  164. (xref-show-xrefs-function #'consult-xref)
  165. (xref-show-definitions-function #'consult-xref)
  166. :config
  167. (defun xref-find-references-current-defun ()
  168. "`xref-find-references' for the enclosing defun."
  169. (interactive)
  170. (xref-backend-identifier-completion-table (xref-find-backend))
  171. (xref-find-references (which-function)))
  172. (defun xref-find-definitions-current-list-function ()
  173. "`xref-find-definitions' for the function at the beginning of the current list.
  174. With a prefix argument, moves up `current-prefix-arg' sexps first."
  175. (interactive)
  176. (let ((fn-name (save-excursion
  177. (when current-prefix-arg
  178. (sp-backward-up-sexp current-prefix-arg))
  179. (sp-beginning-of-sexp) (thing-at-point 'symbol))))
  180. (xref-find-definitions fn-name)))
  181. (defun xref-find-references-other-window (identifier)
  182. "Like `xref-find-references' but switch to the other window."
  183. (interactive (list (xref--read-identifier "Find references of: ")))
  184. (xref--find-xrefs identifier 'references identifier 'window))
  185. (defun xref-find-references-other-frame (identifier)
  186. "Like `xref-find-references' but switch to the other frame."
  187. (interactive (list (xref--read-identifier "Find references of: ")))
  188. (xref--find-xrefs identifier 'references identifier 'frame))
  189. (define-key ctl-x-4-map (kbd "M-?") 'xref-find-references-other-window)
  190. (define-key ctl-x-5-map (kbd "M-?") 'xref-find-references-other-window)
  191. ;; 'xref-prompt-for-identifier begins with not, so adding this prevents
  192. ;; prompting for an identifier when calling xref-find-references, unless
  193. ;; there is no value at point that can be used
  194. (add-to-list 'xref-prompt-for-identifier 'xref-find-references t)
  195. (add-to-list 'xref-prompt-for-identifier 'xref-find-references-other-window t)
  196. (add-to-list 'xref-prompt-for-identifier 'xref-find-references-other-frame t)
  197. :bind
  198. ("C-c q" . xref-find-references-current-defun)
  199. ("C-c C-M-." . xref-find-definitions-current-list-function)
  200. ;; Make sure xref-find-definitions doesn't override this embark binding (unless https://github.com/oantolin/embark/issues/732 can be fixed)
  201. ("M-." . embark-dwim))
  202. (use-package ws-butler
  203. :diminish
  204. :hook (prog-mode . ws-butler-mode))
  205. (use-package aggressive-indent
  206. :diminish
  207. :config
  208. (unbind-key "C-c C-q" aggressive-indent-mode-map)
  209. ;; don't indent lisp comments
  210. (add-to-list 'aggressive-indent-dont-indent-if
  211. '(and (derived-mode-p 'prog-mode)
  212. (string-match "^\s*;"
  213. (or (thing-at-point 'line) ""))))
  214. :hook
  215. (emacs-lisp-mode . aggressive-indent-mode))
  216. (use-package hungry-delete
  217. :diminish
  218. :hook (prog-mode . turn-on-hungry-delete-mode))
  219. (use-package mwim
  220. :bind
  221. ("C-a" . mwim-beginning)
  222. ("C-e" . mwim-end))
  223. (use-package auto-yasnippet
  224. :bind
  225. ("C-c C-y w" . aya-create)
  226. ("C-c C-y TAB" . aya-expand)
  227. ("C-c C-y SPC" . aya-expand-from-history)
  228. ("C-c C-y d" . aya-delete-from-history)
  229. ("C-c C-y c" . aya-clear-history)
  230. ("C-c C-y n" . aya-next-in-history)
  231. ("C-c C-y p" . aya-previous-in-history)
  232. ("C-c C-y s" . aya-persist-snippet)
  233. ("C-c C-y o" . aya-open-line))
  234. (use-package editorconfig
  235. :diminish
  236. :custom (editorconfig-trim-whitespaces-mode 'ws-butler-mode)
  237. :hook (elpaca-after-init . editorconfig-mode))
  238. (use-package titlecase
  239. :bind (("C-c c t t" . titlecase-dwim)
  240. (:map embark-heading-map ("T" . titlecase-line))
  241. (:map embark-region-map ("T" . titlecase-region))))
  242. (use-package caser
  243. :ensure (caser :host github :repo "emacsmirror/caser")
  244. :bind
  245. ("C-c c c" . caser-camelcase-dwim)
  246. ("C-c c s" . caser-snakecase-dwim)
  247. ("C-c c d" . caser-dashcase-dwim))
  248. (use-package selected
  249. :defer 6
  250. :diminish selected-minor-mode
  251. :config
  252. (setq selected-emacs-lisp-mode-map (make-sparse-keymap)
  253. selected-org-mode-map (make-sparse-keymap)
  254. selected-clojure-mode-map (make-sparse-keymap))
  255. (add-to-list 'selected-ignore-modes 'magit-status-mode)
  256. (selected-global-mode +1)
  257. :bind (:map selected-keymap
  258. ("q" . selected-off)
  259. ("u" . upcase-region)
  260. ("l" . downcase-region)
  261. ("C" . count-words-region)
  262. ("m" . apply-macro-to-region-lines)
  263. ("c" . copy-region-as-kill)
  264. ("M-d" . sp-delete-region)
  265. ("j" . jq-format-json-region)
  266. ("i" . indent-region)
  267. ("C-d" . duplicate-dwim)
  268. ("n" . narrow-to-region)
  269. ("_" . ws-butler-clean-region)
  270. ("t t" . titlecase-dwim)
  271. ("t c" . caser-camelcase-dwim)
  272. ("t s" . caser-snakecase-dwim)
  273. ("t d" . caser-dashcase-dwim)
  274. :map selected-org-mode-map
  275. ("t" . org-table-convert-region)
  276. :map selected-emacs-lisp-mode-map
  277. ("x" . elisp-eval-region-or-buffer)
  278. :map selected-clojure-mode-map
  279. ("x" . cider-eval-region)
  280. ("r" . cider-insert-region-in-repl)))
  281. (provide 'init-editor)
  282. ;;; init-editor.el ends here