2014-03-12 13 views
1

在崇高文本3中,我想要創建一個宏來粘貼當前文件的「相對路徑從項目,編碼」,這是由出色的Sidebar Enhancements提供的命令。ST3:如何在宏中使用插件的命令?

我已激活控制檯日誌按照我的實驗:

  • 打開控制檯(Ctrl-`
  • sublime.log_commands(True)

當我執行我想捕捉的動作,我在控制檯中看到:

command: side_bar_copy_path_absolute_from_project_encoded 
command: paste 

但是當我記錄的操作,在節省所產生的JSON是:

[ 
    { 
     "args": null, 
     "command": "paste" 
    } 
] 

如果我手動破解宏(從Unofficial Sublime DocsSideBarEnhancements/Side Bar.sublime-menu獲取參數):

[ 
    { "command": "side_bar_copy_path_relative_from_project_encoded", "args": {"paths": []} }, 
    { "command": "paste", "args": null } 
] 

...然後播放宏,我在控制檯看到以下內容:

​​

(我也試過null作爲ARG爲side_bar_copy_path_relative_from_project_encoded)。

我是否需要在宏命令中引用包或類名?有什麼建議麼?

回答

0

Yeeha!想通了 - 我相信宏可能不支持所有的命令,所以我嘗試了插件:

import sublime, sublime_plugin 

''' 
    Paste the current file's Relative Path From Project (Encoded). 
    Requires https://github.com/titoBouzout/SideBarEnhancements to be installed 

    First save this file as: 
    ~/Library/Application Support/Sublime Text 3/Packages/User/paste-path.py 

    More details about writing plugins: 
    http://docs.sublimetext.info/en/latest/reference/plugins.html 

    To trigger the command with 'Command Option Shift p', 
    add the following to your Sublime Text > Preferences > Keybindings - User 

    [ 
     { "keys": ["super+option+shift+p"], "command": "paste_path"} 
    ] 
''' 

class PastePathCommand(sublime_plugin.WindowCommand): 
    def run(self): 
     self.window.run_command("side_bar_copy_path_relative_from_project_encoded", {"paths": []}) 
     self.window.run_command("paste") 

這是作爲一個要點:https://gist.github.com/9505770


編輯:對不起,不完整的信息!您需要將此文件保存爲這樣的:

~/Library/Application Support/Sublime Text 3/Packages/User/paste-path.py

的更多信息:http://docs.sublimetext.info/en/latest/reference/plugins.html

+1

ST宏只支持文本命令。我對一個在ST論壇上發佈的插件進行了一些修復,以運行任何類型的命令。有關詳細信息,請參閱https://github.com/skuroda/ImprovedMacros/blob/master/improved_macros/run_multiple_commands.py。我最初的目的是建立一些東西來取代默認的宏功能,但還沒有找到一個很好的方法來捕獲所有的鍵,命令等。 – skuroda

+0

我真的很想這樣做,但是當我將你提供的命令複製到我的Keybindings - 用戶文件,它不起作用。在之前的代碼中,「import sublime,sublime plugin」和「class」在最後被調用了什麼? –

+0

對不起,我遺漏了一些顯着的細節!這是編輯我的答案... – ptim

相關問題