Best Python code snippet using Testify_python
EditStructure.py
Source:EditStructure.py
...18 # key bindings are also registered through the menu so only additional19 # bindings should be put in this variable20 self.keybindings = []21 @classmethod22 def new_heading(cls, below=None, insert_mode=False, end_of_last_child=False):23 u"""24 :below: True, insert heading below current heading, False,25 insert heading above current heading, None, special26 behavior for insert mode, use the current text as27 heading28 :insert_mode: True, if action is performed in insert mode29 :end_of_last_child: True, insert heading at the end of last child,30 otherwise the newly created heading will "take31 over" the current heading's children32 """33 d = ORGMODE.get_document()34 current_heading = d.current_heading()35 cursor = vim.current.window.cursor[:]36 if not current_heading:37 # the user is in meta data region38 pos = cursor[0] - 139 heading = Heading(title=d.meta_information[pos], body=d.meta_information[pos + 1:])40 d.headings.insert(0, heading)41 del d.meta_information[pos:]42 d.write()43 vim.command((u'exe "normal %dgg"|startinsert!' % (heading.start_vim, )).encode(u'utf-8'))44 return heading45 heading = Heading(level=current_heading.level)46 # it's weird but this is the behavior of original orgmode47 if below is None:48 below = cursor[1] != 0 or end_of_last_child49 # insert newly created heading50 l = current_heading.get_parent_list()51 idx = current_heading.get_index_in_parent_list()52 if l is not None and idx is not None:53 l.insert(idx + (1 if below else 0), heading)54 else:55 raise HeadingDomError(u'Current heading is not properly linked in DOM')56 if below and not end_of_last_child:57 # append heading at the end of current heading and also take58 # over the children of current heading59 for child in current_heading.children:60 heading.children.append(child, taint=False)61 current_heading.children.remove_slice(0, len(current_heading.children), \62 taint=False)63 # if cursor is currently on a heading, insert parts of it into the64 # newly created heading65 if insert_mode and cursor[1] != 0 and cursor[0] == current_heading.start_vim:66 offset = cursor[1] - current_heading.level - 1 - (len(current_heading.todo) \67 + 1 if current_heading.todo else 0)68 if offset < 0:69 offset = 070 if int(settings.get(u'org_improve_split_heading', u'1')) and \71 offset > 0 and len(current_heading.title) == offset + 1 \72 and current_heading.title[offset - 1] not in (u' ', u'\t'):73 offset += 174 heading.title = current_heading.title[offset:]75 current_heading.title = current_heading.title[:offset]76 heading.body = current_heading.body[:]77 current_heading.body = []78 d.write()79 vim.command((u'exe "normal %dgg"|startinsert!' % (heading.start_vim, )).encode(u'utf-8'))80 # return newly created heading81 return heading82 @classmethod83 def _append_heading(cls, heading, parent):84 if heading.level <= parent.level:85 raise ValueError('Heading level not is lower than parent level: %d ! > %d' % (heading.level, parent.level))86 if parent.children and parent.children[-1].level < heading.level:87 cls._append_heading(heading, parent.children[-1])88 else:89 parent.children.append(heading, taint=False)90 @classmethod91 def _change_heading_level(cls, level, including_children=True, on_heading=False, insert_mode=False):92 u"""93 Change level of heading realtively with or without including children.94 :level: the number of levels to promote/demote heading95 :including_children: True if should should be included in promoting/demoting96 :on_heading: True if promoting/demoting should only happen when the cursor is on the heading97 :insert_mode: True if vim is in insert mode98 """99 d = ORGMODE.get_document()100 current_heading = d.current_heading()101 if not current_heading or on_heading and current_heading.start_vim != vim.current.window.cursor[0]:102 # TODO figure out the actually pressed keybinding and feed these103 # keys instead of making keys up like this104 if level > 0:105 if insert_mode:106 vim.eval(u'feedkeys("\<C-t>", "n")'.encode(u'utf-8'))107 elif including_children:108 vim.eval(u'feedkeys(">]]", "n")'.encode(u'utf-8'))109 elif on_heading:110 vim.eval(u'feedkeys(">>", "n")'.encode(u'utf-8'))111 else:112 vim.eval(u'feedkeys(">}", "n")'.encode(u'utf-8'))113 else:114 if insert_mode:115 vim.eval(u'feedkeys("\<C-d>", "n")'.encode(u'utf-8'))116 elif including_children:117 vim.eval(u'feedkeys("<]]", "n")'.encode(u'utf-8'))118 elif on_heading:119 vim.eval(u'feedkeys("<<", "n")'.encode(u'utf-8'))120 else:121 vim.eval(u'feedkeys("<}", "n")'.encode(u'utf-8'))122 # return True because otherwise apply_count will not work123 return True124 # don't allow demotion below level 1125 if current_heading.level == 1 and level < 1:126 return False127 # reduce level of demotion to a minimum heading level of 1128 if (current_heading.level + level) < 1:129 level = 1130 def indent(heading, ic):131 if not heading:132 return133 heading.level += level134 if ic:135 for child in heading.children:136 indent(child, ic)137 # save cursor position138 c = vim.current.window.cursor[:]139 # indent the promoted/demoted heading140 indent_end_vim = current_heading.end_of_last_child_vim if including_children else current_heading.end_vim141 indent(current_heading, including_children)142 # when changing the level of a heading, its position in the DOM143 # needs to be updated. It's likely that the heading gets a new144 # parent and new children when demoted or promoted145 # find new parent146 p = current_heading.parent147 pl = current_heading.get_parent_list()148 ps = current_heading.previous_sibling149 nhl = current_heading.level150 if level > 0:151 # demotion152 # subheading or top level heading153 if ps and nhl > ps.level:154 pl.remove(current_heading, taint=False)155 # find heading that is the new parent heading156 oh = ps157 h = ps158 while nhl > h.level:159 oh = h160 if h.children:161 h = h.children[-1]162 else:163 break164 np = h if nhl > h.level else oh165 # append current heading to new heading166 np.children.append(current_heading, taint=False)167 # if children are not included, distribute them among the168 # parent heading and it's siblings169 if not including_children:170 for h in current_heading.children[:]:171 if h and h.level <= nhl:172 cls._append_heading(h, np)173 current_heading.children.remove(h, taint=False)174 else:175 # promotion176 if p and nhl <= p.level:177 idx = current_heading.get_index_in_parent_list() + 1178 # find the new parent heading179 oh = p180 h = p181 while nhl <= h.level:182 # append new children to current heading183 for child in h.children[idx:]:184 cls._append_heading(child, current_heading)185 h.children.remove_slice(idx, len(h.children), taint=False)186 idx = h.get_index_in_parent_list() + 1187 if h.parent:188 h = h.parent189 else:190 break191 ns = oh.next_sibling192 while ns and ns.level > current_heading.level:193 nns = ns.next_sibling194 cls._append_heading(ns, current_heading)195 ns = nns196 # append current heading to new parent heading / document197 pl.remove(current_heading, taint=False)198 if nhl > h.level:199 h.children.insert(idx, current_heading, taint=False)200 else:201 d.headings.insert(idx, current_heading, taint=False)202 d.write()203 if indent_end_vim != current_heading.start_vim:204 vim.command((u'normal %dggV%dgg=' % (current_heading.start_vim, indent_end_vim)).encode(u'utf-8'))205 # restore cursor position206 vim.current.window.cursor = (c[0], c[1] + level)207 return True208 @classmethod209 @realign_tags210 @repeat211 @apply_count212 def demote_heading(cls, including_children=True, on_heading=False, insert_mode=False):213 if cls._change_heading_level(1, including_children=including_children, on_heading=on_heading, insert_mode=insert_mode):214 if including_children:215 return u'OrgDemoteSubtree'216 return u'OrgDemoteHeading'217 @classmethod218 @realign_tags219 @repeat220 @apply_count221 def promote_heading(cls, including_children=True, on_heading=False, insert_mode=False):222 if cls._change_heading_level(-1, including_children=including_children, on_heading=on_heading, insert_mode=insert_mode):223 if including_children:224 return u'OrgPromoteSubtreeNormal'225 return u'OrgPromoteHeadingNormal'226 @classmethod227 def _move_heading(cls, direction=Direction.FORWARD, including_children=True):228 u""" Move heading up or down229 :returns: heading or None230 """231 d = ORGMODE.get_document()232 current_heading = d.current_heading()233 if not current_heading or \234 (direction == Direction.FORWARD and not current_heading.next_sibling) or \235 (direction == Direction.BACKWARD and not current_heading.previous_sibling):236 return None237 cursor_offset = vim.current.window.cursor[0] - (current_heading._orig_start + 1)238 l = current_heading.get_parent_list()239 if l is None:240 raise HeadingDomError(u'Current heading is not properly linked in DOM')241 if not including_children:242 if current_heading.previous_sibling:243 npl = current_heading.previous_sibling.children244 for child in current_heading.children:245 npl.append(child, taint=False)246 elif current_heading.parent:247 # if the current heading doesn't have a previous sibling it248 # must be the first heading249 np = current_heading.parent250 for child in current_heading.children:251 cls._append_heading(child, np)252 else:253 # if the current heading doesn't have a parent, its children254 # must be added as top level headings to the document255 npl = l256 for child in current_heading.children[::-1]:257 npl.insert(0, child, taint=False)258 current_heading.children.remove_slice(0, len(current_heading.children), taint=False)259 idx = current_heading.get_index_in_parent_list()260 if idx is None:261 raise HeadingDomError(u'Current heading is not properly linked in DOM')262 offset = 1 if direction == Direction.FORWARD else -1263 del l[idx]264 l.insert(idx + offset, current_heading)265 d.write()266 vim.current.window.cursor = (current_heading.start_vim + cursor_offset, \267 vim.current.window.cursor[1])268 return True269 @classmethod270 @repeat271 @apply_count272 def move_heading_upward(cls, including_children=True):273 if cls._move_heading(direction=Direction.BACKWARD, including_children=including_children):274 if including_children:275 return u'OrgMoveSubtreeUpward'276 return u'OrgMoveHeadingUpward'277 @classmethod278 @repeat279 @apply_count280 def move_heading_downward(cls, including_children=True):281 if cls._move_heading(direction=Direction.FORWARD, including_children=including_children):282 if including_children:283 return u'OrgMoveSubtreeDownward'284 return u'OrgMoveHeadingDownward'285 def register(self):286 u"""287 Registration of plugin. Key bindings and other initialization should be done.288 """289 settings.set(u'org_improve_split_heading', u'1')290 self.keybindings.append(Keybinding(u'<C-S-CR>', Plug(u'OrgNewHeadingAboveNormal', u':silent! py ORGMODE.plugins[u"EditStructure"].new_heading(below=False)<CR>')))291 self.menu + ActionEntry(u'New Heading &above', self.keybindings[-1])292 self.keybindings.append(Keybinding(u'<S-CR>', Plug(u'OrgNewHeadingBelowNormal', u':silent! py ORGMODE.plugins[u"EditStructure"].new_heading(below=True)<CR>')))293 self.menu + ActionEntry(u'New Heading &below', self.keybindings[-1])294 self.keybindings.append(Keybinding(u'<C-CR>', Plug(u'OrgNewHeadingBelowAfterChildrenNormal', u':silent! py ORGMODE.plugins[u"EditStructure"].new_heading(below=True, end_of_last_child=True)<CR>')))295 self.menu + ActionEntry(u'New Heading below, after &children', self.keybindings[-1])296 self.keybindings.append(Keybinding(u'<C-S-CR>', Plug(u'OrgNewHeadingAboveInsert', u'<C-o>:<C-u>silent! py ORGMODE.plugins[u"EditStructure"].new_heading(below=False, insert_mode=True)<CR>', mode=MODE_INSERT)))297 self.keybindings.append(Keybinding(u'<S-CR>', Plug(u'OrgNewHeadingBelowInsert', u'<C-o>:<C-u>silent! py ORGMODE.plugins[u"EditStructure"].new_heading(insert_mode=True)<CR>', mode=MODE_INSERT)))298 self.keybindings.append(Keybinding(u'<C-CR>', Plug(u'OrgNewHeadingBelowAfterChildrenInsert', u'<C-o>:<C-u>silent! py ORGMODE.plugins[u"EditStructure"].new_heading(insert_mode=True, end_of_last_child=True)<CR>', mode=MODE_INSERT)))299 self.menu + Separator()300 self.keybindings.append(Keybinding(u'm{', Plug(u'OrgMoveHeadingUpward', u':py ORGMODE.plugins[u"EditStructure"].move_heading_upward(including_children=False)<CR>')))301 self.keybindings.append(Keybinding(u'm[[', Plug(u'OrgMoveSubtreeUpward', u':py ORGMODE.plugins[u"EditStructure"].move_heading_upward()<CR>')))302 self.menu + ActionEntry(u'Move Subtree &Up', self.keybindings[-1])303 self.keybindings.append(Keybinding(u'm}', Plug(u'OrgMoveHeadingDownward', u':py ORGMODE.plugins[u"EditStructure"].move_heading_downward(including_children=False)<CR>')))304 self.keybindings.append(Keybinding(u'm]]', Plug(u'OrgMoveSubtreeDownward', u':py ORGMODE.plugins[u"EditStructure"].move_heading_downward()<CR>')))305 self.menu + ActionEntry(u'Move Subtree &Down', self.keybindings[-1])306 self.menu + Separator()307 self.menu + ActionEntry(u'&Copy Heading', u'yah', u'yah')308 self.menu + ActionEntry(u'C&ut Heading', u'dah', u'dah')309 self.menu + Separator()310 self.menu + ActionEntry(u'&Copy Subtree', u'yar', u'yar')311 self.menu + ActionEntry(u'C&ut Subtree', u'dar', u'dar')312 self.menu + ActionEntry(u'&Paste Subtree', u'p', u'p')313 self.menu + Separator()314 self.keybindings.append(Keybinding(u'<ah', Plug(u'OrgPromoteHeadingNormal', u':silent! py ORGMODE.plugins[u"EditStructure"].promote_heading(including_children=False)<CR>')))315 self.menu + ActionEntry(u'&Promote Heading', self.keybindings[-1])316 self.keybindings.append(Keybinding(u'<<', Plug(u'OrgPromoteOnHeadingNormal', u':silent! py ORGMODE.plugins[u"EditStructure"].promote_heading(including_children=False, on_heading=True)<CR>')))317 self.keybindings.append(Keybinding(u'<{', u'<Plug>OrgPromoteHeadingNormal', mode=MODE_NORMAL))318 self.keybindings.append(Keybinding(u'<ih', u'<Plug>OrgPromoteHeadingNormal', mode=MODE_NORMAL))319 self.keybindings.append(Keybinding(u'<ar', Plug(u'OrgPromoteSubtreeNormal', u':silent! py ORGMODE.plugins[u"EditStructure"].promote_heading()<CR>')))320 self.menu + ActionEntry(u'&Promote Subtree', self.keybindings[-1])321 self.keybindings.append(Keybinding(u'<[[', u'<Plug>OrgPromoteSubtreeNormal', mode=MODE_NORMAL))322 self.keybindings.append(Keybinding(u'<ir', u'<Plug>OrgPromoteSubtreeNormal', mode=MODE_NORMAL))323 self.keybindings.append(Keybinding(u'>ah', Plug(u'OrgDemoteHeadingNormal', u':silent! py ORGMODE.plugins[u"EditStructure"].demote_heading(including_children=False)<CR>')))324 self.menu + ActionEntry(u'&Demote Heading', self.keybindings[-1])325 self.keybindings.append(Keybinding(u'>>', Plug(u'OrgDemoteOnHeadingNormal', u':silent! py ORGMODE.plugins[u"EditStructure"].demote_heading(including_children=False, on_heading=True)<CR>')))326 self.keybindings.append(Keybinding(u'>}', u'<Plug>OrgDemoteHeadingNormal', mode=MODE_NORMAL))327 self.keybindings.append(Keybinding(u'>ih', u'<Plug>OrgDemoteHeadingNormal', mode=MODE_NORMAL))328 self.keybindings.append(Keybinding(u'>ar', Plug(u'OrgDemoteSubtreeNormal', u':silent! py ORGMODE.plugins[u"EditStructure"].demote_heading()<CR>')))329 self.menu + ActionEntry(u'&Demote Subtree', self.keybindings[-1])330 self.keybindings.append(Keybinding(u'>]]', u'<Plug>OrgDemoteSubtreeNormal', mode=MODE_NORMAL))331 self.keybindings.append(Keybinding(u'>ir', u'<Plug>OrgDemoteSubtreeNormal', mode=MODE_NORMAL))332 # other keybindings333 self.keybindings.append(Keybinding(u'<C-d>', Plug(u'OrgPromoteOnHeadingInsert', u'<C-o>:silent! py ORGMODE.plugins[u"EditStructure"].promote_heading(including_children=False, on_heading=True, insert_mode=True)<CR>', mode=MODE_INSERT)))...
Navigator.py
Source:Navigator.py
...16 u"""17 Focus parent heading18 :returns: parent heading or None19 """20 heading = ORGMODE.get_document().current_heading()21 if not heading:22 if mode == u'visual':23 vim.command(u'normal! gv'.encode(u'utf-8'))24 else:25 echo(u'No heading found')26 return27 if not heading.parent:28 if mode == u'visual':29 vim.command(u'normal! gv'.encode(u'utf-8'))30 else:31 echo(u'No parent heading found')32 return33 p = heading.parent34 if mode == u'visual':35 cls._change_visual_selection(heading, p, direction=Direction.BACKWARD, parent=True)36 else:37 vim.current.window.cursor = (p.start_vim, p.level + 1)38 return p39 @classmethod40 @apply_count41 def parent_next_sibling(cls, mode):42 u"""43 Focus the parent's next sibling44 :returns: parent's next sibling heading or None45 """46 heading = ORGMODE.get_document().current_heading()47 if not heading:48 if mode == u'visual':49 vim.command(u'normal! gv'.encode(u'utf-8'))50 else:51 echo(u'No heading found')52 return53 if not heading.parent or not heading.parent.next_sibling:54 if mode == u'visual':55 vim.command(u'normal! gv'.encode(u'utf-8'))56 else:57 echo(u'No parent heading found')58 return59 ns = heading.parent.next_sibling60 if mode == u'visual':61 cls._change_visual_selection(heading, ns, direction=Direction.FORWARD, parent=False)62 elif mode == u'operator':63 vim.current.window.cursor = (ns.start_vim, 0)64 else:65 vim.current.window.cursor = (ns.start_vim, ns.level + 1)66 return ns67 @classmethod68 def _change_visual_selection(cls, current_heading, heading, direction=Direction.FORWARD, noheadingfound=False, parent=False):69 current = vim.current.window.cursor[0]70 line_start, col_start = [ int(i) for i in vim.eval(u'getpos("\'<")'.encode(u'utf-8'))[1:3] ]71 line_end, col_end = [ int(i) for i in vim.eval(u'getpos("\'>")'.encode(u'utf-8'))[1:3] ]72 f_start = heading.start_vim73 f_end = heading.end_vim74 swap_cursor = True75 # << |visual start76 # selection end >>77 if current == line_start:78 if (direction == Direction.FORWARD and line_end < f_start) or noheadingfound and not direction == Direction.BACKWARD:79 swap_cursor = False80 # focus heading HERE81 # << |visual start82 # selection end >>83 # << |visual start84 # focus heading HERE85 # selection end >>86 if f_start < line_start and direction == Direction.BACKWARD:87 if current_heading.start_vim < line_start and not parent:88 line_start = current_heading.start_vim89 else:90 line_start = f_start91 elif (f_start < line_start or f_start < line_end) and not noheadingfound:92 line_start = f_start93 # << |visual start94 # selection end >>95 # focus heading HERE96 else:97 if direction == Direction.FORWARD:98 if line_end < f_start and not line_start == f_start - 1 and current_heading:99 # focus end of previous heading instead of beginning of next heading100 line_start = line_end101 line_end = f_start - 1102 else:103 # focus end of next heading104 line_start = line_end105 line_end = f_end106 elif direction == Direction.BACKWARD:107 if line_end < f_end:108 pass109 else:110 line_start = line_end111 line_end = f_end112 # << visual start113 # selection end| >>114 else:115 # focus heading HERE116 # << visual start117 # selection end| >>118 if line_start > f_start and line_end > f_end and not parent:119 line_end = f_end120 swap_cursor = False121 elif (line_start > f_start or \122 line_start == f_start) and line_end <= f_end and direction == Direction.BACKWARD:123 line_end = line_start124 line_start = f_start125 # << visual start126 # selection end and focus heading end HERE| >>127 # << visual start128 # focus heading HERE129 # selection end| >>130 # << visual start131 # selection end| >>132 # focus heading HERE133 else:134 if direction == Direction.FORWARD:135 if line_end < f_start - 1:136 # focus end of previous heading instead of beginning of next heading137 line_end = f_start - 1138 else:139 # focus end of next heading140 line_end = f_end141 else:142 line_end = f_end143 swap_cursor = False144 move_col_start = u'%dl' % (col_start - 1) if (col_start - 1) > 0 and (col_start - 1) < 2000000000 else u''145 move_col_end = u'%dl' % (col_end - 1) if (col_end - 1) > 0 and (col_end - 1) < 2000000000 else u''146 swap = u'o' if swap_cursor else u''147 vim.command((u'normal! %dgg%s%s%dgg%s%s' % \148 (line_start, move_col_start, vim.eval(u'visualmode()'.encode(u'utf-8')), line_end, move_col_end, swap)).encode(u'utf-8'))149 @classmethod150 def _focus_heading(cls, mode, direction=Direction.FORWARD, skip_children=False):151 u"""152 Focus next or previous heading in the given direction153 :direction: True for next heading, False for previous heading154 :returns: next heading or None155 """156 d = ORGMODE.get_document()157 current_heading = d.current_heading()158 heading = current_heading159 focus_heading = None160 # FIXME this is just a piece of really ugly and unmaintainable code. It161 # should be rewritten162 if not heading:163 if direction == Direction.FORWARD and d.headings \164 and vim.current.window.cursor[0] < d.headings[0].start_vim:165 # the cursor is in the meta information are, therefore focus166 # first heading167 focus_heading = d.headings[0]168 if not (heading or focus_heading):169 if mode == u'visual':170 # restore visual selection when no heading was found171 vim.command(u'normal! gv'.encode(u'utf-8'))172 else:173 echo(u'No heading found')174 return175 elif direction == Direction.BACKWARD:176 if vim.current.window.cursor[0] != heading.start_vim:177 # the cursor is in the body of the current heading, therefore178 # the current heading will be focused179 if mode == u'visual':180 line_start, col_start = [ int(i) for i in vim.eval(u'getpos("\'<")'.encode(u'utf-8'))[1:3] ]181 line_end, col_end = [ int(i) for i in vim.eval(u'getpos("\'>")'.encode(u'utf-8'))[1:3] ]182 if line_start >= heading.start_vim and line_end > heading.start_vim:183 focus_heading = heading184 else:185 focus_heading = heading186 # so far no heading has been found that the next focus should be on187 if not focus_heading:188 if not skip_children and direction == Direction.FORWARD and heading.children:189 focus_heading = heading.children[0]190 elif direction == Direction.FORWARD and heading.next_sibling:191 focus_heading = heading.next_sibling192 elif direction == Direction.BACKWARD and heading.previous_sibling:193 focus_heading = heading.previous_sibling194 if not skip_children:195 while focus_heading.children:196 focus_heading = focus_heading.children[-1]197 else:198 if direction == Direction.FORWARD:199 focus_heading = current_heading.next_heading200 else:201 focus_heading = current_heading.previous_heading202 noheadingfound = False203 if not focus_heading:204 if mode in (u'visual', u'operator'):205 # the cursor seems to be on the last or first heading of this206 # document and performes another next/previous operation207 focus_heading = heading208 noheadingfound = True209 else:210 if direction == Direction.FORWARD:211 echo(u'Already focussing last heading')212 else:213 echo(u'Already focussing first heading')214 return215 if mode == u'visual':216 cls._change_visual_selection(current_heading, focus_heading, direction=direction, noheadingfound=noheadingfound)217 elif mode == u'operator':218 if direction == Direction.FORWARD and vim.current.window.cursor[0] >= focus_heading.start_vim:219 vim.current.window.cursor = (focus_heading.end_vim, len(vim.current.buffer[focus_heading.end].decode(u'utf-8')))220 else:221 vim.current.window.cursor = (focus_heading.start_vim, 0)222 else:223 vim.current.window.cursor = (focus_heading.start_vim, focus_heading.level + 1)224 if noheadingfound:225 return226 return focus_heading227 @classmethod228 @apply_count229 def previous(cls, mode, skip_children=False):230 u"""231 Focus previous heading232 """233 return cls._focus_heading(mode, direction=Direction.BACKWARD, skip_children=skip_children)234 @classmethod235 @apply_count236 def next(cls, mode, skip_children=False):237 u"""238 Focus next heading239 """240 return cls._focus_heading(mode, direction=Direction.FORWARD, skip_children=skip_children)241 def register(self):242 # normal mode243 self.keybindings.append(Keybinding(u'g{', Plug('OrgJumpToParentNormal', u':py ORGMODE.plugins[u"Navigator"].parent(mode=u"normal")<CR>')))244 self.menu + ActionEntry(u'&Up', self.keybindings[-1])245 self.keybindings.append(Keybinding(u'g}', Plug('OrgJumpToParentsSiblingNormal', u':py ORGMODE.plugins[u"Navigator"].parent_next_sibling(mode=u"normal")<CR>')))246 self.menu + ActionEntry(u'&Down', self.keybindings[-1])247 self.keybindings.append(Keybinding(u'{', Plug(u'OrgJumpToPreviousNormal', u':py ORGMODE.plugins[u"Navigator"].previous(mode=u"normal")<CR>')))248 self.menu + ActionEntry(u'&Previous', self.keybindings[-1])249 self.keybindings.append(Keybinding(u'}', Plug(u'OrgJumpToNextNormal', u':py ORGMODE.plugins[u"Navigator"].next(mode=u"normal")<CR>')))250 self.menu + ActionEntry(u'&Next', self.keybindings[-1])251 # visual mode252 self.keybindings.append(Keybinding(u'g{', Plug(u'OrgJumpToParentVisual', u'<Esc>:<C-u>py ORGMODE.plugins[u"Navigator"].parent(mode=u"visual")<CR>', mode=MODE_VISUAL)))253 self.keybindings.append(Keybinding(u'g}', Plug('OrgJumpToParentsSiblingVisual', u'<Esc>:<C-u>py ORGMODE.plugins[u"Navigator"].parent_next_sibling(mode=u"visual")<CR>', mode=MODE_VISUAL)))254 self.keybindings.append(Keybinding(u'{', Plug(u'OrgJumpToPreviousVisual', u'<Esc>:<C-u>py ORGMODE.plugins[u"Navigator"].previous(mode=u"visual")<CR>', mode=MODE_VISUAL)))...
Misc.py
Source:Misc.py
...15 # bindings should be put in this variable16 self.keybindings = []17 @classmethod18 def jump_to_first_character(cls):19 heading = ORGMODE.get_document().current_heading()20 if not heading:21 vim.eval(u'feedkeys("^", "n")'.encode(u'utf-8'))22 return23 vim.current.window.cursor = (vim.current.window.cursor[0], heading.level + 1)24 @classmethod25 def edit_at_first_character(cls):26 heading = ORGMODE.get_document().current_heading()27 if not heading or heading.start_vim != vim.current.window.cursor[0]:28 vim.eval(u'feedkeys("I", "n")'.encode(u'utf-8'))29 return30 vim.current.window.cursor = (vim.current.window.cursor[0], heading.level + 1)31 vim.command(u'startinsert'.encode(u'utf-8'))32 #@repeat33 @classmethod34 @apply_count35 def i_heading(cls, mode=u'visual', selection=u'inner', skip_children=False):36 u"""37 inner heading text object38 """39 heading = ORGMODE.get_document().current_heading()40 if heading:41 if selection != u'inner':42 heading = heading if not heading.parent else heading.parent43 line_start, col_start = [ int(i) for i in vim.eval(u'getpos("\'<")'.encode(u'utf-8'))[1:3] ]44 line_end, col_end = [ int(i) for i in vim.eval(u'getpos("\'>")'.encode(u'utf-8'))[1:3] ]45 if mode != u'visual':46 line_start = vim.current.window.cursor[0]47 line_end = line_start48 start = line_start49 end = line_end50 move_one_character_back = u'' if mode == u'visual' else u'h'51 if heading.start_vim < line_start:52 start = heading.start_vim53 if heading.end_vim > line_end and not skip_children:54 end = heading.end_vim55 elif heading.end_of_last_child_vim > line_end and skip_children:56 end = heading.end_of_last_child_vim57 if mode != u'visual' and not vim.current.buffer[end - 1]:58 end -= 159 move_one_character_back = u''60 swap_cursor = u'o' if vim.current.window.cursor[0] == line_start else u''61 if selection == u'inner' and vim.current.window.cursor[0] != line_start:62 h = ORGMODE.get_document().current_heading()63 if h:64 heading = h65 visualmode = vim.eval(u'visualmode()').decode(u'utf-8') if mode == u'visual' else u'v'66 if line_start == start and line_start != heading.start_vim:67 if col_start in (0, 1):68 vim.command((u'normal! %dgg0%s%dgg$%s%s' % \69 (start, visualmode, end, move_one_character_back, swap_cursor)).encode(u'utf-8'))70 else:71 vim.command((u'normal! %dgg0%dl%s%dgg$%s%s' % \72 (start, col_start - 1, visualmode, end, move_one_character_back, swap_cursor)).encode(u'utf-8'))73 else:74 vim.command((u'normal! %dgg0%dl%s%dgg$%s%s' % \75 (start, heading.level + 1, visualmode, end, move_one_character_back, swap_cursor)).encode(u'utf-8'))76 if selection == u'inner':77 if mode == u'visual':78 return u'OrgInnerHeadingVisual' if not skip_children else u'OrgInnerTreeVisual'79 else:80 return u'OrgInnerHeadingOperator' if not skip_children else u'OrgInnerTreeOperator'81 else:82 if mode == u'visual':83 return u'OrgOuterHeadingVisual' if not skip_children else u'OrgOuterTreeVisual'84 else:85 return u'OrgOuterHeadingOperator' if not skip_children else u'OrgOuterTreeOperator'86 elif mode == u'visual':87 vim.command(u'normal! gv'.encode(u'utf-8'))88 #@repeat89 @classmethod90 @apply_count91 def a_heading(cls, selection=u'inner', skip_children=False):92 u"""93 a heading text object94 """95 heading = ORGMODE.get_document().current_heading()96 if heading:97 if selection != u'inner':98 heading = heading if not heading.parent else heading.parent99 line_start, col_start = [ int(i) for i in vim.eval(u'getpos("\'<")'.encode(u'utf-8'))[1:3] ]100 line_end, col_end = [ int(i) for i in vim.eval(u'getpos("\'>")'.encode(u'utf-8'))[1:3] ]101 start = line_start102 end = line_end103 if heading.start_vim < line_start:104 start = heading.start_vim105 if heading.end_vim > line_end and not skip_children:106 end = heading.end_vim107 elif heading.end_of_last_child_vim > line_end and skip_children:108 end = heading.end_of_last_child_vim109 swap_cursor = u'o' if vim.current.window.cursor[0] == line_start else u''110 vim.command((u'normal! %dgg%s%dgg$%s' % \111 (start, vim.eval(u'visualmode()'.encode(u'utf-8')), end, swap_cursor)).encode(u'utf-8'))112 if selection == u'inner':113 return u'OrgAInnerHeadingVisual' if not skip_children else u'OrgAInnerTreeVisual'114 else:115 return u'OrgAOuterHeadingVisual' if not skip_children else u'OrgAOuterTreeVisual'116 else:117 vim.command(u'normal! gv'.encode(u'utf-8'))118 def register(self):119 u"""120 Registration of plugin. Key bindings and other initialization should be done.121 """122 self.keybindings.append(Keybinding(u'^', Plug(u'OrgJumpToFirstCharacter', u':py ORGMODE.plugins[u"Misc"].jump_to_first_character()<CR>')))123 self.keybindings.append(Keybinding(u'I', Plug(u'OrgEditAtFirstCharacter', u':py ORGMODE.plugins[u"Misc"].edit_at_first_character()<CR>')))124 self.keybindings.append(Keybinding(u'ih', Plug(u'OrgInnerHeadingVisual', u':<C-u>py ORGMODE.plugins[u"Misc"].i_heading()<CR>', mode=MODE_VISUAL)))125 self.keybindings.append(Keybinding(u'ah', Plug(u'OrgAInnerHeadingVisual', u':<C-u>py ORGMODE.plugins[u"Misc"].a_heading()<CR>', mode=MODE_VISUAL)))126 self.keybindings.append(Keybinding(u'Oh', Plug(u'OrgOuterHeadingVisual', u':<C-u>py ORGMODE.plugins[u"Misc"].i_heading(selection=u"outer")<CR>', mode=MODE_VISUAL)))127 self.keybindings.append(Keybinding(u'OH', Plug(u'OrgAOuterHeadingVisual', u':<C-u>py ORGMODE.plugins[u"Misc"].a_heading(selection=u"outer")<CR>', mode=MODE_VISUAL)))128 self.keybindings.append(Keybinding(u'ih', Plug(u'OrgInnerHeadingOperator', u':<C-u>py ORGMODE.plugins[u"Misc"].i_heading(mode=u"operator")<CR>', mode=MODE_OPERATOR)))129 self.keybindings.append(Keybinding(u'ah', u':normal Vah<CR>', mode=MODE_OPERATOR))130 self.keybindings.append(Keybinding(u'Oh', Plug(u'OrgOuterHeadingOperator', ':<C-u>py ORGMODE.plugins[u"Misc"].i_heading(mode=u"operator", selection=u"outer")<CR>', mode=MODE_OPERATOR)))131 self.keybindings.append(Keybinding(u'OH', u':normal VOH<CR>', mode=MODE_OPERATOR))132 self.keybindings.append(Keybinding(u'ir', Plug(u'OrgInnerTreeVisual', u':<C-u>py ORGMODE.plugins[u"Misc"].i_heading(skip_children=True)<CR>', mode=MODE_VISUAL)))133 self.keybindings.append(Keybinding(u'ar', Plug(u'OrgAInnerTreeVisual', u':<C-u>py ORGMODE.plugins[u"Misc"].a_heading(skip_children=True)<CR>', mode=MODE_VISUAL)))134 self.keybindings.append(Keybinding(u'Or', Plug(u'OrgOuterTreeVisual', u'<:<C-u>py ORGMODE.plugins[u"Misc"].i_heading(selection=u"outer", skip_children=True)<CR>', mode=MODE_VISUAL)))135 self.keybindings.append(Keybinding(u'OR', Plug(u'OrgAOuterTreeVisual', u':<C-u>py ORGMODE.plugins[u"Misc"].a_heading(selection=u"outer", skip_children=True)<CR>', mode=MODE_VISUAL)))136 self.keybindings.append(Keybinding(u'ir', Plug(u'OrgInnerTreeOperator', u':<C-u>py ORGMODE.plugins[u"Misc"].i_heading(mode=u"operator")<CR>', mode=MODE_OPERATOR)))137 self.keybindings.append(Keybinding(u'ar', u':normal Var<CR>', mode=MODE_OPERATOR))138 self.keybindings.append(Keybinding(u'Or', Plug(u'OrgOuterTreeOperator', u':<C-u>py ORGMODE.plugins[u"Misc"].i_heading(mode=u"operator", selection=u"outer", skip_children=True)<CR>', mode=MODE_OPERATOR)))...
index.stories.js
Source:index.stories.js
1import React from 'react';2import { storiesOf } from '@storybook/react';3import { action } from '@storybook/addon-actions';4import { text } from '@storybook/addon-knobs';5import Heading, { SubHeading } from '.';6const stories = storiesOf('Heading', module);7stories.add(8 'level 1',9 () => <Heading level="1">{text('text', 'è¦åºãã¬ãã«1')}</Heading>,10 { info: 'è¦åºãã¬ãã«1' },11);12stories.add(13 'level 1 with sub heading',14 () => (15 <Heading level="1">16 {text('text', 'è¦åºãã¬ãã«1 ')}17 <SubHeading>{text('sub', 'å°è¦åºã')}</SubHeading>18 </Heading>19 ),20 { info: 'è¦åºãã¬ãã«1' },21);22stories.add(23 'level 2',24 () => <Heading level="2">{text('text', 'è¦åºãã¬ãã«2')}</Heading>,25 { info: 'è¦åºãã¬ãã«2' },26);27stories.add(28 'level 2 with sub heading',29 () => (30 <Heading level="2">31 {text('text', 'è¦åºãã¬ãã«2 ')}32 <SubHeading>{text('sub', 'å°è¦åºã')}</SubHeading>33 </Heading>34 ),35 { info: 'è¦åºãã¬ãã«2' },36);37stories.add(38 'level 3',39 () => <Heading level="3">{text('text', 'è¦åºãã¬ãã«3')}</Heading>,40 { info: 'è¦åºãã¬ãã«3' },41);42stories.add(43 'level 3 with sub heading',44 () => (45 <Heading level="3">46 {text('text', 'è¦åºãã¬ãã«3 ')}47 <SubHeading>{text('sub', 'å°è¦åºã')}</SubHeading>48 </Heading>49 ),50 { info: 'è¦åºãã¬ãã«3' },51);52stories.add(53 'level 4',54 () => <Heading level="4">{text('text', 'è¦åºãã¬ãã«4')}</Heading>,55 { info: 'è¦åºãã¬ãã«4' },56);57stories.add(58 'level 4 with sub heading',59 () => (60 <Heading level="4">61 {text('text', 'è¦åºãã¬ãã«4 ')}62 <SubHeading>{text('sub', 'å°è¦åºã')}</SubHeading>63 </Heading>64 ),65 { info: 'è¦åºãã¬ãã«4' },66);67stories.add(68 'level 5',69 () => <Heading level="5">{text('text', 'è¦åºãã¬ãã«5')}</Heading>,70 { info: 'è¦åºãã¬ãã«5' },71);72stories.add(73 'level 5 with sub heading',74 () => (75 <Heading level="5">76 {text('text', 'è¦åºãã¬ãã«5 ')}77 <SubHeading>{text('sub', 'å°è¦åºã')}</SubHeading>78 </Heading>79 ),80 { info: 'è¦åºãã¬ãã«5' },81);82stories.add(83 'level 6',84 () => <Heading level="6">{text('text', 'è¦åºãã¬ãã«6')}</Heading>,85 { info: 'è¦åºãã¬ãã«6' },86);87stories.add(88 'level 6 with sub heading',89 () => (90 <Heading level="6">91 {text('text', 'è¦åºãã¬ãã«6 ')}92 <SubHeading>{text('sub', 'å°è¦åºã')}</SubHeading>93 </Heading>94 ),95 { info: 'è¦åºãã¬ãã«6' },...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!