You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**lua-console.nvim** - is a handy scratch pad / REPL / debug console for Lua development and Neovim exploration and configuration.
4
-
Acts as a user friendly replacement of command mode - messages loop and as a handy scratch pad to store and test your code gists.
5
-
6
-
7
-
**Update:** although it originated as a tool for Lua development, it has now evolved into supporting other languages too. See [`evaluating other languages`](#evaluating-other-languages).
3
+
**lua-console.nvim** - is a REPL / scratch pad / debug console for Neovim. Supports Lua natively and can be extended for other languages.
After installing Neovim, it took me some time to configure it, learn its settings, structure and API, while learning Lua in the process.
14
-
I got fed up of constantly hitting `:`, typing `lua= command`, then typing `:messages` to see the output, only to find out that a made a typo or a
15
-
syntax error and retyping the whole thing again, copying the paths from error stacktraces and so on. I needed something better, so there it is.
16
-
17
-
<br>
18
-
19
7
## ✨ Features
20
8
21
9
- Evaluate single line expressions and statements, visually selected lines or characters of code or the whole buffer
@@ -74,7 +62,7 @@ opts = {
74
62
autosave=true, -- autosave on console hide / close
75
63
load_on_start=true, -- load saved session on start
76
64
preserve_context=true, -- preserve results between evaluations
77
-
strip_local=true, --remove local identifier from source code
65
+
strip_local=true, --strip `local` from top-level variable declarations
78
66
show_one_line_results=true, -- prints one line results, even if already shown as virtual text
79
67
notify_result=false, -- notify result
80
68
clear_before_eval=false, -- clear output below result prefix before evaluation of the whole buffer
@@ -112,7 +100,7 @@ opts = {
112
100
- Install, press the mapped key `` ` `` and start exploring.
113
101
- Enter code as normal, in insert mode.
114
102
- Hit `Enter` in normal mode to evaluate a variable, statement or an expression in the current line.
115
-
- Visually select a region or a range of lines and press `Enter` to evaluate the code in the range or use `<S-Enter>` to evaluate the whole console.
103
+
- Visually select a region or a range of lines and press `Enter` to evaluate the code in the range or use `<S-Enter>` to evaluate the whole buffer.
116
104
- The evaluation of the last line is returned and printed, so no `return` is needed in most cases.
117
105
To avoid noise, if the return of your execution is `nil`, e.g. from a loop or a function without return, it will not be printed, but shown as virtual text.
118
106
The result of assignments on the last line will be also shown as virtual text.
@@ -136,11 +124,13 @@ opts = {
136
124
> [!IMPORTANT]
137
125
> By default, the option `preserve_context` is on, which means that the execution context is preserved between evaluations.
138
126
139
-
All the code executed in the console is evaluated in isolated environment. This means that any variables you declare without the `local` keyword will not be persisted
140
-
in Neovim's global environment, although all global variables are accessible. If you want purposefully to alter the global state, use `_G.My_variable = ..`.
127
+
All the code executed in the console is evaluated in isolated environment, which means that any global variables that you declare will not be persisted
128
+
in Neovim's global environment. If you purposefully want to alter the global state, use `_G.My_variable = ..`.
129
+
130
+
The option `preserve_context` implies that variables without `local` will be stored in the console's local context and preserved between executions.
131
+
So, if you first execute `a = 1`, then `a = a + 1` and then `a` - you will get `2`.
141
132
142
-
The option `preserve_context` means that although you declare variables without `local`, they will be stored in console's local context and preserved between separate executions.
143
-
So, if you first execute `a = 1`, then `a = a + 1` and then `a` - you will get `2`. Variables with `local` are also preserved, unless you set the `strip_local` option to `false`.
133
+
Also, by default, the option `strip_local` is on, which means that `local` modifier is stripped from top-level variable declarations and these variables are also stored in the context.
144
134
145
135
If you want the context to be cleared before every execution, set `preserve_context = false`.
146
136
@@ -162,8 +152,7 @@ There are two functions available within the console:
162
152
163
153
#### Setting up
164
154
165
-
- It is possible to setup external code executors for other languages. Evaluators for `ruby`,`racket` and `python` are working out of the box, support for other languages is coming.
166
-
Meanwhile, you can easily setup your own language.
155
+
- It is possible to setup external code executors for other languages. Evaluators for `ruby`,`racket` and `python` are working out of the box, support for other can be easily added.
167
156
- Below is the default configuration, which can be overridden or extended by your custom config, where `default_process_opts` will be
168
157
replaced by language specific opts, e.g. a possible config for `python` could be:
169
158
@@ -291,7 +280,6 @@ There are a number of alternatives available, notably:
291
280
-[Luadev](https://github.com/bfredl/nvim-luadev)
292
281
-[SnipRun](https://github.com/michaelb/sniprun)
293
282
294
-
Initially, when starting with Lua and Neovim, I tried all the REPLs/code runners I could find. However, I was not satisfied with all of them in one way or another.
295
283
Lua-console is an attempt to combine the best features of all of them, like REPL / scratch pad / code runner / debug console, while leaving the UX and config simple.
0 commit comments