branch: externals/org
commit 960722661080698e363dd977453599a3ec89b046
Author: Ihor Radchenko <yanta...@posteo.net>
Commit: Ihor Radchenko <yanta...@posteo.net>

    org-export--prune-tree: Ensure spaces when removing objects
    
    * lisp/ox.el (org-export--prune-tree): If the removed object has
    trailing spaces and previous object does not have, keep the trailing
    spaces.
    * etc/ORG-NEWS (Blank lines after removed objects are not retained
    during export): Document the change.
    
    Reported-by: Andrea Lazzarini <andrea.lazzari...@gmail.com>
    Link: https://orgmode.org/list/87o7p7z9k3.fsf@localhost
---
 etc/ORG-NEWS | 21 +++++++++++++++++++++
 lisp/ox.el   | 19 ++++++++++++++++++-
 2 files changed, 39 insertions(+), 1 deletion(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 58ac17349a..b6acafc3d1 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -202,6 +202,27 @@ execution completes.  The new ~:async~ header allows users 
to continue
 editing with Emacs while a ~:session~ block executes.
 
 ** Miscellaneous
+*** Blank lines after removed objects are not retained during export
+
+When certain objects in Org document are to be excluded from export,
+spaces after these objects were previously removed as well.
+
+For example, if ~org-export-with-footnotes~ is set to nil, the footnote in
+
+: Pellentesque dapibus suscipit ligula.[fn:1]  Donec posuere augue in quam.
+
+would be removed, leading to the following exported ASCII document
+
+: Pellentesque dapibus suscipit ligula.Donec posuere augue in quam.
+
+This is because spaces after footnote (and other markup) are
+considered a part of the preceding AST object in Org.
+
+Now, unless there is a whitespace before an object to be removed,
+spaces are preserved during export:
+
+: Pellentesque dapibus suscipit ligula.  Donec posuere augue in quam.
+
 *** Remove undocumented ~:target~ header parameter in ~ob-clojure~
 
 The ~:target~ header was only used internally to distinguish
diff --git a/lisp/ox.el b/lisp/ox.el
index 9a6e037b40..8be60985f3 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -2754,7 +2754,24 @@ from tree."
                (let ((type (org-element-type data)))
                  (if (org-export--skip-p data info selected excluded)
                      (if (memq type '(table-cell table-row)) (push data ignore)
-                       (org-element-extract-element data))
+                       (let ((post-blank (org-element-property :post-blank 
data)))
+                         (if (or (not post-blank) (zerop post-blank)
+                                 (eq 'element (org-element-class data)))
+                             (org-element-extract-element data)
+                           ;; Keep spaces in place of removed
+                           ;; element, if necessary.
+                           ;; Example: "Foo.[10%] Bar" would become
+                           ;; "Foo.Bar" if we do not keep spaces.
+                           (let ((previous (org-export-get-previous-element 
data info)))
+                             (if (or (not previous)
+                                     (pcase (org-element-type previous)
+                                       (`plain-text
+                                        (string-match-p
+                                         (rx  whitespace eos) previous))
+                                       (_ (org-element-property :post-blank 
previous))))
+                                 ;; Previous object ends with whitespace 
already.
+                                 (org-element-extract-element data)
+                               (org-element-set-element data (make-string 
post-blank ?\s)))))))
                    (if (and (eq type 'headline)
                             (eq (plist-get info :with-archived-trees)
                                 'headline)

Reply via email to