Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Object Browser and Add Support for Custom Key Mappings (#237)
* Refactor set_buf_options to use an options table and loop Replace multiple `vim.api.nvim_set_option_value` calls with a single options table and iterate over it to set buffer options. This reduces code repetition, improves readability, and simplifies future maintenance. * Update key mappings to use `vim.keymap.set` with buffer-local scope Replace multiple `vim.api.nvim_buf_set_keymap` calls with `vim.keymap.set`, including the `buffer = true` option. This change utilizes the more modern Neovim keymap API. * Refactor browser.lua: Named function declarations, simplify conditional statements. 1. **ConverI guest anonymous function assignments to named function declarations** - From: ```lua local add_backticks = function(word, esc_reserved) M.start = function(_) -- etc ``` To: ```lua local function add_backticks(word, esc_reserved) function M.start(_) -- etc ``` 2. **Fix typos** 3. **Simplify conditional statements** - Original nested `if` statements: ```lua if isutf8 then if idx == 12 then -- Code end elseif idx == 8 then -- Code end ``` - Simplified combined conditions: ```lua if isutf8 and idx == 12 then -- Code elseif not isutf8 and idx == 8 then -- Code end ``` * Add documentation to the object browser module * Add support for custom key mappings in the Object Browser - Introduce `config.objbr_mappings` to allow users to define custom key-command pairs. - Update `set_buf_options` to iterate over `objbr_mappings` and set corresponding key mappings. - Implement `M.run_custom_command` to execute the specified command on the selected object. - Provide a default mapping (`s` key to `summary` command) in the configuration. * Add plot() to default objbr_mappings * Allow placeholder in object browser custom commands. * Add the ability to define a custom placeholder for object browser custom commands. * Add ability to map Lua functions in object browser. * Refactor Object Browser: Consolidate state variables into a single table * Update README and documentation for new object browser features. Document objbr_mappings in README and help files to explain how to configure custom key mappings for running R commands or Lua functions in the object browser. Added notes on using placeholders (e.g., {object}) and the new objbr_placeholder option for flexibility in command customization.
- Loading branch information