emacs-diffs
[Top][All Lists]
Advanced

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

feature/tree-sitter 1575ee2eeb 07/15: Accept nil as NODE in treesit-node


From: Yuan Fu
Subject: feature/tree-sitter 1575ee2eeb 07/15: Accept nil as NODE in treesit-node-text
Date: Sun, 25 Sep 2022 00:11:59 -0400 (EDT)

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

    Accept nil as NODE in treesit-node-text
    
    * lisp/treesit.el (treesit-node-text): Just wrap function body
    in (when ...).
---
 lisp/treesit.el | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/lisp/treesit.el b/lisp/treesit.el
index 9750ac7b7b..28a74657f9 100644
--- a/lisp/treesit.el
+++ b/lisp/treesit.el
@@ -172,14 +172,15 @@ NAMED non-nil, only search for named node."
 (defun treesit-node-text (node &optional no-property)
   "Return the buffer (or string) content corresponding to NODE.
 If NO-PROPERTY is non-nil, remove text properties."
-  (with-current-buffer (treesit-node-buffer node)
-    (if no-property
-        (buffer-substring-no-properties
+  (when node
+    (with-current-buffer (treesit-node-buffer node)
+      (if no-property
+          (buffer-substring-no-properties
+           (treesit-node-start node)
+           (treesit-node-end node))
+        (buffer-substring
          (treesit-node-start node)
-         (treesit-node-end node))
-      (buffer-substring
-       (treesit-node-start node)
-       (treesit-node-end node)))))
+         (treesit-node-end node))))))
 
 (defun treesit-parent-until (node pred)
   "Return the closest parent of NODE that satisfies PRED.



reply via email to

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