Function: markdown-ts-code-block-context-mode

markdown-ts-code-block-context-mode is a byte-compiled function defined in markdown-ts-mode.el.gz.

Signature

(markdown-ts-code-block-context-mode &optional ARG)

Documentation

Minor mode to enable commands in fenced code block context.

If non-nil and point is in a fenced code block, run indent-for-tab-command, newline, et.al., in the mode of the code block.

This is a minor mode. If called interactively, toggle the Markdown-Ts-Code-Block-Context mode mode. If the prefix argument is positive, enable the mode, and if it is zero or negative, disable the mode.

If called from Lisp, toggle the mode if ARG is toggle. Enable the mode if ARG is nil, omitted, or is a positive number. Disable the mode if ARG is a negative number.

To check whether the minor mode is enabled in the current buffer, evaluate the variable markdown-ts-code-block-context-mode(var)/markdown-ts-code-block-context-mode(fun).

The mode's hook is called both when the mode is enabled and when it is disabled.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(define-minor-mode markdown-ts-code-block-context-mode
  "Minor mode to enable commands in fenced code block context.
If non-nil and `point' is in a fenced code block, run `indent-for-tab-command',
`newline', et.al., in the mode of the code block."
  :group 'markdown-ts
  :interactive nil
  (markdown-ts--barf-if-not-mode 'markdown-ts-code-block-context-mode)
  (cond (markdown-ts-code-block-context-mode
         ;; Enable the minor mode `markdown-ts-code-block-in-context-mode' and
         ;; its keymap when point is within a code block.
         (add-hook 'post-command-hook
                   #'markdown-ts--enable-code-block-in-context-mode nil 'local)
         ;; If `save-place-mode' or similar is used, point could start within
         ;; a code block so initialize from that state.
         (run-with-timer 0.01 nil
                         #'markdown-ts--enable-code-block-in-context-mode)
         ;; For each eligible command, execute it in a code-block context,
         ;; otherwise in the `markdown-ts-mode' buffer's context.
         (add-hook 'pre-command-hook
                   #'markdown-ts--maybe-run-command-in-code-block nil 'local)
         ;; Prune stale code block overlays when the host parse tree
         ;; changes (e.g., when fenced code block delimiters are
         ;; deleted but the overlay from a prior fontification remains).
         (treesit-parser-add-notifier
          treesit-primary-parser
          #'markdown-ts--host-ranges-notifier))
        (t
         (remove-hook 'post-command-hook
                      #'markdown-ts--enable-code-block-in-context-mode 'local)
         (remove-hook 'pre-command-hook
                      #'markdown-ts--maybe-run-command-in-code-block 'local)
         (treesit-parser-remove-notifier
          treesit-primary-parser
          #'markdown-ts--host-ranges-notifier))))