geany-plugins
geany-plugins copied to clipboard
Markdown: Update using known GeanyDocument when available
For whatever reason, in some cases document_get_current()
doesn't
return a valid document when it seems like it should, so when updating
the markdown preview from signals where the related GeanyDocument
is available, use that instead of calling document_get_current()
.
In other cases, continue to use document_get_current()
as before.
Closes #1062
Do you have any further information about when/why/how document_get_current()
is not returning valid docs? Given its used all through Geany its a bit of a worry if its not right.
I do not, I just noticed that it was giving invalid/NULL and that I had a valid document pointer already available. Probably one of the callbacks the plugin uses gets triggered early before the document list is fully initialized or something, but I didn't spend much time trying to understand it.
It can definitely return NULL for lots of reasons, but if it returns a pointer it should be valid since it tests it and returns NULL if not valid.
What your change suggests to me is that you'd encounter cases where document_get_current()
doesn't return the document for which the signal was fired for. This sounds weird for the activate
/new
/open
/reload
/filetype-set
signals you're using, and definitely something that should be fixed if it's indeed not in sync (e.g. the signal is fired before the changes that make document_get_current()
return the right value happen) -- unless there is an actual reason for that, but still.
I'm sympathetic to the base idea of using the document for which the signal was fired though. But it really seems like it should be strictly equal to document_get_current()
.