From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: Skeleton angle brackets '<' and '>' Date: Thu, 7 Jan 2016 15:07:15 +0600 Message-ID: References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1452157676 26826 80.91.229.3 (7 Jan 2016 09:07:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 7 Jan 2016 09:07:56 +0000 (UTC) Cc: "help-gnu-emacs@gnu.org" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jan 07 10:07:56 2016 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 1aH6Xy-0008Vm-KT for geh-help-gnu-emacs@m.gmane.org; Thu, 07 Jan 2016 10:07:54 +0100 Original-Received: from localhost ([::1]:57597 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aH6Xs-0000k5-NX for geh-help-gnu-emacs@m.gmane.org; Thu, 07 Jan 2016 04:07:48 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60404) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aH6Xi-0000jn-7Z for help-gnu-emacs@gnu.org; Thu, 07 Jan 2016 04:07:39 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aH6Xh-0000aa-2u for help-gnu-emacs@gnu.org; Thu, 07 Jan 2016 04:07:38 -0500 Original-Received: from mail-lf0-x22e.google.com ([2a00:1450:4010:c07::22e]:35974) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aH6Xg-0000aU-S6 for help-gnu-emacs@gnu.org; Thu, 07 Jan 2016 04:07:37 -0500 Original-Received: by mail-lf0-x22e.google.com with SMTP id z124so323175501lfa.3 for ; Thu, 07 Jan 2016 01:07:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:cc:content-type:content-transfer-encoding; bh=vGasM6hcGflkqJuqGQs0Rj4KGdejaPgxfo2gyPfn31g=; b=qh8q45h3ZsjZkEV2IHKih2PiT5RLTXiD1Efqw0YsG/rAQEIxx5o8ksscaUDbcx4x0V 01qbbt+VgCtI88eGTxvS9ObOXQO4NQ2CEwCahtgOiKU9VAEAi5KLyFl6vanNI2EzK4XD 5pBPv8Olm3z0IlQuvNegQK34mGiPdmQjh6We13MQyL6JXbsBjPAtjjjVoa+eiLriEM6j s0Tcbj6K8fVbbKdBPkxQ4qR7jTFqT6Qekt+MbULwqJ83CAOwVjvBNtbOqDiWkfQsBCNY raqh9HrxMfXvKk3NLPlmln6AJf021xyD6qLHDGKB4URhYz+J4RrknMRNAZdDqdf2POZy 6m9A== X-Received: by 10.25.149.21 with SMTP id x21mr3220111lfd.124.1452157655544; Thu, 07 Jan 2016 01:07:35 -0800 (PST) Original-Received: by 10.112.129.163 with HTTP; Thu, 7 Jan 2016 01:07:15 -0800 (PST) In-Reply-To: X-Google-Sender-Auth: cMhcLv379-vGqrhuyR3PXH9TAR4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::22e 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:108641 Archived-At: On Wed, Jan 6, 2016 at 11:59 PM, Alan Mackenzie wrote: >> I also want to pair the angle brackets, i.e. `<' and `>' characters. > > Be careful what you want! Do you also want automatically to pair up > "less than" with "greater than"? It could get pretty tedious if, every > time you wanted to write "i < 10", you got "i <>", forcing you to delete > the ">" before writing in the "10". With some careful coding convention planning, the impossible becomes easy. > For example, how many parameters are passed to foo in the following: > > foo (a < b, c > d); > > ? As written, it is clearly a function call, because there are spaces on both sides of the operators. > It might be a function call with two relational expressions, it might > be a declaration with the single parameter d of templated type a . In this case, there will be no spaces on the inner side of the brackets, and in some coding conventions, neither before the opening bracket: f(x, y); a. So Foo foo(a d); declares a function foo taking a single parameter named d of type a and returning Foo; while Foo foo(a < b, c > d); declares a variable foo of type Foo passing a < b as the first constructor argument and c > d as the second. (The original example is invalid because C++ does not have implicit int.) (There is one technical exception to the =E2=80=9Cno space on the inner sid= e of a bracket=E2=80=9D rule: we have to put an intervening space when closin= g two template argument lists in code that has to preserve C++03 compatibility.) So, returning to the original question, I do it with smartparens this way: (sp-local-pair 'c++-mode "<" ">" :when '(sp-point-after-word-p)) This way, < is treated as a bracket only when used immediately after an identifier with no intervening space. This also solves the case of the << operator =E2=80=94 the first angle is not paired because it is prece= ded by a space, and the second angle because the immediately preceding token (the first angle) is not a word. (I do, however, get pairing when writing operator< or operator<<, and no pairing when writing #include <>. Should probably code a couple of exceptions for those.)