All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
3 local global_settings = setmetatable({}, {
4 __index = function(_, key)
5 return vim.g['ale_' .. key]
7 __newindex = function(_, key, value)
8 vim.g['ale_' .. key] = value
12 local buffer_settings = setmetatable({}, {
13 __index = function(_, key)
14 return vim.b['ale_' .. key]
16 __newindex = function(_, key, value)
17 vim.b['ale_' .. key] = value
21 ale.set_global = function(c)
22 for key, value in pairs(c) do
23 global_settings[key] = value
27 ale.set_buffer = function(c)
28 for key, value in pairs(c) do
29 buffer_settings[key] = value
33 ---(when called) Set global ALE settings, just like ale.setup.global.
35 ---@field global fun(c: table): nil -- Set global ALE settings.
36 ---@field buffer fun(c: table): nil -- Set buffer-local ALE settings.
37 ---@overload fun(c: table): nil
39 ale.setup = setmetatable({
40 ---Set global ALE settings.
41 ---@param c table The table of ALE settings to set.
46 ---Set buffer-local ALE settings.
47 ---@param c table The table of ALE settings to set.
53 __call = function(self, c)
58 ---Run ALE linters on a buffer after a delay.
60 ---If a delay in milliseconds multiple times, the internal timer used by ALE
61 ---will be reset, so ALE doesn't lint too often.
63 ---If the `linting_flag` is not 'lint_file' then linters that require files to
64 ---be saved will no be run.
65 ---@param delay number Milliseconds to wait for. A delay of 0 lints immediately.
66 ---@param linting_flag string|nil If set to 'lint_file', run all linters.
67 ---@param buffer number|nil The buffer to check. Defaults to the current buffer.
69 ale.queue = function(delay, linting_flag, buffer)
70 vim.fn["ale#Queue"](delay, linting_flag, buffer)
73 ---Check if ALE supports a given feature.
75 ---The ALE version can be checked with ale.has("ale-1.0.0"), etc.
76 ---@param feature string The feature to test for.
77 ---@return boolean supported If the feature is supported.
78 ale.has = function(feature)
79 return vim.fn["ale#Has"](feature) == 1
82 ---Prefix a string with a single space if it is not empty.
83 ---nil will be treated the same as an empty string.
85 ---This function is a convenience for chaining options for commands together
86 ---without adding redundant whitespace.
87 ---@param str string|nil A value to pad with whitespace.
88 ---@return string padded A value padded with whitespace.
89 ale.pad = function(str)
90 if str == nil or str == "" then
97 ---Get an ALE variable for a buffer (first) or globally (second)
98 ---@param buffer number The buffer number to retreive the variable for.
99 ---@param variable_name string The variable to retrieve.
100 ---@return any value The value for the ALE variable
101 ale.var = function(buffer, variable_name)
102 variable_name = "ale_" .. variable_name
103 local exists, value = pcall(vim.api.nvim_buf_get_var, buffer, variable_name)
109 return vim.g[variable_name]
112 ---Escape a string for use in a shell command
113 ---@param str string The string to escape.
114 ---@return string escaped The escaped string.
115 ale.escape = function(str)
116 local shell = vim.fn.fnamemodify(vim.o.shell, ":t")
118 if shell:lower() == "cmd.exe" then
121 if str:find(" ") then
122 step1 = '"' .. str:gsub('"', '""') .. '"'
124 step1 = str:gsub("([&|<>^])", "^%1")
127 local percent_subbed = step1:gsub("%%", "%%%%")
129 return percent_subbed
132 return vim.fn.shellescape(str)
135 ---Create a prefix for a shell command for adding environment variables.
136 ---@param variable_name string The environment variable name.
137 ---@param value string The value to set for the environment variable.
138 ---@return string prefix The shell code for prefixing a command.
139 ale.env = function(variable_name, value)
140 if vim.fn.has("win32") then
141 return "set " .. ale.escape(variable_name .. "=" .. value) .. " && "
144 return variable_name .. "=" .. ale.escape(value) .. " "
147 ---Get an array of arrays for mapping paths to and from filesystems for an ALE
148 ---linter, as configured in the `filename_mappings` setting.
150 ---The result can be used to instruct ALE how to map between filesystems.
151 ---@param buffer number The buffer number.
152 ---@param name string The linter name.
153 ---@return table mappings An array of arrays for mapping filenames.
154 ale.get_filename_mappings = function(buffer, name)
155 local linter_mappings = ale.var(buffer, "filename_mappings")
157 if linter_mappings[1] ~= nil then
158 return linter_mappings
161 if linter_mappings[name] == nil then
165 return linter_mappings[name] or {}