Function: rst-forward-section

rst-forward-section is an interactive and byte-compiled function defined in rst.el.gz.

Signature

(rst-forward-section OFFSET)

Documentation

Jump forward OFFSET section titles ending up at the start of the title line.

OFFSET defaults to 1 and may be negative to move backward. An OFFSET of 0 does not move unless point is inside a title. Go to end or beginning of buffer if no more section titles in the desired direction.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/rst.el.gz
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Section movement

;; FIXME testcover: Use `testcover'. Mark up a function with sufficient test
;;                  coverage by a comment tagged with `testcover' after the
;;                  `defun'. Then move this comment.

(defun rst-forward-section (offset)
  "Jump forward OFFSET section titles ending up at the start of the title line.
OFFSET defaults to 1 and may be negative to move backward.  An
OFFSET of 0 does not move unless point is inside a title.  Go to
end or beginning of buffer if no more section titles in the desired
direction."
  (interactive "p")
  (rst-reset-section-caches)
  (let* ((ttls (rst-all-ttls))
	 (count (length ttls))
	 (pnt (point))
	 (contained nil) ; Title contains point (or is after point otherwise).
         (found (or (cl-position-if
		     ;; Find a title containing or after point.
                     (lambda (ttl)
                       (let ((cmp (rst-Ttl-contains ttl pnt)))
                         (cond
                          ((= cmp 0) ; Title contains point.
                           (setq contained t)
                           t)
                          ((> cmp 0) ; Title after point.
                           t))))
		     ttls)
		    ;; Point after all titles.
		    count))
	 (target (+ found offset
		    ;; If point is in plain text found title is already one
		    ;; step forward.
		    (if (and (not contained) (>= offset 0)) -1 0))))
    (goto-char (cond
		((< target 0)
		 (point-min))
		((>= target count)
		 (point-max))
		((and (not contained) (= offset 0))
		 ;; Point not in title and should not move - do not move.
		 pnt)
		((rst-Ttl-get-title-beginning (nth target ttls)))))))