Function: rst-toc-insert

rst-toc-insert is an interactive and byte-compiled function defined in rst.el.gz.

Signature

(rst-toc-insert &optional MAX-LEVEL)

Documentation

Insert the table of contents of the current section at the current column.

By default the top level is ignored if there is only one, because we assume that the document will have a single title. A numeric prefix argument MAX-LEVEL overrides rst-toc-insert-max-level. Text in the line beyond column is deleted.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/rst.el.gz
(defun rst-toc-insert (&optional max-level)
  ;; testcover: ok.
  "Insert the table of contents of the current section at the current column.
By default the top level is ignored if there is only one, because
we assume that the document will have a single title.  A numeric
prefix argument MAX-LEVEL overrides `rst-toc-insert-max-level'.
Text in the line beyond column is deleted."
  (interactive "P")
  (rst-reset-section-caches)
  (let ((pt-stn (rst-stn-containing-point (rst-all-stn))))
    (when pt-stn
      (let ((max
	     (if (and (integerp max-level)
		      (> (prefix-numeric-value max-level) 0))
		 (prefix-numeric-value max-level)
	       rst-toc-insert-max-level))
	    (ind (current-column))
	    (buf (current-buffer))
	    (tabs indent-tabs-mode) ; Copy buffer local value.
	    txt)
	(setq txt
	      ;; Render to temporary buffer so markers are created correctly.
	      (with-temp-buffer
		(rst-toc-insert-tree pt-stn buf rst-toc-insert-style max
				     rst-toc-link-keymap nil)
		(goto-char (point-min))
		(when (rst-forward-line-strict 1)
		  ;; There are lines to indent.
		  (let ((indent-tabs-mode tabs))
		    (indent-rigidly (point) (point-max) ind)))
		(buffer-string)))
	(unless (zerop (length txt))
	  ;; Delete possible trailing text.
	  (delete-region (point) (line-beginning-position 2))
	  (insert txt)
	  (backward-char 1))))))