From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuan Fu Newsgroups: gmane.emacs.bugs Subject: bug#59534: 29.0.50; Improvement for treesit in python. Date: Thu, 24 Nov 2022 10:29:47 -0800 Message-ID: References: <51760046-6AB8-4161-A95E-F090AC680116@gmail.com> Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7817"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 59534@debbugs.gnu.org To: nasyxx@gmail.com Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 24 19:30:13 2022 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 1oyGzE-0001ok-TM for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 24 Nov 2022 19:30:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oyGz8-0006ah-Ku; Thu, 24 Nov 2022 13:30:06 -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 1oyGz5-0006ZX-CT for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 13:30:03 -0500 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 1oyGz5-0008DW-1b for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 13:30:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oyGz4-00070L-Ss for bug-gnu-emacs@gnu.org; Thu, 24 Nov 2022 13:30:02 -0500 X-Loop: help-debbugs@gnu.org In-Reply-To: <51760046-6AB8-4161-A95E-F090AC680116@gmail.com> Resent-From: Yuan Fu Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 24 Nov 2022 18:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 59534 X-GNU-PR-Package: emacs Original-Received: via spool by 59534-submit@debbugs.gnu.org id=B59534.166931459626801 (code B ref 59534); Thu, 24 Nov 2022 18:30:02 +0000 Original-Received: (at 59534) by debbugs.gnu.org; 24 Nov 2022 18:29:56 +0000 Original-Received: from localhost ([127.0.0.1]:60092 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyGyx-0006yB-UQ for submit@debbugs.gnu.org; Thu, 24 Nov 2022 13:29:56 -0500 Original-Received: from mail-pj1-f53.google.com ([209.85.216.53]:50709) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oyGyw-0006y0-VU for 59534@debbugs.gnu.org; Thu, 24 Nov 2022 13:29:55 -0500 Original-Received: by mail-pj1-f53.google.com with SMTP id mv18so1961292pjb.0 for <59534@debbugs.gnu.org>; Thu, 24 Nov 2022 10:29:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:from:to:cc:subject:date:message-id :reply-to; bh=rmHV4ZEZGUuudT6c8FVFGy3ResvuEAowJ6s8jEA3cRA=; b=qCrRUPoTmp0S4Yn8Ffhq7Nxd/AuxtlbMecR6CnsXzCGqe/y9Sy3t5mWcoq0VefE+Au RZdol/AxN6VUobJnwb712Yy2da3+IYilcx0rZYLo9yvuHgfA9lcKA+Vb1Lq2ogiWfZED 73sE1LjtjfpKucPZvpuX29BMu0Dn1tjWojfGScbUSEs6+DEXBJJF+UFSgT+LAtV+t8kz oAezULRMxi6zU++b8bYHybFt2lntFV5EBI2iri1bdbQTbQsaBAyM17VoxsexhCoUbL5N 16aVqVSnzzxRy+4nkY8KSueUIW3qnfdpwCZm9O7ctqDfItNOQoG+xQ6qfWsRH7vJ/Pvm Q4zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:cc:date:message-id:subject:mime-version :content-transfer-encoding:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rmHV4ZEZGUuudT6c8FVFGy3ResvuEAowJ6s8jEA3cRA=; b=P1usgNA2DmZnwxm1TQnS9/JM49wUku+ouvGa/X6Va1SV2bnPcH4ytEZvhJMkQFdpWg 65fDS0ye2GwZqNXJG2n8CspjZih6RGlepj2OaZl59ipPjqLr8S1R9iu+bvet2EdT2C2M b7Q0V8I52HIpFIAQ7l/MY5dlBMO3XF+by5NLCRS9c74H6ZqbtY60AABuou+1WW2aUB/r t6xepCuG6sz+hYMETzCoeBoqfERMkFAF5ewJHiOscCywtj3qMDV7A2vWa9KdcXvLcUX2 hJQ+Rb1BaDToYgiorZ2eSDlSL6WiLzcyjD7iQiS28AUxOOVfCgMj4YTy4yu/5i5YsozL CavA== X-Gm-Message-State: ANoB5pnLLXAdpOxHcQBvjte/ZIjXtUz6ql6XlKxbCG4yCDOXqEZRLZnX xtImMqu8sNaiop1BtFdi0pc= X-Google-Smtp-Source: AA0mqf5G7hDFRRGtBnbb9ggbDhJUl9IykHCG//4gsY6M8UBbdzyUo+vrL6b9aETgy81VhXnwP97MWg== X-Received: by 2002:a17:903:2616:b0:189:57f1:b8ec with SMTP id jd22-20020a170903261600b0018957f1b8ecmr5043577plb.4.1669314589010; Thu, 24 Nov 2022 10:29:49 -0800 (PST) Original-Received: from smtpclient.apple (cpe-172-117-161-177.socal.res.rr.com. [172.117.161.177]) by smtp.gmail.com with ESMTPSA id u11-20020a17090341cb00b00186b55e3cd6sm1668149ple.133.2022.11.24.10.29.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Nov 2022 10:29:48 -0800 (PST) X-Mailer: Apple Mail (2.3696.120.41.1.1) 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:248889 Archived-At: Nasy writes: > Hi, > > 1. Operators > > Python added "@" and "@=" as operators in version 3.5 and ":=" in > version 3.8. So I guess these three should be in the > =python--treesit-operators=. Thanks! I added them. > 2. Doc strings > > Treesit does not consider the content inside the triple quotes at the > beginning of the Python file to be the documents. > > For example, lines 2-4 of this file > https://github.com/python/cpython/blob/main/Lib/csv.py#L2-L4 > > """ > csv.py - read/write/investigate CSV files > """ > > It be fontify as string instead of doc. > > I changed this function to recognize the outermost single string as the > doc string. > > (defun python--treesit-fontify-string (node override start end &rest _) > "Fontify string. > NODE is the string node. Do not fontify the initial f for > f-strings. OVERRIDE is the override flag described in > `treesit-font-lock-rules'. START and END mark the region to be > fontified." > (let* ((string-beg (treesit-node-start node)) > (string-end (treesit-node-end node)) > (maybe-expression (treesit-node-parent node)) > (maybe-defun (treesit-node-parent > (treesit-node-parent > maybe-expression))) > (face (if (and (member (treesit-node-type maybe-defun) > '("function_definition" > - "class_definition")) > + "class_definition" > + nil)) > ;; This check filters out this case: > ;; def function(): > ;; return "some string" > (equal (treesit-node-type maybe-expression) > "expression_statement")) > 'font-lock-doc-face > 'font-lock-string-face))) > (when (eq (char-after string-beg) ?f) > (cl-incf string-beg)) > (treesit-fontify-with-override > (max start string-beg) (min end string-end) face override))) > > I'm not familiar with treesit, this solution could not be the best, but > I don't know if there is any other simple way to improve it. Maybe we > could use something like =python-info-docstring-p= to check if it is doc > or net. I added something similar to the function. Now it will highlight the string in doc-face if there is nothing or only comments before it. Yuan