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/)