emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [Feature Request] Add an dispatcher command (keybinding) for ins


From: Nicolas Goaziou
Subject: Re: [O] [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
Date: Sun, 30 Dec 2018 10:27:13 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux)

Hello,

stardiviner <address@hidden> 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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]