Пример #1
0
def insert_by_id(paste_id):
    """Fetches paste with `paste_id` and inserts it into current buffer"""
    paste = lodgeit.get_paste_by_id(paste_id)
    if paste:
        lisp.insert(paste.code)
    else:
        lisp.error('There is no paste with id %s', paste_id)
Пример #2
0
def insert_by_id(paste_id):
    """Fetches paste with `paste_id` and inserts it into current buffer"""
    paste = lodgeit.get_paste_by_id(paste_id)
    if paste:
        lisp.insert(paste.code)
    else:
        lisp.error('There is no paste with id {0}'.format(paste_id))
Пример #3
0
def fetch_by_id(paste_id):
    """Fetches paste with `paste_id` and inserts it into a new buffer"""
    paste = lodgeit.get_paste_by_id(paste_id)
    if paste:
        new_buffer_from_paste(paste)
    else:
        lisp.error('There is no paste with id %s', paste_id)
Пример #4
0
def fetch_by_id(paste_id):
    """Fetches paste with `paste_id` and inserts it into a new buffer"""
    paste = lodgeit.get_paste_by_id(paste_id)
    if paste:
        new_buffer_from_paste(paste)
    else:
        lisp.error('There is no paste with id'.format(paste_id))
Пример #5
0
    def emacs_engine(self, flag, find_limits):
        """\
Rebox text while obeying FLAG.  Call FIND_LIMITS to discover the extent
of the boxed comment.
"""
        # `C-u -' means that box style is to be decided interactively.
        if flag == lisp['-']:
            flag = self.ask_for_style()
        # If FLAG is zero or negative, only change default box style.
        if isinstance(flag, int) and flag <= 0:
            self.default_style = -flag
            lisp.message("Default style set to %d" % -flag)
            return
        # Decide box style and refilling.
        if flag is None:
            style = self.default_style
            refill = True
        elif isinstance(flag, int):
            if self.default_style is None:
                style = flag
            else:
                style = merge_styles(self.default_style, flag)
            refill = True
        else:
            flag = flag.copy()
            if isinstance(flag, list):
                style = self.default_style
                refill = False
            else:
                lisp.error("Unexpected flag value %s" % flag)
        # Prepare for reboxing.
        lisp.message("Reboxing...")
        checkpoint = lisp.buffer_undo_list.value()
        start, end = find_limits()
        text = lisp.buffer_substring(start, end)
        width = lisp.fill_column.value()
        tabify = lisp.indent_tabs_mode.value() is not None
        point = lisp.point()
        if start <= point < end:
            position = point - start
        else:
            position = None
        # Rebox the text and replace it in Emacs buffer.
        old_style, new_style, text, position = engine(
            text, style=style, width=width,
            refill=refill, tabify=tabify, position=position)
        if text is None:
            lisp.error("Cannot rebox to style %d" % new_style)
        lisp.delete_region(start, end)
        lisp.insert(text)
        if position is not None:
            lisp.goto_char(start + position)
        # Collapse all operations into a single one, for Undo.
        self.clean_undo_after(checkpoint)
        # We are finished, tell the user.
        if old_style == new_style:
            lisp.message("Reboxed with style %d" % old_style)
        else:
            lisp.message("Reboxed from style %d to %d"
                         % (old_style, new_style))
Пример #6
0
    def emacs_engine(self, flag, find_limits):
        """\
Rebox text while obeying FLAG.  Call FIND_LIMITS to discover the extent
of the boxed comment.
"""
        # `C-u -' means that box style is to be decided interactively.
        if flag == lisp['-']:
            flag = self.ask_for_style()
        # If FLAG is zero or negative, only change default box style.
        if isinstance(flag, int) and flag <= 0:
            self.default_style = -flag
            lisp.message("Default style set to %d" % -flag)
            return
        # Decide box style and refilling.
        if flag is None:
            style = self.default_style
            refill = True
        elif isinstance(flag, int):
            if self.default_style is None:
                style = flag
            else:
                style = merge_styles(self.default_style, flag)
            refill = True
        else:
            flag = flag.copy()
            if isinstance(flag, list):
                style = self.default_style
                refill = False
            else:
                lisp.error("Unexpected flag value %s" % flag)
        # Prepare for reboxing.
        lisp.message("Reboxing...")
        checkpoint = lisp.buffer_undo_list.value()
        start, end = find_limits()
        text = lisp.buffer_substring(start, end)
        width = lisp.fill_column.value()
        tabify = lisp.indent_tabs_mode.value() is not None
        point = lisp.point()
        if start <= point < end:
            position = point - start
        else:
            position = None
        # Rebox the text and replace it in Emacs buffer.
        old_style, new_style, text, position = engine(
            text, style=style, width=width,
            refill=refill, tabify=tabify, position=position)
        if text is None:
            lisp.error("Cannot rebox to style %d" % new_style)
        lisp.delete_region(start, end)
        lisp.insert(text)
        if position is not None:
            lisp.goto_char(start + position)
        # Collapse all operations into a single one, for Undo.
        self.clean_undo_after(checkpoint)
        # We are finished, tell the user.
        if old_style == new_style:
            lisp.message("Reboxed with style %d" % old_style)
        else:
            lisp.message("Reboxed from style %d to %d"
                         % (old_style, new_style))
