Skip to content

Commit

Permalink
fix(org): don't hardcode in-progress state string
Browse files Browse the repository at this point in the history
Adds new local variable `wal-org-todo-in-progress-state` and defaults
it to "IN PROGRESS". Function `wal-org-clock-in-switch-to-state` now
uses this variable and checks whether that is even a legal state for
the buffer.
  • Loading branch information
Walheimat committed Jun 11, 2024
1 parent 1493faa commit 266005b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
11 changes: 9 additions & 2 deletions lib/wal-org.org
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,17 @@ command to ignore continuous clocking as well as one to add a note to
the clocked task.

#+BEGIN_SRC emacs-lisp
(defvar-local wal-org-clock-in-progress-state "IN PROGRESS"
"The state signifying a task is in progress.")
(put 'wal-org-clock-in-progress-state 'safe-local-variable #'stringp)

(defun wal-org-clock-in-switch-to-state (todo-state)
"Only switch state to IN PROGRESS if TODO-STATE was given."
(when todo-state
"IN PROGRESS"))
(defvar org-todo-keywords-1)

(when (and todo-state
(member wal-org-clock-in-progress-state org-todo-keywords-1))
wal-org-clock-in-progress-state))

(defun wal-org-clock-out-switch-to-state (todo-state)
"Switch from TODO-STATE to a user-selected state.
Expand Down
25 changes: 17 additions & 8 deletions test/wal-org-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -211,17 +211,26 @@
(ert-deftest wal-org-clock-in-and-out-switch-to-state ()
:tags '(org)

(should (string-equal "IN PROGRESS" (wal-org-clock-in-switch-to-state "OTHER STATE")))
(defvar org-todo-keywords-1)
(defvar org-clock-current-task)

(let ((wal-org-clock-in-progress-state "IN PROGRESS")
(org-todo-keywords-1 '("BAITING" "WORK" "WAITING")))

(should-not (wal-org-clock-in-switch-to-state "WORK")))

(let ((wal-org-clock-in-progress-state "IN PROGRESS")
(org-todo-keywords-1 '("BAITING" "IN PROGRESS" "WAITING")))

(bydi ((:mock completing-read :return "WAITING"))
(defvar org-todo-keywords-1)
(defvar org-clock-current-task)
(should (string-equal "IN PROGRESS" (wal-org-clock-in-switch-to-state "UNKNOWN STATE")))
(should-not (wal-org-clock-in-switch-to-state nil))
(should (string-equal "IN PROGRESS" (wal-org-clock-in-switch-to-state "BAITING")))

(let ((org-todo-keywords-1 '("BAITING" "WAITING"))
(org-clock-current-task nil))
(bydi ((:mock completing-read :return "WAITING"))
(let ((org-clock-current-task nil))

(should (string-equal "WAITING" (wal-org-clock-out-switch-to-state "OTHER STATE")))
(should (string-equal "WAITING" (wal-org-clock-out-switch-to-state "BAITING"))))))
(should (string-equal "WAITING" (wal-org-clock-out-switch-to-state "OTHER STATE")))
(should (string-equal "WAITING" (wal-org-clock-out-switch-to-state "BAITING")))))))

(ert-deftest wal-org-clock-heading ()
:tags '(org)
Expand Down

0 comments on commit 266005b

Please sign in to comment.