diff --git a/org/keyword.go b/org/keyword.go index 12a8b64..1580ab9 100644 --- a/org/keyword.go +++ b/org/keyword.go @@ -1,8 +1,10 @@ package org import ( + "bytes" "fmt" "io/ioutil" + "log" "path/filepath" "regexp" "strings" @@ -52,6 +54,8 @@ func (d *Document) parseComment(i int, stop stopFn) (int, Node) { func (d *Document) parseKeyword(i int, stop stopFn) (int, Node) { k := parseKeyword(d.tokens[i]) switch k.Key { + case "SETUP_FILE": + return d.loadSetupFile(k) case "INCLUDE": return d.newInclude(k) case "CAPTION", "ATTR_HTML": @@ -131,3 +135,28 @@ func (d *Document) newInclude(k Keyword) (int, Node) { } return 1, Include{k, resolve} } + +func (d *Document) loadSetupFile(k Keyword) (int, Node) { + path := k.Value + if !filepath.IsAbs(path) { + path = filepath.Join(filepath.Dir(d.Path), path) + } + bs, err := ioutil.ReadFile(path) + if err != nil { + if d.Debug { + log.Printf("Bad setup file: %#v: %s", k, err) + } + return 1, k + } + setupDocument := NewDocument().Parse(bytes.NewReader(bs)) + if err := setupDocument.Error; err != nil { + if d.Debug { + log.Printf("Bad setup file: %#v: %s", k, err) + } + return 1, k + } + for k, v := range setupDocument.BufferSettings { + d.BufferSettings[k] = v + } + return 1, k +} diff --git a/org/testdata/headlines.html b/org/testdata/headlines.html index bbec0a5..1ee1a69 100644 --- a/org/testdata/headlines.html +++ b/org/testdata/headlines.html @@ -45,3 +45,15 @@ This is inside the drawer
Still outside the drawer
+
+it's possible to use #+SETUP_FILE
- in this case the setup file contains the following
+
+#+TODO: TODO DONE CUSTOM
+
+
+#+SETUP_FILE: setup_file_org
* Simple Headline [1/2]
- [X] checked
- [ ] unchecked
@@ -63,6 +64,10 @@ Still outside the drawer
This is inside the drawer
:END:
Still outside the drawer
+* CUSTOM headline with custom status
+it's possible to use =#+SETUP_FILE= - in this case the setup file contains the following
+
+#+INCLUDE: "setup_file_org" src org