emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Should comments break paragraphs?


From: Eric Schulte
Subject: Re: [O] Should comments break paragraphs?
Date: Tue, 16 Jul 2013 09:46:26 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Nicolas Goaziou <address@hidden> writes:

> Hello,
>
> Christian Wittern <address@hidden> writes:
>
>> Hmm.  In my book, the concept of comments implies that they should be
>> able to appear on any line in the text, without altering the meaning
>> of the context it appears in.  So to me, it would seem necessary to
>> treat comments as special, different from other elements.
>
> I don't think comments make much sense anywhere in Org (e.g., in an
> example block or in a source block). Also Org has no inline comment
> syntax (and I don't think it needs one: it is no programming language).
> So comments do not really fit in paragraphs.
>

When Org-mode is used as a document preparation language inline comments
are very useful.  The use case being notes on the surrounding material
which are not to be published.  Both HTML and LaTeX support comments and
at least in LaTeX they are extensively used (in my experience) and can
be very helpful.

>
> Last, but not least, it is also easier to parse it that way.
>

Stripping lines starting with "^ *#[^+]" is a trivial pre-processing
step, and would support the traditional Org-mode comments which (as I
recall) could previously appear mid paragraph without causing problems.

>
> Now, if you want to improve comments anyway, you can always provide
> patches. There's some non-trivial work involved, though.
>

The attached patch worked on some small example files for me.

>From ce4c30ebe56d4cd66810bca48824d8841e7b130d Mon Sep 17 00:00:00 2001
From: Eric Schulte <address@hidden>
Date: Tue, 16 Jul 2013 09:44:59 -0600
Subject: [PATCH] support inline comments w/o breaking paragraphs

* lisp/org-element.el (org-element-parse-buffer): Strip inline comments
  as a pre-processing step before exporting.
---
 lisp/org-element.el | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 8d64657..d69d9ba 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4092,13 +4092,19 @@ or objects within the parse tree.
 
 This function assumes that current major mode is `org-mode'."
   (save-excursion
-    (goto-char (point-min))
-    (org-skip-whitespace)
-    (org-element--parse-elements
-     (point-at-bol) (point-max)
-     ;; Start in `first-section' mode so text before the first
-     ;; headline belongs to a section.
-     'first-section nil granularity visible-only (list 'org-data nil))))
+    (let ((save (buffer-string)))
+      (unwind-protect
+         (progn
+           (goto-char (point-min))
+           (delete-matching-lines "^ *# .[^\n]*\n")
+           (org-skip-whitespace)
+           (org-element--parse-elements
+            (point-at-bol) (point-max)
+            ;; Start in `first-section' mode so text before the first
+            ;; headline belongs to a section.
+            'first-section nil granularity visible-only (list 'org-data nil)))
+       (delete-region (point-min) (point-max))
+       (insert save)))))
 
 (defun org-element-parse-secondary-string (string restriction &optional parent)
   "Recursively parse objects in STRING and return structure.
-- 
1.8.3.2

Cheers,

>
>
> Regards,

-- 
Eric Schulte
http://cs.unm.edu/~eschulte

reply via email to

[Prev in Thread] Current Thread [Next in Thread]