gjy5885's blog

By gjy5885, history, 5 weeks ago, In English,

Upd2: This video(https://www.youtube.com/watch?v=XLcKRaw7QtQ&feature=youtu.be) can help better show my problem. Upd1: Instead of reformatting my code, I want to implement real-time space completion in coding.

Hi everyone, For example, if I type "x=1", there are no spaces, unless I manually add them. For convenience and productivity reasons, I’m looking for an automatic way to get: "x = 1". This means that when I enter "=" is equivalent to input " = ". The operator may be =,+,-,/,*,etc. Recently, I have seen similar functions on the website: https://wingware.com/hints/auto-editing#:~:text=When%20enabled%20with%20the%20Editor,Wing%20will%20enter%20x%20%3D%201. It's called Auto-Enter Spaces, but only for Python. Since my main language is C++, I hope to find similar functions for C++. If anyone helps me, thank you very much!

 
 
 
 
  • Vote: I like it
  • +4
  • Vote: I do not like it

»
5 weeks ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it
Deleted
»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by gjy5885 (previous revision, new revision, compare).

»
5 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

Hi
I think what you're looking for is a Code Formatter
But idk what text editor/IDE you use
But you can try this and choose your coding style from the list preferably Google

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thank you so much, I was looking for this too. Before knowing this site I usually do it manually or make a C++ to format it

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

If you use Sublime text 3, you can install CoolFormat from Package Control and use Ctrl + Shift + Alt + Q to format whole code.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it +3 Vote: I do not like it

    Thx! Instead of reformatting my code, I want to implement real-time space completion in coding.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Assuming you use Vim, there are plugins like ALE that you could use. I've only used it for linting Javascript, but stuff like cpplint and clang-tidy exist so it probably works.

»
5 weeks ago, # |
  Vote: I like it +124 Vote: I do not like it
You won't believe
»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

And without jokes, modern IDEs have hotkeys

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thx! Instead of reformatting my code, I want to implement real-time space completion in coding.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by gjy5885 (previous revision, new revision, compare).

»
5 weeks ago, # |
Rev. 3   Vote: I like it 0 Vote: I do not like it

I think what you're trying to hint is known as format-as-you-type/format-on-type feature.

There are many language servers which can do this, I personally use LLVM's clangd in VSCode. It's easy to setup clangd on VSCode and performance is quite good. Besides formatting, clangd also has many cool features because of its integration with the LLVM compiler infrastructure.

I get the formatting done automatically when I break the expression by using {, ;, or ).

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by gjy5885 (previous revision, new revision, compare).

»
5 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

If you're using vscode, there's "format on type". It format each after typing.

  • »
    »
    5 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Sorry, I can't find "format on type" in vscode.

»
5 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

I suggest you try running an auto-formatter (e.g. clangformat or equivalent) automatically when saving the source code file. This way it's not so intrusive that it interferes with your typing flow. All decent IDEs should be able to be configured to run commands on save, and there should be a bunch of tutorials on the internet on how to configure them.