Hi all, #+title: dynamic blocks orgmode manpage
* Example from the manual Concerned page: [[https://orgmode.org/manual/Dynamic-Blocks.html][Dynamic Blocks (The Org Manual)]] Below is an elisp snippet from the manual. You can execute it with =C-c C-c=. #+begin_src emacs-lisp (defun org-dblock-write:block-update-time (params) (let ((fmt (or (plist-get params :format) "%d. %m. %Y"))) (insert "Last block update at: " (format-time-string fmt)))) #+end_src #+RESULTS: : org-dblock-write:block-update-time Below is another snippet from the manual. You can update it with =M-x org- dblock-update=. #+BEGIN: block-update-time :format "on %m/%d/%Y at %H:%M" Last block update at: on 02/14/2024 at 21:33 #+END: Now, after running =C-c C-c= on the line below, trying =M-x org-dynamic-block- insert-dblock= will result in the error: =funcall-interactively: Wrong type argument: commandp, org-dblock-write:block-update-time=. #+begin_src emacs-lisp (org-dynamic-block-define "block update time" #'org-dblock-write:block- update-time) #+end_src #+RESULTS: : ((block update time . org-dblock-write:block-update-time) (abstracts-index . org-dblock-write:abstracts-index) (columnview . org-columns-insert-dblock) (clocktable . org-clock-report)) * Alternative construction Given the circumstances described above, the following snippet works with both =M-x org-dblock-update= and =M-x org-dynamic-block-insert-dblock=. #+begin_src emacs-lisp (defun cool-hello () (string-join '("cool" "hello") " ")) (defun org-dblock-write:hello-dblock (&optional arg) (interactive) (let* ((a (if (called-interactively-p 'any) (format "#+BEGIN: hello-dblock\n%s\n#+END:\n" (cool-hello)) (format "%s" (cool-hello))))) (insert a))) (org-dynamic-block-define "hello dblock" #'org-dblock-write:hello-dblock) #+end_src #+RESULTS: : org-dblock-write:hello-dblock #+BEGIN: hello-dblock cool hello #+END: * Notes In the above snippet, for it to work in both cases, after numerous experiments, I found that both the =(interactive)= part and the =(&optional arg)= part are necessary. If memory serves, depending on whether it is used with =M-x org-dblock-update= or =M-x org-dynamic-block-insert-dblock=, one of them might not require the =interactive= part, while it's a requirement for the other one. Similarly, one scenario requires no arguments, while the other demands that arguments are present. Cheers, Chris