summaryrefslogtreecommitdiff
path: root/paredit.el
diff options
context:
space:
mode:
authorTaylor R Campbell <campbell@mumble.net>2011-03-20 18:38:54 +0000
committerTaylor R Campbell <campbell@mumble.net>2011-03-20 18:38:54 +0000
commit135c94043eee6a97a94a41b0fa2cb79677165c41 (patch)
tree105b00e32383ddc39097a5be3610f99a1f2f8a7f /paredit.el
parentb7f234ab0e201b5e8366ad27ecd0fd70f5101b55 (diff)
Count carefully at end of buffer in `paredit-count-sexps-forward'.
Ignore-this: 710e264ca330414cfb55c295d0ed5f46 Fixes `C-u M-(' at the top level when there is whitespace at the end of the buffer: the closing delimiter should go at the end of the last S-expression, not at the end of the buffer after the whitespace. Thanks to Eitan Postavsky for the report. darcs-hash:20110320183854-00fcc-7162d40b9111aed39ca72a913393af8bb2425025
Diffstat (limited to 'paredit.el')
-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)