This will transcode a file to UTF-8 with a best effort to use the correct encoding, looking at byte order mark, extended attributes, .tm_properties, and falling back on frequency analysis.
The reason for this is mainly that the path given to path_attributes() might be a virtual path, in which case using that to obtain settings can cause problems. For example if the (virtual) path is ‘/net/some/long/path’ (rmate) then we’ll hit that path locally, but stat’ing paths under /net can take seconds.
Also, the ‘scopeAttributes’ read from the user settings isn’t technically path attributes. Though the feature this allows is that we can scope the encrypt/decrypt export/import commands to ‘attr.enable-encryption’ and then put something like this in a project’s .tm_properties:
[ private/** ]
scopeAttributes = "attr.enable-encryption"
Generally we should always provide a base environment, since the scoped variables are format strings. The filtering scope selector is however optional, and we do not have one when executing commands outside an fi;e/editor context.
Only the file browser and the ‘path_variables’ function (used for filters) made use of this method to set the working directory. Previously drop commands also used it, which is probably the only time we really need to set a working directory, as we provide the command with a relative file path.
These are now all prefixed with what they are obtaining variables for (scope, document, bundle, …) which makes it easier to analyze/refactor the code.
Also change document_t’s settings function to document_settings.
We need this in a few places and while calling Gestalt() isn’t that much code, that function is deprecated in 10.8 and the alternative is a lot more code, so we don’t want to repeat that once we update the code.
This is for attr.project.XXX and attr.scm.XXX, although the latter is also provided by scm::info_t.
With this commit, the file::path_attributes function no longer collect this information.
We didn’t actually use the file itself, only its parent directory, and there are several places we want SCM info for an untitled file’s project directory, so removing the need for a file simplifies things.
There is also a new document_t::encoding_for_save_as_path which returns the encoding that would be used for the document, if saved at the given path. If the document was loaded from disk, it will return the encoding used during load, otherwise it will check tmProperties for which encoding should be used for the path provided. Save dialog for untitled documents will be pre-populated with the result of the above function.
The main reason to avoid this is to give a more predictable API. Encoding should be read (from tmProperties) prior to calling file::save and then given as argument.
This includes a minor improvement to handling of virtual paths (i.e. files opened via rmate).
It also slightly changes the logic related to finding file type. It now prefers an explicit user binding (only when there is a path) falling back on content match, then path match via grammar, then user binding for untitled files, and finally user binding for unrecognized files.