[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/paredit 79e7555 086/224: Be more careful about deleting co
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/paredit 79e7555 086/224: Be more careful about deleting comment starts & ends. |
Date: |
Sat, 7 Aug 2021 09:22:24 -0400 (EDT) |
branch: elpa/paredit
commit 79e7555a4296ff12c6723acd4b87e008f85dfaad
Author: Taylor R Campbell <campbell@mumble.net>
Commit: Taylor R Campbell <campbell@mumble.net>
Be more careful about deleting comment starts & ends.
Ignore-this: 710cb2e344eaf6c42c0964dd5481afd6
This way, C-d with
;foo|
(bar
baz)
won't result in an unbalanced buffer: paredit will instead scream at
you.
darcs-hash:20110322202415-00fcc-5291a11ee2e8ffba82602c519957fcc482165d30
---
paredit.el | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 61 insertions(+), 14 deletions(-)
diff --git a/paredit.el b/paredit.el
index 2b6876d..86e2678 100644
--- a/paredit.el
+++ b/paredit.el
@@ -1211,10 +1211,7 @@ With a `C-u' prefix argument, simply delete a character
forward,
((paredit-in-string-p)
(paredit-forward-delete-in-string))
((paredit-in-comment-p)
- ;++ What to do here? This could move a partial S-expression
- ;++ into a comment and thereby invalidate the file's form,
- ;++ or move random text out of a comment.
- (delete-char 1))
+ (paredit-forward-delete-in-comment))
((paredit-in-char-p) ; Escape -- delete both chars.
(backward-delete-char 1)
(delete-char 1))
@@ -1234,12 +1231,14 @@ With a `C-u' prefix argument, simply delete a character
forward,
(eq (char-before) (matching-paren (char-after))))
(backward-delete-char 1) ; Empty list -- delete both
(delete-char 1)) ; delimiters.
+ ((eq ?\; (char-after))
+ (paredit-forward-delete-comment-start))
;; Just delete a single character, if it's not a closing
;; delimiter. (The character literal case is already handled
;; by now.)
((not (eq (char-syntax (char-after)) ?\) ))
(delete-char 1))))
-
+
(defun paredit-forward-delete-in-string ()
(let ((start+end (paredit-string-start+end-points)))
(cond ((not (eq (point) (cdr start+end)))
@@ -1262,6 +1261,28 @@ With a `C-u' prefix argument, simply delete a character
forward,
;; both quotes. Otherwise we refuse to delete it.
(backward-delete-char 1)
(delete-char 1)))))
+
+(defun paredit-forward-delete-in-comment ()
+ ;; Refuse to delete a comment end if moving the next line into the
+ ;; comment would break structure.
+ (if (eolp)
+ (save-excursion
+ (forward-char)
+ (let ((line-start-state (paredit-current-parse-state)))
+ (if (not (comment-search-forward (point-at-eol) t))
+ (goto-char (point-at-eol)))
+ (let ((line-end-state (paredit-current-parse-state)))
+ (paredit-check-region-state line-start-state line-end-state)))))
+ (delete-char 1))
+
+(defun paredit-forward-delete-comment-start ()
+ ;; Refuse to delete a comment start if the comment contains
+ ;; unbalanced junk. Kludge: `paredit-check-region' moves the point
+ ;; even if the region is OK. But if we use `save-excursion', then
+ ;; `check-parens' can't put the point at the bad part.
+ (if (not (paredit-region-ok-p (+ (point) 1) (point-at-eol)))
+ (paredit-check-region (+ (point) 1) (point-at-eol)))
+ (delete-char 1))
(defun paredit-backward-delete (&optional argument)
"Delete a character backward or move backward over a delimiter.
@@ -1285,7 +1306,7 @@ With a `C-u' prefix argument, simply delete a character
backward,
((paredit-in-string-p)
(paredit-backward-delete-in-string))
((paredit-in-comment-p)
- (backward-delete-char 1))
+ (paredit-backward-delete-in-comment))
((paredit-in-char-p) ; Escape -- delete both chars.
(backward-delete-char 1)
(delete-char 1))
@@ -1304,11 +1325,13 @@ With a `C-u' prefix argument, simply delete a character
backward,
(eq (char-after) (matching-paren (char-before))))
(backward-delete-char 1) ; Empty list -- delete both
(delete-char 1)) ; delimiters.
+ ((bolp)
+ (paredit-backward-delete-maybe-comment-end))
;; Delete it, unless it's an opening delimiter. The case of
;; character literals is already handled by now.
((not (eq (char-syntax (char-before)) ?\( ))
(backward-delete-char-untabify 1))))
-
+
(defun paredit-backward-delete-in-string ()
(let ((start+end (paredit-string-start+end-points)))
(cond ((not (eq (1- (point)) (car start+end)))
@@ -1331,6 +1354,29 @@ With a `C-u' prefix argument, simply delete a character
backward,
;; both quotes. Otherwise we refuse to delete it.
(backward-delete-char 1)
(delete-char 1)))))
+
+(defun paredit-backward-delete-in-comment ()
+ ;; Refuse to delete a comment start if the comment contains
+ ;; unbalanced junk.
+ (if (and (save-excursion
+ (backward-char)
+ ;; Must call `paredit-in-string-p' before
+ ;; `paredit-in-comment-p'.
+ (and (not (paredit-in-string-p))
+ (paredit-in-comment-p)))
+ (not (paredit-region-ok-p (point) (point-at-eol))))
+ (paredit-check-region (point) (point-at-eol)))
+ (backward-delete-char-untabify +1))
+
+(defun paredit-backward-delete-maybe-comment-end ()
+ ;; Refuse to delete a comment end if moving the line into the comment
+ ;; would break structure.
+ (let ((line-start-state (paredit-current-parse-state)))
+ (if (not (comment-search-forward (point-at-eol) t))
+ (goto-char (point-at-eol)))
+ (let ((line-end-state (paredit-current-parse-state)))
+ (paredit-check-region-state line-start-state line-end-state)))
+ (backward-delete-char 1))
;;;; Killing
@@ -2505,13 +2551,14 @@ If no parse state is supplied, compute one from the
beginning of the
(check-parens)))
(defun paredit-region-ok-p (start end)
- (paredit-handle-sexp-errors
- (progn
- (save-restriction
- (narrow-to-region start end)
- (scan-sexps (point-min) (point-max)))
- t)
- nil))
+ (save-excursion
+ (paredit-handle-sexp-errors
+ (progn
+ (save-restriction
+ (narrow-to-region start end)
+ (scan-sexps (point-min) (point-max)))
+ t)
+ nil)))
(defun paredit-current-indentation ()
(save-excursion
- [nongnu] elpa/paredit 4d6f3fc 090/224: Fix `imbalanced' -> `unbalanced' in `paredit-kill-region' docstring., (continued)
- [nongnu] elpa/paredit 4d6f3fc 090/224: Fix `imbalanced' -> `unbalanced' in `paredit-kill-region' docstring., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 52670b7 079/224: Fix spacing in `paredit-newline' example., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit bd439e3 083/224: Avoid trailing space when `paredit-comment-dwim' inserts code comments., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 2c972a9 095/224: Omit angled delimiters from the `paredit-open-...' tests., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 2a64a4c 064/224: Eliminate confusing comment over `paredit-splice-sexp'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 48480a1 084/224: Omit needless line break in `paredit-join-sexps'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 4d3ad1e 069/224: Simplify definition of `paredit-count-sexps-forward'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 8a2d457 093/224: Reindent in `paredit-open-round' &c. like `paredit-wrap-round' &c., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 980a4f4 091/224: Add rudimentary and preliminary test suite., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 33f9c67 100/224: Use `error', not `message', to report test failures in test.el., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 79e7555 086/224: Be more careful about deleting comment starts & ends.,
ELPA Syncer <=
- [nongnu] elpa/paredit 121a8b4 104/224: Make backslash escape prompt less confusing., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 41bbc20 078/224: Make `paredit-comment-dwim' code comment example work in isolation., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 5e210b2 087/224: Fix bug in recent change to more carefully delete comment ends., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit d9ecc6d 094/224: Handle scan errors in `paredit-scan-sexps-hack'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 6c14694 113/224: Use `call-interactively' rather than `funcall' in `paredit-test'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 9cac6fa 106/224: Specify that paredit should work in XEmacs 21.5.28 or later., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 0bb4b62 110/224: Check for expected errors in `paredit-close-FOO'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 3c48233 122/224: Fix checks on deletion of comment boundaries., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 620c3a2 116/224: Break page in test.el before indentation regression tests., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit d681e3c 111/224: Check for expected errors in `paredit-forward-delete'., ELPA Syncer, 2021/08/07