From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Kangas Newsgroups: gmane.emacs.bugs Subject: bug#73877: 30; rust-ts-mode: highlight the possible type suffix of number literals Date: Sun, 20 Oct 2024 05:00:07 -0700 Message-ID: References: <874j587459.fsf@poincare.umons.ac.be> 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="17174"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Randy Taylor To: Christophe TROESTLER , 73877@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Oct 20 14:02:08 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 1t2UdM-0004K8-Ku for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 20 Oct 2024 14:02:08 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t2Uct-0008PW-Hu; Sun, 20 Oct 2024 08:01:39 -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 1t2Ucr-0008P4-F9 for bug-gnu-emacs@gnu.org; Sun, 20 Oct 2024 08:01:37 -0400 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 1t2Ucr-0006pc-6e for bug-gnu-emacs@gnu.org; Sun, 20 Oct 2024 08:01:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=Date:MIME-Version:References:In-Reply-To:From:To:Subject; bh=6C4x5E0ggTntNGHJfoeb2e7kMdi3/4ObJtYHoEMynRI=; b=KbPP//jq8N6PMo16pjMW7MrSyr9k4N7xW8RI5oByeukXW6ZnydwrTyFTUwkQj5wNDvZWywcskIdAbQn/G2mwtBepPHbNFyYiROg3rE+Cfge9+b9IKch/8AcTech46yzoqLYWKFGLkcN3S/XKYQvR4z8cmyk9bcFz4H5EDKpwx57dGzDYqTN90S5gsZr6kDn8C1sl1k04uGvT0WBxw7qWD0sBGu1Ew9ZcfK+qzw4PXa3tgdr6N9BiKFtnLZRF0RL+1+qB7xgEh2nteDsgMshkJtrefoJh21cBiapYIuG5zUJZCHiuRHvg6r3fIUTD/6M5UJdB5g7jHUroOYPCu1u13Q==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t2UdG-0003j9-5m for bug-gnu-emacs@gnu.org; Sun, 20 Oct 2024 08:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 20 Oct 2024 12:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73877 X-GNU-PR-Package: emacs Original-Received: via spool by 73877-submit@debbugs.gnu.org id=B73877.172942570014280 (code B ref 73877); Sun, 20 Oct 2024 12:02:02 +0000 Original-Received: (at 73877) by debbugs.gnu.org; 20 Oct 2024 12:01:40 +0000 Original-Received: from localhost ([127.0.0.1]:46188 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t2Ucu-0003iF-9A for submit@debbugs.gnu.org; Sun, 20 Oct 2024 08:01:40 -0400 Original-Received: from mail-ej1-f51.google.com ([209.85.218.51]:58713) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t2Ucs-0003i1-EG for 73877@debbugs.gnu.org; Sun, 20 Oct 2024 08:01:39 -0400 Original-Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a99c0beaaa2so590025266b.1 for <73877@debbugs.gnu.org>; Sun, 20 Oct 2024 05:01:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729425607; x=1730030407; darn=debbugs.gnu.org; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:from:to:cc:subject:date:message-id:reply-to; bh=6C4x5E0ggTntNGHJfoeb2e7kMdi3/4ObJtYHoEMynRI=; b=LAC4/TDPRyGLZlz6yK5mvqNw1AovpxjrQ7dnff99y5CxGL3ZMH3NdHxR5TCK9bNa8X 5P+4vuhIjdE/S2PEEG3Y1j+ZQLYjCl8ZfPAee33KkN63e/qg94eDvw8hEixqxii2InJK ZKoMsgfJxjLuPDSQPCOpwRgHhVNXS8QVggfy1i50WJQa80unI4KVCRBMxeDKmqk17DzY u+5SzW86dUSGbIEzVWl1i5mceOV6G94VZel6B34zHdMjY3daOi1B+W88G4VZSqtHQ8y0 OMuzomjMIsuKv2VzUa99D5pR1rjcT5vBwKz44l7X8jV4xXkSk2eOLdYA8jkOSrI1zNnc KLvg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729425607; x=1730030407; h=cc:to:subject:message-id:date:mime-version:references:in-reply-to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=6C4x5E0ggTntNGHJfoeb2e7kMdi3/4ObJtYHoEMynRI=; b=tzTmLHQ1OA/Sph+VHEkMYCfPsaxYZg4AETNLi3Xfy2aAhzC1V0FSyQmo0o8yWaLLZ0 100qL3v55cPEHEWdYZR4F3NRwSCGrxlaUx/TviduPS0nDSAbktwx0CZLHW1I2Q1asPIE Ujs5DLg0u+H4aYxOSZjV21TR4QGA1N5z7dFGvQhmwyGnDFS+2D83y1UV5Gru2Kh6YDiI xeEPTq4019yhvMn7GDEdrUDlZCg05vKuMY/cijhOykO9j1juPU+4PTF97VPig4XFEs4i IuU3T9K7hFPIvFRDzGHQ0rUrNv9hpsER44Rsv3o5gvhzoVONeWkg0dZPGIaWxDN+6fdV hryA== X-Forwarded-Encrypted: i=1; AJvYcCU0/WF2P41WeMrq81YKvG3quU6ObdWFvyVBG8HwZU/vSl2dT8/0BZFWBm1m0hd0AdWaLsrIMQ==@debbugs.gnu.org X-Gm-Message-State: AOJu0YwYZEROv2ZBLrJSI6Kf6BLdwTiVSN0ve0BHeUraQ1aTdxwJ3AHw bftr3huO/SGDSmZDVBoKCekNaljCaCkl36gMlk9DDED5rP/W2ON8o+t+e3GszToLJxpUnri87oP wPAaAjI340FLaTu87tfRjBA14vhk= X-Google-Smtp-Source: AGHT+IGer7FcTgpPL82W9y+9uYlhBm4lePOrrrIfubfHQMa0s5QFYxPMh6/C5HbbDnYRuUx1P8D+owuhYi26Lame0BI= X-Received: by 2002:a17:907:a4e:b0:a99:f972:7544 with SMTP id a640c23a62f3a-a9a69bafefcmr826899766b.38.1729425607353; Sun, 20 Oct 2024 05:00:07 -0700 (PDT) Original-Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sun, 20 Oct 2024 05:00:07 -0700 In-Reply-To: <874j587459.fsf@poincare.umons.ac.be> 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:293953 Archived-At: Christophe TROESTLER writes: > Hi, > > In order to make Rust number literals such as 1usize, 1.0_f64,... more legible, the type suffix should be highlighted. The attached patch to rust-ts-mode does that. > > Best, > Christophe Thanks. Randy, do you have any comments on the below patch? > From e1cf2f8c59f2abd75688721d08653327c5427da9 Mon Sep 17 00:00:00 2001 > From: Christophe Troestler > Date: Fri, 18 Oct 2024 23:50:06 +0200 > Subject: [PATCH] rust-ts-mode: highlight the possible type suffix of number > literals > Content-Type: text/plain; charset="utf-8" > > --- > lisp/progmodes/rust-ts-mode.el | 25 ++++++++++++++++++++++++- > 1 file changed, 24 insertions(+), 1 deletion(-) > > diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el > index 571ffa9b220..0454c46261f 100644 > --- a/lisp/progmodes/rust-ts-mode.el > +++ b/lisp/progmodes/rust-ts-mode.el > @@ -116,6 +116,12 @@ rust-ts-mode--indent-rules > ((parent-is "use_list") parent-bol rust-ts-mode-indent-offset))) > "Tree-sitter indent rules for `rust-ts-mode'.") > > +(defconst rust-ts-mode--number-types > + (regexp-opt '("u8" "i8" "u16" "i16" "u32" "i32" "u64" > + "i64" "u128" "i128" "usize" "isize" "f32" "f64")) > + "Regexp that matches any suffix on number litterals as documented > +at https://doc.rust-lang.org/reference/tokens.html#suffixes") > + > (defvar rust-ts-mode--builtin-macros > '("concat_bytes" "concat_idents" "const_format_args" > "format_args_nl" "log_syntax" "trace_macros" "assert" "assert_eq" > @@ -221,7 +227,8 @@ rust-ts-mode--font-lock-settings > > :language 'rust > :feature 'number > - '([(float_literal) (integer_literal)] @font-lock-number-face) > + '([(float_literal) (integer_literal)] > + @rust-ts-mode--fontify-number-literal) > > :language 'rust > :feature 'operator > @@ -365,6 +372,22 @@ 'rust-ts-mode--fontify-pattern > (treesit-node-start id) (treesit-node-end id) > 'font-lock-variable-name-face override start end))))))) > > +(defun rust-ts-mode--fontify-number-literal (node override start stop &rest _) > + "Fontify number literals, highlighting the optional type if present" > + (let* ((beg (treesit-node-start node)) > + (end (treesit-node-end node))) > + (save-excursion > + (goto-char end) > + (if (looking-back rust-ts-mode--number-types beg) > + (let* ((ty (match-beginning 0)) > + (nb (if (eq (char-before ty) ?_) (1- ty) ty))) > + (treesit-fontify-with-override > + ty end 'font-lock-type-face override start stop) > + (treesit-fontify-with-override > + beg nb 'font-lock-number-face override start stop)) > + (treesit-fontify-with-override > + beg end 'font-lock-number-face override start stop))))) > + > (defun rust-ts-mode--defun-name (node) > "Return the defun name of NODE. > Return nil if there is no name or if NODE is not a defun node." > -- > 2.45.2