Hacker News new | past | comments | ask | show | jobs | submit login
Run programs in Emacs buffer, seeing their output inline, interactively (github.com/darius)
132 points by behnamoh on Sept 26, 2022 | hide | past | favorite | 38 comments



I am loving the latest Emacs Renaissance! All you can eat buffet, but you can take your lunch (and dinner) home :)

OTOH, org-mode already does this, without any need for external package and minimal config. It works really well, too!


Came here to say this. I use org-mode to do what OP's package is doing. But OP provides some features like

> one keystroke executes all specially-marked lines from a buffer and inserts the results inline

Not sure if we can make such specially-marked lines using org-mode. Never needed this feature myself. But for those who want a workflow like this the new package could be useful. But again maybe there is a way to do this without an external package with a little bit of elisp?


> I am loving the latest Emacs Renaissance!

This repository hasn't been updated in 6 years, and is over 12 years old.

And as someone pointed out, Org mode could already do this.

Not really part of the Renaissance.


More like an all you can eat buffer.

*rimshot*

Thank you, I am here all week.


Tangentially, has there been any work in having more structured scrollback, say one buffer for every command, which can be collapsed, pinned or copied individually? Presently there's the minor annoyance when (accidentally) running any program with lots of output, which is that all the scrollback above it becomes inaccessible. Yeah, could have run them in different splits or redirected to begin with, but sometimes you don't know beforehand. And being able to reuse the output of a slow command after the fact would be handy too.

I was thinking that this'd be a feature of the terminal, but on second thought the terminal doesn't know where one command begins or ends, so it'd have to be the shell that saves the output.


EShell in Emacs can preserve point at the prompt that executed the command. You can then hit space to page through the output, or start typing to immediately jump to the end of the buffer (and thus a blank prompt):

https://www.masteringemacs.org/article/complete-guide-master...

There's also `C-c C-p` to jump to the previous command prompt in the likes of M-x shell. That's not quite what you want, but it's another way to jump back up.


Also eshell imenu support can be enabled https://xenodium.com/imenu-on-emacs-eshell


Hey Xenodium, thanks for this post. I love your site and use Plain Org regularly. I wanted to ask: what utility do you get in jumping back to the old prompts? Can you edit them in-place and re-run them or something?


> Hey Xenodium, thanks for this post. I love your site and use Plain Org regularly.

Thank you. Really nice to hear it.

> I wanted to ask: what utility do you get in jumping back to the old prompts?

Mostly about jumping back to specific points in buffer. If you’ve been investigating or troubleshooting in a shell session, you can quickly jump back to previous invocations of a command to view its output.

By now, I’ve become used to imenu being available in most modes/contexts, so I figured why not eshell too.


A lot of programming modes in emacs give you a quick shortcut to send a given section to the REPL for evaluation. For instance, you can do it in sly-mode and julia-mode (I think it’s named that). Hit C-c C-c to eval one section and see output in the REPL. Works really well.


M-x shell and simple variations (https://github.com/pjj/Emacs-nsh) allow for infinite scrollback, separate histories, comint-based or plain emacs navigation, and ease the manipulation of arbitrary output. Occasionally I close a shell buffer if the output has exceeded a GB or so, but they typically last weeks or months and I never lost info. They are not full terminals, so not everything works and I bind a lot of terminal-only commands (htop, nvtop) to execute in vterm.


Is this different from cells in a notebook (eg Jupyter)?


I would guess, that it is running code directly using the interpreter of the respective language and does not require an "I<language>Kernel". As such it does not require you to install Jupyter or its many dependencies. I guess you only need the correct configuration of Emacs and the language's interpreter/compiler.

Another difference might be, that the result is just the result, not some structure in a JSON file, like it would be in a Jupyter notebook.


some people made a dom based terminal ui with block based entries, every command is linked to its output

it was very ambitious but I don't know where it's at now


Would love if there was a gif in the README, so I could get a feel for this (even more important because the whole selling point is interactivity).


i have this thought for SO MANY TOOLS.

gif, screenshot, anything to make me not install it and run it just to find out it wasn't what i wanted / needed.


As a slightly sight-impaired user (no colors, and I never could learn/figure-out icons (fsck they bother me!)), I really enjoy "screen-shots" but I really wish there was a text alt-image that would render in lynx or emacs-w3m through emacspeak.

For the exact same reasons You are mentioning. Thanks.


I looked through all of the example files, and it generally looks cool. I won’t use it for personal reasons: I like to keep my Emacs configuration simple. Really simple, currently 82 lines https://github.com/mark-watson/emacs_setup/blob/main/.emacs using straight.el.

I love seeing projects like this, but I seldom use them. Emacs out of the box, with my really simple configuration, supports all programming languages I use as well as my markdown-based book writing activities.



Would love to see a comparison with Org's Babel.


This is useful! Are there other packages on MELPA that provide similar functionality?


`org-mode` has the ability to evaluate code blocks and store the output in a following results block[0].

You can configure it to run just about everything in various ways and therefore you can do Literate Programming in nearly the full Knuth sense in it.

I find it's a good solution for a local "notebook" similar to IPython/Jupyter Notebooks but for any language in Emacs.

[0] https://orgmode.org/manual/Evaluating-Code-Blocks.html


Extending org babel to support other languages is fairly accessible. I had a lot of fun getting SwiftUI to rendering inline https://xenodium.com/previewing-swiftui-layouts-in-emacs-rev...

Also did a little experiment for Objective-C https://xenodium.com/org-babel-objective-c-support


The first link is really impressive. Amazing what can be achieved with so little code/configuration.


Org+babel is probably my favorite thing about emacs, magit being a close second.

I tried doing Literate Programming using this blog as my guide http://fgiasson.com/blog/index.php/2016/06/21/optimal-emacs-..., but I got burned out pretty quickly. I think my problem was I put literally everything in a single README.org file, and it was so taxing scrolling up and down. I might try again but with multiple org files.


Org mode provides a supercharged version of this functionality that will work for any language as long as you can point it to an appropriate runtime. It's definitely a little more verbose, since you have to declare the language and stuff inside the org mode syntax, but I'm sure that you could get it to work ad-hoc with a little hacking.

https://orgmode.org/worg/org-contrib/babel/


There is lively.el [1]! It is also on MELPA in a more recent version [2]. It allows to put an elisp expression into any buffer and then replaces that with the output in a time interval or manually. I use that frequently.

[1] https://lukego.livejournal.com/23379.html [2] https://github.com/purcell/lively/tree/348675828c6a81bfa1ac3...


Wow this package rocks!


https://blog.sulami.xyz/posts/literate-calc-mode/ is pretty nice. I always have literate-calc-minor-mode (+org-mode as major) in my scratch buffer for quick calculations.



I tried with Python and it didn't work, possibly because the helper is written in Python 2.x and the repo is rather old (at least in Python terms)

Might work for elisp though.


in my first exposure to emacs I had used it in high school with “C Shape Edit” as an interface to alpha_1 CAD software at the Utah CS department. Just executing lines in the buffer, and waiting for a rerender on the ultrasparc

https://www.cs.utah.edu/gdc/projects/alpha1/


kakoune includes this by default with the pipe operator. very useful functionality.



oh excellent, i’ve been using mostly vim recently and didn’t realize this was available


oh cooool thanks!!!

do you know how to make the output in the terminal cleaner?

for example `:term ls -lah /` isn't well formatted


Interesting. Looks “ok” to me. What’s broken for you?


This is known as a shell.




Join us for AI Startup School this June 16-17 in San Francisco!

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

Search: