Skip to content

Commit

Permalink
Check for universal arg before paste
Browse files Browse the repository at this point in the history
This commit fixes syl20bnr#4219 and fixes syl20bnr#8897
  • Loading branch information
bet4it committed Sep 18, 2018
1 parent 9865e77 commit da33aea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
34 changes: 19 additions & 15 deletions layers/+spacemacs/spacemacs-defaults/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions layers/+spacemacs/spacemacs-evil/funcs.el
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ 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)
(evil-paste-after count (or register evil-this-register))))

(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)
Expand Down

0 comments on commit da33aea

Please sign in to comment.