Skip to content

Commit

Permalink
version 3.0 (#206)
Browse files Browse the repository at this point in the history
* Remove tables functions

They were either not used or provided by neovim already

* Remove unnecessary strings file

* Use vim.fn instead

* Remove unused module

* Replace commands for higher-level api calls

* Replace window number for id

This way is easier to work with neovim's API

* Replace api call for cmd wrapper

* Fix typo

* Prepare simplification of repl creation

Ideally, a top-level function will require the repl creation.
In order to do so, it will have to make sure:
  a) a window exists;
  b) a repl definition exists;

Then, it will have to manually manage the window logic, for example:
  - Create the repl window
  - Move to repl window
  - Create repl
  - Move back to original window

* Prepare simplification of repl definition

It seems convoluted that the users have to:
  a) create a repl definition to an arbitrary name;
  b) refer to that arbitrary name to get the definition;

This seems to cause a lot of confusion.
The new structure should allow for a direct reference:

{
  repl_definition = {
    python = {
      command = {"ipython3", "--whatever-flags"}
    }
  }
}

So the caller code will look up in the config and, if no
value is explicitly defined, it will lookup with the metamethod
to get the first available repl definition.

Explicitly defining the preferred repl definition
would be as easy as:

{
  repl_definition = {
    python = require("iron.fts.python").ipython
  }
}

* Move deprecated functions down

So they are easier to find.
Also, adds documentation to the functions that are being kept.

* Avoid unnecessary function call

* Remove unused parameter

* Refactor core functions to use new internal api

This makes them more straightforward and starts drawing some patterns on
usage that could be simplified even further.

* Simplify view functions

There's no need to curry them. This just makes maintenance less obvious.

* Apply small fixes to internal functions

They should be self-contained and, as the unix philosophy mandates,
do one thing and do it well.

Therefore, we remove the indenting code (that apparently does nothing)
from `send_to_repl`.

Also, it seems logical to me that low level functions should not call
themselves. This lifts the work to the caller but makes them dead
simple.

As a final addition to this, users can configure to use scratch buffers
for the repl, which might make them lose the ability to toggle, but it
is configurable nonetheless.

* Pass `ft` to false clause

This allows for reusing the `false`-case function, as it is now treated
as stateless function and not a closure (as it was implied by the
no-argument arity)

* Split conditional

So a nil true-case function doesn't cause a false-case function to be
called if the repl exists.

* Replace usage of `ensure_repl_exists`

* refactor: Ensure function works on empty ft

It should never happen but since this function could call a side-effect
of creating a repl, to avoid further processing it is better to
short-circuit out of that processing as early as possible

* style: Ensure  condition is in a single line

* docs: Add docstrings to lowlevel functions

* refactor: Extract lowlevel calls to local wrapper

This should solve the issue of lowlevel calls being verbose and
repetitive. With this local layer, core functions can create the REPLs
without much duplication respecting their individual characteristics
(i.e. in the current window, restarting the current repl, etc.).

* refactor: Restructure commands and mappings

This should make it simpler to work with the mappings and commands
defined by iron

* Add function to close repl from lua

* Simplify send functions

* Add documentation to core functions

* fixup! Simplify send functions

* Simplify config

* Auto close windows

* Add docs to low level functions

* Fix marks

* Add docs to marks functions

* Remove unnecessary comments from init

* Add docs

* Break functions for visual an motion

It is easier to maintain if they're separate.

* Fix marks placement

* Fix up docs and remove unused function

Additionally ensures `core.send` will handle null data

* Default to float window

Also, make it easier to use floats from user config by adding a `.curry`
layer, allowing for `view.curry.<fn>` to return a curried version of
`<fn>` that only expects the buffer, instead of forcing the user to
wrap the function, which could lead to bugs by the user forgetting the
return value.

* Fix typo

* Allow to send the data to a hidden repl

* Rename function + Stop focusing on toggle

To keep toggle consistent, we should not focus on the repl when
returning. It can be done by `IronFocus` anyway, which is a keymap away
from the user.

* Remove inspect

* Avoid the creation of unnecessary buffers

Both `new_window` and `create_repl_on_current_window` created buffers
for their local usage, which would cause multiple unnecessary buffers to
be created unnecessarily. By moving the creation out we can avoid that
and reusue previously created buffers for window and term
initialization.

* Document state changes

* Fix codeclimate errors

* Fix command that changed name

* Install locally

* Remove unused import

* Allow for passing in options

It looks like we shouldn't figure "config" in this layer
If that's the case, then we move out the config import

Memory management will then belong to another namespace which could rely
on config, and that is ok
  • Loading branch information
hkupty authored May 17, 2022
1 parent bc9c596 commit 3f6c27b
Show file tree
Hide file tree
Showing 18 changed files with 645 additions and 510 deletions.
2 changes: 1 addition & 1 deletion bin/pctl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ setup(){
}
}

$LUAROCKS install "$1"
$LUAROCKS --local install "$1"
}

tests(){
Expand Down
60 changes: 59 additions & 1 deletion lua/iron/config.lua
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
return require("iron.defaults")._defaults()
-- luacheck: globals vim
local view = require("iron.view")

--- Default values
--@module config
local config

--- Default configurations for iron.nvim
-- @table config.values
-- @tfield false|string highlight_last Either false or the name of a highlight group
-- @field scratch_repl When enabled, the repl buffer will be a scratch buffer
-- @field should_map_plug when enabled iron will provide its mappings as `<plug>(..)` as well,
-- for backwards compatibility
-- @field close_window_on_exit closes repl window on process exit
local values = {
highlight_last = "IronLastSent",
visibility = require("iron.visibility").toggle,
scope = require("iron.scope").path_based,
scratch_repl = false,
close_window_on_exit = true,
preferred = setmetatable({}, {
__newindex = function(tbl, k, v)
vim.api.nvim_err_writeln("iron: Setting preferred repl is deprecated.")
vim.api.nvim_err_writeln(" Use `repl_definition` key instead supplying the complete repl definition")
rawset(tbl, k, v)
end
}),
repl_definition = setmetatable({}, {
__index = function(tbl, key)
local repl_definitions = require("iron.fts")[key]
local repl_def
for _, v in pairs(repl_definitions) do
if vim.fn.executable(v.command[1]) == 1 then
repl_def = v
break
end
end
if repl_def == nil then
vim.api.nvim_err_writeln("Failed to locate REPL executable, aborting")
else
rawset(tbl, key, repl_def)
return repl_def
end
end
}),
should_map_plug = true,
repl_open_cmd = view.curry.bottom(40),
mark = { -- Arbitrary numbers
save_pos = 20,
send = 77,
},
buflisted = false,
}

-- HACK for LDoc to correctly link @see annotations
config = vim.deepcopy(values)
config.values = values

return config
Loading

0 comments on commit 3f6c27b

Please sign in to comment.