Function: cmake-ts-mode

cmake-ts-mode is an autoloaded, interactive and byte-compiled function defined in cmake-ts-mode.el.gz.

Signature

(cmake-ts-mode)

Documentation

Major mode for editing CMake files, powered by tree-sitter.

In addition to any hooks its parent mode prog-mode might have run, this mode runs the hook cmake-ts-mode-hook, as the final or penultimate step during initialization.

Probably introduced at or before Emacs version 29.1.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cmake-ts-mode.el.gz
;;;###autoload
(define-derived-mode cmake-ts-mode prog-mode "CMake"
  "Major mode for editing CMake files, powered by tree-sitter."
  :group 'cmake
  :syntax-table cmake-ts-mode--syntax-table

  (when (treesit-ensure-installed 'cmake)
    (setq treesit-primary-parser (treesit-parser-create 'cmake))

    ;; Comments.
    (setq-local comment-start "# ")
    (setq-local comment-end "")
    (setq-local comment-start-skip (rx "#" (* (syntax whitespace))))

    ;; Defuns.
    (setq-local treesit-defun-type-regexp (rx (or "function" "macro")
                                              "_def"))
    (setq-local treesit-defun-name-function #'cmake-ts-mode--defun-name)

    ;; Imenu.
    (setq-local treesit-simple-imenu-settings
                `(("Function" "^function_def$")
                  ("Macro" "^macro_def$")))
    (setq-local which-func-functions nil)

    ;; Indent.
    (setq-local treesit-simple-indent-rules (cmake-ts-mode--indent-rules))

    ;; Font-lock.
    (setq-local treesit-font-lock-settings (cmake-ts-mode--font-lock-settings))
    (setq-local treesit-font-lock-feature-list
                '((comment)
                  (keyword string)
                  ;; 'function' and 'variable' here play slightly
                  ;; different roles than in other ts modes, so we
                  ;; kept them at level 3.
                  (builtin constant escape-sequence function number variable)
                  (bracket error misc-punctuation)))

    (treesit-major-mode-setup)))