Пример #7
0
def insert(name):
    """Inserts a license out of ``licenses_alist`` into the current
    buffer.
    """
    name = name.upper()
    try:
        args = {"year": date.today().year, "name": lisp.user_full_name.value(), "email": lisp.user_mail_address.value()}
        text = licenses[name] % args
    except KeyError:
        lisp.error("Unknown license %s", name)
        return
    # get the current point
    start_pos = lisp.point_marker()
    lisp.insert(text)
    lisp.insert("\n")
    end_pos = lisp.point_marker()
    lisp.comment_region(start_pos, end_pos)
Пример #8
0
def fetch(paste_id_or_url=None):
    """
    Fetch a paste and insert its content at point.

    If ``paste_id_or_url`` is given, fetch the paste with the given ID or
    URL, otherwise fetch the last paste.

    When called interactively, prompt for a paste ID or URL.  Empty input
    stands for the last paste.
    """

    lodgeit = lodgeIt()

    if paste_id_or_url:
        paste = lodgeit.get_paste_by_id(paste_id_or_url)
    else:
        paste = lodgeit.get_last_paste()
    if paste:
        lisp.insert(paste.code)
    else:
        lisp.error('There is no paste {0}'.format(paste_id_or_url))
Пример #9
0
def qualified_module_name(buffer=None):
    """
    Determine the qualified name of the python module which is currently
    edited in the given ``buffer``.  If unset, ``buffer`` defaults to the
    current buffer.

    If the buffer has no associated filename, this function returns None.
    """
    if not buffer:
        buffer = lisp.current_buffer()
    if isinstance(buffer, basestring):
        buffer = lisp.get_buffer(buffer)
        if buffer is None:
            lisp.error('No such buffer: %s', buffername)
    filename = lisp.buffer_file_name(buffer)
    if filename is None:
        return None

    filepath = os.path.normpath(os.path.abspath(filename))
    modules = []
    modname = os.path.basename(os.path.splitext(filepath)[0])
    if modname != '__init__':
        modules.append(modname)

    directory = os.path.dirname(filepath)
    parent = os.path.dirname(directory)
    while directory != parent:
        if not is_package(directory):
            break
        pkgname = os.path.basename(directory)
        modules.append(pkgname)
        directory = parent
        parent = os.path.dirname(directory)

    modules.reverse()
    return '.'.join(modules)
Пример #10
0
    def find_comment(self):
        """\
Find and return the limits of the block of comments following or enclosing
the cursor, or return an error if the cursor is not within such a block
of comments.  Extend it as far as possible in both directions.
"""
        let = Let().push_excursion()
        try:
            # Find the start of the current or immediately following comment.
            lisp.beginning_of_line()
            lisp.skip_chars_forward(' \t\n')
            lisp.beginning_of_line()
            if not language_matcher[0](self.remainder_of_line()):
                temp = lisp.point()
                if not lisp.re_search_forward('\\*/', None, lisp.t):
                    lisp.error("outside any comment block")
                lisp.re_search_backward('/\\*')
                if lisp.point() > temp:
                    lisp.error("outside any comment block")
                temp = lisp.point()
                lisp.beginning_of_line()
                lisp.skip_chars_forward(' \t')
                if lisp.point() != temp:
                    lisp.error("text before start of comment")
                lisp.beginning_of_line()
            start = lisp.point()
            language = guess_language(self.remainder_of_line())
            # Find the end of this comment.
            if language == 2:
                lisp.search_forward('*/')
                if not lisp.looking_at('[ \t]*$'):
                    lisp.error("text after end of comment")
            lisp.end_of_line()
            if lisp.eobp():
                lisp.insert('\n')
            else:
                lisp.forward_char(1)
            end = lisp.point()
            # Try to extend the comment block backwards.
            lisp.goto_char(start)
            while not lisp.bobp():
                if language == 2:
                    lisp.skip_chars_backward(' \t\n')
                    if not lisp.looking_at('[ \t]*\n[ \t]*/\\*'):
                        break
                    if lisp.point() < 2:
                        break
                    lisp.backward_char(2)
                    if not lisp.looking_at('\\*/'):
                        break
                    lisp.re_search_backward('/\\*')
                    temp = lisp.point()
                    lisp.beginning_of_line()
                    lisp.skip_chars_forward(' \t')
                    if lisp.point() != temp:
                        break
                    lisp.beginning_of_line()
                else:
                    lisp.previous_line(1)
                    if not language_matcher[language](
                            self.remainder_of_line()):
                        break
                start = lisp.point()
            # Try to extend the comment block forward.
            lisp.goto_char(end)
            while language_matcher[language](self.remainder_of_line()):
                if language == 2:
                    lisp.re_search_forward('[ \t]*/\\*')
                    lisp.re_search_forward('\\*/')
                    if lisp.looking_at('[ \t]*$'):
                        lisp.beginning_of_line()
                        lisp.forward_line(1)
                        end = lisp.point()
                else:
                    lisp.forward_line(1)
                    end = lisp.point()
            return start, end
        finally:
            let.pops()
