Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Calling `put-text-property` on the return value of
`filter-buffer-substring-function` will result in modifying
`buffer-undo-list`, which is bad.  We use `propertize` instead in
order to add text properties without modifying the original string.
  • Loading branch information
m2ym committed Jun 29, 2024
1 parent 2548f75 commit 7254ccc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
23 changes: 23 additions & 0 deletions whole-line-or-region-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,29 @@ third"
second
third")))

(ert-deftest wlr-regression-issue-26 ()
(wlr-before-after
"CREATE TABLE account (
name VARCHAR(10) NOT NULL
);|"
(buffer-enable-undo)
(transient-mark-mode 1)
(goto-line 2)
(call-interactively 'whole-line-or-region-kill-region)
"CREATE TABLE account (
|);"
(primitive-undo 1 buffer-undo-list)
"CREATE TABLE account (
| name VARCHAR(10) NOT NULL
);"
(search-forward "10")
(set-mark (- (point) 2))
(should (region-active-p))
(call-interactively 'whole-line-or-region-kill-ring-save)
(call-interactively 'yank)
"CREATE TABLE account (
name VARCHAR(1010|) NOT NULL
);"))


(provide 'whole-line-or-region-test)
Expand Down
8 changes: 3 additions & 5 deletions whole-line-or-region.el
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ The binding ensure killed strings have a yank handler attached."
`(let* ((,orig filter-buffer-substring-function)
(filter-buffer-substring-function
(lambda (&rest args)
(let ((s (apply ,orig args)))
(put-text-property 0 (length s) 'yank-handler
'(whole-line-or-region-yank-handler nil t)
s)
s))))
(propertize (apply ,orig args)
'yank-handler
'(whole-line-or-region-yank-handler nil t)))))
,@body)))

(defun whole-line-or-region-wrap-region-kill (f num-lines)
Expand Down

0 comments on commit 7254ccc

Please sign in to comment.