emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

feature/tree-sitter 08a1c32d0b 02/15: Improve printing treesit nodes


From: Yuan Fu
Subject: feature/tree-sitter 08a1c32d0b 02/15: Improve printing treesit nodes
Date: Sun, 25 Sep 2022 00:11:59 -0400 (EDT)

branch: feature/tree-sitter
commit 08a1c32d0bcaa9369a34e7f7d6d01c3885f62e21
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Improve printing treesit nodes
    
    * src/print.c (print_vectorlike): Instead of position, print the type
    of the node.
---
 src/print.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/print.c b/src/print.c
index 12b5087435..4f41448d86 100644
--- a/src/print.c
+++ b/src/print.c
@@ -2024,12 +2024,15 @@ print_vectorlike (Lisp_Object obj, Lisp_Object 
printcharfun, bool escapeflag,
       printchar ('>', printcharfun);
       break;
     case PVEC_TS_NODE:
-      print_c_string ("#<treesit-node from ", printcharfun);
-      print_object (Ftreesit_node_start (obj),
-                   printcharfun, escapeflag);
-      print_c_string (" to ", printcharfun);
-      print_object (Ftreesit_node_end (obj),
-                   printcharfun, escapeflag);
+      /* Prints #<treesit-node (identifier) in #<buffer xxx>> or
+         #<treesit-node "keyword" in #<buffer xxx>>. */
+      print_c_string ("#<treesit-node ", printcharfun);
+      bool named = ts_node_is_named (XTS_NODE (obj)->node);
+      const char *delim1 = named ? "(" : "\"";
+      const char *delim2 = named ? ")" : "\"";
+      print_c_string (delim1, printcharfun);
+      print_string (Ftreesit_node_type (obj), printcharfun);
+      print_c_string (delim2, printcharfun);
       print_c_string (" in ", printcharfun);
       print_object (XTS_PARSER (XTS_NODE (obj)->parser)->buffer,
                    printcharfun, escapeflag);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]