Пример #11
0
 def __call__(self,  *params, **kwparams ):
     try:
         return self.makeCall(params)
     except:
         traceback.print_exc()
         lisp.error(str(sys.exc_info()[1]))
Пример #12
0
Файл: rebox.py Проект: ing7t/kod
    def find_comment(self):
        """\
Find and return the limits of the block of comments following or enclosing
the cursor, or return an error if the cursor is not within such a block
of comments.  Extend it as far as possible in both directions.
"""
        let = Let().push_excursion()
        try:
            # Find the start of the current or immediately following comment.
            lisp.beginning_of_line()
            lisp.skip_chars_forward(" \t\n")
            lisp.beginning_of_line()
            if not language_matcher[0](self.remainder_of_line()):
                temp = lisp.point()
                if not lisp.re_search_forward("\\*/", None, lisp.t):
                    lisp.error("outside any comment block")
                lisp.re_search_backward("/\\*")
                if lisp.point() > temp:
                    lisp.error("outside any comment block")
                temp = lisp.point()
                lisp.beginning_of_line()
                lisp.skip_chars_forward(" \t")
                if lisp.point() != temp:
                    lisp.error("text before start of comment")
                lisp.beginning_of_line()
            start = lisp.point()
            language = guess_language(self.remainder_of_line())
            # Find the end of this comment.
            if language == 2:
                lisp.search_forward("*/")
                if not lisp.looking_at("[ \t]*$"):
                    lisp.error("text after end of comment")
            lisp.end_of_line()
            if lisp.eobp():
                lisp.insert("\n")
            else:
                lisp.forward_char(1)
            end = lisp.point()
            # Try to extend the comment block backwards.
            lisp.goto_char(start)
            while not lisp.bobp():
                if language == 2:
                    lisp.skip_chars_backward(" \t\n")
                    if not lisp.looking_at("[ \t]*\n[ \t]*/\\*"):
                        break
                    if lisp.point() < 2:
                        break
                    lisp.backward_char(2)
                    if not lisp.looking_at("\\*/"):
                        break
                    lisp.re_search_backward("/\\*")
                    temp = lisp.point()
                    lisp.beginning_of_line()
                    lisp.skip_chars_forward(" \t")
                    if lisp.point() != temp:
                        break
                    lisp.beginning_of_line()
                else:
                    lisp.previous_line(1)
                    if not language_matcher[language](self.remainder_of_line()):
                        break
                start = lisp.point()
            # Try to extend the comment block forward.
            lisp.goto_char(end)
            while language_matcher[language](self.remainder_of_line()):
                if language == 2:
                    lisp.re_search_forward("[ \t]*/\\*")
                    lisp.re_search_forward("\\*/")
                    if lisp.looking_at("[ \t]*$"):
                        lisp.beginning_of_line()
                        lisp.forward_line(1)
                        end = lisp.point()
                else:
                    lisp.forward_line(1)
                    end = lisp.point()
            return start, end
        finally:
            let.pops()
Пример #13
0
 def __call__(self, *params, **kwparams):
     try:
         return self.makeCall(params)
     except:
         traceback.print_exc()
         lisp.error(str(sys.exc_info()[1]))