From mboxrd@z Thu Jan 1 00:00:00 1970 From: Chunyang Xu Subject: Bug: Babel result block '#+end_example' not indented [9.0.9 (release_9.0.9-748-g3359e0 @ /Users/xcy/src/org-mode/lisp/)] Date: Sun, 13 Aug 2017 15:46:28 +0800 Message-ID: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:40824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dgncG-0002t1-TQ for emacs-orgmode@gnu.org; Sun, 13 Aug 2017 03:47:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dgncE-0000xk-B1 for emacs-orgmode@gnu.org; Sun, 13 Aug 2017 03:47:20 -0400 Received: from smtpbguseast2.qq.com ([54.204.34.130]:39661) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dgncE-0000R5-5K for emacs-orgmode@gnu.org; Sun, 13 Aug 2017 03:47:18 -0400 Received: from Chunyangs-MacBook-Air.local (unknown [180.126.146.56]) by esmtp4.qq.com (ESMTP) with SMTP id 0 for ; Sun, 13 Aug 2017 15:46:14 +0800 (CST) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain 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. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-ob-core-Fix-indentation.patch >From f48e1dfc70e7f91fe39c5545997e84855981db82 Mon Sep 17 00:00:00 2001 From: Chunyang Xu 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 --=-=-=--