emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] inline source breaks paragraphs
@ 2013-12-08 22:23 Andreas Leha
  2013-12-08 22:25 ` Andreas Leha
  2013-12-13 20:47 ` Nicolas Goaziou
  0 siblings, 2 replies; 6+ messages in thread
From: Andreas Leha @ 2013-12-08 22:23 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,

inline source -- when on its own line -- breaks the paragraph, which is
unexpected.

Here is a test file:

--8<---------------cut here---------------start------------->8---
* Test

This is a broken
src_R[:exports results :results raw]{10}
paragraph.
--8<---------------cut here---------------end--------------->8---


Here is (the relevant part of) the output of the LaTeX export:

,----
| \section{Test}
| \label{sec-1}
| 
| This is a broken
| 10
| 
| paragraph.
`----


Some info:
GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2013-09-27 on trouble, modified by Debian
Org-mode version 8.2.4 (release_8.2.4-332-g7059d3 @ /home/andreas/local/emacs/org-mode-install/lisp/)


Regards,
Andreas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] inline source breaks paragraphs
  2013-12-08 22:23 [BUG] inline source breaks paragraphs Andreas Leha
@ 2013-12-08 22:25 ` Andreas Leha
  2013-12-13 20:47 ` Nicolas Goaziou
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Leha @ 2013-12-08 22:25 UTC (permalink / raw)
  To: emacs-orgmode

Hi all,

I sent too quickly...

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> Hi all,
>
> inline source -- when on its own line -- breaks the paragraph, which is
                 ^^^^^^^^^^^^^^^^^^^^^^^^
                 delete that.........

> unexpected.
>
> Here is a test file:
>
> * Test
>
> This is a broken
> src_R[:exports results :results raw]{10}
> paragraph.
>
>
> Here is (the relevant part of) the output of the LaTeX export:
>
> ,----
> | \section{Test}
> | \label{sec-1}
> | 
> | This is a broken
> | 10
> | 
> | paragraph.
> `----
>
>
> Some info:
> GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, X toolkit, Xaw3d scroll bars) of 2013-09-27 on trouble, modified by Debian
> Org-mode version 8.2.4 (release_8.2.4-332-g7059d3 @ /home/andreas/local/emacs/org-mode-install/lisp/)
>
>
> Regards,
> Andreas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] inline source breaks paragraphs
  2013-12-08 22:23 [BUG] inline source breaks paragraphs Andreas Leha
  2013-12-08 22:25 ` Andreas Leha
@ 2013-12-13 20:47 ` Nicolas Goaziou
  2013-12-13 23:30   ` Eric Schulte
  1 sibling, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2013-12-13 20:47 UTC (permalink / raw)
  To: Andreas Leha; +Cc: emacs-orgmode, Eric Schulte

[-- Attachment #1: Type: text/plain, Size: 578 bytes --]

Hello,

Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:

> inline source -- when on its own line -- breaks the paragraph, which is
> unexpected.
>
> Here is a test file:
>
> * Test
>
> This is a broken
> src_R[:exports results :results raw]{10}
> paragraph.
>
>
> Here is (the relevant part of) the output of the LaTeX export:
>
> ,----
> | \section{Test}
> | \label{sec-1}
> | 
> | This is a broken
> | 10
> | 
> | paragraph.
> `----

The attached patch solves the problem. It may be a bit intrusive,
though.

Eric, what do you think?


Regards,

-- 
Nicolas Goaziou

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-core-Preserve-paragraph-when-evaluating-inline-bl.patch --]
[-- Type: text/x-diff, Size: 1461 bytes --]

From 8ec02a2fa79b8601565ca7b226b8c1e4790f3439 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Fri, 13 Dec 2013 21:40:33 +0100
Subject: [PATCH] ob-core: Preserve paragraph when evaluating inline blocks

* lisp/ob-core.el (org-babel-insert-result): Trim whitespaces around
  results from inline source blocks.
---
 lisp/ob-core.el | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 84caed7..a6945e4 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2048,12 +2048,14 @@ code ---- the results are extracted in the syntax of the source
 				   (or (> visible-beg existing-result)
 				       (<= visible-end existing-result))))
 	     beg end)
