Skip to content

Commit

Permalink
feat(org-agenda): prefer taking note for clocked task
Browse files Browse the repository at this point in the history
  • Loading branch information
Walheimat committed Jan 22, 2024
1 parent 1e81220 commit 1405401
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Versioning](https://semver.org/spec/v2.0.0.html).
- `:wal-bind[-keymap]` only supports a minimal version of
`:bind[-keymap]`, namely keys, remaps and binding to maps.
- `typescript-mode` is now mostly configured like `js-mode`.
- Command `wal-org-agenda-take-note` now defaults to taking note for
current task (if it exists) unless it's called with prefix argument.

### Fixed

Expand Down
24 changes: 14 additions & 10 deletions lib/wal-org.org
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ Read the manual in Emacs or [[https://orgmode.org/manuals.html][on the web]].
#+BEGIN_SRC emacs-lisp
(defun wal-first-require-ox-md (&rest _args)
"Advise to require `ox-md' before export dispatch."
(unless (featurep 'ox-md)
(require 'ox-md nil t)))
(require 'ox-md nil t))

(defun wal-org-hide-emphasis-markers (&optional show)
"Hide emphasis markers.
Expand Down Expand Up @@ -301,19 +300,24 @@ I need day-to-day and adds a =consult= buffer source.
:predicate #'wal-agenda-buffer-p))

(defun wal-org-agenda-take-note (&optional arg)
"Take a note for and agenda item.
"Take a note for an agenda item.

If called with ARG, this will add a note to the currently clocked
item."
This prefers the currently clocked item unless ARG is passed.

Otherwise (or if there is no clocked item) this prompts to select
the item first."
(interactive "P")

(declare-function org-clock-goto "ext:org-clock.el")

(save-window-excursion
(if arg
(org-clock-goto)
(consult-org-agenda))
(org-add-note)))
(let ((current org-clock-current-task))

(save-window-excursion
(if (and current
(not arg))
(org-clock-goto)
(consult-org-agenda))
(org-add-note))))

(use-package org-agenda
:config
Expand Down
45 changes: 31 additions & 14 deletions test/wal-org-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@
(ert-deftest wal-first-require-ox-md ()
:tags '(org)

(bydi ((:ignore featurep)
require)
(bydi ((:always require))

(wal-first-require-ox-md)

(bydi-was-called-with featurep (list 'ox-md))
(bydi-was-called-with require (list 'ox-md nil t))))

(ert-deftest wal-org-hide-emphasis-makers ()
Expand Down Expand Up @@ -274,21 +272,40 @@
(should (string= "Testing" (buffer-string))))))

(ert-deftest wal-org-agenda-take-note ()
(bydi (consult-org-agenda
org-clock-goto
org-add-note)
:tags '(org user-facing)

(defvar org-clock-current-task)
(let ((org-clock-current-task nil))

(bydi (consult-org-agenda
org-clock-goto
org-add-note)

(wal-org-agenda-take-note)

(bydi-was-called consult-org-agenda t)
(bydi-was-called org-add-note)
(bydi-was-not-called org-clock-goto)

(funcall-interactively 'wal-org-agenda-take-note t)

(bydi-was-called consult-org-agenda t)
(bydi-was-called org-add-note)
(bydi-was-not-called org-clock-goto)

(setq org-clock-current-task "Test task")

(wal-org-agenda-take-note)
(wal-org-agenda-take-note)

(bydi-was-called consult-org-agenda t)
(bydi-was-called org-add-note)
(bydi-was-not-called org-clock-goto)
(bydi-was-not-called consult-org-agenda)
(bydi-was-called org-add-note)
(bydi-was-called org-clock-goto t)

(funcall-interactively 'wal-org-agenda-take-note t)
(funcall-interactively 'wal-org-agenda-take-note t)

(bydi-was-not-called consult-org-agenda)
(bydi-was-called org-add-note)
(bydi-was-called org-clock-goto)))
(bydi-was-called consult-org-agenda)
(bydi-was-called org-add-note)
(bydi-was-not-called org-clock-goto))))

(ert-deftest wal-org--first-record-buffer ()
:tags '(org)
Expand Down

0 comments on commit 1405401

Please sign in to comment.