From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Wilhelm Kirschbaum Newsgroups: gmane.emacs.bugs Subject: bug#62536: 30.0.50; Can we add """ ... """ electric pair in elixir, just like python Date: Wed, 05 Apr 2023 19:28:06 +0200 Message-ID: <87y1n6b56c.fsf@gmail.com> References: <83sfdm6bet.fsf@gnu.org> <87edp6oim6.fsf@gmail.com> <87lejay8n3.fsf@gmail.com> <06DAF2C4-C224-4C30-AAAE-96D1A84ED145@outlook.com> <87bkk642k0.fsf@gmail.com> <87edp2vzvg.fsf@gmail.com> <87h6tx74i4.fsf@gmail.com> <83y1n9ukqb.fsf@gnu.org> <83o7o5uj2c.fsf@gnu.org> <871ql06w59.fsf@gmail.com> <87zg7nfrex.fsf@gmail.com> <87v8ibfnke.fsf@gmail.com> <87mt3nfktw.fsf@gmail.com> <875yaa2yce.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="16812"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.9.3; emacs 30.0.50 Cc: Eli Zaretskii , 62536@debbugs.gnu.org, mou.tong@outlook.com To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 05 19:39:20 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pk76O-0004CM-Co for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 05 Apr 2023 19:39:20 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pk76A-0001fj-HX; Wed, 05 Apr 2023 13:39:06 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pk766-0001fJ-Up for bug-gnu-emacs@gnu.org; Wed, 05 Apr 2023 13:39:04 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pk766-00079s-Kn for bug-gnu-emacs@gnu.org; Wed, 05 Apr 2023 13:39:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pk766-0002zU-8Q for bug-gnu-emacs@gnu.org; Wed, 05 Apr 2023 13:39:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Wilhelm Kirschbaum Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 05 Apr 2023 17:39:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62536 X-GNU-PR-Package: emacs Original-Received: via spool by 62536-submit@debbugs.gnu.org id=B62536.168071631111452 (code B ref 62536); Wed, 05 Apr 2023 17:39:02 +0000 Original-Received: (at 62536) by debbugs.gnu.org; 5 Apr 2023 17:38:31 +0000 Original-Received: from localhost ([127.0.0.1]:52571 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pk75a-0002yd-I0 for submit@debbugs.gnu.org; Wed, 05 Apr 2023 13:38:30 -0400 Original-Received: from mail-wr1-f45.google.com ([209.85.221.45]:38592) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pk75Y-0002yO-FI for 62536@debbugs.gnu.org; Wed, 05 Apr 2023 13:38:28 -0400 Original-Received: by mail-wr1-f45.google.com with SMTP id q19so33924574wrc.5 for <62536@debbugs.gnu.org>; Wed, 05 Apr 2023 10:38:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680716302; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:from:to:cc:subject:date :message-id:reply-to; bh=ucbYVdhZXx+8zH0XtK0vdH6NlLmzNCGyk0tutXl0mQE=; b=MpIZv0QDz/bcB0RNJN2j78h7LsJMckuQB4vt/f5FYRxDgNYkzFu0ChsPE7RzV01iGX AOSvlrfmfzQcIaNcNktb61EL8L5LBCWm1Gm8NYmZwQy7S3tyOp3FXm49yTAiflVOUMWe XCWvpZGGNkniyKNw66LHloxvCAR36pMlCc07LLCycit9cVYoof3XJxZsoEdGvrZHzZ1w 8LuzxP50xrh3XDRNScsXbp0idCIYG9SXYvb/f9LFmGFYKDQuoZzupCqtVWBiMOTXc+1Z D2df93H4KiUsd4xB58FN6DWZmAX0GfpW8oqTTzTeI9n2vAZlkB9CEsnPmzlI2jAVzT/B EbnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680716302; h=content-transfer-encoding:mime-version:message-id:in-reply-to:date :subject:cc:to:from:user-agent:references:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=ucbYVdhZXx+8zH0XtK0vdH6NlLmzNCGyk0tutXl0mQE=; b=rZ+y+u7lLpcIgK0CO6+BILexv+I9GGE+KeyG5D/dllXL0XNs+uk0bTRWPPG8g/nwW1 nIThlBqQJBN5V2TQ5m0tyraCCWAamue28ynhnV+0/mdI2F7fyhS3y4mkaAkUS3I2w3gW bF3/hQ+/T0+nIeuc3TRr3cpmFS9L4bO5qFCYJvyEGp6MzdTgIrK04V+czf4HnYooNIzH Ond1T6z7+Twu34xlhr3qHYGF7RmdtvmO0uOv64xfdvS/G9mSWgnrSUzXVHf3KbWXHVPO 0jdDkiHT1RQ7CduNPhhNZwyhpr8+u5fuzYoQvognRX+4YYdDMCvkgoNjfiV/8h160qFC kXqQ== X-Gm-Message-State: AAQBX9f9GAFkrIRd/m6mJRP8mEMHZcjSN4PKXPpiaSW8PLyuaIarLWbs BOa+yvRIiKHL63VoF2DLNB8= X-Google-Smtp-Source: AKy350bcimte5EXcdRpzB5gdGoKwmLzj03gxrSKi0O2ExKDczjQAFzH9YsIdbLb0yEnjeXGt3bK8nQ== X-Received: by 2002:a5d:62ce:0:b0:2bf:bf05:85ac with SMTP id o14-20020a5d62ce000000b002bfbf0585acmr2207566wrv.23.1680716302515; Wed, 05 Apr 2023 10:38:22 -0700 (PDT) Original-Received: from melissa.local (ec2-13-245-158-50.af-south-1.compute.amazonaws.com. [13.245.158.50]) by smtp.gmail.com with ESMTPSA id n5-20020adffe05000000b002d97529b3bbsm15545924wrr.96.2023.04.05.10.38.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 10:38:22 -0700 (PDT) In-reply-to: <875yaa2yce.fsf@gmail.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:259282 Archived-At: > Wilhelm Kirschbaum writes: > >>>> And in electric-layout-rules you _can_, I think, identify >>>> triple quotes using a function as described in the last >>>> paragraph of its docstring. >>>> >>> Yes, I tested this earlier and it does work. >>> >> >> Even though it works, it does not play nice with the custom=20 >> psif, >> because the layout rules seems to trigger before the hook. > > There could yet be a snag here, which I didn't anticipate, which=20 > is that > rules in electric-layout-rules do not trigger if inside strings=20 > or > comments, and that is hardcoded. > > Let's assume we got rid of the snag or had some mechanism to=20 > override > it: > > diff --git a/lisp/electric.el b/lisp/electric.el > index bac3f5a2b3c..cef5326852c 100644 > --- a/lisp/electric.el > +++ b/lisp/electric.el > @@ -409,9 +409,7 @@=20 > electric-layout-post-self-insert-function-1 > (goto-char pos) > (funcall probe=20 > last-command-event)))) > (when res (throw 'done=20 > res)))))))))) > - (when (and rule > - ;; Not in a string or comment. > - (not (nth 8 (save-excursion (syntax-ppss=20 > pos))))) > + (when rule > (goto-char pos) > (when (functionp rule) (setq rule (funcall rule))) > (dolist (sym (if (symbolp rule) (list rule) rule)) > > > Then, the following simple patch seems to have good results in=20 > my tests. > > (defun joaot/looking-back-at-exactly-three-quotes-p () > (looking-back "\\(\\`\\|[^\"]\\)\"\"\"" (- (point) 4))) >=20=20=20=20=20 > (defun joaot/triple-quotes () > (when (and (eq ?\" last-command-event) > (joaot/looking-back-at-exactly-three-quotes-p)) > (save-excursion (insert "\"\"\"" )))) >=20=20=20=20=20 > (defun joaot/layout-after-triple-quotes (inserted) > (when (and (eq inserted ?\")=20 > (joaot/looking-back-at-exactly-three-quotes-p)) > '(after-stay after))) >=20=20=20=20=20 > (defun joaot/setup-elixir-electricity () > (electric-layout-local-mode 1) > (electric-pair-local-mode 1) > (electric-indent-local-mode 1) > (add-hook 'post-self-insert-hook=20 > 'joaot/super-quotes-and-newlines -05 t) > (setq-local electric-layout-rules > (list #'joaot/layout-after-triple-quotes))) >=20=20=20=20=20 > (add-hook 'elixir-ts-mode-hook=20 > 'joaot/setup-elixir-electricity) > > Jo=C3=A3o Thanks, yes. I think this brings us closer. For some more fun,=20 and the other part of the issue I have not mentioned is this scenario: ```elixir def foo() do ~H"""