init-kill.el 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ;;; init-kill.el --- Kill Ring Configuration File -*- lexical-binding: t -*-
  2. ;;; Commentary:
  3. ;; Contains code copied from prelude-editor.el
  4. ;;; Code:
  5. (use-package browse-kill-ring
  6. :defer 5
  7. :config
  8. (browse-kill-ring-default-keybindings))
  9. (use-package easy-kill
  10. :bind
  11. ([remap kill-ring-save] . easy-kill)
  12. ;; emulate expand-region
  13. ("C-=" . easy-mark)
  14. (:map easy-kill-base-map ("C-=" . easy-kill-expand)))
  15. (use-feature emacs
  16. :custom (kill-do-not-save-duplicates t)
  17. :hook
  18. (elpaca-after-init . (lambda ()
  19. ;; Based on code in prelude-editor.el
  20. (defun yank-advised-indent-function (beg end)
  21. "Do indentation, as long as the region isn't too large."
  22. (if (<= (- end beg) 10000)
  23. (indent-region beg end nil)))
  24. (defmacro advise-commands (advice-name commands class &rest body)
  25. "Apply advice named ADVICE-NAME to multiple COMMANDS.
  26. The body of the advice is in BODY."
  27. `(progn
  28. ,@(mapcar (lambda (command)
  29. `(defadvice ,command (,class ,(intern (concat (symbol-name command) "-" advice-name)) activate)
  30. ,@body))
  31. commands)))
  32. (advise-commands "indent" (yank yank-pop) after
  33. (if (and (not (ad-get-arg 0))
  34. (not (member major-mode '(conf-mode coffee-mode haml-mode python-mode slim-mode yaml-mode)))
  35. (or (derived-mode-p 'prog-mode)
  36. (member major-mode '(LaTeX-mode TeX-mode))))
  37. (let ((transient-mark-mode nil))
  38. (yank-advised-indent-function (region-beginning) (region-end))))))))
  39. (provide 'init-kill)
  40. ;;; init-kill.el ends here