summaryrefslogtreecommitdiff
path: root/paredit.el
diff options
context:
space:
mode:
authorTaylor R Campbell <campbell@mumble.net>2008-09-28 14:25:41 +0000
committerTaylor R Campbell <campbell@mumble.net>2008-09-28 14:25:41 +0000
commit2f3db5fb243c4c13b4340f21714ec2865ec7feb0 (patch)
tree8f79c8db71ddef5e2a9a0c0176119dc952306cf3 /paredit.el
parent27a4b80114ab3d6bb0c0e05d60a2fda5e2f66f99 (diff)
Broaden `paredit-raise-sexp' to act sensibly on strings and characters.
darcs-hash:20080928142541-00fcc-90dd4da3c4fd9e689c7d1558f384f21766f07e86
Diffstat (limited to 'paredit.el')
-rw-r--r--paredit.el44
1 files changed, 26 insertions, 18 deletions
diff --git a/paredit.el b/paredit.el
index 284d8fe..63a19d3 100644
--- a/paredit.el
+++ b/paredit.el
@@ -1678,25 +1678,33 @@ With a prefix argument N, kill only the following N S-expressions."
(defun paredit-raise-sexp (&optional n)
"Raise the following S-expression in a tree, deleting its siblings.
With a prefix argument N, raise the following N S-expressions. If N
- is negative, raise the preceding N S-expressions."
+ is negative, raise the preceding N S-expressions.
+If the point is on an S-expression, such as a string or a symbol, not
+ between them, that S-expression is considered to follow the point."
(interactive "p")
- (paredit-lose-if-not-in-sexp 'paredit-raise-sexp)
- ;; Select the S-expressions we want to raise in a buffer substring.
- (let* ((bound (save-excursion (forward-sexp n) (point)))
- (sexps (if (and n (< n 0))
- (buffer-substring bound
- (paredit-point-at-sexp-end))
- (buffer-substring (paredit-point-at-sexp-start)
- bound))))
- ;; Move up to the list we're raising those S-expressions out of and
- ;; delete it.
- (backward-up-list)
- (delete-region (point) (save-excursion (forward-sexp) (point)))
- (save-excursion (insert sexps)) ; Insert & reindent the sexps.
- (save-excursion (let ((n (abs (or n 1))))
- (while (> n 0)
- (paredit-forward-and-indent)
- (setq n (1- n)))))))
+ (save-excursion
+ (cond ((paredit-in-string-p)
+ (goto-char (car (paredit-string-start+end-points))))
+ ((paredit-in-char-p)
+ (backward-sexp))
+ ((paredit-in-comment-p)
+ (error "No S-expression to raise in comment.")))
+ ;; Select the S-expressions we want to raise in a buffer substring.
+ (let* ((bound (save-excursion (forward-sexp n) (point)))
+ (sexps (if (and n (< n 0))
+ (buffer-substring bound
+ (paredit-point-at-sexp-end))
+ (buffer-substring (paredit-point-at-sexp-start)
+ bound))))
+ ;; Move up to the list we're raising those S-expressions out of and
+ ;; delete it.
+ (backward-up-list)
+ (delete-region (point) (save-excursion (forward-sexp) (point)))
+ (save-excursion (insert sexps)) ; Insert & reindent the sexps.
+ (save-excursion (let ((n (abs (or n 1))))
+ (while (> n 0)
+ (paredit-forward-and-indent)
+ (setq n (1- n))))))))
(defun paredit-convolute-sexp (&optional n)
"Convolute S-expressions.