ascii-boxes / boxes

Command line ASCII boxes unlimited!
https://boxes.thomasjensen.com/
GNU General Public License v3.0
593 stars 78 forks source link

Remove Leading Whitespace When Removing Box #8

Closed kiryph closed 9 years ago

kiryph commented 9 years ago

Is it possible to add an option when removing a box with $ boxes -r also to remove leading whitespace.

For example, I have typed BIBFILE on new line in my tex file and have changed it to a header with :'<,'>!boxes -d tex-box -s 80 which becomes

%------------------------------------------------------------------------------%
%                                   BIBFILE                                    %
%------------------------------------------------------------------------------%

When removing the box with :'<,'>!boxes -r I get:

                                  BIBFILE

Could also the leading whitespace be removed to get a cyclic behaviour?

tsjensen commented 9 years ago

Nice box! Maybe you want to add it to the boxes-config file?

It seems to me that you called :'<,'>!boxes -d tex-box -s 80 -ac (with -ac option to center the text). Now after removing the box, boxes has no way of knowing whether the space to the left of BIBFILE is from centering or from the original input.

Question: Have you tried adding a reverse statement to the box definition? You could add something like this:

reverse once "^[ \t]+" to ""

Which would, if I understand you correctly, do just what you need.

kiryph commented 9 years ago

Yes, indeed I was using the center option. Sorry for the inaccuracy.

For more clarification why I am asking: In case I want to change the centered text in a box, the centering usually gets lost or one has to manually correct for this.

So before I change the text, I remove the box, correct the text and re-apply the box command. But I have to remove the leading whitespace by hand.

If you now a better workflow, let me know.

IMO, this regards to all boxes.

Adding reverse once "^[ \t]+" to ""to my box config has the desired effect, but would require that I add this to all used box configurations.

BOX tex-box

revision "1.0"
revdate "Wed Jun 19 11:10:13 CEST 2013"
created "Wed Jun 19 11:10:13 CEST 2013"

sample
    %--------------------------------------------------------%
    % comments used in tex                                   %
    %--------------------------------------------------------%
ends

shapes {
    nw ("%") n ("-") ne ("%")
     w ("%")          e ("%")
    sw ("%") s ("-") se ("%")
}

padding {
    horiz 1
}
reverse once "^[ \t]+" to ""
elastic (n,e,s,w)

END tex-box
tsjensen commented 9 years ago

Let's see if I understand you correctly. You have this in your editor (with the "east" % wrong because of text editing):

%------------------------------------------------------------------------------%
%                                     BIBFILE                         %
%------------------------------------------------------------------------------%

Then, using your unmodifed box design, I can enter

:'<,'>!boxes -d tex-box -s 80 -ac -m

to fix it. Note that I added -m to mend the box. This works for the tex-box design:

%------------------------------------------------------------------------------%
%                                   BIBFILE                                    %
%------------------------------------------------------------------------------%

I agree that the reverse statement would have to be added to all designs that you want to use like this, which is suboptimal because it mixes the design definition with aspects of its use.

Maybe a hypothetical new option could be a modification of the mend option? Specifying this in detail is difficult because it needs to deal with

What is your proposal?

kiryph commented 9 years ago

The boxes version in the repository of the current debian (wheezy) does not have the mend option, hence I wasn't aware of it. This should allow for a more convenient solution. Information of the existing box and specified options for the new call of boxes can be combined. For instance, the indentation of the box can be retained.

I would kill leading and trailing whitespace inside a box on removal by default. Whitespace is (typically) not visible and should take part in text alignment relative to the box (IMHO). Probably others do not feel the same way.

I had in mind an option similar to -k (kill preceding/following blank lines on removal or not), i.e. kill leading and trailing whitespace inside the box on removal or not. Add e.g. capital -K for kill leading/trailing whitespace inside the box on removal, or change -k bool to -k string where string can be one or a combination of a,h,v,l,r,t,b (similar to -a)

kiryph commented 9 years ago

Ok, I haven't put too much thought into it. Multi-line examples with lines indented relative to a leading line would lose their indentation and that's not intended if it's turned on by default. Probably removing only whitespace which is shared of all lines inside the box would be more sensible, except in case of centering of all lines individually.

Well, I guess I can't give you a satisfying proposal.

tsjensen commented 9 years ago

OK - I support the idea of a new option, for two reasons:

We'll have to come up with a solid spec and find someone to implement it. So I'll leave this open as an enhancement request.

I would try to make this as simple as possible, e.g. only evaluate the -i and -a options when -m is specified. This may already cover your case; at least if we modify boxes so that box indentation is analyzed before removing the box.

tsjensen commented 9 years ago

One more thing: I just read the boxes man page again and found that you can also mend your broken tex-box without a reverse statement if you add -i like this:

:'<,'>!boxes -d tex-box -s80 -i none -ac -m

This obsoletes reason 1, but since it does not retain indentation either, reason 2 remains.

kiryph commented 9 years ago

Perfect. This does exactly the trick.

Using the mend option makes it very convenient when changing centered text in a box.

Note using :'<,'>!boxes -r -i none STILL DOES NOT remove leading whitespace.