gnupack-13.00に更新したときのメモ

gnupackが更新されたので追従してみた。いつもありがとうございます。
http://d.hatena.ne.jp/ksugita0510/20150502/p1

gnupack-13.00の準備

いつものようにcygwinpythonを削除。普段はwindowspythonを使っている。

$ apt-cyg remove python

curl,git-svnがデフォルトだと入っていないのでinstall

$ apt-cyg install curl git-svn
elpy導入

事前にpythonにelpy,jedi,rope-py3kを導入。emacsにelpyパッケージをインストール。
init.elに下記を追記。

    (setq elpy-modules
          '(elpy-module-company
            elpy-module-eldoc
            elpy-module-pyvenv
            elpy-module-yasnippet
            elpy-module-sane-defaults))
    (setq elpy-rpc-backend "jedi")
    (setq elpy-rpc-python-command "/home/bin/python") ;; 俺のpython.exe

    (elpy-enable)

elpy-modulesはflymakeとhighlight-indentationは別のを使ってるのでそれ以外に絞る。
elpy-rpc-backendは明示的に"jedi"にした。デフォルトでもjediになってるような気がした。
elpy入れたらpython-modeあんまり意味無いように思えたので前まで使っていたpython-modeは削除。

python-modeでinternal-shellが起動してしまうとディレクトリが開けなくなる

謎。そもそもデフォルトのpython.elだけだとinternal-shellは起動されないので調べていくと、
semanticをrequireしただけで自動的にsetupで混入される模様。setupを無効な関数に置き換え。

(defun wisent-python-default-setup () nil)
相変わらずauto-revert-modeを有効にすると起動後1回だけ異常に待たされる。

1分近く完全に固まる。emacs24.5でも同じでした。前のgnupack-12.03はemacs24.4。これはローカルの問題なのだろうか…。

追記 cygwin/emacswindows-python/elpy はパス形式が違うため正常に動作しない

site-packages/elpy-1.8.0-py3.4.egg/elpy/rpc.pyを下記のように書き換え。

@@ -10,6 +10,7 @@
 import json
 import sys
 import traceback
+import subprocess
 
 
 class JSONRPCServer(object):
@@ -77,6 +78,14 @@
         self.stdout.write(json.dumps(kwargs) + "\n")
         self.stdout.flush()
 
+    # >>> for cygwin >>>
+    @classmethod
+    def convert_filename(cls, filename):
+        if filename.startswith('/') and ('\n' not in filename):
+            filename = subprocess.getoutput(['cygpath', '-wa', filename])
+        return filename
+    # <<< for cygwin <<<
+
     def handle_request(self):
         """Handle a single JSON-RPC request.
 
@@ -94,6 +103,23 @@
         method_name = request['method']
         request_id = request.get('id', None)
         params = request.get('params') or []
+
+        # >>> for cygwin >>>
+        for pos, value in enumerate(params):
+            if isinstance(value, dict):
+                if 'filename' in value:
+                    value['filename'] = self.convert_filename(value['filename'])
+                if 'project_root' in value:
+                    value['project_root'] = self.convert_filename(value['project_root'])
+            elif isinstance(value, str):
+                params[pos] = self.convert_filename(value)
+        # <<< for cygwin <<<
+
         try:
             method = getattr(self, "rpc_" + method_name, None)
             if method is not None:

かなり適当ですが、これでelpy-refactorも呼べる。
前からemacs側でwindows-path.elを導入してあるので、もしかしたらどこかでそれも必要かも?
http://www.emacswiki.org/emacs/windows-path.el