Skip to content

Instantly share code, notes, and snippets.

@dvzubarev
Last active February 8, 2024 17:55
Show Gist options
  • Save dvzubarev/c7146d9ddb68b1fa850cd71314f388fb to your computer and use it in GitHub Desktop.
Save dvzubarev/c7146d9ddb68b1fa850cd71314f388fb to your computer and use it in GitHub Desktop.
(defun my-copy-region-advice (orig-func beg end &rest r)
(with-silent-modifications
(save-excursion
(goto-char beg)
(put-text-property beg (1+ beg) 'first-line-indent (current-column))))
(unwind-protect
(apply orig-func beg end r)
(with-silent-modifications
(remove-text-properties beg (1+ beg) '(first-line-indent)))))
(advice-add 'copy-region-as-kill :around #'my-copy-region-advice)
(defun my-kill-transform-function (text)
(if-let ((indent (get-text-property 0 'first-line-indent text)))
(concat (make-string indent 32) text)
text))
(if (null kill-transform-function)
(setq kill-transform-function #'my-kill-transform-function)
(add-function :filter-return (local 'kill-transform-function)
#'my-kill-transform-function))
(defun my-yank-transform-func (text)
(evil-ts-obj-util--indent-text-according-to-point-pos text))
(add-to-list 'yank-transform-functions #'my-yank-transform-func)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment