├── .gitignore ├── .no-sublime-package ├── Default.sublime-commands ├── keymaps ├── Default (Linux).sublime-keymap ├── Default (OSX).sublime-keymap └── Default (Windows).sublime-keymap ├── metalang.exe ├── mql4_compiler.py └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | .directory 2 | package-metadata.json 3 | *.pyc 4 | 5 | 6 | # Metatrader files # 7 | ################### 8 | 9 | *.ex4 10 | *.log 11 | *.mql4 12 | *.mq4 13 | -------------------------------------------------------------------------------- /.no-sublime-package: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IlanFrumer/mql4compiler/7ce744277381ccd6d317b2bf82a3c1c7ac02f37d/.no-sublime-package -------------------------------------------------------------------------------- /Default.sublime-commands: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "caption": "Compile mql4", 4 | "command": "mql4_compiler" 5 | } 6 | ] -------------------------------------------------------------------------------- /keymaps/Default (Linux).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | {"keys": ["ctrl+alt+m"], "command": "mql4_compiler"} 3 | ] -------------------------------------------------------------------------------- /keymaps/Default (OSX).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | {"keys": ["ctrl+alt+m"], "command": "mql4_compiler"} 3 | ] -------------------------------------------------------------------------------- /keymaps/Default (Windows).sublime-keymap: -------------------------------------------------------------------------------- 1 | [ 2 | {"keys": ["ctrl+alt+m"], "command": "mql4_compiler"} 3 | ] -------------------------------------------------------------------------------- /metalang.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/IlanFrumer/mql4compiler/7ce744277381ccd6d317b2bf82a3c1c7ac02f37d/metalang.exe -------------------------------------------------------------------------------- /mql4_compiler.py: -------------------------------------------------------------------------------- 1 | import sublime, sublime_plugin 2 | import os 3 | import subprocess 4 | import re 5 | 6 | import sys 7 | 8 | PLATFORM = sublime.platform() 9 | METALANG = 'metalang.exe' 10 | EXTENSION = '.mq4' 11 | WINE = 'wine' 12 | 13 | BASE_PATH = os.path.abspath(os.path.dirname(__file__)) 14 | METALANG_PATH = os.path.join(BASE_PATH, METALANG) 15 | 16 | def which(file): 17 | 18 | manual_path = os.path.join("/usr/bin", file) 19 | if os.path.exists(manual_path): 20 | return manual_path 21 | 22 | manual_path = os.path.join("/usr/local/bin", file) 23 | if os.path.exists(manual_path): 24 | return manual_path 25 | 26 | for dir in os.environ['PATH'].split(os.pathsep): 27 | path = os.path.join(dir, file) 28 | if os.path.exists(path): 29 | return path 30 | 31 | print ("PATH = {0}".format(os.environ['PATH'])) 32 | return None 33 | 34 | 35 | class Mql4CompilerCommand(sublime_plugin.TextCommand): 36 | 37 | def init(self): 38 | view = self.view 39 | 40 | if view.file_name() is not None : 41 | self.dirname = os.path.realpath(os.path.dirname(view.file_name())) 42 | self.filename = os.path.basename(view.file_name()) 43 | self.extension = os.path.splitext(self.filename)[1] 44 | 45 | if PLATFORM != 'windows': 46 | self.wine_path = which(WINE) 47 | 48 | def isError(self): 49 | 50 | iserror = False 51 | 52 | if not os.path.exists(METALANG_PATH): 53 | print (METALANG_PATH) # Debug 54 | print ("Mqlcompiler | error: metalang.exe not found") 55 | iserror = True 56 | 57 | if PLATFORM != 'windows': 58 | if not self.wine_path : 59 | print ("Mqlcompiler | error: wine is not installed") 60 | iserror = True 61 | 62 | if self.view.file_name() is None : 63 | # check if console.. 64 | print ("Mqlcompiler | error: Buffer has to be saved first") 65 | iserror = True 66 | 67 | else : 68 | 69 | if self.extension != EXTENSION: 70 | print ("Mqlcompiler | error: wrong file extension: ({0})".format(self.extension)) 71 | iserror = True 72 | 73 | if self.view.is_dirty(): 74 | print ("Mqlcompiler | error: Save File before compiling") 75 | iserror = True 76 | 77 | return iserror 78 | 79 | def runMetalang(self): 80 | 81 | command = [METALANG_PATH,self.filename] 82 | 83 | startupinfo = None 84 | 85 | # hide pop-up window on windows 86 | if PLATFORM == 'windows': 87 | startupinfo = subprocess.STARTUPINFO() 88 | startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW 89 | 90 | # executing exe files with wine on mac / linux 91 | if PLATFORM != 'windows': 92 | command.insert(0,self.wine_path) 93 | 94 | # execution: 95 | proc = subprocess.Popen(command, 96 | cwd= self.dirname, 97 | stdout=subprocess.PIPE, 98 | shell=False, 99 | startupinfo=startupinfo) 100 | 101 | return proc.stdout.read() 102 | 103 | def formatOutput(self , stdout): 104 | 105 | output = "" 106 | log_lines = re.split('\n',stdout) 107 | group_files = [] 108 | 109 | for l in log_lines : 110 | 111 | line = l.strip() 112 | 113 | if not line: 114 | continue 115 | 116 | line_arr = re.split(';',line) 117 | line_len = len(line_arr) 118 | 119 | if line_len < 5 : 120 | 121 | if re.match(r"^Exp file",line): 122 | output+= "\n-----------------------\n" 123 | 124 | output+= line + "\n" 125 | 126 | if line_len == 5 : 127 | fpath = line_arr[2].split("\\")[-1] 128 | 129 | if fpath and not fpath in group_files: 130 | group_files.append(fpath) 131 | output += "\n-----------------------\n" 132 | output += "file: {0}".format(fpath) 133 | output += "\n-----------------------\n" 134 | 135 | if line_arr[3]: 136 | output+= "line {0} | {1}".format(line_arr[3],line_arr[4]) 137 | else: 138 | output+= "{0}".format(line_arr[4]) 139 | output+= "\n" 140 | 141 | return output 142 | 143 | 144 | def newLogWindow(self, output): 145 | window = self.view.window() 146 | 147 | new_view = window.create_output_panel("mql4log") 148 | new_view.run_command('erase_view') 149 | new_view.run_command('append', {'characters': output}) 150 | window.run_command("show_panel", {"panel": "output.mql4log"}) 151 | 152 | sublime.status_message('Metalang') 153 | 154 | pass 155 | 156 | def run(self , edit): 157 | 158 | self.init() 159 | if self.isError(): 160 | return 161 | 162 | stdout = self.runMetalang() 163 | stdout = stdout.decode(encoding='UTF-8') 164 | output = self.formatOutput(stdout) 165 | self.newLogWindow(output) 166 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # mql4 compiler (Sublime text 3 plugin) 2 | 3 | * **Default key** : ctrl + alt + m 4 | * Using [Metatrader 4 build 509](http://forum.mql4.com/56329) 5 | * Install with [Sublime text Package manager](https://sublime.wbond.net/installation) 6 | 7 | ## Dependencies (mac / linux) 8 | 9 | * wine: 10 | 11 | Linux: 12 | ```bash 13 | sudo apt-get install wine 14 | ``` 15 | OS-X: 16 | ```bash 17 | brew install wine 18 | ``` 19 | --------------------------------------------------------------------------------