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: Mon, 03 Apr 2023 10:26:59 +0200 Message-ID: <87h6tx74i4.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> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="27268"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.9.3; emacs 30.0.50 Cc: "62536@debbugs.gnu.org" <62536@debbugs.gnu.org> To: Mou Tong Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Apr 03 10:30: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 1pjFZz-0006w0-Bm for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 03 Apr 2023 10:30:19 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pjFZq-0001vd-PY; Mon, 03 Apr 2023 04:30:11 -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 1pjFZj-0001vI-Gb for bug-gnu-emacs@gnu.org; Mon, 03 Apr 2023 04:30:03 -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 1pjFZi-0008R7-QI for bug-gnu-emacs@gnu.org; Mon, 03 Apr 2023 04:30:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pjFZi-00063x-Le for bug-gnu-emacs@gnu.org; Mon, 03 Apr 2023 04:30: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: Mon, 03 Apr 2023 08:30: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.168051059223259 (code B ref 62536); Mon, 03 Apr 2023 08:30:02 +0000 Original-Received: (at 62536) by debbugs.gnu.org; 3 Apr 2023 08:29:52 +0000 Original-Received: from localhost ([127.0.0.1]:43321 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pjFZX-000634-Gi for submit@debbugs.gnu.org; Mon, 03 Apr 2023 04:29:52 -0400 Original-Received: from mail-wm1-f52.google.com ([209.85.128.52]:56083) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pjFZV-00062o-QF for 62536@debbugs.gnu.org; Mon, 03 Apr 2023 04:29:50 -0400 Original-Received: by mail-wm1-f52.google.com with SMTP id m8so5661210wmq.5 for <62536@debbugs.gnu.org>; Mon, 03 Apr 2023 01:29:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680510583; h=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=yJhXQG72u7tDNEjjm/7I4W+v5bKW1szVhnLB6MLRmEM=; b=DE7tTUz39zigI2R0FS7tm2vVmDXxICEYYDRdvKdenxRnVJM+9Sd/75gTUoaGBqdmSG 0XPXDT7mJCWcr3P27QO93QxaosPuK3bDduWRPsRhIszSysdHCeDOPO/t58hZhuHBOgNJ 1mr9trsrgbKScdhZTSMDG4iKm8nPmSP5BFyEQv/iYecMZ/n/xK9cmFEsNPcoDCaB5n7F rsnIHCfMdnSHvh1hSDFyiIsrs2B1MWNLqdci2QJd6dDv8VSKnr/8c/+U6Uv3PgJaioZb QalsK7hBumUdvh0qwop8nUUZ4eY6TYAnuZMg/btT5TRxXWYtba+rVpU+XyeDyvF/m3qS ucNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680510583; h=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=yJhXQG72u7tDNEjjm/7I4W+v5bKW1szVhnLB6MLRmEM=; b=tEHor38I9l6jY2CJiQGxXX67vbP3hRmY52sMN9XoGck/sf1oNWKu8Hr7FUrgETnGnp KYYAVHeACa5tTIRO3znNbuin0kG+SgisV8436WHyUUUlB4I75DjbzOt+T/knevcmZ5mQ hZTHL73iBa3M7g3oIR1tyGJDGrWAc8J2Wz7csksMxpHkTUZXjS/tEdpdIu+qFxid+6Et 6pXKKriFYkHiCQIRpPUdWZXdY/mtOicPW36bmLfAPCj5pdhiKVkIwA20mlWDB3ZXxxPn WwW/28xfl2odUYkXpmd2Rfg9OjF8h0oLGTagA3wc8AdPxjPjiMVY8ARqFGhkQmM3cQew YV3g== X-Gm-Message-State: AAQBX9ejiMXdU823WERwE0bqstgWxFjH7sSyA+Ch88WcVY5AA7MwVxNw jlq7KCqsMbkuhNLpu0e7qrblJ+MwweQ= X-Google-Smtp-Source: AKy350aPn9RHrJ3i8kh/NzIPHVjgomtlTmQ694KbTOsUnNi/8ueItnXv42ywuWiNItoiEUffBqHvAw== X-Received: by 2002:a7b:ce84:0:b0:3ef:6fee:803a with SMTP id q4-20020a7bce84000000b003ef6fee803amr17870585wmj.35.1680510583278; Mon, 03 Apr 2023 01:29:43 -0700 (PDT) Original-Received: from melissa.local ([2c0f:ef18:1431:0:b09:9616:db04:c248]) by smtp.gmail.com with ESMTPSA id s15-20020a05600c45cf00b003eb2e33f327sm29186636wmo.2.2023.04.03.01.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 01:29:42 -0700 (PDT) In-reply-to: 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:259161 Archived-At: --=-=-= Content-Type: text/plain; format=flowed Mou Tong writes: >> There should never be a reason for the heredoc to be on a >> single line >> and also makes the tree-sitter grammar invalid, which causes >> the >> blinking issue. > > You are right, I didn't consider that. > >> ``` >> @doc """| >> """ >> ``` >> >> This will be the change ( looking at the electric.el code ). > > Cool, hoping to see the new feature soon (so sorry I don't know > much > about elisp and may not be able to help you much with it.) These two patches should then be sufficient to better handle heredocs for electric-pair-mode: --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Propertize-heredocs-in-elixir-ts-mode.patch Content-Description: Propertize heredocs >From 53a1caf7db5627b9d470b6f652d21812c1fac4db Mon Sep 17 00:00:00 2001 From: Wilhelm H Kirschbaum Date: Tue, 21 Mar 2023 16:34:48 +0200 Subject: [PATCH 1/4] Propertize heredocs in elixir-ts-mode * lisp/progmodes/elixir-ts-mode.el (elixir-ts--syntax-propertize-query): New variable. (elixir-ts--syntax-propertize): New helper. (elixir-ts-mode): Set syntax-propertize-function. --- lisp/progmodes/elixir-ts-mode.el | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lisp/progmodes/elixir-ts-mode.el b/lisp/progmodes/elixir-ts-mode.el index 286f3e39f43..0cd938c2fc9 100644 --- a/lisp/progmodes/elixir-ts-mode.el +++ b/lisp/progmodes/elixir-ts-mode.el @@ -55,7 +55,9 @@ (declare-function treesit-parser-list "treesit.c") (declare-function treesit-node-parent "treesit.c") (declare-function treesit-node-start "treesit.c") +(declare-function treesit-node-end "treesit.c") (declare-function treesit-query-compile "treesit.c") +(declare-function treesit-query-capture "treesit.c") (declare-function treesit-node-eq "treesit.c") (declare-function treesit-node-prev-sibling "treesit.c") @@ -547,6 +549,22 @@ elixir-ts--defun-name (_ nil)))) (_ nil))) +(defvar elixir-ts--syntax-propertize-query + (when (treesit-available-p) + (treesit-query-compile + 'elixir + '(((["\"\"\""] @quoted-text)))))) + +(defun elixir-ts--syntax-propertize (start end) + "Apply syntax text properties between START and END for `elixir-ts-mode'." + (let ((captures + (treesit-query-capture 'elixir elixir-ts--syntax-propertize-query start end))) + (pcase-dolist (`(,name . ,node) captures) + (pcase-exhaustive name + ('quoted-text + (put-text-property (1- (treesit-node-end node)) (treesit-node-end node) + 'syntax-table (string-to-syntax "$"))))))) + ;;;###autoload (define-derived-mode elixir-ts-mode prog-mode "Elixir" "Major mode for editing Elixir, powered by tree-sitter." @@ -627,7 +645,8 @@ elixir-ts-mode ( elixir-sigil elixir-string-escape elixir-string-interpolation )))) - (treesit-major-mode-setup))) + (treesit-major-mode-setup) + (setq-local syntax-propertize-function #'elixir-ts--syntax-propertize))) (if (treesit-ready-p 'elixir) (progn -- 2.40.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Handle-electric-heredocs-pairs-in-elixir-ts-mode.patch Content-Description: Handle electric pairs for heredocs in elixir-ts-mode >From 467876e261ce6f0abfe3aa29b762fae795df65d0 Mon Sep 17 00:00:00 2001 From: Wilhelm H Kirschbaum Date: Sun, 2 Apr 2023 09:43:20 +0200 Subject: [PATCH 2/4] Handle electric heredocs pairs in elixir-ts-mode * lisp/progmodes/elixir-ts-mode.el (elixir-ts--electric-pair-string-delimiter): New helper. (elixir-ts-mode): Add post-self-insert-hook. --- lisp/progmodes/elixir-ts-mode.el | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/lisp/progmodes/elixir-ts-mode.el b/lisp/progmodes/elixir-ts-mode.el index 0cd938c2fc9..9d784aadb26 100644 --- a/lisp/progmodes/elixir-ts-mode.el +++ b/lisp/progmodes/elixir-ts-mode.el @@ -565,13 +565,27 @@ elixir-ts--syntax-propertize (put-text-property (1- (treesit-node-end node)) (treesit-node-end node) 'syntax-table (string-to-syntax "$"))))))) +(defun elixir-ts--electric-pair-string-delimiter () + "Insert corresponding multi-line string for `electric-pair-mode'." + (when (and electric-pair-mode + (eq last-command-event ?\") + (let ((count 0)) + (while (eq (char-before (- (point) count)) last-command-event) + (cl-incf count)) + (= count 3)) + (eq (char-after) last-command-event)) + (save-excursion + (insert (make-string 2 last-command-event))) + (save-excursion + (newline 1 t)))) + ;;;###autoload (define-derived-mode elixir-ts-mode prog-mode "Elixir" "Major mode for editing Elixir, powered by tree-sitter." :group 'elixir-ts :syntax-table elixir-ts--syntax-table - ;; Comments + ;; Comments. (setq-local comment-start "# ") (setq-local comment-start-skip (rx "#" (* (syntax whitespace)))) @@ -581,9 +595,13 @@ elixir-ts-mode (rx (* (syntax whitespace)) (group (or (syntax comment-end) "\n")))) - ;; Compile + ;; Compile. (setq-local compile-command "mix") + ;; Electric pair. + (add-hook 'post-self-insert-hook + #'elixir-ts--electric-pair-string-delimiter 'append t) + (when (treesit-ready-p 'elixir) ;; The HEEx parser has to be created first for elixir to ensure elixir ;; is the first language when looking for treesit ranges. @@ -614,14 +632,14 @@ elixir-ts-mode ;; Indent. (setq-local treesit-simple-indent-rules elixir-ts--indent-rules) - ;; Navigation + ;; Navigation. (setq-local forward-sexp-function #'elixir-ts--forward-sexp) (setq-local treesit-defun-type-regexp '("call" . elixir-ts--defun-p)) (setq-local treesit-defun-name-function #'elixir-ts--defun-name) - ;; Embedded Heex + ;; Embedded Heex. (when (treesit-ready-p 'heex) (setq-local treesit-range-settings elixir-ts--treesit-range-rules) -- 2.40.0 --=-=-=--