summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <n.goaziou@gmail.com>2012-10-05 23:02:03 (GMT)
committer Nicolas Goaziou <n.goaziou@gmail.com>2012-10-05 23:02:03 (GMT)
commitad99ea914711d75eca03e7fdf3383f275d2ffa3b (patch)
tree6680b648168bb87391b914327305ca64d4a9bc1d
parentdaf8cf030c21260b2615c303653913cdf2907e00 (diff)
downloadorg-mode-ad99ea914711d75eca03e7fdf3383f275d2ffa3b.zip
org-mode-ad99ea914711d75eca03e7fdf3383f275d2ffa3b.tar.gz
org-element: Fix parsing with trailing spaces at eob
* lisp/org-element.el (org-element-center-block-parser, org-element-drawer-parser, , org-element-footnote-definition-parser, org-element-inlinetask-parser, org-element-plain-list-parser, org-element-quote-block-parser, org-element-special-block-parser, org-element-babel-call-parser, org-element-clock-parser, org-element-comment-parser, org-element-comment-block-parser, org-element-example-block-parser, org-element-export-block-parser, org-element-fixed-width-parser, org-element-horizontal-rule-parser, org-element-keyword-parser, org-element-latex-environment-parser, org-element-paragraph-parser, org-element-planning-parser, org-element-property-drawer-parser, org-element-src-block-parser, org-element-table-parser, org-element-verse-block-parserorg-element-dynamic-block-parser): Make sure element never ends at the end of a blank non-empty line. * testing/lisp/test-org-element.el: Add test.
-rw-r--r--lisp/org-element.el80
-rw-r--r--testing/lisp/test-org-element.el4
2 files changed, 56 insertions, 28 deletions
diff --git a/lisp/org-element.el b/lisp/org-element.el
index fe4a184..46e668c 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -494,7 +494,8 @@ Assume point is at the beginning of the block."
(forward-line)
(point)))
(end (save-excursion (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'center-block
(nconc
(list :begin begin
@@ -544,7 +545,8 @@ Assume point is at beginning of drawer."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'drawer
(nconc
(list :begin begin
@@ -599,7 +601,8 @@ Assume point is at beginning of dynamic block."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'dynamic-block
(nconc
(list :begin begin
@@ -654,7 +657,8 @@ Assume point is at the beginning of the footnote definition."
(contents-end (and contents-begin ending))
(end (progn (goto-char ending)
(skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'footnote-definition
(nconc
(list :label label
@@ -905,7 +909,8 @@ Assume point is at beginning of the inline task."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position))))
(inlinetask
(list 'inlinetask
(nconc
@@ -1109,7 +1114,8 @@ Assume point is at the beginning of the list."
(unless (bolp) (forward-line))
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
;; Return value.
(list 'plain-list
(nconc
@@ -1163,7 +1169,8 @@ Assume point is at the beginning of the block."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'quote-block
(nconc
(list :begin begin
@@ -1245,8 +1252,9 @@ Assume point is at the beginning of the block."
(pos-before-blank (progn (goto-char block-end-line)
(forward-line)
(point)))
- (end (progn (org-skip-whitespace)
- (if (eobp) (point) (point-at-bol)))))
+ (end (progn (skip-chars-forward " \r\t\n" limit)
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'special-block
(nconc
(list :type type
@@ -1297,7 +1305,8 @@ keywords."
(begin (point-at-bol))
(pos-before-blank (progn (forward-line) (point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'babel-call
(list :begin begin
:end end
@@ -1340,7 +1349,8 @@ as keywords."
(status (if time 'closed 'running))
(post-blank (let ((before-blank (progn (forward-line) (point))))
(skip-chars-forward " \r\t\n" limit)
- (unless (eobp) (beginning-of-line))
+ (skip-chars-backward " \t")
+ (unless (bolp) (end-of-line))
(count-lines before-blank (point))))
(end (point)))
(list 'clock
@@ -1398,7 +1408,8 @@ Assume point is at comment beginning."
(point)))
(end (progn (goto-char com-end)
(skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'comment
(nconc
(list :begin begin
@@ -1440,7 +1451,8 @@ Assume point is at comment block beginning."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position))))
(value (buffer-substring-no-properties
contents-begin contents-end)))
(list 'comment-block
@@ -1511,7 +1523,8 @@ containing `:begin', `:end', `:number-lines', `:preserve-indent',
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'example-block
(nconc
(list :begin begin
@@ -1568,7 +1581,8 @@ Assume point is at export-block beginning."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position))))
(value (buffer-substring-no-properties contents-begin
contents-end)))
(list 'export-block
@@ -1618,7 +1632,8 @@ Assume point is at the beginning of the fixed-width area."
(forward-line))
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'fixed-width
(nconc
(list :begin begin
@@ -1648,7 +1663,8 @@ containing `:begin', `:end' and `:post-blank' keywords."
(begin (car keywords))
(post-hr (progn (forward-line) (point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'horizontal-rule
(nconc
(list :begin begin
@@ -1681,7 +1697,8 @@ keywords."
(match-end 0) (point-at-eol))))
(pos-before-blank (progn (forward-line) (point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'keyword
(list :key key
:value value
@@ -1723,7 +1740,8 @@ Assume point is at the beginning of the latex environment."
(point)))
(value (buffer-substring-no-properties code-begin code-end))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'latex-environment
(nconc
(list :begin begin
@@ -1823,7 +1841,8 @@ Assume point is at the beginning of the paragraph."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'paragraph
(nconc
(list :begin begin
@@ -1854,7 +1873,8 @@ and `:post-blank' keywords."
(begin (point))
(post-blank (let ((before-blank (progn (forward-line) (point))))
(skip-chars-forward " \r\t\n" limit)
- (unless (eobp) (beginning-of-line))
+ (skip-chars-backward " \t")
+ (unless (bolp) (end-of-line))
(count-lines before-blank (point))))
(end (point))
closed deadline scheduled)
@@ -1925,7 +1945,8 @@ Assume point is at the beginning of the property drawer."
(point-at-bol)))
(pos-before-blank (progn (forward-line) (point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'property-drawer
(list :begin begin
:end end
@@ -2042,7 +2063,8 @@ Assume point is at the beginning of the block."
(point)))
;; Get position after ending blank lines.
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'src-block
(nconc
(list :language language
@@ -2070,7 +2092,6 @@ CONTENTS is nil."
(params (org-element-property :parameters src-block))
(value (let ((val (org-element-property :value src-block)))
(cond
-
(org-src-preserve-indentation val)
((zerop org-edit-src-content-indentation)
(org-remove-indentation val))
@@ -2106,7 +2127,10 @@ Assume point is at the beginning of the table."
(type (if (org-at-table.el-p) 'table.el 'org))
(keywords (org-element--collect-affiliated-keywords))
(begin (car keywords))
- (table-end (goto-char (marker-position (org-table-end t))))
+ (table-end
+ (if (re-search-forward org-table-any-border-regexp limit 'm)
+ (goto-char (match-beginning 0))
+ (point)))
(tblfm (let (acc)
(while (looking-at "[ \t]*#\\+TBLFM: +\\(.*\\)[ \t]*$")
(push (org-match-string-no-properties 1) acc)
@@ -2114,7 +2138,8 @@ Assume point is at the beginning of the table."
acc))
(pos-before-blank (point))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'table
(nconc
(list :begin begin
@@ -2211,7 +2236,8 @@ Assume point is at beginning of the block."
(forward-line)
(point)))
(end (progn (skip-chars-forward " \r\t\n" limit)
- (if (eobp) (point) (point-at-bol)))))
+ (skip-chars-backward " \t")
+ (if (bolp) (point) (line-end-position)))))
(list 'verse-block
(nconc
(list :begin begin
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 3467eab..887ca1b 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -1548,7 +1548,9 @@ Outside list"
(length (org-element-property
:tblfm
(org-element-map
- (org-element-parse-buffer) 'table 'identity nil t)))))))
+ (org-element-parse-buffer) 'table 'identity nil t))))))
+ ;; Do not error when parsing a table with trailing white spaces.
+ (should (org-test-with-temp-text "| a |\n " (org-element-parse-buffer))))
;;;; Table Cell