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 You can view, comment on, or merge this pull request online at:
https://github.com/geany/geany-plugins/pull/1064
-- Commit Summary --
* Markdown: Update using known GeanyDocument when available
-- File Changes --
M markdown/src/plugin.c (17)
-- Patch Links --
https://github.com/geany/geany-plugins/pull/1064.patch https://github.com/geany/geany-plugins/pull/1064.diff
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.
@b4n commented on this pull request.
@@ -192,7 +193,7 @@ static gboolean on_editor_notify(GObject *obj, GeanyEditor *editor,
SCNotification *notif, MarkdownViewer *viewer) { if (IS_MOD_NOTIF(notif)) { - update_markdown_viewer(viewer); + update_markdown_viewer(viewer, NULL);
```suggestion update_markdown_viewer(viewer, editor->document); ```
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()`.
@b4n commented on this pull request.
{
- GeanyDocument *doc = document_get_current(); + if (!DOC_VALID(doc))
Wouldn't simply `doc == NULL` work here? Do you really get non-NULL doc pointers that have `doc->valid == FALSE`?
github-comments@lists.geany.org