Skip to content

Customizable face for numbers #459

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

Merged
merged 8 commits into from
Nov 28, 2020

Conversation

jsmestad
Copy link
Contributor

@jsmestad jsmestad commented Jul 22, 2020

Background

I had made a patch to doom-emacs (see doomemacs/doomemacs#3613) to highlight 10_000 correctly after the Elixir formatter had run. As a next step, I wanted to have this functionality built into emacs-elixir mode for those who want to customize how numbers show up.

While I was in there, I did some general cleanup based on best practices and the Emacs Lisp docs.

Changes

  • Expose all variables as customizable
  • Increment version to 2.4.0
  • Expose font faces under the elixir group rather than font-lock-faces
  • Add elixir-numbers-face
    • Set to default so it does not conflict with today's functionality
  • Move elixir-format variables under the same elixir group.
  • Add lexical-binding: t to top of the file (from style guide)

Discussion

Is default appropriate?

@jsmestad jsmestad force-pushed the numbers-with-underscore branch 3 times, most recently from b563cda to cb58953 Compare July 22, 2020 18:48
@jsmestad jsmestad force-pushed the numbers-with-underscore branch from cb58953 to ce66d67 Compare July 22, 2020 18:52
@jsmestad
Copy link
Contributor Author

I changed up the test matrix as it was failing on Emacs 24.5 (same with master).

Looking around at other major modes, most have moved up to a minimum support of Emacs 26.3, so I did the same. I wanted to test Emacs 27.1 and Emacs 28.0.50, but EVM lacks support for these releases at the moment.

@jsmestad
Copy link
Contributor Author

@Trevoke and @victorolinasc I rolled back all the attempted CI fixes. Please take a look when you get the time 👍

Comment on lines +129 to +133
(numbers . ,(rx (and symbol-start
(? "-")
(+ digit)
(0+ (and "_" (= 3 digit)))
symbol-end)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is too naive for parsing numbers in Elixir. I propose the following:

Suggested change
(numbers . ,(rx (and symbol-start
(? "-")
(+ digit)
(0+ (and "_" (= 3 digit)))
symbol-end)))
(numbers . ,(rx (and symbol-start
(zero-or-one "-")
(one-or-more digit)
(zero-or-more (or digit (seq ?_ digit)))
(zero-or-one ".")
(zero-or-more (or digit (seq ?_ digit)))
symbol-end)))

This will match things like:

0
-0
0_0
-0_0.0_0

I know they are not what the formatter will typically do but I see no reason why we should bind this face to only what the formatter does.

Not sure how this will behave inside comments, heredocs and so on though.

Also I am trying to follow the use of zero-or-more and friends because of what the rest of the file is using.

Tests would be good here too if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you prefer that, that's fine. I'll leave it your capable hands to get this across the finish line 🙏

Copy link
Contributor

@axelson axelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this has some good changes (and I really like the documentation improvements for variables).

I think any future work to more flexibly support more number formats can be made as a followup PR.

@axelson axelson merged commit bd43656 into elixir-editors:master Nov 28, 2020
axelson added a commit that referenced this pull request Nov 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants