Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@elextr I still need the extra 'doc->file_name' check otherwise Geany crashes if the user has an 'untitled' document in front of them. Not a typical use case, but I encountered the crash by accident just a couple days after using the plug-in.
- Loading branch information
8151d8b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure new unsaved documents are that rare, so yeah thats another circumstance you need to handle.
8151d8b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. My reason for geany/geany#3770 was that I believed it should be handled by the API.
To be more succinct, are you sure you want
is_valid
to be true for untitled, unsaved docs. And if so, could you explain a little why?8151d8b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And actually, if you do agree, I think my PR should be done a little differently. Instead of returning NULL from where I do, is_valid should be set to 0 around here maybe https://github.com/andy5995/geany/blob/6d06acffa2ab10a0416e550e4b2ac47a597ebbba/src/document.c (L679)
8151d8b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DOC_VALID
simply means that the pointer is to aGeanyDocument
and that it still exists, it hasn't been closed since last time you used it. It says nothing about any other state of the document, eg if it has a filename, that needs to be tested after you are sure its a valid document, otherwise you could be testing rubbish left over after close. IIRC the memory ofGeanyDocument
s is never re-used so cached pointers will never accidentally point to a different document and so the test of is_valid is always the same document object.No.
Perhaps emphasising a couple of concepts might help, a "document" is the in memory buffers and associated metadata, it is not a "file" on disk. It might have an associated name of a disk file for saving to and checking if it changed in background, but it might not. There is absolutely no reason that a memory buffer can't exist and be edited happily without any file associated with it.
Note see the API
DOC_FILENAME
that can return a pointer that can distinguish "untitled" from real filenames.8151d8b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS also note the difference between
doc->file_name
which is the display name in UTF-8 anddoc->real_path
which is the file on disk path probably in the right "encoding" for the user system, maybe, possibly.