summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTaylor R Campbell <campbell+paredit@mumble.net>2022-08-28 21:18:04 +0000
committerTaylor R Campbell <campbell+paredit@mumble.net>2022-08-28 21:30:35 +0000
commit52be50188ef8c49d8c1a5ef71cb0a963c6a05f09 (patch)
tree10351a887b08074e52ed6599a899c9ef6fe93e78
parente4a67f4f23ba936b4bdc8d7e66bd8c6729064558 (diff)
paredit-raise-sexp: Handle active mark in transient mark mode.
-rw-r--r--paredit.el23
-rw-r--r--test.el12
2 files changed, 26 insertions, 9 deletions
diff --git a/paredit.el b/paredit.el
index d8d01d6..b67b1bd 100644
--- a/paredit.el
+++ b/paredit.el
@@ -2158,17 +2158,22 @@ 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")
(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* ((n (prefix-numeric-value argument))
- (bound (scan-sexps (point) n))
+ (let* ((bound
+ (if (and (not argument) (paredit-region-active-p))
+ (progn (if (< (mark) (point))
+ (paredit-check-region (mark) (point))
+ (paredit-check-region (point) (mark)))
+ (mark))
+ (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.")))
+ (scan-sexps (point) (prefix-numeric-value argument))))
(sexps
- (if (< n 0)
+ (if (< bound (point))
(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
diff --git a/test.el b/test.el
index a1df058..bd8ae37 100644
--- a/test.el
+++ b/test.el
@@ -1481,6 +1481,18 @@ Four arguments: the paredit command, the text of the buffer
"(let ((x 5))\n |(foo bar\n baz)\n (wrong indent))")
("(define (f x #!optional\n (|wrong indent))\n (+ 1 2))"
"(define (f x #!optional\n |wrong)\n (+ 1 2))")))
+
+(let ((transient-mark-mode t))
+ (paredit-test 'paredit-raise-sexp
+ '(("(a |b c_ d)" "|b c")
+ ("(a (b |c d_ e) f)" "(a |c d f)")
+ ("(a \"|b\" c_ d)" error))))
+
+(let ((transient-mark-mode nil))
+ (paredit-test 'paredit-raise-sexp
+ '(("(a |b c_ d)" "|b")
+ ("(a (b |c d_ e) f)" "(a |c f)")
+ ("(a \"|b\" c_ d)" "|\"b\""))))
(let ((paredit-comment-prefix-toplevel ";;;T ")
(paredit-comment-prefix-code ";;C ")