diff options
author | Taylor R Campbell <campbell@mumble.net> | 2011-04-11 18:03:00 +0000 |
---|---|---|
committer | Taylor R Campbell <campbell@mumble.net> | 2011-04-11 18:03:00 +0000 |
commit | fc78011c32e601d8a1c91a317382a1e7a1b24024 (patch) | |
tree | 9e0edb51de6f6576d4a582b9e97b793fee417068 | |
parent | ba0de55ad6fbc8501cd713dc751046e773296c16 (diff) |
Tweak `paredit-check-region' and `paredit-region-ok-p'.
Ignore-this: c75566b3db4425b39ca633d55c6d400e
In `paredit-check-region', call `paredit-region-ok-p' to discern
whether the region is OK before narrowing and calling `check-parens'
to report any errors. This avoids unwanted point motion if the
region is OK, or if it isn't, lets `check-parens' move the point to
the part where the region is not OK.
Write docstrings for the two routines.
darcs-hash:20110411180300-00fcc-674d77c0c9566bcfb8ef7cfe88a50de34a373853
-rw-r--r-- | paredit.el | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -2582,11 +2582,19 @@ If no parse state is supplied, compute one from the beginning of the (error "Invalid context for command `%s'." command))) (defun paredit-check-region (start end) - (save-restriction - (narrow-to-region start end) - (check-parens))) + "Signal an error if text between `start' and `end' is unbalanced." + ;; `narrow-to-region' will move the point, so avoid calling it if we + ;; don't need to. We don't want to use `save-excursion' because we + ;; want the point to move if `check-parens' reports an error. + (if (not (paredit-region-ok-p start end)) + (save-restriction + (narrow-to-region start end) + (check-parens)))) (defun paredit-region-ok-p (start end) + "Return true iff the region between `start' and `end' is balanced. +This is independent of context -- it doesn't check what state the + text at `start' is in." (save-excursion (paredit-handle-sexp-errors (progn |