If I have a code snippet that I tangle to a file, but I expect the file name to change over time, Is there a cleaner way to change the filename than Query-replace?
For example, say I tangle code to ~/dir/my-file.el:
#+BEGIN_SRC emacs-lisp :tangle ~/dir/my-file.el
(setq myvar1 "value1")
#+END_SRC
#+BEGIN_SRC emacs-lisp :tangle ~/dir/my-file.el
(defun foo (bar) ... )
#+END_SRC
etc.
Then later on I realize that the file would be better placed in another location:
#+BEGIN_SRC emacs-lisp :tangle ~/dir/my/file.el
(setq myvar1 "value1")
#+END_SRC
#+BEGIN_SRC emacs-lisp :tangle ~/dir/my/file.el
(defun foo (bar) ... )
#+END_SRC
etc.
Is there a way to change the argument to :tangle dynamically.
I have investigated and discovered that I can feed elisp into the :tangle argument. If I evaluate (setq myfile "~/dir/file.el)
and then tangle the following:
#+BEGIN_SRC emacs-lisp :tangle (print myfile)
(setq myvar1 "value1")
#+END_SRC
#+BEGIN_SRC emacs-lisp :tangle (print myfile)
(defun foo (bar) ... )
#+END_SRC
I get the desired result I am looking for. I could then execute an elisp snippet to set the variable using org-babel, but I was wondering if there is a cleaner way to do so.
The docs on the :tangle header do not stipulate a native way.