emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
@ 2018-11-16  1:15 stardiviner
  2018-11-16 17:59 ` Thierry Banel
  0 siblings, 1 reply; 15+ messages in thread
From: stardiviner @ 2018-11-16  1:15 UTC (permalink / raw)
  To: org-mode

In package `orgtbl-aggregate` has bellowing command to insert different dynamic blocks.

#+begin_src emacs-lisp
(defun org-insert-dblock ()
  "Inserts an org table dynamic block.
This is a dispatching function which prompts for the type
of dynamic block to insert. It dispatches to functions
which names matches the pattern `org-insert-dblock:*'"
  (interactive)
  (let ((fun
	 (intern
	  (format
	   "org-insert-dblock:%s" 
	   (org-icompleting-read
	    "Kind of dynamic block: "
	    (mapcar (lambda (x)
		      (replace-regexp-in-string
		       "^org-insert-dblock:"
		       ""
		       (symbol-name x)))
		    (apropos-internal "^org-insert-dblock:")))))))
    (if (functionp fun)
	(funcall fun)
      (message "No such dynamic block: %s" fun))))
#+end_src

This command matches Org Mode API style.

I hope Org Mode can have this built-in. Because there are some other dynamic blocks. They can use this dispatcher function.

For example org-gantt dynamic block, I write a function manually:

#+begin_src emacs-lisp
(defun org-insert-dblock:org-gantt ()
  "Insert org-gantt dynamic block."
  (interactive)
  (org-create-dblock
   (list :name "org-gantt"
         :file "data/images/project-gantt-chart.png"
         :imagemagick t
         :tikz-options "scale=1.5, every node/.style={scale=1.5}"
         :weekend-style "{draw=blue!10, line width=1pt}"
         :workday-style "{draw=blue!5, line width=.75pt}"
         :show-progress 'if-value
         :progress-source 'cookie-clocksum
         :no-date-headlines 'inactive
         :parameters "y unit title=.7cm, y unit chart=.9cm"
         :tags-group-style '(("test"."group label font=\\color{blue}")
                             ("toast"."group label font=\\color{green}"))
         :tags-bar-style '(("test"."bar label font=\\color{blue}")
                           ("toast"."bar label font=\\color{green}")))))
#+end_src

-- 
[ 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
      

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  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
  0 siblings, 1 reply; 15+ messages in thread
From: Thierry Banel @ 2018-11-16 17:59 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/html, Size: 3255 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  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
  0 siblings, 2 replies; 15+ messages in thread
From: Nicolas Goaziou @ 2018-11-25 10:09 UTC (permalink / raw)
  To: Thierry Banel; +Cc: emacs-orgmode

Hello,

Thierry Banel <tbanelwebmin@free.fr> writes:

> Org defines C-c C-x i as org-insert-columns-dblock. Instead, it could call the org-insert-dblock dispatcher shown here. The original org-insert-columns-dblock would be one among
> other dblock inserters.
>
> Possible dblocks:
>   org-insert-columns-dblock
>   org-clock-report
>   propview
>   invoice
>   org-insert-dblock:aggregate
>   org-insert-dblock:join
>   org-insert-dblock:transpose
>
> Any future dblock inserter would be taken into account by the
> dispatcher just by providing an autoloadable
> org-insert-dblock:something function.

I think we could do something similar to links, i.e., populate
a variable (for links, it is `org-link-parameters') with a command
(`org-link-set-parameters'), so the dispatcher knows what dynamic blocks
can be provided.

Otherwise, it sounds like a good idea.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  2018-11-25 10:09   ` Nicolas Goaziou
@ 2018-12-03  6:43     ` stardiviner
  2018-12-20  2:10     ` stardiviner
  1 sibling, 0 replies; 15+ messages in thread
From: stardiviner @ 2018-12-03  6:43 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Thierry Banel, emacs-orgmode


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> I think we could do something similar to links, i.e., populate
> a variable (for links, it is `org-link-parameters') with a command
> (`org-link-set-parameters'), so the dispatcher knows what dynamic blocks
> can be provided.

This is an good idea. Nicolas, do you want to implement it?
I still have some unfinished code in my Org Mode local repo. Like org
inline src block fontify. And ob-diff.el and another one. I become a little lazy currently. :) I know should not use excuse.

Anyway, if you think it's better let me submit PR, I still will add this task in my list.

UPDATE:

I just checked out `org-link-parameters' related source code. I found it is not that complicated. I would like to have a try.

--
[ 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  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
  1 sibling, 1 reply; 15+ messages in thread
From: stardiviner @ 2018-12-20  2:10 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Thierry Banel

[-- Attachment #1: Type: text/plain, Size: 594 bytes --]


I add code patch in attachment. Nicolas, can you review it? Any
suggestion welcome.

After running test with "make test", I got some failed test might related to my code changing. But I checked out the tests, have not found anywhere invoking the renamed functions.

Ran 814 tests, 808 results as expected, 6 unexpected (2018-12-20 09:57:41+0800)
9 expected failures

6 unexpected results:
   FAILED  ob-D/inhomogeneous_table
   FAILED  ob-D/list-list-var
   FAILED  ob-D/list-var
   FAILED  ob-D/vector-var
   FAILED  test-org-clock/clocktable/lang
   FAILED  test-org-colview/columns-width



[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org.el-Add-dispatch-command-for-inserting-dynamic-bl.patch --]
[-- Type: text/x-patch, Size: 11591 bytes --]

From 16ff083a475b7f125136a7bbd131e85833ad822d Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Thu, 20 Dec 2018 09:21:38 +0800
Subject: [PATCH] org.el: Add dispatch command for inserting dynamic blocks

* lisp/org.el (org-dynamic-block-insert-dispatch): The dispatch command
  for inserting dynamic blocks.

  (org-dynamic-block-parameters, org-dynamic-block-functions,
  org-dynamic-block-types, org-dynamic-block-set-parameters,
  org-dynamic-block-get-parameter): New custom option, and new functions
  about dynamic blocks.

  (org-clock-report, org-columns-insert-dblock) Those functions are
  renamed to new name, and removed corresponding keybinding, take
  controled by dispatch command org-dynamic-block-insert-dispatch.

* doc/org-manual.org: Add manual for dispatch command
  ~org-dynamic-block-insert-dispatch~.
---
 doc/org-manual.org  |  9 ++++---
 etc/ORG-NEWS        | 20 +++++++++++++++
 lisp/org-clock.el   |  2 +-
 lisp/org-colview.el |  2 +-
 lisp/org-compat.el  |  2 --
 lisp/org.el         | 59 ++++++++++++++++++++++++++++++++++++++++-----
 6 files changed, 81 insertions(+), 13 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index 051ffaa4d..37afad5b2 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -19872,9 +19872,12 @@ users mailing list, at mailto:emacs-orgmode@gnu.org.
 
 Org supports /dynamic blocks/ in Org documents.  They are inserted
 with begin and end markers like any other code block, but the contents
-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-dispatch~ which is bind to
+keybinding {{{kbd(C-c C-x i)}}} by default.
+
+For example, {{{kbd(C-c C-x i)}}} + ~clocktable~ inserts a dynamic
+table that updates the work time (see [[*Clocking Work Time]]).
 
 Dynamic blocks can have names and function parameters.  The syntax is
 similar to source code block specifications:
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index 811e98147..5bce606f9 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -12,6 +12,11 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
 
 * Version 9.2
 ** Incompatible changes
+*** Renamed some dynamic block generate functions name
+
+- Renamed ~org-clock-report~ to ~org-insert-dblock:clocktable~
+- Renamed ~org-columns-insert-dblock~ to ~org-insert-dblock:columnview~
+
 *** Removal of OrgStruct mode mode and radio lists
 
 OrgStruct minor mode and radio lists mechanism (~org-list-send-list~
@@ -170,6 +175,15 @@ This is consistent with the naming of =org-dblock-write:columnview=
 options, where =:match= is also used as a headlines filter.
 
 ** New features
+
+*** Add a dispatcher command to insert dynamic blocks
+
+You can add dynamic block into ~org-dynamic-block-parameters~ with
+function ~org-dynamic-block-set-parameters~ just like
+~org-link-set-parameters~. All dynamic blocks in
+~org-dynamic-block-set-parameters~ can be used by
+~org-dynamic-block-insert-dispatch~ command.
+
 *** Add ~:results link~ support for Babel
 
 With this output format, create a link to the file specified in
@@ -314,6 +328,12 @@ remove it.
 
 ** New commands and functions
 
+*** ~org-dynamic-block-insert-dispatch~
+
+Use default keybinding =[C-c C-x i]= to run command
+~org-dynamic-block-insert-dispatch~. It will prompt user to select
+dynamic block in ~org-dynamic-block-parameters~.
+
 *** ~org-insert-structure-template~
 
 This function can be used to wrap existing text of Org elements in
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 494423e4e..ebe7b8637 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2024,7 +2024,7 @@ fontified, and then returned."
 				(point-at-bol)))))
 
 ;;;###autoload
-(defun org-clock-report (&optional arg)
+(defun org-insert-dblock:clocktable (&optional arg)
   "Update or create a table containing a report about clocked time.
 
 If point is inside an existing clocktable block, update it.
diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 932275836..6a9a8a601 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -1489,7 +1489,7 @@ PARAMS is a property list of parameters:
 	(org-table-align)))))
 
 ;;;###autoload
