emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Pierre-Henri Trivier <phtrivier@yahoo.fr>
To: "emacs-orgmode@gnu.org" <emacs-orgmode@gnu.org>
Subject: [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/)]
Date: Sun, 23 Apr 2023 17:09:18 +0000 (UTC)	[thread overview]
Message-ID: <1513516023.10763084.1682269758814@mail.yahoo.com> (raw)
In-Reply-To: 1513516023.10763084.1682269758814.ref@mail.yahoo.com

[-- 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 --]

       reply	other threads:[~2023-04-24 11:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1513516023.10763084.1682269758814.ref@mail.yahoo.com>
2023-04-23 17:09 ` Pierre-Henri Trivier [this message]
2023-04-24 12:42   ` [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/)] Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1513516023.10763084.1682269758814@mail.yahoo.com \
    --to=phtrivier@yahoo.fr \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).