From c23f8cc2814fca1afe6634c9e51b3834d0f25c46 Mon Sep 17 00:00:00 2001
From: Niklas Fasching
Date: Wed, 19 Dec 2018 19:54:15 +0100
Subject: [PATCH] Add support for SETUP_FILE
---
org/keyword.go | 29 +++++++++++++++++++++++++++++
org/testdata/headlines.html | 12 ++++++++++++
org/testdata/headlines.org | 5 +++++
org/testdata/headlines.pretty_org | 5 +++++
org/testdata/misc.html | 5 +++++
org/testdata/setup_file_org | 1 +
6 files changed, 57 insertions(+)
create mode 100644 org/testdata/setup_file_org
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
+
+CUSTOM
+headline with custom status
+
+
+it's possible to use #+SETUP_FILE
- in this case the setup file contains the following
+
+
+
+#+TODO: TODO DONE CUSTOM
+
+
diff --git a/org/testdata/headlines.org b/org/testdata/headlines.org
index cc98965..f498598 100644
--- a/org/testdata/headlines.org
+++ b/org/testdata/headlines.org
@@ -1,3 +1,4 @@
+#+SETUP_FILE: setup_file_org
* Simple Headline [1/2]
- [X] checked
- [ ] unchecked
@@ -18,3 +19,7 @@ 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
diff --git a/org/testdata/headlines.pretty_org b/org/testdata/headlines.pretty_org
index 69e24da..c9adde0 100644
--- a/org/testdata/headlines.pretty_org
+++ b/org/testdata/headlines.pretty_org
@@ -1,3 +1,4 @@
+#+SETUP_FILE: setup_file_org
* Simple Headline [1/2]
- [X] checked
- [ ] unchecked
@@ -18,3 +19,7 @@ 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
diff --git a/org/testdata/misc.html b/org/testdata/misc.html
index f10d0ef..fb40dd4 100644
--- a/org/testdata/misc.html
+++ b/org/testdata/misc.html
@@ -43,6 +43,7 @@ src block
+#+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
diff --git a/org/testdata/setup_file_org b/org/testdata/setup_file_org
new file mode 100644
index 0000000..c9a4436
--- /dev/null
+++ b/org/testdata/setup_file_org
@@ -0,0 +1 @@
+#+TODO: TODO DONE CUSTOM