Clang-format Sublime Text Plugin

Hello,

the clang-format sublime text plugin doesn't work reliably, because Sublime
Text's self.view.encoding() doesn't return values that are compatible with
buf.encode. I attach a version that does a manual conversion between these
values. I don't know whether Sublime Text provides a better API for this, but
cursory googling did not reveal anything.

Greets,

Adrian

clang-format-sublime.py (3.76 KB)

How does this compare to this:
https://packagecontrol.io/packages/Clang%20Format

?

It comes from the llvm.org svn and it works with Sublime Text 2.

How does this compare to this:
https://packagecontrol.io/packages/Clang%20Format

?

It comes from the llvm.org svn and it works with Sublime Text 2.

Oh, I understand, I wrote the one from llvm.org. I would just think that
the other one is probably far superior and we should maybe entirely remove
the one from llvm.org. If not, I'd like to know what the differences are.

The other one has many more features and is easier to install, but it doesn't
work for ST2 as far as I understand. Because of this incompatibility removing
the llvm version from the web would leave ST2 users like me without a plugin.

The other one has many more features and is easier to install, but it
doesn't
work for ST2 as far as I understand. Because of this incompatibility
removing
the llvm version from the web would leave ST2 users like me without a
plugin.

If it doesn't work for ST2, why not? Can we make it compatible? How is it
handling the encoding problems you are having? Lets try not to maintain two
distinct plugins and if we have to, lets at least try to keep them in sync.

I agree that having two diverging plugins is not optimal. I will try to
contact the author of the other plugin. I think however that it would make
sense to fix the encoding problem in the svn version of the llvm plugin until
this is resolved.

Sure, but I have briefly looked at the source code of the other plugin and they seem to be able to cope without a big table of encodings. Either they aren’t having this problem yet, or they have a better way to solve it. I’d like to find out which (and I don’t know much about sublime myself). Could you also send your change as a diff against the SVN version? Makes it much easier to see what you actually changed.

I also had a look at the other plugin. Either ST changed its interface or they
have the same problem, I think.

Linke Datei: C:\Users\z003fuea\Downloads\clang-format-sublime.py
Rechte Datei: C:\Users\z003fuea\AppData\Roaming\Sublime Text
2\Packages\User\clang-format-sublime.py
28a29,68

st_encodings_trans = {
   "UTF-8" : "utf-8",
   "UTF-8 with BOM" : "utf-8-sig",
   "UTF-16 LE" : "utf-16-le",
   "UTF-16 LE with BOM" : "utf-16",
   "UTF-16 BE" : "utf-16-be",
   "UTF-16 BE with BOM" : "utf-16",
   "Western (Windows 1252)" : "cp1252",
   "Western (ISO 8859-1)" : "iso8859-1",
   "Western (ISO 8859-3)" : "iso8859-3",
   "Western (ISO 8859-15)" : "iso8859-15",
   "Western (Mac Roman)" : "mac-roman",
   "DOS (CP 437)" : "cp437",
   "Arabic (Windows 1256)" : "cp1256",
   "Arabic (ISO 8859-6)" : "iso8859-6",
   "Baltic (Windows 1257)" : "cp1257",
   "Baltic (ISO 8859-4)" : "iso8859-4",
   "Celtic (ISO 8859-14)" : "iso8859-14",
   "Central European (Windows 1250)" : "cp1250",
   "Central European (ISO 8859-2)" : "iso8859-2",
   "Cyrillic (Windows 1251)" : "cp1251",
   "Cyrillic (Windows 866)" : "cp866",
   "Cyrillic (ISO 8859-5)" : "iso8859-5",
   "Cyrillic (KOI8-R)" : "koi8-r",
   "Cyrillic (KOI8-U)" : "koi8-u",
   "Estonian (ISO 8859-13)" : "iso8859-13",
   "Greek (Windows 1253)" : "cp1253",
   "Greek (ISO 8859-7)" : "iso8859-7",
   "Hebrew (Windows 1255)" : "cp1255",
   "Hebrew (ISO 8859-8)" : "iso8859-8",
   "Nordic (ISO 8859-10)" : "iso8859-10",
   "Romanian (ISO 8859-16)" : "iso8859-16",
   "Turkish (Windows 1254)" : "cp1254",
   "Turkish (ISO 8859-9)" : "iso8859-9",
   "Vietnamese (Windows 1258)" : "cp1258",
   "Hexadecimal" : None,
   "Undefined" : None
}

31,32c71,72
< encoding = self.view.encoding()
< if encoding == 'Undefined':

Sorry for necro-ing this thread.

I have now installed Sublime Text 3 and confirmed that the bug also appears in
the Sublime Text 3 plugin. I was able to add a patch to that plugin's Github
repository. I still think that we should also fix the Sublime Text 2 plugin
from the clang repository, or else remove it completely.

Greets,

Adrian