vfiler.vim icon indicating copy to clipboard operation
vfiler.vim copied to clipboard

Add toggle_show_linenumber, but got E21

Open ShortArrow opened this issue 2 years ago • 5 comments

Overview

I had forked and trying add action named toggle_show_linenumber. But I had got error messsage E21: Cannot make changes, 'modifiable' is off.

Question

I think this is the one of way. It be toggle modifiable at before and after toggle_show_linenumber. Is this better? Or?

https://github.com/obaland/vfiler.vim/blob/9e51bd2d9e348d5d821ea9bcb16141a352301616/lua/vfiler/view.lua#L274-L287

Code

https://github.com/ShortArrow/vfiler.vim/blob/20243fe163271cb62b21f369be8f6cf012d742ca/lua/vfiler/view.lua#L158-L168

Error

Attach toggle_show_linenumber to i key. And type i then get error message, as a bellow.

E21: Cannot make changes, 'modifiable' is off

ShortArrow avatar Jun 16 '22 03:06 ShortArrow

Thank you for your inquiry. Sorry, but I don't know the cause of the error for a moment. As for the row numbering option, we currently think it is best to apply the following to the View:draw function

function View:draw(context)
  -- expand item list
  self._items = {}
  if self._header then
    table.insert(self._items, context.root)
  end

  local options = context.options
  local compare = sort.get(options.sort)
  for item in walk(context.root, compare, context.gitstatus) do
    local hidden = item.name:sub(1, 1) == '.'
    if options.show_hidden_files or not hidden then
      table.insert(self._items, item)
    end
  end

  ------------------------------------------------
  -- for toggle_show_linenumber action
  ------------------------------------------------
  if self._winoptions['number'] ~= options.show_linenumber then
    self._winoptions['number'] = options.show_linenumber
    self:_clear_cache()
  end

  self:redraw()
end

where self._winoptions is a table type and stores the window options. The values stored in self._winoptions will be properly applied by the self:redraw function beyond it. The self:_clear_cache function clears the internal cache. Note that if this function is not called, the options set may not be applied. Try it to see if it works.

obaland avatar Jun 16 '22 04:06 obaland

Thanks, it works. Next, I will try write test code for ci.

In current, I am beginner for lua and vim. So, your code is helpful for me😀.

ShortArrow avatar Jun 16 '22 06:06 ShortArrow

I have turned away from this issue for a long time, but I am back.

If you don't mind my asking, what material did you refer to when writing the test code?

I am having a hard time finding the documentation I need by searching "neovim lua plugin development test driven."

Specifically, I am stuck because I don't know how to find the "lua command that allows me to see if the row index is actually displayed".

ShortArrow avatar Jul 27 '22 07:07 ShortArrow

Sorry for the late response. It may not be what you intended, but if you are testing on the code, it is the option value set as vim.api.nvim_win_get_option(0, 'number') that determines if it is true. For the test code, I refer to nvim-lua/plenary.nvim. I hope this will be helpful.

obaland avatar Aug 01 '22 06:08 obaland

Thank you for your helping. I'll read plenary.nvim, and try nvim_win_get_option!

Your advice helped me realize that. Changing the test requirement from "actually displayed" to "success neovim settings rewritten" , maybe to solve the problem.

ShortArrow avatar Aug 02 '22 04:08 ShortArrow