[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Remove sexp without deleting contents
From: |
Eric Abrahamsen |
Subject: |
Re: Remove sexp without deleting contents |
Date: |
Sat, 29 Sep 2018 18:54:23 -0700 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
Tim Johnson <tim@akwebsoft.com> writes:
> This poses a rather trivial question, but I'm betting on some
> seredipity from responses.
>
> Suppose I want to remove an extraneous sexp. The following code
> is simplistic:
> (defun tj-toggle-menu-visible ()
> "Toggle visibility of menu bar and switches to tmm-style menus"
> (interactive)
> (if tj-menu-visible
> (progn
> (setq tj-menu-visible nil)
> (menu-bar-mode -1)
> (setq tj-is-windows nil))
> (progn
> (setq tj-menu-visible t)
> (menu-bar-mode 1)
> (setq tj-is-windows window-system))))
>
> ;; Suppose I want to remove the second `progn form, but not the
> enclosed sequences. In this simple block of code of code it's pretty
> hard to screw up: just delete/kill the line with "(progn" and any
> right parens from the last line. In a more complex example I might
> delete a parens whose absence could introduce unexpected and
> problematic side effects.
>
> Is there function that might (effectively) simultaneously remove the
> beginning of sexp and the matching closing paren, leaving inner
> contents intact?
I would guess a majority of people who do a lot of lisp/elisp editing
use the paredit package (in the repos). Maybe not a majority, who knows,
but it's really useful. It lets you edit lisp code "logically": by atoms
and sexps, rather than character-by-character. In paredit, the command
`paredit-splice-sexp-killing-backward' would do what you want, it's
bound to M-<up>.
HTH,
Eric