Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Lets start a wiki with good defaults for popular languages #18

Open
IndianBoy42 opened this issue Oct 12, 2021 · 9 comments
Open

Lets start a wiki with good defaults for popular languages #18

IndianBoy42 opened this issue Oct 12, 2021 · 9 comments

Comments

@IndianBoy42
Copy link
Contributor

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

@pianocomposer321
Copy link
Owner

Sounds like a great idea!

@MordechaiHadad
Copy link

Sounds like a great idea!

POG! defaults confirmed?

@IndianBoy42
Copy link
Contributor Author

IndianBoy42 commented Oct 15, 2021

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?

@pianocomposer321
Copy link
Owner

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.

@ybbond
Copy link

ybbond commented Oct 22, 2021

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:

function M.expand(str)
-- Expand % strings and wildcards anywhere in string
local split_str = vim.split(str, ' ')
local expanded_str = vim.tbl_map(vim.fn.expand, split_str)
return table.concat(expanded_str, ' ')
end

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
Copy link

ybbond commented Oct 22, 2021

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",
          },
        },
    }
  }
}

@pianocomposer321
Copy link
Owner

@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
Copy link
Owner

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.

@ybbond
Copy link

ybbond commented Oct 23, 2021

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants