-
Notifications
You must be signed in to change notification settings - Fork 164
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Colour quoted text #1441
base: master
Are you sure you want to change the base?
[RFC] Colour quoted text #1441
Conversation
Welcome to alot @Nelyah, and thanks for starting to contribute right away! Would this only change the urwid representation or does your code changes the text of follow-up reply emails? |
Thank you @pazz, this is a wonderful piece of software you got there! Here is a screenshot of a sample mail. I set up the colours being close from one another, but this can be changed with the options
No, this should only change the urwid representation. The only real modification to existing code is to change the |
I just added the tests as well |
Thank you for the feedback, @lucc! And sorry if this has taken some time and back and forth. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please squash down those commits that make trivial changes or revert stuff you introduced yourself earlier? I started to review the commits one by one and realized that some of my (line) comments are already addressed in later commits...
alot/widgets/colour_text.py
Outdated
is_quoted = False | ||
quote_colour = None | ||
symbol = settings.get('quote_symbol') | ||
if symbol is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the fallback option when getting the config setting? https://github.com/pazz/alot/blob/master/alot/settings/manager.py#L239
(note that the defaul is "> ", with a trailing space)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it make sense here to specify a fallback? If I understand correctly we would still get the default settings value of the variable we're requesting (in this case from quote_symbol
: >
), even if no fallback is defined.
@@ -17,6 +17,10 @@ input_timeout = float(default=1.0) | |||
# .. note:: this config setting is equivalent to, but independent of, the 'search.exclude_tags' in the notmuch config. | |||
exclude_tags = force_list(default=list()) | |||
|
|||
# Show quotes be parsed | |||
parse_quotes = boolean(default=True) | |||
quote_symbol = string(default='>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use the existing quote_prefix
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't see it before!
However, I notice that it has a space added to it. That would mean that a line like:
>> Level 2 quote level
wouldn't get interpreted correctly, because the regex r'^ *({} *){{{}}}'.format(symbol, quote_level)
wouldn't match. It would still be possible to change it but the default wouldn't work really well.
I'm not sure in what context quote_prefix
is used. A first solution would be to remove the space and accommodate for this wherever it is used. A second could be to rename my quote_symbol
to something more explicit, like quotation_regex_detection
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this new option is necessary. The two most commonly used characters for quoting text are >
and |
, and I've only ever seen the bracket being used (wikipedia reference).
It would make the PR leaner to assume only those two characters highlight quotes in messages, plus it would avoid some weird unit tests verifying that the code behaves as expected when using [Aa]
for quote_symbol
.
I'll do the licence change and add the quote_prefix (didn't see it previously). |
You can do an interactive rebase. Like this |
Where are we on this? It'd be a shame to let this get too old and diverge from master too much to be useful.. |
Oh, I'm sorry. I had some things happening at the time and it just slipped out of my mind. I will get back to this in the next few days! Sorry again for the delay... |
Up to quote_level 7
Also generate the docs for those settings
As of now, only the function parse_quotes is implemented, but other ideas could be added.
… True and quotes were found
Add tests for checking that: - Regex works - Empty quote means we return None - Check we're actually getting the expected attribute
dec790c
to
4f1fd0e
Compare
I rebased and resolved a few merge conflicts (mainly in I added a few |
@@ -17,6 +17,10 @@ input_timeout = float(default=1.0) | |||
# .. note:: this config setting is equivalent to, but independent of, the 'search.exclude_tags' in the notmuch config. | |||
exclude_tags = force_list(default=list()) | |||
|
|||
# Show quotes be parsed | |||
parse_quotes = boolean(default=True) | |||
quote_symbol = string(default='>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this new option is necessary. The two most commonly used characters for quoting text are >
and |
, and I've only ever seen the bracket being used (wikipedia reference).
It would make the PR leaner to assume only those two characters highlight quotes in messages, plus it would avoid some weird unit tests verifying that the code behaves as expected when using [Aa]
for quote_symbol
.
symbol = settings.get('quote_symbol') | ||
quote_colour = None | ||
|
||
for quote_level in range(1, max_quote_level+1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think running 7 regex matches on a line that has 7 levels of nested quoting is too much.
I made it work (with a dirty patch) on my local branch with only two calls to re.match()
, for any amount of nesting, I think it's the better way to go about it.
Plus if we remove the quote_symbol
option (c.f. my other comment), it will be easier to parse spaces properly (RFC reference)
'colourmode': 256 | ||
} | ||
|
||
SETTINGS_test_symbol_regex = {'quote_symbol': '([Aa]|<>.b|>)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in another comment, this is a weird thing to test for. Maybe we don't need the code to be that generic.
|
||
else: | ||
# If there is no match at some point, | ||
# we simply use the last level match colour |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think cycling back to the colours for the first level of quoting is a better option:
- 8 → 1
- 9 → 2
- …
- 15 → 1
- 16 → 2
etc.
Basically a modulo.
Context
I feel like being able to render quote text according to the quoted level with colours is important. At least it is for me in terms of readability.
This PR is to answer this particular feature. An issue has been opened #746, but it was answered with #612 and then #1015. These are great features, but don't quite target this specific issue.
Modifications
I modified the file
alot/widget/thread.py
to call theparse_text_colour
function, if we are looking at words linewise. The functionparse_text_colour
asks the config to check if we want to parse quoted text. If yes, it proceeds and calls the functionparse_quotes
.The latter returns the theme value associated with the quote_level in the theme file (if there is one).
Example configuration
This is working well for me and it passes the tests. This is how I set it up in my config file to make either
>
or four spaces a quote symbol.:I am fairly new to this project, please let me know if there are obvious things I am missing.