* dynamic blocks orgmode manpage
@ 2024-02-14 23:08 chris
2024-02-19 10:22 ` Ihor Radchenko
0 siblings, 1 reply; 2+ messages in thread
From: chris @ 2024-02-14 23:08 UTC (permalink / raw)
To: emacs-orgmode
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: dynamic blocks orgmode manpage
2024-02-14 23:08 dynamic blocks orgmode manpage chris
@ 2024-02-19 10:22 ` Ihor Radchenko
0 siblings, 0 replies; 2+ messages in thread
From: Ihor Radchenko @ 2024-02-19 10:22 UTC (permalink / raw)
To: chris; +Cc: emacs-orgmode
chris <inkbottle007@gmail.com> writes:
> 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
Fixed, on bugfix.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=d6c3ab08b
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=d5b98bcfb
Note that function provided in `org-dynamic-block-define' must accept
zero arguments. It is generally not the same function with
org-dblock-write:foo.
--
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-19 10:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-14 23:08 dynamic blocks orgmode manpage chris
2024-02-19 10:22 ` Ihor Radchenko
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.