On Sat, May 6, 2017 at 2:30 AM Kaushal Modi wrote: > + (setq body-str (replace-regexp-in-string "^[ \n\r]*\n" "\n" > body-str))) > > Just one correction to this regexp so that two or more consecutive empty lines in the source block get retained: (setq body-str (replace-regexp-in-string "^[ ]+\n" "\n" body-str)) Here's the draft diff again: diff --git a/lisp/ob-core.el b/lisp/ob-core.el index cb332ffea92..96628f44ab4 100644 --- a/lisp/ob-core.el +++ b/lisp/ob-core.el @@ -2730,9 +2730,7 @@ block but are passed literally to the \"example-block\"." (funcall nb-add (buffer-substring index (point))) (goto-char (match-end 0)) (setq index (point)) - (funcall - nb-add - (with-current-buffer parent-buffer + (let ((body-str (with-current-buffer parent-buffer (save-restriction (widen) (mapconcat ;; Interpose PREFIX between every line. @@ -2794,6 +2792,9 @@ block but are passed literally to the \"example-block\"." "`org-babel-noweb-error-langs')")) ""))) "[\n\r]") (concat "\n" prefix)))))) + (when (string= "yes" (cdr (assq :noweb-notrailingspc (nth 2 info)))) + (setq body-str (replace-regexp-in-string "^[ ]+\n" "\n" body-str))) + (funcall nb-add body-str))) (funcall nb-add (buffer-substring index (point-max)))) new-body)) -- Kaushal Modi