-(defun org-columns-insert-dblock ()
+(defun org-insert-dblock:columnview ()
   "Create a dynamic block capturing a column view table."
   (interactive)
   (let ((id (completing-read
diff --git a/lisp/org-compat.el b/lisp/org-compat.el
index 77bf03650..bfe9fae9c 100644
--- a/lisp/org-compat.el
+++ b/lisp/org-compat.el
@@ -214,8 +214,6 @@ Counting starts at 1."
 
 (define-obsolete-function-alias 'org-babel-trim 'org-trim "Org 9.0")
 (define-obsolete-variable-alias 'org-html-style 'org-html-head "24.4")
-(define-obsolete-function-alias 'org-insert-columns-dblock
-  'org-columns-insert-dblock "Org 9.0")
 (define-obsolete-variable-alias 'org-export-babel-evaluate
   'org-export-use-babel "Org 9.1")
 (define-obsolete-function-alias 'org-activate-bracket-links
diff --git a/lisp/org.el b/lisp/org.el
index 8dddf0295..924cd3866 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -132,7 +132,7 @@ Stars are put in group 1 and the trimmed body in group 2.")
 (declare-function org-clock-in-last "org-clock" (&optional arg))
 (declare-function org-clock-out "org-clock" (&optional switch-to-state fail-quietly at-time))
 (declare-function org-clock-remove-overlays "org-clock" (&optional beg end noremove))
-(declare-function org-clock-report "org-clock" (&optional arg))
+(declare-function org-insert-dblock:clocktable "org-clock" (&optional arg))
 (declare-function org-clock-sum "org-clock" (&optional tstart tend headline-filter propname))
 (declare-function org-clock-sum-current-item "org-clock" (&optional tstart))
 (declare-function org-clock-timestamps-down "org-clock" (&optional n))
@@ -140,7 +140,7 @@ Stars are put in group 1 and the trimmed body in group 2.")
 (declare-function org-clock-update-time-maybe "org-clock" ())
 (declare-function org-clocking-buffer "org-clock" ())
 (declare-function org-clocktable-shift "org-clock" (dir n))
-(declare-function org-columns-insert-dblock "org-colview" ())
+(declare-function org-insert-dblock:columnview "org-colview" ())
 (declare-function org-duration-from-minutes "org-duration" (minutes &optional fmt canonical))
 (declare-function org-element-at-point "org-element" ())
 (declare-function org-element-cache-refresh "org-element" (pos))
@@ -11645,6 +11645,54 @@ If COMMAND is not given, use `org-update-dblock'."
 	(unless (re-search-forward org-dblock-end-re nil t)
 	  (error "Dynamic block not terminated"))))))
 
+(defcustom org-dynamic-block-parameters
+  '(("columnview" :function org-insert-dblock:columnview)
+    ("clocktable" :function org-insert-dblock:clocktable))
+  "An alist of properties that defines all the Org dynamic blocks."
+  :type '(alist :tag "dynamic block name"
+                :value-type plist)
+  :group 'org-block
+  :package-version '(Org . "9.1"))
+
+(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))
+
+(defun org-dynamic-block-set-parameters (type &rest parameters)
+  "Set dynamic block TYPE properties to PARAMETERS.
+PARAMETERS should be :key val pairs. Use it like `org-link-set-parameters'."
+  (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))))
+
+(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))
+
+(defun org-dynamic-block-insert-dispatch (dblock-type)
+  "Select and insert an Org type dynamic block.
+This is a dispatching function which prompts for the type of
+dynamic block to insert. It dispatches to functions which names
+matches the pattern `org-insert-dblock:*'"
+  (interactive (list
+                (completing-read "dynamic block: "
+                                 (mapcar #'car org-dynamic-block-parameters))))
+  (let ((func (org-dynamic-block-get-parameter dblock-type :function)))
+    (if (functionp func)
+        (funcall func)
+      (message "No such dynamic block: %s" func))))
+
 (defun org-dblock-update (&optional arg)
   "User command for updating dynamic blocks.
 Update the dynamic block at point.  With prefix ARG, update all dynamic
@@ -19047,6 +19095,7 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-x C-w") #'org-cut-special)
 (org-defkey org-mode-map (kbd "C-c C-x M-w") #'org-copy-special)
 (org-defkey org-mode-map (kbd "C-c C-x C-y") #'org-paste-special)
+(org-defkey org-mode-map (kbd "C-c C-x i") #'org-dynamic-block-insert-dispatch)
 (org-defkey org-mode-map (kbd "C-c C-x C-t") #'org-toggle-time-stamp-overlays)
 (org-defkey org-mode-map (kbd "C-c C-x C-i") #'org-clock-in)
 (org-defkey org-mode-map (kbd "C-c C-x C-x") #'org-clock-in-last)
@@ -19055,7 +19104,6 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-x C-j") #'org-clock-goto)
 (org-defkey org-mode-map (kbd "C-c C-x C-q") #'org-clock-cancel)
 (org-defkey org-mode-map (kbd "C-c C-x C-d") #'org-clock-display)
-(org-defkey org-mode-map (kbd "C-c C-x C-r") #'org-clock-report)
 (org-defkey org-mode-map (kbd "C-c C-x C-u") #'org-dblock-update)
 (org-defkey org-mode-map (kbd "C-c C-x C-l") #'org-toggle-latex-fragment)
 (org-defkey org-mode-map (kbd "C-c C-x C-v") #'org-toggle-inline-images)
@@ -19067,7 +19115,6 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-x e") #'org-set-effort)
 (org-defkey org-mode-map (kbd "C-c C-x E") #'org-inc-effort)
 (org-defkey org-mode-map (kbd "C-c C-x o") #'org-toggle-ordered-property)
-(org-defkey org-mode-map (kbd "C-c C-x i") #'org-columns-insert-dblock)
 (org-defkey org-mode-map (kbd "C-c C-,") #'org-insert-structure-template)
 (org-defkey org-mode-map (kbd "C-c C-x .") #'org-timer)
 (org-defkey org-mode-map (kbd "C-c C-x -") #'org-timer-item)
@@ -20850,7 +20897,7 @@ an argument, unconditionally call `org-insert-heading'."
      "--"
      ["Set property" org-set-property (not (org-before-first-heading-p))]
      ["Column view of properties" org-columns t]
-     ["Insert Column View DBlock" org-columns-insert-dblock t])
+     ["Insert Column View DBlock" org-insert-dblock:columnview t])
     ("Dates and Scheduling"
      ["Timestamp" org-time-stamp (not (org-before-first-heading-p))]
      ["Timestamp (inactive)" org-time-stamp-inactive (not (org-before-first-heading-p))]
@@ -20885,7 +20932,7 @@ an argument, unconditionally call `org-insert-heading'."
      ["Goto running clock" org-clock-goto t]
      "--"
      ["Display times" org-clock-display t]
-     ["Create clock table" org-clock-report t]
+     ["Create clock table" org-insert-dblock:clocktable t]
      "--"
      ["Record DONE time"
       (progn (setq org-log-done (not org-log-done))
-- 
2.20.0


[-- Attachment #3: Type: text/plain, Size: 246 bytes --]


--
[ 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

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  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
  0 siblings, 2 replies; 15+ messages in thread
From: Nicolas Goaziou @ 2018-12-22 22:54 UTC (permalink / raw)
  To: stardiviner; +Cc: Thierry Banel, emacs-orgmode

Hello,

stardiviner <numbchild@gmail.com> writes:

> I add code patch in attachment. Nicolas, can you review it?

Thank you. Some comments follow.

> After running test with "make test", I got some failed test might
> related to my code changing. But I checked out the tests, have not
> found anywhere invoking the renamed functions.

They are not related.

> Ran 814 tests, 808 results as expected, 6 unexpected (2018-12-20 09:57:41+0800)
> 9 expected failures
>
> 6 unexpected results:
>    FAILED  ob-D/inhomogeneous_table
>    FAILED  ob-D/list-list-var
>    FAILED  ob-D/list-var
>    FAILED  ob-D/vector-var

I don't use D, so I cannot help here.

>    FAILED  test-org-clock/clocktable/lang
>    FAILED  test-org-colview/columns-width

This is probably due to a non-default variable leaking in the test. The
full error may help.

> * lisp/org.el (org-dynamic-block-insert-dispatch): The dispatch command
>   for inserting dynamic blocks.

"New function." is enough.
>
>   (org-dynamic-block-parameters, org-dynamic-block-functions,
>   org-dynamic-block-types, org-dynamic-block-set-parameters,
>   org-dynamic-block-get-parameter): New custom option, and new functions
>   about dynamic blocks.

New variables... New functons, etc.

> +are updated automatically by a user function. You can use dispatch

You need two spaces at the end of sentences.

> +command ~org-dynamic-block-insert-dispatch~ which is bind to
> +keybinding {{{kbd(C-c C-x i)}}} by default.

command ~org-dynamic-block-insert-dispatch~, which is bound to
{{{kbd(C-c C-x i)}}} by default.

> +For example, {{{kbd(C-c C-x i)}}} + ~clocktable~ inserts a dynamic

For example, {{{kbd(C-c C-x i c l o c k t a b l e RET)}}}

> +table that updates the work time (see [[*Clocking Work Time]]).
>  
>  Dynamic blocks can have names and function parameters.  The syntax is
>  similar to source code block specifications:
> diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
> index 811e98147..5bce606f9 100644
> --- a/etc/ORG-NEWS
> +++ b/etc/ORG-NEWS
> @@ -12,6 +12,11 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
>  
>  * Version 9.2
>  ** Incompatible changes
> +*** Renamed some dynamic block generate functions name
> +
> +- Renamed ~org-clock-report~ to ~org-insert-dblock:clocktable~
> +- Renamed ~org-columns-insert-dblock~ to ~org-insert-dblock:columnview~
> +

This change will not go in Org 9.2. You need to apply it on top of 9.3,
aka, "next" branch.

> +*** ~org-dynamic-block-insert-dispatch~
> +
> +Use default keybinding =[C-c C-x i]= to run command

=<C-c C-x i>=

> -(defun org-clock-report (&optional arg)
> +(defun org-insert-dblock:clocktable (&optional arg)
>    "Update or create a table containing a report about clocked time.

This function is in the wrong namespace. It should be `org-clock-*'.

>  ;;;###autoload
> -(defun org-columns-insert-dblock ()
> +(defun org-insert-dblock:columnview ()

Ditto.

> -(define-obsolete-function-alias 'org-insert-columns-dblock
> -  'org-columns-insert-dblock "Org 9.0")

Since you replaced `org-columns-insert-dblock', you need to update the
alias, not remove it.

You also need to introduce other aliases for the functions you renamed.

> +(defcustom org-dynamic-block-parameters
> +  '(("columnview" :function org-insert-dblock:columnview)
> +    ("clocktable" :function org-insert-dblock:clocktable))

Why loading them by default? Org clock may not be available. It seems
better to initialize to nil and use `org-dynamic-blocks-set-parameter'
to fill in the variable in "org-clock.el".

> +  "An alist of properties that defines all the Org dynamic blocks."
> +  :type '(alist :tag "dynamic block name"
> +                :value-type plist)
> +  :group 'org-block
> +  :package-version '(Org . "9.1"))

It should be "9.3".

Also, it is missing, e.g., :safe #'listp.

> +(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))
> +
> +(defun org-dynamic-block-set-parameters (type &rest parameters)
> +  "Set dynamic block TYPE properties to PARAMETERS.
> +PARAMETERS should be :key val pairs. Use it like `org-link-set-parameters'."

Missing a space.  Also, the second sentence is not helpful. Instead what
are the supported keywords?

> +(defun org-dynamic-block-insert-dispatch (dblock-type)

I don't think "dispatch" should be in the function name.

> +  "Select and insert an Org type dynamic block.
> +This is a dispatching function which prompts for the type of
> +dynamic block to insert. It dispatches to functions which names

Missing space.

> +matches the pattern `org-insert-dblock:*'"

I don't think it is true. It dispatches functions listed as :function
value.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  2018-12-22 22:54       ` Nicolas Goaziou
@ 2018-12-23  6:26         ` stardiviner
  2018-12-23  6:28         ` stardiviner
  1 sibling, 0 replies; 15+ messages in thread
From: stardiviner @ 2018-12-23  6:26 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Thierry Banel, emacs-orgmode


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> stardiviner <numbchild@gmail.com> writes:
>
>> I add code patch in attachment. Nicolas, can you review it?
>
> Thank you. Some comments follow.
>
>> After running test with "make test", I got some failed test might
>> related to my code changing. But I checked out the tests, have not
>> found anywhere invoking the renamed functions.
>
> They are not related.

I run `make test` (after adding my commit) again on `next` branch.

Got failed tests:

12 unexpected results:
   FAILED  ob-D/inhomogeneous_table
   FAILED  ob-D/list-list-var
   FAILED  ob-D/list-var
   FAILED  ob-D/vector-var
   FAILED  test-org-clock/clocktable/lang
   FAILED  test-org-colview/columns-move-left
   FAILED  test-org-colview/columns-move-right
   FAILED  test-org-colview/columns-new
   FAILED  test-org-colview/columns-next-allowed-value
   FAILED  test-org-colview/columns-scope
   FAILED  test-org-colview/columns-width
   FAILED  test-org-colview/dblock

All are not related to my commit. about test-org-{clock,colview}/* tests, they are failed because of void functions.

>
>> Ran 814 tests, 808 results as expected, 6 unexpected (2018-12-20 09:57:41+0800)
>> 9 expected failures
>>
>> 6 unexpected results:
>>    FAILED  ob-D/inhomogeneous_table
>>    FAILED  ob-D/list-list-var
>>    FAILED  ob-D/list-var
>>    FAILED  ob-D/vector-var
>
> I don't use D, so I cannot help here.
>
>>    FAILED  test-org-clock/clocktable/lang
>>    FAILED  test-org-colview/columns-width
>
> This is probably due to a non-default variable leaking in the test. The
> full error may help.
>
>> * lisp/org.el (org-dynamic-block-insert-dispatch): The dispatch command
>>   for inserting dynamic blocks.
>
> "New function." is enough.

Fixed.

>>
>>   (org-dynamic-block-parameters, org-dynamic-block-functions,
>>   org-dynamic-block-types, org-dynamic-block-set-parameters,
>>   org-dynamic-block-get-parameter): New custom option, and new functions
>>   about dynamic blocks.
>
> New variables... New functons, etc.

Fixed

>
>> +are updated automatically by a user function. You can use dispatch
>
> You need two spaces at the end of sentences.

Fixed

>
>> +command ~org-dynamic-block-insert-dispatch~ which is bind to
>> +keybinding {{{kbd(C-c C-x i)}}} by default.
>
> command ~org-dynamic-block-insert-dispatch~, which is bound to
> {{{kbd(C-c C-x i)}}} by default.

Fixed

>
>> +For example, {{{kbd(C-c C-x i)}}} + ~clocktable~ inserts a dynamic
>
> For example, {{{kbd(C-c C-x i c l o c k t a b l e RET)}}}

Fixed

>
>> +table that updates the work time (see [[*Clocking Work Time]]).
>>
>>  Dynamic blocks can have names and function parameters.  The syntax is
>>  similar to source code block specifications:
>> diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
>> index 811e98147..5bce606f9 100644
>> --- a/etc/ORG-NEWS
>> +++ b/etc/ORG-NEWS
>> @@ -12,6 +12,11 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
>>
>>  * Version 9.2
>>  ** Incompatible changes
>> +*** Renamed some dynamic block generate functions name
>> +
>> +- Renamed ~org-clock-report~ to ~org-insert-dblock:clocktable~
>> +- Renamed ~org-columns-insert-dblock~ to ~org-insert-dblock:columnview~
>> +
>
> This change will not go in Org 9.2. You need to apply it on top of 9.3,
> aka, "next" branch.

Fixed

>
>> +*** ~org-dynamic-block-insert-dispatch~
>> +
>> +Use default keybinding =[C-c C-x i]= to run command
>
> =<C-c C-x i>=

Fixed

>
>> -(defun org-clock-report (&optional arg)
>> +(defun org-insert-dblock:clocktable (&optional arg)
>>    "Update or create a table containing a report about clocked time.
>
> This function is in the wrong namespace. It should be `org-clock-*'.

Fixed. I restored original function names.

>
>>  ;;;###autoload
>> -(defun org-columns-insert-dblock ()
>> +(defun org-insert-dblock:columnview ()
>
> Ditto.

Fixed

>
>> -(define-obsolete-function-alias 'org-insert-columns-dblock
>> -  'org-columns-insert-dblock "Org 9.0")
>
> Since you replaced `org-columns-insert-dblock', you need to update the
> alias, not remove it.

Fixed. I restored original function names.

>
> You also need to introduce other aliases for the functions you renamed.
>
>> +(defcustom org-dynamic-block-parameters
>> +  '(("columnview" :function org-insert-dblock:columnview)
>> +    ("clocktable" :function org-insert-dblock:clocktable))
>
> Why loading them by default? Org clock may not be available. It seems
> better to initialize to nil and use `org-dynamic-blocks-set-parameter'
> to fill in the variable in "org-clock.el".

Fixed

>
>> +  "An alist of properties that defines all the Org dynamic blocks."
>> +  :type '(alist :tag "dynamic block name"
>> +                :value-type plist)
>> +  :group 'org-block
>> +  :package-version '(Org . "9.1"))
>
> It should be "9.3".
>
> Also, it is missing, e.g., :safe #'listp.

Fixed

>
>> +(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))
>> +
>> +(defun org-dynamic-block-set-parameters (type &rest parameters)
>> +  "Set dynamic block TYPE properties to PARAMETERS.
>> +PARAMETERS should be :key val pairs. Use it like `org-link-set-parameters'."
>
> Missing a space.  Also, the second sentence is not helpful. Instead what
> are the supported keywords?

Fixed

>
>> +(defun org-dynamic-block-insert-dispatch (dblock-type)
>
> I don't think "dispatch" should be in the function name.

I use `org-dynamic-block-insert-dblock` now.

>
>> +  "Select and insert an Org type dynamic block.
>> +This is a dispatching function which prompts for the type of
>> +dynamic block to insert. It dispatches to functions which names
>
> Missing space.

Fixed

>
>> +matches the pattern `org-insert-dblock:*'"
>
> I don't think it is true. It dispatches functions listed as :function
> value.

Fixed

>
>
> Regards,

Ask one off-topic question.  How to configure Emacs to auto insert two
spaces after sentence?

What is the "next" branch? Is it like "develop" related to "master" branch?

--
[ 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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  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
  1 sibling, 1 reply; 15+ messages in thread
From: stardiviner @ 2018-12-23  6:28 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Thierry Banel, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 34 bytes --]


I forgot my patch.

Here it is.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-org.el-org-dynamic-block-insert-dispatch-New-fu.patch --]
[-- Type: text/x-patch, Size: 8967 bytes --]

From a14546b26a085e6f8342341e40e185e75358f306 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Sun, 23 Dec 2018 13:35:38 +0800
Subject: [PATCH] * lisp/org.el (org-dynamic-block-insert-dispatch): New
 function.

  (org-dynamic-block-parameters, org-dynamic-block-functions,
  org-dynamic-block-types, org-dynamic-block-set-parameters,
  org-dynamic-block-get-parameter): New variables, New functions.

* lisp/org-keys.el: (org-dynamic-block-insert-dispatch) New
  functions. (org-clock-report, org-columns-insert-dblock) Remove
  functions.

* doc/org-manual.org: Add manual for dispatch command
  ~org-dynamic-block-insert-dispatch~.
---
 doc/org-manual.org  |  9 ++++++---
 etc/ORG-NEWS        | 14 ++++++++++++++
 lisp/org-clock.el   |  5 +++++
 lisp/org-colview.el |  6 +++++-
 lisp/org-keys.el    |  6 ++----
 lisp/org.el         | 46 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 78 insertions(+), 8 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index aad190b3b..2f0f5f136 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -19926,9 +19926,12 @@ users mailing list, at mailto:emacs-orgmode@gnu.org.
 
 Org supports /dynamic blocks/ in Org documents.  They are inserted
 with begin and end markers like any other code block, but the contents
-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-dispatch~, which is bind to
+keybinding {{{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
+dynamic table that updates the work time (see [[*Clocking Work Time]]).
 
 Dynamic blocks can have names and function parameters.  The syntax is
 similar to source code block specifications:
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index f9bea4b56..16e8884f5 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -40,6 +40,14 @@ arguments no longer imply a "file" result is expected.
 See [[git:3367ac9457]] for details.
 
 ** New features
+*** Add a dispatcher command to insert dynamic blocks
+
+You can add dynamic block into ~org-dynamic-block-parameters~ with
+function ~org-dynamic-block-set-parameters~ just like
+~org-link-set-parameters~. All dynamic blocks in
+~org-dynamic-block-set-parameters~ can be used by
+~org-dynamic-block-insert-dblock~ command.
+
 *** Babel
 **** Add LaTeX output support in PlantUML
 *** New property =HTML_HEADLINE_CLASS= in HTML export
@@ -79,6 +87,12 @@ system than the main Org document.  For example:
 the corresponding direction by swapping with the adjacent cell.
 
 ** New functions
+*** ~org-dynamic-block-insert-dblock~
+
+Use default keybinding =<C-c C-x i>= to run command
+~org-dynamic-block-insert-dblock~.  It will prompt user to select
+dynamic block in ~org-dynamic-block-parameters~.
+
 *** ~org-table-cell-up~
 *** ~org-table-cell-down~
 *** ~org-table-cell-left~
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 1ebfa0201..404d346b3 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -2052,6 +2052,11 @@ in the buffer and update it."
     (start (goto-char start)))
   (org-update-dblock))
 
+;;;###autoload
+(org-dynamic-block-set-parameters
+ "clocktable"
+ :function 'org-clock-report)
+
 (defun org-day-of-week (day month year)
   "Returns the day of the week as an integer."
   (nth 6
diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 507c58a6a..a1345144f 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -1237,7 +1237,7 @@ When PRINTF is non-nil, use it to format the result."
   "Summarize CHECK-BOXES with a check-box cookie."
   (format "[%d/%d]"
 	  (cl-count-if (lambda (b) (or (equal b "[X]")
-				  (string-match-p "\\[\\([1-9]\\)/\\1\\]" b)))
+				   (string-match-p "\\[\\([1-9]\\)/\\1\\]" b)))
 		       check-boxes)
 	  (length check-boxes)))
 
@@ -1537,6 +1537,10 @@ PARAMS is a property list of parameters:
 		     (id)))))
   (org-update-dblock))
 
+;;;###autoload
+(org-dynamic-block-set-parameters
+ "columnview"
+ :function 'org-columns-insert-dblock)
 
 \f
 ;;; Column view in the agenda
diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index bed2f2ad4..5d12ce274 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -49,10 +49,8 @@
 (declare-function org-clock-in "org" (&optional select start-time))
 (declare-function org-clock-in-last "org" (&optional arg))
 (declare-function org-clock-out "org" (&optional switch-to-state fail-quietly at-time))
-(declare-function org-clock-report "org" (&optional arg))
 (declare-function org-clone-subtree-with-time-shift "org" (n &optional shift))
 (declare-function org-columns "org" (&optional global columns-fmt-string))
-(declare-function org-columns-insert-dblock "org" ())
 (declare-function org-comment-dwim "org" (arg))
 (declare-function org-copy "org" ())
 (declare-function org-copy-special "org" ())
@@ -67,6 +65,7 @@
 (declare-function org-cycle "org" (&optional arg))
 (declare-function org-cycle-agenda-files "org" ())
 (declare-function org-date-from-calendar "org" ())
+(declare-function org-dynamic-block-insert-dblock "org" (&optional arg))
 (declare-function org-dblock-update "org" (&optional arg))
 (declare-function org-deadline "org" (arg1 &optional time))
 (declare-function org-decrease-number-at-point "org" (&optional inc))
@@ -638,7 +637,7 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-x C-j") #'org-clock-goto)
 (org-defkey org-mode-map (kbd "C-c C-x C-q") #'org-clock-cancel)
 (org-defkey org-mode-map (kbd "C-c C-x C-d") #'org-clock-display)
-(org-defkey org-mode-map (kbd "C-c C-x C-r") #'org-clock-report)
+(org-defkey org-mode-map (kbd "C-c C-x i") #'org-dynamic-block-insert-dblock)
 (org-defkey org-mode-map (kbd "C-c C-x C-u") #'org-dblock-update)
 (org-defkey org-mode-map (kbd "C-c C-x C-l") #'org-toggle-latex-fragment)
 (org-defkey org-mode-map (kbd "C-c C-x C-v") #'org-toggle-inline-images)
@@ -650,7 +649,6 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-x e") #'org-set-effort)
 (org-defkey org-mode-map (kbd "C-c C-x E") #'org-inc-effort)
 (org-defkey org-mode-map (kbd "C-c C-x o") #'org-toggle-ordered-property)
-(org-defkey org-mode-map (kbd "C-c C-x i") #'org-columns-insert-dblock)
 (org-defkey org-mode-map (kbd "C-c C-,") #'org-insert-structure-template)
 (org-defkey org-mode-map (kbd "C-c C-x .") #'org-timer)
 (org-defkey org-mode-map (kbd "C-c C-x -") #'org-timer-item)
diff --git a/lisp/org.el b/lisp/org.el
index 1ee341f43..6ddb6ddae 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11521,6 +11521,52 @@ If COMMAND is not given, use `org-update-dblock'."
 	(unless (re-search-forward org-dblock-end-re nil t)
 	  (error "Dynamic block not terminated"))))))
 
+(defcustom org-dynamic-block-parameters nil
+  "An alist of properties that defines all the Org dynamic blocks."
+  :type '(alist :tag "dynamic block name"
+                :value-type plist)
+  :safe #'listp
+  :group 'org-block
+  :package-version '(Org . "9.3"))
+
+(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))
+
+(defun org-dynamic-block-set-parameters (type &rest parameters)
+  "Set dynamic block TYPE properties to PARAMETERS.
+PARAMETERS should be :key val pairs."
+  (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))))
+
+(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))
+
+(defun org-dynamic-block-insert-dblock (dblock-type)
+  "Select and insert an Org type dynamic block DBLOCK-TYPE.
+This is a dispatching function which prompts for the type of
+dynamic block to insert."
+  (interactive (list
+                (completing-read "dynamic block: "
+                                 (mapcar #'car org-dynamic-block-parameters))))
+  (let ((func (org-dynamic-block-get-parameter dblock-type :function)))
+    (if (functionp func)
+        (funcall func)
+      (message "No such dynamic block: %s" func))))
+
 (defun org-dblock-update (&optional arg)
   "User command for updating dynamic blocks.
 Update the dynamic block at point.  With prefix ARG, update all dynamic
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 254 bytes --]


-- 
[ 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
      

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  2018-12-23  6:28         ` stardiviner
@ 2018-12-23  7:59           ` stardiviner
  2018-12-27 10:59             ` Nicolas Goaziou
  0 siblings, 1 reply; 15+ messages in thread
From: stardiviner @ 2018-12-23  7:59 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Thierry Banel, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 204 bytes --]


stardiviner <numbchild@gmail.com> writes:

I found `make test` report error void function on
`org-dynamic-block-insert-dblock`.

So I removed autoload cookies.

The re-generated patch is in attachment.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-org.el-org-dynamic-block-insert-dispatch-New-fu.patch --]
[-- Type: text/x-patch, Size: 9730 bytes --]

From 96faa0ec9e0849e051542d89a78b376c52ee2ded Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Sun, 23 Dec 2018 13:35:38 +0800
Subject: [PATCH] * lisp/org.el (org-dynamic-block-insert-dispatch): New
 function.

  (org-dynamic-block-parameters, org-dynamic-block-functions,
  org-dynamic-block-types, org-dynamic-block-set-parameters,
  org-dynamic-block-get-parameter): New variables, New functions.

* lisp/org-keys.el: (org-dynamic-block-insert-dispatch) New
  functions. (org-clock-report, org-columns-insert-dblock) Remove
  functions.

* doc/org-manual.org: Add manual for dispatch command
  ~org-dynamic-block-insert-dispatch~.
---
 doc/org-manual.org  |  9 ++++++---
 etc/ORG-NEWS        | 14 ++++++++++++++
 lisp/org-clock.el   |  5 +++++
 lisp/org-colview.el |  6 +++++-
 lisp/org-keys.el    |  6 ++----
 lisp/org.el         | 46 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 78 insertions(+), 8 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index aad190b3b..2f0f5f136 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -19926,9 +19926,12 @@ users mailing list, at mailto:emacs-orgmode@gnu.org.
 
 Org supports /dynamic blocks/ in Org documents.  They are inserted
 with begin and end markers like any other code block, but the contents
-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-dispatch~, which is bind to
+keybinding {{{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
+dynamic table that updates the work time (see [[*Clocking Work Time]]).
 
 Dynamic blocks can have names and function parameters.  The syntax is
 similar to source code block specifications:
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index f9bea4b56..16e8884f5 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -40,6 +40,14 @@ arguments no longer imply a "file" result is expected.
 See [[git:3367ac9457]] for details.
 
 ** New features
+*** Add a dispatcher command to insert dynamic blocks
+
+You can add dynamic block into ~org-dynamic-block-parameters~ with
+function ~org-dynamic-block-set-parameters~ just like
+~org-link-set-parameters~. All dynamic blocks in
+~org-dynamic-block-set-parameters~ can be used by
+~org-dynamic-block-insert-dblock~ command.
+
 *** Babel
 **** Add LaTeX output support in PlantUML
 *** New property =HTML_HEADLINE_CLASS= in HTML export
@@ -79,6 +87,12 @@ system than the main Org document.  For example:
 the corresponding direction by swapping with the adjacent cell.
 
 ** New functions
+*** ~org-dynamic-block-insert-dblock~
+
+Use default keybinding =<C-c C-x i>= to run command
+~org-dynamic-block-insert-dblock~.  It will prompt user to select
+dynamic block in ~org-dynamic-block-parameters~.
+
 *** ~org-table-cell-up~
 *** ~org-table-cell-down~
 *** ~org-table-cell-left~
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 1ebfa0201..531a76d63 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -36,6 +36,7 @@
 (declare-function org-element-property "org-element" (property element))
 (declare-function org-element-type "org-element" (element))
 (declare-function org-table-goto-line "org-table" (n))
+(declare-function org-dynamic-block-set-parameters "org" (type &rest rest))
 
 (defvar org-frame-title-format-backup frame-title-format)
 (defvar org-time-stamp-formats)
@@ -2052,6 +2053,10 @@ in the buffer and update it."
     (start (goto-char start)))
   (org-update-dblock))
 
+(org-dynamic-block-set-parameters
+ "clocktable"
+ :function 'org-clock-report)
+
 (defun org-day-of-week (day month year)
   "Returns the day of the week as an integer."
   (nth 6
diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 507c58a6a..f898c9695 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -41,6 +41,7 @@
 (declare-function org-element-property "org-element" (property element))
 (declare-function org-element-restriction "org-element" (element))
 (declare-function org-element-type "org-element" (element))
+(declare-function org-dynamic-block-set-parameters "org" (type &rest rest))
 
 (defvar org-agenda-columns-add-appointments-to-effort-sum)
 (defvar org-agenda-columns-compute-summary-properties)
@@ -1237,7 +1238,7 @@ When PRINTF is non-nil, use it to format the result."
   "Summarize CHECK-BOXES with a check-box cookie."
   (format "[%d/%d]"
 	  (cl-count-if (lambda (b) (or (equal b "[X]")
-				  (string-match-p "\\[\\([1-9]\\)/\\1\\]" b)))
+				   (string-match-p "\\[\\([1-9]\\)/\\1\\]" b)))
 		       check-boxes)
 	  (length check-boxes)))
 
@@ -1537,6 +1538,9 @@ PARAMS is a property list of parameters:
 		     (id)))))
   (org-update-dblock))
 
+(org-dynamic-block-set-parameters
+ "columnview"
+ :function 'org-columns-insert-dblock)
 
 \f
 ;;; Column view in the agenda
diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index bed2f2ad4..5d12ce274 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -49,10 +49,8 @@
 (declare-function org-clock-in "org" (&optional select start-time))
 (declare-function org-clock-in-last "org" (&optional arg))
 (declare-function org-clock-out "org" (&optional switch-to-state fail-quietly at-time))
-(declare-function org-clock-report "org" (&optional arg))
 (declare-function org-clone-subtree-with-time-shift "org" (n &optional shift))
 (declare-function org-columns "org" (&optional global columns-fmt-string))
-(declare-function org-columns-insert-dblock "org" ())
 (declare-function org-comment-dwim "org" (arg))
 (declare-function org-copy "org" ())
 (declare-function org-copy-special "org" ())
@@ -67,6 +65,7 @@
 (declare-function org-cycle "org" (&optional arg))
 (declare-function org-cycle-agenda-files "org" ())
 (declare-function org-date-from-calendar "org" ())
+(declare-function org-dynamic-block-insert-dblock "org" (&optional arg))
 (declare-function org-dblock-update "org" (&optional arg))
 (declare-function org-deadline "org" (arg1 &optional time))
 (declare-function org-decrease-number-at-point "org" (&optional inc))
@@ -638,7 +637,7 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-x C-j") #'org-clock-goto)
 (org-defkey org-mode-map (kbd "C-c C-x C-q") #'org-clock-cancel)
 (org-defkey org-mode-map (kbd "C-c C-x C-d") #'org-clock-display)
-(org-defkey org-mode-map (kbd "C-c C-x C-r") #'org-clock-report)
+(org-defkey org-mode-map (kbd "C-c C-x i") #'org-dynamic-block-insert-dblock)
 (org-defkey org-mode-map (kbd "C-c C-x C-u") #'org-dblock-update)
 (org-defkey org-mode-map (kbd "C-c C-x C-l") #'org-toggle-latex-fragment)
 (org-defkey org-mode-map (kbd "C-c C-x C-v") #'org-toggle-inline-images)
@@ -650,7 +649,6 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-x e") #'org-set-effort)
 (org-defkey org-mode-map (kbd "C-c C-x E") #'org-inc-effort)
 (org-defkey org-mode-map (kbd "C-c C-x o") #'org-toggle-ordered-property)
-(org-defkey org-mode-map (kbd "C-c C-x i") #'org-columns-insert-dblock)
 (org-defkey org-mode-map (kbd "C-c C-,") #'org-insert-structure-template)
 (org-defkey org-mode-map (kbd "C-c C-x .") #'org-timer)
 (org-defkey org-mode-map (kbd "C-c C-x -") #'org-timer-item)
diff --git a/lisp/org.el b/lisp/org.el
index 1ee341f43..6ddb6ddae 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11521,6 +11521,52 @@ If COMMAND is not given, use `org-update-dblock'."
 	(unless (re-search-forward org-dblock-end-re nil t)
 	  (error "Dynamic block not terminated"))))))
 
+(defcustom org-dynamic-block-parameters nil
+  "An alist of properties that defines all the Org dynamic blocks."
+  :type '(alist :tag "dynamic block name"
+                :value-type plist)
+  :safe #'listp
+  :group 'org-block
+  :package-version '(Org . "9.3"))
+
+(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))
+
+(defun org-dynamic-block-set-parameters (type &rest parameters)
+  "Set dynamic block TYPE properties to PARAMETERS.
+PARAMETERS should be :key val pairs."
+  (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))))
+
+(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))
+
+(defun org-dynamic-block-insert-dblock (dblock-type)
+  "Select and insert an Org type dynamic block DBLOCK-TYPE.
+This is a dispatching function which prompts for the type of
+dynamic block to insert."
+  (interactive (list
+                (completing-read "dynamic block: "
+                                 (mapcar #'car org-dynamic-block-parameters))))
+  (let ((func (org-dynamic-block-get-parameter dblock-type :function)))
+    (if (functionp func)
+        (funcall func)
+      (message "No such dynamic block: %s" func))))
+
 (defun org-dblock-update (&optional arg)
   "User command for updating dynamic blocks.
 Update the dynamic block at point.  With prefix ARG, update all dynamic
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 247 bytes --]



--
[ 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

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  2018-12-23  7:59           ` stardiviner
@ 2018-12-27 10:59             ` Nicolas Goaziou
  2018-12-27 15:25               ` stardiviner
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Goaziou @ 2018-12-27 10:59 UTC (permalink / raw)
  To: stardiviner; +Cc: Thierry Banel, emacs-orgmode

Hello,

stardiviner <numbchild@gmail.com> writes:

> The re-generated patch is in attachment.

Thank you!

> ---
>  doc/org-manual.org  |  9 ++++++---
>  etc/ORG-NEWS        | 14 ++++++++++++++
>  lisp/org-clock.el   |  5 +++++
>  lisp/org-colview.el |  6 +++++-
>  lisp/org-keys.el    |  6 ++----
>  lisp/org.el         | 46 +++++++++++++++++++++++++++++++++++++++++++++

You forgot to mark removed functions, e.g., `org-clock-report', as
obsolete in "org-compat.el".

>  Org supports /dynamic blocks/ in Org documents.  They are inserted
>  with begin and end markers like any other code block, but the contents
> -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-dispatch~, which is bind to
> +keybinding {{{kbd(C-c C-x i)}}} by default.

which is bound to {{{kbd(C-c C-x i)}}} by default.

Don't forget the #+kindex and #+findex entries above.

> +(defcustom org-dynamic-block-parameters nil
> +  "An alist of properties that defines all the Org dynamic blocks."

What is the key of the alist? The possible keywords for the plist? This
should appear in the docstring.

So far, only :function is supported. If there is no plan for extending
that, maybe a plain alist, e.g., ("type" . function) should suffice?
I.e., isn't mimicking `org-link-set-parameters' a bit too much? WDYT?

> +(defun org-dynamic-block-insert-dblock (dblock-type)
> +  "Select and insert an Org type dynamic block DBLOCK-TYPE.

Insert a dynamic block of type DBLOCK-TYPE.

> +This is a dispatching function which prompts for the type of
> +dynamic block to insert."

When used interactively, select the dynamic block types among defined
types, per `org-dynamic-block-set-parameters'.

Also, once we agree on the design, would you mind writing some tests?

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  2018-12-27 10:59             ` Nicolas Goaziou
@ 2018-12-27 15:25               ` stardiviner
  2018-12-30  9:27                 ` Nicolas Goaziou
  0 siblings, 1 reply; 15+ messages in thread
From: stardiviner @ 2018-12-27 15:25 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Thierry Banel, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 3322 bytes --]


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> stardiviner <numbchild@gmail.com> writes:
>
>> The re-generated patch is in attachment.
>
> Thank you!

:)

>
>> ---
>>  doc/org-manual.org  |  9 ++++++---
>>  etc/ORG-NEWS        | 14 ++++++++++++++
>>  lisp/org-clock.el   |  5 +++++
>>  lisp/org-colview.el |  6 +++++-
>>  lisp/org-keys.el    |  6 ++----
>>  lisp/org.el         | 46 +++++++++++++++++++++++++++++++++++++++++++++
>
> You forgot to mark removed functions, e.g., `org-clock-report', as
> obsolete in "org-compat.el".
>
>>  Org supports /dynamic blocks/ in Org documents.  They are inserted
>>  with begin and end markers like any other code block, but the contents
>> -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-dispatch~, which is bind to
>> +keybinding {{{kbd(C-c C-x i)}}} by default.
>
> which is bound to {{{kbd(C-c C-x i)}}} by default.
>
> Don't forget the #+kindex and #+findex entries above.

Done, I have not really looked the "doc/org-manual.org" seriously. So
have not realized need to add #+kindex and #findex. Added now.

>
>> +(defcustom org-dynamic-block-parameters nil
>> +  "An alist of properties that defines all the Org dynamic blocks."
>
> What is the key of the alist? The possible keywords for the plist? This
> should appear in the docstring.

I improved the docstring. It should be clear now.

>
> So far, only :function is supported. If there is no plan for extending
> that, maybe a plain alist, e.g., ("type" . function) should suffice?
> I.e., isn't mimicking `org-link-set-parameters' a bit too much? WDYT?
>

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.

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. If you this is acceptable, I think I would like to keep
this.

>> +(defun org-dynamic-block-insert-dblock (dblock-type)
>> +  "Select and insert an Org type dynamic block DBLOCK-TYPE.
>
> Insert a dynamic block of type DBLOCK-TYPE.

Modified.

>
>> +This is a dispatching function which prompts for the type of
>> +dynamic block to insert."
>
> When used interactively, select the dynamic block types among defined
> types, per `org-dynamic-block-set-parameters'.

Dito

>
> Also, once we agree on the design, would you mind writing some tests?

About test, would you allow me to write it later? I remember I watched
the org clock dynamic block test once, the literal string is complex,
and I remember I used to wrote a test about similar thing. Make me feel
hard. Give me a little time. I will add it. I promise. Can you merge
this at first? (Keep this commit behind, to merge all new commits, might
need to solve conflicts, Huu.....) WDYT?

>
> Regards,

:) I found you're kind than I think. If I'm wrong, don't tell me.

At last, present my updated patch. Merry Christmas.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-org.el-org-dynamic-block-insert-dblock-New-func.patch --]
[-- Type: text/x-patch, Size: 10090 bytes --]

From e3397a665261bb2c9f9396b16e0100132a3275d5 Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Sun, 23 Dec 2018 13:35:38 +0800
Subject: [PATCH] * lisp/org.el (org-dynamic-block-insert-dblock): New
 function.

  (org-dynamic-block-parameters, org-dynamic-block-functions,
  org-dynamic-block-types, org-dynamic-block-set-parameters,
  org-dynamic-block-get-parameter): New variables, New functions.

* lisp/org-keys.el: (org-dynamic-block-insert-dblock) New
  functions. (org-clock-report, org-columns-insert-dblock) Remove
  functions.

* doc/org-manual.org: Add manual for dispatch command
  ~org-dynamic-block-insert-dblock~.
---
 doc/org-manual.org  | 13 +++++++++---
 etc/ORG-NEWS        | 14 +++++++++++++
 lisp/org-clock.el   |  5 +++++
 lisp/org-colview.el |  6 +++++-
 lisp/org-keys.el    |  6 ++----
 lisp/org.el         | 50 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 86 insertions(+), 8 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index aad190b3b..817b0ac25 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -19926,9 +19926,16 @@ users mailing list, at mailto:emacs-orgmode@gnu.org.
 
 Org supports /dynamic blocks/ in Org documents.  They are inserted
 with begin and end markers like any other code block, but the contents
-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]]).
 
 Dynamic blocks can have names and function parameters.  The syntax is
 similar to source code block specifications:
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index f9bea4b56..16e8884f5 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -40,6 +40,14 @@ arguments no longer imply a "file" result is expected.
 See [[git:3367ac9457]] for details.
 
 ** New features
+*** Add a dispatcher command to insert dynamic blocks
+
+You can add dynamic block into ~org-dynamic-block-parameters~ with
+function ~org-dynamic-block-set-parameters~ just like
+~org-link-set-parameters~. All dynamic blocks in
+~org-dynamic-block-set-parameters~ can be used by
+~org-dynamic-block-insert-dblock~ command.
+
 *** Babel
 **** Add LaTeX output support in PlantUML
 *** New property =HTML_HEADLINE_CLASS= in HTML export
@@ -79,6 +87,12 @@ system than the main Org document.  For example:
 the corresponding direction by swapping with the adjacent cell.
 
 ** New functions
+*** ~org-dynamic-block-insert-dblock~
+
+Use default keybinding =<C-c C-x i>= to run command
+~org-dynamic-block-insert-dblock~.  It will prompt user to select
+dynamic block in ~org-dynamic-block-parameters~.
+
 *** ~org-table-cell-up~
 *** ~org-table-cell-down~
 *** ~org-table-cell-left~
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 1ebfa0201..531a76d63 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -36,6 +36,7 @@
 (declare-function org-element-property "org-element" (property element))
 (declare-function org-element-type "org-element" (element))
 (declare-function org-table-goto-line "org-table" (n))
+(declare-function org-dynamic-block-set-parameters "org" (type &rest rest))
 
 (defvar org-frame-title-format-backup frame-title-format)
 (defvar org-time-stamp-formats)
@@ -2052,6 +2053,10 @@ in the buffer and update it."
     (start (goto-char start)))
   (org-update-dblock))
 
+(org-dynamic-block-set-parameters
+ "clocktable"
+ :function 'org-clock-report)
+
 (defun org-day-of-week (day month year)
   "Returns the day of the week as an integer."
   (nth 6
diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 507c58a6a..f898c9695 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -41,6 +41,7 @@
 (declare-function org-element-property "org-element" (property element))
 (declare-function org-element-restriction "org-element" (element))
 (declare-function org-element-type "org-element" (element))
+(declare-function org-dynamic-block-set-parameters "org" (type &rest rest))
 
 (defvar org-agenda-columns-add-appointments-to-effort-sum)
 (defvar org-agenda-columns-compute-summary-properties)
@@ -1237,7 +1238,7 @@ When PRINTF is non-nil, use it to format the result."
   "Summarize CHECK-BOXES with a check-box cookie."
   (format "[%d/%d]"
 	  (cl-count-if (lambda (b) (or (equal b "[X]")
-				  (string-match-p "\\[\\([1-9]\\)/\\1\\]" b)))
+				   (string-match-p "\\[\\([1-9]\\)/\\1\\]" b)))
 		       check-boxes)
 	  (length check-boxes)))
 
@@ -1537,6 +1538,9 @@ PARAMS is a property list of parameters:
 		     (id)))))
   (org-update-dblock))
 
+(org-dynamic-block-set-parameters
+ "columnview"
+ :function 'org-columns-insert-dblock)
 
 \f
 ;;; Column view in the agenda
diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index bed2f2ad4..5d12ce274 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -49,10 +49,8 @@
 (declare-function org-clock-in "org" (&optional select start-time))
 (declare-function org-clock-in-last "org" (&optional arg))
 (declare-function org-clock-out "org" (&optional switch-to-state fail-quietly at-time))
-(declare-function org-clock-report "org" (&optional arg))
 (declare-function org-clone-subtree-with-time-shift "org" (n &optional shift))
 (declare-function org-columns "org" (&optional global columns-fmt-string))
-(declare-function org-columns-insert-dblock "org" ())
 (declare-function org-comment-dwim "org" (arg))
 (declare-function org-copy "org" ())
 (declare-function org-copy-special "org" ())
@@ -67,6 +65,7 @@
 (declare-function org-cycle "org" (&optional arg))
 (declare-function org-cycle-agenda-files "org" ())
 (declare-function org-date-from-calendar "org" ())
+(declare-function org-dynamic-block-insert-dblock "org" (&optional arg))
 (declare-function org-dblock-update "org" (&optional arg))
 (declare-function org-deadline "org" (arg1 &optional time))
 (declare-function org-decrease-number-at-point "org" (&optional inc))
@@ -638,7 +637,7 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-x C-j") #'org-clock-goto)
 (org-defkey org-mode-map (kbd "C-c C-x C-q") #'org-clock-cancel)
 (org-defkey org-mode-map (kbd "C-c C-x C-d") #'org-clock-display)
-(org-defkey org-mode-map (kbd "C-c C-x C-r") #'org-clock-report)
+(org-defkey org-mode-map (kbd "C-c C-x i") #'org-dynamic-block-insert-dblock)
 (org-defkey org-mode-map (kbd "C-c C-x C-u") #'org-dblock-update)
 (org-defkey org-mode-map (kbd "C-c C-x C-l") #'org-toggle-latex-fragment)
 (org-defkey org-mode-map (kbd "C-c C-x C-v") #'org-toggle-inline-images)
@@ -650,7 +649,6 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-x e") #'org-set-effort)
 (org-defkey org-mode-map (kbd "C-c C-x E") #'org-inc-effort)
 (org-defkey org-mode-map (kbd "C-c C-x o") #'org-toggle-ordered-property)
-(org-defkey org-mode-map (kbd "C-c C-x i") #'org-columns-insert-dblock)
 (org-defkey org-mode-map (kbd "C-c C-,") #'org-insert-structure-template)
 (org-defkey org-mode-map (kbd "C-c C-x .") #'org-timer)
 (org-defkey org-mode-map (kbd "C-c C-x -") #'org-timer-item)
diff --git a/lisp/org.el b/lisp/org.el
index 1ee341f43..f87b898d1 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11521,6 +11521,56 @@ If COMMAND is not given, use `org-update-dblock'."
 	(unless (re-search-forward org-dblock-end-re nil t)
 	  (error "Dynamic block not terminated"))))))
 
+(defcustom org-dynamic-block-parameters nil
+  "An alist of properties that defines all the Org dynamic blocks.
+The key of alist is a string of the dynamic block type name.
+The value of alist is a property list.
+The property list is constructured by key `:function' and a function name. "
+  :type '(alist :tag "dynamic block name"
+		:key-type string
+                :value-type plist)
+  :safe #'listp
+  :group 'org-block
+  :package-version '(Org . "9.3"))
+
+(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))
+
+(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))))
+
+(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))
+
+(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))))
+  (let ((func (org-dynamic-block-get-parameter dblock-type :function)))
+    (if (functionp func)
+        (funcall func)
+      (message "No such dynamic block: %s" func))))
+
 (defun org-dblock-update (&optional arg)
   "User command for updating dynamic blocks.
 Update the dynamic block at point.  With prefix ARG, update all dynamic
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 247 bytes --]



--
[ 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

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  2018-12-27 15:25               ` stardiviner
@ 2018-12-30  9:27                 ` Nicolas Goaziou
  2019-01-02  0:12                   ` stardiviner
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Goaziou @ 2018-12-30  9:27 UTC (permalink / raw)
  To: stardiviner; +Cc: Thierry Banel, emacs-orgmode

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  2018-12-30  9:27                 ` Nicolas Goaziou
@ 2019-01-02  0:12                   ` stardiviner
  2019-01-02 14:57                     ` Nicolas Goaziou
  0 siblings, 1 reply; 15+ messages in thread
From: stardiviner @ 2019-01-02  0:12 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Thierry Banel, emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 4684 bytes --]


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> 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.

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.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-lisp-org.el-org-dynamic-block-insert-dblock-New-func.patch --]
[-- Type: text/x-patch, Size: 10625 bytes --]

From ac812470f074e40727a0ee5487f4608418ec18ea Mon Sep 17 00:00:00 2001
From: stardiviner <numbchild@gmail.com>
Date: Sun, 23 Dec 2018 13:35:38 +0800
Subject: [PATCH] * lisp/org.el (org-dynamic-block-insert-dblock): New
 function.

  (org-dynamic-block-alist, org-dynamic-block-functions,
  org-dynamic-block-types, org-dynamic-block-define,
  org-dynamic-block-get-func): New variables, New functions.

* lisp/org-keys.el: (org-dynamic-block-insert-dblock) New
  functions. (org-clock-report, org-columns-insert-dblock) Remove
  function keybindings.

* doc/org-manual.org: Add manual for dispatch command
  ~org-dynamic-block-insert-dblock~.

* testing/lisp/test-org-clock.el: Add test for inserting clocktable with
  `org-dynamic-block-insert-dblock'.
---
 doc/org-manual.org             | 13 ++++++++++---
 etc/ORG-NEWS                   | 13 +++++++++++++
 lisp/org-clock.el              |  3 +++
 lisp/org-colview.el            |  4 +++-
 lisp/org-keys.el               |  6 ++----
 lisp/org.el                    | 34 ++++++++++++++++++++++++++++++++++
 testing/lisp/test-org-clock.el | 24 ++++++++++++++++++++++++
 7 files changed, 89 insertions(+), 8 deletions(-)

diff --git a/doc/org-manual.org b/doc/org-manual.org
index aad190b3b..5b4a0b241 100644
--- a/doc/org-manual.org
+++ b/doc/org-manual.org
@@ -19926,9 +19926,16 @@ users mailing list, at mailto:emacs-orgmode@gnu.org.
 
 Org supports /dynamic blocks/ in Org documents.  They are inserted
 with begin and end markers like any other code block, but the contents
-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 x)}}} by default.
+
+#+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 x)}}} by default.  For example,
+{{{kbd(C-c C-x x c l o c k t a b l e RET)}}} inserts a table that
+updates the work time (see [[*Clocking Work Time]]).
 
 Dynamic blocks can have names and function parameters.  The syntax is
 similar to source code block specifications:
diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index f9bea4b56..aab006d8e 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -40,6 +40,13 @@ arguments no longer imply a "file" result is expected.
 See [[git:3367ac9457]] for details.
 
 ** New features
+*** Add a dispatcher command to insert dynamic blocks
+
+You can add dynamic block into ~org-dynamic-block-alist~ with function
+~org-dynamic-block-define~.  All dynamic blocks in
+~org-dynamic-block-define~ can be used by
+~org-dynamic-block-insert-dblock~ command.
+
 *** Babel
 **** Add LaTeX output support in PlantUML
 *** New property =HTML_HEADLINE_CLASS= in HTML export
@@ -79,6 +86,12 @@ system than the main Org document.  For example:
 the corresponding direction by swapping with the adjacent cell.
 
 ** New functions
+*** ~org-dynamic-block-insert-dblock~
+
+Use default keybinding =<C-c C-x x>= to run command
+~org-dynamic-block-insert-dblock~.  It will prompt user to select
+dynamic block in ~org-dynamic-block-alist~.
+
 *** ~org-table-cell-up~
 *** ~org-table-cell-down~
 *** ~org-table-cell-left~
diff --git a/lisp/org-clock.el b/lisp/org-clock.el
index 1ebfa0201..3beef39eb 100644
--- a/lisp/org-clock.el
+++ b/lisp/org-clock.el
@@ -36,6 +36,7 @@
 (declare-function org-element-property "org-element" (property element))
 (declare-function org-element-type "org-element" (element))
 (declare-function org-table-goto-line "org-table" (n))
+(declare-function org-dynamic-block-define "org" (type &rest rest))
 
 (defvar org-frame-title-format-backup frame-title-format)
 (defvar org-time-stamp-formats)
@@ -2052,6 +2053,8 @@ in the buffer and update it."
     (start (goto-char start)))
   (org-update-dblock))
 
+(org-dynamic-block-define "clocktable" #'org-clock-report)
+
 (defun org-day-of-week (day month year)
   "Returns the day of the week as an integer."
   (nth 6
diff --git a/lisp/org-colview.el b/lisp/org-colview.el
index 507c58a6a..eb0975ed5 100644
--- a/lisp/org-colview.el
+++ b/lisp/org-colview.el
@@ -41,6 +41,7 @@
 (declare-function org-element-property "org-element" (property element))
 (declare-function org-element-restriction "org-element" (element))
 (declare-function org-element-type "org-element" (element))
+(declare-function org-dynamic-block-define "org" (type &rest rest))
 
 (defvar org-agenda-columns-add-appointments-to-effort-sum)
 (defvar org-agenda-columns-compute-summary-properties)
@@ -1237,7 +1238,7 @@ When PRINTF is non-nil, use it to format the result."
   "Summarize CHECK-BOXES with a check-box cookie."
   (format "[%d/%d]"
 	  (cl-count-if (lambda (b) (or (equal b "[X]")
-				  (string-match-p "\\[\\([1-9]\\)/\\1\\]" b)))
+				   (string-match-p "\\[\\([1-9]\\)/\\1\\]" b)))
 		       check-boxes)
 	  (length check-boxes)))
 
@@ -1537,6 +1538,7 @@ PARAMS is a property list of parameters:
 		     (id)))))
   (org-update-dblock))
 
+(org-dynamic-block-define "columnview" #'org-columns-insert-dblock)
 
 \f
 ;;; Column view in the agenda
diff --git a/lisp/org-keys.el b/lisp/org-keys.el
index bed2f2ad4..cd9ba1d8a 100644
--- a/lisp/org-keys.el
+++ b/lisp/org-keys.el
@@ -49,10 +49,8 @@
 (declare-function org-clock-in "org" (&optional select start-time))
 (declare-function org-clock-in-last "org" (&optional arg))
 (declare-function org-clock-out "org" (&optional switch-to-state fail-quietly at-time))
-(declare-function org-clock-report "org" (&optional arg))
 (declare-function org-clone-subtree-with-time-shift "org" (n &optional shift))
 (declare-function org-columns "org" (&optional global columns-fmt-string))
-(declare-function org-columns-insert-dblock "org" ())
 (declare-function org-comment-dwim "org" (arg))
 (declare-function org-copy "org" ())
 (declare-function org-copy-special "org" ())
@@ -67,6 +65,7 @@
 (declare-function org-cycle "org" (&optional arg))
 (declare-function org-cycle-agenda-files "org" ())
 (declare-function org-date-from-calendar "org" ())
+(declare-function org-dynamic-block-insert-dblock "org" (&optional arg))
 (declare-function org-dblock-update "org" (&optional arg))
 (declare-function org-deadline "org" (arg1 &optional time))
 (declare-function org-decrease-number-at-point "org" (&optional inc))
@@ -638,7 +637,7 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-x C-j") #'org-clock-goto)
 (org-defkey org-mode-map (kbd "C-c C-x C-q") #'org-clock-cancel)
 (org-defkey org-mode-map (kbd "C-c C-x C-d") #'org-clock-display)
-(org-defkey org-mode-map (kbd "C-c C-x C-r") #'org-clock-report)
+(org-defkey org-mode-map (kbd "C-c C-x x") #'org-dynamic-block-insert-dblock)
 (org-defkey org-mode-map (kbd "C-c C-x C-u") #'org-dblock-update)
 (org-defkey org-mode-map (kbd "C-c C-x C-l") #'org-toggle-latex-fragment)
 (org-defkey org-mode-map (kbd "C-c C-x C-v") #'org-toggle-inline-images)
@@ -650,7 +649,6 @@ COMMANDS is a list of alternating OLDDEF NEWDEF command names."
 (org-defkey org-mode-map (kbd "C-c C-x e") #'org-set-effort)
 (org-defkey org-mode-map (kbd "C-c C-x E") #'org-inc-effort)
 (org-defkey org-mode-map (kbd "C-c C-x o") #'org-toggle-ordered-property)
-(org-defkey org-mode-map (kbd "C-c C-x i") #'org-columns-insert-dblock)
 (org-defkey org-mode-map (kbd "C-c C-,") #'org-insert-structure-template)
 (org-defkey org-mode-map (kbd "C-c C-x .") #'org-timer)
 (org-defkey org-mode-map (kbd "C-c C-x -") #'org-timer-item)
diff --git a/lisp/org.el b/lisp/org.el
index 1ee341f43..19f164426 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -11521,6 +11521,40 @@ If COMMAND is not given, use `org-update-dblock'."
 	(unless (re-search-forward org-dblock-end-re nil t)
 	  (error "Dynamic block not terminated"))))))
 
+(defcustom org-dynamic-block-alist nil
+  "An alist that defines all the Org dynamic blocks.
+The key of alist is a string of the dynamic block type name.
+The value of alist is a definition function to insert dynamic block."
+  :type '(alist :tag "dynamic block name"
+		:key-type string
+                :value-type function)
+  :safe #'listp
+  :group 'org-block
+  :package-version '(Org . "9.3"))
+
+(defun org-dynamic-block-get-func (type)
+  "Get TYPE dynamic block property which TYPE is a string."
+  (cdr (assoc type org-dynamic-block-alist)))
+
+(defun org-dynamic-block-types ()
+  "Return all defined dynamic block types."
+  (mapcar #'car org-dynamic-block-alist))
+
+(defun org-dynamic-block-define (type func)
+  "Define dynamic block TYPE with FUNC."
+  (push (cons type func) org-dynamic-block-alist))
+
+(defun org-dynamic-block-insert-dblock (type)
+  "Insert a dynamic block of type TYPE.
+When used interactively, select the dynamic block types among
+defined types, per `org-dynamic-block-define'."
+  (interactive (list (completing-read "dynamic block: "
+				      (org-dynamic-block-types))))
+  (let ((func (org-dynamic-block-get-func type)))
+    (if (functionp func)
+        (funcall func)
+      (message "No such dynamic block: %s" func))))
+
 (defun org-dblock-update (&optional arg)
   "User command for updating dynamic blocks.
 Update the dynamic block at point.  With prefix ARG, update all dynamic
diff --git a/testing/lisp/test-org-clock.el b/testing/lisp/test-org-clock.el
index 0d5cb5569..04ff9c06b 100644
--- a/testing/lisp/test-org-clock.el
+++ b/testing/lisp/test-org-clock.el
@@ -273,6 +273,30 @@ the buffer."
 \f
 ;;; Clocktable
 
+(ert-deftest test-org-clock/clocktable/insert ()
+  "Test insert clocktable dynamic block with `org-dynamic-block-insert-dblock'."
+  (should
+   (equal
+    "| Headline     | Time   |      |
+|--------------+--------+------|
+| *Total time* | *1:00* |      |
+|--------------+--------+------|
+| \\_  H2       |        | 1:00 |"
+    (org-test-with-temp-text "** H1\n\n** H2\n<point>"
+      (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
+
+      (goto-line 2)
+      (require 'org-clock)
+      (org-dynamic-block-insert-dblock "clocktable")
+
+      (goto-line 1)
+      (unwind-protect
+	  (save-excursion
+	    (when (search-forward "#+CAPTION:") (forward-line))
+	    (buffer-substring-no-properties
+	     (point) (progn (search-forward "#+END:") (line-end-position 0))))
+	(delete-region (point) (search-forward "#+END:\n")))))))
+
 (ert-deftest test-org-clock/clocktable/ranges ()
   "Test ranges in Clock table."
   ;; Relative time: Previous two days.
-- 
2.20.1


[-- Attachment #3: Type: text/plain, Size: 255 bytes --]



-- 
[ 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
      

^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  2019-01-02  0:12                   ` stardiviner
@ 2019-01-02 14:57                     ` Nicolas Goaziou
  2019-01-03 12:19                       ` stardiviner
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Goaziou @ 2019-01-02 14:57 UTC (permalink / raw)
  To: stardiviner; +Cc: Thierry Banel, emacs-orgmode

Hello,

stardiviner <numbchild@gmail.com> writes:

> As always, add patch as attachment.

Thank you! I applied your patch, with minor tweaks.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [Feature Request] Add an dispatcher command (keybinding) for inserting dynamic blocks
  2019-01-02 14:57                     ` Nicolas Goaziou
@ 2019-01-03 12:19                       ` stardiviner
  0 siblings, 0 replies; 15+ messages in thread
From: stardiviner @ 2019-01-03 12:19 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: Thierry Banel, emacs-orgmode


Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> stardiviner <numbchild@gmail.com> writes:
>
>> As always, add patch as attachment.
>
> Thank you! I applied your patch, with minor tweaks.
>
> Regards,

Thanks Nicolas.

I will continue contribute in Org Mode.


-- 
[ 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
      

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-01-03 12:17 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2019-01-02  0:12                   ` stardiviner
2019-01-02 14:57                     ` Nicolas Goaziou
2019-01-03 12:19                       ` stardiviner

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).