Skip to content

Commit

Permalink
docs: fix broken/buggy lua examples (#943)
Browse files Browse the repository at this point in the history
* docs: fix lua syntax error

* docs: fix custom_areas example

Previously a new highlight was created and cached for each index.
For example when the result table only has a warning, an orange color
highlight will be created and cached for index 1. Then the user fixes
the warning but generates an error with index 1, the orange color will be
reused from the cache rather than creating a highlight for the
associated red color. Using an existing highlight with link will
avoid using that cache entirely.

* docs: fix sort_by function example

`buffer_a.modified` returned a bool rather than a number.
  • Loading branch information
gepbird authored Jul 18, 2024
1 parent 28e347d commit f98ede0
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions doc/bufferline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ The available configuration are:
},
sort_by = 'insert_after_current' |'insert_at_end' | 'id' | 'extension' | 'relative_directory' | 'directory' | 'tabs' | function(buffer_a, buffer_b)
-- add custom logic
return buffer_a.modified > buffer_b.modified
local modified_a = vim.fn.getftime(buffer_a.path)
local modified_b = vim.fn.getftime(buffer_b.path)
return modified_a > modified_b
end
}
}
Expand Down Expand Up @@ -484,7 +486,9 @@ are available to use using >lua
sort_by = function(buffer_a, buffer_b)
print(vim.inspect(buffer_a))
-- add custom logic
return buffer_a.modified > buffer_b.modified
local modified_a = vim.fn.getftime(buffer_a.path)
local modified_b = vim.fn.getftime(buffer_b.path)
return modified_a > modified_b
end
<

Expand Down Expand Up @@ -574,7 +578,7 @@ A user can also execute arbitrary functions against a buffer using the
function _G.bdel(num)
require('bufferline').exec(num, function(buf, visible_buffers)
vim.cmd('bdelete '..buf.id)
end
end)
end

vim.cmd [[
Expand Down Expand Up @@ -1127,19 +1131,19 @@ to be shown in a list of tables. For example:
local hint = #vim.diagnostic.get(0, {severity = seve.HINT})

if error ~= 0 then
table.insert(result, {text = "  " .. error, fg = "#EC5241"})
table.insert(result, {text = "  " .. error, link = "DiagnosticError"})
end

if warning ~= 0 then
table.insert(result, {text = "  " .. warning, fg = "#EFB839"})
table.insert(result, {text = "  " .. warning, link = "DiagnosticWarn"})
end

if hint ~= 0 then
table.insert(result, {text = "  " .. hint, fg = "#A3BA5E"})
table.insert(result, {text = "  " .. hint, link = "DiagnosticHint"})
end

if info ~= 0 then
table.insert(result, {text = "  " .. info, fg = "#7EA9A7"})
table.insert(result, {text = "  " .. info, link = "DiagnosticInfo"})
end
return result
end,
Expand Down

0 comments on commit f98ede0

Please sign in to comment.