Vim as ide for mql

 

Anyway, I wanted to give up the metaeditor. It turned out pretty good, I want to share it with you.

Requirements: 1. OS - linux (suitable for Windows, but not for me); 2 - installed dos2unix utility; 3 - installed clangd (LSP server); 4 - package manager vim-plug for vimhttps://github.com/junegunn/vim-plug. 5- terminal directory "~/.wine/drive_c/Program Files/MetaTrader 5"; 6 - I use console vim, I haven't tested how it works with goo.

Attached are the necessary files. Instructions:

1. Put in ~ .vimrc (or copy to your own). Run vim, run :PlugInstall

2. Restart vim, execute :CocConfig, copy

{
    "signature.enable": true,
    "signature.target": "float",
    "signature.maxWindowHeight": 100,

    "languageserver": {
        "clangd": {
            "command": "clangd",
            "filetypes": [
                "c",
                "cpp",
                "objc",
                "objcpp"
            ],
            "rootPatterns": [
                ".clangd",
                "compile_flags.txt",
                "compile_commands.json",
                ".vim/",
                ".git/",
                ".hg/"
            ],
            "initializationOptions": {
                "cache": {
                    "directory": "/tmp/clangd"
                }
            }
        }
    }
}

3. Copy coc.nvim_vimrc to ~/.vim/plugged/.

4. Copy to one of the PATH paths of compile_mql (change owner/group if necessary, give run permissions).

5. mql compiler refuses to compile when there are spaces in the paths, create a link

ln -s "${HOME}/.wine/drive_c/Program Files/MetaTrader 5/MQL5" "${HOME}/.wine/"

6. In ~/.wine/MQL5/Include create compile_flags.txt with content (instead of YOUR_HOME_DIR write your home directory, ${HOME} does not work):

-xc++-header
-IYOUR_HOME_DIR/.wine/MQL5/Include
-DVIM

7. Put vim.mqh in the Include subdirectory (mine is Include/myincl) (it must be included in every script/expert).

8. In the directory with scripts/experts create compile_flags.txt with the contents:

-xc++
-IYOUR_HOME_DIR/.wine/MQL5/Include
-DVIM


That's it. Now we don't need to touch meta-editor at all, create file, edit in vime, compile there too. We need to note:

1. it is much more advanced tool than autocomplete and related in meta-editor, clangd cannot be confused neither by cunning macrosnoy nor templates (editor on templates does not work even in simple cases). And vim itself is faster (at least the editor via vin).

2. Compile in vime with F7, view results with :copen or :clist/:cnext/... With possibility to jump to error/warning, i.e. everything is serious.

3. Combinations on all sorts of coder tricks (go to definition/...) look in coc.nvim_vimrc, basic:

gd - defenition
gy - type defenition
gy - implementation
gr - reference
K  - show documentation
[g - diagnost previous
]g - diagnost next
<leadir> rn - rename    (у меня leadir - ,)
<space> a - diagnost list
<space> o - outline list
<space> s - symbol list

4. When passing arrays to a function, replace & with ref, otherwise it won't show sinature help for that function (void examp_fn(int ref ar[]). Let's ignore clang's complaints about dots when dereferencing pointers, it's not critical.

5. In each header file do include guard, like this:

#ifndef  NEW_FILE_MQH
#define  NEW_FILE_MQH
...// кодим здесь
#endif //NEW_FILE_MQH

6. clang does not like #propert strict

7. Each post with new version of files will be hashtagged #vim_as_mql_ide_X for easy search among possible floods, where X is version.

8. vim.mqh contains function/constant declarations. Of course, I did not copy everything, it would be nice if someone could connect to the process and throw in declarations (but do not change formatting of existing ones - indentations, comments; to be able to easily make a diff). You can send me the updated vim.mqh and I will merge it into one and post it.

9. As a cheat sheet for vim you can use https://www.linux.org.ru/forum/general/15373588


#vim_as_mql_ide_0.

Files:
 

The new release, in my opinion, has more interesting plushies than the official releases ))

1. Screwed clang preprocessor to µl. Now you can implement any preprocessor tricks, even such http://jhnet.co.uk/articles/cpp_magic. The whole process looks like this: F7->clang preprocessor->mql preprocessor/compiler. To pass mql to mql compiler specific constructs (well, to avoid infuriating and confusing clang with all kind of rubbish, it does not like it very much) do the following

#ifndef  VIM
input int            MA_Period=13; // Ну или INPUT макрос
input int            MA_Shift=0;
#else
int            MA_Period=13;
int            MA_Shift=0;
#endif

#ifndef  VIM
mqlcpp_#import "user32.dll"
#endif
   int GetCursorPos(int ref point[]);
   int GetWindowRect(HWND hWnd, int ref rect[]);
#ifndef  VIM
mqlcpp_#import
#endif

add mqlcpp__ before the directives to the μl preprocessor, otherwise it will be handled by the first preprocessor. Include the headers from the std library as follows

#ifndef  VIM
mqlcpp_#include <Arrays/ArrayObj.mqh>
#endif

