Function: markdown-ts-toc-clear
markdown-ts-toc-clear is an interactive and byte-compiled function
defined in markdown-ts-mode-x.el.gz.
Signature
(markdown-ts-toc-clear &optional BEG END REMOVE)
Documentation
Clear markdown-ts-mode table of contents bodies.
Operate on the active region BEG to END, otherwise operate on the buffer, which may be narrowed. If optional REMOVE is non-nil, remove tables including their templates.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode-x.el.gz
(defun markdown-ts-toc-clear (&optional beg end remove)
"Clear `markdown-ts-mode' table of contents bodies.
Operate on the active region BEG to END, otherwise operate on the
buffer, which may be narrowed.
If optional REMOVE is non-nil, remove tables including their templates."
(interactive "R")
(markdown-ts--barf-if-not-mode 'markdown-ts-toc-clear)
(setq beg (or beg (point-min)))
(setq end (or end (point-max)))
(unless (eq beg end)
;; Convert markers to absolute positions.
(setq beg (if (markerp beg) (marker-position beg) beg))
(setq end (if (markerp end) (marker-position end) end))
;; NOTE: Operate on the widened buffer to avoid treesiter crash issues.
(without-restriction
(let ((tocs)
(beg-pos beg)
(end-pos end))
;; We scan each pass because their positions change.
(while (and (< beg-pos end-pos)
(setq tocs (markdown-ts--tocs beg-pos end-pos)))
(markdown-ts--tocs-sanity-check tocs)
;; After sanity checking, we know the second element is a
;; toc-end.
(let* ((toc (nth 0 tocs))
(toc-end (nth 1 tocs))
(reg-beg (if remove
(alist-get 'beg toc)
(alist-get 'end toc)))
(reg-end (if remove
(alist-get 'end toc-end)
(alist-get 'beg toc-end)))
(reg-size (- reg-end reg-beg)))
(delete-region reg-beg reg-end)
;; Start the next pass after this toc-end. Adjust for the
;; deleted region.
(setq beg-pos (- (alist-get 'end toc-end)
reg-size))
(setq end-pos (min (point-max) (- end-pos reg-size)))))))))