Copyright | (c) Lally Singh, 2015 |
---|---|
License | BSD3 |
Maintainer | yell@lal.ly |
Stability | experimental |
Portability | BangPatterns, GADTs, DeriveDataTypeable, StandaloneDeriving |
Safe Haskell | None |
Language | Haskell2010 |
A package to parse and interpret Emacs Org-Mode documents. It also supports
arbitrary types that map back and forth with Node
. Create an instance of
NodeUpdate a
and use OrgDocView a
to read/write values of a
in an
org-mode file. Property drawers are great for this mapping.
- data Prefix = Prefix String
- data Drawer = Drawer {}
- data Babel = Babel [TextLine]
- data Table = Table [TextLine]
- data NodeChild
- data Node = Node {}
- data OrgFileProperty = OrgFileProperty {}
- data OrgFileElement
- data OrgDocView a = OrgDocView {
- ovElements :: [(a, Node)]
- ovDocument :: OrgDoc
- class Eq a => NodeUpdate a where
- findItemInNode :: Node -> Maybe a
- updateNodeLine :: a -> Node -> Maybe Node
- data OrgDoc = OrgDoc {
- odNodes :: [Node]
- odProperties :: [OrgFileProperty]
- odLines :: [TextLine]
- data TextLine = TextLine {}
- type LineNumber = Maybe Int
- class TextLineSource s where
- getTextLines :: s -> [TextLine]
- orgFile :: String -> OrgDoc
- generateDocView :: NodeUpdate a => OrgDoc -> OrgDocView a
- getRawElements :: OrgDocView a -> [a]
- updateNode :: (Node -> Maybe Node) -> Node -> Node
- addOrgLine :: OrgDocZipper -> OrgLine -> OrgDocZipper
- emptyZip :: OrgDocZipper
- categorizeLines :: String -> [OrgLine]
Documentation
A keyword at the front of a node heading, like TODO or DONE.
Currently underimplemented: stores the lines of the babel environment.
Currently underimplemented: stores the lines of the table.
Children of top-level Org Nodes.
ChildText TextLine | Regular text. |
ChildDrawer Drawer | |
ChildNode Node | outline nodes of higher depth. |
ChildBabel Babel | |
ChildTable Table |
An outline node in org-mode. For a node ** TODO Foo a bar :FOOBAR:
data OrgFileElement Source
data OrgDocView a Source
OrgDocView | |
|
class Eq a => NodeUpdate a where Source
Generic visitor for updating a Node's values. Intentionally, we
don't allow node deletion, just update. Preferably, if you want to
delete a Node, you should control the parent. We also have
findItemInNode which will construct an a
from the Node, which we
may then update against a list.
findItemInNode :: Node -> Maybe a Source
updateNodeLine :: a -> Node -> Maybe Node Source
Full contents of an org file.
OrgDoc | |
|
Raw data about each line of text. Lines with 'tlLineNum == None' are generated and don't exist within the Org file (yet).
type LineNumber = Maybe Int Source
Line numbers, where we can have an unattached root.
class TextLineSource s where Source
Implements an API for getting text lines. Useful for Org file generation or mutation.
getTextLines :: s -> [TextLine] Source
orgFile :: String -> OrgDoc Source
Parsing the file efficiently. Let's keep it non-quadratic.
- Split it up into lines
Identify each line, as part of one of the big structure types:
- Node headers
- Drawers
- File-level properties
- Babel headers
- Lines who's type depend on context (e.g., babel entries or node text)
- Then fold the lines over a builder function and a zipper of the tree.
generateDocView :: NodeUpdate a => OrgDoc -> OrgDocView a Source
getRawElements :: OrgDocView a -> [a] Source
addOrgLine :: OrgDocZipper -> OrgLine -> OrgDocZipper Source
Adds a pre-classified OrgLine to an OrgDocZipper, possibly adding it to some existing part of the OrgDocZipper.
categorizeLines :: String -> [OrgLine] Source