Automatically perform measurement on task completion

This commit is contained in:
Bram Schoenmakers 2022-11-26 21:21:04 +01:00
parent 9545da18f7
commit 80228b0cdb
2 changed files with 13 additions and 37 deletions

View file

@ -51,11 +51,14 @@ Put this in ~/.termux/termux.properties for a better Emacs experience inside Ter
:URL: https://emacs.ch/@bram85/109403483724552863
:END:
Using the idea of evaluating code on state changes [[id:3be8333e-7a47-4251-8ee4-2cba0ec4614b][below]].
#+begin_src org :tangle gists/track-use-package-over-time.org
,* TODO Update Emacs package count
DEADLINE: <2022-12-26 Mon .+1m>
:PROPERTIES:
:LAST_REPEAT: [2022-11-26 Sat 07:57]
:ON_DONE: (org-babel-execute-subtree)
:END:
:LOGBOOK:
- State "DONE" from "TODO" [2022-11-26 Sat 07:57]
@ -63,38 +66,10 @@ Put this in ~/.termux/termux.properties for a better Emacs experience inside Ter
A small org file to keep track of some metric in a table, see [[https://orgmode.org/manual/Results-of-Evaluation.html][Results of Evaluation]] in the Org mode manual for more information.
In this case, count the number of packages in my Emacs init file. The code will automatically mark the task as DONE (thanks to [[https://emacs.ch/@leadore@toot.cafe/109406486013699362][@leadore@toot.cafe]]).
In this case, count the number of packages in my Emacs init file. It is executed automatically when the task is marked as done, using [[https://apps.bram85.nl/gitea/bram/gists/src/branch/main/gists/evaluate-code-on-task-state-change.org][this function]].
Press =C-c C-c= inside the code block to add a new entry to the table below.
,#+begin_src elisp :results table append
(save-excursion
(org-back-to-heading t)
(org-todo "DONE")
(with-temp-buffer
(insert-file-contents user-init-file)
(list (format-time-string "%F") (count-matches "(use-package "))))
,#+end_src
,#+RESULTS:
| 2022-11-25 | 140 |
| 2022-11-26 | 140 |
#+end_src
** Idea: event handlers :idea:
:PROPERTIES:
:URL: https://emacs.ch/@bram85/109408862071542059
:END:
Have =ON_<STATE>= properties containing code that evaluates when that state is reached. Can be looked up and evaluated from =org-after-todo-state-change-hook=.
#+begin_src org :tangle gists/org-event-handlers.org
,* TODO Update metric
:PROPERTIES:
:ON_DONE: (org-babel-execute-subtree)
:END:
,#+begin_src elisp :results table append
(with-temp-buffer
(insert-file-contents user-init-file)
@ -102,6 +77,7 @@ Have =ON_<STATE>= properties containing code that evaluates when that state is r
,#+end_src
,#+RESULTS:
| 2022-11-25 | 140 |
| 2022-11-26 | 140 |
#+end_src
@ -125,6 +101,9 @@ My vertico-repeat setup.
#+end_src
* Evaluate code on task state changes :emacs:org:
:PROPERTIES:
:ID: 3be8333e-7a47-4251-8ee4-2cba0ec4614b
:END:
#+begin_src org :tangle gists/evaluate-code-on-task-state-change.org
The function below evaluates Lisp forms stored in properties of a task, when it changes to a certain state. The function is supposed to be added to the =org-after-todo-state-change-hook=.

View file

@ -2,6 +2,7 @@
DEADLINE: <2022-12-26 Mon .+1m>
:PROPERTIES:
:LAST_REPEAT: [2022-11-26 Sat 07:57]
:ON_DONE: (org-babel-execute-subtree)
:END:
:LOGBOOK:
- State "DONE" from "TODO" [2022-11-26 Sat 07:57]
@ -9,18 +10,14 @@ DEADLINE: <2022-12-26 Mon .+1m>
A small org file to keep track of some metric in a table, see [[https://orgmode.org/manual/Results-of-Evaluation.html][Results of Evaluation]] in the Org mode manual for more information.
In this case, count the number of packages in my Emacs init file. The code will automatically mark the task as DONE (thanks to [[https://emacs.ch/@leadore@toot.cafe/109406486013699362][@leadore@toot.cafe]]).
In this case, count the number of packages in my Emacs init file. It is executed automatically when the task is marked as done, using [[https://apps.bram85.nl/gitea/bram/gists/src/branch/main/gists/evaluate-code-on-task-state-change.org][this function]].
Press =C-c C-c= inside the code block to add a new entry to the table below.
#+begin_src elisp :results table append
(save-excursion
(org-back-to-heading t)
(org-todo "DONE")
(with-temp-buffer
(insert-file-contents user-init-file)
(list (format-time-string "%F") (count-matches "(use-package "))))
(with-temp-buffer
(insert-file-contents user-init-file)
(list (format-time-string "%F") (count-matches "(use-package ")))
#+end_src
#+RESULTS: