Function: rst-adjust-new-hdr
rst-adjust-new-hdr is a byte-compiled function defined in rst.el.gz.
Signature
(rst-adjust-new-hdr TOGGLE-STYLE REVERSE TTL)
Documentation
Return a new rst-Hdr for rst-adjust-section related to TTL.
TOGGLE-STYLE and REVERSE are from
rst-adjust-section. TOGGLE-STYLE may be consumed and thus is
returned.
Return a list (HDR TOGGLE-STYLE MSG...). HDR is the result or
nil. TOGGLE-STYLE is the new TOGGLE-STYLE to use in the
caller. MSG is a list which is non-empty in case HDR is nil
giving an argument list for message.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/rst.el.gz
(defun rst-adjust-new-hdr (toggle-style reverse ttl)
;; testcover: ok.
"Return a new `rst-Hdr' for `rst-adjust-section' related to TTL.
TOGGLE-STYLE and REVERSE are from
`rst-adjust-section'. TOGGLE-STYLE may be consumed and thus is
returned.
Return a list (HDR TOGGLE-STYLE MSG...). HDR is the result or
nil. TOGGLE-STYLE is the new TOGGLE-STYLE to use in the
caller. MSG is a list which is non-empty in case HDR is nil
giving an argument list for `message'."
(save-excursion
(goto-char (rst-Ttl-get-title-beginning ttl))
(let ((indent (rst-Ttl-indent ttl))
(ado (rst-Ttl-ado ttl))
(prev (rst-get-previous-hdr))
hdr-msg)
(setq
hdr-msg
(cond
((rst-Ttl-is-candidate ttl)
;; Case 1: No adornment at all.
(let ((hier (rst-hdr-hierarchy)))
(if prev
;; Previous header exists - use it.
(cond
;; Customization and parameters require that the previous level
;; is used - use it as is.
((or (and rst-new-adornment-down reverse)
(and (not rst-new-adornment-down) (not reverse)))
prev)
;; Advance one level down.
((rst-next-hdr prev hier prev t))
("Neither hierarchy nor preferences can suggest a deeper header"))
;; First header in the buffer - use the first adornment from
;; preferences or hierarchy.
(let ((p (car (rst-Hdr-preferred-adornments)))
(h (car hier)))
(cond
((if reverse
;; Prefer hierarchy for downwards
(or h p)
;; Prefer preferences for upwards
(or p h)))
("No preferences to suggest a top level from"))))))
((not (rst-adornment-complete-p ado indent))
;; Case 2: Incomplete adornment.
;; Use lax since indentation might not match suggestion.
(rst-Hdr-new-lax ado indent))
;; Case 3: Complete adornment exists from here on.
(toggle-style
;; Simply switch the style of the current adornment.
(setq toggle-style nil) ; Remember toggling has been done.
(rst-Hdr-new-invert ado rst-default-indent))
(t
;; Rotate, ignoring a sole adornment around the current line.
(let ((hier (rst-hdr-hierarchy (point))))
(cond
;; Next header can be determined from hierarchy or preferences.
((rst-next-hdr
;; Use lax since indentation might not match suggestion.
(rst-Hdr-new-lax ado indent) hier prev reverse))
;; No next header found.
("No preferences or hierarchy to suggest another level from"))))))
(if (stringp hdr-msg)
(list nil toggle-style hdr-msg)
(list hdr-msg toggle-style)))))