emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [BUG] Unable to detangle code with noweb comments [9.6.1 (9.6.1-??-fe92a3c @ /home/phtrivier/.emacs.d/.local/straight/build-28.1/org/)]
       [not found] <1513516023.10763084.1682269758814.ref@mail.yahoo.com>
@ 2023-04-23 17:09 ` Pierre-Henri Trivier
  2023-04-24 12:42   ` Ihor Radchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Pierre-Henri Trivier @ 2023-04-23 17:09 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 3469 bytes --]

I'm using an org file like this one:

    * Simu

    `simu` is a program to simulate counting up to a certain number.

    The program has two main parts:

    ** Gathering input

    We simply get the first parameter, panicking if there is nothing specified.

    #+name: gather-input
    #+begin_src rust :noweb yes :comments noweb
    let args: Vec<String> = env::args().collect();
    if args.len() < 2 {
        panic!("No argument provided");
    }
    <<parse-input>>
    #+end_src

    This uses the `env` package, so we should add it:

    #+name: imports
    #+begin_src rust :noweb yes :comments link
    use std::env;
    #+end_src

    The input is provided as a string, so we need to parse, and report error if it fails.

    #+name: parse-input
    #+begin_src rust :noweb yes :comments link
    let count = args[1].parse::<i32>().unwrap();
    #+end_src

    ** Counting up to the number

    The loop is pretty straigforward:

    #+name: count
    #+begin_src rust :noweb yes :comments noweb
    let mut i = 0;
    while i < count {
        <<print-current-number>>
        i = i+1;
    }
    #+end_src

    Displaying the counter is a matter of presentation:

    #+name: print-current-number
    #+begin_src rust :noweb yes :comments link
    println!("Current number is {}", i);
    #+end_src

    ** Tying things up

    #+name: main
    #+begin_src rust :tangle main.rs :noweb yes :comments noweb
    <<imports>>
    fn main() {
        <<gather-input>>
        <<count>>
    }
    #+end_src

When using org-babel-tangle, a file is generated with this content:

    // [[file:simu.org::main][main]]
    // [[file:simu.org::imports][imports]]
    use std::env;
    // imports ends here
    fn main() {
        // [[file:simu.org::gather-input][gather-input]]
        let args: Vec<String> = env::args().collect();
        if args.len() < 2 {
            panic!("No argument provided");
        }
        // [[file:simu.org::parse-input][parse-input]]
        let count = args[1].parse::<i32>().unwrap();
        // parse-input ends here
        // gather-input ends here
        // [[file:simu.org::count][count]]
        let mut i = 0;
        while i < count {
            // [[file:simu.org::print-current-number][print-current-number]]
            println!("Current number is {}", i);
            // print-current-number ends here
            i = i+1;
        }
        // count ends here
    }
    // main ends here

When I visit the generated file, modify it, and I run
org-babel-detangle, I'm execting the org file to be changed.

Instead, I always get the error "Not in tangled code"

If instead I annotate my blocks with :comments links , then I don't even
get any comments in the generated file.

I supposed it's related to using noweb expansion.

What am I doing wrong ?

Emacs  : GNU Emacs 28.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.16.0)
 of 2022-05-31
Package: Org mode version 9.6.1 (9.6.1-??-fe92a3c @ /home/phtrivier/.emacs.d/.local/straight/build-28.1/org/)

[-- Attachment #2: Type: text/html, Size: 5322 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [BUG] Unable to detangle code with noweb comments [9.6.1 (9.6.1-??-fe92a3c @ /home/phtrivier/.emacs.d/.local/straight/build-28.1/org/)]
  2023-04-23 17:09 ` [BUG] Unable to detangle code with noweb comments [9.6.1 (9.6.1-??-fe92a3c @ /home/phtrivier/.emacs.d/.local/straight/build-28.1/org/)] Pierre-Henri Trivier
@ 2023-04-24 12:42   ` Ihor Radchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2023-04-24 12:42 UTC (permalink / raw)
  To: Pierre-Henri Trivier; +Cc: emacs-orgmode@gnu.org

Pierre-Henri Trivier <phtrivier@yahoo.fr> writes:

> I'm using an org file like this one:
> ...
>     #+name: main
>     #+begin_src rust :tangle main.rs :noweb yes :comments noweb
>     <<imports>>
>     fn main() {
>         <<gather-input>>
>         <<count>>
>     }
>     #+end_src
> When I visit the generated file, modify it, and I run
> org-babel-detangle, I'm execting the org file to be changed.
>
> Instead, I always get the error "Not in tangled code"

AFAIU, `org-babel-detangle' does not support nested noweb blocks.
The last discussion was in https://orgmode.org/list/20211017021707.Horde.p9ib-mMooANjOrUuCbc5EPl@www.vfemail.net

Confirmed.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-04-24 12:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1513516023.10763084.1682269758814.ref@mail.yahoo.com>
2023-04-23 17:09 ` [BUG] Unable to detangle code with noweb comments [9.6.1 (9.6.1-??-fe92a3c @ /home/phtrivier/.emacs.d/.local/straight/build-28.1/org/)] Pierre-Henri Trivier
2023-04-24 12:42   ` Ihor Radchenko

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).