purcell / whole-line-or-region

In Emacs, operate on current line if no region is active
114 stars 12 forks source link

Weird behaviour when yanking #26

Closed jcs090218 closed 1 month ago

jcs090218 commented 2 months ago

Same issue with emacs -q with GNU Emacs 29.3 (build 2, x86_64-w64-mingw32) of 2024-03-24.

ezgif-4-43418e0f0a

I was expecting the line should be (after yanking):

  name VARCHAR(1010) NOT NULL

And not (in the image):

10
  name VARCHAR(10) NOT NULL

Step to reproduce

  1. emacs -q
  2. eval the following (in scratch buffer):
(require 'package)
(package-initialize)  ; assumed you have this package installed
  1. Open a sql file with these lines:
CREATE TABLE account (
  name VARCHAR(10) NOT NULL
);
  1. M-x whole-line-or-region-local-mode
  2. Navigate to line 2 and M-x whole-line-or-region-kill-region
  3. M-x undo
  4. Select text 10 then M-x kill-ring-save
  5. M-x yank
m2ym commented 2 months ago

I'm facing very same issue. After taking a quick look at the source code, I found that the issue is caused by the uncleared yank-handler text property. It seems to be easy to fix, but I wonder why `yank-handler' is needed actually.

m2ym commented 2 months ago

I'll work on that anyways when I have time.

purcell commented 2 months ago

IIRC, the yank-handler was so that the yank behaviour is overridden when whole-line-or-region-mode is enabled to handle the following case: if you copy the final line of a file, and there's no newline after it, then when it's yanked a newline should be added. Hopefully a test should fail if you disable the yank-handler, but a couple of tests are failing for me right now anyway. I'd appreciate a second opinion!