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.
4
+
Supports Lua natively and can be extended for other languages.
> All settings are self explanatory, but please read below about [`preserve_context`](#-notes-on-globals-locals-and-preserving-execution-context) option.
60
47
61
-
Mappings are local to the console, except the ones for toggling the console - `` ` `` and attaching to a buffer - ``<Leader>` ``. All mappings can be overridden in your custom
62
-
config. If you want to delete a mapping - set its value to `false`.
48
+
Mappings are local to the console, except the ones for toggling the console - `` ` `` and attaching to a buffer - ``<Leader>` ``.
49
+
All mappings can be overridden in your custom config. If you want to delete a mapping - set its value to `false`.
63
50
64
51
<details><summary>Default Settings</summary>
65
52
@@ -74,7 +61,7 @@ opts = {
74
61
autosave=true, -- autosave on console hide / close
75
62
load_on_start=true, -- load saved session on start
76
63
preserve_context=true, -- preserve results between evaluations
77
-
strip_local=true, --remove local identifier from source code
64
+
strip_local=true, --strip `local` from top-level variable declarations
78
65
show_one_line_results=true, -- prints one line results, even if already shown as virtual text
79
66
notify_result=false, -- notify result
80
67
clear_before_eval=false, -- clear output below result prefix before evaluation of the whole buffer
@@ -105,14 +92,12 @@ opts = {
105
92
106
93
</details>
107
94
108
-
<br>
109
-
110
95
## 🚀 Basic usage (with default mappings)
111
96
112
97
- Install, press the mapped key `` ` `` and start exploring.
113
98
- Enter code as normal, in insert mode.
114
99
- 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.
100
+
- 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
101
- The evaluation of the last line is returned and printed, so no `return` is needed in most cases.
117
102
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
103
The result of assignments on the last line will be also shown as virtual text.
@@ -136,11 +121,14 @@ opts = {
136
121
> [!IMPORTANT]
137
122
> By default, the option `preserve_context` is on, which means that the execution context is preserved between evaluations.
138
123
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 = ..`.
124
+
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 in Neovim's global environment.
125
+
If you purposefully want to alter the global state, use `_G.My_variable = ..`.
126
+
127
+
The option `preserve_context` implies that variables without `local` will be stored in the console's local context and preserved between executions.
141
128
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`.
129
+
So, if you first execute `a = 1`, then `a = a + 1` and then `a` - you will get `2`.
130
+
131
+
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
132
145
133
If you want the context to be cleared before every execution, set `preserve_context = false`.
146
134
@@ -149,8 +137,6 @@ There are two functions available within the console:
149
137
-`_ctx` - will print the contents of the context
150
138
-`_ctx_clear()` - clears the context
151
139
152
-
<br>
153
-
154
140
## ⭐ Extra features
155
141
156
142
### Attaching code evaluator to other buffers
@@ -162,8 +148,7 @@ There are two functions available within the console:
162
148
163
149
#### Setting up
164
150
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.
151
+
- 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
152
- Below is the default configuration, which can be overridden or extended by your custom config, where `default_process_opts` will be
168
153
replaced by language specific opts, e.g. a possible config for `python` could be:
169
154
@@ -291,7 +276,6 @@ There are a number of alternatives available, notably:
291
276
-[Luadev](https://github.com/bfredl/nvim-luadev)
292
277
-[SnipRun](https://github.com/michaelb/sniprun)
293
278
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
279
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