From ea253d7dc09d8619ebf4805518d643423df3b222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=94=D1=83=D0=BD?= =?UTF-8?q?=D0=B0=D0=B5=D0=B2=D1=81=D0=BA=D0=B8=D0=B9?= Date: Wed, 5 Apr 2023 11:58:33 +0300 Subject: [PATCH 1/2] Replace title and table sregexp to rx samples --- adoc-mode.el | 131 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 109 insertions(+), 22 deletions(-) diff --git a/adoc-mode.el b/adoc-mode.el index e661047..3e0d086 100644 --- a/adoc-mode.el +++ b/adoc-mode.el @@ -47,6 +47,7 @@ (require 'cl-lib) (require 'tempo) +(require 'rx) (defconst adoc-mode-version "0.7.0-snapshot" @@ -261,9 +262,9 @@ aligned. (defvar adoc-align-face 'adoc-align-face) ;; Despite the comment in font-lock.el near 'defvar font-lock-comment-face', it -;; seems I still need variables to refer to faces in adoc-font-lock-keywords. +;; seems I still need variables to refer to faces in adoc-mode-font-lock-keywords. ;; Not having variables and only referring to face names in -;; adoc-font-lock-keywords does not work. +;; adoc-mode-font-lock-keywords does not work. (defvar adoc-delimiter 'adoc-meta-face) (defvar adoc-hide-delimiter 'adoc-meta-hide-face) @@ -309,8 +310,77 @@ customizable.") (defvar adoc-mode-abbrev-table nil "Abbrev table in use in adoc-mode buffers.") -(defvar adoc-font-lock-keywords nil - "Font lock keywords in adoc-mode buffers.") +(defconst adoc-title-0-regexp + (rx bol + "=" + space + (one-or-more any) + eol) + "Regular expression for AsciiDoc Document Title (Level 0).") + +(defconst adoc-title-1-regexp + (rx bol + "==" + space + (one-or-more any) + eol) + "Regular expression for AsciiDoc Level 1 Section Title.") + +(defconst adoc-title-2-regexp + (rx bol + "===" + space + (one-or-more any) + eol) + "Regular expression for AsciiDoc Level 2 Section Title.") + +(defconst adoc-title-3-regexp + (rx bol + "====" + space + (one-or-more any) + eol) + "Regular expression for AsciiDoc Level 3 Section Title.") + +(defconst adoc-title-4-regexp + (rx bol + "====" + space + (one-or-more any) + eol) + "Regular expression for AsciiDoc Level 4 Section Title.") + +(defconst adoc-title-5-regexp + (rx bol + "=====" + space + (one-or-more any) + eol) + "Regular expression for AsciiDoc Level 5 Section Title.") + +(defconst adoc-table-regexp + (rx (seq + (minimal-match + bol + "|===" + eol + (zero-or-more anything) + bol + "|===" + eol))) + "Regular expression for AsciiDoc table.") + +(defconst adoc-code-regexp + (rx (seq + (minimal-match + bol + "----" + eol + (zero-or-more anything) + bol + "----" + eol))) + "Regular expression for AsciiDoc code block.") (defvar adoc-replacement-failed nil ) @@ -706,13 +776,13 @@ language. (defvar adoc-verbatim-face 'adoc-verbatim-face) (defface adoc-warning-face - '((t :inherit (font-lock-warning-face))) + '((t :inherit font-lock-warning-face)) "For things that should stand out" :group 'adoc-faces) (defvar adoc-warning-face 'adoc-warning-face) (defface adoc-table-face - '((t (:inherit (adoc-code-face)))) + '((t (:inherit fixed-pitch))) "Face for tables." :group 'adoc-faces) (defvar adoc-table-face 'adoc-table-face) @@ -865,6 +935,7 @@ this feature." ;; from asciidoc.conf: ^= +(?P[\S].*?)( +=)?$ ;; asciidoc src code: Title.isnext reads two lines, which are then parsed by ;; Title.parse. The second line is only for the underline of two line titles. + (defun adoc-re-one-line-title (level) "Returns a regex matching a one line title of the given LEVEL. When LEVEL is nil, a one line title of any level is matched. @@ -878,7 +949,7 @@ match-data has these sub groups: == my title == n ---12------23------ - 4--4" +4--4" (let* ((del (if level (make-string (+ level 1) ?=) (concat "=\\{1," (+ adoc-title-max-level 1) "\\}")))) @@ -933,7 +1004,7 @@ DEL is described in `adoc-re-two-line-title-undlerline'. match-data has these sub groups: 1 dummy, so that group 2 is the title's text as in - adoc-re-one-line-title +adoc-re-one-line-title 2 title's text 3 delimiter 0 only chars that belong to the title block element" @@ -953,8 +1024,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 + line of the title's text. When nil it defaults to 4." (unless length (setq length 4)) (let* ((repetition-cnt (if (>= length 2) (/ length 2) 1)) @@ -1043,7 +1114,7 @@ Subgroups: 3 delimiter incl trailing whites 4 delimiter only - foo :: bar +foo :: bar -12--23-3 44" (cond @@ -2449,7 +2520,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)) (when (and font-lock-mode (eq major-mode 'adoc-mode)) (font-lock-flush) (font-lock-ensure))) @@ -3189,16 +3260,32 @@ LOCAL-ATTRIBUTE-FACE-ALIST before it is looked up in "Keymap used in adoc mode.") +(defcustom adoc-mode-font-lock-keywords + `( + ((adoc-title-0-regexp) 0 ,adoc-title-0-face) + ((adoc-title-1-regexp) 0 ,adoc-title-1-face) + ((adoc-title-2-regexp) 0 ,adoc-title-2-face) + ((adoc-title-3-regexp) 0 ,adoc-title-3-face) + ((adoc-title-4-regexp) 0 ,adoc-title-4-face) + ((adoc-title-5-regexp) 0 ,adoc-title-5-face) + ((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" + :type 'sexp + :group 'adoc-mode) + + ;;;###autoload (define-derived-mode adoc-mode text-mode "adoc" "Major mode for editing AsciiDoc text files. Turning on Adoc mode runs the normal hook `adoc-mode-hook'." ;; comments - (setq-local comment-column 0) - (setq-local comment-start "// ") - (setq-local comment-end "") - (setq-local comment-start-skip "^//[ \t]*") - (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\'\\)") + (set (make-local-variable 'comment-column) 0) + (set (make-local-variable 'comment-start) "// ") + (set (make-local-variable 'comment-end) "") + (set (make-local-variable 'comment-start-skip) "^//[ \t]*") + (set (make-local-variable 'comment-end-skip) "[ \t]*\\(?:\n\\|\\'\\)") ;; paragraphs (setq-local paragraph-separate (adoc-re-paragraph-separate)) @@ -3206,11 +3293,11 @@ Turning on Adoc mode runs the normal hook `adoc-mode-hook'." (setq-local paragraph-ignore-fill-prefix t) ;; font lock - (setq-local font-lock-defaults - '(adoc-font-lock-keywords - nil nil nil nil - (font-lock-multiline . t) - (font-lock-mark-block-function . adoc-font-lock-mark-block-function))) + (set (make-local-variable 'font-lock-defaults) + '(adoc-mode-font-lock-keywords + nil nil nil nil + (font-lock-multiline . t) + (font-lock-mark-block-function . adoc-font-lock-mark-block-function))) (setq-local font-lock-extra-managed-props '(adoc-reserved adoc-attribute-list)) (setq-local font-lock-unfontify-region-function 'adoc-unfontify-region-function) From e71a6264789a0dddc00e099971aa007162d60438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B0=D0=BA=D1=81=D0=B8=D0=BC=20=D0=94=D1=83=D0=BD?= =?UTF-8?q?=D0=B0=D0=B5=D0=B2=D1=81=D0=BA=D0=B8=D0=B9?= <mdunaevskii@astralinux.ru> Date: Thu, 6 Apr 2023 09:02:09 +0300 Subject: [PATCH 2/2] ISSUE-24 Updated Changelog --- CHANGELOG.md | 4 ++++ adoc-mode.el | 18 +++++++++--------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f94c9c..2e37039 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## master (unreleased) +## 0.7.1 (2023-04-05) + +- [#24](https://github.com/bbatsov/adoc-mode/issues/24): Fix regexp for tables font-locking. + ### New features - [#21](https://github.com/bbatsov/adoc-mode/pull/21): Add support for native font-locking in code blocks. diff --git a/adoc-mode.el b/adoc-mode.el index 16826af..996ec74 100644 --- a/adoc-mode.el +++ b/adoc-mode.el @@ -47,7 +47,7 @@ (require 'rx) (defconst adoc-mode-version "0.8.0-snapshot" - "adoc mode version number. + "`adoc-mode' version number. Based upon AsciiDoc version 8.5.2. I.e. regexeps and rules are taken from that version's asciidoc.conf / manual.") @@ -1093,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 +line of the title's text. When nil it defaults to 4." (unless length (setq length 4)) (let* ((repetition-cnt (if (>= length 2) (/ length 2) 1)) @@ -3498,7 +3498,7 @@ LOCAL-ATTRIBUTE-FACE-ALIST before it is looked up in ((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" + :version "0.8.0-snapshot" :type 'sexp :group 'adoc-mode) @@ -3508,11 +3508,11 @@ LOCAL-ATTRIBUTE-FACE-ALIST before it is looked up in "Major mode for editing AsciiDoc text files. Turning on Adoc mode runs the normal hook `adoc-mode-hook'." ;; comments - (set (make-local-variable 'comment-column) 0) - (set (make-local-variable 'comment-start) "// ") - (set (make-local-variable 'comment-end) "") - (set (make-local-variable 'comment-start-skip) "^//[ \t]*") - (set (make-local-variable 'comment-end-skip) "[ \t]*\\(?:\n\\|\\'\\)") + (setq-local comment-column 0) + (setq-local comment-start "// ") + (setq-local comment-end "") + (setq-local comment-start-skip "^//[ \t]*") + (setq-local comment-end-skip "[ \t]*\\(?:\n\\|\\'\\)") ;; paragraphs (setq-local paragraph-separate (adoc-re-paragraph-separate))