nvim-orgmode / orgmode

Orgmode clone written in Lua for Neovim 0.9+.
https://nvim-orgmode.github.io/
MIT License
2.85k stars 125 forks source link

Orgmode Babel #190

Open aareman opened 2 years ago

aareman commented 2 years ago

Does this feature exist in Emacs orgmode core?

N/A

Orgmode link

https://blog.8bitzen.com/posts/27-02-2019-using-orgmode-babel/ https://orgmode.org/worg/org-contrib/babel/intro.html

Note- marked as N/A above, since i'm not familiar enough with orgmode to know if its in core or a library. The docs link says contrib, but it seems builtin (ie. don't need to install another package in emacs to use).

Feature value

Very high. I think this is one of orgmodes killer features for writing "smart notes" (literate programming).

I think a combo of sniprun/treesitter should be able to do this, and i'm playing around a little with it. The treesitter org parser doesn't handle (block parameters) just lumps them as one value. Also using header-args as a property at the top of the document doesn't work.

I'm not sure how to run sniprun in a way where we can setup the environment based on org properties for the run. (for example per file settings, or per block settings)

Org Babel also allows for including other files with helper functions in different languages, and named blocks.

Its very cool. Here is a video that demonstrates its power https://www.youtube.com/watch?v=0g9BcZvQbXU&ab_channel=spudlyo

Again, thank you for this amazing plugin. I know most of the features have been focused on GTD, this opens up a can of goodness, but it isn't directly in the GTD world of org.

Additional context

No response

kristijanhusak commented 2 years ago

sniprun provides basic functionality for this (evaluating blocks), but I have a long term plan to support something like org babel out of the box.

aareman commented 2 years ago

That would be great. I don't have a lot of free time but lmk when you start working on it just in case i have something you can use at that point.

Yeah, sniprun, is great, but is really missing a lot of the features. Though a treesitter combo with sniprun api mode might be a quick midwaypoint.

Thank you again for this great plugin!


From: Kristijan Husak @.> Sent: Wednesday, January 5, 2022 11:06:10 AM To: nvim-orgmode/orgmode @.> Cc: Avraham Areman @.>; Author @.> Subject: Re: [nvim-orgmode/orgmode] Orgmode Babel (Issue #190)

sniprunhttps://github.com/michaelb/sniprun provides basic functionality for this (evaluating blocks), but I have a long term plan to support something like org babel out of the box.

— Reply to this email directly, view it on GitHubhttps://github.com/nvim-orgmode/orgmode/issues/190#issuecomment-1005858583, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACQDVV7HBCCDWAYJMK3PDLLUURT7FANCNFSM5LBSIWPA. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub. You are receiving this because you authored the thread.Message ID: @.***>

aareman commented 2 years ago

Not sure where to put this, but I noticed there is a difference in the names between what emacs babel supports and syntax highlighting and vim.

For example in emacs javascript is referred to as js so a codeblock needs to be

  #+BEGIN_SRC js
  const a = "something";
  const b = 2;
  const c = 3;
  console.log(b+c)
  #+END_SRC

but, in vim javascript is javascript so image

If there was some way to map the blocks so that we would use the same as emacs (so there is maximum compatibility) and have a mapping to vim languages so that the treesitter language highlighting works well.

I looked into creating a mapping in emacs to fix this but no luck, something like this

;; Org Babel
;;;###autoload
(with-eval-after-load "org"
(add-to-list 'org-src-lang-modes '("javascript" . js))) ; key line

(org-babel-do-load-languages
 'org-babel-load-languages
 '((emacs-lisp . t)
   (C . t)
   (js . t)
   (shell . t)
   (python . t)))

note - i barely know elisp and my code could just be broken. Its based on a lot of internet searching...

refaelsh commented 1 year ago

I also think that Babel is the killer feature of Org Mode. I would love it if was implemented here in this plugin.

+1.

aleksandersumowski commented 1 year ago

What does Babel do on top what sniprun provides?

sangaline commented 1 year ago

It's less sophisticated than sniprun, but people might also want to check out mdeval.nvim. It seems to have a more narrow scope focused on running code blocks in markdown or org documents.

I'll second the original sentiment that babel is a killer feature. After spending a couple years using emacs, babel and tangle are the two things that are most difficult to live without when coming back to vim.

kristijanhusak commented 4 months ago

Basic support for tangle and noweb syntax was added in https://github.com/nvim-orgmode/orgmode/pull/685. It does not support evaluation yet, but does support tangling and basic noweb referencing.