Function: gptel-markdown-cycle-block

gptel-markdown-cycle-block is an interactive and natively compiled function defined in gptel.el.

Signature

(gptel-markdown-cycle-block)

Documentation

Cycle code blocks in Markdown.

Key Bindings

gptel--markdown-block-map <tab> gptel--markdown-block-map TAB

Source Code

;; Defined in /nix/store/q3r7g81pvghw7a523kjk2k2zih3pfk8z-emacs-packages-deps/share/emacs/site-lisp/elpa/gptel-20261002.545/gptel.el
(defun gptel-markdown-cycle-block ()
  "Cycle code blocks in Markdown."
  (interactive)
  (save-excursion
    (forward-line 0)
    (let (start end (parity 0))
      (cond            ;Find start and end of block, with possible nested blocks
       ((looking-at-p "^``` *\n")       ;end of block, find corresponding start
        (setq parity -1 end (line-end-position))
        (while (and (not (= parity 0)) (not (bobp)) (forward-line -1))
          (cond ((looking-at-p "^``` *\n") (cl-decf parity))
                ((looking-at-p "^``` ?[a-z]") (cl-incf parity))))
        (when (= parity 0) (setq start (point))))

       ((looking-at-p "^``` ?[a-z]") ;beginning of block, find corresponding end
        (setq parity 1 start (point))
        (while (and (not (= parity 0)) (not (eobp)) (forward-line 1))
          (cond ((looking-at-p "^``` *\n") (cl-decf parity))
                ((looking-at-p "^``` ?[a-z]") (cl-incf parity))))
        (when (= parity 0) (setq end (line-end-position)))))
      (when (and start end)
        (goto-char start)
        (end-of-line)
        (pcase-let* ((`(,value . ,hide-ov)
                      (get-char-property-and-overlay (point) 'invisible)))
          (if (and hide-ov (eq value t))
              (delete-overlay hide-ov)
            (unless hide-ov (setq hide-ov (make-overlay (point) end)))
            (overlay-put hide-ov 'evaporate t)
            (overlay-put hide-ov 'invisible t)
            (overlay-put hide-ov 'before-string
                         (propertize "..." 'face 'shadow))))))))