Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Code macros #14

Open
adoxa opened this issue Oct 9, 2019 · 4 comments
Open

Code macros #14

adoxa opened this issue Oct 9, 2019 · 4 comments
Labels
Completed The requested enhancement/bug fix/doc change was implemented in some fashion open to ideas

Comments

@adoxa
Copy link
Collaborator

adoxa commented Oct 9, 2019

I was looking at implementing for /f "line" ... (shorthand option to read a complete line) when I realised rather than patching cmd it'd be far easier to just insert the necessary text using normal variable substitution. Another area where this could be useful is with the infinite loop - I thought of patching cmd to allow for (...) or do ... as shorthand for for %%_ in (:*) do ..., but it was just too complicated, when, again, a simple substitution would get the job done. I was thinking variables starting with # could be used for this.

setVar(L"#line", L"delims^=^ eol^=");
setVar(L"#loop", L"for /f %%_ in (:*) do");
%#loop% echo Infinite loop.
for /f %#line% %%L in (file) do echo %%L

Pehaps the for /f could even be included in the variable, making it #forline instead; perhaps another variation to include usebackq, as usebackq^ %#line% isn't very nice (#forlinebackq).

@adoxa
Copy link
Collaborator Author

adoxa commented Oct 10, 2019

Naturally, as soon as I post, I think of a way I might be able to do them, after all. Still, it doesn't preclude defining macros, anyway.

@carlos-montiers
Copy link
Owner

Nice idea Jason
I think infinite loop should be use in a normal for, not for /f.
What about extension function that in the get return the correct options for use in for /f.
Something like this for example:
for /f %@opt(line,usebackq)% %%L in (file) do echo %%L
that expand in this case to: usebackq^ delims^=^ eol^=

@adoxa
Copy link
Collaborator Author

adoxa commented Oct 11, 2019

I think infinite loop should be use in a normal for, not for /f.

Oops, it was supposed to, fixed.

What about extension function that in the get return the correct options for use in for /f.

Interesting idea, but I should be able to patch it in directly, now. I also hope to use for do as the infinite loop shortcut.

@adoxa
Copy link
Collaborator Author

adoxa commented Oct 13, 2019

Commit 39a5e25 adds "line" option to for /f; for do for infinite loop; for %%? do for infinite range; and for %%? N for a range of N. That implements what I originally wanted macros for, but I'll leave it open should there be other ideas.

@carlos-montiers carlos-montiers added Completed The requested enhancement/bug fix/doc change was implemented in some fashion open to ideas labels Apr 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Completed The requested enhancement/bug fix/doc change was implemented in some fashion open to ideas
Projects
None yet
Development

No branches or pull requests

2 participants