diff options
author | Taylor R Campbell <campbell@mumble.net> | 2011-03-20 19:42:42 +0000 |
---|---|---|
committer | Taylor R Campbell <campbell@mumble.net> | 2011-03-20 19:42:42 +0000 |
commit | ace4f62faec2aa1f157ab9c647d023df15d44888 (patch) | |
tree | 6e4bcaa430a61881629dfc26c4bcf95b204cae71 | |
parent | 9faf474ddc220d2341e37171ae8373d3721a41e4 (diff) |
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
-rw-r--r-- | paredit.el | 27 |
1 files changed, 22 insertions, 5 deletions
@@ -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)) |