Skip to main content
Conclusion & workaround
Source Link

I would likeRegarding my initial goal, which was to settle for a solution like the following for now:

(defun my/org-babel-plantuml-header-args ()
  "Set dynamic header arguments for PlantUML source blocks."
  (let ((output-dir (org-attach-dir-get-create)))
    `((:results . "file link")
      (:output-dir . ,output-dir)
      (:file-ext . "png")
      (:exports . "results"))))

  (setq org-babel-default-header-args:plantuml
         (my/org-babel-plantuml-header-args))

I would have to set the file manually, but I wrote a simple snippet for conveniencediagram files created in the attachment directory, and most of my initial requirements would be fulfilleddisplayed in the buffer, it is not possible to achieve using the header default arguments.

UnfortunatelyAs @NickD commented, any function used there to set an option is only called once upon setting the (org-attachbabel-dirdefault-getheader-create)args:plantuml function is called on Doom Emacs startup which causes errors and some destructive editing of my literatevariable. This approach even had other adverse effects as I am using an org config file. The

I managed to achieve the same results by using a custom function in a Yasnippet snippet to build the output-dir string. It works fine, just has a bit of a cluttered header.

Sorry if this thread is tryinga bit all over the place. If future readers are looking to createachieve the same kind of thing, I would gladly share the snippet code, and the custom hook function to set the attachment tag to the appropriate org node. I am not posting it because it uses Org-roam which is a property drawer with an ID fieldniche use case I think, and I think it is off-topic considering how the thread started.

I would like to settle for a solution like the following for now:

(defun my/org-babel-plantuml-header-args ()
  "Set dynamic header arguments for PlantUML source blocks."
  (let ((output-dir (org-attach-dir-get-create)))
    `((:results . "file link")
      (:output-dir . ,output-dir)
      (:file-ext . "png")
      (:exports . "results"))))

  (setq org-babel-default-header-args:plantuml
         (my/org-babel-plantuml-header-args))

I would have to set the file manually, but I wrote a simple snippet for convenience, and most of my initial requirements would be fulfilled.

Unfortunately, the (org-attach-dir-get-create) function is called on Doom Emacs startup which causes errors and some destructive editing of my literate config file. The function is trying to create a property drawer with an ID field.

Regarding my initial goal, which was to have the diagram files created in the attachment directory, and displayed in the buffer, it is not possible to achieve using the header default arguments.

As @NickD commented, any function used there to set an option is only called once upon setting the org-babel-default-header-args:plantuml variable. This approach even had other adverse effects as I am using an org config file.

I managed to achieve the same results by using a custom function in a Yasnippet snippet to build the output-dir string. It works fine, just has a bit of a cluttered header.

Sorry if this thread is a bit all over the place. If future readers are looking to achieve the same kind of thing, I would gladly share the snippet code, and the custom hook function to set the attachment tag to the appropriate org node. I am not posting it because it uses Org-roam which is a niche use case I think, and I think it is off-topic considering how the thread started.

new problems found
Source Link

I settledwould like to settle for a solution like the following solution for now:

I would have to set the file manually, but I wrote a simple snippet for convenience, and most of my initial requirements arewould be fulfilled.

Please note that my first attempt does not work well for me after further testing. TheUnfortunately, the (org-attach-dir-get-create) function is called on Doom Emacs reload and startup which causes errors and some destructive editing of themy literate config file. I have not tested on plain Emacs.

If other users can reproduce this buggy behavior on plain Emacs, maybe I could report it as The function is trying to create a bug. Thanksproperty drawer with an ID field.

I settled for the following solution for now:

I have to set the file manually, but I wrote a simple snippet for convenience, and most of my initial requirements are fulfilled.

Please note that my first attempt does not work well for me after further testing. The (org-attach-dir-get-create) function is called on Doom Emacs reload and startup which causes errors and some destructive editing of the config file. I have not tested on plain Emacs.

If other users can reproduce this buggy behavior on plain Emacs, maybe I could report it as a bug. Thanks.

I would like to settle for a solution like the following for now:

I would have to set the file manually, but I wrote a simple snippet for convenience, and most of my initial requirements would be fulfilled.

Unfortunately, the (org-attach-dir-get-create) function is called on Doom Emacs startup which causes errors and some destructive editing of my literate config file. The function is trying to create a property drawer with an ID field.

added 1268 characters in body
Source Link

=== EDIT ===

After further testing, I jumped to the wrong conclusion when blaming this buggy behavior on the dynamic setting of the output directory.

I can reproduce it every time I set both output-dir and file within the org-babel-default-header-args variable even with a static string.

I settled for the following solution for now:

(defun my/org-babel-plantuml-header-args ()
  "Set dynamic header arguments for PlantUML source blocks."
  (let ((output-dir (org-attach-dir-get-create)))
    `((:results . "file link")
      (:output-dir . ,output-dir)
      (:file-ext . "png")
      (:exports . "results"))))

  (setq org-babel-default-header-args:plantuml
         (my/org-babel-plantuml-header-args))

I have to set the file manually, but I wrote a simple snippet for convenience, and most of my initial requirements are fulfilled.

Please note that my first attempt does not work well for me after further testing. The (org-attach-dir-get-create) function is called on Doom Emacs reload and startup which causes errors and some destructive editing of the config file. I have not tested on plain Emacs.

If other users can reproduce this buggy behavior on plain Emacs, maybe I could report it as a bug. Thanks.

=== EDIT ===

After further testing, I jumped to the wrong conclusion when blaming this buggy behavior on the dynamic setting of the output directory.

I can reproduce it every time I set both output-dir and file within the org-babel-default-header-args variable even with a static string.

I settled for the following solution for now:

(defun my/org-babel-plantuml-header-args ()
  "Set dynamic header arguments for PlantUML source blocks."
  (let ((output-dir (org-attach-dir-get-create)))
    `((:results . "file link")
      (:output-dir . ,output-dir)
      (:file-ext . "png")
      (:exports . "results"))))

  (setq org-babel-default-header-args:plantuml
         (my/org-babel-plantuml-header-args))

I have to set the file manually, but I wrote a simple snippet for convenience, and most of my initial requirements are fulfilled.

Please note that my first attempt does not work well for me after further testing. The (org-attach-dir-get-create) function is called on Doom Emacs reload and startup which causes errors and some destructive editing of the config file. I have not tested on plain Emacs.

If other users can reproduce this buggy behavior on plain Emacs, maybe I could report it as a bug. Thanks.

added 12 characters in body
Source Link
Loading
improve problem description
Source Link
Loading
added 1 character in body
Source Link
Loading
Source Link
Loading