{"id":13395067,"url":"https://github.com/rafcamlet/nvim-luapad","last_synced_at":"2025-04-05T05:06:16.103Z","repository":{"id":37930206,"uuid":"251688866","full_name":"rafcamlet/nvim-luapad","owner":"rafcamlet","description":"Interactive real time neovim scratchpad for embedded lua engine - type and watch!","archived":false,"fork":false,"pushed_at":"2024-05-26T11:37:08.000Z","size":5112,"stargazers_count":548,"open_issues_count":4,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-07-31T17:23:29.246Z","etag":null,"topics":["neovim","neovim-plugins","nvim"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rafcamlet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-03-31T18:03:30.000Z","updated_at":"2024-07-26T14:41:23.000Z","dependencies_parsed_at":"2024-10-25T10:17:18.408Z","dependency_job_id":"e79a996b-ba39-487a-bc94-468e3d81373d","html_url":"https://github.com/rafcamlet/nvim-luapad","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafcamlet%2Fnvim-luapad","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafcamlet%2Fnvim-luapad/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafcamlet%2Fnvim-luapad/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafcamlet%2Fnvim-luapad/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafcamlet","download_url":"https://codeload.github.com/rafcamlet/nvim-luapad/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247289426,"owners_count":20914464,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["neovim","neovim-plugins","nvim"],"created_at":"2024-07-30T17:01:40.907Z","updated_at":"2025-04-05T05:06:16.083Z","avatar_url":"https://github.com/rafcamlet.png","language":"Lua","funding_links":[],"categories":["Lua","Neovim Lua Development","Code Runner"],"sub_categories":["Quickfix"],"readme":"# Interactive neovim scratchpad for lua\n\nLuapad runs your code in context with overwritten print function and displays the captured input as virtual text right there, where it was called - **in real time!**\n\n![Luapad print demo](https://user-images.githubusercontent.com/8767998/198146427-c7488912-16e3-49de-811e-8bbc33c1f3da.gif)\n\n![luapad colors demo](https://user-images.githubusercontent.com/8767998/198146416-04e026ce-8966-4c57-afc0-12fb62d6cff1.gif)\n\n-------\n\nLuapad adds Lua command (as native lua command extension) with deep function completion.\n\n![luapad Lua demo](https://user-images.githubusercontent.com/8767998/198146413-d2026d9e-f266-478c-959a-1ac65061aec0.gif)\n\n-------\n\n# WARNING!!!\n\nLuapad evaluates every code that you put in it, so be careful what you type in, specially if it's system calls, file operations etc. Also calling functions like `nvim_open_win` isn't good idea, because every single change in buffer is evaluated (you will get new window with every typed char :D).\n\nLuapad was designed to mess with small nvim lua code chunks. It probably will not work well with big \"real\" / \"production\" scripts.\n\nAll thoughts or/and error reports are welcome.\n\n### Installation\n\nWith vim-plug:\n\n```\n    Plug 'rafcamlet/nvim-luapad'\n```\n\nWith packer.nvim and Neovim \u003e= [v0.8.0](https://github.com/neovim/neovim/releases/tag/v0.8.0):\n\n```\n    use 'rafcamlet/nvim-luapad'\n```\n\nIn versions of Neovim prior to v0.8.0, the `CursorHold` event is [buggy](https://github.com/neovim/neovim/issues/12587). If you're using an older version, it's recomended to use [this fix](https://github.com/antoinemadec/FixCursorHold.nvim):\n\n```\n    use { 'rafcamlet/nvim-luapad', requires = \"antoinemadec/FixCursorHold.nvim\" }\n```\n\n### Usage\n\nLuapadd provides three different commands, that will help you with developing neovim plugins in lua:\n  - **Luapad** - which open interactive scratch buffer with real time evaluation.\n  - **LuaRun** - which run content of current buffer as lua script in new scope. You do not need to write file to disc or have to worry about overwriting functions in global scope.\n  - ~~**Lua** - which is extension of native lua command with function completion.~~ *This command will be removed in the next release, because the current version of Neovim has built-in cmd completion.*\n\nFrom version 0.2 luapad will move towards lua api exposure. Several useful functions are already available.\n\n```lua\nrequire('luapad').init() -- same as Luapad command\n\n-- Creates a new luapad instance and attaches it to the current buffer.\n-- Optionally, you can pass a context table to it, the elements of which will be\n-- available during the evaluation as \"global\" variables.\nrequire('luapad').attach({\n  context = { return_4 =  function() return 4 end }\n})\n\n-- Detaches current luapad instance from buffer, which just means turning it off. :)\nrequire('luapad').detach()\n\n-- Toggles luapad in current buffer.\nrequire('luapad').toggle({\n  context = { return_4 =  function() return 4 end }\n})\n\n-- You can also create new luapad instance by yourself, which can be helpfull if you\n-- want to attach it to a buffer different than the current one.\nlocal buffer_handler = 5\nrequire('luapad.evaluator'):new {\n  buf = buffer_handler,\n  context = { a = 'asdf' }\n}:start()\n\n-- luapad/run offers a run function (same as the LuaRun command) but allows you\n-- to specify a context tbl\nrequire 'luapad.run'.run {\n  context = {\n    print = function(str) print(string.upper(str)) end\n  }\n}\n\n-- If you turn off evaluation on change (and move) you can trigger it manualy by:\nlocal luapad = require('luapad.evaluator'):new{buf = vim.api.nvim_get_current_buf()}\nluapad:start()\nluapad:eval()\n\n-- You can always access current luapad instance by:\nlocal luapad = require 'luapad.state'.current()\nluapad:eval()\n\n-- ...or iterate through all instances\nfor _, v in ipairs(require('luapad.state').instances) do\n  v:eval()\nend\n```\n\n\n### Configuration\n\nYou can configure luapad via `require('luapad').setup({})` function (or its alias `config`). Configuration via vim globals is disabled. If you want to use old configuration method, please checkout version 0.2.\n\n\n| Name                    | default value | Description                                                                                                                                                                                                  |\n| ---                     | ---               | ---                                                                                                                                                                                                      |\n| count_limit             | 200000            | Luapad uses count hook method to prevent infinite loops occurring during code execution. Setting count_limit too high will make Luapad laggy, setting it too low, may cause premature code termination.  |\n| error_indicator         | true              | Show virtual text with error message (except syntax or timeout. errors)                                                                                                                                  |\n| preview                 | true              | Show floating output window on cursor hold. It's a good idea to set low update time. For example: `let \u0026updatetime = 300` You can jump to it by `^w` `w`.                                                |\n| eval_on_change          | true              | Evaluate buffer content when it changes.                                                                                                                                                                 |\n| eval_on_move            | false             | Evaluate all luapad buffers when the cursor moves.                                                                                                                                                       |\n| print_highlight         | 'Comment'         | Highlight group used to coloring luapad print output.                                                                                                                                                    |\n| error_highlight         | 'ErrorMsg'        | Highlight group used to coloring luapad error indicator.                                                                                                                                                 |\n| on_init                 | function          | Callback function called after creating new luapad instance.                                                                                                                                             |\n| context                 | {}                | The default context tbl in which luapad buffer is evaluated. Its properties will be available in buffer as \"global\" variables.                                                                           |\n| split_orientation       | 'vertical'        | The orientation of the split created by `Luapad` command. Can be `vertical` or `horizontal`.                                                                                                             |\n| wipe                    | true              | The Luapad buffer by default is wiped out after closing/loosing a window. If you're used to switching buffers, and you want to keep Luapad instance alive in the background, set it to false. |\n\n\nExample configuration (note it isn't the default one!)\n\n```lua\nrequire('luapad').setup {\n  count_limit = 150000,\n  error_indicator = false,\n  eval_on_move = true,\n  error_highlight = 'WarningMsg',\n  split_orientation = 'horizontal',\n  on_init = function()\n    print 'Hello from Luapad!'\n  end,\n  context = {\n    the_answer = 42,\n    shout = function(str) return(string.upper(str) .. '!') end\n  }\n}\n```\n\n### Statusline\n\nLuapad has ready to use lightline function_components.\n\n\u003cdetails\u003e\n\u003csummary\u003eExample lightline configuration:\u003c/summary\u003e\n\u003cpre\u003e\nlet g:lightline = {\n      \\ 'active': {\n      \\   'left': [\n      \\     [ 'mode', 'paste' ],\n      \\     [ 'readonly', 'filename', 'modified' ],\n      \\     [ 'luapad_msg']\n      \\   ],\n      \\ 'right': [\n      \\   ['luapad_status'],\n      \\   ['lineinfo'],\n      \\   ['percent'],\n      \\ ],\n      \\ },\n      \\ 'component_function': {\n      \\   'luapad_msg': 'luapad#lightline_msg',\n      \\   'luapad_status': 'luapad#lightline_status',\n      \\ },\n      \\ }\n\u003c/pre\u003e\n\u003c/details\u003e\n\u003cbr\u003e\n\n\nBut you can also create your own integration, using lua functions  `require'luapad.statusline'.status()` and `require'luapad.statusline'.msg()`.\n\n\n\u003cdetails\u003e\n\u003csummary\u003eExample galaxyline configuration:\u003c/summary\u003e\n\u003cpre\u003e\nlocal function luapad_color()\n  if require('luapad.statusline').status() == 'ok' then\n    return colors.green\n  else\n    return colors.red\n  end\nend\n\u003c/pre\u003e\n\n\u003cpre\u003e\nrequire('galaxyline').section.right[1] = {\n  Luapad = {\n    condition = require('luapad.state').current,\n    highlight = { luapad_color(), colors.bg },\n    provider = function()\n      vim.cmd('hi GalaxyLuapad guifg=' .. luapad_color())\n      local status = require('luapad.statusline').status()\n      return string.upper(tostring(status))\n    end\n  }\n}\n\u003c/pre\u003e\n\u003c/details\u003e\n\u003cbr\u003e\n\n\n### Types of errors\n\nLuapad separates errors into 3 categories:\n\n| Error   | Description                                                                                                  |\n| ---     | ---                                                                                                          |\n| SYNTAX  | Content of buffer is not valid lua script (you will see it a lot during typing)                              |\n| TIMEOUT | Interpreter has done more count instructions than luapad_count_limit, so there probably was a infinite loop |\n| ERROR   | Execution logical errors                                                                                     |\n\n\n### Changelog\n#### v0.3\n\n- Drop viml configuration\n- Improve preview window resizing (although it still needs some work)\n- Fix \"file no longer available\" error\n- Galaxyline example added to readme\n- Upgrading specs\n- Other minor upgrades and refactor\n\n#### v0.2\n\n- Better nvim native lsp integration (now you should have lsp completion in luapad buffers)\n- Enable creation of multiple luapads instances\n- Allow luapad to be attached to an existing buffer\n- Add on_init callback\n- Allow providing evaluation context for luapad buffers\n- Allow configure luapad via lua\n- Add `eval_on_move` and `eval_on_change` settings\n- Expose luapad lua api\n- Replace `g:luapad_status` and `g:luapad_msg` variables by `status()` and `msg()` lua functions.\n- Now luapad print function print also nil values\n\n### TODO\n- Allow changing orientation of the preview window\n\n### Shameless self promotion\n\nIf you want to start your adventure with writing lua plugins and are you are wondering where to begin, you can take a look at the links below.\n\n1. [How to write neovim plugins in Lua](https://www.2n.pl/blog/how-to-write-neovim-plugins-in-lua)\n2. [How to make UI for neovim plugins in Lua](https://www.2n.pl/blog/how-to-make-ui-for-neovim-plugins-in-lua)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafcamlet%2Fnvim-luapad","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafcamlet%2Fnvim-luapad","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafcamlet%2Fnvim-luapad/lists"}