(defun jm~lua-ts-documentation-at-point () "Show documentation of function at point in the Lua manual." (interactive) (save-excursion ;; When point is mid-word `treesit-thing-at-point' may return ;; the parent node of the thing at point. Go to the beginning ;; of the line or word to make sure we have the right thing. (unless (or (bolp) (not (string-match-p "[[:alnum:]]" (char-to-string (char-before))))) (backward-word)) (when-let* ((node (treesit-thing-at-point 'sentence nil)) ((equal "function_call" (treesit-node-type node))) (child (treesit-node-child-by-field-name node "name")) (name (treesit-node-text child t)) (id (if (string-match-p ":" name) (replace-regexp-in-string "^.*:" "file:" name) name)) ((string-match-p (rx-to-string `(: (? "file:") (or ,@lua-ts--builtins))) id))) (browse-url (concat "file:///usr/share/doc/lua/manual.html" "#pdf-" id)))))