Say I have 2 files, file1.org and file2.org, both tangling to source.el, which I arranged to look like this:

;; [[file:file1.org::ha][ha]]
(defun the-first-block()    )
;; ha ends here

;; [[file:file2.org::hh][hh]]
(defun the-first-block()  )
;; hh ends here

;; [[file:file1.org::+begin_src emacs-lisp][No heading:2]]
(defun the-second-block())
;; No heading:2 ends here

My question is, is there a way that I can tangle file2.org, and it does not overwrite the whole file source.el, but only overwite the

;; [[file:file2.org::hh][hh]]
(defun the-first-block()  )
;; hh ends here


ps. background: I was trying to write code directly from org-roam's zettel files. I'm aware that similar effect can be achived with noweb and have all code blocks in the same file. I'm looking for a way to do it with source blocks in different files.

  • If they both tangle to source.el, they will step on each other. Why not make them tangle to different files (file1.el, file2.el, ...) and then concatenate them all into source.el? I usually write simple Makefiles for such purposes and run them with M-x compile: the Makefile knows if a file has been updated, so it can do the concatenation if necessary.
    – NickD
    Commented Apr 27 at 4:45
  • This is interesting, and you can sure jump back/detangle from source.el as the links in the comments still points to the right org file. Still having to write makefile is a bit of additional complexity but I guess maybe a layer can be built to automate that.
    – Herman He
    Commented Apr 27 at 21:11


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.