* Add prettify configuration to the rust-ts-mode
@ 2023-09-11 14:24 Christophe TROESTLER
2023-09-12 0:15 ` Yuan Fu
2023-09-17 9:58 ` Eli Zaretskii
0 siblings, 2 replies; 4+ messages in thread
From: Christophe TROESTLER @ 2023-09-11 14:24 UTC (permalink / raw)
To: emacs-devel@gnu.org
[-- Attachment #1: Type: text/plain, Size: 236 bytes --]
Hi,
I noticed that the rust-ts-mode does not have a configuration for the prettify-symbols-mode. The attached patch aims to add that.
On another note, is it planned to have compile support for Rust?
Best regards,
Christophe
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-prettify-configuration-to-rust-ts-mode.patch --]
[-- Type: text/x-diff; name="0001-Add-prettify-configuration-to-rust-ts-mode.patch", Size: 2470 bytes --]
From b9d3549810465aae90c5917b943e0393d6519485 Mon Sep 17 00:00:00 2001
From: Christophe Troestler <Christophe.Troestler@umons.ac.be>
Date: Mon, 11 Sep 2023 15:32:57 +0200
Subject: [PATCH] Add prettify configuration to rust-ts-mode
Content-Type: text/plain; charset="utf-8"
* lisp/progmodes/rust-ts-mode.el: Add prettify configuration to the mode.
---
lisp/progmodes/rust-ts-mode.el | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/lisp/progmodes/rust-ts-mode.el b/lisp/progmodes/rust-ts-mode.el
index 999c1d7ae96..88344934e49 100644
--- a/lisp/progmodes/rust-ts-mode.el
+++ b/lisp/progmodes/rust-ts-mode.el
@@ -48,6 +48,12 @@ rust-ts-mode-indent-offset
:safe 'integerp
:group 'rust)
+(defvar rust-ts-mode-prettify-symbols-alist
+ '(("&&" . ?∧) ("||" . ?∨)
+ ("<=" . ?≤) (">=" . ?≥) ("!=" . ?≠)
+ ("INFINITY" . ?∞) ("->" . ?→) ("=>" . ?⇒))
+ "Value for `prettify-symbols-alist' in `rust-ts-mode'.")
+
(defvar rust-ts-mode--syntax-table
(let ((table (make-syntax-table)))
(modify-syntax-entry ?+ "." table)
@@ -386,6 +392,19 @@ rust-ts-mode--syntax-propertize
(?< '(4 . ?>))
(?> '(5 . ?<))))))))
+(defun rust-ts-mode--prettify-symbols-compose-p (start end match)
+ "Return true iff the symbol MATCH should be composed.
+See `prettify-symbols-compose-predicate'."
+ (and (fboundp 'prettify-symbols-default-compose-p)
+ (prettify-symbols-default-compose-p start end match)
+ ;; Make sure || is not a closure with 0 arguments and && is not
+ ;; a double reference.
+ (pcase match
+ ((or "||" "&&")
+ (string= (treesit-node-field-name (treesit-node-at (point)))
+ "operator"))
+ (_ t))))
+
;;;###autoload
(define-derived-mode rust-ts-mode prog-mode "Rust"
"Major mode for editing Rust, powered by tree-sitter."
@@ -411,6 +430,11 @@ rust-ts-mode
number type)
( bracket delimiter error function operator property variable)))
+ ;; Prettify configuration
+ (setq prettify-symbols-alist rust-ts-mode-prettify-symbols-alist)
+ (setq prettify-symbols-compose-predicate
+ #'rust-ts-mode--prettify-symbols-compose-p)
+
;; Imenu.
(setq-local treesit-simple-imenu-settings
`(("Module" "\\`mod_item\\'" nil nil)
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: Add prettify configuration to the rust-ts-mode
2023-09-11 14:24 Add prettify configuration to the rust-ts-mode Christophe TROESTLER
@ 2023-09-12 0:15 ` Yuan Fu
2023-09-12 2:34 ` Eli Zaretskii
2023-09-17 9:58 ` Eli Zaretskii
1 sibling, 1 reply; 4+ messages in thread
From: Yuan Fu @ 2023-09-12 0:15 UTC (permalink / raw)
To: Christophe TROESTLER; +Cc: emacs-devel@gnu.org
> On Sep 11, 2023, at 7:24 AM, Christophe TROESTLER <Christophe.TROESTLER@umons.ac.be> wrote:
>
> Hi,
>
> I noticed that the rust-ts-mode does not have a configuration for the prettify-symbols-mode. The attached patch aims to add that.
Thanks! Have you signed the copyright assignment?
>
> On another note, is it planned to have compile support for Rust?
Yes, any useful feature is welcome.
Yuan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Add prettify configuration to the rust-ts-mode
2023-09-12 0:15 ` Yuan Fu
@ 2023-09-12 2:34 ` Eli Zaretskii
0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2023-09-12 2:34 UTC (permalink / raw)
To: Yuan Fu; +Cc: Christophe.TROESTLER, emacs-devel
> From: Yuan Fu <casouri@gmail.com>
> Date: Mon, 11 Sep 2023 17:15:17 -0700
> Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
>
>
>
> > On Sep 11, 2023, at 7:24 AM, Christophe TROESTLER <Christophe.TROESTLER@umons.ac.be> wrote:
> >
> > Hi,
> >
> > I noticed that the rust-ts-mode does not have a configuration for the prettify-symbols-mode. The attached patch aims to add that.
>
> Thanks! Have you signed the copyright assignment?
Yes, Christophe's assignment is on file.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Add prettify configuration to the rust-ts-mode
2023-09-11 14:24 Add prettify configuration to the rust-ts-mode Christophe TROESTLER
2023-09-12 0:15 ` Yuan Fu
@ 2023-09-17 9:58 ` Eli Zaretskii
1 sibling, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2023-09-17 9:58 UTC (permalink / raw)
To: Christophe TROESTLER; +Cc: emacs-devel
> From: Christophe TROESTLER <Christophe.TROESTLER@umons.ac.be>
> Date: Mon, 11 Sep 2023 14:24:59 +0000
>
> I noticed that the rust-ts-mode does not have a configuration for the prettify-symbols-mode. The attached patch aims to add that.
Thanks, installed on the master branch.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-09-17 9:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-09-11 14:24 Add prettify configuration to the rust-ts-mode Christophe TROESTLER
2023-09-12 0:15 ` Yuan Fu
2023-09-12 2:34 ` Eli Zaretskii
2023-09-17 9:58 ` Eli Zaretskii
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).