org.el (org-adaptive-fill-function, org-fill-paragraph): Throw a useful error message

* org.el (org-adaptive-fill-function, org-fill-paragraph):
Throw a useful error message when parse an element fails in
the current buffer.

This can happen for example in a `message-mode' buffer when using
orgstruct-mode.  If you insert a line like:

SCHEDULED: <2013-04-13 Sat> is blablabla

then org-element-at-point will fail and the user will get an error
he cannot understand.
This commit is contained in:
Bastien Guerry 2013-04-14 11:21:23 +02:00
parent 7c048fd886
commit 0ffeb8709e
1 changed files with 10 additions and 3 deletions

View File

@ -22063,8 +22063,11 @@ meant to be filled."
(throw 'exit (make-string (length (match-string 0)) ? )))))) (throw 'exit (make-string (length (match-string 0)) ? ))))))
(org-with-wide-buffer (org-with-wide-buffer
(let* ((p (line-beginning-position)) (let* ((p (line-beginning-position))
(element (save-excursion (beginning-of-line) (element (save-excursion
(org-element-at-point))) (beginning-of-line)
(or (ignore-errors (org-element-at-point))
(user-error "An element cannot be parsed line %d"
(line-number-at-pos (point))))))
(type (org-element-type element)) (type (org-element-type element))
(post-affiliated (org-element-property :post-affiliated element))) (post-affiliated (org-element-property :post-affiliated element)))
(unless (and post-affiliated (< p post-affiliated)) (unless (and post-affiliated (< p post-affiliated))
@ -22134,7 +22137,11 @@ a footnote definition, try to fill the first paragraph within."
(with-syntax-table org-mode-transpose-word-syntax-table (with-syntax-table org-mode-transpose-word-syntax-table
;; Move to end of line in order to get the first paragraph ;; Move to end of line in order to get the first paragraph
;; within a plain list or a footnote definition. ;; within a plain list or a footnote definition.
(let ((element (save-excursion (end-of-line) (org-element-at-point)))) (let ((element (save-excursion
(end-of-line)
(or (ignore-errors (org-element-at-point))
(user-error "An element cannot be parsed line %d"
(line-number-at-pos (point)))))))
;; First check if point is in a blank line at the beginning of ;; First check if point is in a blank line at the beginning of
;; the buffer. In that case, ignore filling. ;; the buffer. In that case, ignore filling.
(case (org-element-type element) (case (org-element-type element)