unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60049: [PATCH] Add < and > to the syntax table in c++-ts-mode
       [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
  2022-12-14  2:10   ` Yuan Fu
  0 siblings, 1 reply; 2+ messages in thread
From: Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2022-12-13 21:39 UTC (permalink / raw)
  To: 60049

[-- 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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#60049: [PATCH] Add < and > to the syntax table in c++-ts-mode
  2022-12-13 21:39 ` bug#60049: [PATCH] Add < and > to the syntax table in c++-ts-mode Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
@ 2022-12-14  2:10   ` Yuan Fu
  0 siblings, 0 replies; 2+ messages in thread
From: Yuan Fu @ 2022-12-14  2:10 UTC (permalink / raw)
  To: Daniel Martín; +Cc: 60049-done


Daniel Martín <mardani29@yahoo.es> writes:

> 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.

Applied, thanks!

Yuan





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-14  2:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <m17cyv6l0n.fsf.ref@yahoo.es>
2022-12-13 21:39 ` bug#60049: [PATCH] Add < and > to the syntax table in c++-ts-mode Daniel Martín via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-14  2:10   ` Yuan Fu

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).