[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/paredit 18cf19f 164/224: Implement `paredit-preserving-col
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/paredit 18cf19f 164/224: Implement `paredit-preserving-column'. |
Date: |
Sat, 7 Aug 2021 09:22:42 -0400 (EDT) |
branch: elpa/paredit
commit 18cf19f4d12dbe95b952b895c85579bb41801602
Author: Taylor R Campbell <campbell@mumble.net>
Commit: Taylor R Campbell <campbell@mumble.net>
Implement `paredit-preserving-column'.
---
paredit.el | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/paredit.el b/paredit.el
index e2d3f78..80d83d5 100644
--- a/paredit.el
+++ b/paredit.el
@@ -173,6 +173,21 @@ Signal an error if no clause matches."
(put 'paredit-ignore-sexp-errors 'lisp-indent-function 0)
+ (defmacro paredit-preserving-column (&rest body)
+ "Evaluate BODY and restore point to former column, relative to code.
+Assumes BODY will change only indentation.
+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))
+ (,indentation (paredit-current-indentation)))
+ (let ((value (progn ,@body)))
+ (paredit-restore-column ,column ,indentation)
+ value))))
+
+ (put 'paredit-preserving-column 'lisp-indent-function 0)
+
nil)
;;;; Minor Mode Definition
@@ -2611,6 +2626,20 @@ This is independent of context -- it doesn't check what
state the
(save-excursion
(back-to-indentation)
(current-column)))
+
+(defun paredit-restore-column (column indentation)
+ ;; Preserve the point's position either in the indentation or in the
+ ;; code: if on code, move with the code; if in indentation, leave it
+ ;; in the indentation, either where it was (if still on indentation)
+ ;; or at the end of the indentation (if the code moved far enough
+ ;; left).
+ (let ((indentation* (paredit-current-indentation)))
+ (goto-char
+ (+ (point-at-bol)
+ (cond ((not (< column indentation))
+ (+ column (- indentation* indentation)))
+ ((<= indentation* column) indentation*)
+ (t column))))))
;;;; Initialization
- [nongnu] elpa/paredit d80a9db 141/224: Fail early in `paredit-convolute-sexp'., (continued)
- [nongnu] elpa/paredit d80a9db 141/224: Fail early in `paredit-convolute-sexp'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 2ec6000 145/224: Fix error message in `paredit-test'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 6f2677b 148/224: Tweak `paredit-convolute-sexp' a little and add some tests for it., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit d54ea28 149/224: Add a trivial shell script to generate paredit.html., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 540bc9c 153/224: Remove unnecessarily nasty text about reporting bugs., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit b02f509 156/224: New file NEWS from paredit.release., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit b647a1a 158/224: Bump copyright year on test.el to 2013., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit f25cd3b 159/224: Add a zillion paredit-kill tests. Fix a tiny bug they revealed., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 460254d 162/224: Fix paredit-doublequote inside a string escape., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit db82936 163/224: Make `paredit-forward' and `paredit-backward' move out of strings., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 18cf19f 164/224: Implement `paredit-preserving-column'.,
ELPA Syncer <=
- [nongnu] elpa/paredit 5840f55 165/224: Preserve column better in `paredit-join'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 9838fe2 174/224: In check.sh, use $EMACS if set, defaulting to `emacs'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 3bdd840 175/224: Rework paredit-semicolon and add some tests for it., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 014cdfe 177/224: Handle shift selection in motion commands in recent GNU Emacs., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit be28e85 178/224: Mention shift selection for motion commands in NEWS., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 42a0494 179/224: Use $EMACS in genhtml.sh too., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 856d927 180/224: Use `paredit-preserving-column' in `paredit-reindent-defun'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit a26c148 182/224: Bind M-[ to paredit-wrap-square., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 4e5ba81 184/224: Make slurping `(|) foo' yield `(|foo)', not `(| foo)'., ELPA Syncer, 2021/08/07
- [nongnu] elpa/paredit 0c805ec 188/224: Rework HTML output to simplify and prettify everything., ELPA Syncer, 2021/08/07