all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: chris <inkbottle007@gmail.com>
To: emacs-orgmode@gnu.org
Subject: dynamic blocks orgmode manpage
Date: Wed, 14 Feb 2024 23:08:18 +0000	[thread overview]
Message-ID: <5790810.DvuYhMxLoT@nixos> (raw)

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





             reply	other threads:[~2024-02-14 23:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14 23:08 chris [this message]
2024-02-19 10:22 ` dynamic blocks orgmode manpage Ihor Radchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5790810.DvuYhMxLoT@nixos \
    --to=inkbottle007@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.