• 写一下我的SublimeText3 for Python 的配置之路吧


     Windows7 32bits 环境,Sublime Text3 安装,参考这个帖子,http://www.xiumu.org/note/sublime-text-3.shtml 不解释。我是使用VIM模式的,如果不用VIM模式,下面的AHK脚本可能不正常工作。

    Python安装2.7.8, 另外安装了 ipython。控制台使用的是 ConEmu。ipython和ConEmu都在PATH中可以搜索到。

    直接安装SublimeCodeIntel - dev 版,实现代码的自动补全,很爽。稳定版 Windows下有问题,不能用!

    我需要实现的是,代码在 SublimeText 中完成,快捷键送到 python下执行。试验了 SublimeREPL,发现python在sublimetext中非常慢,而且sublimeREPL中的ipython环境显示的颜色是按照代码着色的,很不爽。因为有时候会出现代码错误提示信息,且由于信息太长,显示不全。这时候,可能只有一个引号出现,sublimetext着色的时候,就认为字符串开始了,而且没有结束。反正各种不爽。

    其实比较喜欢的方式是 Enhanced-R的方式,通过Autohotkey,把代码发送到 R 环境中。既然没有现成的,只好自己写一个简单的凑合用了。

    1. 在SublimeText中实现打开ConEmu和ipython。在SublimeTex的插件目录中,例如:d:Program FilesSublime TextDataPackages,新建目录 CMD,在CMD中,新建文件 cmd.py,输入如下内容,

     1 import os, sublime_plugin
     2 class CmdCommand(sublime_plugin.TextCommand):
     3     def run(self, edit):
     4         file_name=self.view.file_name()
     5         path=file_name.split("\")
     6         current_driver=path[0]
     7         path.pop()
     8         current_directory="\".join(path)
     9         command= "cd "+current_directory+" & "+current_driver+" & start ConEmu /cmd ipython"
    10         os.system(command)        

    2. 在CMD目录中,创建文件Context.sublime-menu,输入如下内容,

    [
         { "command": "cmd" }
    ]
    

    这样在SublimeText中可以通过右键打开ipython环境,并且是在当前文件的目录下。

    3. 安装 Autohotkey,创建hotkey.ahk文件,如下,

    SetTitleMatchMode, 3
    SetTitleMatchMode, Fast
    SetKeyDelay, 10, 10
    IfWinActive ahk_class PX_WINDOW_CLASS
    {
        #s::
            Send ^c
            IfWinExist ahk_class VirtualConsoleClass
            {
                WinActivate
                Send {Enter}
                Send {ASC 0037}paste {Enter}
            }
            return
        #b::
            Send ^c
            IfWinExist ahk_class VirtualConsoleClass
            {
                WinActivate
                Send {Enter}
                Send {ASC 0037}paste {Enter}
                WinActivate ahk_class PX_WINDOW_CLASS
            }
            return
    }
      
    

    把文件编程成可执行文件,(autohotkey自带ahk2exe工具),添加到开机执行菜单中。

    这样,通过 Win+s 键就可以把选择的行发送到 ipython里面执行了,(如果没有选择,就发送当前行)。Win+b是发送选择的行,但光标停留在当前窗口。

  • 相关阅读:
    Maven仓库详解
    Maven镜像配置
    使用spring的jdbcTemplate-----用JDBC模板查询数据库
    struts2+spring的两种整合方式
    Spring 中设置依赖注入
    Struts_json插件配置参数
    String、StringBuffer与StringBuilder之间区别
    有关collection中的一些数据结构
    MyBatis的foreach语句详解
    struts文件上传拦截器中参数的配置(maximumSize,allowedTypes ,allowedExtensions)问题
  • 原文地址:https://www.cnblogs.com/kidoln/p/3977372.html
Copyright © 2020-2023  润新知