summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2018-07-02 00:24:38 +0200
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2018-07-02 00:24:38 +0200
commit7d9e4da447fa54633daf75a241c6b0a603c0e662 (patch)
treefc684d739fa88665a4d2aa13a4313b378f85593d
parent937e7ce76b887d7049c7e37a19a1e7b4ab8936d8 (diff)
downloadorg-mode-7d9e4da447fa54633daf75a241c6b0a603c0e662.tar.gz
Prevent spurious newline character in fixed-width area value
* lisp/org-element.el (org-element-fixed-width-parser): Prevent spurious newline character at the end of the value. * lisp/ox-latex.el (org-latex-fixed-width): * lisp/ox-man.el (org-man-fixed-width): * lisp/ox-texinfo.el (org-texinfo-fixed-width): * contrib/lisp/ox-groff.el (org-groff-fixed-width): Adapt to change. * testing/lisp/test-org-element.el (test-org-element/fixed-width-parser): Update tests. Reported-by: 孙振祥 <sunznx@icloud.com> <http://lists.gnu.org/archive/html/emacs-orgmode/2018-07/msg00003.html>
-rw-r--r--contrib/lisp/ox-groff.el2
-rw-r--r--lisp/org-element.el19
-rw-r--r--lisp/ox-latex.el2
-rw-r--r--lisp/ox-man.el2
-rw-r--r--lisp/ox-texinfo.el2
-rw-r--r--testing/lisp/test-org-element.el36
6 files changed, 25 insertions, 38 deletions
diff --git a/contrib/lisp/ox-groff.el b/contrib/lisp/ox-groff.el
index 14bc2ce..85e24a5 100644
--- a/contrib/lisp/ox-groff.el
+++ b/contrib/lisp/ox-groff.el
@@ -902,7 +902,7 @@ CONTENTS is nil. INFO is a plist holding contextual information."
CONTENTS is nil. INFO is a plist holding contextual information."
(org-groff--wrap-label
fixed-width
- (format "\\fC\n%s\\fP"
+ (format "\\fC\n%s\n\\fP"
(org-remove-indentation
(org-element-property :value fixed-width)))))
diff --git a/lisp/org-element.el b/lisp/org-element.el
index fde0209..d757e65 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -2072,26 +2072,22 @@ Assume point is at the beginning of the fixed-width area."
(save-excursion
(let* ((begin (car affiliated))
(post-affiliated (point))
- value
(end-area
(progn
(while (and (< (point) limit)
(looking-at "[ \t]*:\\( \\|$\\)"))
- ;; Accumulate text without starting colons.
- (setq value
- (concat value
- (buffer-substring-no-properties
- (match-end 0) (point-at-eol))
- "\n"))
(forward-line))
- (point)))
+ (if (bolp) (line-end-position 0) (point))))
(end (progn (skip-chars-forward " \r\t\n" limit)
(if (eobp) (point) (line-beginning-position)))))
(list 'fixed-width
(nconc
(list :begin begin
:end end
- :value value
+ :value (replace-regexp-in-string
+ "^[ \t]*: ?" ""
+ (buffer-substring-no-properties post-affiliated
+ end-area))
:post-blank (count-lines end-area end)
:post-affiliated post-affiliated)
(cdr affiliated))))))
@@ -2099,10 +2095,7 @@ Assume point is at the beginning of the fixed-width area."
(defun org-element-fixed-width-interpreter (fixed-width _)
"Interpret FIXED-WIDTH element as Org syntax."
(let ((value (org-element-property :value fixed-width)))
- (and value
- (replace-regexp-in-string
- "^" ": "
- (if (string-match "\n\\'" value) (substring value 0 -1) value)))))
+ (and value (replace-regexp-in-string "^" ": " value))))
;;;; Horizontal Rule
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index c67f217..7191a39 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1852,7 +1852,7 @@ CONTENTS is nil. INFO is a plist holding contextual information."
CONTENTS is nil. INFO is a plist holding contextual information."
(org-latex--wrap-label
fixed-width
- (format "\\begin{verbatim}\n%s\\end{verbatim}"
+ (format "\\begin{verbatim}\n%s\n\\end{verbatim}"
(org-remove-indentation
(org-element-property :value fixed-width)))
info))
diff --git a/lisp/ox-man.el b/lisp/ox-man.el
index 2bc6392..1bcfa7b 100644
--- a/lisp/ox-man.el
+++ b/lisp/ox-man.el
@@ -424,7 +424,7 @@ CONTENTS is nil. INFO is a plist holding contextual information."
CONTENTS is nil. INFO is a plist holding contextual information."
(org-man--wrap-label
fixed-width
- (format "\\fC\n%s\\fP"
+ (format "\\fC\n%s\n\\fP"
(org-remove-indentation
(org-element-property :value fixed-width)))))
diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index c58f47f..7bfdc03 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -825,7 +825,7 @@ CONTENTS is nil. INFO is a plist holding contextual information."
(defun org-texinfo-fixed-width (fixed-width _contents _info)
"Transcode a FIXED-WIDTH element from Org to Texinfo.
CONTENTS is nil. INFO is a plist holding contextual information."
- (format "@example\n%s@end example"
+ (format "@example\n%s\n@end example"
(org-remove-indentation
(org-texinfo--sanitize-content
(org-element-property :value fixed-width)))))
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 2155f27..5685159 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -900,29 +900,32 @@ Some other text
"Test fixed-width area parsing."
;; Preserve indentation.
(should
- (org-test-with-temp-text ": no blank\n: one blank"
- (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
+ (equal "no blank\n one blank"
+ (org-test-with-temp-text ": no blank\n: one blank"
+ (org-element-property :value (org-element-at-point)))))
;; Fixed-width with empty lines.
(should
- (org-test-with-temp-text ": first part\n:\n: \n: second part"
- (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
+ (equal "first part\n\n\nsecond part"
+ (org-test-with-temp-text ": first part\n:\n: \n: second part"
+ (org-element-property :value (org-element-at-point)))))
;; Parse indented fixed-width markers.
(should
- (org-test-with-temp-text "Text\n : no blank\n : one blank"
- (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))
+ (eq 'fixed-width
+ (org-test-with-temp-text "Text\n<point> : no blank\n : one blank"
+ (org-element-type (org-element-at-point)))))
;; Distinguish fixed-width areas within a list and outside of it.
(should
- (= 2
- (length
- (org-test-with-temp-text "
+ (org-test-with-temp-text "
- Item
- : fixed-width inside
+ : fixed-width inside<point>
: fixed-width outside"
- (org-element-map (org-element-parse-buffer) 'fixed-width 'identity)))))
+ (= (org-element-property :end (org-element-at-point))
+ (line-beginning-position 2))))
;; Handle non-empty blank line at the end of buffer.
(should
(org-test-with-temp-text ": A\n "
- (= (org-element-property :end (org-element-at-point)) (point-max)))))
+ (= (org-element-property :end (org-element-at-point))
+ (point-max)))))
;;;; Footnote Definition
@@ -2859,15 +2862,6 @@ CLOCK: [2012-01-01 sun. 00:01]--[2012-01-01 sun. 00:02] => 0:01"))))
;; Preserve indentation.
(should (equal (org-test-parse-and-interpret ": 2 blanks\n: 1 blank")
": 2 blanks\n: 1 blank\n"))
- ;; Remove last newline character
- (should
- (equal (org-element-fixed-width-interpreter
- '(fixed-width (:value "Test\n")) nil)
- ": Test"))
- (should
- (equal (org-element-fixed-width-interpreter
- '(fixed-width (:value "Test")) nil)
- ": Test"))
;; Handle empty string.
(should
(equal (org-element-fixed-width-interpreter