Skip to content

Commit

Permalink
last failing test, the big one
Browse files Browse the repository at this point in the history
  • Loading branch information
Trevoke committed Apr 3, 2023
1 parent 197064d commit 240045b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
27 changes: 13 additions & 14 deletions org-gtd-organize.el
Original file line number Diff line number Diff line change
Expand Up @@ -199,18 +199,19 @@ point as something to be discarded."
(defun org-gtd-organize--call (func)
"Organize the item within org-gtd. FUNC is the function that does the actual
work. This is simply a wrapper function that cleans up emacs as required."
;; TODO handle errors from here (see: malformed project)
(goto-char (point-min))
(save-excursion (funcall func))
(let ((task-id org-gtd-clarify--clarify-id)
(window-config org-gtd-clarify--window-config)
(buffer (marker-buffer org-gtd-clarify--source-heading-marker))
(position (marker-position org-gtd-clarify--source-heading-marker)))
(with-current-buffer buffer
(goto-char position)
(org-cut-subtree))
(set-window-configuration window-config)
(kill-buffer (org-gtd-clarify--buffer-name task-id))))
;; TODO handle errors from here (see: malformed project)
(catch 'org-gtd-error
(save-excursion (funcall func))
(let ((task-id org-gtd-clarify--clarify-id)
(window-config org-gtd-clarify--window-config)
(buffer (marker-buffer org-gtd-clarify--source-heading-marker))
(position (marker-position org-gtd-clarify--source-heading-marker)))
(with-current-buffer buffer
(goto-char position)
(org-cut-subtree))
(set-window-configuration window-config)
(kill-buffer (org-gtd-clarify--buffer-name task-id)))))

(defun org-gtd-organize-inbox-item (func)
"Run FUNC as part of a flow that loops over each item in the inbox."
Expand Down Expand Up @@ -255,11 +256,9 @@ the inbox. Refile to `org-gtd-actionable-file-basename'."
(interactive)

(if (org-gtd-projects--poorly-formatted-p)
;; TODO the error message can't also
;; call the process inbox, that is not its job
(progn
(org-gtd-projects--show-error)
(read-char))
(throw 'org-gtd-error "Malformed project"))

(org-gtd-organize-decorate-item)
(org-gtd-projects--nextify)
Expand Down
16 changes: 11 additions & 5 deletions org-gtd-projects.el
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,8 @@ Add the TODO keyword to all subsequent actions/tasks."
;(basic-save-buffer)
(eql 1 (length (org-map-entries t))))

(defun org-gtd-projects--show-error ()
"Tell the user something is wrong with the project."
(display-message-or-buffer
"A 'project' in GTD is a finite set of steps after which a given task is
(defconst org-gtd-projects--malformed
"A 'project' in GTD is a finite set of steps after which a given task is
complete. In Org GTD, this is defined as a top-level org heading with at least
one second-level org headings. When the item you are editing is intended to be
a project, create such a headline structure, like so:
Expand All @@ -126,7 +124,15 @@ a project, create such a headline structure, like so:
** Second task
** Third task
If you do not need sub-headings, then make a single action instead."))
If you do not need sub-headings, then organize this item as a 'single action'
instead.
Hit a key to continue.")

(defun org-gtd-projects--show-error ()
"Tell the user something is wrong with the project."
(display-message-or-buffer org-gtd-projects--malformed)
(read-key nil t))

(provide 'org-gtd-projects)
;;; org-gtd-projects.el ends here
5 changes: 2 additions & 3 deletions test/processing-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@
(describe "when project has incorrect shape"
(it "tells the user and returns to editing"
(org-gtd-process-inbox)
(execute-kbd-macro (kbd "C-c c p"))
(execute-kbd-macro (kbd "RET")) ;; any key
(expect (buffer-name) :to-match "inbox")
(execute-kbd-macro (kbd "C-c c p RET")) ;; RET is "any key" to continue after error message
(expect (buffer-name) :to-match org-gtd-clarify--prefix)
(with-current-buffer "*Message*"
(expect (ogt--current-buffer-raw-text) :to-match "First task"))))))

0 comments on commit 240045b

Please sign in to comment.