Skip to content

Feat/new api #138

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

Open
wants to merge 20 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/panvimdoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# https://github.com/kdheepak/panvimdoc
name: panvimdoc

on:
push:
paths:
- README.md
- .github/workflows/panvimdoc.yml

permissions:
contents: write

jobs:
docs:
runs-on: ubuntu-latest
name: pandoc to vimdoc
steps:
- uses: actions/checkout@v2
- uses: kdheepak/panvimdoc@main
with:
vimdoc: code_runner
version: "NVIM v0.11.0"
- uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: "docs: :memo: Auto generate docs"
branch: ${{ github.head_ref }}
3 changes: 3 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"runtime.version": "LuaJIT"
}
71 changes: 38 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<h1 align='center'>Code_Runner</h1>
# code_runner.nvim

<h4 align='center'>🔥 Code Runner for Neovim written in pure lua 🔥</h4>
🏃‍♂️ Code Runner for Neovim written in pure lua 🌙

<p align='center'><img src='https://i.ibb.co/1njTRTL/ezgif-com-video-to-gif.gif'></p>

Expand All @@ -10,15 +10,17 @@ When I was still in college it was common to try multiple programming languages,

## Requirements

- Neovim (>= 0.8)
- Neovim (>= 0.11)

## Install

- With [lazy.nvim](https://github.com/folke/lazy.nvim)

```lua
require("lazy").setup({
{ "CRAG666/code_runner.nvim", config = true },
{ "CRAG666/code_runner.nvim",
event= "VeryLazy",
},
}
```

Expand Down Expand Up @@ -54,7 +56,7 @@ Please see my config [code_runner.lua](https://github.com/CRAG666/dotfiles/blob/

## Setup

This plugin can be configured either in lua, with the `setup` function, or with json files for interopability between this plugin and the [original code runner](https://github.com/formulahendry/vscode-code-runner) vscode plugin.
This plugin can be configured either in lua, with the `setup` function, or with json files for interoperability between this plugin and the [original code runner](https://github.com/formulahendry/vscode-code-runner) vscode plugin.

### Minimal example

Expand Down Expand Up @@ -118,24 +120,22 @@ require('code_runner').setup {

All run commands allow restart. So, for example, if you use a command that does not have hot reload, you can call a command again and it will close the previous one and start again.

- `:RunCode`: Runs based on file type, first checking if belongs to project, then if filetype mapping exists
- `:RunCode <A_key_here>`: Execute command from its key in current directory.
- `:RunFile <mode>`: Run the current file (optionally you can select an opening mode).
- `:RunProject <mode>`: Run the current project(If you are in a project otherwise you will not do anything,).
- `:RunClose`: Close runner(Doesn't work in better_term mode, use native plugin options)
- `:CRFiletype` - Open json with supported files(Use only if you configured with json files).
- `:CRProjects` - Open json with list of projects(Use only if you configured with json files).
- `:Run`: Evaluate and write the current buffer based on filetype, first checking if belongs to project, then if filetype mapping exists
- `:Run on <display_mode>`: Run the current file (optionally you can select an display mode).
- `:Run with <filetype/cmd>`: Run the current file with the associate filetype/command (will run in the default display mode).
- `:<range>Run`: Execute range can be combined with `on` or `with`.
- `:Run project <display_mode>`: Run the current project (If you are in a project, optionally you can select an display mode).
- `:Run closeRunnerWindow`: Close runner window/viewport (Doesn't work in better_term mode, use native plugin options)
- `:Run openProjectFiletypes` - Open json with supported files (Use only if you configured with json files).
- `:Run openProjectList` - Open json with list of projects(Use only if you configured with json files).

Recommended mappings:

```lua
vim.keymap.set('n', '<leader>r', ':RunCode<CR>', { noremap = true, silent = false })
vim.keymap.set('n', '<leader>rf', ':RunFile<CR>', { noremap = true, silent = false })
vim.keymap.set('n', '<leader>rft', ':RunFile tab<CR>', { noremap = true, silent = false })
vim.keymap.set('n', '<leader>rp', ':RunProject<CR>', { noremap = true, silent = false })
vim.keymap.set('n', '<leader>rc', ':RunClose<CR>', { noremap = true, silent = false })
vim.keymap.set('n', '<leader>crf', ':CRFiletype<CR>', { noremap = true, silent = false })
vim.keymap.set('n', '<leader>crp', ':CRProjects<CR>', { noremap = true, silent = false })
vim.keymap.set('n', '<leader>rr', ':Run<CR>', { noremap = true, silent = false })
vim.keymap.set('n', '<leader>rot', ':Run on tab<CR>', { noremap = true, silent = false })
vim.keymap.set('n', '<leader>rp', ':Run project<CR>', { noremap = true, silent = false })
vim.keymap.set('n', '<leader>rc', ':Run closeRunnerWindow<CR>', { noremap = true, silent = false })
```

## Parameters
Expand All @@ -146,21 +146,23 @@ This are the the configuration option you can pass to the `setup` function. To s

Parameters:

- `mode`: Mode in which you want to run. Are supported: "better_term", "float", "tab", "toggleterm" (type: `bool`)
- `focus`: Focus on runner window. Only works on term and tab mode (type: `bool`)
- `startinsert`: init in insert mode.Only works on term and tab mode (type: `bool`)
- `term`: Configurations for the integrated terminal
- `mode`: Display Mode in which you want to run. Supported: "term", "float", "tab","better_term", "toggleterm" (type: `string`, default: "term")
- `focus`: Focus on runner window. Only works on "term" and "tab" display modes (type: `bool`, default: false)
- `startinsert`: init in insert mode. Only works on "term" and "tab" display modes (type: `bool`, default: false)
- `hot_reload`: Run automatically on buffer save, only works in "term" or similar (type: `bool`, default: true)
- `term`: Configurations for the integrated terminal (type: `table`)
- `position`: terminal position consult `:h windows` for options (type: `string`)
- `size`: Size of the terminal window (type: `uint` | `float`)
- `float`: Configurations for the float window
- `float`: Configurations for the float window (type: `table`)

- `border`: Window border options (type: `string`)
- "none": No border (default).
- "single": A single line box.
- "double": A double line box.
- "rounded": Like "single", but with rounded corners ("╭" etc.).
- "solid": Adds padding by a single whitespace cell.
- "shadow": A drop shadow effect by blending with the background.
- For more border options see `:h nvim_open_win()` or [NeoVim API Documentation](https://neovim.io/doc/user/api.html#nvim_open_win())
- For more border options see `:h nvim_open_win()` or [NeoVim API Documentation](<https://neovim.io/doc/user/api.html#nvim_open_win()>)
- `width`: (type: `float`)
- `x`: (type: `float`)
- `y`: (type: `float`)
Expand All @@ -180,7 +182,7 @@ Parameters:
### Setup Filetypes

> **Note**
> The commands are runned in a shell. This means that you can't run neovim commands with [this](https://github.com/CRAG666/code_runner.nvim/issues/59).
> The commands ran in a shell. This means that you can't run neovim commands with [this](https://github.com/CRAG666/code_runner.nvim/issues/59).

#### Lua

Expand All @@ -203,7 +205,7 @@ filetype = {
},
```

If you want to add some other language or some other command follow this structure `key = commans`.
If you want to add some other language or some other command follow this structure `key = commands`.

#### Json

Expand Down Expand Up @@ -242,8 +244,8 @@ If you want to add some other language or some other command follow this structu

There are 3 main ways to configure the execution of a project (found in the example.)

1. Use the default command defined in the filetypes file (see `:CRFiletype`or check your config). In order to do that it is necessary to define file_name.
2. Use a different command than the one set in `CRFiletype` or your config. In this case, the file_name and command must be provided.
1. Use the default command defined in the filetypes file (see `:Run openProjectFiletypes`or check your config). In order to do that it is necessary to define file_name.
2. Use a different command than the one set in `Run openProjectFiletypes` or your config. In this case, the file_name and command must be provided.
3. Use a command to run the project. It is only necessary to define command (You do not need to write navigate to the root of the project, because automatically the plugin is located in the root of the project).

The key for each project is a pattern to match against the current filename of
Expand Down Expand Up @@ -316,7 +318,7 @@ project = {
- `name`: Project name
- `description`: Project description
- `file_name`: Filename relative to root path
- `command`: Command to run the project. It is possible to use variables exactly the same as we would in [`CRFiletype`](#commands).
- `command`: Command to run the project. It is possible to use variables exactly the same as we would in [`Run openProjectFiletypes`](#commands).

> **Warning**
> Avoid using all the parameters at the same time. The correct way to use them is shown in the example and described above.
Expand Down Expand Up @@ -447,7 +449,7 @@ local function runTsFile(fileName)
vim.cmd 'vsplit term://'

-- Run the TypeScript file and print the result
vim.fn.termopen('ts-node ' .. fileName)
vim.fn.jobstart('ts-node ' .. fileName, {term=true})

-- Restore the focus to the original window
vim.fn.win_gotoid(current_win)
Expand Down Expand Up @@ -521,8 +523,11 @@ require("harpoon.term").sendCommand(1, require("code_runner.commands").get_filet

Your help is needed to make this plugin the best of its kind, be free to contribute, criticize (don't be soft) or contribute ideas. All PRs are welcome.

# LICENCE
## Similar Projects

---
- [SnipRun](https://github.com/michaelb/sniprun)
- [iron.nvim](https://github.com/Vigemus/iron.nvim)

# LICENCE

[MIT](https://github.com/CRAG666/code_runner.nvim/blob/main/LICENSE)
Empty file added doc/.gitkeep
Empty file.
Loading