示例#1
0
def occurrences_goto():
    if lisp.line_number_at_pos() < 1:
        lisp.forward_line(1 - lisp.line_number_at_pos())
    lisp.end_of_line()
    end = lisp.point()
    lisp.beginning_of_line()
    line = lisp.buffer_substring_no_properties(lisp.point(), end)
    tokens = line.split()
    semicolon_tokens = line.split(":")

    project_root = lisp.rope_get_project_root()
    if tokens and semicolon_tokens:
        # Mark this line with an arrow
        lisp('''
        (remove-overlays (point-min) (point-max))
            (overlay-put (make-overlay (line-beginning-position) (line-end-position))
            'before-string
            (propertize "A" 'display '(left-fringe right-triangle)))
        ''')


        filename = project_root + "/" + semicolon_tokens[0]
        offset = int(tokens[-1])
        resource = _interface._get_resource(filename)
        LispUtils().find_file(resource.real_path, other=True)
        lisp.goto_char(offset + 1)
示例#2
0
    def __init__(self, brmctx):
        self.ctx = brmctx

        lisp.require(lisp["python-mode"])
        lisp("""
        (defvar brm-menu nil "Menu for Bicycle Repair Man")
         (easy-menu-define
          brm-menu py-mode-map "Bicycle Repair Man"
          '("BicycleRepairMan"
                   "Queries"
                   ["Find-References" brm-find-references]
                   ["Find-Definition" brm-find-definition]
                   "---"
                   "Refactoring"
                   ["Rename" brm-rename t]
                   ["Extract-Method" brm-extract-method t]
                   ["Extract-Local-Variable" brm-extract-local-variable t]
                   ["Inline-Local-Variable" brm-inline-local-variable t]
                   ["Undo Last Refactoring" brm-undo t]

        ))
        (add-hook 'python-mode-hook (lambda () (easy-menu-add brm-menu)))
        """)
        #           ["Move-Class-To-New-Module" brm-move-class t]
        #           ["Move-Function-To-New-Module" brm-move-class t]

        self.ctx.setProgressLogger(logger)
示例#3
0
    def __init__(self,brmctx):
        self.ctx = brmctx

        lisp.require(lisp["python-mode"])
        lisp("""
        (defvar brm-menu nil "Menu for Bicycle Repair Man")
         (easy-menu-define
          brm-menu py-mode-map "Bicycle Repair Man"
          '("BicycleRepairMan"
                   "Queries"
                   ["Find-References" brm-find-references]
                   ["Find-Definition" brm-find-definition]
                   "---"
                   "Refactoring"
                   ["Rename" brm-rename t]
                   ["Extract-Method" brm-extract-method t]
                   ["Extract-Local-Variable" brm-extract-local-variable t]
                   ["Inline-Local-Variable" brm-inline-local-variable t]
                   ["Undo Last Refactoring" brm-undo t]

        ))
        (add-hook 'python-mode-hook (lambda () (easy-menu-add brm-menu)))
        """)
        #           ["Move-Class-To-New-Module" brm-move-class t]
        #           ["Move-Function-To-New-Module" brm-move-class t]

        self.ctx.setProgressLogger(logger)
示例#4
0
def emacs_writebuf(srcpath, bufname):
    if lisp is None:
        return None
    temppath = os.path.join( os.path.dirname(srcpath), 'fn_%04d.py' 
                             % random.randint(1000,9999) )
    lisp('(write-region nil nil "%s" :visit 1)' % temppath)
    return temppath
示例#5
0
文件: buffer_.py 项目: sdjc/embundle
 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
示例#6
0
文件: buffer_.py 项目: sdjc/embundle
 def _read_local(self, key):
     '''读取本buffer的变量值'''
     raw_trace('_read_local %s' % key) ####
     r = lisp("(local-variable-if-set-p '%s %s)" % (key, self.varname))
     raw_trace('r=%s' % str(r)) ####
     if not r:
         raise AttributeError()
     return lisp("(buffer-local-value '%(key)s %(var)s)" %
                 {'key':key, 'var': self.varname})
示例#7
0
    def __init__(self):
        self.project = None
        self.old_content = None
        lisp(DEFVARS)

        self._prepare_refactorings()
        self.autoimport = None
        self._init_ropemacs()
        lisp(MINOR_MODE)
示例#8
0
def emacs_update(bufname, info):
    if lisp is None:
        return None
    let = Let().push_excursion()
    if True:
        lisp('(set-buffer (get-buffer "%s"))' % bufname)
        lisp.flynote_last = info
        lisp('(flynote-update)')
    del let
示例#9
0
def _load_ropemacs():
    global _interface
    ropemode.decorators.logger.message = message
    lisp(DEFVARS)
    _interface = ropemode.interface.RopeMode(env=LispUtils())
    _interface.init()
    lisp(MINOR_MODE)

    if LispUtils().get('enable_shortcuts'):
        for key, command in shortcuts:
            LispUtils()._bind_local(command, key)

    lisp.add_hook(lisp['python-mode-hook'], lisp['ropemacs-mode'])
示例#10
0
def _load_ropemacs():
    global _interface
    ropemode.decorators.logger.message = message
    lisp(DEFVARS)
    _interface = ropemode.interface.RopeMode(env=LispUtils())
    _interface.init()
    lisp(MINOR_MODE)

    if LispUtils().get('enable_shortcuts'):
        for key, command in shortcuts:
            LispUtils()._bind_local(command, key)

    lisp.add_hook(lisp['python-mode-hook'], lisp['ropemacs-mode'])
示例#11
0
    def clean_undo_after(self, checkpoint):
        """\
Remove all intermediate boundaries from the Undo list since CHECKPOINT.
"""
        lisp("""
(let ((undo-list %s))
  (if (not (eq buffer-undo-list undo-list))
      (let ((cursor buffer-undo-list))
        (while (not (eq (cdr cursor) undo-list))
          (if (car (cdr cursor))
              (setq cursor (cdr cursor))
            (setcdr cursor (cdr (cdr cursor)))))))
  nil)
""" % (checkpoint or 'nil'))
示例#12
0
文件: pym.py 项目: Airead/airemacs.d
def clean_undo_after(checkpoint):
        """\
Remove all intermediate boundaries from the Undo list since CHECKPOINT.
"""
        lisp("""
(let ((undo-list %s))
  (if (not (eq buffer-undo-list undo-list))
      (let ((cursor buffer-undo-list))
        (while (not (eq (cdr cursor) undo-list))
          (if (car (cdr cursor))
              (setq cursor (cdr cursor))
            (setcdr cursor (cdr (cdr cursor)))))))
  nil)
"""
             % (checkpoint or 'nil'))
示例#13
0
    def remainder_of_line(self):
        """\
Return all characters between point and end of line in Emacs buffer.
"""
        return lisp('''\
(buffer-substring (point) (save-excursion (skip-chars-forward "^\n") (point)))
''')
示例#14
0
文件: buffer_.py 项目: sdjc/embundle
    def _write_local(self, key, value):
        '''设置本buffer的变量值'''
        # 这个value有点特殊
        if isinstance(value, str):
            tranvalue = '"' + value + '"'
        elif isinstance(value, unicode):
            tranvalue = '"' + value.encode('utf-8') + '"'
        else:
            tranvalue = str(value)

        lisp('''
(with-current-buffer %(varname)s
  (setq %(key)s %(value)s))''' %
             {'varname': self.varname,
              'key': key,
              'value': tranvalue})
示例#15
0
    def remainder_of_line(self):
        """\
Return all characters between point and end of line in Emacs buffer.
"""
        return lisp('''\
(buffer-substring (point) (save-excursion (skip-chars-forward "^\n") (point)))
''')
示例#16
0
文件: _e2p.py 项目: sdjc/embundle
 def __getattr__(self, key):
     '''
     特殊的读取对象的方式
     '''
     # 从emacs lisp中读取这个东西
     val = lisp(key)
     # 把val转换成python类型
     # todo: 假定这里读出来的东西不是对象类型
     raw_trace('%s %s' % (type(val), str(val))) ####
     return val
示例#17
0
def check_now(srcpath, bufname):
    logging.info('check %s', bufname or srcpath)
    temppath = emacs_writebuf(srcpath, bufname)
    info = []
    try:
        info = run_checks(srcpath=temppath, bufname=bufname)
    except Exception:
        logging.exception('check_now(%s, %s)', srcpath, bufname)
        lisp('(message "{0}: {1}")'.format(bufname, traceback.format_exc()))
        return None
    finally:
        if temppath:
            os.remove(temppath)
            pyc_path = temppath+'c'
            if os.path.exists(pyc_path):
                os.remove(pyc_path)
    logging.info('%s => %d notes', bufname, len(info))
    if info:
        logging.info('- %s', str(info[:5]))
    return len(info)
示例#18
0
文件: _e2p.py 项目: sdjc/embundle
def map2py(lispstat):
    '''
    假设不作任何缓存;即使做,这里的接口也不变,这样才能使上面那一层足
    够灵活
    '''
    varname = _getvarname()
    lisp('(setq %s %s)' % (varname, lispstat))
    ehash = lisp('(prin1-to-string %s)' % varname)

    # 从ehash中提取出类型信息
    tp = _gettypefromhash(ehash)
    handle = tp.get_handle(ehash)

    # 好吧,不让同一个hash存在一个以上的实例
    try:
        return _objpool[handle]
    except KeyError:
        obj = tp(varname, handle)
        _objpool[varname] = obj
        _objpool[handle]  = obj
        return obj
示例#19
0
文件: _e2p.py 项目: sdjc/embundle
def getlist(lispstat):
    """
    从Emacs中获得一个列表对象,这里假设这个列表中放着的都是因为对象,列
    表不存在嵌套,比如(frame-list), (buffer-list)
    """
    result = []
    one = lisp(lispstat)
    for i in range(len(one)):
        # 如果对象不存在就创建
        obj = map2py('(nth %d %s)' % (i, lispstat))
        result.append(obj)
    return result
