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

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

[elpa] externals/org bb6f328: org-src: Implement native inline src fonti


From: ELPA Syncer
Subject: [elpa] externals/org bb6f328: org-src: Implement native inline src fontification
Date: Tue, 30 Nov 2021 06:57:27 -0500 (EST)

branch: externals/org
commit bb6f32884767bec9b471ecf75d8b79c3b97dbf69
Author: TEC <tec@tecosaur.com>
Commit: TEC <tec@tecosaur.com>

    org-src: Implement native inline src fontification
    
    * lisp/org-src.el (org-fontify-inline-src-blocks,
    org-fontify-inline-src-blocks-1): Create a function to search the buffer
    up to a limit for inline src blocks.  Light fontification is applied to
    matched inline src blocks.  When `org-src-fontify-natively' is
    set, `org-src-font-lock-fontify-block' is applied to the content.
    
    * lisp/org.el (org-set-font-lock-defaults): Add
    `org-fontify-inline-src-blocks' to `org-font-lock-extra-keywords', which
    is locally bound inside `org-set-font-lock-defaults'.
    
    * lisp/org-faces.el: Introduce a new face `org-inline-src-block' which
    inherits from `org-block' by default.
---
 lisp/org-faces.el |  4 ++++
 lisp/org-src.el   | 44 ++++++++++++++++++++++++++++++++++++++++++++
 lisp/org.el       |  1 +
 3 files changed, 49 insertions(+)

diff --git a/lisp/org-faces.el b/lisp/org-faces.el
index b151045..2727627 100644
--- a/lisp/org-faces.el
+++ b/lisp/org-faces.el
@@ -459,6 +459,10 @@ verse and quote blocks are fontified using the `org-verse' 
and
   "Face used for the line delimiting the end of source blocks."
   :group 'org-faces)
 
+(defface org-inline-src-block '((t (:inherit org-block)))
+  "Face used for inline source blocks as a whole."
+  :group 'org-faces)
+
 (defface org-verbatim '((t (:inherit (fixed-pitch shadow))))
   "Face for fixed-with text like code snippets."
   :group 'org-faces
diff --git a/lisp/org-src.el b/lisp/org-src.el
index 51dde60..639a447 100644
--- a/lisp/org-src.el
+++ b/lisp/org-src.el
@@ -654,6 +654,50 @@ as `org-src-fontify-natively' is non-nil."
         '(font-lock-fontified t fontified t font-lock-multiline t))
        (set-buffer-modified-p modified)))))
 
+(defun org-fontify-inline-src-blocks (limit)
+  "Try to apply `org-fontify-inline-src-blocks-1'."
+  (condition-case nil
+      (org-fontify-inline-src-blocks-1 limit)
+    (error (message "Org mode fontification error in %S at %d"
+                    (current-buffer)
+                    (line-number-at-pos)))))
+
+(defun org-fontify-inline-src-blocks-1 (limit)
+  "Fontify inline src_LANG blocks, from `point' up to LIMIT."
+  (let ((case-fold-search t)
+        (initial-point (point)))
+    (while (re-search-forward "\\_<src_\\([^ \t\n[{]+\\)[{[]?" limit t) ; 
copied from `org-element-inline-src-block-parser'
+      (let ((beg (match-beginning 0))
+            (lang-beg (match-beginning 1))
+            (lang-end (match-end 1))
+            pt)
+        (font-lock-append-text-property lang-beg lang-end 'face 'org-meta-line)
+        (font-lock-append-text-property beg lang-beg 'face 'shadow)
+        (font-lock-append-text-property beg lang-end 'face 
'org-inline-src-block)
+        (setq pt (goto-char lang-end))
+        ;; `org-element--parse-paired-brackets' doesn't take a limit, so to
+        ;; prevent it searching the entire rest of the buffer we temporarily
+        ;; narrow the active region.
+        (save-restriction
+          (narrow-to-region beg (min limit (or (save-excursion (and 
(search-forward "\n" limit t 2) (point)))
+                                               (point-max))))
+          (message "buf: %S" (substring-no-properties (buffer-string)))
+          (when (ignore-errors (org-element--parse-paired-brackets ?\[))
+            (font-lock-append-text-property pt (point) 'face 
'org-inline-src-block)
+            (setq pt (point)))
+          (when (ignore-errors (org-element--parse-paired-brackets ?\{))
+            (remove-text-properties pt (point) '(face nil))
+            (font-lock-append-text-property pt (1+ pt) 'face 
'(org-inline-src-block shadow))
+            (unless (= (1+ pt) (1- (point)))
+              (if org-src-fontify-natively
+                  (org-src-font-lock-fontify-block
+                   (buffer-substring-no-properties lang-beg lang-end)
+                   (1+ pt) (1- (point)))
+                (font-lock-append-text-property (1+ pt) (1- (point)) 'face 
'org-inline-src-block)))
+            (font-lock-append-text-property (1- (point)) (point)'face 
'(org-inline-src-block shadow))
+            (setq pt (point)))))
+      t)))
+
 
 ;;; Escape contents
 
diff --git a/lisp/org.el b/lisp/org.el
index 025513e..ec59ddf 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5785,6 +5785,7 @@ needs to be inserted at a specific position in the 
font-lock sequence.")
                '(9 'org-special-keyword t))
          ;; Blocks and meta lines
          '(org-fontify-meta-lines-and-blocks)
+          '(org-fontify-inline-src-blocks)
           ;; Citations
           '(org-cite-activate))))
     (setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))



reply via email to

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