Function: combobulate-maybe-activate

combobulate-maybe-activate is a natively compiled function defined in combobulate-setup.el.

Signature

(combobulate-maybe-activate &optional RAISE-IF-MISSING CALLED-INTERACTIVELY)

Documentation

Maybe activate Combobulate in the current buffer.

Do not call this directly. Please use M-x combobulate-mode (combobulate-mode) to enable Combobulate.

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-setup.el
(defun combobulate-maybe-activate (&optional raise-if-missing called-interactively)
  "Maybe activate Combobulate in the current buffer.

Do not call this directly. Please use \\[combobulate-mode] to
enable Combobulate."
  ;; (unless combobulate-mode
  ;;   (error "Do not call `combobulate-maybe-activate' directly. Invoke \\[combobulate-mode] instead"))
  ;; Combobulate can activate in any major mode provided it's listed
  ;; in `combobulate-registered-languages-alist'.
  ;;
  (when-let (match (or (when-let ((existing-parsers (combobulate-parser-list)))
                         (let ((ts-lang (combobulate-parser-language (car existing-parsers))))
                           (seq-find (pcase-lambda (`(,name _ _))
                                       (eq name ts-lang))
                                     combobulate-registered-languages-alist)))
                       (combobulate-get-registered-language major-mode)))
    (pcase-let ((`(,name _ ,minor-mode-fn) match))
      (let ((language name))
        ;; Only error out if RAISE-IF-MISSING is non-nil. The expected
        ;; behaviour is that Combobulate may get activated in major
        ;; modes for which no grammar exists. Raising an error
        ;; unconditionally in that case would be annoying to users.
        (if (and raise-if-missing (not (combobulate-language-available-p language)))
            (error "Cannot activate Combobulate in buffer `%s' because tree-sitter is missing a language library.

The major mode `%s' is registered as supporting the tree-sitter
language `%s' but that language is not known to tree-sitter.

Try reinstalling the grammar for that language and try again."
                   (current-buffer) major-mode language)
          ;; Language parser exists. Make sure that, if we already have
          ;; an initialised language in the buffer that it is not
          ;; different from the one we think it should be.
          (when-let ((existing-parsers (mapcar #'combobulate-parser-language (combobulate-parser-list))))
            (unless (member language existing-parsers)
              (error "Cannot activate Combobulate in buffer `%s' because of a parser mismatch.

The buffer's language is `%s' and does not match Combobulate's
expected language of `%s'. This can happen if you have major
modes with conflicting ideas of what type of language to use."
                     (current-buffer) (car-safe existing-parsers) language)))
          ;; Okay. All good, then... Create the language parser.
          (combobulate-create-language language (current-buffer) nil)
          (let ((toggle (if (combobulate-read minor-mode name) -1 1)))
            (prog1
                (funcall minor-mode-fn toggle)
              (when (and (> toggle 0) called-interactively)
                (combobulate-message
                 (substitute-command-keys "Activating Combobulate. Type \\[combobulate] to start."))))))))))