orbitalquark / textadept

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

Opening the preferences or opening a file doesn't emit BUFFER_AFTER_SWITCH #314

Closed paaguti closed 1 year ago

paaguti commented 1 year ago

On the latest nightly (Qt) tested on Linux (self-compiled) and WIndows (downloaded from github) I'm tracking BUFFER_NEW and BUFFER_AFTER_SWITCH and when they are emitted, I print view.buffer.lexer_language. with

events.connect(events.BUFFER_NEW , function()
  print ('BUFFER_NEW -> ' .. view.buffer.lexer_language)
end)

events.connect(events.BUFFER_AFTER_SWITCH , function()
  print ('BUFFER_AFTER_SWITCH ->' .. view.buffer.lexer_language)
end)

The sequence of actions is 1.- Call textadept to edit a Python File and then 2.- Open the preferences

BUFFER_NEW -> text
BUFFER_NEW -> text
BUFFER_NEW -> text
BUFFER_AFTER_SWITCH ->python
BUFFER_NEW -> text

I'm missing a final BUFFER_AFTER_SWITCH ->lua when ~/.textadept/init.lua is opened.

orbitalquark commented 1 year ago

Textadept does not emit events.BUFFER_AFTER_SWITCH after events.BUFFER_NEW (the latter implies the former). What you are seeing is a side-effect of closing an initial empty buffer when opening a Python file (https://github.com/orbitalquark/textadept/blob/c210f2bd184d78245a7be4b6c6ebb1849c6697d3/core/file_io.lua#L308-L313). If you start Textadept, type into the empty buffer, and then attempt to open a Python file, you will not see an events.BUFFER_AFTER_SWITCH event.

I know this was intentional, but I don't exactly remember the rationale, so I'm not certain this is a bug.

paaguti commented 1 year ago

I've found a workaround: I connect to events.LEXER_LOADED events.FILE_OPENED and events.BUFFER_AFTER_SWITCH and I get the lexer with view.buffer.lexer_language and I don't seem to miss anything right now.

paaguti commented 1 year ago

I'm happy with my current workaround. Close this if you have something more urgent.