[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/paredit 90c7eda 042/224: Revive `paredit-semicolon', with
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/paredit 90c7eda 042/224: Revive `paredit-semicolon', with better behaviour. |
Date: |
Sat, 7 Aug 2021 09:22:15 -0400 (EDT) |
branch: elpa/paredit
commit 90c7eda317d3633b3c59ac45ac926f5b4a6fe363
Author: Taylor R Campbell <campbell@mumble.net>
Commit: Taylor R Campbell <campbell@mumble.net>
Revive `paredit-semicolon', with better behaviour.
Ignore-this: 2ebf74083c75ef978f8f4e15070002e3
darcs-hash:20100917204244-00fcc-b698a185d46aaf792f065e98e0b1509eaee4f0a3
---
paredit.el | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+)
diff --git a/paredit.el b/paredit.el
index 848312d..4fa5c7d 100644
--- a/paredit.el
+++ b/paredit.el
@@ -323,6 +323,15 @@ Paredit behaves badly if parentheses are imbalanced, so
exercise
"(string #\\x|)")
("\"foo|bar\"\n ; Escaping character... (\")"
"\"foo\\\"|bar\""))
+ (";" paredit-semicolon
+ ("|(frob grovel)"
+ ";|(frob grovel)")
+ ("(frob |grovel)"
+ "(frob ;grovel\n)")
+ ("(frob |grovel (bloit\n zargh))"
+ "(frob ;|grovel\n (bloit\n zargh))")
+ ("(frob grovel) |"
+ "(frob grovel) ;|"))
("M-;" paredit-comment-dwim
("(foo |bar) ; baz"
"(foo bar) ; |baz")
@@ -1012,6 +1021,64 @@ If the point is in a string or a comment, fill the
paragraph instead,
;;;; Comment Insertion
+(defun paredit-semicolon (&optional n)
+ "Insert a semicolon.
+With a prefix argument N, insert N semicolons.
+If in a string, do just that and nothing else.
+If in a character literal, move to the beginning of the character
+ literal before inserting the semicolon.
+If the enclosing list ends on the line after the point, break the line
+ after the last S-expression following the point.
+If a list begins on the line after the point but ends on a different
+ line, break the line after the last S-expression following the point
+ before the list."
+ (interactive "p")
+ (if (or (paredit-in-string-p) (paredit-in-comment-p))
+ (insert (make-string (or n 1) ?\; ))
+ (if (paredit-in-char-p)
+ (backward-char 2))
+ (let ((line-break-point (paredit-semicolon-find-line-break-point)))
+ (if line-break-point
+ (paredit-semicolon-with-line-break line-break-point (or n 1))
+ (insert (make-string (or n 1) ?\; ))))))
+
+(defun paredit-semicolon-find-line-break-point ()
+ (let ((line-break-point nil)
+ (eol (point-at-eol)))
+ (and (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)
+ (eq eol (point-at-eol)))
+ ;; 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)))
+
+(defun paredit-semicolon-with-line-break (line-break-point n)
+ (let ((line-break-marker (make-marker)))
+ (set-marker line-break-marker line-break-point)
+ (set-marker-insertion-type line-break-marker t)
+ (insert (make-string (or n 1) ?\; ))
+ (save-excursion
+ (goto-char line-break-marker)
+ (set-marker line-break-marker nil)
+ (newline)
+ (lisp-indent-line)
+ ;; This step is redundant if we are inside a list, but even if we
+ ;; are at the top level, we want at least to indent whatever we
+ ;; bumped off the line.
+ (paredit-ignore-sexp-errors (indent-sexp))
+ (paredit-indent-sexps))))
+
;;; This is all a horrible, horrible hack, primarily for GNU Emacs 21,
;;; in which there is no `comment-or-uncomment-region'.
- [nongnu] branch elpa/paredit created (now 8330a41), ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit de45eb6 005/224: Changes for version 9., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 9464588 016/224: Changes for version 20., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 0ada66e 023/224: Update the compatibility and compiler warning suppression hacks for Emacs 22., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit f7c26b9 027/224: Fix kill & yank errors with `paredit-lose-if-not-in-sexp' while barfing., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 929e547 038/224: Fix some opening remarks about enabling paredit mode., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 90c7eda 042/224: Revive `paredit-semicolon', with better behaviour.,
ELPA Syncer <=
- [nongnu] elpa/paredit a26a9a7 075/224: Permit joining adjacent lists without intervening whitespace., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit f27c480 070/224: Implement `paredit-override-check-parens-function'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 67caf7e 071/224: Eliminate fboundp check for `check-parens' in `paredit-check-region'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit ae53a2c 077/224: Show point in `paredit-semicolon' example., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 26a3ddb 085/224: Add `paredit-doublequote' examples at end of string and in comment., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 33463ae 102/224: Third argument to `indent-region' is not optional in GNU Emacs 21., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit c91bc2f 099/224: Fix bug in change to check structure in backward-delete of comment end., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 7e3b3f0 096/224: In `paredit-recenter-on-sexp', handle S-expressions larger than screen., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 6918d89 108/224: Don't indent while the buffer is in intermediate broken states., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit adfccc5 123/224: Check `paredit-kill' in a comment more carefully., ELPA Syncer, 2021/08/07