From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= 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 15:33:05 +0100 Message-ID: <875yaa2yce.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> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23291"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , 62536@debbugs.gnu.org, mou.tong@outlook.com To: Wilhelm Kirschbaum Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 05 16:32:30 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 1pk4Ba-0005rp-2J for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 05 Apr 2023 16:32:30 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pk4BM-0003GY-GA; Wed, 05 Apr 2023 10:32:17 -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 1pk4BB-0003GC-Ln for bug-gnu-emacs@gnu.org; Wed, 05 Apr 2023 10:32:05 -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 1pk4B8-0001DR-Sd for bug-gnu-emacs@gnu.org; Wed, 05 Apr 2023 10:32:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pk4B8-0005PK-Hn for bug-gnu-emacs@gnu.org; Wed, 05 Apr 2023 10:32:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 05 Apr 2023 14:32: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.168070507120716 (code B ref 62536); Wed, 05 Apr 2023 14:32:02 +0000 Original-Received: (at 62536) by debbugs.gnu.org; 5 Apr 2023 14:31:11 +0000 Original-Received: from localhost ([127.0.0.1]:52392 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pk4AJ-0005O3-7u for submit@debbugs.gnu.org; Wed, 05 Apr 2023 10:31:11 -0400 Original-Received: from mail-wr1-f53.google.com ([209.85.221.53]:34792) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pk4AH-0005Np-5w for 62536@debbugs.gnu.org; Wed, 05 Apr 2023 10:31:10 -0400 Original-Received: by mail-wr1-f53.google.com with SMTP id v1so36421411wrv.1 for <62536@debbugs.gnu.org>; Wed, 05 Apr 2023 07:31:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680705063; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RRnl20ORsDUkAYe/cW1AN384IT2/wvlhgCv/miBHoCI=; b=R1/ot6pexdbKiqnGLAY2BsepdSEZ+0UXQ7dyYY5A8aiQ7vvgp1OW6Zz5flklOFwF5V CsWgHGLVua7If2GoDL/vIy0Zw9LGwfw+Xm0fDJ8PK6n5MJjydNlqepeBFpksdsy1CME2 Pp4VjjAOBzRioqnsdKQPJtgWL9xXoI2HUff5RI0mSizWeJqQ4L79b2fCOOP0GQikZotN oMZoelO0hHxBt0XWHos7p/UU++Ml05RstHJHNmGJ56VjHhDoA6hOomxZQJ1yob2uT79I hkNH+c7QqLb9HT1QMFU1d0XPIDdX0RS5BIUbjVoPxmBFDu86CjjGGvgiMwl8lR7ITQ8N P/6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680705063; h=content-transfer-encoding:mime-version:user-agent:message-id:date :references:in-reply-to:subject:cc:to:from:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=RRnl20ORsDUkAYe/cW1AN384IT2/wvlhgCv/miBHoCI=; b=f7nvMmFqnEEGbo5svIw2yNPL+I/uu5109+iy2mT/wYwHWPop96JjHcS8dFELvMNXbx WhEACYjby7/CdGMHzlnSMdZ4w7GRl4RAT54b/NRN2MJpIuEyQOJRy4Lb01lQOjXI/13B gHKTvrsxwjGmL609z9LQFJf/UJEJ4cyw9Y/MrFNkKQb2BKGsHccdp+EmFqueHX3qz32g Mr+DCpQVSC0j5V/503r80vTwwgyWw+HPI6UMIb+/1uEc6ZvRmRPNcaES98kIz2dsE+kx zPUNKygvoKiXBdu6rkvPFf3ny1S+YIj4AHXRGNNf3/+Ak8f+hw1XzYEl/c4qoVgvyHux 5MIQ== X-Gm-Message-State: AAQBX9f6VJEqtowRIolXyrudCmYBjUMb9BFmn7+c1PVgd/q1uM3Op8ne L6drEYUlms1bT/sAkJrpCDk= X-Google-Smtp-Source: AKy350bqtjGMqUDj64Vd9TAg+pXBooWEAQxu4ChJg1jC2v+VGesgFNLvlCTG6tFjf9pI0EMoGkuG/g== X-Received: by 2002:adf:fe8e:0:b0:2c5:4c9d:2dab with SMTP id l14-20020adffe8e000000b002c54c9d2dabmr2075904wrr.10.1680705063327; Wed, 05 Apr 2023 07:31:03 -0700 (PDT) Original-Received: from krug (87-196-72-128.net.novis.pt. [87.196.72.128]) by smtp.gmail.com with ESMTPSA id r8-20020a5d4e48000000b002c70e60abd4sm15370477wrt.2.2023.04.05.07.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 07:31:02 -0700 (PDT) In-Reply-To: <87mt3nfktw.fsf@gmail.com> (Wilhelm Kirschbaum's message of "Tue, 04 Apr 2023 22:29:10 +0200") 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:259269 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 psif, > because the layout rules seems to trigger before the hook. There could yet be a snag here, which I didn't anticipate, which is that rules in electric-layout-rules do not trigger if inside strings or comments, and that is hardcoded. Let's assume we got rid of the snag or had some mechanism to 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 @@ electric-layout-post-self-insert-function-1 (goto-char pos) (funcall probe last-command-event)))) (when res (throw 'done res)))))))))) - (when (and rule - ;; Not in a string or comment. - (not (nth 8 (save-excursion (syntax-ppss 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 my tests. (defun joaot/looking-back-at-exactly-three-quotes-p () (looking-back "\\(\\`\\|[^\"]\\)\"\"\"" (- (point) 4))) =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 (defun joaot/layout-after-triple-quotes (inserted) (when (and (eq inserted ?\") (joaot/looking-back-at-exactly-three-quot= es-p)) '(after-stay after))) =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 'joaot/super-quotes-and-newlines -05 = t) (setq-local electric-layout-rules (list #'joaot/layout-after-triple-quotes))) =20=20=20=20 (add-hook 'elixir-ts-mode-hook 'joaot/setup-elixir-electricity) Jo=C3=A3o