From 3c48233833f8afcf42b6e2e6722ae0badf28183d Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Mon, 11 Apr 2011 18:05:00 +0000 Subject: Fix checks on deletion of comment boundaries. Ignore-this: db6c2b72e92eadc7b98d3c0613916f9d darcs-hash:20110411180500-00fcc-5e23c6d9675a260d692830ecdc40302d4ab52141 --- paredit.el | 54 +++++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 31 deletions(-) (limited to 'paredit.el') diff --git a/paredit.el b/paredit.el index 3a05af6..72d7544 100644 --- a/paredit.el +++ b/paredit.el @@ -1274,25 +1274,19 @@ With a `C-u' prefix argument, simply delete a character forward, (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. + ;; Point is in a comment, possibly at eol. 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))))) + (let ((next-line-start (point-at-bol 2)) + (next-line-end (point-at-eol 2))) + (paredit-check-region next-line-start next-line-end))) (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))) + ;; Point precedes a comment start (not at eol). Refuse to delete a + ;; comment start if the comment contains unbalanced junk. + (paredit-check-region (+ (point) 1) (point-at-eol)) (delete-char 1)) (defun paredit-backward-delete (&optional argument) @@ -1367,28 +1361,26 @@ With a `C-u' prefix argument, simply delete a character backward, (delete-char 1))))) (defun paredit-backward-delete-in-comment () + ;; Point is in a comment, possibly just after the comment start. ;; 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'. - (not (or (paredit-in-string-p) - (paredit-in-comment-p)))) - (not (paredit-region-ok-p (point) (point-at-eol)))) + (if (save-excursion + (backward-char) + ;; Must call `paredit-in-string-p' before + ;; `paredit-in-comment-p'. + (not (or (paredit-in-string-p) (paredit-in-comment-p)))) (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)) - (line-end-state - (save-excursion - (if (not (comment-search-forward (point-at-eol) t)) - (goto-char (point-at-eol))) - (paredit-current-parse-state)))) - (paredit-check-region-state line-start-state line-end-state)) + ;; Point is at bol, possibly just after a comment end (i.e., the + ;; previous line may have had a line comment). Refuse to delete a + ;; comment end if moving the current line into the previous line's + ;; comment would break structure. + (if (save-excursion + (backward-char) + (and (not (paredit-in-string-p)) (paredit-in-comment-p))) + (paredit-check-region (point-at-eol) (point-at-bol))) (backward-delete-char 1)) ;;;; Killing -- cgit v1.2.1