[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/paredit 683b454ff2 1/3: Fix column preservation in text fi
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/paredit 683b454ff2 1/3: Fix column preservation in text fields like ielm after prompt. |
Date: |
Fri, 25 Nov 2022 21:59:16 -0500 (EST) |
branch: elpa/paredit
commit 683b454ff269600c59ffbbded415058971adde86
Author: Taylor R Campbell <campbell@paredit.org>
Commit: Taylor R Campbell <campbell@paredit.org>
Fix column preservation in text fields like ielm after prompt.
Add a hacky one-off test to assemble buffer text with a field.
---
NEWS | 4 ++++
paredit.el | 10 ++++++++--
test.el | 20 ++++++++++++++++++++
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/NEWS b/NEWS
index 6a89f57cda..21f86dca13 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,10 @@ https://paredit.org
Latest release: https://paredit.org/paredit.el
Current development version: https://paredit.org/paredit-beta.el
+** Version 26 (beta)
+
+*** M-s (paredit-splice-sexp) now restores column in text fields like ielm.
+
** Version 25 -- 2022-11-25
*** paredit now lives at paredit.org.
diff --git a/paredit.el b/paredit.el
index 449a75b81c..77f5a68450 100644
--- a/paredit.el
+++ b/paredit.el
@@ -184,7 +184,7 @@ If point was on code, it moves with the code.
If point was on indentation, it stays in indentation."
(let ((column (make-symbol "column"))
(indentation (make-symbol "indentation")))
- `(let ((,column (current-column))
+ `(let ((,column (paredit-current-column))
(,indentation (paredit-current-indentation)))
(let ((value (progn ,@body)))
(paredit-restore-column ,column ,indentation)
@@ -2953,10 +2953,16 @@ This is independent of context -- it doesn't check what
state the
t)
nil)))
+(defun paredit-current-column ()
+ ;; Like current-column, but respects field boundaries in interactive
+ ;; modes like ielm. For use only with paredit-restore-column, which
+ ;; works relative to point-at-bol.
+ (- (point) (point-at-bol)))
+
(defun paredit-current-indentation ()
(save-excursion
(back-to-indentation)
- (current-column)))
+ (paredit-current-column)))
(defun paredit-restore-column (column indentation)
;; Preserve the point's position either in the indentation or in the
diff --git a/test.el b/test.el
index 8e6ebe91ff..3930e4369b 100644
--- a/test.el
+++ b/test.el
@@ -1251,6 +1251,26 @@ Four arguments: the paredit command, the text of the
buffer
("\"|foo\\\"bar\"" error)
;++ ("(\"|foo\\\;bar\")" error)
))
+
+(let ((prompt "prompt> ")
+ (before "(foo (bar| baz))")
+ (expected "(foo bar| baz)"))
+ (with-temp-buffer
+ (paredit-test-buffer-setup)
+ (insert prompt)
+ (add-text-properties (point-min) (point-max) '(field output))
+ (insert before)
+ (goto-char (length prompt))
+ (search-forward "|")
+ (delete-char -1)
+ (call-interactively 'paredit-splice-sexp)
+ (insert "|")
+ (let ((actual (buffer-string)))
+ (if (not (string= (concat prompt expected) actual))
+ (paredit-test-failed 'paredit-splice-sexp
+ (concat prompt before)
+ actual
+ (concat prompt expected))))))
(paredit-test 'paredit-forward-slurp-sexp
'(("|" error)