Giter Site home page Giter Site logo

sublimeclangformat's People

Contributors

adrian-tut avatar adriann avatar bblanchon avatar digiter avatar jasjuang avatar lnksz avatar moritzfago avatar mortenfyhn avatar rapimo avatar reicrof avatar rosshemsley avatar ryboe avatar sailormoon avatar temoto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sublimeclangformat's Issues

Please update all_settings in clang_format.py for clang format 3.7

There is a important new feature I would like to have that is only available in clang format 3.7, which is "AlignConsecutiveAssignments". I am able to run clang format 3.7 with this feature on command line. After sometime of digging into why passing this argument has no effect on sublime, I came to the conclusion that It looks like the fix is to add the new settings in all_settings in clang_format.py. Please update. Thank you!

Format on paste

Great tool!
I would love the feature to format the area just after pasting some code. Any idea of how complex this would be to implement, or pointers to where I should start to achieve this.

Cheers.

when formatting, the screen of ST moves to middle or rightmost..

I have been searching for this issue for several days, and have not found any solution to this.
As the title says, the screen of ST jumps to the middle or rightmost when formatting.
Here is my custom clang-format config.
{
"BasedOnStyle" : "Google",
"IndentWidth" : 5,
"AllowShortIfStatementsOnASingleLine" : "Always",
"TabWidth" : 4,
"AlignEscapedNewlinesLeft" : true,
"AllowShortIfStatementsOnASingleLine": true,
}
Please help!
Thank you.

wrong work with selection on file with multibyte symbols

How to reproduce
1. open file
/* Header with NLS UTF-8 symbols
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда
ываофыдаоывоалдывоадлыовадоывдаоыдлодоадфываоыдаоыфдаоыдваоыалыда

*/
int main(void)
{
    print_descriptor(0, 0, 0);
    print_descriptor(0,     0x000FFFFF, (GDT_CODE_PL0));
    print_descriptor(0, 0x000FFFFF, (GDT_DATA_PL0));
    print_descriptor(0, 0x000FFFFF, (GDT_CODE_PL3));
    print_descriptor(0, 0x000FFFFF, (GDT_DATA_PL3));

    return 0;
}

int main(void)
{
    // start selection here
    print_descriptor(0, 0, 0);
    print_descriptor(0,     0x000FFFFF, (GDT_CODE_PL0));
    print_descriptor(0, 0x000FFFFF, (GDT_DATA_PL0));
    print_descriptor(0, 0x000FFFFF, (GDT_CODE_PL3));
    print_descriptor(0, 0x000FFFFF, (GDT_DATA_PL3));

    return 0;
}

int main(void)
{
    print_descriptor(0, 0, 0);
    print_descriptor(0,     0x000FFFFF, (GDT_CODE_PL0));
    print_descriptor(0, 0x000FFFFF, (GDT_DATA_PL0));
    print_descriptor(0, 0x000FFFFF, (GDT_CODE_PL3));
    print_descriptor(0, 0x000FFFFF, (GDT_DATA_PL3));

    return 0;
}

