neomutt: support list in binds.map (#1885)

* neomutt: support list in binds.map
Closes #1245

Adds support for specifying programs.neomutt.binds[].map as a list. If
specified as a list, then the binds will be concatenated with a ",".

* neomutt: add deprecation warning for (binds|macros).map as string
Added note that specifying 'programs.neomutt.(binds|macros).map' as a string is deprecated. Instead, use the list form.

* neomutt: note deprecation warning in release notes
Added note that specifying 'programs.neomutt.(binds|macros).map' as a
single string is deprecated in favor of specifying it as a list

* neomutt: add assertion that map is not empty
Added an assertion that each 'programs.neomutt.(binds|macros).map' list contains at least one element.
This commit is contained in:
Sumner Evans 2021-04-03 17:47:40 -06:00 committed by GitHub
parent 6e3d93d7cc
commit 25a6a6d298
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 247 additions and 19 deletions

View file

@ -129,6 +129,10 @@ https://github.com/jonls/redshift/blob/master/redshift.conf.sample[redshift.conf
https://gitlab.com/chinstrap/gammastep/-/blob/master/gammastep.conf.sample[gammastep.conf.sample]
for the available additional options in each program.
* Specifying `programs.neomutt.binds.map` or `programs.neomutt.macros.map` as a
single string is now deprecated in favor of specfiying it as a list of
strings.
* The `programs.neovim.configure` is deprecated in favor of other `programs.neovim` options;
please use the other options at your disposal:
+

View file

@ -54,21 +54,23 @@ let
bindModule = types.submodule {
options = {
map = mkOption {
type = types.enum [
"alias"
"attach"
"browser"
"compose"
"editor"
"generic"
"index"
"mix"
"pager"
"pgp"
"postpone"
"query"
"smime"
];
type = let
menus = [
"alias"
"attach"
"browser"
"compose"
"editor"
"generic"
"index"
"mix"
"pager"
"pgp"
"postpone"
"query"
"smime"
];
in with types; either (enum menus) (listOf (enum menus));
default = "index";
description = "Select the menu to bind the command to.";
};
@ -154,11 +156,16 @@ let
set sidebar_format = '${cfg.sidebar.format}'
'';
bindSection = concatMapStringsSep "\n"
(bind: ''bind ${bind.map} ${bind.key} "${bind.action}"'') cfg.binds;
genBindMapper = bindType:
concatMapStringsSep "\n" (bind:
''
${bindType} ${
concatStringsSep "," (toList bind.map)
} ${bind.key} "${bind.action}"'');
macroSection = concatMapStringsSep "\n"
(bind: ''macro ${bind.map} ${bind.key} "${bind.action}"'') cfg.macros;
bindSection = (genBindMapper "bind") cfg.binds;
macroSection = (genBindMapper "macro") cfg.macros;
mailCheckSection = ''
set mail_check_stats
@ -316,5 +323,19 @@ in {
source ${accountFilename primary}
'';
};
assertions = [{
assertion =
((filter (b: (length (toList b.map)) == 0) (cfg.binds ++ cfg.macros))
== [ ]);
message =
"The 'programs.neomutt.(binds|macros).map' list must contain at least one element.";
}];
warnings =
let hasOldBinds = binds: (filter (b: !(isList b.map)) binds) != [ ];
in mkIf (hasOldBinds (cfg.binds ++ cfg.macros)) [
"Specifying 'programs.neomutt.(binds|macros).map' as a string is deprecated, use a list of strings instead. See https://github.com/nix-community/home-manager/pull/1885."
];
};
}

View file

@ -2,4 +2,8 @@
neomutt-simple = ./neomutt.nix;
neomutt-with-msmtp = ./neomutt-with-msmtp.nix;
neomutt-not-primary = ./neomutt-not-primary.nix;
neomutt-with-binds = ./neomutt-with-binds.nix;
neomutt-with-binds-with-warning = ./neomutt-with-binds-with-warning.nix;
neomutt-with-binds-invalid-settings =
./neomutt-with-binds-invalid-settings.nix;
}

View file

