Declutter patterns for org-mode tags

32 skatījumi
Pāriet uz pirmo nelasīto ziņojumu

Edward K. Ream

nelasīta,
2017. gada 22. nov. 05:05:2522.11.17
uz leo-editor
This thread is a continuation of
"ENB: Completing #578: support for org-mode tags", focused exclusively on the declutter regex.

tl;dr: Read the summary. 

My original attempt was:

RULE ^([^:]*):([\w_@]+:)+\s*$
REPLACE
\1

This is almost what we want.  It will compute \1 properly for these strings:

abc :tag1:tag2:
abc
:tag1:tag2:

but not if the head (everything before the tags) contains a colon.  This fails:

abc:xyz :tag1:tag2:

Imo, if any regex is going to work, it is likely to involve a lookahead assertion.  Indeed, after considerable experimentation, the following almost works:

RULE ^((.(?!:[\w_@]+:))+)\s*:([\w_@]+:)+\s*$
REPLACE
\1

Now the following all match, setting \1 correctly.

abc :tag1:tag2:
abc
:xyz :tag1:tag2:

However, the space before the first tag is required.  These do not match:

abc:tag1:tag2:
abc
:xyz:tag1:tag2:

I'm not sure whether whitespace will always precede the first org-mode tag.  Leo's org-mode writer does write a single space before the list of tags.

Summary

Rev 59bd6b1 adds two disabled declutter rules for org-mode tags.

Rule 1: This rule does not allow ":" before the trailing list of tags:

RULE ^([^:]*):([\w_@]+:)+\s*$
REPLACE
\1

Rule 2: This rule does allow ":" before the trailing list of tags, but only if the list of tags is preceded by at least one blank. 

RULE ^((.(?!:[\w_@]+:))+)\s*:([\w_@]+:)+\s*$
REPLACE
\1

Leo's org-mode writer supplies that blank, but I'm not sure about headlines produced by org-mode itself.

Imo, rule 2 is preferable.  If the rule fails when tags are actually present, it is easy enough to add the required blank. As soon as the user does so, the tags will disappear.

What do you think, Amigos?

Edward

Edward K. Ream

nelasīta,
2017. gada 22. nov. 05:11:1022.11.17
uz leo-editor
On Wednesday, November 22, 2017 at 4:05:25 AM UTC-6, Edward K. Ream wrote:

> This thread...[focuses] exclusively on the declutter regex.

I should add that the org-mode importer regex is much simpler, because the code only needs to recognize the trailing tags themselves, not the head. Indeed, the code finds tags using:

tag_pattern = re.compile(r':([\w_@]+:)+\s*$')

This completely avoids the problem of specifying what doesn't match. For details, see the org_i.clean_headline method. But for decluttering, we have to know what precedes the tags.

Edward

Edward K. Ream

nelasīta,
2017. gada 22. nov. 06:09:2122.11.17
uz leo-editor
On Wednesday, November 22, 2017 at 4:11:10 AM UTC-6, Edward K. Ream wrote:
 
the org-mode importer regex is much simpler, because the code only needs to recognize the trailing tags themselves, not the head.

This suggests a much easier way to specify org-mode regex patterns.  I knew about this possibility several days ago, but I wanted to give regex's a chance to show what they can do.  They failed ;-)

Instead of contortions trying to specify \1, the declutter mechanism should support this:

RULE :([\w_@]+:)+\s*$
REPLACE
-HEAD

This tells the declutter code to replace the headline by the text preceding the matched text.  Similarly:

- REPLACE-TAIL replaces the headline by the text that follows the matched text.

- REPLACE-REST replaces the headline by everything except the matched text.

These should be easy to do.

Edward

Edward K. Ream

nelasīta,
2017. gada 22. nov. 07:39:4422.11.17
uz leo-editor
On Wednesday, November 22, 2017 at 5:09:21 AM UTC-6, Edward K. Ream wrote


Instead of contortions trying to specify \1, the declutter mechanism should support this:

RULE :([\w_@]+:)+\s*$
REPLACE
-HEAD

This tells the declutter code to replace the headline by the text preceding the matched text.  Similarly:

- REPLACE-TAIL replaces the headline by the text that follows the matched text.

- REPLACE-REST replaces the headline by everything except the matched text.

Done at f5bca85.  This is highly experimental code, despite looking straightforward.

Please report any problems immediately.

Edward

Edward K. Ream

nelasīta,
2017. gada 22. nov. 08:01:3922.11.17
uz leo-editor
Rev fee9130 simplifies the declutter code significantly, but this remains experimental code.

Edward

Edward K. Ream

nelasīta,
2017. gada 22. nov. 12:48:1522.11.17
uz leo-editor
On Wednesday, November 22, 2017 at 7:01:39 AM UTC-6, Edward K. Ream wrote:
Rev fee9130 simplifies the declutter code significantly, but this remains experimental code.

Recent revs update the declutter docs in LeoDocs.leo and leoSettings.leo.  Both have been pushed to master.

At present I am not able to connect to my brother Speed's server, so I the revised docs are not on the web.  However, the docs in LeoDocs.leo are readable enough.  See:

LeoDocs.leo#Leo's Documentation-->Users Guide-->Customizing Leo-->
@rst html\customizing.html-->Decluttering headlines

Edward
Atbildēt visiem
Atbildēt autoram
Pārsūtīt
0 jauni ziņojumi