Skip to content

Instantly share code, notes, and snippets.

@hkjels
Last active January 21, 2019 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hkjels/6c88840f00ab5715fbb00faae4fda0d7 to your computer and use it in GitHub Desktop.
Save hkjels/6c88840f00ab5715fbb00faae4fda0d7 to your computer and use it in GitHub Desktop.
Hook is run, code is executed, but the tangled files have the original content
(defun svg2code/transpileES5 ()
"Transpiles the current javascript-mode buffer from ES2015 to ES5"
(when (and (string-match ".js$" (buffer-file-name))
(not (string-match "exports.*" (buffer-file-name))))
(shell-command-on-region
(point-min) (point-max)
"babel --no-babelrc --compact false --presets env"
(current-buffer)
t
"*Babel Error Buffer*"
t)))
(defun svg2code/run-before-save-hook ()
(run-hooks 'before-save-hook)
(save-buffer))
(add-hook 'js-mode-hook (lambda () (add-hook 'before-save-hook 'svg2code/transpileES5)))
(add-hook 'org-babel-post-tangle-hook 'svg2code/run-before-save-hook)
@hkjels
Copy link
Author

hkjels commented Jan 21, 2019

Updated with a working version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment