Beispiel #1
0
	def test_filter_items(self):
		# only headings with date and todo should be returned
		tmpdate = date.today()
		odate = OrgDate(True, tmpdate.year, tmpdate.month, tmpdate.day)
		tmp_head = Heading(title=u'Refactor the code', todo=u'TODO', active_date=odate)
		headings = [tmp_head]
		filtered = filter_items(headings,
				[contains_active_date, contains_active_todo])

		self.assertEqual(len(filtered), 1)
		self.assertEqual(filtered, headings)

		# try a longer list
		headings = headings * 3
		filtered = filter_items(headings,
				[contains_active_date, contains_active_todo])

		self.assertEqual(len(filtered), 3)
		self.assertEqual(filtered, headings)

		# date does not contain all needed fields thus gets ignored
		tmpdate = date.today()
		odate = OrgDate(True, tmpdate.year, tmpdate.month, tmpdate.day)
		tmp_head = Heading(title=u'Refactor the code', active_date=odate)
		headings = [tmp_head]
		filtered = filter_items(headings, [contains_active_date,
				contains_active_todo])
		self.assertEqual([], filtered)
Beispiel #2
0
	def test_contains_active_date(self):
		heading = Heading(title=u'Refactor the code', active_date=None)
		self.assertFalse(contains_active_date(heading))

		odate = OrgDate(True, 2011, 11, 1)
		heading = Heading(title=u'Refactor the code', active_date=odate)
		self.assertTrue(contains_active_date(heading))
Beispiel #3
0
	def test_contains_active_todo(self):
		heading = Heading(title=u'Refactor the code', todo='TODO')
		self.assertTrue(contains_active_todo(heading))

		heading = Heading(title=u'Refactor the code', todo='DONE')
		self.assertFalse(contains_active_todo(heading))

		heading = Heading(title=u'Refactor the code', todo=None)
		self.assertFalse(contains_active_todo(heading))
Beispiel #4
0
	def test_is_within_week_with_orgdatetime(self):
		# to far in the future
		tmp = date.today() + timedelta(days=1000)
		odate = OrgDateTime(True, tmp.year, tmp.month, tmp.day, 10, 10)
		heading = Heading(title=u'Refactor the code', active_date=odate)
		self.assertFalse(is_within_week(heading))

		# within a week
		tmpdate = date.today() + timedelta(days=5)
		odate = OrgDateTime(True, tmpdate.year, tmpdate.month, tmpdate.day, 1, 0)
		heading = Heading(title=u'Refactor the code', active_date=odate)
		self.assertTrue(is_within_week(heading))

		# in the past
		tmpdate = date.today() - timedelta(days=5)
		odate = OrgDateTime(True, tmpdate.year, tmpdate.month, tmpdate.day, 1, 0)
		heading = Heading(title=u'Refactor the code', active_date=odate)
		self.assertTrue(is_within_week(heading))
    def test_filter_items(self):
        # only headings with date and todo should be returned
        vim.command(
            u_encode(
                u"let g:org_todo_keywords = ['TODO', 'STARTED', '|', 'DONE']"))
        tmpdate = date.today()
        odate = OrgDate(True, tmpdate.year, tmpdate.month, tmpdate.day)
        tmp_head = Heading(title=u'Refactor the code',
                           todo=u'TODO',
                           active_date=odate)
        tmp_head_01 = Heading(title=u'Refactor the code',
                              todo=u'STARTED',
                              active_date=odate)
        headings = [tmp_head, tmp_head_01]
        filtered = list(
            filter_items(headings,
                         [contains_active_date, contains_active_todo]))

        self.assertEqual(len(filtered), 2)
        self.assertEqual(filtered, headings)

        # try a longer list
        headings = headings * 3
        filtered = list(
            filter_items(headings,
                         [contains_active_date, contains_active_todo]))

        self.assertEqual(len(filtered), 6)
        self.assertEqual(filtered, headings)

        # date does not contain all needed fields thus gets ignored
        tmpdate = date.today()
        odate = OrgDate(True, tmpdate.year, tmpdate.month, tmpdate.day)
        tmp_head = Heading(title=u'Refactor the code', active_date=odate)
        headings = [tmp_head]
        filtered = list(
            filter_items(headings,
                         [contains_active_date, contains_active_todo]))
        self.assertEqual([], filtered)
Beispiel #6
0
    def new_heading(cls,
                    below=None,
                    insert_mode=False,
                    end_of_last_child=False):
        u"""
		:below:				True, insert heading below current heading, False,
							insert heading above current heading, None, special
							behavior for insert mode, use the current text as
							heading
		:insert_mode:		True, if action is performed in insert mode
		:end_of_last_child:	True, insert heading at the end of last child,
							otherwise the newly created heading will "take
							over" the current heading's children
		"""
        d = ORGMODE.get_document()
        current_heading = d.current_heading()
        cursor = vim.current.window.cursor[:]
        if not current_heading:
            # the user is in meta data region
            pos = cursor[0] - 1
            heading = Heading(title=d.meta_information[pos],
                              body=d.meta_information[pos + 1:])
            d.headings.insert(0, heading)
            del d.meta_information[pos:]
            d.write()
            vim.command(
                u_encode(u'exe "normal %dgg"|startinsert!' %
                         (heading.start_vim, )))
            return heading

        # check for plain list(checkbox)
        current_heading.init_checkboxes()
        c = current_heading.current_checkbox()
        if c is not None:
            ORGMODE.plugins[u"EditCheckbox"].new_checkbox(below, not c.status)
            return

        heading = Heading(level=current_heading.level)

        # it's weird but this is the behavior of original orgmode
        if below is None:
            below = cursor[1] != 0 or end_of_last_child

        # insert newly created heading
        l = current_heading.get_parent_list()
        idx = current_heading.get_index_in_parent_list()
        if l is not None and idx is not None:
            l.insert(idx + (1 if below else 0), heading)
        else:
            raise HeadingDomError(
                u'Current heading is not properly linked in DOM')

        if below and not end_of_last_child:
            # append heading at the end of current heading and also take
            # over the children of current heading
            for child in current_heading.children:
                heading.children.append(child, taint=False)
            current_heading.children.remove_slice(
                0, len(current_heading.children), taint=False)

        # if cursor is currently on a heading, insert parts of it into the
        # newly created heading
        if insert_mode and cursor[1] != 0 and cursor[
                0] == current_heading.start_vim:
            offset = cursor[1] - current_heading.level - 1 - (
                len(current_heading.todo) + 1 if current_heading.todo else 0)
            if offset < 0:
                offset = 0
            if int(settings.get(u'org_improve_split_heading', u'1')) and \
             offset > 0 and len(current_heading.title) == offset + 1 \
             and current_heading.title[offset - 1] not in (u' ', u'\t'):
                offset += 1
            heading.title = current_heading.title[offset:]
            current_heading.title = current_heading.title[:offset]
            heading.body = current_heading.body[:]
            current_heading.body = []

        d.write()
        # do not start insert upon adding new headings, unless already in insert mode. Issue #211
        if int(settings.get(u'org_prefer_insert_mode', u'1')) or insert_mode:
            vim.command(
                u_encode(u'exe "normal %dgg"|startinsert!' %
                         (heading.start_vim, )))
        else:
            vim.command(u_encode(u'exe "normal %dgg$"' %
                                 (heading.start_vim, )))

        # return newly created heading
        return heading