From: Yuan Fu Date: Fri, 28 Oct 2022 23:38:37 +0000 (-0700) Subject: Make Emacs compile without tree-sitter library X-Git-Tag: emacs-29.0.90~1761 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=434fc2a22e4fd65fd63018e9373cbf56b51f8ab2;p=emacs.git Make Emacs compile without tree-sitter library * lisp/treesit.el: Add function declaration forms. * src/emacs.c: Always include syms_of_treesit. --- diff --git a/lisp/treesit.el b/lisp/treesit.el index 8db47048231..f1440412028 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -33,6 +33,57 @@ (require 'cl-seq) (require 'font-lock) +;;; Function declarations + +(declare-function treesit-language-available-p "treesit.c") +(declare-function treesit-language-version "treesit.c") + +(declare-function treesit-parser-p "treesit.c") +(declare-function treesit-node-p "treesit.c") +(declare-function treesit-compiled-query-p "treesit.c") +(declare-function treesit-query-p "treesit.c") +(declare-function treesit-query-language "treesit.c") + +(declare-function treesit-node-parser "treesit.c") + +(declare-function treesit-parser-create "treesit.c") +(declare-function treesit-parser-delete "treesit.c") +(declare-function treesit-parser-list "treesit.c") +(declare-function treesit-parser-buffer "treesit.c") +(declare-function treesit-parser-language "treesit.c") + +(declare-function treesit-parser-root-node "treesit.c") + +(declare-function treesit-parser-set-included-ranges "treesit.c") +(declare-function treesit-parser-included-ranges "treesit.c") + +(declare-function treesit-node-type "treesit.c") +(declare-function treesit-node-start "treesit.c") +(declare-function treesit-node-end "treesit.c") +(declare-function treesit-node-string "treesit.c") +(declare-function treesit-node-parent "treesit.c") +(declare-function treesit-node-child "treesit.c") +(declare-function treesit-node-check "treesit.c") +(declare-function treesit-node-field-name-for-child "treesit.c") +(declare-function treesit-node-child-count "treesit.c") +(declare-function treesit-node-child-by-field-name "treesit.c") +(declare-function treesit-node-next-sibling "treesit.c") +(declare-function treesit-node-prev-sibling "treesit.c") +(declare-function treesit-node-first-child-for-pos "treesit.c") +(declare-function treesit-node-descendant-for-range "treesit.c") +(declare-function treesit-node-eq "treesit.c") + +(declare-function treesit-pattern-expand "treesit.c") +(declare-function treesit-query-expand "treesit.c") +(declare-function treesit-query-compile "treesit.c") +(declare-function treesit-query-capture "treesit.c") + +(declare-function treesit-search-subtree "treesit.c") +(declare-function treesit-search-forward "treesit.c") +(declare-function treesit-induce-sparse-tree "treesit.c") + +(declare-function treesit-available-p "treesit.c") + ;;; Custom options ;; Tree-sitter always appear as treesit in symbols. @@ -48,8 +99,6 @@ indent, imenu, etc." :type 'integer :version "29.1") -(declare-function treesit-available-p "treesit.c") - (defcustom treesit-settings '((t nil t)) "Tree-sitter toggle settings for major modes. @@ -459,63 +508,69 @@ a capture name is not a face name nor a function name, it is ignored. \(fn :KEYWORD VALUE QUERY...)" - (let (;; Tracks the current :language/:override/:toggle/:level value - ;; that following queries will apply to. - current-language current-override - current-feature - ;; The list this function returns. - (result nil)) - (while args - (let ((token (pop args))) - (pcase token - ;; (1) Process keywords. - (:language - (let ((lang (pop args))) - (when (or (not (symbolp lang)) (null lang)) - (signal 'treesit-font-lock-error - `("Value of :language should be a symbol" - ,lang))) - (setq current-language lang))) - (:override - (let ((flag (pop args))) - (when (not (memq flag '(t nil append prepend keep))) + ;; Other tree-sitter function don't tend to be called unless + ;; tree-sitter is enabled, which means tree-sitter must be compiled. + ;; But this function is usually call in `defvar' which runs + ;; regardless whether tree-sitter is enabled. So we need this + ;; guard. + (when (treesit-available-p) + (let (;; Tracks the current :language/:override/:toggle/:level value + ;; that following queries will apply to. + current-language current-override + current-feature + ;; The list this function returns. + (result nil)) + (while args + (let ((token (pop args))) + (pcase token + ;; (1) Process keywords. + (:language + (let ((lang (pop args))) + (when (or (not (symbolp lang)) (null lang)) + (signal 'treesit-font-lock-error + `("Value of :language should be a symbol" + ,lang))) + (setq current-language lang))) + (:override + (let ((flag (pop args))) + (when (not (memq flag '(t nil append prepend keep))) + (signal 'treesit-font-lock-error + `("Value of :override should be one of t, nil, append, prepend, keep" + ,flag)) + (signal 'wrong-type-argument + `((or t nil append prepend keep) + ,flag))) + (setq current-override flag))) + (:feature + (let ((var (pop args))) + (when (or (not (symbolp var)) + (memq var '(t nil))) + (signal 'treesit-font-lock-error + `("Value of :feature should be a symbol" + ,var))) + (setq current-feature var))) + ;; (2) Process query. + ((pred treesit-query-p) + (when (null current-language) (signal 'treesit-font-lock-error - `("Value of :override should be one of t, nil, append, prepend, keep" - ,flag)) - (signal 'wrong-type-argument - `((or t nil append prepend keep) - ,flag))) - (setq current-override flag))) - (:feature - (let ((var (pop args))) - (when (or (not (symbolp var)) - (memq var '(t nil))) + `("Language unspecified, use :language keyword to specify a language for this query" ,token))) + (when (null current-feature) (signal 'treesit-font-lock-error - `("Value of :feature should be a symbol" - ,var))) - (setq current-feature var))) - ;; (2) Process query. - ((pred treesit-query-p) - (when (null current-language) - (signal 'treesit-font-lock-error - `("Language unspecified, use :language keyword to specify a language for this query" ,token))) - (when (null current-feature) - (signal 'treesit-font-lock-error - `("Feature unspecified, use :feature keyword to specify the feature name for this query" ,token))) - (if (treesit-compiled-query-p token) - (push `(,current-language token) result) - (push `(,(treesit-query-compile current-language token) - t - ,current-feature - ,current-override) - result)) - ;; Clears any configurations set for this query. - (setq current-language nil - current-override nil - current-feature nil)) - (_ (signal 'treesit-font-lock-error - `("Unexpected value" ,token)))))) - (nreverse result))) + `("Feature unspecified, use :feature keyword to specify the feature name for this query" ,token))) + (if (treesit-compiled-query-p token) + (push `(,current-language token) result) + (push `(,(treesit-query-compile current-language token) + t + ,current-feature + ,current-override) + result)) + ;; Clears any configurations set for this query. + (setq current-language nil + current-override nil + current-feature nil)) + (_ (signal 'treesit-font-lock-error + `("Unexpected value" ,token)))))) + (nreverse result)))) (defun treesit-font-lock-recompute-features () "Enable/disable font-lock settings according to decoration level. diff --git a/src/emacs.c b/src/emacs.c index ba8b9c651a7..ed21cce1e25 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -136,9 +136,9 @@ extern char etext; #include #endif -#ifdef HAVE_TREE_SITTER +/* We don't guard this with HAVE_TREE_SITTER because treesit.o is + always compiled (to provide treesit-available-p). */ #include "treesit.h" -#endif #include "pdumper.h" #include "fingerprint.h" @@ -2269,10 +2269,9 @@ Using an Emacs configured with --with-x-toolkit=lucid does not have this problem #ifdef HAVE_MODULES syms_of_module (); #endif - -#ifdef HAVE_TREE_SITTER + /* We don't guard this with HAVE_TREE_SITTER because treesit.o + is always compiled (to provide treesit-available-p). */ syms_of_treesit (); -#endif #ifdef HAVE_SOUND syms_of_sound (); #endif