branch: elpa/paredit
commit ace4f62faec2aa1f157ab9c647d023df15d44888
Author: Taylor R Campbell <[email protected]>
Commit: Taylor R Campbell <[email protected]>
Count S-expressions more carefully in `paredit-insert-pair'.
Ignore-this: 1b8fe110a0983c730918eb16ed81911a
Suggested by Eitan Postavsky.
I'm not yet sure this is right (and I'm not yet sure of the similar
change to `paredit-count-sexps-forward' and thus `C-u M-('), but I'll
try it out.
darcs-hash:20110320194242-00fcc-635c1cdba60f9a6b395561a64349876b6e524d29
---
paredit.el | 27 ++++++++++++++++++++++-----
1 file changed, 22 insertions(+), 5 deletions(-)
diff --git a/paredit.el b/paredit.el
index a05ed06..6d8d827 100644
--- a/paredit.el
+++ b/paredit.el
@@ -732,15 +732,32 @@ If such a comment exists, delete the comment (including
all leading
(insert open)
(save-excursion
;; Move past the desired region.
- (cond (n (funcall forward
- (save-excursion
- (forward-sexp (prefix-numeric-value n))
- (point))))
- (regionp (funcall forward (+ end (if spacep 2 1)))))
+ (cond (n
+ (funcall forward
+ (paredit-scan-sexps-hack (point)
+ (prefix-numeric-value n))))
+ (regionp
+ (funcall forward (+ end (if spacep 2 1)))))
(insert close)
(if (paredit-space-for-delimiter-p t close)
(insert " "))))))
+;++ This needs a better name...
+
+(defun paredit-scan-sexps-hack (point n)
+ (save-excursion
+ (goto-char point)
+ (let ((direction (if (< 0 n) +1 -1))
+ (magnitude (abs n))
+ (count 0))
+ (catch 'exit
+ (while (< count magnitude)
+ (let ((p (scan-sexps (point) direction)))
+ (if (not p) (throw 'exit nil))
+ (goto-char p))
+ (setq count (+ count 1)))))
+ (point)))
+
(defun paredit-region-safe-for-insert-p ()
(save-excursion
(let ((beginning (region-beginning))