textedit - how to set tab size for correct column calculation?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

textedit - how to set tab size for correct column calculation?

David Baptista
Good afternoon,

I have been fiddling with textedit on Windows, and I have determined that when source files contain tabs, lilypond always calculates the "column" parameter assuming that tabs occupy 8 spaces. In my case I have my editor configured for 4 spaces, so the link always overshoots.

Luckily since textedit also includes the char position, and my textedit protocol handler is a custom python script, I was able to compensate (actual_column = (3*char+4*column+4) / 7 ).

Obviously this is just an workaround. Is there a way to parametrize lilypond itself to assume tabs = 4 spaces instead of 8 when computing the textedit link?

Best regards,
David Baptista

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: textedit - how to set tab size for correct column calculation?

Andrew Bernard
Hi David,

Lilypond only cares about whitespace. Tbas are not integral to the syntax, as they are in some programming languages. Why don't you consider using Frescobaldi? Its a very capable and good lilypond environment. I cant see why, given that it exists, anybody would use a crude text editor. I can understand using emacs, however. Give it a go!

Andrew


On Sat, 3 Nov 2018 at 07:15, David Baptista <[hidden email]> wrote:

I have been fiddling with textedit on Windows, and I have determined that when source files contain tabs, lilypond always calculates the "column" parameter assuming that tabs occupy 8 spaces. In my case I have my editor configured for 4 spaces, so the link always overshoots.


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: textedit - how to set tab size for correct column calculation?

