Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better setup for quarto #1329

Open
4 tasks
laguill opened this issue Jan 23, 2025 · 0 comments
Open
4 tasks

Better setup for quarto #1329

laguill opened this issue Jan 23, 2025 · 0 comments
Labels
enhancement New feature or request

Comments

@laguill
Copy link

laguill commented Jan 23, 2025

Hello,

I am trying to implement some more feature to the quarto pack like syntax hilghtings, snippets, send code.
Like you can find in quarto kickstarter

  • vim-slim is not working properly to send code to ipython ➡ I have error Terminal not found (after opening it)

  • mini-snippets might work

  • syntax highlighting of code chunck

  • Implement leader key for quarto commands ➡ Require a better mapping

Describe the new feature

Here is the config file I tried to implement but without that much success

return {

  {
    "quarto-dev/quarto-nvim",
    opts = {
      lspFeatures = {
        languages = { "r", "python", "julia", "bash", "html", "lua" },
      },
    },
    ft = "quarto",
    keys = {
      { "<Leader>qa", ":QuartoActivate<cr>", desc = "quarto activate" },
      { "<Leader>qp", ":lua require'quarto'.quartoPreview()<cr>", desc = "quarto preview" },
      { "<Leader>qq", ":lua require'quarto'.quartoClosePreview()<cr>", desc = "quarto close" },
      { "<Leader>qh", ":QuartoHelp ", desc = "quarto help" },
      { "<Leader>qe", ":lua require'otter'.export()<cr>", desc = "quarto export" },
      { "<Leader>qE", ":lua require'otter'.export(true)<cr>", desc = "quarto export overwrite" },
      { "<Leader>qrr", ":QuartoSendAbove<cr>", desc = "quarto run to cursor" },
      { "<Leader>qra", ":QuartoSendAll<cr>", desc = "quarto run all" },
      { "<Leader><cr>", ":<Plug>SlimeSendCell<cr>", desc = "send code chunk" },
      { "<c-cr>", ":<Plug>SlimeSendCell<cr>", desc = "send code chunk" },
      { "<c-cr>", "<esc>:SlimeSendCell<cr>i", mode = "i", desc = "send code chunk" },
      { "<c-cr>", "<Plug>SlimeRegionSend<cr>", mode = "v", desc = "send code chunk" },
      { "<cr>", "<Plug>SlimeRegionSend<cr>", mode = "v", desc = "send code chunk" },
      { "<Leader>tr", ":split term://R<cr>", desc = "terminal: R" },
      { "<Leader>ti", ":vsplit term://ipython<cr>", desc = "terminal: ipython" },
      { "<Leader>tp", ":split term://python<cr>", desc = "terminal: python" },
      { "<Leader>tj", ":split term://julia<cr>", desc = "terminal: julia" },
    },

    
  },

  {
    "jmbuhr/otter.nvim",
    opts = {
      buffers = {
        set_filetype = true,
      },
    },
  },

  {
    "hrsh7th/nvim-cmp",
    dependencies = { "jmbuhr/otter.nvim" },
    opts = function(_, opts)
      ---@param opts cmp.ConfigSchema
      local cmp = require("cmp")
      opts.sources = cmp.config.sources(vim.list_extend(opts.sources, { { name = "otter" } }))
    end,
  },

  -- send code from python/r/qmd documets to a terminal or REPL
  -- like ipython, R, bash
  {
    "jpalardy/vim-slime",
    init = function()
      vim.b["quarto_is_" .. "python" .. "_chunk"] = false
      Quarto_is_in_python_chunk = function()
        require("otter.tools.functions").is_otter_language_context("python")
      end

      vim.cmd([[
      let g:slime_dispatch_ipython_pause = 100
      function SlimeOverride_EscapeText_quarto(text)
      call v:lua.Quarto_is_in_python_chunk()
      if exists('g:slime_python_ipython') && len(split(a:text,"\n")) > 1 && b:quarto_is_python_chunk
      return ["%cpaste -q\n", g:slime_dispatch_ipython_pause, a:text, "--", "\n"]
      else
      return a:text
      end
      endfunction
      ]])

      local function mark_terminal()
        vim.g.slime_last_channel = vim.b.terminal_job_id
        vim.print(vim.g.slime_last_channel)
      end

      local function set_terminal()
        vim.b.slime_config = { jobid = vim.g.slime_last_channel }
      end

      -- slime, neovvim terminal
      vim.g.slime_target = "neovim"
      vim.g.slime_python_ipython = 1

      keys={
        ["<Leader>cm"] = { mark_terminal, desc="mark terminal" },
        ["<Leader>cs"] = { set_terminal, desc="set terminal" },
      }
    end,
  },

  {
    "neovim/nvim-lspconfig",
    ---@class PluginLspOpts
    opts = {
      ---@type lspconfig.options
      servers = {
        pyright = {},
        r_language_server = {},
        julials = {},
        marksman = {
          -- also needs:
          -- $home/.config/marksman/config.toml :
          -- [core]
          -- markdown.file_extensions = ["md", "markdown", "qmd"]
          filetypes = { "markdown", "quarto" },
          root_dir = require("lspconfig.util").root_pattern(".git", ".marksman.toml", "_quarto.yml"),
        },
      },
    },
  },

  {
    "nvim-treesitter/nvim-treesitter",
    optional = true,
    opts = function(_, opts)
      if opts.ensure_installed ~= "all" then
        opts.ensure_installed = require("astrocore").list_insert_unique(opts.ensure_installed, {
          "bash",
          "c",
          "html",
          "javascript",
          "json",
          "lua",
          "luadoc",
          "luap",
          "markdown",
          "markdown_inline",
          "python",
          "query",
          "regex",
          "tsx",
          "typescript",
          "vim",
          "vimdoc",
          "yaml",
          "bash",
          "html",
          "css",
          "javascript",
          "json",
          "lua",
          "markdown",
          "markdown_inline",
          "python",
          "vim",
          "yaml",
          "python",
          "julia",
          "r",
        })
      end
  end,
  }
}

Additional context

No response

@laguill laguill added the enhancement New feature or request label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant