Codemirror - Get editor lines number - line

I'm trying to get the number of lines in the codemirror editor to check if the editor contains more or less rows then some minutes befor. Is there any method or function in codemirror to do so?

I used the function
var lines = editor.lineCount();

you can also use: editor.doc.size

Related

Formatting column in pandas to decimal places using table.style based on value

I am trying to format a column in a dataframe using style.
So far I successfully used the styling for a fixed number of decimals:
mytable.style.format('{:,.2f}', pd.IndexSlice[:, ['Price']])
but I need to expand this to formatting based on value as this:
if value is >=1000, then format to zero decimal places
if value is between 1000 and 1, then format to two decimal places
if value is < 1, then format to five decimal places
Does anyone have a solution for this?
Thank you!
Building upon #Code_beginner's answer – the callable should return formatted string as output:
def my_format(val):
if val >= 1000:
return f"{val:,.0f}"
if val >= 1:
return f"{val:,.2f}"
return f"{val:,.5f}"
mytable.style.format({'Price': my_format})
What you are looking for is called "conditional formatting". In which you set the conditions like you described and return the right format. There are examples in the documentation, they used a lambda function there. But you can also create a normal function which might look something like this:
def customfunc(val):
if val>=1000:
format='{:,.0f}'
if val<1000 and val>=1:
format='{:,.2f}'
if val<1:
format='{:,.5f}'
return format
df.style.format({0:customfunc})
This should style your first column like described in your problem. If the columns has a name you have to adjust it accordingly. If you have trouble see the documentation linked abve there are more examples.
Just to have it visually clear, this is how it looks now:
That's my line of code:
df.style.format({'Price': customfunc})

How to format code to use the specified `tabSize` with the built-in formatter?

I have the following AutoHotkey script sample, notice the code is indented by a single space:
#z::
MsgBox The Win-Z hotkey was pressed.
Gosub MySubroutine
return
MySubroutine:
Sleep 1000
return
I searched through the VS Marketplace but didn't find a usable formatter extension for AHK scripts.
I've configured "editor.tabSize": 2, is there a way to format the code to use the specified tabSize with the VSCode built-in formatter?
It looks like there is an AutoHotKey Plus extension that includes formatting that seems to adhere to the Visual Studio Code built-in formatter setting for the tab size. I set my tab size to two and performed the format shortcut using the extension (Shift + Alt + F):
It seems though that certain keywords, such as return will cling to the margin, presumably because the formatter for the extension interprets this as the standard convention for AHK (in my opinion though, I like the way it looks).
This feature request is tracked here.

How to set IDEA better align parameters passed to some method?

I cannot make IDEA perfectly align parameters passed to some method when I break them into new line by Enter key.
Here is visually what I need. I have a method like this.
When I break parameters into new row each, it looks like this.
Even trying to align them with Tab key does not help.
You see how ugly this is, not to say it's not easy to reach such code. And all I want is too look like this:
(Note: this one I set via Space key).
I must have been doing something wrong as I can bet this can be set in IDEA. But where?
Bring up Settings panel :
Code Style > Java > Wrapping and Braces (tab)
Enable Align when multiline option in Method declaration parameters and Method call arguments
Apart from the way suggested by #Rangi Lin, also make sure that your
Code Style > Java > Keep When Reformating > Line Breaks
in your settings is also checked. Otherwise reformatting your code could realign your method params into a single line.

Reformatting to have method parameters in a new line

There are so many settings in the preferences for Code->Style->Objective-C. I'm looking for the right one to reformat this line of code
SCPropertyDefinition *test = [SCPropertyDefinition definitionWithName:#"created_at" title:#"Tweeted At" type:SCPropertyTypeLabel];
to this format
SCPropertyDefinition *test = [SCPropertyDefinition definitionWithName:#"created_at"
title:#"Tweeted At"
type:SCPropertyTypeLabel];
(the point is to have the colons indention matching)
I guess the it should be in the Wrapping and Braces Tab, but I havn't found the right setting yet.
Thanks for your ideas.
The setting you are looking for is Wrapping and Braces | Method call arguments set to Chop down if long with enabled Align by colon. Note that there are separate settings for Method parameters.
It seems like as of App Code 2017.1 (perhaps earlier too) the align by colon option is not available in Swift. You can still tell App Code to chop a long argument/parameter list:

How do I force opening braces to share the previous code line?

Using the Uncrustify tool I would like to apply the 1TBS style, which places braces like this:
if (x < 0) {
printf("Negative");
}
How do I do this? I can't seem to find the right options.
I think you need to set nl_if_brace to ignore/add/remove/force.
Also, check the sp_else_brace and sp_brace_else options. Set it to 1, otherwise your code will end up with code such as:
if (condition){
instead of
if (condition) {
There's a tool called UniversalIndentGui that lets you play with Uncrustify's various tersely-worded settings and see immediate impact on a block of sample code.
Screenshots of UniversalIndentGUI