yabs.nvim icon indicating copy to clipboard operation
yabs.nvim copied to clipboard

Lets start a wiki with good defaults for popular languages

Open IndianBoy42 opened this issue 4 years ago • 9 comments
trafficstars

I think this would make this plugin a lot more use friendly

IndianBoy42 avatar Oct 12 '21 02:10 IndianBoy42

Sounds like a great idea!

pianocomposer321 avatar Oct 12 '21 02:10 pianocomposer321

Sounds like a great idea!

POG! defaults confirmed?

MordechaiHadad avatar Oct 15 '21 10:10 MordechaiHadad

I am trying to get good tasks for python, cpp (although this depends on build system), rust, lua and shells, because I work with those regularly. I can contribute those, I just need help with a few things, basically to do with getting the name of the current file and the path of the current project (cwd or lsp root).

I wan't a task something like this that just uses a terminal to execute the file (works for shell files or python files)

  tasks = {
    run = {
      command = "./%",
      output = "terminal",
    },
  },

The lsp root is for activating cmake correctly.

I think % should work (I think a link to documentation about which wildcards are available would be helpful), but what about getting the LSP root?

IndianBoy42 avatar Oct 15 '21 10:10 IndianBoy42

I'm not sure exactly what you need...maybe just getcwd()?

IIRC, the terminal should already start in the current working directory. If your cwd is not already correct, you're probably not starting vim from the project root. You should probably look into something like https://github.com/airblade/vim-rooter or https://github.com/ahmedkhalf/project.nvim.

pianocomposer321 avatar Oct 15 '21 14:10 pianocomposer321

I'm not sure exactly what you need...maybe just getcwd()?

IIRC, the terminal should already start in the current working directory. If your cwd is not already correct, you're probably not starting vim from the project root. You should probably look into something like https://github.com/airblade/vim-rooter or https://github.com/ahmedkhalf/project.nvim.

I maybe can relate on what @IndianBoy42 referring to.

suppose I build a C file in /Users/ybbond/c/hello.c with command = "gcc % -o %:r". It will generate new build file: /Users/ybbond/c/hello that I expect to run it with command ./hello

I cannot do that right now because expansion done after split:

https://github.com/pianocomposer321/yabs.nvim/blob/0ccc156a07fb7902374cb8e4fb3d43bb20ee1a56/lua/yabs/util.lua#L88-L93

while I need to add period slash ./ before filename. That makes command = "./%:p:r" cannot be done because it will not recognize the expansion.

Is there any way to achieve that? Thanks

ybbond avatar Oct 22 '21 03:10 ybbond

my hacky solution is to add this in my config:

require("yabs.util").expand = function(str)
  local split_str = vim.split(str, ' ')
  local expanded_str = vim.tbl_map(vim.fn.expand, split_str)
  if expanded_str[1] == "./" then
    return table.concat(expanded_str, '')
  else
    return table.concat(expanded_str, ' ')
  end
end

-- ...

yabs:setup{
  -- ...
  c = {
    tasks = {
        -- ...
        run = {
          command = "./ %:r",
          output = "terminal",
          opts = {
            open_on_run = "always",
          },
        },
    }
  }
}

ybbond avatar Oct 22 '21 03:10 ybbond

@ybbond Here's a better solution (this is untested but I think it should work lol):

run = {
  command = function()
    return "./" .. vim.fn.expand("%:r")
  end,
  output = "terminal",
  opts = {
    open_on_run = "always",
  }
}

This should work because if the command key is function, it uses the value that it returns as the actual command to run.

Try it and LMK if that works.

pianocomposer321 avatar Oct 22 '21 13:10 pianocomposer321

You're right though, the expand function should be improved. Either that or removed in favor of doing it the above way all the time, but I'd rather get it to work in those edge cases instead if possible.

pianocomposer321 avatar Oct 22 '21 14:10 pianocomposer321

@ybbond Here's a better solution (this is untested but I think it should work lol):

run = {
  command = function()
    return "./" .. vim.fn.expand("%:r")
  end,
  output = "terminal",
  opts = {
    open_on_run = "always",
  }
}

This should work because if the command key is function, it uses the value that it returns as the actual command to run.

Try it and LMK if that works.

glad to inform that your advice does the job. thanks! maybe that's a start of example to be added to the README.md?

anyway, fun fact. previously I tried:

        run = {
          command = "lua './'..vim.fn.expand('%:r')",
          type = "vim",
          output = "terminal",
          opts = {
            open_on_run = "always",
          },
        },

that does not work. that's why I end up using the hacky solution.

ybbond avatar Oct 23 '21 07:10 ybbond