From 90ca9317f524359786f6427f6d5a109abee2211c Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Fri, 1 Oct 2021 09:25:43 +0200 Subject: [PATCH] Add slurp-sexp and barf-sexp * lisp.el (slurp-sexp): Add function (barf-sexp): Add function --- lisp/emacs-lisp/lisp.el | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lisp/emacs-lisp/lisp.el b/lisp/emacs-lisp/lisp.el index 9b38d86e2c..e49893303c 100644 --- a/lisp/emacs-lisp/lisp.el +++ b/lisp/emacs-lisp/lisp.el @@ -867,6 +867,33 @@ raise-sexp (delete-region (point) (save-excursion (forward-sexp 1) (point))) (save-excursion (insert s)))) +(defun slurp-sexp (&optional arg) + "Pull the next ARG sexps into the current list." + (interactive "p") + (save-excursion + (up-list 1) + (let ((start (point))) + (forward-sexp arg) + (let ((copy (delete-and-extract-region start (point)))) + (down-list -1) + (insert copy))) + (let ((bounds (bounds-of-thing-at-point 'sexp))) + (indent-region (car bounds) (cdr bounds))))) + +(defun barf-sexp (&optional arg) + "Push the last ARG sexps out of the current list." + (interactive "p") + (save-excursion + (up-list 1) + (down-list -1) + (let ((start (point))) + (backward-sexp arg) + (let ((copy (delete-and-extract-region (point) start))) + (move-past-close-and-reindent) + (insert copy))) + (let ((bounds (bounds-of-thing-at-point 'sexp))) + (indent-region (car bounds) (cdr bounds))))) + (defun move-past-close-and-reindent () "Move past next `)', delete indentation before it, then indent after it." (interactive) -- 2.30.2