From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: stardiviner <numbchild@gmail.com>
Cc: Thierry Banel <tbanelwebmin@free.fr>, emacs-orgmode@gnu.org
Subject: Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
Date: Sun, 30 Dec 2018 10:27:13 +0100 [thread overview]
Message-ID: <87a7kn1i1a.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <877efvkn4d.fsf@gmail.com> (stardiviner's message of "Thu, 27 Dec 2018 23:25:38 +0800")
Hello,
stardiviner <numbchild@gmail.com> writes:
> Indeed, I mimicked `org-link-set-parameters' almost all. About this, I
> originally just lazy, now I have a thought about this alist of plist
> design, I think adding snippet-like text template string. This idea is
> still coarse. I will update this idea in my org agenda todo list.
We are not sure this would end up as a good idea anyway. Meanwhile,
I think the alist of plists idea is a bit complicated.
> And I have another reason, I think use same structure can make user feel
> comfortable, because it is same as `org-link-set-parameters`. It's a
> good reason.
Org uses a lot of data types in its defcustoms. I don't think there is
more comfort in sticking to a particular one. OTOH, a simpler structure
means simpler code.
So if we have no other property than :function, I'd rather have a simple
alist (KEY . FUNCTION). If we ever need more properties, we can change
the structure, as long as it is in master, it is not set in stone.
> About test, would you allow me to write it later?
No problem. They do not need to be complex, tho.
> At last, present my updated patch. Merry Christmas.
Thank you.
> -are updated automatically by a user function. For example, {{{kbd(C-c
> -C-x C-r)}}} inserts a dynamic table that updates the work time (see
> -[[*Clocking Work Time]]).
> +are updated automatically by a user function. You can use dispatch
> +command ~org-dynamic-block-insert-dblock~, which is bound to
> +keybinding {{{kbd(C-c C-x i)}}} by default.
> +
> +#+kindex: C-c C-x i
> +#+findex: org-dynamic-block-insert-dblock
> +Select one type of dynamic block to insert.
> +
> +For example, {{{kbd(C-c C-x i c l o c k t a b l e RET)}}} inserts a
> +dynamic table that updates the work time (see [[*Clocking Work
> Time]]).
by a user function.
#+kindex: C-c C-x x
#+findex: org-dynamic-block-insert-dblock
You can insert a dynamic block with ~org-dynamic-block-insert-dblock~,
which is bound to {{{kbd(C-c C-x i)}}} by default. For example,
{{{kbd(C-c C-x i c l o c k t a b l e RET)}}} inserts a table that
updates the work time (see [[*Clocking Work Time]]).
> +(org-dynamic-block-set-parameters
> + "clocktable"
> + :function 'org-clock-report)
The function could be, e.g.,
(org-dynamic-block-define "clocktable" #'org-clock-report)
> +(defun org-dynamic-block-get-parameter (type key)
> + "Get TYPE dynamic block property for KEY.
> +TYPE is a string and KEY is a plist keyword."
> + (plist-get
> + (cdr (assoc type org-dynamic-block-parameters))
> + key))
Simply
(cdr (assoc type org-dynamic-block-parameters))
if you simplify the structure.
> +(defun org-dynamic-block-set-parameters (type &rest parameters)
> + "Set dynamic block TYPE properties to PARAMETERS.
> +PARAMETERS should be :key val pairs.
> +The key is usually is `:function', and the value is a function name symbol."
> + (let ((data (assoc type org-dynamic-block-parameters)))
> + (if data (setcdr data (org-combine-plists (cdr data) parameters))
> + (push (cons type parameters) org-dynamic-block-parameters))))
Ditto. It could be
(defun org-dynamic-block-define (type fun)
(push (cons type fun) org-dynamic-block-parameters))
> +(defun org-dynamic-block-types ()
> + "Return a list of known dynamic block types."
> + (mapcar #'car org-dynamic-block-parameters))
> +
> +(defun org-dynamic-block-functions ()
> + "Return a list of functions that are called to insert dynamic block."
> + (cl-loop for dblock in org-dynamic-block-parameters
> + with insert-func
> + do (setq insert-func (org-dynamic-block-get-parameter (car dblock) :function))
> + if insert-func
> + collect insert-func))
Is this function necessary?
> +(defun org-dynamic-block-insert-dblock (dblock-type)
> + "Insert a dynamic block of type DBLOCK-TYPE.
> +When used interactively, select the dynamic block types among
> +defined types, per `org-dynamic-block-set-parameters'."
> + (interactive (list (completing-read "dynamic block: "
> + (mapcar #'car org-dynamic-block-parameters))))
(mapcar #'car ...) -> (org-dynamic-block-types)
> + (let ((func (org-dynamic-block-get-parameter dblock-type :function)))
See above.
WDYT?
Regards,
--
Nicolas Goaziou
next prev parent reply other threads:[~2018-12-30 9:27 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-16 1:15 [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks stardiviner
2018-11-16 17:59 ` Thierry Banel
2018-11-25 10:09 ` Nicolas Goaziou
2018-12-03 6:43 ` stardiviner
2018-12-20 2:10 ` stardiviner
2018-12-22 22:54 ` Nicolas Goaziou
2018-12-23 6:26 ` stardiviner
2018-12-23 6:28 ` stardiviner
2018-12-23 7:59 ` stardiviner
2018-12-27 10:59 ` Nicolas Goaziou
2018-12-27 15:25 ` stardiviner
2018-12-30 9:27 ` Nicolas Goaziou [this message]
2019-01-02 0:12 ` stardiviner
2019-01-02 14:57 ` Nicolas Goaziou
2019-01-03 12:19 ` stardiviner
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a7kn1i1a.fsf@nicolasgoaziou.fr \
--to=mail@nicolasgoaziou.fr \
--cc=emacs-orgmode@gnu.org \
--cc=numbchild@gmail.com \
--cc=tbanelwebmin@free.fr \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).