Regarding tags, I hacked the nodetags.py plugin together, available at
commit b9a764c59de263fbdb47969f1d318759b955c442.
Attached is a test leo file for playing with it.
This is only an API for tags, but I feel like it should simplify the
process and allow someone to focus on the important bits, i.e. UI hooks,
rather than low-level details. Also, it's usable now for scripts.
Here is the docstring:
Leo.plugins.nodetags
Provides an API for manipulating and querying textual tags on nodes
By Jacob M. Peck
This plugin registers a controller object to c.theTagController, which
provides the following API:
tc = c.theTagController
tc.get_all_tags() # return a list of all tags used in the current
outline, automatically updated to be consistent
tc.get_tagged_nodes('foo') # return a list of positions tagged 'foo'
tc.get_tags(p) # return a list of tags applied to the node at position
p; returns [] if node has no tags
tc.add_tag(p, 'bar') # add the tag 'bar' to the node at position p
tc.remove_tag(p, 'baz') # remove the tag 'baz' from p if it is in the
tag list
Internally, tags are stored in p.v.unknownAttributes['__node_tags'] as a
set.
-->Jake
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to leo-editor+unsubscr...@googlegroups.com.
To post to this group, send email to leo-editor@googlegroups.com.
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.
<?xml version="1.0" encoding="utf-8"?>
<!-- Created by Leo (http://leoeditor.com/leo_toc.html) -->
<?xml-stylesheet ekr_test?>
<leo_file xmlns:leo="http://www.leo-editor.org/2011/leo" >
<leo_header file_format="2" tnodes="0" max_tnode_index="0" clone_windows="0"/>
<globals body_outline_ratio="0.5" body_secondary_ratio="0.5">
<global_window_position top="50" left="50" height="500" width="700"/>
<global_log_window_position top="0" left="0" height="0" width="0"/>
</globals>
<preferences/>
<find_panel_settings/>
<vnodes>
<v t="peckj.20140804114044.3756"><vh>@settings</vh>
<v t="peckj.20140804114044.3757"><vh>@plugin nodetags</vh></v>
</v>
<v t="peckj.20140804114044.3759"><vh>@button add-tag</vh></v>
<v t="peckj.20140804114044.3761"><vh>@button rm-tag</vh></v>
<v t="peckj.20140804114044.3763"><vh>@button list-tags</vh></v>
<v t="peckj.20140804114044.3765"><vh>@button add-tag-test</vh></v>
<v t="peckj.20140804114044.3767"><vh>@button get-tagged-nodes-test</vh></v>
<v t="peckj.20140804114044.3769"><vh>@button list-all-tags</vh></v>
<v t="peckj.20140804114044.3770" a="E"><vh>Tag test nodes</vh>
<v t="peckj.20140804114044.3771"><vh>node 1</vh></v>
<v t="peckj.20140804114044.3772"><vh>node 2</vh></v>
<v t="peckj.20140804114044.3773"><vh>node 3</vh></v>
</v>
</vnodes>
<tnodes>
<t tx="peckj.20140804114044.3756"></t>
<t tx="peckj.20140804114044.3757"></t>
<t tx="peckj.20140804114044.3759">@language python
''' add a random tag to the selected node '''
import string, random
import random
tc = c.theTagController
tag = ''.join(random.choice(string.ascii_uppercase) for _ in range(8))
g.es('tags before: ', tc.get_tags(p))
tc.add_tag(p, tag)
g.es('tags after: ', tc.get_tags(p))
</t>
<t tx="peckj.20140804114044.3761">@language python
''' remove the first tag on the node '''
import random
tc = c.theTagController
tag = tc.get_tags(p)[0]
g.es('tags before: ', tc.get_tags(p))
tc.remove_tag(p, tag)
g.es('tags after: ', tc.get_tags(p))
</t>
<t tx="peckj.20140804114044.3763">@language python
''' list all tags on the selected node '''
tc = c.theTagController
g.es('tags: ', tc.get_tags(p))
</t>
<t tx="peckj.20140804114044.3765">@language python
''' add the tag "test" to the node '''
tc = c.theTagController
tag = 'test'
g.es('tags before: ', tc.get_tags(p))
tc.add_tag(p, tag)
g.es('tags after: ', tc.get_tags(p))
</t>
<t tx="peckj.20140804114044.3767">@language python
''' get all nodes tagged "test" '''
tc = c.theTagController
tag = 'test'
nodelist = tc.get_tagged_nodes(tag)
nodelist = [n.h for n in nodelist]
g.es('nodes tagged "test": ', nodelist)
</t>
<t tx="peckj.20140804114044.3769">@language python
''' list all tags in the current outline '''
tc = c.theTagController
g.es('All tags in this outline: ', tc.get_all_tags())</t>
<t tx="peckj.20140804114044.3770"></t>
<t tx="peckj.20140804114044.3771" __node_tags="635f5f6275696c74696e5f5f0a7365740a7100285d71015504746573747102617471035271042e"></t>
<t tx="peckj.20140804114044.3772" __node_tags="635f5f6275696c74696e5f5f0a7365740a7100285d7101285508424d555a4953594c710255084d4a4e48464d4c5171035508455649464443574f7104657471055271062e"></t>
<t tx="peckj.20140804114044.3773" __node_tags="635f5f6275696c74696e5f5f0a7365740a7100285d71015504746573747102617471035271042e"></t>
</tnodes>
</leo_file>