From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Nicolas Richard Newsgroups: gmane.emacs.help Subject: Re: How to delete the parens around a sexp? Date: Tue, 22 Sep 2015 12:11:41 +0200 Message-ID: <87lhby7ogy.fsf@members.fsf.org> References: <87vbb23nrn.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1442916886 2520 80.91.229.3 (22 Sep 2015 10:14:46 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 22 Sep 2015 10:14:46 +0000 (UTC) Cc: Help Gnu Emacs mailing list To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Sep 22 12:14:32 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 1ZeKal-0007ep-F6 for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Sep 2015 12:14:31 +0200 Original-Received: from localhost ([::1]:38197 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeKak-0008TO-ST for geh-help-gnu-emacs@m.gmane.org; Tue, 22 Sep 2015 06:14:30 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60846) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeKaW-0008T3-TF for help-gnu-emacs@gnu.org; Tue, 22 Sep 2015 06:14:17 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZeKaS-0003rY-JD for help-gnu-emacs@gnu.org; Tue, 22 Sep 2015 06:14:16 -0400 Original-Received: from mxin.ulb.ac.be ([164.15.128.112]:37920) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZeKaS-0003qE-Dn for help-gnu-emacs@gnu.org; Tue, 22 Sep 2015 06:14:12 -0400 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApoEABQpAVakD4Xx/2dsb2JhbABdglLHZQKCCwEBAQEBAYELhCUBBXkFCwgDDhMlDwEESROILstZi3CFDQeELAWVZ45XhDaCbjORfmOEAzyKIAEBAQ Original-Received: from mathsrv4.ulb.ac.be (HELO localhost) ([164.15.133.241]) by smtp.ulb.ac.be with ESMTP; 22 Sep 2015 12:11:14 +0200 In-Reply-To: <87vbb23nrn.fsf@mbork.pl> (Marcin Borkowski's message of "Tue, 22 Sep 2015 09:40:28 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 164.15.128.112 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:107276 Archived-At: 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