From b9a2628e46404e8c7f155626cb7954019713b6f7 Mon Sep 17 00:00:00 2001 From: Gaetan Lepage Date: Fri, 1 Mar 2024 14:35:07 +0100 Subject: [PATCH] plugins/startify: switch to settings option --- plugins/default.nix | 2 +- plugins/utils/startify.nix | 237 ----------------- plugins/utils/startify/default.nix | 104 ++++++++ plugins/utils/startify/options.nix | 406 +++++++++++++++++++++++++++++ 4 files changed, 511 insertions(+), 238 deletions(-) delete mode 100644 plugins/utils/startify.nix create mode 100644 plugins/utils/startify/default.nix create mode 100644 plugins/utils/startify/options.nix diff --git a/plugins/default.nix b/plugins/default.nix index 5fbecc49..434a031c 100644 --- a/plugins/default.nix +++ b/plugins/default.nix @@ -171,7 +171,7 @@ ./utils/smart-splits.nix ./utils/specs.nix ./utils/spider.nix - ./utils/startify.nix + ./utils/startify ./utils/startup.nix ./utils/surround.nix ./utils/tmux-navigator.nix diff --git a/plugins/utils/startify.nix b/plugins/utils/startify.nix deleted file mode 100644 index 6edf8062..00000000 --- a/plugins/utils/startify.nix +++ /dev/null @@ -1,237 +0,0 @@ -{ - lib, - config, - helpers, - pkgs, - ... -}: -with lib; -with helpers.vim-plugin; - mkVimPlugin config { - name = "startify"; - originalName = "vim-startify"; - defaultPackage = pkgs.vimPlugins.vim-startify; - globalPrefix = "startify_"; - deprecateExtraConfig = true; - - maintainers = [maintainers.GaetanLepage]; - - options = { - sessionDir = mkDefaultOpt { - description = "Directory to save/load session"; - global = "session_dir"; - type = types.str; - }; - - lists = mkDefaultOpt { - description = "Startify display lists. If it's a string, it'll be interpreted as literal lua code"; - global = "lists"; - type = types.listOf (types.oneOf [ - (types.submodule { - options = { - type = mkOption { - type = types.str; - description = "The type of the list"; - }; - # TODO the header should be a literal lua string! - header = mkOption { - type = types.nullOr (types.listOf types.str); - description = "Optional header. It's a list of strings"; - default = null; - }; - indices = mkOption { - type = types.nullOr (types.listOf types.str); - description = "Optional indices for the current list"; - default = null; - }; - }; - }) - types.str - ]); - - value = val: let - list = map (v: - if builtins.isAttrs v - then toLuaObject v - else v) - val; - in - "{" + (concatStringsSep "," list) + "}"; - }; - - bookmarks = mkDefaultOpt { - description = "A list of files or directories to bookmark."; - global = "bookmarks"; - type = with types; listOf (oneOf [str (attrsOf str)]); - }; - - commands = mkDefaultOpt { - description = "A list of commands to execute on selection"; - global = "commands"; - type = with types; listOf (oneOf [str (listOf str) attrs]); - }; - - filesNumber = mkDefaultOpt { - description = "The number of files to list"; - global = "files_number"; - type = types.int; - }; - - updateOldFiles = mkDefaultOpt { - description = "Update v:oldfiles on-the-fly, so that :Startify is always up-to-date"; - global = "update_oldfiles"; - type = types.bool; - }; - - sessionAutoload = mkDefaultOpt { - description = "Load Session.vim"; - global = "session_autoload"; - type = types.bool; - }; - - sessionBeforeSave = mkDefaultOpt { - description = "Commands to be executed before saving a session"; - global = "session_before_save"; - type = types.listOf types.str; - }; - - sessionPersistence = mkDefaultOpt { - description = "Automatically update sessions"; - global = "session_persistence"; - type = types.bool; - }; - - sessionDeleteBuffers = mkDefaultOpt { - description = "Delete all buffers when loading or closing a session"; - global = "session_delete_buffers"; - type = types.bool; - }; - - changeToDir = mkDefaultOpt { - description = "When opening a file or bookmark, change to its directory"; - global = "change_to_dir"; - type = types.bool; - }; - - changeToVcsRoot = mkDefaultOpt { - description = "When opening a file or bookmark, change to the root directory of the VCS"; - global = "change_to_vcs_root"; - type = types.bool; - }; - - changeCmd = mkDefaultOpt { - description = "The default command for switching directories"; - global = "change_cmd"; - type = types.enum ["cd" "lcd" "tcd"]; - }; - - skipList = mkDefaultOpt { - description = "A list of regexes that is used to filter recently used files"; - global = "skiplist"; - type = types.listOf types.str; - }; - - useUnicode = mkDefaultOpt { - description = "Use unicode box drawing characters for the fortune header"; - global = "fortune_use_unicode"; - type = types.bool; - }; - - paddingLeft = mkDefaultOpt { - description = "Number of spaces used for left padding"; - global = "padding_left"; - type = types.int; - }; - - skipListServer = mkDefaultOpt { - description = "Do not create the startify buffer if this is a Vim server instance with a name contained in this list"; - global = "skiplist_server"; - type = types.listOf types.str; - }; - - enableSpecial = mkDefaultOpt { - description = "Show <empty buffer> and <quit>"; - global = "enable_special"; - type = types.bool; - }; - - enableUnsafe = mkDefaultOpt { - description = "Improves start time but reduces accuracy of the file list"; - global = "enable_unsafe"; - type = types.bool; - }; - - sessionRemoveLines = mkDefaultOpt { - description = "Lines matching any of the patterns in this list will be removed from the session file"; - global = "session_remove_lines"; - type = types.listOf types.str; - }; - - sessionSaveVars = mkDefaultOpt { - description = "List of variables for Startify to save into the session file"; - global = "session_savevars"; - type = types.listOf types.str; - }; - - sessionSaveCmds = mkDefaultOpt { - description = "List of cmdline commands to run when loading the session"; - global = "session_savecmds"; - type = types.listOf types.str; - }; - - sessionNumber = mkDefaultOpt { - description = "Maximum number of sessions to display"; - global = "session_number"; - type = types.listOf types.str; - }; - - sessionSort = mkDefaultOpt { - description = "Sort sessions by modification time rather than alphabetically"; - global = "session_sort"; - type = types.bool; - }; - - customIndices = mkDefaultOpt { - description = "Use this list as indices instead of increasing numbers"; - global = "custom_indices"; - type = types.listOf types.str; - }; - - customHeader = mkDefaultOpt { - description = "Define your own header"; - global = "custom_header"; - type = types.oneOf [types.str (types.listOf types.str)]; - }; - - customQuotes = mkDefaultOpt { - description = "Own quotes for the cowsay header"; - global = "custom_header_quotes"; - # TODO this should also support funcrefs! - type = types.listOf (types.listOf types.str); - }; - - customFooter = mkDefaultOpt { - description = "Custom footer"; - global = "custom_footer"; - type = types.str; - }; - - disableAtVimEnter = mkDefaultOpt { - description = "Don't run Startify at Vim startup"; - global = "disable_at_vimenter"; - type = types.bool; - }; - - relativePath = mkDefaultOpt { - description = "If the file is in or below the current working directory, use a relative path"; - global = "relative_path"; - type = types.bool; - }; - - useEnv = mkDefaultOpt { - description = "Show environment variables in path, if their name is shorter than their value"; - global = "use_env"; - type = types.bool; - }; - }; - } diff --git a/plugins/utils/startify/default.nix b/plugins/utils/startify/default.nix new file mode 100644 index 00000000..386ab073 --- /dev/null +++ b/plugins/utils/startify/default.nix @@ -0,0 +1,104 @@ +{ + lib, + config, + helpers, + pkgs, + ... +}: +with lib; +with helpers.vim-plugin; + mkVimPlugin config { + name = "startify"; + originalName = "vim-startify"; + defaultPackage = pkgs.vimPlugins.vim-startify; + globalPrefix = "startify_"; + + maintainers = [maintainers.GaetanLepage]; + + # TODO introduced 2024-03-01: remove 2024-05-01 + deprecateExtraConfig = true; + optionsRenamedToSettings = [ + "sessionDir" + "lists" + "bookmarks" + "commands" + "filesNumber" + "sessionAutoload" + "sessionBeforeSave" + "sessionPersistence" + "sessionDeleteBuffers" + "changeToDir" + "changeToVcsRoot" + "changeCmd" + "paddingLeft" + "enableSpecial" + "enableUnsafe" + "sessionRemoveLines" + "sessionNumber" + "sessionSort" + "customIndices" + "customHeader" + "customFooter" + "relativePath" + "useEnv" + ]; + imports = + map + ( + option: + mkRenamedOptionModule + ["plugins" "startify" option.old] + ["plugins" "startify" "settings" option.new] + ) + [ + { + old = "updateOldFiles"; + new = "update_oldfiles"; + } + { + old = "skipList"; + new = "skiplist"; + } + { + old = "useUnicode"; + new = "fortune_use_unicode"; + } + { + old = "skipListServer"; + new = "skiplist_server"; + } + { + old = "sessionSaveVars"; + new = "session_savevars"; + } + { + old = "sessionCmds"; + new = "session_savecmds"; + } + { + old = "customQuotes"; + new = "custom_header_quotes"; + } + { + old = "disableAtVimEnter"; + new = "disable_at_vimenter"; + } + ]; + + settingsOptions = import ./options.nix {inherit lib helpers;}; + + # TODO + settingsExample = { + custom_header = [ + "" + " ███╗ ██╗██╗██╗ ██╗██╗ ██╗██╗███╗ ███╗" + " ████╗ ██║██║╚██╗██╔╝██║ ██║██║████╗ ████║" + " ██╔██╗ ██║██║ ╚███╔╝ ██║ ██║██║██╔████╔██║" + " ██║╚██╗██║██║ ██╔██╗ ╚██╗ ██╔╝██║██║╚██╔╝██║" + " ██║ ╚████║██║██╔╝ ██╗ ╚████╔╝ ██║██║ ╚═╝ ██║" + " ╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝" + ]; + change_to_dir = false; + fortune_use_unicode = true; + }; + } diff --git a/plugins/utils/startify/options.nix b/plugins/utils/startify/options.nix new file mode 100644 index 00000000..e093f88a --- /dev/null +++ b/plugins/utils/startify/options.nix @@ -0,0 +1,406 @@ +{ + lib, + helpers, +}: +with lib; { + session_dir = helpers.defaultNullOpts.mkStr "~/.vim/session" '' + The directory to save/load sessions to/from. + ''; + + lists = mkOption { + type = with helpers.nixvimTypes; + listOf + ( + either + strLua + (submodule { + freeformType = with types; attrsOf anything; + options = { + type = mkOption { + type = types.str; + description = "The type of the list"; + example = "files"; + }; + + header = helpers.mkNullOrOption (with helpers.nixvimTypes; listOf (maybeRaw str)) '' + The 'header' is a list of strings, whereas each string will be put on its own + line in the header. + ''; + + indices = helpers.mkNullOrOption (with helpers.nixvimTypes; listOf (maybeRaw str)) '' + The 'indices' is a list of strings, which act as indices for the current list. + Opposed to the global `custom_indices`, this is limited to the current list. + ''; + }; + }) + ); + apply = v: + map (listElem: + if isString listElem + then helpers.mkRaw listElem + else listElem) + v; + default = []; + description = '' + Startify displays lists. Each list consists of a `type` and optionally a `header` and + custom `indices`. + + Default: + ```nix + [ + { + type = "files"; + header = [" MRU"]; + } + { + type = "dir"; + header = [{__raw = "' MRU' .. vim.loop.cwd()";}]; + } + { + type = "sessions"; + header = [" Sessions"]; + } + { + type = "bookmarks"; + header = [" Bookmarks"]; + } + { + type = "commands"; + header = [" Commands"]; + } + ] + ``` + ''; + }; + + bookmarks = + helpers.defaultNullOpts.mkListOf + ( + with helpers.nixvimTypes; + oneOf [str rawLua attrs] + ) + "[]" + '' + A list of files or directories to bookmark. + The list can contain two kinds of types. + Either a path (str) or an attrs where the key is the custom index and the value is the path. + ''; + + commands = + helpers.defaultNullOpts.mkListOf + ( + with types; + oneOf + [ + str + (attrsOf (either str (listOf str))) + (listOf str) + ] + ) + "[]" + '' + A list of commands to execute on selection. + Leading colons are optional. + It supports optional custom indices and/or command descriptions. + + Example: + ```nix + [ + ":help reference" + ["Vim Reference" "h ref"] + {h = "h ref";} + {m = ["My magical function" "call Magic()"];} + ] + ``` + ''; + + files_number = helpers.defaultNullOpts.mkUnsignedInt 10 '' + The number of files to list. + ''; + + update_oldfiles = helpers.defaultNullOpts.mkBool false '' + Usually `|v:oldfiles|` only gets updated when Vim exits. + Using this option updates it on-the-fly, so that `:Startify` is always up-to-date. + ''; + + session_autoload = helpers.defaultNullOpts.mkBool false '' + If this option is enabled and you start Vim in a directory that contains a `Session.vim`, + that session will be loaded automatically. + Otherwise it will be shown as the top entry in the Startify buffer. + + The same happens when you `|:cd|` to a directory that contains a `Session.vim` and execute + `|:Startify|`. + + It also works if you open a bookmarked directory. See the `bookmarks` option. + + This is great way to create a portable project folder! + + NOTE: This option is affected by `session_delete_buffers`. + ''; + + session_before_save = helpers.defaultNullOpts.mkListOf types.str "[]" '' + This is a list of commands to be executed before saving a session. + + Example: `["silent! tabdo NERDTreeClose"]` + ''; + + session_persistence = helpers.defaultNullOpts.mkBool false '' + Automatically update sessions in two cases: + - Before leaving Vim + - Before loading a new session via `:SLoad` + ''; + + session_delete_buffers = helpers.defaultNullOpts.mkBool true '' + Delete all buffers when loading or closing a session: + - When using `|startify-:SLoad|`. + - When using `|startify-:SClose|`. + - When using `session_autoload`. + - When choosing a session from the Startify buffer. + + NOTE: Buffers with unsaved changes are silently ignored. + ''; + + change_to_dir = helpers.defaultNullOpts.mkBool true '' + When opening a file or bookmark, change to its directory. + + You want to disable this, if you're using `|'autochdir'|` as well. + + NOTE: It defaults to `true`, because that was already the behaviour at the time this option was + introduced. + ''; + + change_to_vcs_root = helpers.defaultNullOpts.mkBool false '' + When opening a file or bookmark, seek and change to the root directory of the VCS (if there is + one). + + At the moment only git, hg, bzr and svn are supported. + ''; + + change_cmd = helpers.defaultNullOpts.mkStr "lcd" '' + The default command for switching directories. + + Valid values: + - `cd` + - `lcd` + - `tcd` + + Affects `change_to_dir` and `change_to_vcs_root`. + ''; + + skiplist = helpers.defaultNullOpts.mkListOf types.str "[]" '' + A list of Vim regular expressions that is used to filter recently used files. + See `|pattern.txt|` for what patterns can be used. + + The following patterns are filtered by default: + - `'runtime/doc/.*\.txt$'` + - `'bundle/.*/doc/.*\.txt$'` + - `'plugged/.*/doc/.*\.txt$'` + - `'/.git/'` + - `'fugitiveblame$'` + - `escape(fnamemodify(resolve($VIMRUNTIME), ':p'), '\') .'doc/.*\.txt$'` + + NOTE: Due to the nature of patterns, you can't just use "~/mysecret" but have to use + "$HOME .'/mysecret.txt'". + The former would do something entirely different: `|/\~|`. + + NOTE: When using backslashes as path separators, escape them. Otherwise using + "C:\this\vim\path\is\problematic" would not match what you would expect, since `|/\v|` is a + pattern, too. + + Example: + ```nix + [ + "\.vimgolf" + "^/tmp" + "/project/.*/documentation" + ] + ``` + ''; + + fortune_use_unicode = helpers.defaultNullOpts.mkBool false '' + By default, the fortune header uses ASCII characters, because they work for everyone. + If you set this option to `true` and your 'encoding' is "utf-8", Unicode box-drawing characters + will be used instead. + + This is not the default, because users of East Asian languages often set 'ambiwidth' to "double" + or make their terminal emulator treat characters of ambiguous width as double width. + Both would make the drawn box look funny. + + For more information: http://unicode.org/reports/tr11 + ''; + + padding_left = helpers.defaultNullOpts.mkUnsignedInt 3 '' + The number of spaces used for left padding. + ''; + + skiplist_server = + helpers.defaultNullOpts.mkListOf + (with helpers.nixvimTypes; maybeRaw str) + "[]" + '' + Do not create the startify buffer, if this is a Vim server instance with a name contained in + this list. + + Example: `["GVIM"]` + ''; + + enable_special = helpers.defaultNullOpts.mkBool true '' + Show `` and ``. + ''; + + enable_unsafe = helpers.defaultNullOpts.mkBool false '' + Enable the option only in case you think Vim starts too slowly (because of `:Startify`) or if + you often edit files on remote filesystems. + + It's called unsafe because it improves the time `:Startify` needs to execute by reducing the + amount of syscalls to the underlying operating system, but sacrifices the precision of shown + entries. + + This could lead to inconsistences in the shown `:Startify` entries (e.g. the same file could be + shown twice, because one time file was opened via absolute path and another time via symlink). + + Currently this option does this: + - don't resolves symlinks (`readlink(2)`) + - don't check every file if it's readable (`stat(2)`) + - don't filter through the bookmark list + ''; + + session_remove_lines = helpers.defaultNullOpts.mkListOf types.str "[]" '' + Lines matching any of the patterns in this list, will be removed from the session file. + + Example: + ```nix + ["setlocal" "winheight"] + ``` + Internally this simply does: + - `:global/setlocal/delete` + - `:global/winheight/delete` + + So you can use any `|pattern|`. + + NOTE: Take care not to mess up any expressions within the session file, otherwise you'll + probably get problems when trying to load it. + ''; + + session_savevars = helpers.defaultNullOpts.mkListOf types.str "[]" '' + Include a list of variables in here which you would like Startify to save into the session file + in addition to what Vim normally saves into the session file. + + Example: + ```nix + [ + "g:startify_session_savevars" + "g:startify_session_savecmds" + "g:random_plugin_use_feature" + ] + ``` + ''; + + session_savecmds = helpers.defaultNullOpts.mkListOf types.str "[]" '' + Include a list of cmdline commands which Vim will run upon loading the session. + + Example: + ```nix + [ + "silent !pdfreader ~/latexproject/main.pdf &" + ] + ``` + ''; + + session_number = helpers.defaultNullOpts.mkUnsignedInt 999 '' + The maximum number of sessions to display. + Makes the most sense together with `session_sort`. + ''; + + session_sort = helpers.defaultNullOpts.mkBool false '' + Sort sessions by modification time (when the session files were written) rather than + alphabetically. + ''; + + custom_indices = + helpers.defaultNullOpts.mkNullable + ( + with helpers.nixvimTypes; + maybeRaw (listOf str) + ) + "[]" + '' + Use any list of strings as indices instead of increasing numbers. If there are more startify + entries than actual items in the custom list, the remaining entries will be filled using the + default numbering scheme starting from 0. + + Thus you can create your own indexing scheme that fits your keyboard layout. + You don't want to leave the home row, do you?! + + Example: + ```nix + ["f" "g" "h"] + ``` + ''; + + custom_header = + helpers.mkNullOrOption + ( + with helpers.nixvimTypes; + maybeRaw (listOf (maybeRaw str)) + ) + '' + Define your own header. + + This option takes a `list of strings`, whereas each string will be put on its own line. + If it is a simple `string`, it should evaluate to a list of strings. + + Example: + ```nix + [ + "" + " ███╗ ██╗██╗██╗ ██╗██╗ ██╗██╗███╗ ███╗" + " ████╗ ██║██║╚██╗██╔╝██║ ██║██║████╗ ████║" + " ██╔██╗ ██║██║ ╚███╔╝ ██║ ██║██║██╔████╔██║" + " ██║╚██╗██║██║ ██╔██╗ ╚██╗ ██╔╝██║██║╚██╔╝██║" + " ██║ ╚████║██║██╔╝ ██╗ ╚████╔╝ ██║██║ ╚═╝ ██║" + " ╚═╝ ╚═══╝╚═╝╚═╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝" + ] + ``` + ''; + + custom_header_quotes = helpers.defaultNullOpts.mkListOf (with types; listOf str) "[]" '' + Example: + ```nix + [ + ["quote #1"] + ["quote #2" "using" "three lines"] + ] + ``` + ''; + + custom_footer = + helpers.mkNullOrOption + ( + with helpers.nixvimTypes; + maybeRaw (listOf (maybeRaw str)) + ) + '' + Same as the custom header, but shown at the bottom of the startify buffer. + ''; + + disable_at_vimenter = helpers.defaultNullOpts.mkBool false '' + Don't run Startify at Vim startup. + You can still call it anytime via `:Startify`. + ''; + + relative_path = helpers.defaultNullOpts.mkBool false '' + If the file is in or below the current working directory, use a relative path. + Otherwise an absolute path is used. + The latter prevents hard to grasp entries like `../../../../../foo`. + + NOTE: This only applies to the "files" list, since the "dir" list is relative by nature. + ''; + + use_env = helpers.defaultNullOpts.mkBool false '' + Show environment variables in path, if their name is shorter than their value. + See `|startify-colors|` for highlighting them. + + `$PWD` and `$OLDPWD` are ignored. + ''; +}