emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: Babel result block '#+end_example' not indented [9.0.9 (release_9.0.9-748-g3359e0 @ /Users/xcy/src/org-mode/lisp/)]
@ 2017-08-13  7:46 Chunyang Xu
  2017-08-13  7:57 ` Chunyang Xu
  0 siblings, 1 reply; 3+ messages in thread
From: Chunyang Xu @ 2017-08-13  7:46 UTC (permalink / raw)
  To: emacs-orgmode

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


For example (noticing the last line '#+end_example' is not indented with
two space)

* test
  #+BEGIN_SRC sh :results output
  seq 10
  #+END_SRC

  #+RESULTS:
  #+begin_example
  1
  2
  3
  4
  5
  6
  7
  8
  9
  10
#+end_example


By reading the source code, I think 'indent-rigidly' doesn't the correct
end bound so the last line is not indented

(defun org-babel-insert-result (result &optional result-params info hash lang)
  ...
  (org-babel-examplify-region beg end results-switches inline)
  (setq end (point))
  ...
  (indent-rigidly beg end indent)
  ...
  )

'org-babel-examplify-region' wraps the result within
#+begin_example..#+end_example but doesn't move the point forward by one
line because of using save-excursion.

I attach a patch which uses the marker 'end' to track where the result
block ends, instead of (point). I have tested it against Emacs
24.5 and 25.2 slightly.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-core-Fix-indentation.patch --]
[-- Type: text/x-patch, Size: 2329 bytes --]

From f48e1dfc70e7f91fe39c5545997e84855981db82 Mon Sep 17 00:00:00 2001
From: Chunyang Xu <mail@xuchunyang.me>
Date: Sun, 13 Aug 2017 15:08:52 +0800
Subject: [PATCH] ob-core: Fix indentation

* lisp/ob-core.el (org-babel-insert-result): Track the end position of the
result block with the marker 'end'.

TINYCHANGE
---
 lisp/ob-core.el | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index f8a660312..cb4d463a4 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2290,7 +2290,9 @@ INFO may provide the values of these header arguments (in the
 				(org-escape-code-in-region (min (point) end) end))
 			      (goto-char end)
 			      (unless no-newlines (goto-char (point-at-eol)))
-			      (setq end (point-marker))))
+			      (when (markerp end) (set-marker end nil))
+			      (setq end (point-marker))
+			      (set-marker-insertion-type end t)))
 		      (tabulablep
 		       (lambda (r)
 			 ;; Non-nil when result R can be turned into
@@ -2345,6 +2347,7 @@ INFO may provide the values of these header arguments (in the
 			     (org-babel-chomp result "\n"))))
 		   (t (goto-char beg) (insert result)))
 		  (setq end (point-marker))
+		  (set-marker-insertion-type end t)
 		  ;; possibly wrap result
 		  (cond
 		   ((assq :wrap (nth 2 info))
@@ -2384,8 +2387,7 @@ INFO may provide the values of these header arguments (in the
 			   ;; Hard code {{{results(...)}}} on top of customization.
 			   (format "{{{results(%s)}}}"
 				   org-babel-inline-result-wrap)))
-		      (org-babel-examplify-region beg end results-switches inline)
-		      (setq end (point))))))
+		      (org-babel-examplify-region beg end results-switches inline)))))
 		;; Possibly indent results in par with #+results line.
 		(when (and (not inline) (numberp indent) (> indent 0)
 			   ;; In this case `table-align' does the work
@@ -2398,6 +2400,7 @@ INFO may provide the values of these header arguments (in the
 			(message "Code block returned no value.")
 		      (message "Code block produced no output."))
 		  (message "Code block evaluation complete.")))
+	    (when (markerp end) (set-marker end nil))
 	    (when outside-scope (narrow-to-region visible-beg visible-end))
 	    (set-marker visible-beg nil)
 	    (set-marker visible-end nil)))))))
-- 
2.14.1


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

* Re: Bug: Babel result block '#+end_example' not indented [9.0.9 (release_9.0.9-748-g3359e0 @ /Users/xcy/src/org-mode/lisp/)]
  2017-08-13  7:46 Bug: Babel result block '#+end_example' not indented [9.0.9 (release_9.0.9-748-g3359e0 @ /Users/xcy/src/org-mode/lisp/)] Chunyang Xu
@ 2017-08-13  7:57 ` Chunyang Xu
  2017-08-13 14:22   ` Nicolas Goaziou
  0 siblings, 1 reply; 3+ messages in thread
From: Chunyang Xu @ 2017-08-13  7:57 UTC (permalink / raw)
  To: emacs-orgmode

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


I find my last patch breaks at least ":result org", please see the newer
patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ob-core-Fix-indentation.patch --]
[-- Type: text/x-patch, Size: 1926 bytes --]

From 4ef5b67af22469bf2591dda0b9b90db1f4df8617 Mon Sep 17 00:00:00 2001
From: Chunyang Xu <mail@xuchunyang.me>
Date: Sun, 13 Aug 2017 15:08:52 +0800
Subject: [PATCH] ob-core: Fix indentation

* lisp/ob-core.el (org-babel-insert-result): Track the end position of the
result block with the marker 'end'.

TINYCHANGE
---
 lisp/ob-core.el | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index f8a660312..dd1efb710 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2290,6 +2290,7 @@ INFO may provide the values of these header arguments (in the
 				(org-escape-code-in-region (min (point) end) end))
 			      (goto-char end)
 			      (unless no-newlines (goto-char (point-at-eol)))
+			      (when (markerp end) (set-marker end nil))
 			      (setq end (point-marker))))
 		      (tabulablep
 		       (lambda (r)
@@ -2384,8 +2385,8 @@ INFO may provide the values of these header arguments (in the
 			   ;; Hard code {{{results(...)}}} on top of customization.
 			   (format "{{{results(%s)}}}"
 				   org-babel-inline-result-wrap)))
-		      (org-babel-examplify-region beg end results-switches inline)
-		      (setq end (point))))))
+		      (set-marker-insertion-type end t)
+		      (org-babel-examplify-region beg end results-switches inline)))))
 		;; Possibly indent results in par with #+results line.
 		(when (and (not inline) (numberp indent) (> indent 0)
 			   ;; In this case `table-align' does the work
@@ -2398,6 +2399,7 @@ INFO may provide the values of these header arguments (in the
 			(message "Code block returned no value.")
 		      (message "Code block produced no output."))
 		  (message "Code block evaluation complete.")))
+	    (when (markerp end) (set-marker end nil))
 	    (when outside-scope (narrow-to-region visible-beg visible-end))
 	    (set-marker visible-beg nil)
 	    (set-marker visible-end nil)))))))
-- 
2.14.1


[-- Attachment #3: Type: text/plain, Size: 3544 bytes --]


Chunyang Xu <mail@xuchunyang.me> writes:

> For example (noticing the last line '#+end_example' is not indented with
> two space)
>
> * test
>   #+BEGIN_SRC sh :results output
>   seq 10
>   #+END_SRC
>
>   #+RESULTS:
>   #+begin_example
>   1
>   2
>   3
>   4
>   5
>   6
>   7
>   8
>   9
>   10
> #+end_example
>
>
> By reading the source code, I think 'indent-rigidly' doesn't the correct
> end bound so the last line is not indented
>
> (defun org-babel-insert-result (result &optional result-params info hash lang)
>   ...
>   (org-babel-examplify-region beg end results-switches inline)
>   (setq end (point))
>   ...
>   (indent-rigidly beg end indent)
>   ...
>   )
>
> 'org-babel-examplify-region' wraps the result within
> #+begin_example..#+end_example but doesn't move the point forward by one
> line because of using save-excursion.
>
> I attach a patch which uses the marker 'end' to track where the result
> block ends, instead of (point). I have tested it against Emacs
> 24.5 and 25.2 slightly.
>
> From f48e1dfc70e7f91fe39c5545997e84855981db82 Mon Sep 17 00:00:00 2001
> From: Chunyang Xu <mail@xuchunyang.me>
> Date: Sun, 13 Aug 2017 15:08:52 +0800
> Subject: [PATCH] ob-core: Fix indentation
>
> * lisp/ob-core.el (org-babel-insert-result): Track the end position of the
> result block with the marker 'end'.
>
> TINYCHANGE
> ---
>  lisp/ob-core.el | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/lisp/ob-core.el b/lisp/ob-core.el
> index f8a660312..cb4d463a4 100644
> --- a/lisp/ob-core.el
> +++ b/lisp/ob-core.el
> @@ -2290,7 +2290,9 @@ INFO may provide the values of these header arguments (in the
>  				(org-escape-code-in-region (min (point) end) end))
>  			      (goto-char end)
>  			      (unless no-newlines (goto-char (point-at-eol)))
> -			      (setq end (point-marker))))
> +			      (when (markerp end) (set-marker end nil))
> +			      (setq end (point-marker))
> +			      (set-marker-insertion-type end t)))
>  		      (tabulablep
>  		       (lambda (r)
>  			 ;; Non-nil when result R can be turned into
> @@ -2345,6 +2347,7 @@ INFO may provide the values of these header arguments (in the
>  			     (org-babel-chomp result "\n"))))
>  		   (t (goto-char beg) (insert result)))
>  		  (setq end (point-marker))
> +		  (set-marker-insertion-type end t)
>  		  ;; possibly wrap result
>  		  (cond
>  		   ((assq :wrap (nth 2 info))
> @@ -2384,8 +2387,7 @@ INFO may provide the values of these header arguments (in the
>  			   ;; Hard code {{{results(...)}}} on top of customization.
>  			   (format "{{{results(%s)}}}"
>  				   org-babel-inline-result-wrap)))
> -		      (org-babel-examplify-region beg end results-switches inline)
> -		      (setq end (point))))))
> +		      (org-babel-examplify-region beg end results-switches inline)))))
>  		;; Possibly indent results in par with #+results line.
>  		(when (and (not inline) (numberp indent) (> indent 0)
>  			   ;; In this case `table-align' does the work
> @@ -2398,6 +2400,7 @@ INFO may provide the values of these header arguments (in the
>  			(message "Code block returned no value.")
>  		      (message "Code block produced no output."))
>  		  (message "Code block evaluation complete.")))
> +	    (when (markerp end) (set-marker end nil))
>  	    (when outside-scope (narrow-to-region visible-beg visible-end))
>  	    (set-marker visible-beg nil)
>  	    (set-marker visible-end nil)))))))
> -- 
> 2.14.1
>

-- 
Org mode version 9.0.9 (release_9.0.9-749-g4ef5b6 @
/Users/xcy/src/org-mode/lisp/)

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

* Re: Bug: Babel result block '#+end_example' not indented [9.0.9 (release_9.0.9-748-g3359e0 @ /Users/xcy/src/org-mode/lisp/)]
  2017-08-13  7:57 ` Chunyang Xu
@ 2017-08-13 14:22   ` Nicolas Goaziou
  0 siblings, 0 replies; 3+ messages in thread
From: Nicolas Goaziou @ 2017-08-13 14:22 UTC (permalink / raw)
  To: Chunyang Xu; +Cc: emacs-orgmode

Hello,

Chunyang Xu <mail@xuchunyang.me> writes:

> I find my last patch breaks at least ":result org", please see the newer
> patch.

Thank you for the report and the patch. I ended up applying a slightly
different patch, however.

Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2017-08-13 14:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-13  7:46 Bug: Babel result block '#+end_example' not indented [9.0.9 (release_9.0.9-748-g3359e0 @ /Users/xcy/src/org-mode/lisp/)] Chunyang Xu
2017-08-13  7:57 ` Chunyang Xu
2017-08-13 14:22   ` Nicolas Goaziou

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).