Commit 57c8bfa3 authored by Kai Willadsen's avatar Kai Willadsen

Assume same file type if not available for all files (closes bgo#658407)

For the purpose of syntax highlighting, we always try to determine the
mime type of files, currently using only the filename. In situations
where the filename tells us nothing, we can reasonably assume that all
files have the same type.

This commit changes our behaviour so that, if we get one useful file
type, we use it to fill in missing file types in the remaining files.
This should specifically help with cases where temporary files are
given different extensions. e.g., TortoiseSVN uses .mine, .working, etc.
parent 870ab2ba
......@@ -1093,11 +1093,21 @@ class FileDiff(melddoc.MeldDoc, gnomeglade.Component):
langs = []
for i in range(self.num_panes):
filename = self.bufferdata[i].filename
if filename:
lang = srcviewer.get_language_from_file(filename)
srcviewer.set_language(self.textbuffer[i], lang)
# If we have only one identified language then we assume that all of
# the files are actually of that type.
real_langs = [l for l in langs if l]
if real_langs and real_langs.count(real_langs[0]) == len(real_langs):
langs = (real_langs[0],) * len(langs)
for i in range(self.num_panes):
srcviewer.set_language(self.textbuffer[i], langs[i])
yield 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment