From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jim Porter Newsgroups: gmane.emacs.bugs Subject: bug#49518: 28.0.50; electric-pair-mode skip-self fails for single-quotes in python-mode Date: Sat, 10 Jul 2021 18:32:34 -0700 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="24927"; mail-complaints-to="usenet@ciao.gmane.io" To: 49518@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Jul 11 03:33:15 2021 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 1m2OLK-0006JQ-PI for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 11 Jul 2021 03:33:14 +0200 Original-Received: from localhost ([::1]:34820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1m2OLI-0005tn-1n for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 10 Jul 2021 21:33:12 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:33148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2OL8-0005tR-LC for bug-gnu-emacs@gnu.org; Sat, 10 Jul 2021 21:33:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50361) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m2OL8-0001t5-Ds for bug-gnu-emacs@gnu.org; Sat, 10 Jul 2021 21:33:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1m2OL8-0006Da-68 for bug-gnu-emacs@gnu.org; Sat, 10 Jul 2021 21:33:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jim Porter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 11 Jul 2021 01:33:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 49518 X-GNU-PR-Package: emacs X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.162596717123883 (code B ref -1); Sun, 11 Jul 2021 01:33:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 11 Jul 2021 01:32:51 +0000 Original-Received: from localhost ([127.0.0.1]:33674 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m2OKw-0006D9-Lq for submit@debbugs.gnu.org; Sat, 10 Jul 2021 21:32:50 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:50548) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1m2OKu-0006D0-Rk for submit@debbugs.gnu.org; Sat, 10 Jul 2021 21:32:49 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:32868) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1m2OKu-0005sh-Jq for bug-gnu-emacs@gnu.org; Sat, 10 Jul 2021 21:32:48 -0400 Original-Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:44657) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1m2OKs-0001dq-VY for bug-gnu-emacs@gnu.org; Sat, 10 Jul 2021 21:32:48 -0400 Original-Received: by mail-pj1-x1035.google.com with SMTP id p4-20020a17090a9304b029016f3020d867so8331311pjo.3 for ; Sat, 10 Jul 2021 18:32:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=gLbAaXkZlqHtX7PHLGs1DKokOmand3/HbzqMG7A2EGA=; b=LJmBqnJLy1gm41DBZOLb/90XWgHCO6PENLBwqjY4NFJb5kCpw3ZMDq7w2T8Hm1cPae 58R3AvCRinOqUM5qU+I8yW/eExilLwH0JLBtCiDCOwAONbcQM8rWtikEmgZzEZElUvl3 PBa8iUwEIlPR5RqmNemtgCtu+jtfjhtTl2788YpKsbQIOJTBRMFIo1z79ygMjFMBkw5t dpTSY9T4s4dlz2SV1g6ypEkm/ZVd1IKzXpdxVr3/B6pZKis+iHppbPvKALxy79D6Peus Zw3CJKKknDg5XVhW0O/8uRzByv3IB5EfTnv93j31herQ7ZFQNGTlXImyPoTLa3BEDVtH pjCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=gLbAaXkZlqHtX7PHLGs1DKokOmand3/HbzqMG7A2EGA=; b=l8dHafsDTAMH4nd4yi4A3k0UixISGcZkqZdjVOOei+YnLQ2NtD4eMjZQpK4MblTmMa WzDgqaRvVQeEMTB6e4cGLQbJQcjfv97j3uvk4rTNK/HTFvV9p5pCi9WEe9nBHiY8KyYG TfALzhxT5G1h5UyCfyB2E8XtiHrNpuHP7ouTvroKuMwNVPtlVVQgxNoLhstCNF+XLgJa 0tvnRelzpAyQuX4do/AfObQw8w9uufmorpfvPMQbqnve00JI6ErXtKCTD3G7ZMH+FQ+o 0nQT4xJcxFZcn8e7dcbhKXUsDISXABuTImYvBpCuCGYRfr5BgsG5JYN+odhO1k0n02mE /4hQ== X-Gm-Message-State: AOAM530fHv3Msw0ux/cTFHYyt+D4cJbJTUWpJt8CmUIXRYCDYkA0mJ/S v/hupY51KCvRWKtBGBPgeAL8H8sT+ygVHgtoZMgA3cwjTlI= X-Google-Smtp-Source: ABdhPJxCgRVPiNrOiLxMuxftgYmT787BKx3074u5Q1S3xKcBFNig7yPP2SD+vAB+ry5V0qclL1kA/DiD3KqyFeDRfzM= X-Received: by 2002:a17:90a:710a:: with SMTP id h10mr6899640pjk.103.1625967164494; Sat, 10 Jul 2021 18:32:44 -0700 (PDT) Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=jporterbugs@gmail.com; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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" Xref: news.gmane.io gmane.emacs.bugs:209779 Archived-At: To reproduce this issue: 1. emacs -Q --eval '(electric-pair-mode)' foo.py 2a. Type " (double-quote); result should be "|", where | is the point 2b. Type " (double-quote); result should be ""| (Note: This is the correct behavior, as I understand it.) 3. Delete everything (optional) 4a. Type ' (single-quote); result should be '|' 4b. Type ' (single-quote); result is ''|', but (I think) it should be ''| Having looked through the source of both `electric-pair-mode' and `python-mode', I believe I understand the problem. First, some background: in `electric-pair-syntax-info', it checks whether the point is inside a string or comment. If so, it uses `electric-pair-text-syntax-table' (defaulting to `prog-mode-syntax-table'); if not, it uses `python-mode-syntax-table'. Normally, this means if you have a snippet like ''|', the point is *not* inside string; it's after the end of one string and before the start of the next. However, Python has multiline strings, which causes an issue here. When python-mode sees 3 quotation marks in a row, it doesn't see that as an empty string followed by the start of a separate string; it sees the start of a multiline string. Thus, when we have our snippet ''|', the point is considered to be in a string. That means `electric-pair-syntax-info' uses `electric-pair-text-syntax-table'. Since the default prog-mode syntax table doesn't consider single-quote to be a quote character, `electric-pair-syntax-info' ends up returning nil. Notably, this *isn't* an issue for double-quote. While we (temporarily) have the state ""|", double-quote is a quote character according to `electric-pair-text-syntax-table', and so skip-self proceeds as expected. (You might think the fix here would be to do like `emacs-lisp-mode' and locally set `electric-pair-text-pairs' to include single-quote. This wouldn't work though, since it would make it hard to type an apostrophe in a word; `electric-pair-mode' would double it up.) One possible fix would be for `python-mode' to locally set `electric-pair-text-syntax-table' to `python-mode-syntax-table'. This seems to work for me after some basic testing, but I'm not confident it's the right thing to do here; I don't see any examples of other modes that do this, and I haven't thought over all the possible problems with it.