Conversation
The test helper had drifted from main(): it skipped preinit and ran InitGlobals() after InitTabs(), so a test built on it saw a different startup state than plugins do. Extract the shared span into initEditor(), with an onErr callback.
Plugin hooks can run before the editor's global state exists: * onBufPaneOpen fires for the infobar's own pane, which InitGlobals() builds before LogBuf and Tabs are assigned * onBufferOpen fires for the user's files, which load before InitTabs() A handler that calls an action then hits a nil dereference in Go (e.g. buffer.Log() -> WriteLog, or micro.CurPane() -> MainTab()), and startup stops on "Press enter to continue". MainTab(), micro.CurPane(), WriteLog(), and SetGlobalOption() no longer assume a tab, pane, or log buffer exists.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Plugin hooks can run before the editor's global state exists:
onBufPaneOpenfires for the infobar's own pane, whichInitGlobals()builds beforeLogBufandTabsare assigned.onBufferOpenfires for the user's files, which load beforeInitTabs().A handler that calls an action then hits a nil dereference in Go (e.g.
buffer.Log()→WriteLog, ormicro.CurPane()→MainTab()), and startup stops on "Press enter to continue".Two commits:
b706262b:main()and the test helper share oneinitEditor().b7a3882d: nil guards inMainTab(),micro.CurPane(),WriteLog(),SetGlobalOption(), andTabs.Resize()for layout options set beforeInitTabs(); the plugin docs now say which API calls return nil during startup.Example
~/.config/micro/plug/crashdemo/crashdemo.lua:Run
micro README.md.Before fix
After fix
micro starts normally. The infobar's call is dropped, since the log buffer does not exist yet; the call for
README.mdreaches the log.