how to use macro to make my code
-
Please do not delete your topic after there have been replies. We might not have a way to mark a topic as “answered”, but deleting the topic is not the right way to “end” the question. Just say, “thanks, that worked” or something to that effect, and the conversation will end naturally.
-
-
@alan-kilborn
You should have used an existing file with 920 lines.editor.lineDown()
does not add a new line. -
@paul-wormer
My solution was useless anyway now that I saw his BEFORE and AFTER. I, too, misunderstood his problem. -
I don’t think you have a handle on how to reply to postings here, evidence:
So you are telling me that I “should have used an existing file with 920 lines”. Well, I don’t know what that means, because I haven’t contributed in that way to this thread.
Also, you’re replying to yourself; this can be done, but try to do it only if it makes sense.
-
@alan-kilborn said in how to use macro to make my code:
II gave it a whirl and upon execution I got one really long line generated (12420 characters), that pretty much looks like this, over and over on that one line:
country= coutry_word=country_flag=country_code_number=
I’m not sure how that gets close to what the OP wants.
I am sorry that I don’t understand the mechanics of this particular forum. But my answer about
editor.lineDown()
was about your comment above. -
@paul-wormer said in how to use macro to make my code:
I am sorry that I don’t understand the mechanics of this particular forum. But my answer about editor.lineDown() was about your comment above.
Ah, apologies.
And you did say earlier:Here I assume that you have an existing file of 920 lines
So I missed that.
Again, sorry.
Other thoughts:
editor.lineDown()
isn’t really a great way to script something like this. It’s too “macro”-ish, and scripts give you the power to work with more of a data set rather than “careting” around a document as in a macro approach.But…it is hard to say more, because I really don’t have a great grasp on the problem statement, as IMO the OP hasn’t made it very clear (and the longer that state persists, the less interested I am).
-
@alan-kilborn said in how to use macro to make my code:
as IMO the OP hasn’t made it very clear
Since the OP deleted their question and it had to be resurrected, I am pretty sure either the OP got the answer they needed, or they left in a huff because they couldn’t figure out how to make us understand what they wanted. Either way, I doubt the OP is going to come back and clarify, and I doubt there’s much point in our spending any more time on it (unless the OP does come back and clarify).
-
@peterjones said in how to use macro to make my code:
OP deleted their question and it had to be resurrected
@igor-lerinc A rather anti-social thing to do.
@peterjones said in how to use macro to make my code:
I doubt there’s much point in our spending any more time on it
I realized this morning an enhancement to the spreadsheet approach I suggested earlier I’d like to briefly describe.
Without too much difficulty a column could be added consisting of formulas to calculate the line number in the target file to be assembled.
Assuming 6 lines per case (1 for “case” stmnt, 4 vars, and 1 for static “break” stmnt),
the first bank, the “case” numbers, would have target line numbers 1,7,13… (1+(92-1)*6)
the second bank, the “country” fields would have target line numbers 2,8,14… (2+(92-1)*6)
etc.
Now the lines could be sorted, either in the spreadsheet or after xfer to text editor.
To make it amenable to upkeep and modification, one should define things like NUM_COUNTRIES (92) and LINES_PER_CASE (6 in my example), and use those in the formulas.
As before, there are many variations on implementation details, such as, doing C-ification early, in spreadsheet:
CONCAT spaces/tabs + "case " + case num " “:”
CONCAT spaces/tabs + “country=” + country text + “;”
etc
or late, in Npp using fancy regex in a F&R. -
this was the answer i was looking for:
https://stackoverflow.com/a/70632134/17848947
i just didn’t wanted to continue building on more misunderstandings trying to explain further and waste anyone’s time…
-
Hello, @igor-lerinc, @peterjones, @alan-kilborn, @neil-schipper, @paul-wormer and All;
I found out a nice solution with a minimum of actions to proceed ! This further method is rather difficult to express but is finally easy to execute :-))
I will expose my method with a short list of
6
countries ( Andorre, United Arab Emirates, Afganistan, Albania, Armenia and Angola ) which, of course, can be extend to your230
items and even more !Basically, you have three informative zones and two pseudo-zones
case n;
andR.drawable.flag_
+ the current country code, located on the next lineLet’s place each of these
5
zones in a different file, from fileA.txt
to fileE.txt
. Presently, the filesB
,C
andE
will contain6
informative lines and filesA
andD
are still empty !
-
In the
B.txt
file :-
Move to the very beginning of file
-
Create a zero-length rectangular selection onto the
6
lines -
Open the Column Editor (
Alt + C
) -
Choose the
Number to Insert
radio button -
Initial number
2
-
Increase by
5
-
Repeat
1
-
Tick the
Leading zeros
option -
Click on the
OK
button
-
=> You should get the numbering :
02, 07, 12, 17, 22, 27
-
In the
C.txt
file :-
Move to the very beginning of file
-
Create a zero-length rectangular selection onto the
6
lines -
Open the Column Editor (
Alt + C
) -
Choose the
Number to Insert
radio button -
Initial number
3
-
Increase by
5
-
Repeat
1
-
Tick the
Leading zeros
option -
Click on the
OK
button
-
=> You should get the numbering :
03, 08, 13, 18, 23, 28
-
In the
E.txt
file :-
Move to the very beginning of file
-
Create a zero-length rectangular selection onto the
6
lines -
Open the Column Editor (
Alt + C
) -
Choose the
Number to Insert
radio button -
Initial number
5
-
Increase by
5
-
Repeat
1
-
Tick the
Leading zeros
option -
Click on the
OK
button
-
=> You should get the numbering :
05, 10, 15, 20, 25, 30
-
In the
D.txt
empty file :-
Hit
6
times on theEnter
key -
Insert a
semicolon
character on each line -
Move to the very beginning of file
-
Create a zero-length rectangular selection onto these
6
lines -
Open the Column Editor (
Alt + C
) -
Choose the
Number to Insert
radio button -
Initial number
4
-
Increase by
5
-
Repeat
1
-
Tick the
Leading zeros
option -
Click on the
OK
button
-
=> You should get the numbering :
04, 09, 14, 19, 24, 29
, followed with a semicolon-
Finally, in the
A.txt
empty file :-
Hit
6
times on theEnter
key -
Move to the very beginning of file
-
Create a zero-length rectangular selection onto these
6
lines -
Open the Column Editor (
Alt + C
) -
Choose the
Number to Insert
radio button -
Initial number
1
-
Increase by
5
-
Repeat
1
-
Tick the
Leading zeros
option -
Click on the
OK
button
-
=> You should get the numbering :
01, 06, 11, 16, 21, 26
-
Secondly :
-
Move the caret at end of the first line
-
Create, again, a zero-lengh rectangular selection onto these
6
lines -
Open the Column Editor (
Alt + C
) -
Choose the
Number to Insert
radio button -
Initial number
1
-
Increase by
1
, this time -
Repeat
1
-
Untick the
Leading zeros
option, this time -
Click on the
OK
button
-
You should get the final numbering :
011, 062, 113, 164, 215, 266
Then, let’s merge the files, from
A.txt
toE.txt
, in any order, in a new tab, renamed asResul.txt
, which possible blank lines in between. You obtain this text :011 062 113 164 215 266 02"ad" 07"ae" 12"af" 17"al" 22"am" 27"an" 03"+376" 08"+971" 13"+93" 18"+355" 23"+374" 28"+244" 04; 09; 14; 19; 24; 29; 05"Andorra" 10"United Arab Emirates (UAE)" 15"Afghanistan" 20"Albania" 25"Armenia" 30"Angola"
- Perform a classical sort with the
Edit > Line Operations > Sort Lines Lexicographically Ascending
option. After deleting the first possible blank lines, you’re left with theseResult.txt
contents :
011 02"ad" 03"+376" 04; 05"Andorra" 062 07"ae" 08"+971" 09; 10"United Arab Emirates (UAE)" 113 12"af" 13"+93" 14; 15"Afghanistan" 164 17"al" 18"+355" 19; 20"Albania" 215 22"am" 23"+374" 24; 25"Armenia" 266 27"an" 28"+244" 29; 30"Angola"
-
Move to the very beginning of file
-
For the last time, do a zero-length rectangular selection onto the
30
lines -
Delete the first two digits, hitting twice the
Delete
key
The
Resul.txt
file becomes :1 "ad" "+376" ; "Andorra" 2 "ae" "+971" ; "United Arab Emirates (UAE)" 3 "af" "+93" ; "Afghanistan" 4 "al" "+355" ; "Albania" 5 "am" "+374" ; "Armenia" 6 "an" "+244" ; "Angola"
Almost finished ! Open the
Replace
dialog and performs this regex S/R :SEARCH
(?-s)^(\d+)\R(.+)\R(.+)\R(.+)\R"(.+)"(\R)
REPLACE
\tcase \1:\6\t\tcountry=\2\6\t\tcountry_code_number=\3\6\t\tcountry_flag=R\.drawable\.flag_\5;\6\t\tcountry_word="\5"\6\t\tbreak;\6
Magically, the text is changed into :
case 1: country="ad" country_code_number="+376" country_flag=R.drawable.flag_Andorra; country_word="Andorra" break; case 2: country="ae" country_code_number="+971" country_flag=R.drawable.flag_United Arab Emirates (UAE); country_word="United Arab Emirates (UAE)" break; case 3: country="af" country_code_number="+93" country_flag=R.drawable.flag_Afghanistan; country_word="Afghanistan" break; case 4: country="al" country_code_number="+355" country_flag=R.drawable.flag_Albania; country_word="Albania" break; case 5: country="am" country_code_number="+374" country_flag=R.drawable.flag_Armenia; country_word="Armenia" break; case 6: country="an" country_code_number="+244" country_flag=R.drawable.flag_Angola; country_word="Angola" break;
To end, run this second regex S/R :
SEARCH
(?s)(?!\r|\n).+
REPLACE
switch (5) {\r\n$0\tdefault:\r\n\tconsole.log\(\x96Nothing here\x96\);\r\n\t}\r\n
And here is, Igor, your expected result :
switch 5 { case 1: country="ad" country_code_number="+376" country_flag=R.drawable.flag_Andorra; country_word="Andorra" break; case 2: country="ae" country_code_number="+971" country_flag=R.drawable.flag_United Arab Emirates (UAE); country_word="United Arab Emirates (UAE)" break; case 3: country="af" country_code_number="+93" country_flag=R.drawable.flag_Afghanistan; country_word="Afghanistan" break; case 4: country="al" country_code_number="+355" country_flag=R.drawable.flag_Albania; country_word="Albania" break; case 5: country="am" country_code_number="+374" country_flag=R.drawable.flag_Armenia; country_word="Armenia" break; case 6: country="an" country_code_number="+244" country_flag=R.drawable.flag_Angola; country_word="Angola" break; default: console.log(`Nothing here`); }
Best Regards
guy038
P.S. :
-
Your
Two-letters
country, in theB.txt
file, represents theISO 3166-1 alpha-2
standard for each country -
Your
Country_code_number
, in theC.txt
file, represents theE_164 codes
standard for each country
Refer to this main link :
-
-
@guy038
Congratulations with your ingenious solution. Although it seems to me that an editor - any editor - is not quite the right tool for this job. It is as if you are explaining how to build a wooden chicken coop with as only tool the heel of a shoe.