Exemplo n.º 1
0
    def register_plugin(self, plugin):
        if not isinstance(plugin, basestring):
            raise ValueError(u'Parameter plugin is not of type string')

        if plugin == u'|':
            self.orgmenu + orgmode.menu.Separator()
            self.orgmenu.children[-1].create()
            return

        if plugin in self._plugins:
            raise PluginError(u'Plugin %s has already been loaded')

        # a python module
        module = None

        # actual plugin class
        _class = None

        # locate module and initialize plugin class
        try:
            module = imp.find_module(plugin, orgmode.plugins.__path__)
        except ImportError as e:
            echom(u'Plugin not found: %s' % plugin)
            if self.debug:
                raise e
            return

        if not module:
            echom(u'Plugin not found: %s' % plugin)
            return

        try:
            module = imp.load_module(plugin, *module)
            if not hasattr(module, plugin):
                echoe(u'Unable to find plugin: %s' % plugin)
                if self.debug:
                    raise PluginError(u'Unable to find class %s' % plugin)
                return
            _class = getattr(module, plugin)
            self._plugins[plugin] = _class()
            self._plugins[plugin].register()
            if self.debug:
                echo(u'Plugin registered: %s' % plugin)
            return self._plugins[plugin]
        except Exception as e:
            echoe(u'Unable to activate plugin: %s' % plugin)
            echoe(u"%s" % e)
            if self.debug:
                import traceback
                echoe(traceback.format_exc())
Exemplo n.º 2
0
    def register_plugin(self, plugin):
        if not isinstance(plugin, basestring):
            raise ValueError(u'Parameter plugin is not of type string')

        if plugin == u'|':
            self.orgmenu + orgmode.menu.Separator()
            self.orgmenu.children[-1].create()
            return

        if plugin in self._plugins:
            raise PluginError(u'Plugin %s has already been loaded')

        # a python module
        module = None

        # actual plugin class
        _class = None

        # locate module and initialize plugin class
        try:
            module = imp.find_module(plugin, orgmode.plugins.__path__)
        except ImportError, e:
            echom(u'Plugin not found: %s' % plugin)
            if self.debug:
                raise e
            return
Exemplo n.º 3
0
    def _process_all_states(cls, all_states):
        u""" verify if states defined by user is valid.
		Return cleaned_todo and flattened if is. Raise Exception if not.
		Valid checking:
			* no two state share a same name
		"""
        # TODO Write tests. -- Ron89
        cleaned_todos = [[
            split_access_key(todo)[0] for todo in it.chain.from_iterable(x)
        ] for x in all_states] + [[None]]

        flattened_todos = list(it.chain.from_iterable(cleaned_todos))
        if len(flattened_todos) != len(set(flattened_todos)):
            raise PluginError(
                u"Duplicate names detected in TODO keyword list. Please examine `g/b:org_todo_keywords`"
            )
        # TODO This is the case when there are 2 todo states with the same
        # name. It should be handled by making a simple class to hold TODO
        # states, which would avoid mixing 2 todo states with the same name
        # since they would have a different reference (but same content),
        # albeit this can fail because python optimizes short strings (i.e.
        # they hold the same ref) so care should be taken in implementation
        return (cleaned_todos, flattened_todos)
Exemplo n.º 4
0
class OrgMode(object):
    u""" Vim Buffer """
    def __init__(self):
        object.__init__(self)
        self.debug = bool(int(orgmode.settings.get(u'org_debug', False)))

        self.orgmenu = orgmode.menu.Submenu(u'&Org')
        self._plugins = {}
        # list of vim buffer objects
        self._documents = {}

        # agenda manager
        self.agenda_manager = AgendaManager()

    def get_document(self, bufnr=0, allow_dirty=False):
        """ Retrieve instance of vim buffer document. This Document should be
		used for manipulating the vim buffer.

		:bufnr:			Retrieve document with bufnr
		:allow_dirty:	Allow the retrieved document to be dirty

		:returns:	vim buffer instance
		"""
        if bufnr == 0:
            bufnr = vim.current.buffer.number

        if bufnr in self._documents:
            if allow_dirty or self._documents[bufnr].is_insync:
                return self._documents[bufnr]
        self._documents[bufnr] = VimBuffer(bufnr).init_dom()
        return self._documents[bufnr]

    @property
    def plugins(self):
        return self._plugins.copy()

    @orgmode.keybinding.register_keybindings
    @orgmode.keybinding.register_commands
    @orgmode.menu.register_menu
    def register_plugin(self, plugin):
        if not isinstance(plugin, basestring):
            raise ValueError(u'Parameter plugin is not of type string')

        if plugin == u'|':
            self.orgmenu + orgmode.menu.Separator()
            self.orgmenu.children[-1].create()
            return

        if plugin in self._plugins:
            raise PluginError(u'Plugin %s has already been loaded')

        # a python module
        module = None

        # actual plugin class
        _class = None

        # locate module and initialize plugin class
        try:
            module = imp.find_module(plugin, orgmode.plugins.__path__)
        except ImportError, e:
            echom(u'Plugin not found: %s' % plugin)
            if self.debug:
                raise e
            return

        if not module:
            echom(u'Plugin not found: %s' % plugin)
            return

        try:
            module = imp.load_module(plugin, *module)
            if not hasattr(module, plugin):
                echoe(u'Unable to find plugin: %s' % plugin)
                if self.debug:
                    raise PluginError(u'Unable to find class %s' % plugin)
                return
            _class = getattr(module, plugin)
            self._plugins[plugin] = _class()
            self._plugins[plugin].register()
            if self.debug:
                echo(u'Plugin registered: %s' % plugin)
            return self._plugins[plugin]
        except Exception, e:
            echoe(u'Unable to activate plugin: %s' % plugin)
            echoe(u"%s" % e)
            if self.debug:
                import traceback
                echoe(traceback.format_exc())