修改dired插件

本文介绍了如何在Sublime Text中修改Dired插件,使其能够直接打开Word文档,提供了代码片段和实现步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

修改dired插件

sublime text中有个仿emacs中的dired插件,可以方便的访问文件夹及文件。在打开文件时,都是在sublime text中,如果要开word文档,需要修改写插件,如下:

class DiredSelect(TextCommand, DiredBaseCommand):
    def run(self, edit, new_view=False):
        path = self.path
        filenames = self.get_selected()

        # If reuse view is turned on and the only item is a directory, refresh the existing view.
        if not new_view and reuse_view():
            if len(filenames) == 1 and isdir(join(path, filenames[0])):
                fqn = join(path, filenames[0])
                show(self.view.window(), fqn, view_id=self.view.id())
                return

        for filename in filenames:
            fqn = join(path, filename)
            if isdir(fqn):
                show(self.view.window(), fqn, ignore_existing=new_view)
+            elif os.path.splitext(fqn)[1] in (".doc", ".docx"):
+                subprocess.Popen(['C:\Program Files\Microsoft Office\Office12\WINWORD.exe', fqn])
            else:
                self.view.window().open_file(fqn)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值