Skip to content

Commit

Permalink
plugins/hex: init
Browse files Browse the repository at this point in the history
  • Loading branch information
GaetanLepage committed Sep 9, 2024
1 parent 1d6afdb commit ffa9b8f
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
45 changes: 45 additions & 0 deletions plugins/by-name/hex/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{ lib, pkgs, ... }:
let
inherit (lib.nixvim) defaultNullOpts mkNullOrLuaFn;
in
lib.nixvim.neovim-plugin.mkNeovimPlugin {
name = "hex";
originalName = "hex.nvim";
package = "hex-nvim";

maintainers = [ lib.maintainers.GaetanLepage ];

extraOptions = {
xxdPackage = lib.mkPackageOption pkgs [
"unixtools"
"xxd"
] { nullable = true; };
};

extraConfig = cfg: { extraPackages = [ cfg.xxdPackage ]; };

settingsOptions = {
dump_cmd = defaultNullOpts.mkStr "xxd -g 1 -u" ''
cli command used to dump hex data.
'';

assemble_cmd = defaultNullOpts.mkStr "xxd -r" ''
cli command used to dump hex data.
'';

is_buf_binary_pre_read = mkNullOrLuaFn ''
Function that runs on `BufReadPre` to determine if it's binary or not.
It should return a boolean value.
'';

is_buf_binary_post_read = mkNullOrLuaFn ''
Function that runs on `BufReadPost` to determine if it's binary or not.
It should return a boolean value.
'';
};

settingsExample = {
dump_cmd = "xxd -g 1 -u";
assemble_cmd = "xxd -r";
};
}
38 changes: 38 additions & 0 deletions tests/test-sources/plugins/by-name/hex/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
empty = {
plugins.hex.enable = true;
};

defaults = {
plugins.hex = {
enable = true;

settings = {
dump_cmd = "xxd -g 1 -u";
assemble_cmd = "xxd -r";
is_buf_binary_pre_read.__raw = ''
function()
binary_ext = { 'out', 'bin', 'png', 'jpg', 'jpeg', 'exe', 'dll' }
-- only work on normal buffers
if vim.bo.ft ~= "" then return false end
-- check -b flag
if vim.bo.bin then return true end
-- check ext within binary_ext
local filename = vim.fn.expand('%:t')
local ext = vim.fn.expand('%:e')
if vim.tbl_contains(binary_ext, ext) then return true end
-- none of the above
return false
end
'';
is_buf_binary_post_read.__raw = ''
function()
local encoding = (vim.bo.fenc ~= "" and vim.bo.fenc) or vim.o.enc
if encoding ~= 'utf-8' then return true end
return false
end
'';
};
};
};
}

0 comments on commit ffa9b8f

Please sign in to comment.