From: "Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 60049@debbugs.gnu.org
Subject: bug#60049: [PATCH] Add < and > to the syntax table in c++-ts-mode
Date: Tue, 13 Dec 2022 22:39:36 +0100 [thread overview]
Message-ID: <m17cyv6l0n.fsf@yahoo.es> (raw)
In-Reply-To: m17cyv6l0n.fsf.ref@yahoo.es
[-- Attachment #1: Type: text/plain, Size: 510 bytes --]
Tags: patch
Given the following C++ code (where "|" represents the point):
|Expected<int> getFoo();
If you press C-M-d when c++-ts-mode is enabled, point moves to:
Expected<int> getFoo(|);
In c++-mode, point moves (correctly) to:
Expected<|int> getFoo();
Also, show-paren-mode does not highlight any <> pairs in c++-ts-mode.
My proposed fix is to create a syntax table for c++-ts-mode and add "<"
and ">" to it as open/close delimiters.
The attached patch implements the proposed solution. Thanks.
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-and-to-the-syntax-table-in-c-ts-mode.patch --]
[-- Type: text/patch, Size: 1463 bytes --]
From 868322dae6a881792c5601615c8d11b4181e7424 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Mart=C3=ADn?= <mardani29@yahoo.es>
Date: Tue, 13 Dec 2022 22:28:13 +0100
Subject: [PATCH] Add < and > to the syntax table in c++-ts-mode
* lisp/progmodes/c-ts-mode.el (c++-ts-mode--syntax-table): Add a
specific syntax table for C++. Consider "<" and ">" open/close
delimiters (C++ templates).
(c++-ts-mode): Use the new syntax table.
---
lisp/progmodes/c-ts-mode.el | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/lisp/progmodes/c-ts-mode.el b/lisp/progmodes/c-ts-mode.el
index 8407be3b6b..31c22dc321 100644
--- a/lisp/progmodes/c-ts-mode.el
+++ b/lisp/progmodes/c-ts-mode.el
@@ -83,6 +83,14 @@ c-ts-mode--syntax-table
table)
"Syntax table for `c-ts-mode'.")
+(defvar c++-ts-mode--syntax-table
+ (let ((table (make-syntax-table c-ts-mode--syntax-table)))
+ ;; Template delimiters.
+ (modify-syntax-entry ?< "(" table)
+ (modify-syntax-entry ?> ")" table)
+ table)
+ "Syntax table for `c++-ts-mode'.")
+
(defun c-ts-mode--indent-styles (mode)
"Indent rules supported by `c-ts-mode'.
MODE is either `c' or `cpp'."
@@ -615,6 +623,7 @@ c-ts-mode
(define-derived-mode c++-ts-mode c-ts-base-mode "C++"
"Major mode for editing C++, powered by tree-sitter."
:group 'c++
+ :syntax-table c++-ts-mode--syntax-table
(unless (treesit-ready-p 'cpp)
(error "Tree-sitter for C++ isn't available"))
--
2.34.1
next parent reply other threads:[~2022-12-13 21:39 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <m17cyv6l0n.fsf.ref@yahoo.es>
2022-12-13 21:39 ` Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-12-14 2:10 ` bug#60049: [PATCH] Add < and > to the syntax table in c++-ts-mode Yuan Fu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m17cyv6l0n.fsf@yahoo.es \
--to=bug-gnu-emacs@gnu.org \
--cc=60049@debbugs.gnu.org \
--cc=mardani29@yahoo.es \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).