How to align multi line array in Vscode - visual-studio-code

In PhpStrom there are some facilities which are short array Align when multiline and many more
Here is an example
http://prntscr.com/pyfkc8
Another Link
Now I want to align array in vs-code ....
How can I do that?
This is a normal Array
$x=array(
0 => "zero",
123122 => "one two three",
251=> "two five"
);
Now I want Like this
$x=[
0 => "zero",
123 => "one two three",
25 => "two five"
];
Is this possible is vs-code?

I think you are looking for a extension called "ALIGNMENT"
JUST INSTALL IT AND ALIGN THE SECTION OF CODE YOU WANT JUST BY
SELECTION.
HERE is a list of Extension:
https://marketplace.visualstudio.com/search?term=tag%3Aalignment&target=VSCode&category=All%20categories&sortBy=Relevance
And Here is the Extension i'm talking about:
https://marketplace.visualstudio.com/items?itemName=annsk.alignment

Related

vscode if/else conditions in user defined snippet

Looking at the vscode documentation for user defined snippets, it would appear that using the regex transform, you can do if/else conditions.
However, I can't seem to find any examples of this and I'm struggling to understand the correct syntax based on the BNF alone.
Can someone explain the syntax for this?
For example,
Lets say I have a snippet like this:
"body": [
"let color = '${1|white,black|}';",
"let hex = '${???}';"
]
If color==white, I want hex to output #fff, otherwise if black #000.
This works:
"color conditional": {
"prefix": "_hex",
"body": [
"let color = '${1};",
"let hex = '${1/(white)|(black)|(red)/${1:+#fff}${2:+#000}${3:+#f00}/}';" //works
],
"description": "conditional color"
},
However, as soon as I try it with default placeholders and choices, like
"let color = '${1|white,black|}';", // does not work
Apparently, you cannot do snippet transforms on default placeholder values. See transforms on placeholder values issues
I used the simpler if transform style, so here:
${1/(white)|(black)|(red)/${1:+#fff}${2:+#000}${3:+#f00}
if there is a group 1 $[1} in this case white then replace that group 1 with #fff and if group 2 (black) replace with #000, etc.
You could make it just an if/else (white) or not pretty easily.
"let hex = '${1/(white)/${1:?#fff:#000}/}';" // any non-`white` entry will print `#000`.
${1:? => if group 1 (white) print #fff , else print #000
The vscode docs are not very helpful on these conditional replacements, if you have more questions on their syntax, let me know.

OpenOffice::OODoc - How to insert Horizontal Line/Rule in a Page

I am creating ODF Document using OpenOffice::OODoc module. I want to have a Horizontal Line/Rule after a Heading.
I have seen documentation but it has no solution for this problem. I even tried to insert a paragraph with border, but it leaves a vertical white space after top border and next line.
Any idea how can this be done?
I've noticed that there are two methods--which I'm aware of--to
accomplish this task. There's Insert > Horizontal Ruler or by applying
a bottom border to the a paragraph.
From what it appears, the "Horizontal Ruler" is just an image inserted
in the text. - OpenOffice forum
So I think you could use an image (which contains a line).
$document->createImageStyle
(
"NewImageStyle",
properties =>
{
'draw:luminance' => '20%',
'draw:color-inversion' => 'true'
}
);
$document->createImageElement
(
"Image1",
style => "NewImageStyle",
attachment => $newparagraph,
import => "path\to\rule.jpg"
);

Why not have Lists build the other way around and have them append elements?

Since in Scala lists are actually build like (here for List(1,2,3)) this:
[ 1 , [ 2, [ 3 , Nill ] ] ] // (pseudo-code)
it is more efficient to pretend new elements and that is why :: is right associative (all explained in https://stackoverflow.com/a/1162980/4533188) - to be better readable (here 1 :: 2 :: 3). That answers my question, why it's good to have right association in the first place. But why didn't the designers of Lists simply construct them like
[ Nill , [ 3, [ 2 , 1 ] ] ] // (pseudo-code)
internally and use conventional left association?
Here in a graphic what my pseudo-code is supposed to mean (since it does not show the "links" of the linked list):
Because an append-list wouldn't be immutable (or you'd have to copy it in its entirety on each change).
See https://en.wikipedia.org/wiki/Linked_list for mre.

Perl checkbox group subgroupings

I'm trying to make a checkbox group in Perl with sub-titles dividing certain checkboxes. All the checkboxes are related, but they are in subcategories that I would like to be displayed when the user is selecting their choices.
my $grocery_list = $q->checkbox_group(
-name=>'grocery_list',
-values=>\#items,
-linebreak=>'true',
-labels=>\%items,
In the above example, I might have 'Milk' and 'Cheese' be under the subcategory of "DAIRY", while 'Ham' and 'Turkey' are under the subcategory of "MEATS". I already have a checkbox group with my values but I'm struggling creating those subcategory titles (DAIRY and MEATS) in between the subgroups of checkboxes. Ideally, the subcategory titles wouldn't be checkboxes, but would just divide checkboxes. Is it possible to put these subdivisions in a single checkbox, or would I have to make multiple checkboxes and merge the checked items into a single array afterward?
Note that CGI is no longer considered to be best practice. You should read CGI::Alternatives for an explanation, as well as suggestions for alternative modules.
You need the fieldset and legend elements to do what you describe. Without any additional CSS, the former draws a box around the group of inputs that it contains, and the latter labels that box.
Unfortunately, the checkbox_group convenience method doesn't allow you to subdivide its elements between two field sets, so you will have to call it twice with the same parameters except for the values and labels. It may be better to write your own helper routine that calls checkbox directly to build appropriate grouping.
Here's the basic idea. There's nothing magical about the CGI methods -- they just generate HTML according to the parameters you pass.
my %labels = (
milk => 'Milk',
cheese => 'Cheese',
ham => 'Ham',
turkey => 'Turkey',
);
my #dairy_items = qw/ milk cheese /;
my #meat_items = qw/ ham turkey /;
my $dairy = $q->checkbox_group(
-name => 'grocery_list',
-values => \#dairy_items,
-linebreak => 'true',
-labels => \%labels,
);
my $meat = $q->checkbox_group(
-name => 'grocery_list',
-values => \#meat_items,
-linebreak => 'true',
-labels => \%labels,
);
print
$q->start_form,
$q->fieldset(
$q->legend('Dairy'),
$dairy,
),
$q->fieldset(
$q->legend('Meat'),
$meat,
),
$q->end_form;

How to align a label versus its content?

I have a label (e.g. "A list of stuff") and some content (e.g. an actual list). When I add all of this to a PDF, I get:
A list of stuff: test A, test B, coconut, coconut, watermelons, apple, oranges, many more
fruites, carshow, monstertrucks thing
I want to change this so that the content is aligned like this:
A list of stuff: test A, test B, coconut, coconut, watermelons, apple, oranges, many more
fruites, carshow, monstertrucks thing, everything is startting on the
same point in the line now
In other words: I want the content to be aligned so that it every line starts at the same X position, no matter how many items are added to the list.
There are many different ways to achieve what you want: Take a look at the following screen shot:
This PDF was created using the IndentationOptions example.
In the first option, we use a List with the label ("A list of stuff: ") as the list symbol:
List list = new List();
list.setListSymbol(new Chunk(LABEL));
list.add(CONTENT);
document.add(list);
document.add(Chunk.NEWLINE);
In the second option, we use a paragraph of which we use the width of the LABEL as indentation, but we change the indentation of the first line to compensate for that indentation.
BaseFont bf = BaseFont.createFont();
Paragraph p = new Paragraph(LABEL + CONTENT, new Font(bf, 12));
float indentation = bf.getWidthPoint(LABEL, 12);
p.setIndentationLeft(indentation);
p.setFirstLineIndent(-indentation);
document.add(p);
document.add(Chunk.NEWLINE);
In the third option, we use a table with columns for which we define an absolute width. We use the previously calculated width for the first column, but we add 4, because the default padding (left and right) of a cell equals 2. (Obviously, you can change this padding.)
PdfPTable table = new PdfPTable(2);
table.getDefaultCell().setBorder(Rectangle.NO_BORDER);
table.setTotalWidth(new float[]{indentation + 4, 519 - indentation});
table.setLockedWidth(true);
table.addCell(LABEL);
table.addCell(CONTENT);
document.add(table);
There may be other ways to achieve the same result, and you can always tweak the above options. It's up to you to decide which option fits best in your case.