From: Yuan Fu Date: Sun, 25 Sep 2022 02:24:06 +0000 (-0700) Subject: Accept nil as NODE in treesit-node-text X-Git-Tag: emacs-29.0.90~1876 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1575ee2eeb1ebb5b73b4b76fc7dc7f5702748540;p=emacs.git Accept nil as NODE in treesit-node-text * lisp/treesit.el (treesit-node-text): Just wrap function body in (when ...). --- 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.