示例#20
0
文件: frame.py 项目: sdjc/embundle
 def select_frame_set_input_focus(self):
     lisp("(select-frame-set-input-focus %s)" % self._v)
示例#21
0
文件: frame.py 项目: sdjc/embundle
 def set_frame_position(self, left, top):
     lisp('(set-frame-position %s %d %d)' % (self._v, left, top))
示例#22
0
文件: frame.py 项目: sdjc/embundle
 def top(self):
     return lisp("(frame-parameter %s 'top)" % self._v)
示例#23
0
文件: frame.py 项目: sdjc/embundle
 def left(self):
     return lisp("(frame-parameter %s 'left)" % self._v)
示例#24
0
文件: window.py 项目: sdjc/embundle
 def set_window_buffer(self, buffer_object):
     lisp('(set-window-buffer %s %s)' %
          (self.varname, buffer_object.varname))
示例#25
0
 def _bind_local(self, name, key):
     lisp('(define-key ropemacs-local-keymap "%s" \'%s)' %
          (self._key_sequence(key), name))
示例#26
0
  "Try to guess the project when needed.

If non-nil, ropemacs tries to guess and open the project that contains
a file on which the rope command is performed when no project is
already opened.")

(provide 'ropemacs)
"""

MINOR_MODE = """\
(define-minor-mode ropemacs-mode
 "ropemacs, rope in emacs!" nil " Rope" ropemacs-local-keymap
  :global nil)
)
"""

shortcuts = [('M-/', 'rope-code-assist'), ('M-?', 'rope-lucky-assist'),
             ('C-c g', 'rope-goto-definition'), ('C-c d', 'rope-show-doc'),
             ('C-c f', 'rope-find-occurrences')]

ropemode.decorators.logger.message = message
lisp(DEFVARS)
_interface = ropemode.interface.RopeMode(env=LispUtils())
_interface.init()
lisp(MINOR_MODE)

for key, command in shortcuts:
    LispUtils()._bind_local(command, key)

lisp.add_hook(lisp['python-mode-hook'], lisp['ropemacs-mode'])
示例#27
0
文件: frame.py 项目: sdjc/embundle
 def window_list(self):
     lst = []
     for i, _w in enumerate(lisp('(window-list)')):
         wobj = map2py('(nth %d (window-list))' % i)
         lst.append(wobj)
     return lst
示例#28
0
文件: window.py 项目: sdjc/embundle
 def delete_window(self):
     lisp('(delete-window %s)' % self._v)
示例#29
0
文件: window.py 项目: sdjc/embundle
 def split_window_vertically(self):
     lisp('(select-window %s)' % self._v)
     return map2py('(split-window-vertically)')
示例#30
0
文件: window.py 项目: sdjc/embundle
 def select_window(self):
     lisp('(select-window %s)' % self._v)
示例#31
0
 def _bind_local_key(self, callback, key):
     lisp('(define-key ropemacs-local-keymap "%s" \'%s)' %
          (self._key_sequence(key), callback))
示例#32
0
def mark_exists():
    if is_xemacs:
        return lisp.mark()
    else:
        return lisp("mark-active") and lisp.mark()
示例#33
0
 def _bind_local(self, name, key):
     lisp('(define-key ropemacs-local-keymap "%s" \'%s)' %
          (self._key_sequence(key), name))
示例#34
0
from lodgeitlib import lodgeit

# necessary references
lisp.require(lisp['easymenu'])
lisp.require(lisp['browse-url'])

# customisation group
# XXX: maybe this could somehow be written in python
lisp("""
(defgroup pastebin nil
  "Access to the pastebin on paste.pocoo.org"
  :group 'convenience)

(defcustom paste-kill-url nil
  "*If non-nil, put the url of a new paste into kill ring"
  :group 'pastebin
  :type 'boolean)

(defcustom paste-show-in-browser nil
  "*If non-nil, invoke the browser with the paste url after
  pasting a new snippet"
  :group 'pastebin
  :type 'boolean)
""")


## lodgeit wrappers which add some messaging
def new_paste(code, language, filename):
    """Creates a new paste."""
    lisp.message('Transferring paste to server...')
    id = lodgeit.new_paste(code, language, filename=filename)
    paste = lodgeit.get_paste_by_id(id)
示例#35
0
文件: window.py 项目: sdjc/embundle
 def set_window_point(self, pt):
     lisp('(set-window-point %s %d)' % (self._v, pt))
示例#36
0
文件: buffer_.py 项目: sdjc/embundle
 def set_buffer(self):
     '''使buffer实例成为"当前"的'''
     lisp('(set-buffer %s)' % self._v)
示例#37
0
文件: window.py 项目: sdjc/embundle
 def get_window_point(self):
     return lisp('(window-point %s)' % self._v)
示例#38
0
def mark_exists():
    if is_xemacs:
        return lisp.mark()
    else:
        return lisp("mark-active") and lisp.mark()