David Baptista
I actually like then setup I currently have (Lilypond + Notepad++ with custom Lilypond language definition for auto complete and syntax highlighting [the definitions file is out there on the Internet] plus Sumatra PDF as a viewer that allows PDF updating even when open - one custom Notepad shortcut for compiling with NppExec and that's it). The only part that is hacky is the referred "textedit" links because somehow internally, when lilypond generates them, it assumes that one tab equals 8 spaces and this is actually editor and configuration dependant (so it seems there should be a way to set tab size for textedit link calculations within Lilypond, which I do not know if it is the case).

In consequence, I have some nasty calculations in a custom script for textedit:// links to actually land in the right column in Notepad++.

Andrew Bernard <[hidden email]> escreveu no dia sexta, 2/11/2018 à(s) 22:35:
Hi David,

Lilypond only cares about whitespace. Tbas are not integral to the syntax, as they are in some programming languages. Why don't you consider using Frescobaldi? Its a very capable and good lilypond environment. I cant see why, given that it exists, anybody would use a crude text editor. I can understand using emacs, however. Give it a go!

Andrew


On Sat, 3 Nov 2018 at 07:15, David Baptista <[hidden email]> wrote:

I have been fiddling with textedit on Windows, and I have determined that when source files contain tabs, lilypond always calculates the "column" parameter assuming that tabs occupy 8 spaces. In my case I have my editor configured for 4 spaces, so the link always overshoots.


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: textedit - how to set tab size for correct column calculation?

Federico Bruni-2
Hi David

I confirm the problem.
But I wonder how lilypond can predict how many spaces an editor will
consider for a tab. It's impossible, isn't it? The best workaround is
not using tabs at all (or replace them with spaces upon save).

For those who want to reproduce the problem, do not use Frescobaldi,
which converts tabs to spaces. Create a ly file with another editor,
use tabs, compile the PDF and you'll see that the COLUMN in
textedit://FILE:LINE:CHAR:COLUMN has a shift forward.


Il giorno sab 3 nov 2018 alle 7:03, David Baptista
<[hidden email]> ha scritto:

> I actually like then setup I currently have (Lilypond + Notepad++
> with custom Lilypond language definition for auto complete and syntax
> highlighting [the definitions file is out there on the Internet] plus
> Sumatra PDF as a viewer that allows PDF updating even when open - one
> custom Notepad shortcut for compiling with NppExec and that's it).
> The only part that is hacky is the referred "textedit" links because
> somehow internally, when lilypond generates them, it assumes that one
> tab equals 8 spaces and this is actually editor and configuration
> dependant (so it seems there should be a way to set tab size for
> textedit link calculations within Lilypond, which I do not know if it
> is the case).
>
> In consequence, I have some nasty calculations in a custom script for
> textedit:// links to actually land in the right column in Notepad++.
>
> Andrew Bernard <[hidden email]> escreveu no dia sexta,
> 2/11/2018 à(s) 22:35:
>> Hi David,
>>
>> Lilypond only cares about whitespace. Tbas are not integral to the
>> syntax, as they are in some programming languages. Why don't you
>> consider using Frescobaldi? Its a very capable and good lilypond
>> environment. I cant see why, given that it exists, anybody would use
>> a crude text editor. I can understand using emacs, however. Give it
>> a go!
>>
>> Andrew
>>
>>
>> On Sat, 3 Nov 2018 at 07:15, David Baptista
>> <[hidden email]> wrote:
>>>
>>> I have been fiddling with textedit on Windows, and I have
>>> determined that when source files contain tabs, lilypond always
>>> calculates the "column" parameter assuming that tabs occupy 8
>>> spaces. In my case I have my editor configured for 4 spaces, so the
>>> link always overshoots.
>>>


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: textedit - how to set tab size for correct column calculation?

David Baptista
I think the main way around this would be to expose a setting (ex tab-size) to be configured by the user.

Federico Bruni <[hidden email]> escreveu no dia sábado, 3/11/2018 à(s) 07:55:
Hi David

I confirm the problem.
But I wonder how lilypond can predict how many spaces an editor will
consider for a tab. It's impossible, isn't it? The best workaround is
not using tabs at all (or replace them with spaces upon save).

For those who want to reproduce the problem, do not use Frescobaldi,
which converts tabs to spaces. Create a ly file with another editor,
use tabs, compile the PDF and you'll see that the COLUMN in
textedit://FILE:LINE:CHAR:COLUMN has a shift forward.


Il giorno sab 3 nov 2018 alle 7:03, David Baptista
<[hidden email]> ha scritto:
> I actually like then setup I currently have (Lilypond + Notepad++
> with custom Lilypond language definition for auto complete and syntax
> highlighting [the definitions file is out there on the Internet] plus
> Sumatra PDF as a viewer that allows PDF updating even when open - one
> custom Notepad shortcut for compiling with NppExec and that's it).
> The only part that is hacky is the referred "textedit" links because
> somehow internally, when lilypond generates them, it assumes that one
> tab equals 8 spaces and this is actually editor and configuration
> dependant (so it seems there should be a way to set tab size for
> textedit link calculations within Lilypond, which I do not know if it
> is the case).
>
> In consequence, I have some nasty calculations in a custom script for
> textedit:// links to actually land in the right column in Notepad++.
>
> Andrew Bernard <[hidden email]> escreveu no dia sexta,
> 2/11/2018 à(s) 22:35:
>> Hi David,
>>
>> Lilypond only cares about whitespace. Tbas are not integral to the
>> syntax, as they are in some programming languages. Why don't you
>> consider using Frescobaldi? Its a very capable and good lilypond
>> environment. I cant see why, given that it exists, anybody would use
>> a crude text editor. I can understand using emacs, however. Give it
>> a go!
>>
>> Andrew
>>
>>
>> On Sat, 3 Nov 2018 at 07:15, David Baptista
>> <[hidden email]> wrote:
>>>
>>> I have been fiddling with textedit on Windows, and I have
>>> determined that when source files contain tabs, lilypond always
>>> calculates the "column" parameter assuming that tabs occupy 8
>>> spaces. In my case I have my editor configured for 4 spaces, so the
>>> link always overshoots.
>>>


_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: textedit - how to set tab size for correct column calculation?

David Wright
On Sat 03 Nov 2018 at 09:35:54 (+0000), David Baptista wrote:
> I think the main way around this would be to expose a setting (ex tab-size)
> to be configured by the user.

Ouch. That's just a step backwards. Why fixed every N? Even
typewriters could set custom stops as desired. But then you
just get chaos when files are moved around.

There are two parts to handling tabs:

1) Pressing the TAB key. Here you can set your editor to do whatever
you like, custom or otherwise. But it should add spaces (± tabs),
as required, to move to the correct location.

2) What gets put in the file. Here, you should at least stick to the
standard TAB spacing of eight characters. It's also safer to avoid
the storing of any <SPACE><TAB> sequences in case someone somewhere
has forgotten to handle this case.

Anything else and you'll get tripped up somewhere. Fix LP and it'll
happen somewhere else instead.

> Federico Bruni <[hidden email]> escreveu no dia sábado, 3/11/2018 à(s)
> 07:55:
>
> > Hi David
> >
> > I confirm the problem.
> > But I wonder how lilypond can predict how many spaces an editor will
> > consider for a tab. It's impossible, isn't it? The best workaround is
> > not using tabs at all (or replace them with spaces upon save).
> >
> > For those who want to reproduce the problem, do not use Frescobaldi,
> > which converts tabs to spaces. Create a ly file with another editor,
> > use tabs, compile the PDF and you'll see that the COLUMN in
> > textedit://FILE:LINE:CHAR:COLUMN has a shift forward.
> >
> >
> > Il giorno sab 3 nov 2018 alle 7:03, David Baptista
> > <[hidden email]> ha scritto:
> > > I actually like then setup I currently have (Lilypond + Notepad++
> > > with custom Lilypond language definition for auto complete and syntax
> > > highlighting [the definitions file is out there on the Internet] plus
> > > Sumatra PDF as a viewer that allows PDF updating even when open - one
> > > custom Notepad shortcut for compiling with NppExec and that's it).
> > > The only part that is hacky is the referred "textedit" links because
> > > somehow internally, when lilypond generates them, it assumes that one
> > > tab equals 8 spaces and this is actually editor and configuration
> > > dependant (so it seems there should be a way to set tab size for
> > > textedit link calculations within Lilypond, which I do not know if it
> > > is the case).
> > >
> > > In consequence, I have some nasty calculations in a custom script for
> > > textedit:// links to actually land in the right column in Notepad++.
> > >
> > > Andrew Bernard <[hidden email]> escreveu no dia sexta,
> > > 2/11/2018 à(s) 22:35:
> > >> Hi David,
> > >>
> > >> Lilypond only cares about whitespace. Tbas are not integral to the
> > >> syntax, as they are in some programming languages. Why don't you
> > >> consider using Frescobaldi? Its a very capable and good lilypond
> > >> environment. I cant see why, given that it exists, anybody would use
> > >> a crude text editor. I can understand using emacs, however. Give it
> > >> a go!
> > >>
> > >> Andrew
> > >>
> > >>
> > >> On Sat, 3 Nov 2018 at 07:15, David Baptista
> > >> <[hidden email]> wrote:
> > >>>
> > >>> I have been fiddling with textedit on Windows, and I have
> > >>> determined that when source files contain tabs, lilypond always
> > >>> calculates the "column" parameter assuming that tabs occupy 8
> > >>> spaces. In my case I have my editor configured for 4 spaces, so the
> > >>> link always overshoots.

Cheers,
David.

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: textedit - how to set tab size for correct column calculation?

David Baptista
I'm not sure I was able to follow your reasoning. Maybe a practical case would help me: I use tab for spacing a .ly file. My editor happens to default to showing the tabs as 4 spaces. One line of the file is:

<tab>c'<other stuff>

The c' is on column 5. 
Now when lilypond computes the textedit link for that note, it computes as column 9 so the textedit link is wrong for my editor. What is your proposed resolution?

Na(o) sábado, 3/11/2018, 15:02, David Wright <[hidden email]> escreveu:
On Sat 03 Nov 2018 at 09:35:54 (+0000), David Baptista wrote:
> I think the main way around this would be to expose a setting (ex tab-size)
> to be configured by the user.

Ouch. That's just a step backwards. Why fixed every N? Even
typewriters could set custom stops as desired. But then you
just get chaos when files are moved around.

There are two parts to handling tabs:

1) Pressing the TAB key. Here you can set your editor to do whatever
you like, custom or otherwise. But it should add spaces (± tabs),
as required, to move to the correct location.

2) What gets put in the file. Here, you should at least stick to the
standard TAB spacing of eight characters. It's also safer to avoid
the storing of any <SPACE><TAB> sequences in case someone somewhere
has forgotten to handle this case.

