summaryrefslogtreecommitdiff
path: root/paredit.el
diff options
context:
space:
mode:
authorTaylor R Campbell <campbell@mumble.net>2010-09-20 20:55:49 +0000
committerTaylor R Campbell <campbell@mumble.net>2010-09-20 20:55:49 +0000
commit30f564df98cad42fb61cd021c10b1caf47cf7b62 (patch)
tree1319d9d0bda57da5262439ccefa39092be53d198 /paredit.el
parent3ce96a48102c2467376753910a4851d59fe25c86 (diff)
Add utilities for `check-parens' restricted to a region.
Ignore-this: e5cd5cbea4e5866aec9e657902fd9663 darcs-hash:20100920205549-00fcc-0855cb26399bc060cb863c14bc794166505b9982
Diffstat (limited to 'paredit.el')
-rw-r--r--paredit.el47
1 files changed, 27 insertions, 20 deletions
diff --git a/paredit.el b/paredit.el
index 1660bbb..f32ae46 100644
--- a/paredit.el
+++ b/paredit.el
@@ -986,16 +986,7 @@ If in a comment and if followed by invalid structure, call
(cond ((paredit-in-string-p)
(newline))
((paredit-in-comment-p)
- (if (paredit-handle-sexp-errors
- ;; Check for anything that would break structure in
- ;; the comment.
- (save-restriction
- (narrow-to-region (point) (point-at-eol))
- (save-excursion
- (while (< (point) (point-max))
- (forward-sexp)))
- t)
- nil)
+ (if (paredit-region-ok-p (point) (point-at-eol))
(progn (newline-and-indent) (indent-sexp))
(indent-new-comment-line)))
(t
@@ -1613,15 +1604,7 @@ If the text of the region is imbalanced, signal an error instead.
With a prefix argument, disregard any imbalance."
(interactive "r")
(if (not current-prefix-arg)
- ;; Check that the region is balanced.
- (save-restriction
- (narrow-to-region beginning end)
- (if (fboundp 'check-parens)
- (check-parens)
- (save-excursion
- (goto-char (point-min))
- (while (not (eobp))
- (forward-sexp))))))
+ (paredit-check-region beginning end))
(setq this-command 'kill-ring-save)
(kill-ring-save beginning end))
@@ -2472,7 +2455,7 @@ If no parse state is supplied, compute one from the beginning of the
;; else an integer (the current comment nesting)
(and (nth 4 (or state (paredit-current-parse-state)))
t))
-
+
(defun paredit-point-at-sexp-boundary (n)
(cond ((< n 0) (paredit-point-at-sexp-start))
((= n 0) (point))
@@ -2495,6 +2478,30 @@ If no parse state is supplied, compute one from the beginning of the
(paredit-in-comment-p)
(paredit-in-char-p))
(error "Invalid context for command `%s'." command)))
+
+(defun paredit-check-region (start end)
+ (save-restriction
+ (narrow-to-region start end)
+ (if (fboundp 'check-parens)
+ (check-parens)
+ (save-excursion
+ (goto-char (point-min))
+ (while (not (eobp))
+ (forward-sexp))))))
+
+(defun paredit-region-ok-p (start end)
+ (paredit-handle-sexp-errors
+ (progn
+ (save-restriction
+ (narrow-to-region start end)
+ ;; Can't use `check-parens' here -- it signals the wrong kind
+ ;; of errors.
+ (save-excursion
+ (goto-char (point-min))
+ (while (not (eobp))
+ (forward-sexp))))
+ t)
+ nil))
;;;; Initialization