[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [O] [Feature Request] Add an dispatcher command (keybinding) for ins
From: |
stardiviner |
Subject: |
Re: [O] [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks |
Date: |
Wed, 02 Jan 2019 08:12:15 +0800 |
User-agent: |
mu4e 1.1.0; emacs 26.1 |
Nicolas Goaziou <address@hidden> writes:
> 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.
Ok, I changed data structure into alist now.
>
>> 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.
Ditto
>
> 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.
I added a test by insert clocktable. It's passed.
>
>> 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]]).
Copied.
>
>> +(org-dynamic-block-set-parameters
>> + "clocktable"
>> + :function 'org-clock-report)
>
> The function could be, e.g.,
>
> (org-dynamic-block-define "clocktable" #'org-clock-report)
Updated.
>
>> +(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.
Updated.
>
>> +(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))
Updated.
>
>> +(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?
Updated.
>
>> +(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)
Updated.
>
>> + (let ((func (org-dynamic-block-get-parameter dblock-type :function)))
>
> See above.
Updated.
Regards.
As always, add patch as attachment.
0001-lisp-org.el-org-dynamic-block-insert-dblock-New-func.patch
Description: Text Data
--
[ stardiviner ]
I try to make every word tell the meaning what I want to express.
Blog: https://stardiviner.github.io/
IRC(freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
- Re: [O] [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks,
stardiviner <=