Skip to content
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

Replace title and table sregexp to rx samples #31

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dunmaksim
Copy link

@dunmaksim dunmaksim commented Apr 5, 2023

  • Added rx builtin library.
  • RegExp's for title level 0-5 builded with rx.
  • RegExp for code and tables builded with rx.
  • Updated local variables code (like dns-mode.el).

close #24

adoc-mode.el Outdated
(setq-local comment-end "")
(setq-local comment-start-skip "^//[ \t]*")
(setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\'\\)")
(set (make-local-variable 'comment-column) 0)
Copy link
Owner

Choose a reason for hiding this comment

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

The previous code does exactly the same, but more compactly. :-)

adoc-mode.el Outdated
@@ -1022,8 +1093,8 @@ LEVEL starts at 1."

(defun adoc-make-two-line-title-underline (level &optional length)
"Returns a two line title underline.
LEVEL is the level of the title, starting at 1. LENGTH is the
line of the title's text. When nil it defaults to 4."
LEVEL is the level of the title, starting at 1. LENGTH is the
Copy link
Owner

Choose a reason for hiding this comment

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

This indentation seems wrong to me.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed.

adoc-mode.el Outdated
((adoc-table-regexp) 0 ,adoc-table-face)
((adoc-code-regexp) 0 ,adoc-code-face))
"Font lock keywords used to highlight text in AsciiDoc files mode."
:version "26.1"
Copy link
Owner

Choose a reason for hiding this comment

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

That's the version of adoc-mode, not Emacs.

@@ -3416,16 +3487,32 @@ LOCAL-ATTRIBUTE-FACE-ALIST before it is looked up in
"Keymap used in adoc mode.")


(defcustom adoc-mode-font-lock-keywords
Copy link
Owner

Choose a reason for hiding this comment

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

Why does this have the same name as the variable that you set above? Seems incorrect to me.

Copy link
Author

Choose a reason for hiding this comment

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

Variable adoc-mode-font-lock-keywords is used with (setq adoc-mode-font-lock-keywords...) but not defined. I don't see code like this:

(defvar adoc-mode-font-lock-keywords ...)

I used example from dns-mode.el for writing this code. Also I saw some TODO's like this:

1539 ;; TODO: use same regexps as for font lock

I think, it is a good idea replace functions for regexp to constants with more human readable (and maintain!) code, based on rx.

Copy link
Owner

Choose a reason for hiding this comment

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

I think you didn't get my point - this defcustom has some value that simple gets overwritten here:

(setq adoc-mode-font-lock-keywords (adoc-get-font-lock-keywords))

I'm fine with simplifying code by using rx, but I just don't understand what's the point of this defcustom right now.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe, I add before adoc-calc function declaration like this?

(defvar adoc-font-lock-keywords nil "Keywords for font-lock in `adoc-mode'.")

Copy link
Owner

Choose a reason for hiding this comment

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

I'd probably remove this adoc-calc completely, as few modes do something like this. If you want to factor in some font-lock customizations you typically just disable/enable the mode and its init code will take care of such updates. In general it's very bad style to have a top-level function call to initialize anything (as adoc-mode currently does).

@@ -2,6 +2,10 @@

## master (unreleased)

## 0.7.1 (2023-04-05)
Copy link
Owner

Choose a reason for hiding this comment

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

No need for this release header, as it will be added on release time. The heading here should actually be "Bugs fixed".

@@ -2676,7 +2747,7 @@ new customization demands."
(null adoc-unichar-alist))
(adoc-make-unichar-alist))

(setq adoc-font-lock-keywords (adoc-get-font-lock-keywords))
(setq adoc-mode-font-lock-keywords (adoc-get-font-lock-keywords))
Copy link
Owner

Choose a reason for hiding this comment

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

As you can see we intentionally don't use variables named adoc-mode-something most of the time, so we can have shorter identifiers. Please, don't rename this variable.

@bbatsov
Copy link
Owner

bbatsov commented Apr 7, 2023

You should also check the CI error - seems some rx invocation is incorrect.

@bbatsov
Copy link
Owner

bbatsov commented Apr 7, 2023

Adding a few unit tests covering your changes would be nice as well.

@dunmaksim
Copy link
Author

Perhaps it is worth closing this PR and opening it again after fixing all issues.

Should I remove the 'adoc-calc` function?

@dunmaksim dunmaksim marked this pull request as draft April 7, 2023 06:53
@bbatsov
Copy link
Owner

bbatsov commented Apr 7, 2023

Perhaps it is worth closing this PR and opening it again after fixing all issues.

Up to you - I don't mind keeping it open and marked as draft.

Should I remove the 'adoc-calc` function?

Yep.

eol)))
"Regular expression for AsciiDoc table.")

(defconst adoc-code-regexp
Copy link
Collaborator

@TobiasZawada TobiasZawada Aug 2, 2023

Choose a reason for hiding this comment

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

Side-note: Without source-style these are actually listings, see https://docs.asciidoctor.org/asciidoc/latest/blocks/delimited/.

(rx (seq
(minimal-match
bol
"----"
Copy link
Collaborator

@TobiasZawada TobiasZawada Aug 2, 2023

Choose a reason for hiding this comment

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

This rigid kind of regexp is wrong.
The fence is actually "----+" and the end fence must exactly match the start fence.
This makes nested blocks possible.
See https://docs.asciidoctor.org/asciidoc/latest/blocks/delimited/#linewise-delimiters.

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.

table colors and delimiter inconsistencies
3 participants