When I type a period after an end, this is the indenting I get:
a() ->
receive
{abc, Val} ->
io:format("Val: ~w~n", [Val])
end.
On the other hand, if I type a comma after an end, the end slides to the left:
a() ->
receive
{abc, Val} ->
io:format("Val: ~w~n", [Val])
end,
I wish a period would make the end slide to the left as well.
And, in the first example if I select the whole function clause and choose Erlang > Indent > Indent Region from the menu bar, I get:
a() ->
receive
{abc, Val} ->
io:format("Val: ~w~n", [Val])
end.
Why am I unable to get that indenting automatically? In fact, I think that after I type end, the end should automatically move to the left and line up with the receive--before I type any punctuation. It shouldn't matter what punctuation follows.
Related
I have add Prettier in my VScode but I want to format my code only when I highlight my code,
say
let a = [1, 2, 3, 4]; (line1)
let b = [ 1,2 ,3,4]; (line3)
how can I just format line 1 when I highlight line 1 only and the result should be
let a = [1, 2, 3, 4]; (line1)
let b = [ 1,2 ,3,4]; (line3)
thanks
UPDATE:
I know we can format the code in a code block. But what I want to do is
const test = (a, b, c) => { (line 1)
console.log("show a", a); (line 2)
console.log("show b", b); (line 3)
}
If I highlight b, c in line 1 and format it. It only formats the code in line 1 but not 2 and 3
futher update:
this is my vscode shortcut setting
when I highlight like this,
it becomes like that
I dont know the solution yet, but there are some info that may help.
Basically, there are something wrong with the linter. ( https://github.com/prettier/prettier-vscode/issues/137 )
And your may fix it by checking out this https://prettier.io/docs/en/integrating-with-linters.html ,
I dont know how & didnt try. cuz:: [[
looks complicated (download many things) & mess up with the project structure
may not even work
some info I have no knowledge of / incompatible with my understanding
dont know what will happen to my linters
dont know what is the next step
[]
https://github.com/prettier/prettier-vscode/issues/134
[]
No, the issue is with prettier-eslint not supporting range formatting.
...
I would suggest switching to the recommended approach of integrating ESLint and Prettier
https://github.com/prettier/prettier-vscode/issues/137
[]
let Prettier do the formatting and configure the linter to not deal with formatting rules. You can find instructions on how to configure each linter on the Prettier docs site.
...
For details refer to the Prettier documentation.
https://github.com/prettier/prettier-vscode#linter-integration
[]
Linters usually contain not only code quality rules, but also stylistic rules. Most stylistic rules are unnecessary when using Prettier, but worse – they might conflict with Prettier! Use Prettier for code formatting concerns, and linters for code-quality concerns, as outlined in Prettier vs. Linters.
Luckily it’s easy to turn off rules that conflict or are unnecessary with Prettier, by using these pre-made configs:
eslint-config-prettier
stylelint-config-prettier
https://prettier.io/docs/en/integrating-with-linters.html
[]
I would like to format my code with prettier, then apply all eslint fixes. Previously, this could be achieved by setting prettier.eslintIntegration to true. Now, the extension say that this option is [DEPRECTAED] and prettier-eslint should be used instead. However, it's not clear how to use prettier-eslint in vscode.
https://github.com/prettier/prettier-vscode/issues/999
Actually, "format only selected code" is working on my end, I didnt do any fancy extra config.
What you need to pay attention to is the "syntax tree"
-- ie: dont blindly select across the scope (the bracket {}).
#eg::
given
function test() {
let a = [1, 2, 3, 4];
let b = [ 1,2 ,3,4]; // select only this line
return false
}
if you only select::
let b = [ 1,2 ,3,4];
then press ctrl+k, ctrl+f
everything is fine
if you select across the bracket (the } for function scope)::
let b = [ 1,2 ,3,4]; // select only this line
return false
}
then press ctrl+k, ctrl+f
the whole thing in the bracket (the } for function scope) gets formatted
the "syntax tree" in a class is a bit weird.
-- ie: if you select the WHOLE function AA & format it -- codes inside another function BB will also get formatted...
you may need to apply // prettier-ignore somewhere to prevent formatting
prettier-ignore
A JavaScript comment of // prettier-ignore will exclude the next node in the abstract syntax tree from formatting.
https://prettier.io/docs/en/ignore.html
(note, it seems there is no ending tag for // prettier-ignore for Javascript (at current stage of Prettier))
for the meaning of a "syntax tree", see ex below
if you place it above the code line
seems it applies to the item (the code) (-- which is a "syntax tree node") directly below ((empty lines not counted for)) the // prettier-ignore line
-- eg-below: console.log("show a", a);, and ends there.
if you place it behind the code line (inline)
seems it applies to the inline code only
#for_your_case-do_this:
const test = (a, b, c) => {
// prettier-ignore
console.log("show a", a);
// prettier-ignore
console.log("show b", b);
}
// or
const test = (a, b, c) => {
console.log("show a", a); // prettier-ignore
console.log("show b", b); // prettier-ignore
}
Select the code you want to format and press CTRL + SHIFT + P to open the command pallette. Then type in "format" and select format selected code. Or you can select your code and press right click which should bring up a context menu where you can select the option
Select the code or leave the cursor in the row you want to format and press Ctrl + K Ctrl + F.
I have an input file that I scan each line until the end. I use the first character as an indicator as what I want to do: 1. paused for x cycles, 2. write a 16-bit word serially, 3. write one bit at a time, 4 end of file.
The issue is that I see an extra mode in between the first p to w transition.
I tried printing out the string value of my variable "mode" but what I see is printed on the wave in between the first p and w is an additional mode not specified in my case statement.
at time = 0: mode equals " " (blank, nothing, all fine)
at time = A: mode now equals "p" (paused 4 cycles long, sure fine, I can fix this later)
at time = B: mode now equals "[]" (ERROR! this is not the next line)
at time = C: mode now equals "w" (back to normal)
input file:
p 10
w DEAD
w BEEF
p 5
b HHLL
p 100
eol
I have my systemverilog code that is suppose to scan the input file:
$fscanf(fd, "%c %h", mode, mystr);
case(mode)
"p": begin
wait_v = mystr.atoi();
repeat ( wait_v) begin
//turns bits on or off, but only modifies wire outputs and not mode
end
end
"w": begin
data = mystr.atohex();
// writes data, each character is 4 bits. each word is 16 cycles
end
"b": begin
lastsix = mystr.atobin();
// writes data outputs either high or low, each character is 1 cycle long
end
"eol": begin
$fclose(fn);
$stop;
end
Expected:
time => 0: mode equals " " (blank, nothing, all fine)
time => A: mode now equals "p" (paused for 3 cycles)
time => C: mode now equals "w" (back to normal)
Actual:
time => 0: mode equals " " (blank, nothing, all fine)
time => A: mode now equals "p" (paused 4 cycles long, sure fine, I can fix this later)
time => B: mode now equals "[]" (ERROR! this is not the next line)
time => C: mode now equals "w" (back to normal)
When you use %c in scanf it will read the very next character. When you use %h it will read a hex value, stopping after the last valid hex digit, and not reading what is next. So after your first fscanf call, the input will be pointing at the newline a the end of the first line, and the next fscanf call will read that newline with %c, and you'll get mode == "\n"
What you probably want is to use " %c%h" as your format -- note the (space) before the %c. The space causes fscanf to read and discard whitespace. Since %h automatically skips whitespace before reading a number, you don't need the space before it.
The first typed letter should match the first letter of every word of the result in the drop down.
Currently I am matching with any letter in the option like below but I should be match only starting letter(s) of any word in the option.
My current logic is below,
return this.allUniversities.filter(university => university.toLowerCase().indexOf(filterValue) > -1);
If the entry in the list is Industrial Designer, then this entry should show up if a candidate types the letter I or the letter D. It should not show up if the candiate types the letters ‘N, D, U, S’ etc.
All you need to do is split the string and then check if the substrings start with the typed characters:
return this.allUniversities.filter(university => {
return university.toLowerCase().split(' ').some(substr => substr.startsWith(filterValue));
});
Here
is a stackblitz that shows it in action.
I've modified the variable paragraph-start to count lines starting with .*: as a paragraph start:
(setq paragraph-start "\f\\|[ \t]*$\\|[ \t]*[0-9.]\.\\|.*:$\\|" )
However, if I have a buffer:
foo:
bar:
baz: some stuff
more
_
(Where _ indicates point location)
Then the first backward-paragraph skips to the beginning of the line 'bar:', not the line starting with 'baz:' as expected. How do I change this behaviour/why is it behaving this way?
It's because you have $ after ::
"\f\\|[ \t]*$\\|[ \t]*[0-9.]\.\\|.*:$\\|"
$ matches at the end of a line. So the part of your regexp that matches something followed by : also requires that nothing follow the :.
The first line (going backward from point) that ends in a : is the bar: line.
(Note too that you might not want .*:, if you want to exclude the possibility that what precedes the : not include a :, e.g., if you want to exclude a:b:c foo. To exclude :, use [^:]* instead of .*. And to exclude a lone :, use [^:]+.)
I have a data file like the following:
----------------------------
a b c d e .............
A B C D E .............
----------------------------
But I want it to be in the following format:
----------------------------
a A
b B
c C
d D
e E
...
...
----------------------------
What is the quickest way to do the transformation in Vim or Perl?
Basically :.s/ /SpaceCtrl+vEnter/gEnterjma:.s/ /Ctrl+vEnter/gEnterCtrl+v'axgg$p'adG will do the trick. :)
OK, let's break that down:
:.s/ /Ctrl+vEnter/gEnter: On the current line (.), substitute (s) spaces (/ /) with a space followed by a carriage return (SpaceCtrl+vEnter/), in all positions (g). The cursor should now be on the last letter's line (e in the example).
j: Go one line down (to A B C D E).
ma: Set mark a to the current position... because we want to refer to this position later.
:.s/ /Ctrl+vEnter/gEnter: Do the same substitution as above, but without the Space. The cursor should now be on the last letter's line (E in the example).
Ctrl+v'a: Select from the current cursor position (E) to mark a (that we set in step 3 above), using the block select.
x: Cut the selection (into the " register).
gg: Move the cursor to the first line.
$: Move the cursor to the end of the line.
p: Paste the previously cut text after the cursor position.
'a: Move the cursor to the a mark (set in step 3).
dG: Delete everything (the empty lines left at the bottom) from the cursor position to the end of the file.
P.S. I was hoping to learn about a "built-in" solution, but until such time...
Simple re-map of the columns:
use strict;
use warnings;
my #a = map [ split ], <>; # split each line on whitespace and store in array
for (0 .. $#{$a[0]}) { # for each such array element
printf "%s %s\n", $a[0]->[$_], $a[1]->[$_]; # print elements in order
}
Usage:
perl script.pl input.txt
Assuming that the cursor is on the first of the two lines, I would use
the command
:s/ /\r/g|+&&|'[-;1,g/^/''+m.|-j