18
1
When using Markup, like on the SE network, an indentation of four spaces before a line of text denotes it as part of a code block, as I hope you know. If you don't, here's an example (with .
representing a space):
....Code
....More code
results in
Code
More code
The problem is, when you copy-paste code into an answer, you need to indent each line manually. This is especially difficult when working with ungolfed code, as it's likely already indented and can cause confusion. You can just select your code and hit Ctrl + K
, it turns out. Hours of my life wasted for no reason aside...
So, your goal is, given an input, return it with four spaces before each line. In the spirit of saving time copy-pasting, you are to process the entire input as a single string (so long as your language can parse it). If your language is unable to process a character (such as newlines) in strings, you may assume it is denoted/escaped through some other method supported by the language; however, the output must output each line on its own line (so no passing something like ....foo\n....bar
).
Standard loopholes not allowed. As this is code-golf, the shortest answer in bytes wins. Good luck!
3"you need to indent each line manually" (or select the text and click the button :)) – Jonathan Allan – 2017-04-08T19:29:00.547
11@JonathanAllan "Button"? Surely you mean "keyboard shortcut". (Ctrl+K) – Martin Ender – 2017-04-08T19:29:59.730
31@JonathanAllan ...I... I am very upset. SO MUCH TIME. WASTED. – Papayaman1000 – 2017-04-08T19:31:31.607
I find mashing my big trackpad easier than finding two keys, but hey each to their own – Jonathan Allan – 2017-04-08T19:31:46.293
Must the output be printed, or is a list of strings acceptable? – Greg Martin – 2017-04-08T19:38:37.593
@GregMartin It can be output however you like, but said output must be copy-pastable without altering the input (wrappers aside). In other words, so long as it's identical to just using
Ctrl + K
, go for it. – Papayaman1000 – 2017-04-08T19:40:41.8706While I'm fairly confident that Kritixi's V answer won't be beaten, I would typically recommend waiting a bit longer before accepting an answer, because accepting so early poses a disadvantage to people who could answer with a shorter answer but weren't on the site at the time (timezones or just not always being on PPCG 24/7) – HyperNeutrino – 2017-04-08T20:12:00.363
@HyperNeutrino Right. I did take that into account, but...
I mean, 6 bytes?! I'm pretty sure even some HQ9+ answers use more. [In the meantime, though, I'll wait until they at least change the bytecount to reflect Unicode as well.] – Papayaman1000 – 2017-04-08T20:13:12.160
It's 4 now, so it's probably not going to be beaten, but you never know. – HyperNeutrino – 2017-04-08T20:13:42.503
you are to process the entire input as a single string
Do you mean that the program must accept the input as a whole but can get it char-by-char or line-by-line or anything or that the program must actually load the whole input in memory at once before processing it? – Erik the Outgolfer – 2017-04-09T09:27:57.5672+1 for informing people about
Ctrl + K
– Koishore Roy – 2017-04-09T09:54:43.267So is it kay with tab spacing. Without ctrl+k is nothing but a tab! – Keerthana Prabhakaran – 2017-04-09T13:29:50.947
@KoishoreRoy Thank Johnathan Allan and Martin Ender. I had no clue (hence the strikethrough [which apparently doesn't work in comments, no matter which method you try]). – Papayaman1000 – 2017-04-09T18:23:13.603
I prefer to copy a tab and paste it in front of each line, unless my code is long. – mbomb007 – 2017-04-12T16:09:23.077
@HyperNeutrino If they aren't on PPCG 24/7, they don't deserve to win :P – Esolanging Fruit – 2017-04-14T22:51:45.753
Puzzle still valid if you want to insert code after a list item.
– Draco18s no longer trusts SE – 2017-04-26T03:16:39.203@Papayaman1000 wh... WHAT THE $@#* I'M ANGRY AS HELL TOO. – Magic Octopus Urn – 2017-05-09T19:40:58.567