Why? They don't have include guards. If they are (three extra lines in each file), you can include them as usual.

2. Now you can dereference pointers in a normal way, not the way you want the MC to dereference them.

this->member;
pntr->field;

3. The same way with passing arrays into functions - you can now do it in a normal, generally accepted way

void fn(int ar[]);   // в топку &

4) Source code with utf-16 encoding will not work (it will be if the source code contains Cyrillic). But recoding in utf-8 is simple.

$ dos2unix file1 ...


Syntax is a plus, you can tell. Handy for porting to/from µl + means good support from clang side (autocomplete etc.).


ZS: as forum search in general is fire (forum search via search engine also not ace), will make a link to the latest version on the main page of my profile.


#vim_as_mql_ide_1

Files:
 

Plus. At the same time, I'll keep the topic at the top, maybe the developers will read it.

The point is that your editor is really lame (highlighting of all occurrences of a variable, auto-change of variable/function name throughout the project, search for all references to a variable, etc... well, look at any "adult" IDE and compare). The preprocessor seems to be there, but in fact it's a stump. As for templates, the same: non-type template-parameter absent, no possibility to specialize templates. Maybe you can plan a development in this direction sometime?

 
Vladimir Simakov:

Plus. I'll keep the topic on top too, maybe the developers will read it.

The point is that your editor is really cheesy (highlighting of all occurrences of a variable, automatic variable/function name substitution throughout the project, search for all references to a variable, etc., well, look at any "adult" IDE and compare). The preprocessor seems to be there, but in fact it is a stump. As for templates, the same: non-type template-parameter absent, no possibility to specialize templates. Maybe you can plan a development in this direction sometime?

Before you call it cheesy, be kind enough to write a list of all the editor's functionality.

And you will see that your statements are either outdated or completely wrong.

 
Renat Fatkhullin:

Before you call it cheesy, would you be kind enough to write a full list of the editor's functionality.

At the same time and you will see that your statements are either outdated or completely wrong.

Editor:


Highlight all occurrences of a variable (can someone tell me how to do this in the editor?):

Auto substitute variable/function name - that's what I mean:


Search for all references to a variable - I don't need just this file or all directory files in general, I need to show all references (analogous to Shift+F12 in MVS)

This is just from my observations.

The preprocessor and templates are a different story, but I'm right (I'll check the template specialisation again tonight), aren't I?
 
Make sure to add the 'Dark theme' (and colour setting in general) and github connectivity to the MetaEditor.
 
Renat Fatkhullin:

Before you call it cheesy, be kind enough to write the entire list of the editor's functionality.

And you will see that your statements are either outdated or completely wrong.

Are you serious? A simple template is beyond your editor's capabilities.

template <typename T>
class Qwerty
{
public:
   void func1() {}
};
...
Qwerty<int> qwerty;
qwerty.

And could it not be possible to add colour schemes for so many years (I'm interested in the dark one, I can't stand the light one)? And macros in vime, I can't live without them...

But I'm not here for the development of the editor, there are so many ready-made ones around, why reinvent.

 
How much code I've written in ME in 6 years of continuous programming in it! I've always liked it. I've tried other IDEs though. There's nothing extra there. And I really needed very little of it. That's why I don't support bloated claims. It all looks like a criticism of the ball by a team of football players)). (like wrong colour, bounces sadly...)
 

Guys, don't go all meta-editor on me, really.

Personally, I like it.

Well, this one's cool, too.

 
Vladimir Simakov:

Editor:


Highlighting of all occurrences of a variable (can someone tell me how to do this in the editor?):

Auto variable/function name substitution - that's what I mean:


Search for all references to a variable - I don't need just this file or all files in the directory in general, I need to show all references (analogous to Shift+F12 in MVS)

This is just from my observations.

The preprocessor and templates are a different story, but I'm right (I'll check the template specialisation again tonight), aren't I?

Is it possible to call "it" by hotkeys??? I think it's ctrl+h if at all. And your mother does not allow to press ctrl+h in mql editor? Before you make a complaint, try variants not described in the help.

But with the highlighting of all variables, I agree. Not a problem, but it's not fatal without it either. Just like I don't suffer without collapsing part of the code.

Here's another little tidbit: the "Forward/Backward" mouse keys work in the mql editor as they do in other applications.

 
Alexey Viktorov:

Is there a hotkey to call "it"??? I think it's ctrl+h if there is one at all. Doesn't your mother allow you to press ctrl+h in the mql editor? Before you make a complaint, try variants not described in the help.

But with the highlighting of all variables, I agree. Not a problem, but it's not fatal without it either. And I don't suffer without collapsing part of the code as well.

One more small tip: mouse buttons "Forward/Backward" work in mql editor as well as in other applications.

Only in the editor it will change only the current file, while I was talking about the whole project. Humor me, you named a method poorly, and it's in 90% of files in your library is called more than once, and the number of files is already tens. So yes, 5-10 minutes of rename work in all places, but when in other IDE you're doing it on the fly...
Reason: