Last active
October 3, 2023 12:23
-
-
Save cxa/2dbde60f608feac3e28bf69340528b04 to your computer and use it in GitHub Desktop.
Support `:stdin` for `ob-C` for org-mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(advice-add 'org-babel-C-execute | |
:filter-args | |
(defun sloth/org-babel-C-execute/filter-args (args) | |
(when-let* ((params (cadr args)) | |
(stdin (cdr (assoc :stdin params))) | |
(res (org-babel-ref-resolve stdin)) | |
(stdin (org-babel-temp-file "c-stdin-"))) | |
(with-temp-file stdin (insert res)) | |
(let* ((cmdline (assoc :cmdline params)) | |
(cmdline-val (or (cdr cmdline) ""))) | |
(when cmdline (setq params (delq cmdline params))) | |
(setq params | |
(cons (cons :cmdline (concat cmdline-val " <" stdin)) | |
params)) | |
(setf (cadr args) params))) | |
args)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment