Function: rst-update-section

rst-update-section is a byte-compiled function defined in rst.el.gz.

Signature

(rst-update-section HDR)

Documentation

Unconditionally update the style of the section header at point to HDR.

If there are existing overline and/or underline from the existing adornment, they are removed before adding the requested adornment.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/rst.el.gz
(defun rst-update-section (hdr)
  ;; testcover: ok.
  "Unconditionally update the style of the section header at point to HDR.
If there are existing overline and/or underline from the
existing adornment, they are removed before adding the
requested adornment."
  (end-of-line)
  (let ((indent (or (rst-Hdr-indent hdr) 0))
	(marker (point-marker))
	new)

    ;; Fixup whitespace at the beginning and end of the line.
    (1value
     (rst-forward-line-strict 0))
    (delete-horizontal-space)
    (insert (make-string indent ? ))
    (end-of-line)
    (delete-horizontal-space)
    (setq new (make-string (+ (current-column) indent) (rst-Hdr-get-char hdr)))

    ;; Remove previous line if it is an adornment.
    ;; FIXME refactoring: Check whether this deletes `hdr' which *has* all the
    ;;                    data necessary.
    (when (and (rst-forward-line-looking-at -1 'ado-beg-2-1)
	       ;; Avoid removing the underline of a title right above us.
	       (not (rst-forward-line-looking-at -2 'ttl-beg-1)))
      (rst-delete-entire-line -1))

    ;; Remove following line if it is an adornment.
    (when (rst-forward-line-looking-at +1 'ado-beg-2-1)
      (rst-delete-entire-line +1))

    ;; Insert underline.
    (unless (rst-forward-line-strict +1)
      ;; Normalize buffer by adding final newline.
      (newline 1))
    (open-line 1)
    (insert new)

    ;; Insert overline.
    (when (rst-Hdr-is-over-and-under hdr)
      (1value ; Underline inserted above.
       (rst-forward-line-strict -1))
      (open-line 1)
      (insert new))

    (goto-char marker)))