Fuco1 / smartparens

Minor mode for Emacs that deals with parens pairs and tries to be smart about it.
GNU General Public License v3.0
1.82k stars 195 forks source link

Delete commands bugging out yank #1097

Closed AkashaP closed 11 months ago

AkashaP commented 3 years ago

Ive noticed a lot of delete commands seem to bug out the emacs yanking system, but im not sure exactly why. I dont know if this is because of smartparens but using smartparens based commands does cause the bug to happen.

Expected behavior

delete commands to leave next yank alone, as per the steps:

  1. write some text
  2. Place cursor before it
  3. invoke vanilla 'kill-region' command on it
  4. Repeat 1 and 2 with different text
  5. invoke vanilla 'delete-region' command on that
  6. yank. Should yank the text that was killed using kill-region

Actual behavior

The equivalent smartparens commands seem to bug out yank system completely and yank something i think i appended to the kill ring like days or weeks ago

Steps to reproduce the problem

(The bug seems to happen with all delete-like commands and not just sp-delete-word)

  1. write some text
  2. Place cursor before it
  3. invoke 'sp-kill-word' command on it
  4. Repeat 1 and 2 with different text
  5. invoke vanilla 'sp-delete-word' command on that
  6. yank

I usually end up with text i dont even know where it is coming from. I'm relatively new to emacs, I looked at the smartparens source and saw that it does something along the lines of shadowing the kill-ring in a let so that the real kill-ring doesnt actually get changed.

In addition i can't yank-pop after step 6 i get the error 'previous command was not a yank'

But when i evaluate (car kill-ring-yank-pointer) i can see that the deleted text is still there ~~, but not in (car kill-ring). I dont really understand why kill-ring-yank-pointer contains different things from kill-ring or why it bugs out yank. I might experiment around with my own yank command that just pops kill-ring-yank-pointer or something. EDIT just looked at the documentation for emacs and i think most of this is actually working as intended but~~ doing the steps for the vanilla emacs commands doesnt append the deleted text to kill-ring-yank-pointer

By the way, looking at emacs source i can see that emacs itself is coded to put its delete commands in terms of kill commands but i find that logic so backwards, shouldnt it be the other way around?

Backtraces if necessary (M-x toggle-debug-on-error)

Environment & version information

im using spacemacs-base for my emacs configuration

AkashaP commented 3 years ago

I have found a solution that seems to work for me but i have no idea if it is a good idea or not

(defun sp-delete-word-issue-1097 ()
  "hotfix for https://github.com/Fuco1/smartparens/issues/1097#issue-970201884"
  (interactive)
  (make-local-variable 'kill-ring-yank-pointer) ;; is this really safe?
  (let* (;;(kill-ring kill-ring)
         (kill-ring-yank-pointer kill-ring-yank-pointer)
         (select-enable-clipboard nil))
    (sp-delete-word 1)))
Fuco1 commented 3 years ago

Yea, I also get this from time to time but I never connected it to smartparens. It might be that some internals changed in the meantime and our code is no longer compatible with newer Emacs versions. I'll test your fix.

Fuco1 commented 11 months ago

Fixed in #1169