[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/paredit 3bdd840 175/224: Rework paredit-semicolon and add
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/paredit 3bdd840 175/224: Rework paredit-semicolon and add some tests for it. |
Date: |
Sat, 7 Aug 2021 09:22:44 -0400 (EDT) |
branch: elpa/paredit
commit 3bdd8402a180623e77b13224807bb8f16df499f4
Author: Taylor R Campbell <campbell@mumble.net>
Commit: Taylor R Campbell <campbell@mumble.net>
Rework paredit-semicolon and add some tests for it.
---
paredit.el | 52 ++++++++++++++++++++++++++++++----------------------
test.el | 28 +++++++++++++++++++++++++++-
2 files changed, 57 insertions(+), 23 deletions(-)
diff --git a/paredit.el b/paredit.el
index fc86311..1f1a2c7 100644
--- a/paredit.el
+++ b/paredit.el
@@ -1055,29 +1055,37 @@ If a list begins on the line after the point but ends
on a different
(insert (make-string (or n 1) ?\; ))))))
(defun paredit-semicolon-find-line-break-point ()
- (let ((line-break-point nil)
- (eol (point-at-eol)))
- (and (not (eolp)) ;Implies (not (eobp)).
+ (and (not (eolp)) ;Implies (not (eobp)).
+ (let ((eol (point-at-eol)))
(save-excursion
- (paredit-handle-sexp-errors
- (progn
- (while
- (progn
- (setq line-break-point (point))
- (forward-sexp)
- (and (eq eol (point-at-eol))
- (not (eobp)))))
- (backward-sexp)
- (and (eq eol (point-at-eol))
- ;; Don't break the line if the end of the last
- ;; S-expression is at the end of the buffer.
- (progn (forward-sexp) (not (eobp)))))
- ;; If we hit the end of an expression, but the closing
- ;; delimiter is on another line, don't break the line.
- (save-excursion
- (paredit-skip-whitespace t (point-at-eol))
- (not (or (eolp) (eq (char-after) ?\; ))))))
- line-break-point)))
+ (catch 'exit
+ (while t
+ (let ((line-break-point (point)))
+ (cond ((paredit-handle-sexp-errors (progn (forward-sexp) t)
+ nil)
+ ;; Successfully advanced by an S-expression.
+ ;; If that S-expression started on this line
+ ;; and ended on another one, break here.
+ (cond ((not (eq eol (point-at-eol)))
+ (throw 'exit
+ (and (save-excursion
+ (backward-sexp)
+ (eq eol (point-at-eol)))
+ line-break-point)))
+ ((eobp)
+ (throw 'exit nil))))
+ ((save-excursion
+ (paredit-skip-whitespace t (point-at-eol))
+ (or (eolp) (eobp) (eq (char-after) ?\;)))
+ ;; Can't move further, but there's no closing
+ ;; delimiter we're about to clobber -- either
+ ;; it's on the next line or we're at the end of
+ ;; the buffer. Don't break the line.
+ (throw 'exit nil))
+ (t
+ ;; Can't move because we hit a delimiter at the
+ ;; end of this line. Break here.
+ (throw 'exit line-break-point))))))))))
(defun paredit-semicolon-with-line-break (line-break-point n)
(let ((line-break-marker (make-marker)))
diff --git a/test.el b/test.el
index eb7ef04..66d22ed 100644
--- a/test.el
+++ b/test.el
@@ -221,7 +221,33 @@ Four arguments: the paredit command, the text of the buffer
"(define (square x)\n (* |x x))")))
(paredit-test 'paredit-semicolon
- '(("#\\|(" ";|#\\(")))
+ '(("|" ";|")
+ ("|foo" ";|foo")
+ ("f|oo" "f;|oo")
+ ("fo|o" "fo;|o")
+ ("foo|" "foo;|")
+ ("|(foo bar)" ";|(foo bar)")
+ ("(|foo bar)" "(;|foo bar\n )")
+ ("(f|oo bar)" "(f;|oo bar\n )")
+ ("(fo|o bar)" "(fo;|o bar\n )")
+ ("(foo| bar)" "(foo;| bar\n )")
+ ("(foo |bar)" "(foo ;|bar\n )")
+ ("(foo b|ar)" "(foo b;|ar\n )")
+ ("(foo ba|r)" "(foo ba;|r\n )")
+ ("(foo bar|)" "(foo bar;|\n )")
+ ("(foo bar)|" "(foo bar);|")
+ ("|(foo\n bar)" ";|\n(foo\n bar)")
+ ("(|foo\n bar)" "(;|foo\n bar)")
+ ("(f|oo\n bar)" "(f;|oo\n bar)")
+ ("(fo|o\n bar)" "(fo;|o\n bar)")
+ ("(foo|\n bar)" "(foo;|\n bar)")
+ ("(foo\n| bar)" "(foo\n;| bar\n )")
+ ("(foo\n |bar)" "(foo\n ;|bar\n )")
+ ("(foo\n b|ar)" "(foo\n b;|ar\n )")
+ ("(foo\n ba|r)" "(foo\n ba;|r\n )")
+ ("(foo\n bar|)" "(foo\n bar;|\n )")
+ ("(foo\n bar)|" "(foo\n bar);|")
+ ("#\\|(" ";|#\\(")))
(paredit-test 'paredit-comment-dwim
'(("\"foo|bar;baz\" ;quux"
- [nongnu] elpa/paredit d54ea28 149/224: Add a trivial shell script to generate paredit.html., (continued)
- [nongnu] elpa/paredit d54ea28 149/224: Add a trivial shell script to generate paredit.html., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 540bc9c 153/224: Remove unnecessarily nasty text about reporting bugs., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit b02f509 156/224: New file NEWS from paredit.release., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit b647a1a 158/224: Bump copyright year on test.el to 2013., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit f25cd3b 159/224: Add a zillion paredit-kill tests. Fix a tiny bug they revealed., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 460254d 162/224: Fix paredit-doublequote inside a string escape., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit db82936 163/224: Make `paredit-forward' and `paredit-backward' move out of strings., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 18cf19f 164/224: Implement `paredit-preserving-column'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 5840f55 165/224: Preserve column better in `paredit-join'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 9838fe2 174/224: In check.sh, use $EMACS if set, defaulting to `emacs'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 3bdd840 175/224: Rework paredit-semicolon and add some tests for it.,
ELPA Syncer <=
- [nongnu] elpa/paredit 014cdfe 177/224: Handle shift selection in motion commands in recent GNU Emacs., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit be28e85 178/224: Mention shift selection for motion commands in NEWS., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 42a0494 179/224: Use $EMACS in genhtml.sh too., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 856d927 180/224: Use `paredit-preserving-column' in `paredit-reindent-defun'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit a26c148 182/224: Bind M-[ to paredit-wrap-square., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 4e5ba81 184/224: Make slurping `(|) foo' yield `(|foo)', not `(| foo)'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 0c805ec 188/224: Rework HTML output to simplify and prettify everything., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 5114a62 193/224: If in a string, slurp into the enclosing list if necessary., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 8b38538 190/224: A little more HTML tweaking. Not perfect, but enough for the day., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 6304b64 191/224: Suggest `M-x enable-paredit-mode RET'., ELPA Syncer, 2021/08/07