Function: treesit-font-lock-recompute-features

treesit-font-lock-recompute-features is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit-font-lock-recompute-features &optional ADD-LIST REMOVE-LIST LANGUAGE)

Documentation

Enable/disable font-lock features.

Enable each feature in ADD-LIST, disable each feature in REMOVE-LIST.

If both ADD-LIST and REMOVE-LIST are omitted, recompute each feature according to treesit-font-lock-feature-list and treesit-font-lock-level. If the value of treesit-font-lock-level, is N, then the features in the first N sublists of treesit-font-lock-feature-list are enabled, and the rest of the features are disabled.

ADD-LIST and REMOVE-LIST are lists of feature symbols. The same feature symbol cannot appear in both lists; the function signals the treesit-font-lock-error error if that happens.

If LANGUAGE is non-nil, only compute features for that language, and leave settings for other languages unchanged.

View in manual

Source Code

;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit-font-lock-recompute-features
    (&optional add-list remove-list language)
  "Enable/disable font-lock features.

Enable each feature in ADD-LIST, disable each feature in
REMOVE-LIST.

If both ADD-LIST and REMOVE-LIST are omitted, recompute each
feature according to `treesit-font-lock-feature-list' and
`treesit-font-lock-level'.  If the value of `treesit-font-lock-level',
is N, then the features in the first N sublists of
`treesit-font-lock-feature-list' are enabled, and the rest of
the features are disabled.

ADD-LIST and REMOVE-LIST are lists of feature symbols.  The
same feature symbol cannot appear in both lists; the function
signals the `treesit-font-lock-error' error if that happens.

If LANGUAGE is non-nil, only compute features for that language,
and leave settings for other languages unchanged."
  (when-let* ((intersection (cl-intersection add-list remove-list)))
    (signal 'treesit-font-lock-error
            (list "ADD-LIST and REMOVE-LIST contain the same feature"
                  intersection)))
  (let* ((level (treesit--compute-font-lock-level
                 treesit-font-lock-level))
         (base-features (cl-loop
                         for idx = 0 then (1+ idx)
                         for features in treesit-font-lock-feature-list
                         if (or (eq level t)
                                (>= level (1+ idx)))
                         append features))
         (features (cl-set-difference (cl-union base-features add-list)
                                      remove-list))
         ;; If additive non-nil, we are configuring on top of the
         ;; existing configuration, if nil, we are resetting
         ;; everything according to `treesit-font-lock-feature-list'.
         (additive (or add-list remove-list)))
    (cl-loop for idx = 0 then (1+ idx)
             for setting in treesit-font-lock-settings
             for lang = (treesit-font-lock-setting-language setting)
             for feature = (treesit-font-lock-setting-feature setting)
             for current-value = (treesit-font-lock-setting-enable setting)
             for reversed = (treesit-font-lock-setting-reversed setting)
             ;; Set the ENABLE flag for the setting if its language is
             ;; relevant.
             if (or (null language)
                    (eq language lang))
             do (setf (nth 1 (nth idx treesit-font-lock-settings))
                      (cond
                       ((not additive)
                        (if (not reversed)
                            (if (memq feature features) t nil)
                          (if (memq feature features) nil t)))
                       ((memq feature add-list) t)
                       ((memq feature remove-list) nil)
                       (t current-value))))))