From 52be50188ef8c49d8c1a5ef71cb0a963c6a05f09 Mon Sep 17 00:00:00 2001 From: Taylor R Campbell Date: Sun, 28 Aug 2022 21:18:04 +0000 Subject: paredit-raise-sexp: Handle active mark in transient mark mode. --- paredit.el | 23 ++++++++++++++--------- test.el | 12 ++++++++++++ 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 ") -- cgit v1.2.1