From 4f1b02ea023b11787732ce488cfe9fbd42fd35dc Mon Sep 17 00:00:00 2001 From: Ben Puryear <54869170+Ben10164@users.noreply.github.com> Date: Thu, 23 May 2024 12:31:10 -0700 Subject: [PATCH] Rework into opts, modify `pdfviewer` to be os dependent --- lua/lazyvim/plugins/extras/lang/r.lua | 103 ++++++++++++-------------- 1 file changed, 46 insertions(+), 57 deletions(-) diff --git a/lua/lazyvim/plugins/extras/lang/r.lua b/lua/lazyvim/plugins/extras/lang/r.lua index 2232b308..a57ce011 100644 --- a/lua/lazyvim/plugins/extras/lang/r.lua +++ b/lua/lazyvim/plugins/extras/lang/r.lua @@ -7,64 +7,53 @@ return { end, { "R-nvim/R.nvim", - config = function() - -- Create a table with the options to be passed to setup() - local opts = { - R_args = { "--quiet", "--no-save" }, - hook = { - on_filetype = function() - -- This function will be called at the FileType event - -- of files supported by R.nvim. This is an - -- opportunity to create mappings local to buffers. - vim.api.nvim_buf_set_keymap(0, "n", "", "RDSendLine", {}) - vim.api.nvim_buf_set_keymap(0, "v", "", "RSendSelection", {}) - - -- Increase the width of which-key to handle the r-nvim descriptions - local wk = require("which-key") - wk.setup({ - layout = { - width = { min = 20, max = 100 }, -- min and max width of the columns - }, - }) - -- Workaround from https://github.com/folke/which-key.nvim/issues/514#issuecomment-1987286901 - wk.register({ - [""] = { - a = { name = "+(a)ll", ["🚫"] = "which_key_ignore" }, - b = { name = "+(b)etween marks", ["🚫"] = "which_key_ignore" }, - c = { name = "+(c)hunks", ["🚫"] = "which_key_ignore" }, - f = { name = "+(f)unctions", ["🚫"] = "which_key_ignore" }, - g = { name = "+(g)oto", ["🚫"] = "which_key_ignore" }, - k = { name = "+(k)nit", ["🚫"] = "which_key_ignore" }, - p = { name = "+(p)aragraph", ["🚫"] = "which_key_ignore" }, - r = { name = "+(r) general", ["🚫"] = "which_key_ignore" }, - s = { name = "+(s)plit or (s)end", ["🚫"] = "which_key_ignore" }, - t = { name = "+(t)erminal", ["🚫"] = "which_key_ignore" }, - v = { name = "+(v)iew", ["🚫"] = "which_key_ignore" }, - }, - }) - end, - }, - min_editor_width = 72, - rconsole_width = 78, - disable_cmds = { - "RClearConsole", - "RCustomStart", - "RSPlot", - "RSaveClose", - }, - synctex = false, - pdfviewer = "open", - } - -- Check if the environment variable "R_AUTO_START" exists. - -- If using fish shell, you could put in your config.fish: - -- alias r "R_AUTO_START=true nvim" - if vim.env.R_AUTO_START == "true" then - opts.auto_start = "on startup" - opts.objbr_auto_start = true - end - require("r").setup(opts) - end, lazy = false, + opts = { + -- Create a table with the options to be passed to setup() + R_args = { "--quiet", "--no-save" }, + hook = { + on_filetype = function() + -- This function will be called at the FileType event + -- of files supported by R.nvim. This is an + -- opportunity to create mappings local to buffers. + vim.api.nvim_buf_set_keymap(0, "n", "", "RDSendLine", {}) + vim.api.nvim_buf_set_keymap(0, "v", "", "RSendSelection", {}) + + -- Increase the width of which-key to handle the longer r-nvim descriptions + local wk = require("which-key") + wk.setup({ + layout = { + width = { min = 20, max = 100 }, -- min and max width of the columns + }, + }) + -- Workaround from https://github.com/folke/which-key.nvim/issues/514#issuecomment-1987286901 + wk.register({ + [""] = { + a = { name = "+(a)ll", ["🚫"] = "which_key_ignore" }, + b = { name = "+(b)etween marks", ["🚫"] = "which_key_ignore" }, + c = { name = "+(c)hunks", ["🚫"] = "which_key_ignore" }, + f = { name = "+(f)unctions", ["🚫"] = "which_key_ignore" }, + g = { name = "+(g)oto", ["🚫"] = "which_key_ignore" }, + k = { name = "+(k)nit", ["🚫"] = "which_key_ignore" }, + p = { name = "+(p)aragraph", ["🚫"] = "which_key_ignore" }, + r = { name = "+(r) general", ["🚫"] = "which_key_ignore" }, + s = { name = "+(s)plit or (s)end", ["🚫"] = "which_key_ignore" }, + t = { name = "+(t)erminal", ["🚫"] = "which_key_ignore" }, + v = { name = "+(v)iew", ["🚫"] = "which_key_ignore" }, + }, + }) + end, + }, + pdfviewer = (function() + if vim.loop.os_uname().sysname:find("Windows", 1, true) then + return "open" -- according to @Aman9das on Github + elseif vim.loop.os_uname().sysname:find("Darwin", 1, true) then + return "open" + else + return "xdg-open" -- according to @Aman9das on Github + end + end)(), + }, }, { "hrsh7th/nvim-cmp",