Format code #7636
Replies: 1 comment
-
Posted at 2018-02-23 by Wilberforce I don't believe there is anything built in. Save to a file and then format in another editor? Posted at 2018-02-23 by coopjmz Yes, I just use online formatter. But I think IDE without code formatting... Posted at 2018-02-26 by @gfwilliams You're right - there's no code formatter in the IDE. One could be added relatively easily if anyone felt like it though. Posted at 2018-02-26 by Chaapu Code formatting will be really awesome to have. Posted at 2021-05-29 by neshanjo Hi together, I'd like to bring attention to this topic again. I think it would be really great to have a code formatter available. Not only does it unify our code base e.g. in BangleApps, it can also prevent bugs (for instance, the typical if without braces problems, see https://softwareengineering.stackexchange.com/a/16530). I'm also willing to help implementing this (however, I'm not familiar with the code of EspruineWebIDE yet, so I'd need some help where to get started). Posted at 2021-05-29 by Robin Sat 2021.05.29
The repository: Here is an online open source solution:
Posted at 2021-05-29 by neshanjo Thanks. I've seen the the Github repo for EspruinoWebIDE. Anyway, it will take some time to understand how everything works... Maybe already some simple questions: Should this be implemented as a plugin? How can the formatter be registered to a certain key combination? And, regarding the beautifier link, why not use prettier?
It is also open source and supported in almost any IDE - so it would provide consistent results also between different tools... Posted at 2021-06-03 by JumJum @neshanjo
get/setCursor principally seems to do the trick, however, it changes the scrolling position. The line with the cursor becomes the last line in the editor window. You can try this by e.g. using large app code like https://github.com/espruino/BangleApps/blob/master/apps/trex/trex.js Posted at 2021-07-07 by JumJum @neshanjo great to see what you did. Your point of adding setCursor, great idea. Thanks for your nice feedback. Applause is what keeps artists going ;-) Beautifier was the first I used and it worked. Posted at 2021-07-08 by @allObjects
from @jumjum is very useful. Because often I use human formatting rather that machine formatting for the code to have a better visualize for repetitive source lines (such as lines 13 thru 27 in first code block in post http://forum.espruino.com/comments/13218059/ - part of the conversation about Modular and extensible UI framework and ui elements.). To go a step further, I'd suggest to add a directive (as JS comment) that turns it off and on again, so the manual selection and formatting falls away. No matter what on formatting the whole file, the section(s) marked stay(s) untouched where as all other areas are formatted. Posted at 2021-07-08 by neshanjo https://prettier.io/docs/en/ignore.html#javascript You can ignore certain lines/parts of the code with this special comment. Implemeting "format only the selected code" is possible by using the Editor properties. This could be the next feature in another PR. Posted at 2021-07-09 by JumJum Just checked an idea for "format only the selected code" in my environment.
Posted at 2021-07-09 by neshanjo @jumjum Edit: Have a look at https://codemirror.net/doc/manual.html#api and try using |
Beta Was this translation helpful? Give feedback.
-
Posted at 2018-02-22 by coopjmz
How can I format code in Espruino IDE? Any hotkey? I can't find anythyng...
Beta Was this translation helpful? Give feedback.
All reactions