From: Joseph Jones Date: 2015-12-17T21:05:56-07:00 Subject: [ruby-core:72249] [Ruby trunk - Feature #9098] Indent heredoc against the left margin by default when \"indented closing identifier\" is turned on. --56738624_ded7263_16c Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Joseph Jones liked your message with Boxer. On November 30, 2015 at 23:20= :35 MST, nobu=40ruby-lang.org wrote:Issue =239098 has been updated by Nob= uyoshi Nakada.=228 spaces for tab stops=22 is not enough to make the spec= .When tabs and spaces are mixed, e.g., there are=60=22=5Ct=22*2+=222 tabs= =22=60 line and =60=22 =22*10+=2210 spaces=22=60 line, what should be exp= ected=3F1. dedent at the greatest indent column where all lines have a wh= ite space. a tab which includes the column will remain, but spaces betwee= n previous tab stop and the column will be removed. this is the implement= ation by =40bjmllr, and results =60=22=5Ct=22+=222 tabs=22=60 line and =60= =22 =22*2+=2210 spaces=22=60 line.2. dedent at the greatest indent column= exclusively tabs a tab which includes the column will remain, and also s= paces before the column will be removed. this is like =60kill-rectangle=60= of Emacs, and I've thought this, and results =60=22=5Ct=22+=222 tabs=22=60= line and =60=2210 spaces=22=60 line.3. expand tabs first tabs are expand= ed first before dedent, and results =60=22 =22*6+=222 tabs=22=60 line and= =60=2210 spaces=22=60 line.4. or, like Andrew M claims, dedent of byte-w= ise common parts can be an option, I think now.--------------------------= --------------=46eature =239098: Indent heredoc against the left margin b= y default when =22indented closing identifier=22 is turned on.https://bug= s.ruby-lang.org/issues/9098=23change-55183* Author: Prem Sichanugrist* St= atus: Assigned* Priority: Normal* Assignee: Yukihiro Matsumoto-----------= -----------------------------tl;dr: I would like to port +String=23strip=5F= heredoc+ (http://api.rubyonrails.org/classes/String.html=23method-i-strip= =5Fheredoc) from Rails and enable it on =60Hi,I've been using here docume= nt (heredoc) for a while, and I've found out that it's very annoying that= the content is always treated as flushed left. Per syntax doc: Note that= the while the closing identifier may be indented, the content is always = treated as if it is flush left. If you indent the content those spaces wi= ll appear in the output.So, this is the current result if you use heredoc= in Ruby: class =46ancyHello def self.hello puts Hello World=21 README e= nd end =46ancyHello.hello =23 =3D> =22 Hello=5Cn World=21=5Cn=22In Rails= , the core team has implemented +String=23strip=5Fheredoc+, which handles= this scenario by remove leading white spaces from the string. However, n= ot many user know that Rails has that method, and instead doing this to g= et around it: class =46ancyHello def self.hello puts Hello World=21 READ= ME end end =46ancyHello.hello =23 =3D> =22Hello=5Cn World=21=5Cn=22I rea= lly think that we could do better on this by removing the leading white s= paces, matching +String=23strip=5Fheredoc+ method.So, after the change, I= want to be able to do this, and get this result: class =46ancyHello def = self.hello puts Hello World=21 README end end =46ancyHello.hello =23 =3D= > =22Hello=5Cn World=21=5Cn=22Note: the behavior on =60I'll write up a pa= tch and submit it if you think this is a good idea. Please let me know an= y question or concern you may have.Thank you,Prem---=46iles--------------= ------------------dedent=5Fheredoc.patch (12.8 KB)-- https://bugs.ruby-la= ng.org/ --56738624_ded7263_16c Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Joseph Jones liked your message with Boxer.


= On November 30, 2015 at 23:20:35 MST, nobu=40ruby-lang.org wrote:
Issue =239098 has been update= d by Nobuyoshi Nakada.


=228 spaces for tab stops=22 is n= ot enough to make the spec.

When tabs and spaces are mixed, e.= g., there are=60=22=5Ct=22*2+=222 tabs=22=60 line and =60=22 =22*10+=2210= spaces=22=60 line, what should be expected=3F

1. dedent at th= e greatest indent column where all lines have a white space.

= a tab which includes the column will remain, but spaces between previo= us tab stop and the column will be removed.
this is the implemen= tation by =40bjmllr, and results
=60=22=5Ct=22+=222 tabs=22=60 l= ine and =60=22 =22*2+=2210 spaces=22=60 line.

2. dedent at the= greatest indent column exclusively tabs

a tab which inclu= des the column will remain, and also spaces before the column will be rem= oved.
this is like =60kill-rectangle=60 of Emacs, and I've thoug= ht this, and results
=60=22=5Ct=22+=222 tabs=22=60 line and =60=22= 10 spaces=22=60 line.

3. expand tabs first

tabs= are expanded first before dedent, and results
=60=22 =22*6+=222= tabs=22=60 line and =60=2210 spaces=22=60 line.

4. or, like A= ndrew M claims, dedent of byte-wise common parts can be an option, I thin= k now.

----------------------------------------
=46eature= =239098: Indent heredoc against the left margin by default when =22inden= ted closing identifier=22 is turned on.
https://bugs.ruby-lang.org/i= ssues/9098=23change-55183

* Author: Prem Sichanugrist
* S= tatus: Assigned
* Priority: Normal
* Assignee: Yukihiro Matsumo= to
----------------------------------------
tl;dr: I would like= to port +String=23strip=5Fheredoc+ (http://api.rubyonrails.org/classes/S= tring.html=23method-i-strip=5Fheredoc) from Rails and enable it on =60<<-= =60 heredoc.

Hi,

I've been using here document (her= edoc) for a while, and I've found out that it's very annoying that the co= ntent is always treated as flushed left. Per syntax doc:

N= ote that the while the closing identifier may be indented, the content is=
always treated as if it is flush left. If you indent the conte= nt those spaces
will appear in the output.

So, this i= s the current result if you use heredoc in Ruby:

class =46= ancyHello
def self.hello
puts <<-README.inspect Hello
World=21
README
= end
end

=46ancyHello.hello =23 =3D> =22 = Hello=5Cn World=21=5Cn=22

In Rails, the core team h= as implemented +String=23strip=5Fheredoc+, which handles this scenario by= remove leading white spaces from the string. However, not many user kno= w that Rails has that method, and instead doing this to get around it:
class =46ancyHello
def self.hello
pu= ts <<-README.inspect
Hello
World=21
READ= ME
end
end

=46ancyHello.hello =23 = =3D> =22Hello=5Cn World=21=5Cn=22

I really think that we coul= d do better on this by removing the leading white spaces, matching +Strin= g=23strip=5Fheredoc+ method.

So, after the change, I want to b= e able to do this, and get this result:

class =46ancyHello=
def self.hello
puts <<-README.inspect
= Hello
World=21
README
end end

=46ancyHello.hello =23 =3D> =22Hello=5Cn = World=21=5Cn=22

Note: the behavior on =60<
I'll write up a patch and submit it if you think = this is a good idea. Please let me know any question or concern you may h= ave.

Thank you,

Prem

---=46iles---------= -----------------------
dedent=5Fheredoc.patch (12.8 KB)

=
--
https://bugs.ruby-lang.org/
= --56738624_ded7263_16c--