int main(void)
{
    print_descriptor(0, 0, 0);
    print_descriptor(0,     0x000FFFFF, (GDT_CODE_PL0));
    print_descriptor(0, 0x000FFFFF, (GDT_DATA_PL0));
    print_descriptor(0, 0x000FFFFF, (GDT_CODE_PL3));
    print_descriptor(0, 0x000FFFFF, (GDT_DATA_PL3));
    // end selection here and press ctrl+alt+a
    return 0;
}
2. select in bottom code
3. press ctrl+alt+a
4. nothing happened (in correct variant we should see remove  intent from 0x000FFFFF

PROBLEM SOURCE
Offset option of clang get bytes offset (not a symbols offset)

  -offset=            - Format a range starting at this byte offset.
                              Multiple ranges can be formatted by specifying
                              several -offset and -length pairs.
                              Can only be used with one input file.



PATCH sorry can't remove PEP8 decoration

--- /tmp/clang-format.orig/clang_format.py
+++ /Packages/ClangFormat/clang_format.py

@@ -230,42 +248,54 @@
         else:
             regions = self.view.sel()
 
+        # Get all view to buf
+        buf = self.view.substr(sublime.Region(0, self.view.size()))
+        buf_bytes = buf.encode(encoding)
+
         # Deal with all selected regions.
         for region in regions:
             region_offset = region.begin()
-            print("region_offset="+region_offset)
             region_length = region.size()
 
             view = sublime.active_window().active_view()
+
+            # Get selection
+            sel = self.view.substr(region)
+            sel_bytes = sel.encode(encoding)
 
             # If the command is run at the end of the line,
             # Run the command on the whole line.
             if view.classify(region_offset) & sublime.CLASS_LINE_END > 0:
-                region        = view.line(region_offset)
-                region_offset = region.begin()
-                region_lenth  = region.size()
+                region = view.line(region_offset)
+
+            region_offset = region.begin()
+            region_length = len(sel_bytes)
+
+            # Convert offset from symbols to bytes
+            buf_before_sel = buf[:region_offset]
+            buf_before_sel_bytes = buf_before_sel.encode(encoding)
+            region_offset = len(buf_before_sel_bytes)
 
             # Add this region to the set of offsets.
             command.extend(['-offset', str(region_offset),
                             '-length', str(region_length)])
 
         # We only set the offset once, otherwise CF complains.
-        command.extend(['-assume-filename', str(self.view.file_name())] )
+        command.extend(['-assume-filename', str(self.view.file_name())])
 
         # TODO: Work out what this does.
         # command.extend(['-output-replacements-xml'])
 
         # Run CF, and set buf to its output.
-        buf = self.view.substr(sublime.Region(0, self.view.size()))
+
         startupinfo = None
         if os_is_windows:
             startupinfo = subprocess.STARTUPINFO()
             startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
-        p   = subprocess.Popen(command, stdout=subprocess.PIPE,
-                               stderr=subprocess.PIPE, stdin=subprocess.PIPE,
-                               startupinfo=startupinfo)
-        output, error = p.communicate(buf.encode(encoding))
-
+        p = subprocess.Popen(command, stdout=subprocess.PIPE,
+                             stderr=subprocess.PIPE, stdin=subprocess.PIPE,
+                             startupinfo=startupinfo)
+        output, error = p.communicate(buf_bytes)
         # Display any errors returned by clang-format using a message box,
         # instead of just printing them to the console. Also, we halt on all
         # errors: e.g. We don't just settle for using using a default style.

Force clang-format selection (Feature request)

In some files I turn off clang-format for the entire file using // clang-format off comments. In these cases, I may still want to format a selection of the file, which is tricky, because clang format selection has no effect due to // clang-format off. So I need to copy the selection, paste it in a different file, clang-format it there, and paste the result back in the original. file.

It would be nice if that could be automated with a new option: "Force clang-format selection"

Seems to work fine on ST2, why not supported?

Works fine on ST2 with a few formatting changes (basically just removing trailing commas) to config files. So, why is it not supported officially?
Initially I was suprised to see in package control that sublimeclang works on st2, whereas clang-format doesnt.

Unstable formatting in Sublime Text 4

sublime4-bug

When I press CTRL+S to format the document, the entire text buffer shifts to the left. The shifting also happened on the previous version, but then it was just one row down, so it was not as bad.

Removing tabs in the whole file even when formatting few lines

I format only using spaces, but work with files that might contain both tabs and spaces. When working in some files that have both and try to format only a few lines, all the tabs in the file are converted to spaces. If the file is large, this creates a big diff and can be quite annoying to revert all the spaces to tabs. Could we have only the selected lines be changed instead of the whole file ?
Thanks :)

Custom Format options using Settings Doesn't Seem to work at all

I'm on Ubuntu 12 with clang-format 3.4. The other predefined format styles work fine. However, when I try to edit and use the settings file for a custom format options, it doesn't recognize any of the key.

I get an error: unknown key,

then it says

Error parsing-style: invalid argument

It doesn't seem to matter which key I use, they all fail in the same manner.

Feature request: fallback-style

Please add a fallback-style setting to the user settings, that will add the fallback-style parameter from clang-format. I don't want any formatting when not style file is provided. Thanks in advance!

I Found "SortIncludes" is not worked

I do not want SortIncludes my #include files, so I add setting
{
...
"SortIncludes": false
...
}
is not worked.
My Config is sublime-text-3, clang-format 3.8

How to use BraceWrapping

Hello,

thanks for this very useful tool! I have a question related to bracewrapping, because I cannot make it work. A standard clang-format file should have something like this:

BraceWrapping:
  AfterClass:      false
  AfterControlStatement: false
  AfterEnum:       false
  AfterFunction:   true
  AfterNamespace:  false
  AfterObjCDeclaration: false
  AfterStruct:     false
  AfterUnion:      false
  BeforeCatch:     false
  BeforeElse:      false
  IndentBraces: false

How to replicate this in a custom style for this package?

Can't recognize tab-width

I hope this plugin can recognize the view's setting of tab_size automatically and use it in the process of formatting.

Custom Settings

Great Package! The clang-format has several styles to have, but I would like to use my own prefered style, I noticed there is “Custom” in the “Select Style” option, but I didn’t know how to configure that, I know the configuration file is exported as .clang-format, but how to apply it in the package?

Include directories in clang-format

Hi,
I have some .cpp files in ./src and their .h files in ./include. In the .cpp files, a bunch of errors show up saying, "could not find this file" when including the .h files, or "unknown type" when declaring objects from classes defined in the includes. Is there a way for the plugin to detect these other libraries? I am just beginning to program in cpp, I am sorry if the question is trivial or I said something wrong.

