Function: rst-toc-update
rst-toc-update is an interactive and byte-compiled function defined in
rst.el.gz.
Signature
(rst-toc-update)
Documentation
Automatically find the contents section of a document and update.
Updates the inserted TOC if present. You can use this in your file-write hook to always make it up-to-date automatically.
Key Bindings
Aliases
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/rst.el.gz
(defun rst-toc-update ()
;; testcover: ok.
"Automatically find the contents section of a document and update.
Updates the inserted TOC if present. You can use this in your
file-write hook to always make it up-to-date automatically."
(interactive)
(save-match-data
(save-excursion
;; Find and delete an existing comment after the first contents
;; directive. Delete that region.
(goto-char (point-min))
;; FIXME: Should accept indentation of the whole block.
;; We look for the following and the following only (in other words, if
;; your syntax differs, this won't work.).
;;
;; .. contents:: [...anything here...]
;; [:field: value]...
;; ..
;; XXXXXXXX
;; XXXXXXXX
;; [more lines]
;; FIXME: Works only for the first of these tocs. There should be a
;; fixed text after the comment such as "RST-MODE ELECTRIC TOC".
;; May be parameters such as `max-level' should be appended.
(let ((beg (re-search-forward
(1value
(rst-re "^" 'exm-sta "contents" 'dcl-tag ".*\n"
"\\(?:" 'hws-sta 'fld-tag ".*\n\\)*" 'exm-tag))
nil t))
fnd)
(when
(and beg
(rst-forward-line-looking-at
1 'lin-end
(lambda (mtcd)
(unless mtcd
(rst-apply-indented-blocks
(point) (point-max) (current-indentation)
(lambda (count _in-first _in-sub in-super in-empty
_relind)
(cond
((or (> count 1) in-super))
((not in-empty)
(setq fnd (line-end-position))
nil)))))
t)))
(when fnd
(delete-region beg fnd))
(goto-char beg)
(insert "\n ")
;; FIXME: Ignores an `max-level' given to the original
;; `rst-toc-insert'. `max-level' could be rendered to the first
;; line.
(rst-toc-insert)))))
;; Note: always return nil, because this may be used as a hook.
nil)