Anything else and you'll get tripped up somewhere. Fix LP and it'll
happen somewhere else instead.

> Federico Bruni <[hidden email]> escreveu no dia sábado, 3/11/2018 à(s)
> 07:55:
>
> > Hi David
> >
> > I confirm the problem.
> > But I wonder how lilypond can predict how many spaces an editor will
> > consider for a tab. It's impossible, isn't it? The best workaround is
> > not using tabs at all (or replace them with spaces upon save).
> >
> > For those who want to reproduce the problem, do not use Frescobaldi,
> > which converts tabs to spaces. Create a ly file with another editor,
> > use tabs, compile the PDF and you'll see that the COLUMN in
> > textedit://FILE:LINE:CHAR:COLUMN has a shift forward.
> >
> >
> > Il giorno sab 3 nov 2018 alle 7:03, David Baptista
> > <[hidden email]> ha scritto:
> > > I actually like then setup I currently have (Lilypond + Notepad++
> > > with custom Lilypond language definition for auto complete and syntax
> > > highlighting [the definitions file is out there on the Internet] plus
> > > Sumatra PDF as a viewer that allows PDF updating even when open - one
> > > custom Notepad shortcut for compiling with NppExec and that's it).
> > > The only part that is hacky is the referred "textedit" links because
> > > somehow internally, when lilypond generates them, it assumes that one
> > > tab equals 8 spaces and this is actually editor and configuration
> > > dependant (so it seems there should be a way to set tab size for
> > > textedit link calculations within Lilypond, which I do not know if it
> > > is the case).
> > >
> > > In consequence, I have some nasty calculations in a custom script for
> > > textedit:// links to actually land in the right column in Notepad++.
> > >
> > > Andrew Bernard <[hidden email]> escreveu no dia sexta,
> > > 2/11/2018 à(s) 22:35:
> > >> Hi David,
> > >>
> > >> Lilypond only cares about whitespace. Tbas are not integral to the
> > >> syntax, as they are in some programming languages. Why don't you
> > >> consider using Frescobaldi? Its a very capable and good lilypond
> > >> environment. I cant see why, given that it exists, anybody would use
> > >> a crude text editor. I can understand using emacs, however. Give it
> > >> a go!
> > >>
> > >> Andrew
> > >>
> > >>
> > >> On Sat, 3 Nov 2018 at 07:15, David Baptista
> > >> <[hidden email]> wrote:
> > >>>
> > >>> I have been fiddling with textedit on Windows, and I have
> > >>> determined that when source files contain tabs, lilypond always
> > >>> calculates the "column" parameter assuming that tabs occupy 8
> > >>> spaces. In my case I have my editor configured for 4 spaces, so the
> > >>> link always overshoots.

Cheers,
David.

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: textedit - how to set tab size for correct column calculation?

Br. Samuel Springuel
On 2018-11-03 2:10 PM, David Baptista wrote:
> <tab>c'<other stuff>

For Lilypond the tab is 8 spaces, thus the c' is on columns 9 and 10
(one column for each character).  Lilypond is not aware of your editor
settings (which change that result) and thus cannot account for that.
The "\t" = "        " convention is an old one [1].  There has been a
trend in recent times to reduce the number of spaces, especially for
programming languages which use indentation as a meaningful
representation of nesting level (and have lots of nesting).  Since
Lilypond doesn't pay attention to indentation (it's merely an aesthetic
thing to make human reading of the program easier), there probably
hasn't been much call for breaking the old convention.

