From 45209275259c71b1f68cce4760747fa0ccc93b9b Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Sat, 26 Nov 2022 23:19:43 +0000 Subject: paredit-kill: Tweak rule for adding space if kill-whole-line is t. For now, disable the yank part of the test -- with kill-whole-line, killing and then yanking is not always a noop and it's not clear making it a noop is the right approach. I don't use kill-whole-line so I'm not sure what expectations are and I'm reluctant to change it, except to fix obviously-wrong outcomes like (x|(y)) that should be (x| (y)). While here, document the effect of kill-whole-line on paredit-kill. --- NEWS | 5 +++++ paredit.el | 17 +++++++++-------- test.el | 27 +++++++++++++-------------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/NEWS b/NEWS index 59659bb..29f9ca8 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,11 @@ https://paredit.org Latest release: https://paredit.org/paredit.el Current development version: https://paredit.org/paredit-beta.el +** Version 27 (beta) + +*** Improved some edge cases in paredit-kill with kill-whole-line enabled. +**** Many other edge cases are slightly broken; patches welcome! + ** Version 26 -- 2022-11-26 Minor bug fix release, mainly to set a new branch scheme: diff --git a/paredit.el b/paredit.el index 8522421..ea14a15 100644 --- a/paredit.el +++ b/paredit.el @@ -1509,7 +1509,12 @@ On a line with no S-expressions on it starting after the point or within a comment, act exactly as `kill-line'. Otherwise, kill all S-expressions that start after the point. With a `C-u' prefix argument, just do the standard `kill-line'. -With a numeric prefix argument N, do `kill-line' that many times." +With a numeric prefix argument N, do `kill-line' that many times. + +If `kill-whole-line' is true, kills the newline character and + indentation on the next line as well. +In that case, ensure there is at least one space between the + preceding S-expression and whatever follows on the next line." (interactive "P") (cond (argument (kill-line (if (integerp argument) argument 1))) @@ -1623,13 +1628,9 @@ With a numeric prefix argument N, do `kill-line' that many times." ;; Insert a space to avoid invalid joining if necessary. ((let ((syn-before (char-syntax (char-before))) (syn-after (char-syntax (char-after)))) - (or (and (eq syn-before ?\) ) ; Separate opposing - (eq syn-after ?\( )) ; parentheses, - (and (eq syn-before ?\" ) ; string delimiter - (eq syn-after ?\" )) ; pairs, - (and (memq syn-before '(?_ ?w)) ; or word or symbol - (memq syn-after '(?_ ?w))))) ; constituents. - (insert " ")))) + (and (memq syn-before '(?\) ?\" ?_ ?w)) + (memq syn-after '(?\( ?\" ?_ ?w)))) + (save-excursion (insert " "))))) ;;;;; Killing Words diff --git a/test.el b/test.el index 9e1b50c..ca85187 100644 --- a/test.el +++ b/test.el @@ -752,13 +752,14 @@ Four arguments: the paredit command, the text of the buffer (";f\n(b\n z|)\n" ";f\n(b\n z|)\n"))) (let ((kill-whole-line t)) - (paredit-test (defun paredit-test-kill () + (paredit-test (defun paredit-test-kill-whole-line () (interactive) - ;; Horrible kludge. Do it once, and then yank to make - ;; sure we get back what we expect. Then do it again, - ;; to get the effects on the buffer the automatic test - ;; framework will check. - (save-excursion + ;; For now the check to see that we yanked the + ;; correct string is disabled, because it isn't quite + ;; right: with kill-whole-line enabled, sometimes it + ;; inserts an extra space to avoid joining two + ;; expressions. + '(save-excursion (let ((kill-ring nil)) (let ((text (buffer-string))) (call-interactively 'paredit-kill) @@ -819,9 +820,8 @@ Four arguments: the paredit command, the text of the buffer ("\"\n\"\n|" error) ("|(a (b) (c)\n (d) (e))" "|" error) - (xfail - "(a| (b) (c)\n (d) (e))" - "(a| (d) (e))" + ("(a| (b) (c)\n (d) (e))" + "(a| (d) (e))" "(a|)" "(a|)") (xfail @@ -885,7 +885,7 @@ Four arguments: the paredit command, the text of the buffer ("|(a ((b) (c)\n (d) (e)) (f))" "|" error) (xfail "(|a ((b) (c)\n (d) (e)) (f))" "(| (f))" "(|)" "(|)") - (xfail "(a| ((b) (c)\n (d) (e)) (f))" "(a| (f))" "(a|)" "(a|)") + ("(a| ((b) (c)\n (d) (e)) (f))" "(a| (f))" "(a|)" "(a|)") (xfail "(a |((b) (c)\n (d) (e)) (f))" "(a | (f))" "(a |)" "(a |)") (xfail "(a (|(b) (c)\n (d) (e)) (f))" @@ -968,8 +968,7 @@ Four arguments: the paredit command, the text of the buffer "(| (f))" "(|)" "(|)") - (xfail - "(a| \"(b) (c)\n ) { ;;;; \n\n\n(d)( (e);\" (f))" + ("(a| \"(b) (c)\n ) { ;;;; \n\n\n(d)( (e);\" (f))" "(a| (f))" "(a|)" "(a|)") @@ -1006,7 +1005,7 @@ Four arguments: the paredit command, the text of the buffer "(a \"(b) (c)\n ) { ;;;; \n\n\n|\" (f))") ("|x(\n)(z)" "|(z)" "|" error) - ("x|(\n)(z)" "x|(z)" "x|" error) + ("x|(\n)(z)" "x| (z)" "x|" error) ("x(|\n)(z)" "x(|)(z)" "x(|)(z)") (xfail "x(\n|)(z)" "x(\n|)(z)") ("x(\n)|(z)" "x(\n)|" error) @@ -1015,7 +1014,7 @@ Four arguments: the paredit command, the text of the buffer ("x(\n)(z)|" error) ("|x\"\n\"(z)" "|(z)" "|" error) - ("x|\"\n\"(z)" "x|(z)" "x|" error) + ("x|\"\n\"(z)" "x| (z)" "x|" error) ("x\"|\n\"(z)" "x\"|\"(z)" "x\"|\"(z)") ("x\"\n|\"(z)" "x\"\n|\"(z)") ("x\"\n\"|(z)" "x\"\n\"|" error) -- cgit v1.2.1