Пример #1
0
 def get_region(self):
     '''
     获得这个buffer对象中被选中的部分文字
     '''
     lisp('(set-buffer %s)' % self.varname)
     b, e = lisp.region_beginning(), lisp.region_end()
     s = lisp.buffer_substring(b, e)
     return s
Пример #2
0
def new(language, region_start=None, region_end=None):
    """
    Create a new paste.  Use the given (programming) ``language`` for server
    side highlighting.

    If ``region_start`` and ``region_end`` are given, create a paste with
    the contents of this region.

    When called interactively with transient mark mode enabled and an active
    mark, create a paste with the contents of the region.  Otherwise create
    a paste with the contents of the whole buffer.
    """

    lodgeit = lodgeIt()

    mark_active = lisp.mark_active.value()
    transient_mark_mode = lisp.transient_mark_mode.value()
    if lisp.interactive and  transient_mark_mode and mark_active:
        # use a region, if we have one
        region_start = lisp.region_beginning()
        region_end = lisp.region_end()
    elif region_start:
        # otherwise use the given arguments
        region_start = min(region_start, region_end)
        region_end = max(region_start, region_end)
    else:
        # as last resort, paste the whole buffer
        region_start = lisp.point_min_marker()
        region_end = lisp.point_max_marker()

    code = unicode(lisp.buffer_substring(region_start, region_end))
    filename = lisp.buffer_file_name()

    lisp.message('Transferring paste to server...')
    paste_id = lodgeit.new_paste(code, language, filename=filename)
    paste = lodgeit.get_paste_by_id(paste_id)
    lisp.message(
        'New paste with ID {0.id} created. Refer to {0.url}'.format(paste))
    if lisp.paste_kill_url.value():
        lisp.kill_new(paste.url)
    if lisp.paste_show_in_browser.value():
        lisp.browse_url(paste.url)
Пример #3
0
def get_new_from_region_args():
    """Gets args for new_from_region:
    The language and the currently active region"""
    lang = read_language()
    start, end = lisp.region_beginning(), lisp.region_end()
    return [start, end, lang]
Пример #4
0
def get_new_from_region_args():
    """Gets args for new_from_region:
    The language and the currently active region"""
    lang = read_language()
    start, end = lisp.region_beginning(), lisp.region_end()
    return [start, end, lang]