branch: elpa/adoc-mode
commit 47bb27d00cb747ca6e4178be9d1fd4d705c96408
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>

    Highlight checklist items
    
    An unordered list item whose text begins with [ ], [x]/[X], or [*] is a
    checklist item in modern AsciiDoc. Add adoc-kw-checkbox and the
    adoc-checkbox-face to fontify the checkbox marker.
---
 CHANGELOG.md             |  1 +
 adoc-mode.el             | 18 ++++++++++++++++++
 doc/spec-compliance.adoc | 11 ++++++-----
 test/adoc-mode-test.el   | 12 ++++++++++++
 4 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index f33e21a365..4a8a12ae80 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
 
 ### New features
 
+- Highlight checklist items. An unordered list item whose text begins with `[ 
]` (unchecked), `[x]`/`[X]`, or `[*]` (checked) now fontifies the checkbox with 
the new `adoc-checkbox-face` (inherits `font-lock-constant-face`).
 - Honour backslash escapes in inline formatting: a backslash before a 
formatting delimiter (e.g. `\*not bold*`, `\**nor this**`, `` \`nor code` ``) 
now de-emphasises the backslash and leaves the escaped span as literal text 
instead of fontifying it as markup. Previously the unconstrained forms still 
leaked an inner constrained match (`\**x**` highlighted `x`).
 - `fill-paragraph` (and auto-fill) now preserve AsciiDoc hard line breaks: a 
line ending in a space and a `+` is no longer merged with the following line. 
Filling still joins ordinary soft-wrapped lines and indents list-item 
continuations.
 - Add region-aware text-styling commands under the `C-c C-s` prefix, modelled 
on `markdown-mode`: `adoc-insert-bold` (`C-c C-s b`, `*text*`), 
`adoc-insert-italic` (`i`, `_text_`), `adoc-insert-monospace` (`m`, `` `text` 
``), `adoc-insert-highlight` (`h`, `#text#`), `adoc-insert-superscript` (`^`, 
`^text^`), `adoc-insert-subscript` (`~`, `~text~`), and `adoc-insert-link` 
(`l`). Each wraps the active region or the word at point, removes the markup 
again when it is already wrapped, and inse [...]
diff --git a/adoc-mode.el b/adoc-mode.el
index de8d21dc17..f1b6427bc3 100644
--- a/adoc-mode.el
+++ b/adoc-mode.el
@@ -692,6 +692,11 @@ AsciiDoc: *bold emphasis text* or _emphasis text_
   "Face for list item markers."
   :group 'adoc-faces)
 
+(defface adoc-checkbox-face
+  '((t (:inherit font-lock-constant-face)))
+  "Face for checklist checkboxes (`[ ]', `[x]', `[*]')."
+  :group 'adoc-faces)
+
 (defface adoc-code-face
   '((t (:inherit fixed-pitch)))
   "Face for inline code and fenced code blocks.
@@ -1833,6 +1838,18 @@ Concerning TYPE, LEVEL and SUB-TYPE see 
`adoc-re-llisti'."
    (lambda (end) (adoc-kwf-std end "^\\(\\+\\)[ \t]*$" '(1)))
    '(1 '(face adoc-meta-face adoc-reserved block-del) t)))
 
+(defun adoc-kw-checkbox ()
+  "Creates a keyword for font-lock which highlights checklist checkboxes.
+A checklist item is an unordered list item whose text begins with
+`[ ]' (unchecked), `[x]'/`[X]', or `[*]' (checked)."
+  (list
+   `(lambda (end)
+      (adoc-kwf-std end
+                    ,(concat "^[ \t]*\\(?:-\\|\\*\\{1,5\\}\\)[ \t]+"
+                             "\\(\\[[ xX*]\\]\\)[ \t]")
+                    '(1)))
+   '(1 'adoc-checkbox-face t)))
+
 (defun adoc-kw-delimited-block (del &optional text-face inhibit-text-reserved)
   "Creates a keyword for font-lock which highlights a delimited block.
 TEXT-FACE is a face name symbol or nil."
@@ -2517,6 +2534,7 @@ for multiline constructs to be matched."
    (adoc-kw-llisti 'adoc-labeled-normal 3)
    (adoc-kw-llisti 'adoc-labeled-qanda)
    (adoc-kw-llisti 'adoc-labeled-glossary)
+   (adoc-kw-checkbox)
    (adoc-kw-list-continuation)
 
    ;; Delimited blocks
diff --git a/doc/spec-compliance.adoc b/doc/spec-compliance.adoc
index 55031e1735..f9b24177d8 100644
--- a/doc/spec-compliance.adoc
+++ b/doc/spec-compliance.adoc
@@ -200,9 +200,9 @@ Findings are graded:
 | -
 
 | Checklists `* [ ]` / `* [x]` / `* [*]`
-| Not recognised (highlighted as a plain unordered item, the `[ ]`/`[x]`
-  is not treated as a checkbox)
-| Medium
+| *Fixed* - the checkbox is highlighted with `adoc-checkbox-face`
+  (`adoc-kw-checkbox`)
+| -
 
 | List continuation `+`
 | Supported
@@ -374,8 +374,9 @@ implements.
   reclassified as inline passthroughs (`adoc-kw-inline-passthrough`).
   Note: the menu / tempo templates still offer `+...+` / `++...++` under a
   "Monospaced" label; fold that into the template cleanup (item 5).
-. [ ] *Recognise checklist items* (`* [ ]`, `* [x]`, `* [*]`) with a
-  dedicated face for the checkbox.
+. [x] *Recognise checklist items* (`* [ ]`, `* [x]`, `* [*]`) with a
+  dedicated face for the checkbox. Done - `adoc-kw-checkbox` /
+  `adoc-checkbox-face`.
 . [ ] *Recognise the block-attribute ID/role/option shorthand* `[#id]`,
   `[#id.role]`, `[%opt]` on block attribute lines, and treat `[#id]` as a
   block anchor for `adoc-goto-ref-label` / xref following.
diff --git a/test/adoc-mode-test.el b/test/adoc-mode-test.el
index 2234295e69..837040f27f 100644
--- a/test/adoc-mode-test.el
+++ b/test/adoc-mode-test.el
@@ -680,6 +680,18 @@ Don't use it for anything real.")
                   ;; preceding newline, because we're at the beginning of the 
buffer
                   "lorem" 'adoc-gen-face "::" 'adoc-list-face " " nil "ipsum" 
'no-face))
 
+(ert-deftest adoctest-test-checklist ()
+  ;; checked and unchecked checklist boxes get the checkbox face
+  (adoctest-faces "checklist-checked"
+                  "*" 'adoc-list-face " " 'adoc-align-face "[x]" 
'adoc-checkbox-face " done" 'no-face)
+  (adoctest-faces "checklist-unchecked"
+                  "*" 'adoc-list-face " " 'adoc-align-face "[ ]" 
'adoc-checkbox-face " todo" 'no-face)
+  (adoctest-faces "checklist-star"
+                  "-" 'adoc-list-face " " 'adoc-align-face "[*]" 
'adoc-checkbox-face " done" 'no-face)
+  ;; a bracketed token that isn't a checkbox is left alone
+  (adoctest-faces "checklist-not-a-box"
+                  "*" 'adoc-list-face " " 'adoc-align-face "[z] nope" 
'no-face))
+
 (ert-deftest adoctest-test-inline-macros ()
   (adoctest-faces "inline-macros"
                   "commandname" 'adoc-command-face ":target[" 'adoc-meta-face 
"attribute list" 'adoc-value-face "]" 'adoc-meta-face))

Reply via email to