├── .gitignore ├── Default.sublime-commands ├── keymaps ├── Default (Linux).sublime-keymap ├── Default (OSX).sublime-keymap └── Default (Windows).sublime-keymap ├── metalang.exe ├── mql564.dll ├── mql564.exe ├── mql5_compiler.py └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | 3 | 4 | # Metatrader files # 5 | ################### 6 | 7 | *.ex5 8 | *.log 9 | *.mql5 10 | *.mq5 11 | -------------------------------------------------------------------------------- /Default.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Compile mql5", 4 | "command": "mql5_compiler", 5 | "args": { 6 | "compile":"True" 7 | } 8 | }, 9 | { 10 | "caption": "Check syntax mql5", 11 | "command": "mql5_compiler", 12 | "args": { 13 | "compile": "False" 14 | } 15 | } 16 | ] -------------------------------------------------------------------------------- /keymaps/Default (Linux).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": ["ctrl+alt+shift+n"], 4 | "command": "mql5_compiler", 5 | "args": { 6 | "compile":"true" 7 | } 8 | }, 9 | { 10 | "keys": ["ctrl+alt+n"], 11 | "command": "mql5_compiler", 12 | "args": { 13 | "compile":"false" 14 | } 15 | } 16 | ] -------------------------------------------------------------------------------- /keymaps/Default (OSX).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": ["ctrl+alt+shift+n"], 4 | "command": "mql5_compiler", 5 | "args": { 6 | "compile":"true" 7 | } 8 | }, 9 | { 10 | "keys": ["ctrl+alt+n"], 11 | "command": "mql5_compiler", 12 | "args": { 13 | "compile":"false" 14 | } 15 | } 16 | ] -------------------------------------------------------------------------------- /keymaps/Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "keys": ["ctrl+alt+shift+n"], 4 | "command": "mql5_compiler", 5 | "args": { 6 | "compile":"true" 7 | } 8 | }, 9 | { 10 | "keys": ["ctrl+alt+n"], 11 | "command": "mql5_compiler", 12 | "args": { 13 | "compile":"false" 14 | } 15 | } 16 | ] -------------------------------------------------------------------------------- /metalang.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IlanFrumer/mql5compiler/a561d3ee2dc4492351ca2e88b0d37d4f97e62a2a/metalang.exe -------------------------------------------------------------------------------- /mql564.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IlanFrumer/mql5compiler/a561d3ee2dc4492351ca2e88b0d37d4f97e62a2a/mql564.dll -------------------------------------------------------------------------------- /mql564.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IlanFrumer/mql5compiler/a561d3ee2dc4492351ca2e88b0d37d4f97e62a2a/mql564.exe -------------------------------------------------------------------------------- /mql5_compiler.py: -------------------------------------------------------------------------------- 1 | import sublime, sublime_plugin 2 | import os 3 | import subprocess 4 | import re 5 | 6 | PLATFORM = sublime.platform() 7 | METALANG = 'mql564.exe' 8 | EXTENSION = '.mq5' 9 | WINE = 'wine' 10 | 11 | BASE_PATH = os.path.abspath(os.path.dirname(__file__)) 12 | PLUGIN_FOLDER = '%s/' % os.path.basename(BASE_PATH) 13 | METALANG_PATH = os.path.join (sublime.packages_path(), PLUGIN_FOLDER , METALANG) 14 | 15 | def which(file): 16 | 17 | manual_path = os.path.join("/usr/bin", file) 18 | if os.path.exists(manual_path): 19 | return manual_path 20 | 21 | manual_path = os.path.join("/usr/local/bin", file) 22 | if os.path.exists(manual_path): 23 | return manual_path 24 | 25 | for dir in os.environ['PATH'].split(os.pathsep): 26 | path = os.path.join(dir, file) 27 | if os.path.exists(path): 28 | return path 29 | 30 | print "PATH = {0}".format(os.environ['PATH']) 31 | return None 32 | 33 | 34 | class Mql5CompilerCommand(sublime_plugin.TextCommand): 35 | 36 | def init(self): 37 | view = self.view 38 | 39 | self.dirname = os.path.realpath(os.path.dirname(view.file_name())) 40 | self.filename = os.path.basename(view.file_name()) 41 | self.extension = os.path.splitext(self.filename)[1] 42 | 43 | if PLATFORM != 'windows': 44 | self.wine_path = which(WINE) 45 | 46 | def isError(self): 47 | 48 | iserror = False 49 | 50 | if not os.path.exists(METALANG_PATH): 51 | print METALANG_PATH # Debug 52 | print "Mqlcompiler | error: metalang.exe not found" 53 | iserror = True 54 | 55 | if not self.view.file_name() : 56 | # check if console.. 57 | print "Mqlcompiler | error: Buffer has to be saved first" 58 | iserror = True 59 | 60 | if self.extension != EXTENSION: 61 | print "Mqlcompiler | error: wrong file extension: ({0})". \ 62 | format(self.extension) 63 | iserror = True 64 | 65 | if self.view.is_dirty(): 66 | print "Mqlcompiler | error: Save File before compiling" 67 | iserror = True 68 | 69 | if PLATFORM != 'windows': 70 | if not self.wine_path : 71 | print "Mqlcompiler | error: wine is not installed" 72 | iserror = True 73 | 74 | return iserror 75 | 76 | def runMetalang(self): 77 | 78 | command = [METALANG_PATH] 79 | 80 | if self.compile == "False": 81 | command.append("/s") 82 | 83 | command.append(self.filename) 84 | 85 | startupinfo = None 86 | 87 | # hide pop-up window on windows 88 | if PLATFORM == 'windows': 89 | startupinfo = subprocess.STARTUPINFO() 90 | startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW 91 | 92 | # executing exe files with wine on mac / linux 93 | if PLATFORM != 'windows': 94 | command.insert(0,self.wine_path) 95 | 96 | # execution: 97 | proc = subprocess.Popen(command, 98 | cwd= self.dirname, 99 | stdout=subprocess.PIPE, 100 | shell=False, 101 | startupinfo=startupinfo) 102 | 103 | return proc.stdout.read() 104 | 105 | def newLogWindow(self, output): 106 | view = self.view 107 | 108 | new_view = view.window().new_file() 109 | new_view.set_scratch(True) 110 | new_edit = new_view.begin_edit() 111 | new_view.insert(new_edit, 0, output) 112 | new_view.end_edit(new_edit) 113 | sublime.status_message('Metalang') 114 | 115 | pass 116 | 117 | def run(self , edit , compile): 118 | 119 | # compile or just check syntax 120 | self.compile = compile 121 | 122 | self.init() 123 | if self.isError(): 124 | return 125 | 126 | stdout = self.runMetalang() 127 | 128 | self.newLogWindow(stdout) -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # mql5 compiler (Sublime text plugin) 2 | 3 | **Default keys** : 4 | * Compile mql5 : ctrl + alt + shift + n 5 | * Check syntax mql5 : ctrl + alt + n 6 | 7 | * Tested on linux 8 | * please inform me if there are any issues. 9 | * fork & pull request me ! 10 | 11 | ## Dependencies (mac / linux) 12 | 13 | * wine: 14 | 15 | Linux: 16 | ```bash 17 | sudo apt-get install wine 18 | ``` 19 | OS-X: 20 | ```bash 21 | brew install wine 22 | ``` 23 | 24 | ## sublime folder 25 | 26 | Linux: 27 | ```bash 28 | cd ~/.config/sublime-text-2/Packages/ 29 | ``` 30 | 31 | OS-X: 32 | ```bash 33 | cd ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/ 34 | ``` 35 | 36 | Windows ([git-bash](http://git-scm.com/)): 37 | ```bash 38 | cd $APPDATA/Sublime\ Text\ 2/Packages/ 39 | ``` 40 | 41 | ## Installation 42 | * goto sublime folder , then: 43 | 44 | ```bash 45 | git clone https://github.com/IlanFrumer/mql5compiler.git 46 | ``` 47 | 48 | ## Update 49 | * goto sublime folder , then: 50 | 51 | ```bash 52 | cd mql5compiler/ 53 | git pull 54 | ``` 55 | --------------------------------------------------------------------------------