Coverage for C:\leo.repo\leo-editor\leo\plugins\writers\org.py: 97%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#@+leo-ver=5-thin
2#@+node:ekr.20140726091031.18079: * @file ../plugins/writers/org.py
3"""The @auto write code for Emacs org-mode (.org) files."""
4from leo.core import leoGlobals as g
5import leo.plugins.writers.basewriter as basewriter
6#@+others
7#@+node:ekr.20140726091031.18155: ** class OrgModeWriter
8class OrgModeWriter(basewriter.BaseWriter):
9 """The writer class for .org files."""
11 def __init__(self, c):
12 super().__init__(c)
13 self.tc = self.load_nodetags()
15 #@+others
16 #@+node:ekr.20171121020009.1: *3* orgw.load_nodetags
17 def load_nodetags(self):
18 """
19 Load the nodetags.py plugin if necessary.
20 Return c.theTagController.
21 """
22 c = self.c
23 if not getattr(c, 'theTagController', None):
24 g.app.pluginsController.loadOnePlugin('nodetags.py', verbose=False)
25 return getattr(c, 'theTagController', None)
26 #@+node:ekr.20140726091031.18154: *3* orgw.write
27 def write(self, root):
28 """Write all the *descendants* of an @auto-org-mode node."""
29 root_level = root.level()
30 self.write_root(root)
31 for p in root.subtree():
32 if hasattr(self.at, 'force_sentinels'):
33 self.put_node_sentinel(p, '#')
34 indent = p.level() - root_level
35 self.put('%s %s' % ('*' * indent, p.h))
36 for s in p.b.splitlines(False):
37 self.put(s)
38 root.setVisited()
39 return True
40 #@+node:ekr.20171230050625.1: *3* orgw.write_root
41 def write_root(self, root):
42 """Write the root @auto-org node."""
43 lines = [z for z in g.splitLines(root.b) if not g.isDirective(z)]
44 for s in lines:
45 self.put(s)
46 #@-others
47#@-others
48writer_dict = {
49 '@auto': ['@auto-org-mode', '@auto-org',],
50 'class': OrgModeWriter,
51 'extensions': ['.org',],
52}
53#@@language python
54#@@tabwidth -4
55#@-leo