orbitalquark / textadept

Textadept is a fast, minimalist, and remarkably extensible cross-platform text editor for programmers.
https://orbitalquark.github.io/textadept
MIT License
624 stars 38 forks source link

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

Closed paaguti closed 1 month ago

paaguti commented 2 months ago

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 commented 2 months ago

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...

orbitalquark commented 2 months ago

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.