From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: kobarity Newsgroups: gmane.emacs.bugs Subject: bug#68284: [PATCH] Fix python-info-docstring-p bug in the 2nd line of a buffer Date: Sat, 06 Jan 2024 22:12:36 +0900 Message-ID: Mime-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: multipart/mixed; boundary="Multipart_Sat_Jan__6_22:12:36_2024-1" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="8805"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?Q?Goj=C5=8D?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/30.0.50 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) To: 68284@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jan 06 14:14:12 2024 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 1rM6V9-00027o-VX for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Jan 2024 14:14:12 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rM6Uw-00069k-Vw; Sat, 06 Jan 2024 08:13:59 -0500 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 1rM6Uv-00069A-Ho for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 08:13:57 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rM6Uv-00082a-9r for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 08:13:57 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rM6Uz-0005Cr-Ue for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 08:14:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: kobarity Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 Jan 2024 13:14:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 68284 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.170454678319910 (code B ref -1); Sat, 06 Jan 2024 13:14:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Jan 2024 13:13:03 +0000 Original-Received: from localhost ([127.0.0.1]:58806 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rM6U3-0005B3-AB for submit@debbugs.gnu.org; Sat, 06 Jan 2024 08:13:03 -0500 Original-Received: from lists.gnu.org ([2001:470:142::17]:44380) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rM6U1-0005AX-Gu for submit@debbugs.gnu.org; Sat, 06 Jan 2024 08:13:02 -0500 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 1rM6Tq-0005uV-Pd for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 08:12:51 -0500 Original-Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rM6Tp-0005jT-2y for bug-gnu-emacs@gnu.org; Sat, 06 Jan 2024 08:12:50 -0500 Original-Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-3bbce1202ebso544708b6e.2 for ; Sat, 06 Jan 2024 05:12:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704546767; x=1705151567; darn=gnu.org; h=mime-version:user-agent:subject:to:from:message-id:date:from:to:cc :subject:date:message-id:reply-to; bh=Rd+5NWQveDuvclMF71SQ1zjCEQT9sK/KIjs81z4XsJE=; b=LSgp/bskgvAqLmsxnKFfpcDdxZR2pIovxj3ERzldxzdSTHN8rJucM1NcFD6w1r7zf8 PychwoCIvbZNDfJpu4M5NvK7gSdSKqnPvRg64XlvDmhjFJS6G97HjNrxJEpmcfdz0h/3 yg/VZZIgjDlY5yTKQ3uCaQm3gRxHstclwwXDEk5wY6fjozkdmsK8QZJBHWBL3wjwVqtB OEu9CbQrM7NS6Rl8fu+yKugOkpBvGHHeiEZ5tiBsbOHLXOMFH8ETM/t6Gw8jM/uTlLGn iR/3iPrM+OAHl5i6DcMMd1Xc1LFsl2qpH1uqbTwXzAZRFX3uOudNvJoQ5CNpUOEljh3s Gj1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704546767; x=1705151567; h=mime-version:user-agent:subject:to:from:message-id:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Rd+5NWQveDuvclMF71SQ1zjCEQT9sK/KIjs81z4XsJE=; b=NQzgnNsUBP5nvS+989N58ycEbktxPEYB77wfMzyRQKaZuHjgOPOmQQxJKBGllgmCZH pAOrA6NAptgsfatNiEb3beCftirdWjI5ro7oLMkvSjRFAhOCar2NAvStdI6LsSQT6jCu PhJEvIEruQh+AIy524USiGZjKDd/M4sumJbXDI+ANvAq2a1muHHVFx4slnFWxVRYbDE8 tDQQlt5fIJXUSwNtKnGPKqTNesKNRyf3toH9wROD7I/wjjrgt82OWbHi1NToPmjD1TZG +E5urBMPk31NOWJ7bMaYCtTEyKffQAC01oBOp8hF4bCMGQfHKPEX3QhlKp9avzsX3hWo +yUQ== X-Gm-Message-State: AOJu0Yxv6QjUlIEsKTXmE9S25z0QrlybpaY6v17mPh1u4UqsGqNNA22A sWNs0VFGEZpk7oH9u6AUbgk3uhf8Mbk= X-Google-Smtp-Source: AGHT+IGy1pbhRMP/k/z9rjPGElnCnmvyhP46CL1zn7HJHx3I5TIl4W0EN0aLWj5DGKtmmkk6kEZS6g== X-Received: by 2002:a05:6808:1709:b0:3bd:1ff9:b430 with SMTP id bc9-20020a056808170900b003bd1ff9b430mr894862oib.61.1704546767186; Sat, 06 Jan 2024 05:12:47 -0800 (PST) Original-Received: from localhost (58x12x133x161.ap58.ftth.ucom.ne.jp. [58.12.133.161]) by smtp.gmail.com with ESMTPSA id fd4-20020a056a002e8400b006daaf9d7856sm3008379pfb.219.2024.01.06.05.12.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jan 2024 05:12:46 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::22b; envelope-from=kobarity@gmail.com; helo=mail-oi1-x22b.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, T_SCC_BODY_TEXT_LINE=-0.01 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:277462 Archived-At: --Multipart_Sat_Jan__6_22:12:36_2024-1 Content-Type: text/plain; charset=US-ASCII Hi, No matter what the first line of the buffer is, if the second line is a string literal, `python-info-docstring-p` will misjudge it as a docstring. This issue can be reproduced as follows: 1. emacs -Q 2. Open a Python file whose contents are as follows: #+begin_src python import sys """Not a docstring.""" #+end_src 3. Locate the point at the string literal on the second line. 4. M-: (python-info-docstring-p) Although this string literal is not a docstring, it returns t. Therefore, in `python-mode` (not `python-ts-mode`), this string literal is rendered in `font-lock-doc-face`. This is the reason I changed some ERTs to "expected fail" in the commit b7b82ecb2b4c2ce33c11e5388b692cd403ab55e6 of Bug#63622. Attached is a patch to fix this bug and the above mentioned ERTs and to restore ERTs I deleted by mistake in commit 6b2c8dc9050c5c0514fa404733ce1d4a37d00e39 of Bug#63844 (related to Bug#63622). -- In GNU Emacs 30.0.50 (build 3, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw scroll bars) of 2024-01-03 built on ubuntu Repository revision: 91bc775b0c60342f118640001d2ce293d4f1f7ef Repository branch: master System Description: Ubuntu 22.04.3 LTS --Multipart_Sat_Jan__6_22:12:36_2024-1 Content-Type: application/octet-stream; type=patch; name="0001-Fix-python-info-docstring-p-bug-in-the-2nd-line-of-a.patch" Content-Disposition: attachment; filename="0001-Fix-python-info-docstring-p-bug-in-the-2nd-line-of-a.patch" Content-Transfer-Encoding: 7bit >From a292abf5ef41483df24323c36b0c97802df9d9d6 Mon Sep 17 00:00:00 2001 From: kobarity Date: Sat, 6 Jan 2024 22:04:42 +0900 Subject: [PATCH] Fix python-info-docstring-p bug in the 2nd line of a buffer * lisp/progmodes/python.el (python-info-docstring-p): Add looking-at-p check when bobp. * test/lisp/progmodes/python-tests.el (python-font-lock-operator-1) (python-font-lock-operator-2): Restoration of ERTs deleted by mistake. (python-font-lock-escape-sequence-bytes-newline) (python-font-lock-escape-sequence-hex-octal) (python-font-lock-escape-sequence-unicode) (python-font-lock-raw-escape-sequence): Change font-lock-doc-face to font-lock-string-face and remove :expected-result :failed. (python-info-docstring-p-8): New test. --- lisp/progmodes/python.el | 4 +- test/lisp/progmodes/python-tests.el | 73 ++++++++++++++++++++--------- 2 files changed, 53 insertions(+), 24 deletions(-) diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 1148da11a06..a44d4215d7c 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -6260,7 +6260,9 @@ python-info-docstring-p counter))) (python-util-forward-comment -1) (python-nav-beginning-of-statement) - (cond ((bobp)) + (cond ((and (bobp) (save-excursion + (python-util-forward-comment) + (looking-at-p re)))) ((python-info-assignment-statement-p) t) ((python-info-looking-at-beginning-of-defun)) (t nil)))))) diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el index 1df0c42a0ce..97ffd5fe20f 100644 --- a/test/lisp/progmodes/python-tests.el +++ b/test/lisp/progmodes/python-tests.el @@ -474,6 +474,28 @@ python-font-lock-assignment-statement-18 (136 . font-lock-operator-face) (137) (144 . font-lock-keyword-face) (150)))) +(ert-deftest python-font-lock-operator-1 () + (python-tests-assert-faces + "1 << 2 ** 3 == +4%-5|~6&7^8%9" + '((1) + (3 . font-lock-operator-face) (5) + (8 . font-lock-operator-face) (10) + (13 . font-lock-operator-face) (15) + (16 . font-lock-operator-face) (17) + (18 . font-lock-operator-face) (20) + (21 . font-lock-operator-face) (23) + (24 . font-lock-operator-face) (25) + (26 . font-lock-operator-face) (27) + (28 . font-lock-operator-face) (29)))) + +(ert-deftest python-font-lock-operator-2 () + "Keyword operators are font-locked as keywords." + (python-tests-assert-faces + "is_ is None" + '((1) + (5 . font-lock-keyword-face) (7) + (8 . font-lock-constant-face)))) + (ert-deftest python-font-lock-escape-sequence-string-newline () (python-tests-assert-faces "'\\n' @@ -585,62 +607,58 @@ python-font-lock-escape-sequence-multiline-string (845 . font-lock-string-face) (886)))) (ert-deftest python-font-lock-escape-sequence-bytes-newline () - :expected-result :failed (python-tests-assert-faces "b'\\n' b\"\\n\"" '((1) - (2 . font-lock-doc-face) + (2 . font-lock-string-face) (3 . font-lock-constant-face) - (5 . font-lock-doc-face) (6) - (8 . font-lock-doc-face) + (5 . font-lock-string-face) (6) + (8 . font-lock-string-face) (9 . font-lock-constant-face) - (11 . font-lock-doc-face)))) + (11 . font-lock-string-face)))) (ert-deftest python-font-lock-escape-sequence-hex-octal () - :expected-result :failed (python-tests-assert-faces "b'\\x12 \\777 \\1\\23' '\\x12 \\777 \\1\\23'" '((1) - (2 . font-lock-doc-face) + (2 . font-lock-string-face) (3 . font-lock-constant-face) - (7 . font-lock-doc-face) + (7 . font-lock-string-face) (8 . font-lock-constant-face) - (12 . font-lock-doc-face) + (12 . font-lock-string-face) (13 . font-lock-constant-face) - (18 . font-lock-doc-face) (19) - (20 . font-lock-doc-face) + (18 . font-lock-string-face) (19) + (20 . font-lock-string-face) (21 . font-lock-constant-face) - (25 . font-lock-doc-face) + (25 . font-lock-string-face) (26 . font-lock-constant-face) - (30 . font-lock-doc-face) + (30 . font-lock-string-face) (31 . font-lock-constant-face) - (36 . font-lock-doc-face)))) + (36 . font-lock-string-face)))) (ert-deftest python-font-lock-escape-sequence-unicode () - :expected-result :failed (python-tests-assert-faces "b'\\u1234 \\U00010348 \\N{Plus-Minus Sign}' '\\u1234 \\U00010348 \\N{Plus-Minus Sign}'" '((1) - (2 . font-lock-doc-face) (41) - (42 . font-lock-doc-face) + (2 . font-lock-string-face) (41) + (42 . font-lock-string-face) (43 . font-lock-constant-face) - (49 . font-lock-doc-face) + (49 . font-lock-string-face) (50 . font-lock-constant-face) - (60 . font-lock-doc-face) + (60 . font-lock-string-face) (61 . font-lock-constant-face) - (80 . font-lock-doc-face)))) + (80 . font-lock-string-face)))) (ert-deftest python-font-lock-raw-escape-sequence () - :expected-result :failed (python-tests-assert-faces "rb'\\x12 \123 \\n' r'\\x12 \123 \\n \\u1234 \\U00010348 \\N{Plus-Minus Sign}'" '((1) - (3 . font-lock-doc-face) (14) - (16 . font-lock-doc-face)))) + (3 . font-lock-string-face) (14) + (16 . font-lock-string-face)))) ;;; Indentation @@ -6647,6 +6665,15 @@ python-info-docstring-p-7 (python-tests-look-at "Also not a docstring") (should-not (python-info-docstring-p)))) +(ert-deftest python-info-docstring-p-8 () + "Test string in the 2nd line of a buffer." + (python-tests-with-temp-buffer + "import sys +'''Not a docstring.''' +" + (python-tests-look-at "Not a docstring") + (should-not (python-info-docstring-p)))) + (ert-deftest python-info-triple-quoted-string-p-1 () "Test triple quoted string." (python-tests-with-temp-buffer -- 2.34.1 --Multipart_Sat_Jan__6_22:12:36_2024-1--