@ -0,0 +1,34 @@
# Generated by Home Manager.
set header_cache = "/home/hm-user/.cache/neomutt/headers/"
set message_cachedir = "/home/hm-user/.cache/neomutt/messages/"
set editor = "$EDITOR"
set implicit_autoview = yes
alternative_order text/enriched text/plain text
set delete = yes
# Binds
bind editor <Tab> "complete-query"
bind index,pager \Cp "sidebar-prev"
# Macros
macro index s "<save-message>?<tab>"
macro index,pager c "<change-folder>?<change-dir><home>^K=<enter><tab>"
# Extra configuration
# Register accounts
# register account hm@example.com
mailboxes "/home/hm-user/Mail/hm@example.com/Inbox"
folder-hook /home/hm-user/Mail/hm@example.com/ " \
source /home/hm-user/.config/neomutt/hm@example.com "
# Source primary account
source /home/hm-user/.config/neomutt/hm@example.com

View file

@ -0,0 +1,27 @@
{ config, lib, pkgs, ... }:
with lib;
{
config = {
programs.neomutt = {
enable = true;
binds = [{
action = "complete-query";
key = "<Tab>";
map = [ ];
}];
macros = [{
action = "<change-folder>?<change-dir><home>^K=<enter><tab>";
key = "c";
map = [ ];
}];
};
test.asserts.assertions.expected = [
"The 'programs.neomutt.(binds|macros).map' list must contain at least one element."
];
};
}

View file

@ -0,0 +1,71 @@
{ config, lib, pkgs, ... }:
with lib;
{
imports = [ ../../accounts/email-test-accounts.nix ];
config = {
accounts.email.accounts = {
"hm@example.com" = {
notmuch.enable = true;
neomutt = {
enable = true;
extraConfig = ''
color status cyan default
'';
};
imap.port = 993;
};
};
programs.neomutt = {
enable = true;
vimKeys = false;
binds = [
{
action = "complete-query";
key = "<Tab>";
map = "editor";
}
{
action = "sidebar-prev";
key = "\\Cp";
map = [ "index" "pager" ];
}
];
macros = [
{
action = "<save-message>?<tab>";
key = "s";
map = "index";
}
{
action = "<change-folder>?<change-dir><home>^K=<enter><tab>";
key = "c";
map = [ "index" "pager" ];
}
];
};
nixpkgs.overlays =
[ (self: super: { neomutt = pkgs.writeScriptBin "dummy-neomutt" ""; }) ];
test.asserts.warnings.expected = [
"Specifying 'programs.neomutt.(binds|macros).map' as a string is deprecated, use a list of strings instead. See https://github.com/nix-community/home-manager/pull/1885."
];
nmt.script = ''
assertFileExists home-files/.config/neomutt/neomuttrc
assertFileExists home-files/.config/neomutt/hm@example.com
assertFileContent home-files/.config/neomutt/neomuttrc ${
./neomutt-with-binds-expected.conf
}
assertFileContent home-files/.config/neomutt/hm@example.com ${
./hm-example.com-expected
}
'';
};
}

View file

@ -0,0 +1,67 @@
{ config, lib, pkgs, ... }:
with lib;
{
imports = [ ../../accounts/email-test-accounts.nix ];
config = {
accounts.email.accounts = {
"hm@example.com" = {
notmuch.enable = true;
neomutt = {
enable = true;
extraConfig = ''
color status cyan default
'';
};
imap.port = 993;
};
};
programs.neomutt = {
enable = true;
vimKeys = false;
binds = [
{
action = "complete-query";
key = "<Tab>";
map = [ "editor" ];
}
{
action = "sidebar-prev";
key = "\\Cp";
map = [ "index" "pager" ];
}
];
macros = [
{
action = "<save-message>?<tab>";
key = "s";
map = [ "index" ];
}
{
action = "<change-folder>?<change-dir><home>^K=<enter><tab>";
key = "c";
map = [ "index" "pager" ];
}
];
};
nixpkgs.overlays =
[ (self: super: { neomutt = pkgs.writeScriptBin "dummy-neomutt" ""; }) ];
nmt.script = ''
assertFileExists home-files/.config/neomutt/neomuttrc
assertFileExists home-files/.config/neomutt/hm@example.com
assertFileContent home-files/.config/neomutt/neomuttrc ${
./neomutt-with-binds-expected.conf
}
assertFileContent home-files/.config/neomutt/hm@example.com ${
./hm-example.com-expected
}
'';
};
}