summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--paredit.el16
1 files changed, 12 insertions, 4 deletions
diff --git a/paredit.el b/paredit.el
index 637dd72..3c89c50 100644
--- a/paredit.el
+++ b/paredit.el
@@ -1866,10 +1866,18 @@ By default OPEN and CLOSE are round delimiters."
(defun paredit-count-sexps-forward ()
(save-excursion
(let ((n 0))
- (paredit-ignore-sexp-errors
- (while (not (eobp))
- (forward-sexp)
- (setq n (+ n 1))))
+ (catch 'exit
+ (paredit-ignore-sexp-errors
+ (while (not (eobp))
+ (let ((start (point)))
+ (forward-sexp)
+ ;; Don't count whitespace at the end of the buffer as
+ ;; another S-expression.
+ (if (and (eobp)
+ (save-excursion (backward-sexp)
+ (or (bobp) (< (point) start))))
+ (throw 'exit nil)))
+ (setq n (+ n 1)))))
n)))
(defun paredit-yank-pop (&optional argument)