From: Philip Kaludercic <philipk@posteo.net>
To: 50929@debbugs.gnu.org
Subject: bug#50929: Add slurp-sexp and barf-sexp
Date: Fri, 01 Oct 2021 07:43:49 +0000 [thread overview]
Message-ID: <87czop2nre.fsf@posteo.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 767 bytes --]
Tags: patch
Hi,
I'd like to suggest adding the command slurp-sexp and barf-sexp to
lisp.el (perhaps after changing the names). These commands were
popularized by structural editing packages like Paredit, and allow the
user to quickly pull or push s-expressions into the current list.
In GNU Emacs 28.0.50 (build 5, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars)
of 2021-09-30 built on icterid
Repository revision: a1789fd67b2dd67d891b6c7181aee885a9ab9447
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12011000
System Description: Debian GNU/Linux 11 (bullseye)
Configured using:
'configure --with-native-compilation --with-x-toolkit=athena
'CFLAGS=-Os -march=native -pipe' LDFLAGS=-flto'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-slurp-sexp-and-barf-sexp.patch --]
[-- Type: text/patch, Size: 1679 bytes --]
From 90ca9317f524359786f6427f6d5a109abee2211c Mon Sep 17 00:00:00 2001
From: Philip Kaludercic <philipk@posteo.net>
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
[-- Attachment #3: Type: text/plain, Size: 16 bytes --]
--
Philip K.
next reply other threads:[~2021-10-01 7:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-01 7:43 Philip Kaludercic [this message]
2021-10-01 8:12 ` bug#50929: Add slurp-sexp and barf-sexp Lars Ingebrigtsen
2021-10-01 8:31 ` Philip Kaludercic
2021-11-05 3:04 ` Lars Ingebrigtsen
2021-11-06 18:53 ` Juri Linkov
2021-11-08 3:08 ` Richard Stallman
2021-11-08 15:23 ` Philip Kaludercic
2021-11-09 11:38 ` Richard Stallman
2021-11-09 12:13 ` Philip Kaludercic
2021-11-09 16:26 ` bug#50929: [External] : " Drew Adams
2021-11-09 18:44 ` Philip Kaludercic
2021-11-09 19:15 ` Drew Adams
2021-11-09 22:17 ` Drew Adams
2021-11-11 3:39 ` Richard Stallman
2021-11-14 0:05 ` Philip Kaludercic
2021-11-14 17:32 ` Drew Adams
2021-11-09 22:14 ` Rudolf Adamkovič via Bug reports for GNU Emacs, the Swiss army knife of text editors
2021-11-11 3:39 ` Richard Stallman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87czop2nre.fsf@posteo.net \
--to=philipk@posteo.net \
--cc=50929@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).