]> git.eshelyaron.com Git - emacs.git/commitdiff
New command 'lisp-duplicate-sexp'
authorEshel Yaron <me@eshelyaron.com>
Tue, 25 Feb 2025 19:54:05 +0000 (20:54 +0100)
committerEshel Yaron <me@eshelyaron.com>
Tue, 25 Feb 2025 19:54:05 +0000 (20:54 +0100)
lisp/emacs-lisp/lisp-mode.el

index 8ae1e7f4e0471970bd6bdc7aa357f3922fd86163..787bc7f634eddfa8ea51be1c7c190a0d2fd7145a 100644 (file)
@@ -1064,6 +1064,18 @@ font-lock keywords will not be case sensitive."
     (backward-sexp)
     (delete-char 1)))
 
+(defun lisp-duplicate-sexp (n)
+  "Duplicate sexp immediately after or before point in a new line N times."
+  (interactive "p")
+  (let ((exp (thing-at-point 'sexp)))
+    (dotimes (_ n)
+      (save-excursion
+        (cond
+         ((equal (char-after)  ?\() (insert exp "\n"))
+         ((equal (char-before) ?\)) (insert "\n" exp))
+         (t (user-error "No list at point")))
+        (when (nth 9 (syntax-ppss)) (lisp-tidy-sexp))))))
+
 (defvar-keymap lisp-mode-shared-map
   :doc "Keymap for commands shared by all sorts of Lisp modes."
   :parent prog-mode-map
@@ -1076,6 +1088,7 @@ font-lock keywords will not be case sensitive."
   "M-r"      #'raise-sexp
   "M-S"      #'lisp-split-sexp
   "M-J"      #'lisp-join-sexps
+  "M-D"      #'lisp-duplicate-sexp
   "M-<up>"   #'lisp-splice-following
   "?"        #'lisp-character
   "C-)"      #'lisp-slurp-forward