Function: magit-todos--fontify-like-in-org-mode

magit-todos--fontify-like-in-org-mode is a natively compiled function defined in magit-todos.el.

Signature

(magit-todos--fontify-like-in-org-mode S &optional ODD-LEVELS)

Documentation

Fontify string S like in Org-mode.

Bind org-odd-levels-only to ODD-LEVELS.

org-fontify-like-in-org-mode is a very, very slow function because it creates a new temporary buffer and runs org-mode for every string it fontifies. This function reuses a single invisible buffer and only runs org-mode when the buffer is created.

Source Code

;; Defined in /nix/store/xy37aj9089qvbs5clw0qszpi3hrh3mxx-emacs-packages-deps/share/emacs/site-lisp/elpa/magit-todos-20250928.1611/magit-todos.el
(defun magit-todos--fontify-like-in-org-mode (s &optional odd-levels)
  "Fontify string S like in Org-mode.
Bind `org-odd-levels-only' to ODD-LEVELS.

`org-fontify-like-in-org-mode' is a very, very slow function
because it creates a new temporary buffer and runs `org-mode' for
every string it fontifies.  This function reuses a single
invisible buffer and only runs `org-mode' when the buffer is
created."
  (let ((buffer (get-buffer " *magit-todos--fontify-like-in-org-mode*")))
    (unless buffer
      (setq buffer (get-buffer-create " *magit-todos--fontify-like-in-org-mode*"))
      (with-current-buffer buffer
        (buffer-disable-undo)
        (org-mode)))
    (with-current-buffer buffer
      (erase-buffer)
      (insert s)
      (let ((org-odd-levels-only odd-levels))
        (font-lock-ensure)
        (buffer-string)))))