mirror of
https://github.com/NotAShelf/neovim-flake.git
synced 2025-12-20 05:50:11 +01:00
Simplified pdfViewer configuration implementation
This commit is contained in:
parent
0da99e05ae
commit
0e3fc249f6
6 changed files with 178 additions and 216 deletions
|
|
@ -13,7 +13,7 @@ in {
|
|||
imports = [
|
||||
./build
|
||||
./lsp
|
||||
./pdfViewer
|
||||
./pdfViewer.nix
|
||||
./treesitter.nix
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@
|
|||
builderCfg = cfg.build.builder;
|
||||
|
||||
# Get the enabled pdf viewer.
|
||||
pdfViewer = import ../pdfViewer/getEnabledPdfViewer.nix {inherit lib config;};
|
||||
pdfViewer = cfg.pdfViewer.viewers.${cfg.pdfViewer.name};
|
||||
in {
|
||||
options.vim.languages.tex.lsp.texlab = {
|
||||
enable = mkBool config.vim.lsp.enable ''
|
||||
|
|
|
|||
176
modules/plugins/languages/tex/pdfViewer.nix
Normal file
176
modules/plugins/languages/tex/pdfViewer.nix
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (builtins) toString;
|
||||
inherit (lib) attrNames mkEnableOption mkDefault;
|
||||
inherit (lib.options) mkOption;
|
||||
inherit (lib.strings) concatStringsSep;
|
||||
inherit (lib.types) str package listOf enum;
|
||||
|
||||
cfg = config.vim.languages.tex;
|
||||
|
||||
# **===============================================**
|
||||
# || <<<<< Default Viewers >>>>> ||
|
||||
# **===============================================**
|
||||
|
||||
viewers = let
|
||||
mkPdfViewerDefaults = {
|
||||
package,
|
||||
executable,
|
||||
args ? [],
|
||||
}: {
|
||||
package = mkDefault package;
|
||||
executable = mkDefault executable;
|
||||
args = mkDefault args;
|
||||
};
|
||||
in {
|
||||
okular = mkPdfViewerDefaults {
|
||||
package = pkgs.kdePackages.okular;
|
||||
executable = "okular";
|
||||
args = [
|
||||
"--unique"
|
||||
"file:%p#src:%l%f"
|
||||
];
|
||||
};
|
||||
|
||||
sioyek = mkPdfViewerDefaults {
|
||||
package = pkgs.sioyek;
|
||||
executable = "sioyek";
|
||||
args = [
|
||||
"--reuse-window"
|
||||
"--execute-command"
|
||||
"toggle_synctex"
|
||||
"--inverse-search"
|
||||
"texlab inverse-search -i \"%%1\" -l %%2"
|
||||
"--forward-search-file"
|
||||
"%f"
|
||||
"--forward-search-line"
|
||||
"%l"
|
||||
"%p"
|
||||
];
|
||||
};
|
||||
|
||||
qpdfview = mkPdfViewerDefaults {
|
||||
package = pkgs.qpdfview;
|
||||
executable = "qpdfview";
|
||||
args = [
|
||||
"--unique"
|
||||
"%p#src:%f:%l:1"
|
||||
];
|
||||
};
|
||||
|
||||
zathura = mkPdfViewerDefaults {
|
||||
package = pkgs.zathura;
|
||||
executable = "zathura";
|
||||
args = [
|
||||
"--synctex-forward"
|
||||
"%l:1:%f"
|
||||
"%p"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
# **====================================================**
|
||||
# || <<<<< PDF Viewer Submodule >>>>> ||
|
||||
# **====================================================**
|
||||
|
||||
pdfViewer = {name, ...}: {
|
||||
options = {
|
||||
name = mkOption {
|
||||
type = str;
|
||||
example = "okular";
|
||||
description = ''
|
||||
The name of the pdf viewer to use.
|
||||
|
||||
This value will be automatically set when any of the viewers are
|
||||
enabled.
|
||||
|
||||
This value will be automatically set to the value of the parent
|
||||
attribute set. ex. `...tex.pdfViewer.viewers.<name>.name = "$${name}"`
|
||||
This value cannot, and should not, be changed to be different from this
|
||||
parent value.
|
||||
|
||||
Default values already exist such as `...tex.pdfViewer.okular` but
|
||||
you can override the default values or created completely custom
|
||||
pdf viewers should you wish.
|
||||
'';
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = package;
|
||||
example = pkgs.kdePackages.okular;
|
||||
description = "The package of the pdf viewer to use.";
|
||||
};
|
||||
|
||||
executable = mkOption {
|
||||
type = str;
|
||||
default = "${toString name}";
|
||||
description = ''
|
||||
The executable for the pdf viewer to use.
|
||||
|
||||
It will be called as `<package_path>/bin/<executable>`.
|
||||
|
||||
By default, the name of the pdf viewer will be used.
|
||||
'';
|
||||
};
|
||||
|
||||
args = mkOption {
|
||||
type = listOf str;
|
||||
default = [];
|
||||
description = ''
|
||||
The command line arguments to use when calling the pdf viewer command.
|
||||
|
||||
These will be called as
|
||||
`<package_path>/bin/<executable> <arg1> <arg2> ...`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# The name of the pdf viewer must be set to the parent attribute set name.
|
||||
config.name = lib.mkForce name;
|
||||
};
|
||||
in {
|
||||
# **==================================================**
|
||||
# || <<<<< PDF Viewer Options >>>>> ||
|
||||
# **==================================================**
|
||||
|
||||
options.vim.languages.tex.pdfViewer = {
|
||||
enable = mkEnableOption "PDF viewer for TeX";
|
||||
|
||||
name = mkOption {
|
||||
type = enum (attrNames cfg.pdfViewer.viewers);
|
||||
default = "okular";
|
||||
description = ''
|
||||
The PDF viewer chosen to view compiled TeX documents.
|
||||
|
||||
Must be one of the names of the PDF viewers configured in
|
||||
`vim.languages.tex.pdfViewer.viewers`, or one of the default configured
|
||||
viewers: ${concatStringsSep ", " (attrNames cfg.pdfViewer.viewers)}.
|
||||
'';
|
||||
};
|
||||
|
||||
viewers = mkOption {
|
||||
type = with lib.types; attrsOf (submodule pdfViewer);
|
||||
default = {};
|
||||
example = {
|
||||
customOkular = {
|
||||
package = pkgs.kdePackages.okular;
|
||||
executable = "okular";
|
||||
args = [
|
||||
"--unique"
|
||||
"file:%p#src:%l%f"
|
||||
];
|
||||
};
|
||||
};
|
||||
description = ''
|
||||
Define the PDF viewers that can be used for viewing compiled tex documents.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# Set the default pdf viewers.
|
||||
config.vim.languages.tex.pdfViewer.viewers = viewers;
|
||||
}
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption;
|
||||
inherit (lib.types) str package listOf;
|
||||
|
||||
cfg = config.vim.languages.tex;
|
||||
|
||||
pdfViewer = {name, ...}: {
|
||||
options = {
|
||||
enable = lib.mkEnableOption "${builtins.toString name} pdf viewer";
|
||||
|
||||
name = mkOption {
|
||||
type = str;
|
||||
example = "okular";
|
||||
description = ''
|
||||
The name of the pdf viewer to use.
|
||||
|
||||
This value will be automatically set when any of the viewers are
|
||||
enabled.
|
||||
|
||||
This value will be automatically set to the value of the parent
|
||||
attribute set. ex. `...tex.pdfViewer.<name>.name = "$${name}"`
|
||||
This value cannot and should not be changed to be different from this
|
||||
parent value.
|
||||
|
||||
Default values already exist such as `...tex.pdfViewer.okular` but
|
||||
you can override the default values or created completely custom
|
||||
pdf viewers should you wish.
|
||||
'';
|
||||
};
|
||||
|
||||
package = mkOption {
|
||||
type = package;
|
||||
example = pkgs.kdePackages.okular;
|
||||
description = "The package of the pdf viewer to use.";
|
||||
};
|
||||
|
||||
executable = mkOption {
|
||||
type = str;
|
||||
default = "${builtins.toString name}";
|
||||
description = ''
|
||||
The executable for the pdf viewer to use.
|
||||
|
||||
It will be called as `<package_path>/bin/<executable>`.
|
||||
|
||||
By default, the name of the pdf viewer will be used.
|
||||
'';
|
||||
};
|
||||
|
||||
args = mkOption {
|
||||
type = listOf str;
|
||||
default = [];
|
||||
description = ''
|
||||
The command line arguments to use when calling the pdf viewer command.
|
||||
|
||||
These will be called as
|
||||
`<package_path>/bin/<executable> <arg1> <arg2> ...`.
|
||||
'';
|
||||
};
|
||||
};
|
||||
|
||||
# The name of the pdf viewer must be set to the parent attribute set name.
|
||||
config.name = lib.mkForce name;
|
||||
};
|
||||
in {
|
||||
imports = [
|
||||
./premadePdfViewers.nix
|
||||
];
|
||||
|
||||
options.vim.languages.tex.pdfViewer = mkOption {
|
||||
type = with lib.types; attrsOf (submodule pdfViewer);
|
||||
default = {};
|
||||
example = {
|
||||
zathura.enable = true;
|
||||
|
||||
customOkular = {
|
||||
enable = false;
|
||||
package = pkgs.kdePackages.okular;
|
||||
executable = "okular";
|
||||
args = [
|
||||
"--unique"
|
||||
"file:%p#src:%l%f"
|
||||
];
|
||||
};
|
||||
};
|
||||
description = ''
|
||||
Define the pdf viewer to use for viewing compiled tex documents.
|
||||
'';
|
||||
};
|
||||
|
||||
config = let
|
||||
# List form of all pdf viewers.
|
||||
pdfViewers = builtins.attrValues cfg.pdfViewer;
|
||||
|
||||
countPdfViewers = viewers: (lib.lists.count (x: x.enable) viewers);
|
||||
in {
|
||||
assertions = [
|
||||
{
|
||||
# Assert that there is only one enabled pdf viewer.
|
||||
assertion = (countPdfViewers pdfViewers) < 2;
|
||||
message = ''
|
||||
The nvf-tex-language implementation does not support having more than
|
||||
1 pdf viewers enabled.
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
# The attribute set of pdf viewers in this configuration.
|
||||
pdfViewers = config.vim.languages.tex.pdfViewer;
|
||||
|
||||
# The list of pdf viewers in this configuration.
|
||||
pdfViewersList = builtins.attrValues pdfViewers;
|
||||
|
||||
# The list of enabled pdf viewers.
|
||||
enabledPdfViewersList = builtins.filter (x: x.enable) pdfViewersList;
|
||||
|
||||
# The number of enabled pdf viewers.
|
||||
enabledPdfViewersCount = lib.lists.count (x: x.enable) pdfViewersList;
|
||||
in
|
||||
if (enabledPdfViewersCount == 0)
|
||||
# Use the fallback if no pdf viewer was enabled.
|
||||
then pdfViewers.fallback
|
||||
# Otherwise get the first enabled viewer.
|
||||
else builtins.head enabledPdfViewersList
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib) mkDefault mkForce;
|
||||
|
||||
mkPdfViewerDefaults = {
|
||||
package,
|
||||
executable,
|
||||
args ? [],
|
||||
}: {
|
||||
package = mkDefault package;
|
||||
executable = mkDefault executable;
|
||||
args = mkDefault args;
|
||||
};
|
||||
in {
|
||||
config.vim.languages.tex.pdfViewer = {
|
||||
okular = mkPdfViewerDefaults {
|
||||
package = pkgs.kdePackages.okular;
|
||||
executable = "okular";
|
||||
args = [
|
||||
"--unique"
|
||||
"file:%p#src:%l%f"
|
||||
];
|
||||
};
|
||||
|
||||
sioyek = mkPdfViewerDefaults {
|
||||
package = pkgs.sioyek;
|
||||
executable = "sioyek";
|
||||
args = [
|
||||
"--reuse-window"
|
||||
"--execute-command"
|
||||
"toggle_synctex"
|
||||
"--inverse-search"
|
||||
"texlab inverse-search -i \"%%1\" -l %%2"
|
||||
"--forward-search-file"
|
||||
"%f"
|
||||
"--forward-search-line"
|
||||
"%l"
|
||||
"%p"
|
||||
];
|
||||
};
|
||||
|
||||
qpdfview = mkPdfViewerDefaults {
|
||||
package = pkgs.qpdfview;
|
||||
executable = "qpdfview";
|
||||
args = [
|
||||
"--unique"
|
||||
"%p#src:%f:%l:1"
|
||||
];
|
||||
};
|
||||
|
||||
zathura = mkPdfViewerDefaults {
|
||||
package = pkgs.zathura;
|
||||
executable = "zathura";
|
||||
args = [
|
||||
"--synctex-forward"
|
||||
"%l:1:%f"
|
||||
"%p"
|
||||
];
|
||||
};
|
||||
|
||||
# This is a special pdf viewer. It is force set to a basic and known
|
||||
# working configuration of okular and is used where needed in the
|
||||
# rest of the tex language configuration encase no other pdf viewer
|
||||
# was enabled.
|
||||
# It cannot be enabled on its own and exists purely as a fallback
|
||||
# option for internal use.
|
||||
fallback = {
|
||||
enable = mkForce false;
|
||||
package = mkForce pkgs.kdePackages.okular;
|
||||
executable = mkForce "okular";
|
||||
args = mkForce [
|
||||
"--unique"
|
||||
"file:%p#src:%l%f"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue