From da33aeade1d36500d299641be240d4a71e298373 Mon Sep 17 00:00:00 2001 From: Bet4 <16643669+bet4it@users.noreply.github.com> Date: Tue, 18 Sep 2018 20:53:55 +0800 Subject: [PATCH] Check for universal arg before paste This commit fixes #4219 and fixes #8897 --- layers/+spacemacs/spacemacs-defaults/funcs.el | 34 +++++++++++-------- layers/+spacemacs/spacemacs-evil/funcs.el | 4 +-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/layers/+spacemacs/spacemacs-defaults/funcs.el b/layers/+spacemacs/spacemacs-defaults/funcs.el index be56037e7df8..29e39a7b6cc6 100644 --- a/layers/+spacemacs/spacemacs-defaults/funcs.el +++ b/layers/+spacemacs/spacemacs-defaults/funcs.el @@ -1292,21 +1292,25 @@ Compare them on count first,and in case of tie sort them alphabetically." (if (<= (- end beg) spacemacs-yank-indent-threshold) (indent-region beg end nil))) -(spacemacs|advise-commands - "indent" (yank yank-pop evil-paste-before evil-paste-after) around - "If current mode is not one of spacemacs-indent-sensitive-modes - indent yanked text (with universal arg don't indent)." - (evil-start-undo-step) - ad-do-it - (if (and (not (equal '(4) (ad-get-arg 0))) - (not (member major-mode spacemacs-indent-sensitive-modes)) - (or (derived-mode-p 'prog-mode) - (member major-mode spacemacs-indent-sensitive-modes))) - (let ((transient-mark-mode nil) - (save-undo buffer-undo-list)) - (spacemacs/yank-advised-indent-function (region-beginning) - (region-end)))) - (evil-end-undo-step)) +(defun spacemacs//yank-indent-region (yank-func &rest args) + "If current mode is not one of spacemacs-indent-sensitive-modes +indent yanked text (with universal arg don't indent)." + (evil-start-undo-step) + (let ((prefix (car args))) + (setcar args (unless (equal '(4) prefix) prefix)) + (apply yank-func args) + (if (and (not (equal '(4) prefix)) + (not (member major-mode spacemacs-indent-sensitive-modes)) + (or (derived-mode-p 'prog-mode) + (member major-mode spacemacs-indent-sensitive-modes))) + (let ((transient-mark-mode nil) + (save-undo buffer-undo-list)) + (spacemacs/yank-advised-indent-function (region-beginning) + (region-end))))) + (evil-end-undo-step)) + +(dolist (func '(yank yank-pop evil-paste-before evil-paste-after)) + (advice-add func :around #'spacemacs//yank-indent-region)) ;; find file functions in split (defun spacemacs//display-in-split (buffer alist) diff --git a/layers/+spacemacs/spacemacs-evil/funcs.el b/layers/+spacemacs/spacemacs-evil/funcs.el index 818569dc3902..4721c617979d 100644 --- a/layers/+spacemacs/spacemacs-evil/funcs.el +++ b/layers/+spacemacs/spacemacs-evil/funcs.el @@ -91,7 +91,7 @@ Otherwise, revert to the default behavior (i.e. enable `evil-insert-state')." (defun spacemacs/evil-mc-paste-after (&optional count register) "Disable paste transient state if there is more than 1 cursor." - (interactive "p") + (interactive "*P") (setq this-command 'evil-paste-after) (if (spacemacs//paste-transient-state-p) (spacemacs/paste-transient-state/evil-paste-after) @@ -99,7 +99,7 @@ Otherwise, revert to the default behavior (i.e. enable `evil-insert-state')." (defun spacemacs/evil-mc-paste-before (&optional count register) "Disable paste transient state if there is more than 1 cursor." - (interactive "p") + (interactive "*P") (setq this-command 'evil-paste-before) (if (spacemacs//paste-transient-state-p) (spacemacs/paste-transient-state/evil-paste-before)