Function: org--backward-paragraph-once
org--backward-paragraph-once is an interactive and byte-compiled
function defined in org.el.gz.
Signature
(org--backward-paragraph-once)
Documentation
Move backward to start of paragraph or equivalent, once.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org--backward-paragraph-once ()
"Move backward to start of paragraph or equivalent, once.
See `org-backward-paragraph'."
(interactive)
(save-restriction
(widen)
(cond
((bobp) nil)
;; Blank lines at the beginning of the buffer.
((and (org-match-line "^[ \t]*$")
(save-excursion (skip-chars-backward " \t\n") (bobp)))
(goto-char (point-min)))
;; When inside a folded part, move out of it.
((when (org-invisible-p (1- (point)) t)
(goto-char (1- (car (org-fold-get-region-at-point nil (1- (point))))))
(org--backward-paragraph-once)
t))
(t
(let* ((element (org--paragraph-at-point))
(type (org-element-type element))
(begin (org-element-begin element))
(post-affiliated (org-element-post-affiliated element))
(contents-end (org-element-contents-end element))
(end (org-element-end element))
(parent (org-element-parent element))
(reach
;; Move to the visible empty line above position P, or
;; to position P. Return t.
(lambda (p)
(goto-char p)
(when (and (org-previous-line-empty-p)
(let ((end (line-end-position 0)))
(or (= end (point-min))
(not (org-invisible-p (1- end))))))
(forward-line -1))
t)))
(cond
;; Already at the beginning of an element.
((= begin (point))
(cond
;; There is a blank line above. Move there.
((and (org-previous-line-empty-p)
(not (org-invisible-p (1- (line-end-position 0)))))
(forward-line -1))
;; At the beginning of the first element within a greater
;; element. Move to the beginning of the greater element.
((and parent
(not (org-element-type-p parent 'section))
(= begin (org-element-contents-begin parent)))
(funcall reach (org-element-begin parent)))
;; Since we have to move anyway, find the beginning
;; position of the element above.
(t
(forward-char -1)
(org--backward-paragraph-once))))
;; Skip paragraphs at the very beginning of footnote
;; definitions or items.
((and (eq type 'paragraph)
(org-with-point-at begin (not (bolp))))
(funcall reach (progn (goto-char begin) (line-beginning-position))))
;; If the element is folded, skip it altogether.
((org-with-point-at post-affiliated (org-invisible-p (line-end-position) t))
(funcall reach begin))
;; At the end of a greater element, move inside.
((and contents-end
(<= contents-end (point))
(not (eq type 'paragraph)))
(cond
((memq type '(footnote-definition plain-list))
(skip-chars-backward " \t\n")
(org--backward-paragraph-once))
((= contents-end (point))
(forward-char -1)
(org--backward-paragraph-once))
(t
(goto-char contents-end))))
;; Move between empty lines in some blocks.
((and (memq type '(comment-block example-block export-block src-block
verse-block))
(let ((contents-start
(org-with-point-at post-affiliated
(line-beginning-position 2))))
(when (> (point) contents-start)
(let ((contents-end
(org-with-point-at end
(skip-chars-backward " \t\n")
(line-beginning-position))))
(if (> (point) contents-end)
(progn (goto-char contents-end) t)
(skip-chars-backward " \t\n" begin)
(re-search-backward "^[ \t]*\n" contents-start :move)
t))))))
;; Move to element's start.
(t
(funcall reach begin))))))))