Hello, I have this MWE:
#+TITLE: Org babel tangle and noweb #+PROPERTY: header-args:shell :shebang "#!/usr/bin/env bash" * Shell Script #+BEGIN_SRC shell :noweb yes :tangle code.sh exec emacs -Q "$@" \ --eval '(progn <<elisp>> )' 2>/dev/null </dev/tty #+END_SRC * Emacs Configuration #+BEGIN_SRC emacs-lisp :noweb-ref elisp :noweb-sep "\\n\\n" (menu-bar-mode -1) #+END_SRC Some comment. #+BEGIN_SRC emacs-lisp :noweb-ref elisp (line-number-mode 1) #+END_SRC When tangled (C-c C-v t), it generates: [image: image.png] Notice that the empty line is created between noweb segments as expected because of ":noweb-sep "\\n\\n"". But what was unexpected to me was the creation of empty line with spaces inserted to match the indentation. Is this by design? If it is by design, I would propose to have a new switch called something like ":noweb-notrailingspc" (would like a better suggestion for this switch name). So the src block where noweb expansion needs to happen will look like this: #+BEGIN_SRC shell :noweb yes :tangle code.sh :noweb-notrailingspc yes exec emacs -Q "$@" \ --eval '(progn <<elisp>> )' 2>/dev/null </dev/tty #+END_SRC Now, tangling will generate [image: image.png] Here is a diff (without whitespace differences) of the change I made to ob-core locally to get this: diff --git a/lisp/ob-core.el b/lisp/ob-core.el index cb332ffea92..0f04d8b85e1 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\r]*\n" "\n" body-str))) + (funcall nb-add body-str))) (funcall nb-add (buffer-substring index (point-max)))) new-body)) Questions: 1. If the above empty lines with prefix number of spaces are not expected, the fix would be simpler.. to just throw in that (setq body-str (replace-regexp-in-string "^[ \n\r]*\n" "\n" body-str)) form in-between. 2a. If the spacey empty lines are as per design, then does this diff look good? Should I work on a proper patch? 2b. What would be a better/more intuitive switch name than ":noweb-notrailingspc"? -- Kaushal Modi