Trevoke / org-gtd.el

A package for using GTD with org-mode
GNU General Public License v3.0
376 stars 46 forks source link

Fix processing with empty inbox #183

Closed yetanotherfossman closed 1 year ago

yetanotherfossman commented 1 year ago

Currently, when calling org-gtd-process-inbox with an empty inbox (i.e. one without headings), a PROPERTIES drawer is incorrectly added to the top of the inbox file, because org-gtd-id-get-create will eventually be called no matter what. This PR fix that by simply checking if there is an org heading before starting to process the item.

Trevoke commented 1 year ago

Ah, thank you for the pull request!

I'm very surprised to hear that this behavior occurs, because ... Well... At least when I wrote this, org-mode errored out when the code called (outline-next-visible-heading 1) and there wasn't a visible heading (that is the whole reason for the error catch here).

Can you tell me what version of org-mode you are using? It's possible this behavior changed in a more recent version of org-mode.

yetanotherfossman commented 1 year ago

I'm at 9.6.4, which is fairly new (I compile Emacs from source). And yes, after investigating a little I see that in etc/ORG-NEWS, since version 9.6, there's the following warning:

The new folding backend breaks some of the outline-* functions that rely on the details of visibility state implementation in outline.el. The old Org folding backend was compatible with the outline.el folding, but it is not the case anymore with the new backend. From now on, using outline-* functions is strongly discouraged when working with Org files.

Now outline-next-visible-heading is hacked to call org-next-visible-heading, which indeed doesn't error out.

Trevoke commented 1 year ago

Okay, so I need to update all the code to stop using outline- and start using org- instead, this is good to know.

It also means I can afford to rework this code to not use an error for control flow, which is nice, too.

Is that second part something you can provide as part of this pull request? No worries if not.

yetanotherfossman commented 1 year ago

Done! Also, now a meaningful message is displayed in the echo area, so the user knows when the inbox is empty.

Trevoke commented 1 year ago

Hmm, the tests are failing. Did you run them locally?

yetanotherfossman commented 1 year ago

Right, I should have replaced user-error there. Everything should be OK now.

Trevoke commented 1 year ago

Thank you!