Thanks a lot for the help!

Raimon

format_on_save

For some reason, even though I have format_on_save as true, the file doesn't format. Clicking super+option+a seems to work though.

This is my config:

{
"style": "Google",
  "format_on_save": true
}


Fast auto-fix enabe/disable

Often I am working with another person's codebase, and need to disable fixing so I don't touch every line in a commit, of a file with a quick-change. I find this very handy, from standard format:

Screenshot 2023-04-14 at 5 56 18 PM

This is under "Sublime Text" / "Settings"

Also handy to add it to the command-palette:
Screenshot 2023-04-14 at 6 00 18 PM

Looks like they do it in the menu file. I can add a PR, if you're interested.

Please update all_settings in clang_format.py for clang format 3.8

There is an important new feature I would like to have that is only available in clang format 3.8, which is "AlignOperands". I am able to run clang format 3.8 with this feature on command line. Please update. Thank you!

I opened a pull request a week ago but got no response. Please look into it.

Allow custom file

We have our custom file in a certain directory. Sadly it seems like I cannot set a custom path to that format file.

Add support for Objective-C, Objective-C++

I started to make a Clang Format Sublime plugin before I discovered your plugin. Great work! One thing I'd like to ask is: would it be possible to add support for Objective-C, Objective-C++. The capability is already there in the clang-format binary, so it shouldn't be hard to add it.

Clang Format doesn't format whole file

In Sublime, I've enabled format on save, but the clang-format only applies on the current line the cursor is on, is it possible to clang format the whole file?

Possible to use yaml clang-format as config?

Hello and thanks for this plug-in, it was a breeze to install and get up and running.

I was wondering, is it possible to use a standard config file for this plug-in, written in yaml (such as ~/.clang-format or one at a user specified path)? I'd like this so that I could re-use the clang-format settings that are used by a different application.

cheers,
Rich

Specify ignore_folders

Is it possible to include a setting to ignore formatting certain folders / files? I have a bunch of thirdparty packages as submodules, and auto-formatting them on save messes up my builds!

clang-format: scrolls horizontally

Hi There!

I like this plugin but when clang-format is executed, the code scrolls horizontally (to the right) a bit. So if I use the format on save option, then each time I save it will scroll a bit. I don't use word-wrap and sometimes my code will continue further than the size of the editor.

I love using this plugin but this kind of irritates me!

Is there something we can do about this?

Many thanks on any help on this matter!

Regards!

Keybindings don't work under Linux and Windows

In linux and window, the option key is referred to as the alt key. This means that the keybindings do not work on Linux and Windows.

Solution: Change the option in Keybinding (Windows & Linux) to say alt instead of option.

Format on save

Hi

What should I do to automatically format a file when saving?

Additionally, if possible, I would like to enable that setting to my current project/workspace only (and not system wide).

Are you planning to support such feature?

Thanks

unknown key "BraceWrapping" in clang_format_custom.sublime-settings (default)

Hi! Something about the update to solve #49 has broken my ability to format. My clang_format_custom.sublime-settings (Clang format default) reflects the update, but when I go to actually format I get the error:

Clang format: YAML:1:254: error: unknown key 'BraceWrapping'
{AlignTrailingComments: true, AllowShortLoopsOnASingleLine: true, BasedOnStyle: LLVM, ColumnLimit: 150, AllowShortIfStatementsOnASingleLine: true, AllowAllParametersOfDeclarationOnNextLine: false, BinPackArguments: false, UseTab: Never, BraceWrapping: {}, TabWidth: 4, IndentWidth: 4}
^
Error parsing -style: Invalid argument

Add other file extensions for a given language

I want to format my CUDA code (suffixes ".cu" and ".cuh") using the C++ format. How can I specify the formatter to apply to ".cu" and ".cuh" files? Is there a line I can enter in the clang_format_custom.sublime-settings file?

AlignConsecutiveMacros does not work when set through Custom ST settings

I have the same style configuration written on a .clang-format file and the clang_format_custom.sublime_settings file (modulo whatever syntactic changes are necessary). The particular line of interest is the following.

"AlignConsecutiveMacros": "Consecutive", // .clang-format has: AlignConsecutiveMacros: Consecutive

Now, when I run this by first changing Clang Format: Select Style to File, then choosing Clang Format: Format Selection, I get the correct result (most of the times): namely, the preprocessor macros of consecutive lines are aligned. However, if I change Clang Format: Select Style to Custom and then choose Clang Format: Format Selection, then the macros are all unaligned.

I am seeing this bug on two of my Fedora 32 machines using Sublime Text 4 (build 4113).

For Cud

Hello
do you think it's easy to "port" clang-format to CudaText?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.