From 1575ee2eeb1ebb5b73b4b76fc7dc7f5702748540 Mon Sep 17 00:00:00 2001 From: Yuan Fu Date: Sat, 24 Sep 2022 19:24:06 -0700 Subject: [PATCH] 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 9750ac7b7b9..28a74657f9d 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. -- 2.39.5