From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Wilhelm H Kirschbaum Newsgroups: gmane.emacs.bugs Subject: bug#60256: 29.0.60; Maybe improve tree sitter default treesit-language-at function Date: Thu, 22 Dec 2022 12:30:09 +0200 Message-ID: <87h6xnenhl.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; format=flowed Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5398"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.9.3; emacs 29.0.60 To: 60256@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Dec 22 11:37:38 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 1p8IxF-0001BS-PR for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 22 Dec 2022 11:37:37 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p8Iuo-00067I-Vw; Thu, 22 Dec 2022 05:35:07 -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 1p8Iul-00066U-Eb for bug-gnu-emacs@gnu.org; Thu, 22 Dec 2022 05:35:04 -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 1p8Iul-0004HW-2d for bug-gnu-emacs@gnu.org; Thu, 22 Dec 2022 05:35:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p8Iuk-0005j4-NJ for bug-gnu-emacs@gnu.org; Thu, 22 Dec 2022 05:35:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Wilhelm H Kirschbaum Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 22 Dec 2022 10:35:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 60256 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.167170524921976 (code B ref -1); Thu, 22 Dec 2022 10:35:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 22 Dec 2022 10:34:09 +0000 Original-Received: from localhost ([127.0.0.1]:57554 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p8Its-0005iO-L1 for submit@debbugs.gnu.org; Thu, 22 Dec 2022 05:34:09 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:44904) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p8Itq-0005iI-Gi for submit@debbugs.gnu.org; Thu, 22 Dec 2022 05:34:07 -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 1p8Itp-0005pm-Uv for bug-gnu-emacs@gnu.org; Thu, 22 Dec 2022 05:34:06 -0500 Original-Received: from mail-wm1-x336.google.com ([2a00:1450:4864:20::336]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p8Ito-0004DH-Ab for bug-gnu-emacs@gnu.org; Thu, 22 Dec 2022 05:34:05 -0500 Original-Received: by mail-wm1-x336.google.com with SMTP id m19so1077961wms.5 for ; Thu, 22 Dec 2022 02:34:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=floatpays.co.za; s=google; h=mime-version:message-id:date:subject:to:user-agent:from:from:to:cc :subject:date:message-id:reply-to; bh=1OKogxL7PDRwfpCbmGQoOxMFLjFUM2piF3671XkNOqY=; b=OiclP1CFDNDwlT74HoBopxJRylMHQHQqtCCbgmZ37CSiPnBY9ycTlbVf2jB0mTSFJS Sm5tcgYhV304Ckbj49SRnoafDZYZrx2PmQW8YGrcOgjFAYAldEuV6N8oRzfjDZCdzw8o 3/5j5ZIFXIJ/uS+hrB7CTzfZosBNjsUYqGos8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:subject:to:user-agent:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1OKogxL7PDRwfpCbmGQoOxMFLjFUM2piF3671XkNOqY=; b=uJgi4ZPaUB1x1bcCtG/B+J7Ksd8HHU7hA/hbZPaCuE6JAFmM26D1JSK54EJZnhSaHC kWb/xoi+PhFk1fbG/GMvYjX07LDsiOuSXwBH/rYzvp/e2c03QJs1JIp4UW73hwZznpV8 5v0MjKZNcQgMi/1IHt2l/jqjs4TsSy5MFtFXUe3rVUbwT7gO0HOXXxyKXNE6+bbMCGCQ 1F8cG5OyzVf3+b4wV0XY/pu8xcvNohSSy0UO4yKqdfQzqhOcauwhbnA6DN1Jt7NhQkT2 QQSrNbSXkQHXM17gak/ksokJ51MdQPDaWgLc/7j3G41UUgvNem58kKvg5baLYe23VrtG I5tg== X-Gm-Message-State: AFqh2kqC60NheCqzVdZOsEqiBW2KTpjgPh80y07SnBO+Ir+qiuJSTeLx AncdlQmIBSSBtyg+gP5hCnFZutoCt+54RD6P X-Google-Smtp-Source: AMrXdXv6MDLKWfVS3estSW6MgaBX3ZJN0GvZ+HVO3gFj/gpSKhNVurXUtJotvi/lLqqYU3D2nXMSNg== X-Received: by 2002:a05:600c:4fd4:b0:3d3:4877:e556 with SMTP id o20-20020a05600c4fd400b003d34877e556mr4080866wmq.29.1671705241811; Thu, 22 Dec 2022 02:34:01 -0800 (PST) Original-Received: from melissa.local ([2c0f:ef18:1431:0:b09:9616:db04:c248]) by smtp.gmail.com with ESMTPSA id i9-20020a05600c354900b003d33ab317dasm798572wmq.14.2022.12.22.02.34.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 02:34:01 -0800 (PST) X-Google-Original-From: Wilhelm H Kirschbaum Received-SPF: pass client-ip=2a00:1450:4864:20::336; envelope-from=wilhelm@floatpays.co.za; helo=mail-wm1-x336.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, 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:251663 Archived-At: We can detect the language from treesit-parser-included-ranges, so instead of taking the first parser from the list what about taking the first parser within known ranges? diff --git a/lisp/treesit.el b/lisp/treesit.el index 6407669118..f08bb1cd40 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -136,8 +136,20 @@ treesit-language-at parser in `treesit-parser-list', or nil if there is no parser." (if treesit-language-at-point-function (funcall treesit-language-at-point-function position) - (when-let ((parser (car (treesit-parser-list)))) - (treesit-parser-language parser)))) + (let ((language-in-range + (cl-loop + for parser in (treesit-parser-list) + do (setq range + (cl-loop + for range in (treesit-parser-included-ranges parser) + if (and (>= point (car range)) (<= point (cdr range))) + return parser)) + if range + return (treesit-parser-language parser)))) + (if (null language-in-range) + (when-let ((parser (car (treesit-parser-list)))) + (treesit-parser-language parser)) + language-in-range)))) Maybe there is a better way of doing this, but seems like it can be generic enough to make this work without having to set treesit-language-at-point-function for the majority of the cases. Wilhelm