From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Edward Knyshov Newsgroups: gmane.emacs.help Subject: Re: How to delete the parens around a sexp? Date: Tue, 22 Sep 2015 11:30:10 +0000 Message-ID: References: <87vbb23nrn.fsf@mbork.pl> <87lhby7ogy.fsf@members.fsf.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1442921533 11315 80.91.229.3 (22 Sep 2015 11:32:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Sep 2015 11:32:13 +0000 (UTC) Cc: Help Gnu Emacs mailing list To: Nicolas Richard , Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Sep 22 13:32:12 2015 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ZeLnv-0007e3-IH for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Sep 2015 13:32:11 +0200 Original-Received: from localhost ([::1]:38569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeLnv-0001dz-0W for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Sep 2015 07:32:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55375) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeLmA-0000aK-Ub for help-gnu-emacs@gnu.org; Tue, 22 Sep 2015 07:30:24 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZeLm9-0001uq-T8 for help-gnu-emacs@gnu.org; Tue, 22 Sep 2015 07:30:22 -0400 Original-Received: from mail-la0-x235.google.com ([2a00:1450:4010:c03::235]:36743) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeLm9-0001ro-8w for help-gnu-emacs@gnu.org; Tue, 22 Sep 2015 07:30:21 -0400 Original-Received: by lanb10 with SMTP id b10so7909804lan.3 for ; Tue, 22 Sep 2015 04:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-type; bh=0ZUoRfgqtFW4RRkkj7ruy2DjbZST66itYQKyOqbKeQs=; b=bU8NrshcZsKJL97z6SCgVi/o3EbxN/LhBmSU3V7h7mRYvJ7A3ZU09cXtskbVzHdU2o eEu9KuJAn8est5J7XqRQwn9weDwNK7bVm4l8OK1df4dyT5jigdDreVozBM/rtx3Abj9h xq1qGce9+hVm31nF78h5XbBb6abY0bGc+syyXrP1thrH5HM6OGeg4R+layHC87ahvP9s 1YmnIWBmPVBOSie0VWjN7x6jUTAKu62qACWe1prIGwGKesgZAB/J5QGZNxM1PhBN6Ab+ nHFw/wK1bZpOag1jBDmFqNVILZIcVVbQTj9zhcoAjfviK0MCuNwEXWCuoDHAd76wyrfE cfvg== X-Received: by 10.152.29.198 with SMTP id m6mr9500115lah.25.1442921419891; Tue, 22 Sep 2015 04:30:19 -0700 (PDT) In-Reply-To: <87lhby7ogy.fsf@members.fsf.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::235 X-Content-Filtered-By: Mailman/MimeDel 2.1.14 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:107277 Archived-At: You may use unwrap-sexp from smartparens On Tue, Sep 22, 2015, 1:14 PM Nicolas Richard wrote: > Marcin Borkowski writes: > > > Hi list, > > > > I'd like to transform this: > > > > -!-(some gibberish) > > > > into this: > > > > -!-some gibberish > > I use the following code, which allows me to delete the brackets (M-D > RET) or replace them by another pair, e.g. square brackets (M-D [). > > M-D runs the command yf/replace-or-delete-pair defined as follows: > > (defun yf/replace-or-delete-pair (open) > "Replace pair at point by OPEN and its corresponding closing character. > The closing character is lookup in the syntax table or asked to > the user if not found." > (interactive > (list > (read-char > (format "Replacing pair %c%c by (or hit RET to delete pair):" > (char-after) > (save-excursion > (forward-sexp 1) > (char-before)))))) > (if (memq open '(?\n ?\r)) > (delete-pair) > (let ((close (cdr (aref (syntax-table) open)))) > (when (not close) > (setq close > (read-char > (format "Don't know how to close character %s (#%d) ; > please provide a closing character: " > (single-key-description open 'no-angles) > open)))) > (yf/replace-pair open close)))) > > (defun yf/replace-pair (open close) > "Replace pair at point by respective chars OPEN and CLOSE. > If CLOSE is nil, lookup the syntax table. If that fails, signal > an error." > (let ((close (or close > (cdr-safe (aref (syntax-table) open)) > (error "No matching closing char for character %s (#%d)" > (single-key-description open t) > open))) > (parens-require-spaces)) > (insert-pair 1 open close)) > (delete-pair) > (backward-char 1)) > > -- > Nicolas Richard > >