Skip to content

Commit

Permalink
fix(kill-ring): prevent kill-ring-yank-pointer changes when deleting
Browse files Browse the repository at this point in the history
See comments in #1169
  • Loading branch information
Fuco1 committed Oct 20, 2023
1 parent dd22a3e commit 708f2d6
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions smartparens.el
Original file line number Diff line number Diff line change
Expand Up @@ -6622,6 +6622,20 @@ Note: prefix argument is shown after the example in
(when (= 0 sp-successive-kill-preserve-whitespace)
(kill-append sp-last-kill-whitespace nil)))))))))

(defmacro sp-save-kill-ring (&rest forms)
"Run FORMS while preserving `kill-ring'.

Any changes to `kill-ring' inside this macro will be reversed
after exiting.

The changes are usually done by functions suck as `kill-region',
`copy-region-as-kill', `kill-append' and similar."
(declare (indent 0))
`(let* ((kill-ring nil)
(kill-ring-yank-pointer nil)
(select-enable-clipboard nil))
,@forms))

(defun sp-delete-sexp (&optional arg)
"Delete the balanced expression following point.

Expand All @@ -6635,8 +6649,7 @@ backward direction.

See also `sp-kill-sexp' examples."
(interactive "*p")
(let* ((kill-ring nil)
(select-enable-clipboard nil))
(sp-save-kill-ring
(sp-kill-sexp arg)))

(defun sp--cleanup-after-kill ()
Expand Down Expand Up @@ -6706,8 +6719,7 @@ forward direction.

See also `sp-backward-kill-sexp' examples."
(interactive "*p")
(let* ((kill-ring nil)
(select-enable-clipboard nil))
(sp-save-kill-ring
(sp-backward-kill-sexp arg)))

(defun sp-copy-sexp (&optional arg)
Expand Down Expand Up @@ -9122,8 +9134,7 @@ backward direction.

See `sp-forward-symbol' for what constitutes a symbol."
(interactive "*p")
(let* ((kill-ring nil)
(select-enable-clipboard nil))
(sp-save-kill-ring
(sp-kill-symbol arg word)))

(defun sp-delete-word (&optional arg)
Expand Down Expand Up @@ -9199,8 +9210,7 @@ forward direction.

See `sp-backward-symbol' for what constitutes a symbol."
(interactive "*p")
(let* ((kill-ring nil)
(select-enable-clipboard nil))
(sp-save-kill-ring
(sp-backward-kill-symbol arg word)))

(defun sp-backward-delete-word (&optional arg)
Expand Down

0 comments on commit 708f2d6

Please sign in to comment.