about summary refs log tree commit diff stats
path: root/.emacs.d/lisp/init-kill.el
blob: f442fda82dcd307632629a46dc09e3aad6868ca3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
;;; init-kill.el --- Kill Ring Configuration File -*- lexical-binding: t -*-
;;; Commentary:
;; Contains code copied from prelude-editor.el
;;; Code:

(use-package browse-kill-ring
  :defer 5
  :config
  (browse-kill-ring-default-keybindings))

(use-package easy-kill
  :bind
  ([remap kill-ring-save] . easy-kill)
  ;; emulate expand-region
  ("C-=" . easy-mark)
  (:map easy-kill-base-map ("C-=" . easy-kill-expand)))

(use-package emacs
  :hook
  (emacs-startup . (lambda ()
                     ;; Based on code in prelude-editor.el
                     (defun yank-advised-indent-function (beg end)
                       "Do indentation, as long as the region isn't too large."
                       (if (<= (- end beg) 10000)
                           (indent-region beg end nil)))

                     (defmacro advise-commands (advice-name commands class &rest body)
                       "Apply advice named ADVICE-NAME to multiple COMMANDS.

The body of the advice is in BODY."
                       `(progn
                          ,@(mapcar (lambda (command)
                                      `(defadvice ,command (,class ,(intern (concat (symbol-name command) "-" advice-name)) activate)
                                         ,@body))
                                    commands)))

                     (advise-commands "indent" (yank yank-pop) after
                                      (if (and (not (ad-get-arg 0))
                                               (not (member major-mode '(conf-mode coffee-mode haml-mode python-mode slim-mode yaml-mode)))
                                               (or (derived-mode-p 'prog-mode)
                                                   (member major-mode '(LaTeX-mode TeX-mode))))
                                          (let ((transient-mark-mode nil))
                                            (yank-advised-indent-function (region-beginning) (region-end))))))))

(provide 'init-kill)
;;; init-kill.el ends here