zyedidia / micro

A modern and intuitive terminal-based text editor
https://micro-editor.github.io
MIT License
24.9k stars 1.17k forks source link

Changing default linter behaviour #3408

Open BenWeisz opened 2 months ago

BenWeisz commented 2 months ago

Modifying default linter behaviour for C files

Problem

For projects configured with cmake, include paths using #include directives need not contain a direct path to the H files being included. This is possible because we can configure include directories for project layout. When I hit save the linter plugin runs and if I'm editing a C file the linter fails on the H files since it can't find their location.

I'm just curious if anyone knows how I could edit the linter script without rebuilding the editor (I believe I installed micro through homebrew for my mac). My thinking is that I could just have the linter call make with the target object file.

Thanks!

Platform: MacOS, installed via homebrew

Andriamanitra commented 2 months ago

The linter is a built-in Lua plugin ^1 that runs external programs. You can read an explanation of how to configure it with the help linter command ^2. Essentially you just need to put something like this in your ~/.config/micro/init.lua (this is just the default configuration for C, adjust it to fit your needs):

function init()
    linter.makeLinter("gcc", "c", "gcc", {"-fsyntax-only", "-Wall", "-Wextra", "%f"}, "%f:%l:%c:.+: %m")
end