Line breaks on string literals


#1

Hi, excuse my ignorance I searched everywhere and could not find it anywhere

Is there a way to configure atom to automaticaly break lines when pasting into “” só that the text becomes the string concatenated ?


#2

So you’re asking for a feature where if I have the following text in the clipboard:

blah blah blah blah blah
foo foo foo foo foo foo
bar bar bar bar bar bar

And I have my cursor between a pair of double-quotes then paste the text in, you want this to be the result?

"blah blah blah blah blah"
"foo foo foo foo foo foo"
"bar bar bar bar bar bar"

#3

That wouldn’t be concatenated. You need to have the concatenation operator +.

I’m getting deja vue. Maybe a package was just announced for this?


#4

Some languages, including C, concatenate string literals that are separated only by whitespace. I’ve seen it cause just as many nasty bugs as the number of times that I’ve seen it be useful … but some people like the feature.


#5

Bash does that also.


#6

Yes it should be

“blah blah blah blah blah \n” +
“foo foo foo foo foo foo \n”+
"bar bar bar bar bar bar ";

I find it usefull because often I have to write complex DB queryes this way it keeps identation when I see it in my console


#7

There’s nothing built-in to Atom that does this, no. It sounds like a great idea for a package though :grinning:


#8

I use this. It almost gets you what you want.

It splits whenever your press enter with a cursor in a string. I’m surprised it doesn’t happen by accident more often. One place it has a problem is in long herestrings where every enter, even at the end of a line, messes things up. I’ve been putting off posting an issue or a PR.


#9

Thanks, I am using it in fact … togheter with https://atom.io/packages/text-manipulation and https://atom.io/packages/atom-quoter I first encode the text to query quote it then break rhe lines at \n with enter


#10

This is so simple and works so well that it should be built in. I can’t think of any reason why you wouldn’t want it to work like this?