Your editor, on the other hand, knows that there is a tab there and that
it's displaying tabs as 4 spaces.  Clearly if the position it goes to
when following the textedit link is wrong, then it's taking the column
number to be the visible column number, not the hypothetical one which
would result if the tabs were expanded using the old 8 space convention.
  I don't know if your editor can be told "pretend tabs are 8 spaces
when computing column numbers but only display them as 4", but that's
the sort of thing you're asking it to do.

What you can probably do, however, is set the editor to auto-expand tabs
[2].  In this case, you can press the tab button and things will indent
normally, but the editor will automatically insert multiple spaces (4,
given your current settings) instead of tabs.  Thus your line would become:

 > <space><space><space><space>c'<other stuff>

In this case a space is a single column character and Lilypond and your
editor will agree that c' is in columns 5 and 6.  No issues with how
many spaces in a tab to deal with.

[1] https://superuser.com/a/355868
[2] I see you use Notepad++ so https://stackoverflow.com/a/7471232

--
✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝✝
Br. Samuel, OSB
(R. Padraic Springuel)
St. Anselm’s Abbey
4501 South Dakota Ave, NE
Washington, DC, 20017
202-269-2300
(c) 202-853-7036

PAX ☧ ΧΡΙΣΤΟΣ

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user
Reply | Threaded
Open this post in threaded view
|

