On Sat, May 6, 2017, 3:23 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
Hello,

Kaushal Modi <kaushal.modi@gmail.com> writes:

I'd rather clean every empty line upon tangling, or let the user do it
with `org-babel-post-tangle-hook'.

I just tried this again and it worked this time!

    (add-hook 'org-babel-post-tangle-hook #'delete-trailing-whitespace)
    (add-hook 'org-babel-post-tangle-hook #'save-buffer :append)

Thanks!

Some back-story on what led me to modify ob-core.el:

I did try changing the hook earlier, but that did not work. So this was my next attempt[1], and that led me to try this approach of preventing white spaces in the first place. 

Earlier I was also trying to tangle using ox-publish with this element in org-publish-project-alist:

        ("foo"
         :base-directory "/some/dir"
         :publishing-function org-babel-tangle-publish
         :publishing-directory "/some/dir")

Probably the base directory and publishing directory being the same caused some issue with saving the buffer after delete-trailing-whitespace. So I ended up having to manually save the tangled file after each publish step.

Or probably I somehow didn't have the hooks right.

After that I switched to calling just the below separately instead of tangling through publish step:

    (org-babel-tangle file FILE)

And now with the above hook modifications, the deletion of whitespaces is working exactly as I wanted.

Well, that was an interesting journey.

[1]: https://github.com/kaushalmodi/eless/blob/aa060eaede906e6bd4205f997074e7048c0c810c/build/build.el#L28-L47
--

Kaushal Modi