On Wed, Dec 13, 2017 at 04:59:00PM -0800, H. S. Teoh via Digitalmars-d-announce wrote: [...] > Sadly, `dmd - -run` currently doesn't quite work just yet. I should look > into fixing that. And *then* we wouldn't need to invent a temporary > filename for the executable in our keybinding. [...]
Turns out, the code change to make this happen is trivial: https://github.com/dlang/dmd/pull/7435 With this PR, you can compile and run code in standard input without needing to specify any filenames: $ echo 'import std.stdio; void main() { writeln("Hello, World!"); }' | dmd -run - Hello, World! $ Of course, piping the output of `echo` to dmd isn't a big deal. A more interesting use case is being able to pipe the contents of an editor buffer to dmd as input, and instantly receiving the program output in the editor. For example, I can open a new window in Vim (no filename), and type in the following contents: ------ import std.stdio; void main() { writeln("Instant win!"); } ------ Then type: :0,$!dmd -run - and the buffer contents are now: ------ Instant win! ------ (In English, the vim magic word above means: : Enter command mode 0,$ Take the range of lines from 0 to the end of file ! And filter these lines by a shell command dmd -run - The command to run ) This can, of course, be bound to a custom keybinding, then you'll have your one-stop shop for compiling D snippets without ever seeing (much less typing) any temporary filenames. And without needing an internet connection. Instant win! :-P T -- When solving a problem, take care that you do not become part of the problem.