Giter Site home page Giter Site logo

Comments (3)

karlicoss avatar karlicoss commented on June 21, 2024

Hi! Not familiar with this bit of API (I'm not the one who implemented it), but I did a quick check.

Looks like it supports per-file todo keywords.

import orgparse
data = """#+TODO: TODO WAITING | DONE CANCELED 
* WAITING do it later... 
"""
od = orgparse.loads(data).root.children[0]

>>> od.todo                                                                                                                                                                                                                                        
 'WAITING'

>>> od.heading                                                                                                                                                                                                                                     
 'do it later...'

However, you probably have these set in your emacs config and don't want to specify in each file.
Looks like it's indeed hidden in the OrgEnv class and the user has no control about it. I guess need to figure out what was the intended way of using this class.. Looks like it should be an env keyword argument that's passed all the way up from loads/load/loadi functions and defaults to OrgEnv().

But, in the meantime: there is a hacky, but working way to solve it, so you don't have to wait for the fix. You can override parse_lines function:

import orgparse
def parse_lines_patched(lines, filename): 
    from orgparse.node import OrgEnv, lines_to_chunks # added this line!
    env = OrgEnv(filename=filename) 
    env.add_todo_keys(['TODO', 'WAITING'], ['DONE', 'CANCELED'])  # added this line!
    # parse into node of list (environment will be parsed) 
    nodelist = list(env.from_chunks(lines_to_chunks(lines))) 
    # parse headings (level, TODO, TAGs, and heading) 
    nodelist[0]._index = 0 
    for (i, node) in enumerate(nodelist[1:], 1):   # nodes except root node 
        node._index = i 
        node._parse_pre() 
    env._nodes = nodelist 
    return nodelist[0]  # root
orgparse.parse_lines = parse_lines_patched # overrid

After that it should work!

> orgparse.loads('* WAITING whatever').root.children[0].todo
'WAITING'

Let me know if it helps!

from orgparse.

schlagenhauf avatar schlagenhauf commented on June 21, 2024

Awesome, your workaround does the trick. Thanks!

I'd try my hands at a PR for that, anything to look out for?

from orgparse.

karlicoss avatar karlicoss commented on June 21, 2024

@schlagenhauf glad I could help!

PR would be cool! It's all CI tested, so should be straightforward without fear to break anything. If you add also add tests for custom todo keywords and add_todo_keys logic here, I'd be grateful :) You can run tests locally via tox, although running pytest directly should work too.

from orgparse.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.