smartparens icon indicating copy to clipboard operation
smartparens copied to clipboard

sp-backward-kill-word and prefix arg in text- and org-mode

Open contrapunctus-1 opened this issue 8 years ago • 4 comments

I have observed this in text-mode and org-mode; it does not happen in fundamental-mode. EDIT - I just realized that C-y was bound to whole-line-or-region-yank (from whole-line-or-region.el). The behavior described below does not occur with the default yank command. This issue may not be (as) relevant, in that case.

Expected behavior

Point represented by |, and C-w bound to sp-backward-kill-word - The quick brown fox.| C-4 C-w | C-y The quick brown fox.|

Actual behavior

The quick brown fox.| C-4 C-w | C-y The | C-y The The |

Environment & version information

  • smartparens version: 1.10.1
  • Active major-mode: (org-mode|text-mode)
  • Emacs version (M-x emacs-version): GNU Emacs 24.5.1 (i686-pc-linux-gnu, GTK+ Version 3.22.12) of 2017-04-29 on x86-grnet-01, modified by Debian
  • Spacemacs/Evil/Other starterkit (specify which)/Vanilla: Vanilla
  • OS: Debian Testing

contrapunctus-1 avatar Jun 23 '17 16:06 contrapunctus-1

I can reproduce this on emacs 25.2.1 even with the default yank. I think there is a bug somewhere in this after all :)

Fuco1 avatar Jun 23 '17 20:06 Fuco1

Hm, there's this issue though. sp-kill-word and friends were designed to skip over delimiters so you can call it in a context like this (yank raw-prefix)))| and it would kill the word prefix but leave the parens alone to not break your stuff. This is, I think, super handy.

What should then happen if we have a context like foo ) bar| and we call it with an argument 2. Should it yank back foobar or foo bar? The resulting buffer would look like |) after the kill.

The built-in kill-word just forwards n words and then kills the region from point to there, but that would also wipe delimiters etc.

Fuco1 avatar Jun 23 '17 20:06 Fuco1

I think the current behaviour is fine for that use case. (yanking "foobar", in your example, would be useless, so yanking the last deleted word is better.)

Perhaps the behaviour should change depending on whether one is in a programming mode or a natural language mode? (chat modes like erc/rcirc/circe, text-mode, org-mode, ...)

So in programming modes we'd have - foo ) bar | C-2 <M-backspace> |) C-y foo|) M-y bar|)

And in natural language modes we'd have - foo ) bar | C-2 <M-backspace> |) C-y foo bar|)

contrapunctus-1 avatar Jun 24 '17 19:06 contrapunctus-1

If the function is called 4 times manually, without a prefix, it actually works correctly, because any function that uses kill-region internally automatically gets this behaviour. But with the prefix argument, we call kill-region from the same command invocation four times and this smart Emacs behaviour does not trigger, so it only keeps the last kill.

The solution is to call kill-region ourselves only on the first word and then actually use kill-append.

  • [ ] Fix sp-kill-symbol
  • [ ] go over all the commands using kill-region and check if they are looping internally, if so, add the kill-append logic

Fuco1 avatar Mar 24 '24 21:03 Fuco1