summaryrefslogtreecommitdiff
path: root/paredit.el
diff options
context:
space:
mode:
authorTaylor R Campbell <campbell@mumble.net>2013-04-07 17:05:53 +0000
committerTaylor R Campbell <campbell@mumble.net>2013-04-07 17:08:39 +0000
commit425e1a43c59942ad3edbe357d6dc655e5fd6aac4 (patch)
treef94d804615fc05268e6bad6a9aecb30a10ccc6ea /paredit.el
parent56eff644d5c55a4c452ae813f91441e847a11c81 (diff)
Improve indentation and column preservation in `paredit-splice'.
Diffstat (limited to 'paredit.el')
-rw-r--r--paredit.el52
1 files changed, 36 insertions, 16 deletions
diff --git a/paredit.el b/paredit.el
index 5e91197..1adbe45 100644
--- a/paredit.el
+++ b/paredit.el
@@ -2032,23 +2032,43 @@ Inside a string, unescape all backslashes, or signal an error if doing
(interactive "P")
(if (paredit-in-string-p)
(paredit-splice-string argument)
- (save-excursion
- (paredit-kill-surrounding-sexps-for-splice argument)
- (let ((end (point)))
- (backward-up-list) ; Go up to the beginning...
- (save-excursion
- (forward-char 1) ; (Skip over leading whitespace
- (paredit-skip-whitespace t end)
- (setq end (point))) ; for the `delete-region'.)
- (let ((indent-start nil) (indent-end nil))
+ (if (paredit-in-comment-p)
+ (error "Can't splice comment."))
+ (paredit-handle-sexp-errors (paredit-enclosing-list-start)
+ (error "Can't splice top level."))
+ (paredit-kill-surrounding-sexps-for-splice argument)
+ (let ((delete-start (paredit-enclosing-list-start))
+ (delete-end
+ (let ((limit
+ (save-excursion
+ (paredit-ignore-sexp-errors (forward-sexp) (backward-sexp))
+ (point))))
+ (save-excursion
+ (backward-up-list)
+ (forward-char +1)
+ (paredit-skip-whitespace t limit)
+ (point)))))
+ (let ((end-marker (make-marker)))
+ (save-excursion
+ (up-list)
+ (backward-delete-char +1)
+ (set-marker end-marker (point)))
+ (delete-region delete-start delete-end)
+ (paredit-splice-reindent delete-start (marker-position end-marker))))))
+
+(defun paredit-splice-reindent (start end)
+ (paredit-preserving-column
+ ;; If we changed the first subform of the enclosing list, we must
+ ;; reindent the whole enclosing list.
+ (if (paredit-handle-sexp-errors
(save-excursion
- (setq indent-start (point))
- (forward-sexp) ; Go forward an expression, to
- (backward-delete-char 1) ; delete the end delimiter.
- (setq indent-end (point)))
- (delete-region (point) end) ; ...to delete the open char.
- ;; Reindent only the region we preserved.
- (indent-region indent-start indent-end nil))))))
+ (backward-up-list)
+ (down-list)
+ (paredit-ignore-sexp-errors (forward-sexp))
+ (< start (point)))
+ nil)
+ (save-excursion (backward-up-list) (indent-sexp))
+ (paredit-indent-region start end))))
(defun paredit-kill-surrounding-sexps-for-splice (argument)
(cond ((or (paredit-in-string-p)