Hacker News new | past | comments | ask | show | jobs | submit login

Do it!



Actually. I just added something similar to my emacs yesterday:

    (defun sh-line ()
      (interactive)
      (let ((cmd (buffer-substring-no-properties (line-beginning-position) (line-end-position))))
        (end-of-line)
        (newline)
        (insert (shell-command-to-string cmd))))
    (local-set-key (kbd "M-RET") 'sh-line)
With this Alt-RET will evaluate the last line in your shell, and insert the output.


It is worth mentioning that Emacs is a wee bit easier to script than notepad.exe :)


Speaking of Emacs, shells and WSL, I recently had to shell out from Emacs under WSL to git-bash under Windows proper, to run cmake to run MSBuild, and get the generation/compilation output all the way back. Turns out, while regular M-x shell-command would work, M-x async-shell-command (i.e. shell-command with appended &) would not - it wasn't able to communicate with the spawned process. I needed it to be async so that a compile wouldn't block my Emacs.

The solution I came up with is a bit lower-level, looks like this:

  (make-process :name "some_name"
                :buffer "buffer"
                :command ("cmd" "to" "run")
                :connection-type 'pipe
                :coding 'utf-8-dos)
Two key lines are :connection-type 'pipe, which solves the I/O issues, and :coding 'utf-8-dos, which ensures the output streamed to an Emacs buffer isn't polluted by ^M (CR from CRLF line ending).

Now, if anyone figured out how to configure a connection to a language server across the WSL boundary, I'm all ears.


Does `M-x compile` not work for you on windows? This is what I use to do run build scripts async.


Thank you! Macintosh MPW had a very similar feature back in the day, it rocked. Haven't seen it since. Added to my .emacs!




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: