emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[nongnu] elpa/adoc-mode e144653832 005/199: refactored title constructs,


From: ELPA Syncer
Subject: [nongnu] elpa/adoc-mode e144653832 005/199: refactored title constructs, initiated testing adoc-mode
Date: Sun, 3 Sep 2023 06:59:11 -0400 (EDT)

branch: elpa/adoc-mode
commit e1446538322c3fddd20aa23628a34f75a40b83f2
Author: Florian Kaufmann <sensorflo@gmail.com>
Commit: Florian Kaufmann <sensorflo@gmail.com>

    refactored title constructs, initiated testing adoc-mode
    
    only concerning title constructs
    - no longer use varibles pointing to faces
    - deleted adoc faces, only using markup faces
    - simple tests
    - regexps now all use adoc-two-line-title-del instead own redundant literals
---
 adoc-mode-test.el | 80 +++++++++++++++++++++++++++++++++++++++++++++++++
 adoc-mode.el      | 89 +++++++++++++++++++++++--------------------------------
 2 files changed, 117 insertions(+), 52 deletions(-)

diff --git a/adoc-mode-test.el b/adoc-mode-test.el
new file mode 100644
index 0000000000..3d3ddf59e9
--- /dev/null
+++ b/adoc-mode-test.el
@@ -0,0 +1,80 @@
+(require 'ert)
+(require 'adoc-mode)
+
+;; todo
+;; test for font lock multiline property 
+
+(defun adoctest-make-buffer (&rest args)
+  (set-buffer (get-buffer-create "adoctest")) 
+  (delete-region (point-min) (point-max))
+
+  (while args
+    (insert (propertize (car args) 'adoctest (cadr args)))
+    (setq args (cddr args)))
+
+  (adoc-mode)
+  (font-lock-fontify-buffer))
+
+(ert-deftest adoctest-foo ()
+  ;; todo
+  ;;  !!!!!!!!!!!!!
+  ;;  Lock Support Mode must be set to nil
+  ;;  !!!!!!!!!!!!!
+
+
+  ;; the white after = really is part of the delimiter
+  (adoctest-make-buffer
+   "= " markup-meta-hide-face "document title" markup-title-0-face "\n" nil
+   "\n" nil
+   "== " markup-meta-hide-face "chapter 1" markup-title-1-face "\n" nil
+   "\n" nil
+   "=== " markup-meta-hide-face "chapter 2" markup-title-2-face "\n" nil
+   "\n" nil
+   "==== " markup-meta-hide-face "chapter 3" markup-title-3-face "\n" nil
+   "\n" nil
+   "===== " markup-meta-hide-face "chapter 4" markup-title-4-face "\n" nil
+   "\n" nil
+
+   "= " markup-meta-hide-face "document title" markup-title-0-face " =" 
markup-meta-hide-face "\n" nil
+   "\n" nil
+   "== " markup-meta-hide-face "chapter 1" markup-title-1-face " ==" 
markup-meta-hide-face "\n" nil
+   "\n" nil
+   "=== " markup-meta-hide-face "chapter 2" markup-title-2-face " ===" 
markup-meta-hide-face "\n" nil
+   "\n" nil
+   "==== " markup-meta-hide-face "chapter 3" markup-title-3-face " ====" 
markup-meta-hide-face "\n" nil
+   "\n" nil
+   "===== " markup-meta-hide-face "chapter 4" markup-title-4-face " =====" 
markup-meta-hide-face "\n" nil
+   "\n" nil
+
+   ;; todo
+   ;; ensure somehow adoc-enable-two-line-title is t
+   "document title" markup-title-0-face "\n" nil
+   "==============" markup-meta-hide-face "\n" nil
+   "\n" nil
+   "chapter 1" markup-title-1-face "\n" nil
+   "---------" markup-meta-hide-face "\n" nil
+   "\n" nil
+   "chapter 2" markup-title-2-face "\n" nil
+   "~~~~~~~~~" markup-meta-hide-face "\n" nil
+   "\n" nil
+   "chapter 3" markup-title-3-face "\n" nil
+   "^^^^^^^^^" markup-meta-hide-face "\n" nil
+   "\n" nil
+   "chapter 4" markup-title-4-face "\n" nil
+   "+++++++++" markup-meta-hide-face "\n" nil
+   "\n" nil
+   )
+
+  (goto-char (point-min))
+  (let ((not-done t))
+    (while not-done
+      (let* ((tmp (get-text-property (point) 'adoctest))
+            (tmp2 (get-text-property (point) 'face)))
+       (when tmp
+         (ert-should (equal tmp2 tmp))))
+      (if (< (point) (point-max))
+         (forward-char 1)
+       (setq not-done nil)))))
+
+(ert-run-tests-interactively "^adoctest-")
+
diff --git a/adoc-mode.el b/adoc-mode.el
index 670fb68f33..cdd49fe447 100644
--- a/adoc-mode.el
+++ b/adoc-mode.el
@@ -222,11 +222,6 @@ aligned.
   :group 'adoc)
 
 (define-obsolete-face-alias 'adoc-generic 'markup-gen-face "23.3")
-(define-obsolete-face-alias 'adoc-title-0 'markup-title-0-face "23.3")
-(define-obsolete-face-alias 'adoc-title-1 'markup-title-1-face "23.3")
-(define-obsolete-face-alias 'adoc-title-2 'markup-title-2-face "23.3")
-(define-obsolete-face-alias 'adoc-title-3 'markup-title-3-face "23.3")
-(define-obsolete-face-alias 'adoc-title-4 'markup-title-4-face "23.3")
 (define-obsolete-face-alias 'adoc-monospace 'markup-typewriter-face "23.3")
 (define-obsolete-face-alias 'adoc-strong 'markup-strong-face "23.3")
 (define-obsolete-face-alias 'adoc-emphasis 'markup-emphasis-face "23.3")
@@ -251,11 +246,6 @@ aligned.
 ;; adoc-font-lock-keywords does not work.
 (defvar adoc-align 'adoc-align)
 (defvar adoc-generic 'markup-gen-face)
-(defvar adoc-title-0 'markup-title-0-face)
-(defvar adoc-title-1 'markup-title-1-face)
-(defvar adoc-title-2 'markup-title-2-face)
-(defvar adoc-title-3 'markup-title-3-face)
-(defvar adoc-title-4 'markup-title-4-face)
 (defvar adoc-monospace 'markup-typewriter-face)
 (defvar adoc-strong 'markup-strong-face)
 (defvar adoc-emphasis 'markup-emphasis-face)
@@ -268,7 +258,7 @@ aligned.
 (defvar adoc-reference 'markup-reference-face)
 (defvar adoc-secondary-text 'markup-secondary-text-face)
 (defvar adoc-delimiter 'markup-meta-face)
-(defvar adoc-hide-delimiter 'markup-hide-delimiter-face)
+(defvar adoc-hide-delimiter 'markup-meta-hide-face)
 (defvar adoc-anchor 'markup-anchor-face)
 (defvar adoc-comment 'markup-comment-face)
 (defvar adoc-warning 'markup-error-face)
@@ -352,8 +342,8 @@ match-data has his this sub groups:
   (when (not (eq (length del) 2))
     (error "two line title delimiters must be 2 chars long"))
   (concat
-   ;; title must contain at least one \w character. You don't see that in
-   ;; asciidoc.conf, only in asciidoc source code.
+   ;; title text (the first line) must contain at least one \w character. You
+   ;; don't see that in asciidoc.conf, only in asciidoc source code.
    "\\(^.*?[a-zA-Z0-9_].*?\\)[ \t]*\n" 
    "\\("
      "\\(?:" (regexp-quote del) "\\)+"
@@ -682,17 +672,17 @@ subgroups:
   ;; attribute list
   ;; title
   ;;   single line
-  ,(list (adoc-re-one-line-title 0) adoc-hide-delimiter adoc-title-0 
adoc-hide-delimiter)
-  ,(list (adoc-re-one-line-title 1) adoc-hide-delimiter adoc-title-1 
adoc-hide-delimiter)
-  ,(list (adoc-re-one-line-title 2) adoc-hide-delimiter adoc-title-2 
adoc-hide-delimiter)
-  ,(list (adoc-re-one-line-title 3) adoc-hide-delimiter adoc-title-3 
adoc-hide-delimiter)
-  ,(list (adoc-re-one-line-title 4) adoc-hide-delimiter adoc-title-4 
adoc-hide-delimiter)
+  ,(list (adoc-re-one-line-title 0) adoc-hide-delimiter markup-title-0-face 
adoc-hide-delimiter)
+  ,(list (adoc-re-one-line-title 1) adoc-hide-delimiter markup-title-1-face 
adoc-hide-delimiter)
+  ,(list (adoc-re-one-line-title 2) adoc-hide-delimiter markup-title-2-face 
adoc-hide-delimiter)
+  ,(list (adoc-re-one-line-title 3) adoc-hide-delimiter markup-title-3-face 
adoc-hide-delimiter)
+  ,(list (adoc-re-one-line-title 4) adoc-hide-delimiter markup-title-4-face 
adoc-hide-delimiter)
   ;;   double line
-  ,(list (adoc-re-two-line-title "==") adoc-title-0 adoc-hide-delimiter)
-  ,(list (adoc-re-two-line-title "--") adoc-title-1 adoc-hide-delimiter)
-  ,(list (adoc-re-two-line-title "~~") adoc-title-2 adoc-hide-delimiter)
-  ,(list (adoc-re-two-line-title "^^") adoc-title-3 adoc-hide-delimiter)
-  ,(list (adoc-re-two-line-title "++") adoc-title-4 adoc-hide-delimiter)
+  ,(list (adoc-re-two-line-title (nth 0 adoc-two-line-title-del)) 
markup-title-0-face adoc-hide-delimiter)
+  ,(list (adoc-re-two-line-title (nth 1 adoc-two-line-title-del)) 
markup-title-1-face adoc-hide-delimiter)
+  ,(list (adoc-re-two-line-title (nth 2 adoc-two-line-title-del)) 
markup-title-2-face adoc-hide-delimiter)
+  ,(list (adoc-re-two-line-title (nth 3 adoc-two-line-title-del)) 
markup-title-3-face adoc-hide-delimiter)
+  ,(list (adoc-re-two-line-title (nth 4 adoc-two-line-title-del)) 
markup-title-4-face adoc-hide-delimiter)
   ;; macros
   ;; lists
   ;; blocks
@@ -754,33 +744,34 @@ subgroups:
 ;; match because of adoc-reserved, following quotes of the same type which
 ;; should be highlighed are not, because font-lock abandons that keyword.
 
-(defmacro adoc-kw-one-line-title (level text-face)
+(defun adoc-kw-one-line-title (level text-face)
   "Creates a keyword for font-lock which highlights one line titles"
-  `(list
+  (list
     ;; matcher function
-    (lambda (end)
+    `(lambda (end)
       (and (re-search-forward ,(adoc-re-one-line-title level) end t)
            (not (text-property-not-all (match-beginning 0) (match-end 0) 
'adoc-reserved nil))))
     ;; highlighers
-    '(1 '(face adoc-hide-delimiter adoc-reserved t) t)
-    '(2 ,text-face t) 
-    '(3 '(face adoc-hide-delimiter adoc-reserved t) t)))
+    '(1 '(face markup-meta-hide-face adoc-reserved t) t)
+    `(2 ,text-face t) 
+    '(3 '(face markup-meta-hide-face adoc-reserved t) t)))
 
 ;; todo: highlight bogous 'two line titles' with warning face
-(defmacro adoc-kw-two-line-title (del text-face)
+;; todo: completly remove keyword when adoc-enable-two-line-title is nil
+(defun adoc-kw-two-line-title (del text-face)
   "Creates a keyword for font-lock which highlights two line titles"
-  `(list
-    ;; matcher function
-    (lambda (end)
+  (list
+   ;; matcher function
+   `(lambda (end)
       (and adoc-enable-two-line-title
            (re-search-forward ,(adoc-re-two-line-title del) end t)
            (< (abs (- (length (match-string 1)) (length (match-string 2)))) 3)
           (or (not (numberp adoc-enable-two-line-title))
               (not (equal adoc-enable-two-line-title (length (match-string 
2)))))
            (not (text-property-not-all (match-beginning 0) (match-end 0) 
'adoc-reserved nil))))
-    ;; highlighers
-    '(1 ,text-face t)
-    '(2 '(face adoc-hide-delimiter adoc-reserved t) t)))
+   ;; highlighers
+   `(1 ,text-face t)
+   `(2 '(face markup-meta-hide-face adoc-reserved t) t)))
 
 (defmacro adoc-kw-oulisti (type &optional level sub-type)
   "Creates a keyword for font-lock which highlights both (un)ordered list 
elements.
@@ -958,22 +949,16 @@ When LITERAL-P is non-nil, the contained text is literal 
text."
 
    ;; sections / document structure
    ;; ------------------------------
-   (adoc-kw-one-line-title 0 adoc-title-0)
-   (adoc-kw-one-line-title 1 adoc-title-1)
-   (adoc-kw-one-line-title 2 adoc-title-2)
-   (adoc-kw-one-line-title 3 adoc-title-3)
-   (adoc-kw-one-line-title 4 adoc-title-4)
-   ;; todo: bring that to work
-   ;; (adoc-kw-two-line-title ,(nth 0 adoc-two-line-title-del) adoc-title-0)
-   ;; (adoc-kw-two-line-title (nth 1 adoc-two-line-title-del) adoc-title-1)
-   ;; (adoc-kw-two-line-title (nth 2 adoc-two-line-title-del) adoc-title-2)
-   ;; (adoc-kw-two-line-title (nth 3 adoc-two-line-title-del) adoc-title-3)
-   ;; (adoc-kw-two-line-title (nth 4 adoc-two-line-title-del) adoc-title-4)
-   (adoc-kw-two-line-title "==" adoc-title-0)
-   (adoc-kw-two-line-title "--" adoc-title-1)
-   (adoc-kw-two-line-title "~~" adoc-title-2)
-   (adoc-kw-two-line-title "^^" adoc-title-3)
-   (adoc-kw-two-line-title "++" adoc-title-4)
+   (adoc-kw-one-line-title 0 markup-title-0-face)
+   (adoc-kw-one-line-title 1 markup-title-1-face)
+   (adoc-kw-one-line-title 2 markup-title-2-face)
+   (adoc-kw-one-line-title 3 markup-title-3-face)
+   (adoc-kw-one-line-title 4 markup-title-4-face)
+   (adoc-kw-two-line-title (nth 0 adoc-two-line-title-del) markup-title-0-face)
+   (adoc-kw-two-line-title (nth 1 adoc-two-line-title-del) markup-title-1-face)
+   (adoc-kw-two-line-title (nth 2 adoc-two-line-title-del) markup-title-2-face)
+   (adoc-kw-two-line-title (nth 3 adoc-two-line-title-del) markup-title-3-face)
+   (adoc-kw-two-line-title (nth 4 adoc-two-line-title-del) markup-title-4-face)
 
 
    ;; block macros 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]