Re: textedit - how to set tab size for correct column calculation?

David Wright
On Sat 03 Nov 2018 at 15:05:42 (-0400), Br. Samuel Springuel wrote:
> On 2018-11-03 2:10 PM, David Baptista wrote:
> > <tab>c'<other stuff>
>
> For Lilypond the tab is 8 spaces, thus the c' is on columns 9 and 10
> (one column for each character).  Lilypond is not aware of your editor
> settings (which change that result) and thus cannot account for that.
> The "\t" = "        " convention is an old one [1].

Bear in mind that that substitution only works if you're at the
start of a line or at a tab stop position.

> There has been a
> trend in recent times to reduce the number of spaces, especially for
> programming languages which use indentation as a meaningful
> representation of nesting level (and have lots of nesting).  Since
> Lilypond doesn't pay attention to indentation (it's merely an
> aesthetic thing to make human reading of the program easier), there
> probably hasn't been much call for breaking the old convention.

Yes, the emacs configuration I use has the indentation set to 2 for
LilyPond (and 4 for python).

Note that repeated use of the TAB key for LilyPond has no effect after
the first press, ie it does not keep advancing by 2, but just sets the
appropriate indentation according to its rules. (For python, its
behaviour is completely different.)

BTW the convention is old, but well respected as far as TAB characters
in files is concerned. But what has changed completely since the time
of typewriters is the action taken when the TAB key is pressed. TAB
is an instruction to the computer (a control character) rather than
a literal.

> Your editor, on the other hand, knows that there is a tab there and
> that it's displaying tabs as 4 spaces.

And *there's* the difference (between Input Method and File Contents).
Pressing the TAB key only results in a TAB character being placed in
the file when the indentation required has reached 8 or more (as in
the example attached).

> Clearly if the position it
> goes to when following the textedit link is wrong, then it's taking
> the column number to be the visible column number, not the
> hypothetical one which would result if the tabs were expanded using
> the old 8 space convention.  I don't know if your editor can be told
> "pretend tabs are 8 spaces when computing column numbers but only
> display them as 4", but that's the sort of thing you're asking it to
> do.

None of this is necessary or relevant when "TAB as an input key" is
decoupled from "TAB as a character in a file".

> What you can probably do, however, is set the editor to auto-expand
> tabs [2].  In this case, you can press the tab button and things will
> indent normally, but the editor will automatically insert multiple
> spaces (4, given your current settings) instead of tabs.  Thus your
> line would become:
>
> > <space><space><space><space>c'<other stuff>
>
> In this case a space is a single column character and Lilypond and
> your editor will agree that c' is in columns 5 and 6.  No issues with
> how many spaces in a tab to deal with.
Correct. And of course there's no real need to use TAB characters
for this purpose at all with modern storage capabilities and
compression programs.

> [1] https://superuser.com/a/355868
> [2] I see you use Notepad++ so https://stackoverflow.com/a/7471232

Cheers,
David.

_______________________________________________
lilypond-user mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/lilypond-user

tabbing.ly (602 bytes) Download Attachment