Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ob-rustic : run code snippets with no main() #266

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

flintforge
Copy link

Hi there,
this wraps the code block with main()
eg: fn main(){<body>} when there's none,
like rust-mode does, allowing more concise snippets.
p.s: the main function detection should be made more robust: by searching for it after rust-fmt

@brotzeit
Copy link
Owner

Sorry for the late reply.

(wrapped-body (if (string-match-p "fn main()" body)

I think this regex search can slow things down. I know that some users make excessive use of org-babel and if they use hundreds of lines in babel blocks I think this can be annoying.

I know this would be very convenient and as far as I remember I also considered this when I added the babel code, but I think the potential downsides are not worth it.

Maybe we should rather provide an option for the babel block so you can use a template like:

#+BEGIN_SRC rust :wrap t

#+END_SRC

@flintforge
Copy link
Author

flintforge commented Aug 29, 2021

Running a regexp without wildcard when interactively executing a block through babel is barely perceptible.
Ob-C has the option :main to tell if it has to check for the presence of main and eventually add one (most babel modes do)
Which template would the :wrap option select ? Would this provide something that :noweb doesn't ?

@flintforge
Copy link
Author

flintforge commented Aug 29, 2021

PR updated to insert the main block as follows:

fn main() {
    let result = {
        #{script}
    };
    println!("{:?}", result);
}

The usage of ob-rust stays limited to :results output.

@brotzeit
Copy link
Owner

Which template would the :wrap option select ? Would this provide something that :noweb doesn't ?

Something like your example. I haven't used :noweb.

Ob-C has the option :main to tell if it has to check for the its presence of main and eventually add one (most babel modes do)

Ok, I didn't know but certainly sounds reasonable. Maybe we should also do it this way ? We can also add an option to make it the default.

lroolle pushed a commit to lroolle/rustic that referenced this pull request Nov 5, 2021
lroolle pushed a commit to lroolle/rustic that referenced this pull request Nov 5, 2021
lroolle pushed a commit to lroolle/rustic that referenced this pull request Nov 5, 2021
lroolle pushed a commit to lroolle/rustic that referenced this pull request Nov 5, 2021
lroolle pushed a commit to lroolle/rustic that referenced this pull request Nov 5, 2021
lroolle pushed a commit to lroolle/rustic that referenced this pull request Nov 5, 2021
lroolle pushed a commit to lroolle/rustic that referenced this pull request Nov 5, 2021
lroolle pushed a commit to lroolle/rustic that referenced this pull request Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants