textadept icon indicating copy to clipboard operation
textadept copied to clipboard

`events.connect(events.LEXER_LOADED,...)` strange behaviour in nightly

Open paaguti opened this issue 10 months ago • 2 comments

Hi,

I'm on nightly, Ubuntu 22.04. In my init.lua I have a simple function to set indentation according to buffer mode:

function adjust_edit(lexer)
  ui.statusbar_text = 'Loaded ' .. lexer
  if lexer == 'bash' then
    buffer.indent = 2
    buffer.use_tabs = false
  elseif lexer == 'latex' then
    buffer.indent = 2
    buffer.use_tabs = false
  elseif lexer == 'lua' then
    buffer.indent = 3
    buffer.use_tabs = false
  elseif lexer == 'python' then 
    buffer.indent = 4
    buffer.use_tabs = false
  else
    buffer.use_tabs = true
    buffer.tab_width = 8
  end
end

And I connect it to the LEXER_LOADED with:

events.connect(events.LEXER_LOADED, 
  function (name) 
    adjust_edit(name) 
  end
)

Indentation seems to work correctly set. However, the status bar message doesn't seem to change from 'Spaces: 8' when the lexer is loaded.

paaguti avatar Apr 22 '24 05:04 paaguti

OK, I should be using buffer.tab_width and not buffer.indent.. So my question: what is the use of buffer.indent then? Maybe an example in the documentation could illustrate the use...

paaguti avatar Apr 22 '24 12:04 paaguti

buffer.indent is the width (number of spaces) in a level of indentation, when the indentation is composed of spaces. buffer.tab_width is the width (number of spaces) in a level of indentation, when the indentation is composed of tabs. As mentioned in the API documentation, buffer.indent is 0 by default, which will match buffer.tab_width. Having different values for these settings often just causes confusion, and buffer.tab_width is the more familiar setting, so that's what you see in the manual.

orbitalquark avatar Apr 24 '24 12:04 orbitalquark