-
Notifications
You must be signed in to change notification settings - Fork 15
/
orgdwim.py
140 lines (131 loc) · 5.56 KB
/
orgdwim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import sublime
import sublime_plugin
import os
import OrgExtended.orgparse.node as node
from OrgExtended.orgparse.sublimenode import *
import OrgExtended.orgutil.util as util
import logging
import sys
import traceback
import OrgExtended.orgdb as db
import OrgExtended.asettings as sets
import OrgExtended.orgcheckbox as checkbox
import OrgExtended.orgnumberedlist as numberedlist
import OrgExtended.orgdynamicblock as dynamic
import OrgExtended.orgsourceblock as src
import OrgExtended.orgediting as editing
import OrgExtended.orgtableformula as tbl
log = logging.getLogger(__name__)
# ====================================================================
# Another Do What I Mean style command.
# Contextually looks at where you are and "does the right thing."
# All about inserting things state.
class OrgGenericInsertCommand(sublime_plugin.TextCommand):
def run(self, edit):
line = self.view.curLine()
cb = checkbox.get_checkbox(self.view, line)
if(cb):
self.view.run_command('org_insert_checkbox')
return
if(checkbox.isUnorderedList(self.view.substr(line))):
self.view.run_command('org_insert_unordered_list')
return
if(numberedlist.isNumberedLine(self.view)):
numberedlist.AppendLine(self.view, edit)
return
n = db.Get().AtInView(self.view)
if(not n.is_root()):
self.view.run_command('org_insert_heading_sibling')
# ====================================================================
class OrgGenericInsertAuxCommand(sublime_plugin.TextCommand):
def run(self, edit):
line = self.view.curLine()
cb = checkbox.get_checkbox(self.view, line)
if(cb):
self.view.run_command('org_insert_checkbox',{'insertHere': False})
return
if(checkbox.isUnorderedList(self.view.substr(line))):
self.view.run_command('org_insert_unordered_list',{'insertHere': False})
return
if(numberedlist.isNumberedLine(self.view)):
numberedlist.AppendLine(self.view, edit, insertHere=False)
return
n = db.Get().AtInView(self.view)
if(not n.is_root()):
self.view.run_command('org_insert_heading_child')
# ====================================================================
# Another Do What I Mean style command.
# Contextually looks at where you are and "does the right thing."
# Recalculates checkboxes, recalculates blocks etc.
class OrgRecalcCommand(sublime_plugin.TextCommand):
def run(self, edit):
if(dynamic.IsDynamicBlock(self.view)):
self.view.run_command('org_execute_dynamic_block')
return
if(src.IsInlineSourceBlock(self.view)):
self.view.run_command('org_execute_inline_source_block')
return
if(src.IsSourceBlock(self.view)):
self.view.run_command('org_execute_source_block')
return
if(src.IsCallCommentBlock(self.view)):
self.view.run_command('org_execute_call_comment')
return
if(tbl.isTable(self.view)):
self.view.run_command('org_execute_table')
return
checkbox.recalculate_all_checkbox_summaries(self.view, edit)
numberedlist.UpdateLine(self.view, edit)
# ====================================================================
# Another Do What I Mean style command.
# Contextually looks at where you are and "does the right thing."
# All about toggling things state.
class OrgToggleCommand(sublime_plugin.TextCommand):
def run(self, edit):
line = self.view.curLine()
cb = checkbox.is_checkbox_line(self.view)
#cb = checkbox.get_checkbox(self.view, line)
if(cb):
self.view.run_command('org_toggle_checkbox')
return
else:
self.view.run_command('org_todo_change')
# ====================================================================
class OrgChangeIndentCommand(sublime_plugin.TextCommand):
def run(self, edit):
line = self.view.curLine()
cb = checkbox.get_checkbox(self.view, line)
if(cb):
editing.indent_list(self.view,self.view.curRow(), edit)
return
if(checkbox.isUnorderedList(self.view.substr(line))):
editing.indent_list(self.view,self.view.curRow(), edit)
return
if(numberedlist.isNumberedLine(self.view)):
editing.indent_list(self.view,self.view.curRow(), edit)
return
n = db.Get().AtInView(self.view)
if(n and type(n) != node.OrgRootNode):
editing.indent_node(self.view, n, edit)
file = db.Get().FindInfo(self.view)
file.LoadS(self.view)
# ====================================================================
# This does not handle indention of sub trees! Need to fix that!
class OrgChangeDeIndentCommand(sublime_plugin.TextCommand):
def run(self, edit):
line = self.view.curLine()
cb = checkbox.get_checkbox(self.view, line)
if(cb):
editing.deindent_list(self.view,self.view.curRow(), edit)
return
if(checkbox.isUnorderedList(self.view.substr(line))):
editing.deindent_list(self.view,self.view.curRow(), edit)
return
if(numberedlist.isNumberedLine(self.view)):
editing.deindent_list(self.view,self.view.curRow(), edit)
return
n = db.Get().AtInView(self.view)
if(n and type(n) != node.OrgRootNode):
editing.deindent_node(self.view, n, edit)
file = db.Get().FindInfo(self.view)
file.LoadS(self.view)