option defaultEditor: Set {env}VISUAL on true (#8322)

The defaultEditor option sets {env}`EDITOR` however strictly speaking
{env}`EDITOR` is intended for editors that are fully compatible with
teletype terminals (ex: `ed` or `vi`'s `ex` mode).

The {env}`VISUAL variable is intended for modern "visual mode"
terminal editors (ex: `vi` or `emacs`).

Technically speaking editors that are assigned to {env}`EDITOR` should
be configured to operate in teletype compatible mode (see `vi -e` and
`vim -e`).

We don't do this currently because for most users this would be
unintuitive behavior when a script or program mistakenly checks
{env}`EDITOR` instead of first checking {env}`VISUAL`.

In the future it may be worthwhile to introduce an additional option to
these modules to configure {env}`EDITOR` in a strictly conforming manner
(i.e. using the teletype/`ex` mode flags or unsetting {env}`EDITOR`
entirely).

Related Issue: #8314

Signed-off-by: Jacob Abel <jacobabel@nullpo.dev>
This commit is contained in:
Jacob Abel 2025-12-11 14:04:13 -05:00 committed by GitHub
parent 9b5ac85d79
commit 0cf525a5be
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 14 deletions

View file

@ -49,7 +49,8 @@ in
default = false;
description = ''
Whether to configure {command}`hx` as the default
editor using the {env}`EDITOR` environment variable.
editor using the {env}`EDITOR` and {env}`VISUAL`
environment variables.
'';
};
@ -225,7 +226,10 @@ in
else
[ cfg.package ];
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "hx"; };
home.sessionVariables = mkIf cfg.defaultEditor {
EDITOR = "hx";
VISUAL = "hx";
};
xdg.configFile =
let

View file

@ -705,7 +705,8 @@ in
default = false;
description = ''
Whether to configure {command}`kak` as the default
editor using the {env}`EDITOR` environment variable.
editor using the {env}`EDITOR` and {env}`VISUAL`
environment variables.
'';
};
@ -755,7 +756,10 @@ in
programs.kakoune.finalPackage = lib.mkIf (cfg.package != null) kakouneWithPlugins;
home.packages = lib.mkIf (cfg.finalPackage != null) [ cfg.finalPackage ];
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "kak"; };
home.sessionVariables = mkIf cfg.defaultEditor {
EDITOR = "kak";
VISUAL = "kak";
};
xdg.configFile = lib.mkMerge [
{ "kak/kakrc".source = configFile; }
(mkIf (cfg.colorSchemePackage != null) {

View file

@ -289,7 +289,8 @@ in
default = false;
description = ''
Whether to configure {command}`nvim` as the default
editor using the {env}`EDITOR` environment variable.
editor using the {env}`EDITOR` and {env}`VISUAL`
environment variables.
'';
};
@ -453,7 +454,10 @@ in
home.packages = [ cfg.finalPackage ];
home.sessionVariables = mkIf cfg.defaultEditor { EDITOR = "nvim"; };
home.sessionVariables = mkIf cfg.defaultEditor {
EDITOR = "nvim";
VISUAL = "nvim";
};
home.shellAliases = mkIf cfg.vimdiffAlias { vimdiff = "nvim -d"; };

View file

@ -162,7 +162,8 @@ in
default = false;
description = ''
Whether to configure {command}`vim` as the default
editor using the {env}`EDITOR` environment variable.
editor using the {env}`EDITOR` and {env}`VISUAL`
environment variables.
'';
};
};
@ -213,7 +214,10 @@ in
home.packages = [ cfg.package ];
home.sessionVariables = lib.mkIf cfg.defaultEditor { EDITOR = "vim"; };
home.sessionVariables = lib.mkIf cfg.defaultEditor {
EDITOR = "vim";
VISUAL = "vim";
};
programs.vim = {
package = vim;

View file

@ -113,7 +113,8 @@ in
example = !default;
description = ''
Whether to configure {command}`emacsclient` as the default
editor using the {env}`EDITOR` environment variable.
editor using the {env}`EDITOR` and {env}`VISUAL`
environment variables.
'';
};
};
@ -121,11 +122,16 @@ in
config = mkIf cfg.enable (
lib.mkMerge [
{
home.sessionVariables = mkIf cfg.defaultEditor {
EDITOR = lib.getBin (
pkgs.writeShellScript "editor" ''exec ${lib.getBin cfg.package}/bin/emacsclient "''${@:---create-frame}"''
);
};
home.sessionVariables =
let
editorBin = lib.getBin (
pkgs.writeShellScript "editor" ''exec ${lib.getBin cfg.package}/bin/emacsclient "''${@:---create-frame}"''
);
in
mkIf cfg.defaultEditor {
EDITOR = editorBin;
VISUAL = editorBin;
};
}
(mkIf pkgs.stdenv.isLinux {