-	(when (and (stringp result)  ; ensure results end in a newline
-		   (not inlinep)
-		   (> (length result) 0)
-		   (not (or (string-equal (substring result -1) "\n")
-			    (string-equal (substring result -1) "\r"))))
-	  (setq result (concat result "\n")))
+	;; Ensure inline results never end with a newline, but regular
+	;; results always do.
+	(cond ((not (stringp result)))
+	      (inlinep (setq result (org-babel-trim result)))
+	      ((and (> (length result) 0)
+		    (not (or (string-equal (substring result -1) "\n")
+			     (string-equal (substring result -1) "\r"))))
+	       (setq result (concat result "\n"))))
 	(unwind-protect
 	    (progn
 	      (when outside-scope-p (widen))
-- 
1.8.5.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [BUG] inline source breaks paragraphs
  2013-12-13 20:47 ` Nicolas Goaziou
@ 2013-12-13 23:30   ` Eric Schulte
  2013-12-14 11:27     ` Nicolas Goaziou
  2013-12-14 11:53     ` Andreas Leha
  0 siblings, 2 replies; 6+ messages in thread
From: Eric Schulte @ 2013-12-13 23:30 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Andreas Leha, emacs-orgmode

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Hello,
>
> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>
>> inline source -- when on its own line -- breaks the paragraph, which is
>> unexpected.
>>
>> Here is a test file:
>>
>> * Test
>>
>> This is a broken
>> src_R[:exports results :results raw]{10}
>> paragraph.
>>
>>
>> Here is (the relevant part of) the output of the LaTeX export:
>>
>> ,----
>> | \section{Test}
>> | \label{sec-1}
>> | 
>> | This is a broken
>> | 10
>> | 
>> | paragraph.
>> `----
>
> The attached patch solves the problem. It may be a bit intrusive,
> though.
>
> Eric, what do you think?
>

Invariably someone would then ask why the newline is being stripped from
their inline code block.

I think this is only necessary because the R code block is returning
"10\n" instead of 10.  Ideally this should be fixed in ob-R.el.

Best,

>
>
> Regards,
>
> -- 
> Nicolas Goaziou
>
> From 8ec02a2fa79b8601565ca7b226b8c1e4790f3439 Mon Sep 17 00:00:00 2001
> From: Nicolas Goaziou <n.goaziou@gmail.com>
> Date: Fri, 13 Dec 2013 21:40:33 +0100
> Subject: [PATCH] ob-core: Preserve paragraph when evaluating inline blocks
>
> * lisp/ob-core.el (org-babel-insert-result): Trim whitespaces around
>   results from inline source blocks.
> ---
>  lisp/ob-core.el | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
>
> diff --git a/lisp/ob-core.el b/lisp/ob-core.el
> index 84caed7..a6945e4 100644
> --- a/lisp/ob-core.el
> +++ b/lisp/ob-core.el
> @@ -2048,12 +2048,14 @@ code ---- the results are extracted in the syntax of the source
>  				   (or (> visible-beg existing-result)
>  				       (<= visible-end existing-result))))
>  	     beg end)
> -	(when (and (stringp result)  ; ensure results end in a newline
> -		   (not inlinep)
> -		   (> (length result) 0)
> -		   (not (or (string-equal (substring result -1) "\n")
> -			    (string-equal (substring result -1) "\r"))))
> -	  (setq result (concat result "\n")))
> +	;; Ensure inline results never end with a newline, but regular
> +	;; results always do.
> +	(cond ((not (stringp result)))
> +	      (inlinep (setq result (org-babel-trim result)))
> +	      ((and (> (length result) 0)
> +		    (not (or (string-equal (substring result -1) "\n")
> +			     (string-equal (substring result -1) "\r"))))
> +	       (setq result (concat result "\n"))))
>  	(unwind-protect
>  	    (progn
>  	      (when outside-scope-p (widen))

-- 
Eric Schulte
https://cs.unm.edu/~eschulte
PGP: 0x614CA05D

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] inline source breaks paragraphs
  2013-12-13 23:30   ` Eric Schulte
@ 2013-12-14 11:27     ` Nicolas Goaziou
  2013-12-14 11:53     ` Andreas Leha
  1 sibling, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2013-12-14 11:27 UTC (permalink / raw)
  To: Eric Schulte; +Cc: Andreas Leha, emacs-orgmode

Hello,

Eric Schulte <schulte.eric@gmail.com> writes:

> Invariably someone would then ask why the newline is being stripped from
> their inline code block.

True.

> I think this is only necessary because the R code block is returning
> "10\n" instead of 10.  Ideally this should be fixed in ob-R.el.

Ok, I'll let specialists handle the problem then.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [BUG] inline source breaks paragraphs
  2013-12-13 23:30   ` Eric Schulte
  2013-12-14 11:27     ` Nicolas Goaziou
@ 2013-12-14 11:53     ` Andreas Leha
  1 sibling, 0 replies; 6+ messages in thread
From: Andreas Leha @ 2013-12-14 11:53 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

Eric Schulte <schulte.eric@gmail.com> writes:

> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>
>> Hello,
>>
>> Andreas Leha <andreas.leha@med.uni-goettingen.de> writes:
>>
>>> inline source -- when on its own line -- breaks the paragraph, which is
>>> unexpected.
>>>
>>> Here is a test file:
>>>
>>> * Test
>>>
>>> This is a broken
>>> src_R[:exports results :results raw]{10}
>>> paragraph.
>>>
>>>
>>> Here is (the relevant part of) the output of the LaTeX export:
>>>
>>> ,----
>>> | \section{Test}
>>> | \label{sec-1}
>>> | 
>>> | This is a broken
>>> | 10
>>> | 
>>> | paragraph.
>>> `----
>>
>> The attached patch solves the problem. It may be a bit intrusive,
>> though.
>>
>> Eric, what do you think?
>>
>
> Invariably someone would then ask why the newline is being stripped from
> their inline code block.
>
> I think this is only necessary because the R code block is returning
> "10\n" instead of 10.  Ideally this should be fixed in ob-R.el.
>

Maybe the fix should ideally live in ob-R, but I do not agree that
someone should expect "10\n" to be returned from an inline source block.
For two reasons (I seem to remember to have read these on this list
before...)
1. The person who gets '10' but wants '10\n' can easily fix this in the
   inline source code.  The other way around I can not fix it.
2. At present, if the inline code returns '10\n' it does not stay
   inline.  So, why is it an inline code at the first place?  At least
   from the exported document's viewpoint then the inline code could as
   well be a regular code block.  So, what is the use of an inline block
   then?


My use-case is quite simple:
I quite often want small inline code blocks in my writing.  Something
like 'the sample size was n = src_R[:results raw]{nrow(P)}' 

In the mean time I'll go with Nicolas' patch -- thanks a lot, Nicolas!

Best,
Andreas




> Best,
>
>>
>>
>> Regards,
>>
>> -- 
>> Nicolas Goaziou
>>
>> From 8ec02a2fa79b8601565ca7b226b8c1e4790f3439 Mon Sep 17 00:00:00 2001
>> From: Nicolas Goaziou <n.goaziou@gmail.com>
>> Date: Fri, 13 Dec 2013 21:40:33 +0100
>> Subject: [PATCH] ob-core: Preserve paragraph when evaluating inline blocks
>>
>> * lisp/ob-core.el (org-babel-insert-result): Trim whitespaces around
>>   results from inline source blocks.
>> ---
>>  lisp/ob-core.el | 14 ++++++++------
>>  1 file changed, 8 insertions(+), 6 deletions(-)
>>
>> diff --git a/lisp/ob-core.el b/lisp/ob-core.el
>> index 84caed7..a6945e4 100644
>> --- a/lisp/ob-core.el
>> +++ b/lisp/ob-core.el
>> @@ -2048,12 +2048,14 @@ code ---- the results are extracted in the syntax of the source
>>  				   (or (> visible-beg existing-result)
>>  				       (<= visible-end existing-result))))
>>  	     beg end)
>> -	(when (and (stringp result)  ; ensure results end in a newline
>> -		   (not inlinep)
>> -		   (> (length result) 0)
>> -		   (not (or (string-equal (substring result -1) "\n")
>> -			    (string-equal (substring result -1) "\r"))))
>> -	  (setq result (concat result "\n")))
>> +	;; Ensure inline results never end with a newline, but regular
>> +	;; results always do.
>> +	(cond ((not (stringp result)))
>> +	      (inlinep (setq result (org-babel-trim result)))
>> +	      ((and (> (length result) 0)
>> +		    (not (or (string-equal (substring result -1) "\n")
>> +			     (string-equal (substring result -1) "\r"))))
>> +	       (setq result (concat result "\n"))))
>>  	(unwind-protect
>>  	    (progn
>>  	      (when outside-scope-p (widen))

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-12-14 11:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-08 22:23 [BUG] inline source breaks paragraphs Andreas Leha
2013-12-08 22:25 ` Andreas Leha
2013-12-13 20:47 ` Nicolas Goaziou
2013-12-13 23:30   ` Eric Schulte
2013-12-14 11:27     ` Nicolas Goaziou
2013-12-14 11:53     ` Andreas Leha

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).