[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/adoc-mode 2c2eb80436: Fall back to general fontification
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/adoc-mode 2c2eb80436: Fall back to general fontification of source blocks if lang attr is n… (#55) |
Date: |
Sun, 18 Feb 2024 06:59:13 -0500 (EST) |
branch: elpa/adoc-mode
commit 2c2eb8043623aa99d35aacbad2ee39188bf1bad3
Author: TobiasZawada <i@tn-home.de>
Commit: GitHub <noreply@github.com>
Fall back to general fontification of source blocks if lang attr is n… (#55)
* Fall back to general fontification of source blocks if lang attr is not
given
* Add test case for source blocks without language attribute
Restructure adoc-fontify-code-blocks and adoc-fontify-code-block-natively
such that things that are needed for blocks with and without language
attribute
are done in adoc-fontify-code-blocks.
---------
Co-authored-by: Tobias Zawada <TOZ@esi-group.com>
---
adoc-mode.el | 40 +++++++++++++++++++---------------------
test/adoc-mode-test.el | 14 ++++++++++----
2 files changed, 29 insertions(+), 25 deletions(-)
diff --git a/adoc-mode.el b/adoc-mode.el
index 613301ba8a..a468e92fdc 100644
--- a/adoc-mode.el
+++ b/adoc-mode.el
@@ -2066,12 +2066,6 @@ START-SRC and END-SRC delimit the actual source code."
(put-text-property
(+ start-src (1- pos)) (1- (+ start-src next)) 'face
val adoc-buffer))))
- (add-text-properties start-block start-src '(face adoc-meta-face))
- (add-text-properties end-src end-block '(face adoc-meta-face))
- (add-text-properties
- start-block end-block
- '(font-lock-fontified t fontified t font-lock-multiline t
- adoc-code-block t adoc-reserved t))
(set-buffer-modified-p modified)))))
(defconst adoc-code-block-begin-regexp
@@ -2109,9 +2103,10 @@ Group 2 contains the block delimiter.")
"Search for next adoc-code block up to LAST.
NOERROR is the same as for `search-forward'.
-Return the source block language and
+Return a string with the source block language and
set match data if a source block is found.
-Otherwise return nil.
+If the source block is given without the language attribute return t.
+If no source block is found return nil.
The overall match data begins at the
header of the code block and ends at the end of the
@@ -2167,19 +2162,22 @@ Use this function as matching function MATCHER in
`font-lock-keywords'."
(end-src (match-end 1))
(end-src+nl (if (eq (char-after end-src) ?\n) (1+ end-src)
end-src))
(size (1+ (- end-src start-src))))
- (if (if (numberp adoc-fontify-code-blocks-natively)
- (<= size adoc-fontify-code-blocks-natively)
- adoc-fontify-code-blocks-natively)
- (adoc-fontify-code-block-natively lang start-block end-block
start-src end-src)
- (add-text-properties
- start-src
- end-src
- '(font-lock-face adoc-verbatim-face)))
- ;; Set background for block as well as opening and closing lines.
- (font-lock-append-text-property
- start-src end-src+nl 'face 'adoc-native-code-face)
- (add-text-properties
- start-src end-src+nl '(font-lock-fontified t font-lock-multiline
t adoc-code-block t))
+ (if (and
+ (stringp lang)
+ (if (numberp adoc-fontify-code-blocks-natively)
+ (<= size adoc-fontify-code-blocks-natively)
+ adoc-fontify-code-blocks-natively))
+ (progn
+ (adoc-fontify-code-block-natively lang start-block end-block
start-src end-src)
+ (font-lock-append-text-property start-src end-src 'face
'adoc-native-code-face)
+ (add-text-properties end-src end-src+nl '(face
adoc-native-code-face)))
+ ;; code block without language attribute or too large
+ (add-text-properties start-src end-src '(face
(adoc-verbatim-face adoc-code-face)))
+ (add-text-properties end-src end-src+nl '(face adoc-code-face)))
+ (add-text-properties start-block start-src '(face adoc-meta-face))
+ (put-text-property end-src+nl end-block 'face adoc-meta-face)
+ (add-text-properties start-src end-src+nl '(adoc-code-block t))
+ (add-text-properties start-block end-block '(font-lock-fontified t
font-lock-multiline t adoc-reserved t))
)))
t)))
diff --git a/test/adoc-mode-test.el b/test/adoc-mode-test.el
index 6222b4338c..754dee05fb 100644
--- a/test/adoc-mode-test.el
+++ b/test/adoc-mode-test.el
@@ -349,26 +349,32 @@ Don't use it for anything real.")
"\n" nil
"[source,adoctest-lang]\n----\n" 'adoc-meta-face
source-code
- "\n" '(adoc-meta-face adoc-native-code-face)
+ "\n" 'adoc-native-code-face
+ "----" 'adoc-meta-face
+ "\n" nil
+ ;; Code blocks without language attribute
+ "[source]\n----\n" 'adoc-meta-face
+ (apply #'concat (cl-loop for str in source-code by #'cddr collect str))
'(adoc-verbatim-face adoc-code-face)
+ "\n" 'adoc-code-face
"----" 'adoc-meta-face
"\n" nil
;; Code block as OPEN BLOCK
"\n" nil
"[source,adoctest-lang]\n--\n" 'adoc-meta-face
source-code
- "\n" '(adoc-meta-face adoc-native-code-face)
+ "\n" 'adoc-native-code-face
"--" 'adoc-meta-face
"\n" nil
;; Code block as Literal block
"[source,adoctest-lang]\n....\n" 'adoc-meta-face
source-code
- "\n" '(adoc-meta-face adoc-native-code-face)
+ "\n" 'adoc-native-code-face
"...." 'adoc-meta-face
"\n" nil
;; Test ignored spaces
"[source,\t adoctest-lang]\t \n....\n" 'adoc-meta-face
source-code
- "\n" '(adoc-meta-face adoc-native-code-face)
+ "\n" 'adoc-native-code-face
"...." 'adoc-meta-face
"\n" nil
))))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [nongnu] elpa/adoc-mode 2c2eb80436: Fall back to general fontification of source blocks if lang attr is n… (#55),
ELPA Syncer <=