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

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

[nongnu] elpa/raku-mode e0639c89a3 230/253: Merge pull request #35 from


From: ELPA Syncer
Subject: [nongnu] elpa/raku-mode e0639c89a3 230/253: Merge pull request #35 from tmtvl/24-highlight-pod-the-same-as-comments
Date: Sat, 29 Jan 2022 08:29:01 -0500 (EST)

branch: elpa/raku-mode
commit e0639c89a3a29e9196e298951da6c3a79fb944e8
Merge: 43fd562825 357a72be71
Author: Tim Van den Langenbergh <tmt_vdl@gmx.com>
Commit: GitHub <noreply@github.com>

    Merge pull request #35 from tmtvl/24-highlight-pod-the-same-as-comments
    
    Add comment-style highlighting to POD.
---
 raku-font-lock.el | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/raku-font-lock.el b/raku-font-lock.el
index dd10f85ffc..90b60bc048 100644
--- a/raku-font-lock.el
+++ b/raku-font-lock.el
@@ -372,6 +372,53 @@ opening delimiter."
         (put-text-property (1- (point)) (point)
                            'syntax-table (string-to-syntax ">")))))
 
+(defun raku-syntax-propertize-pod-code-blocks (limit)
+  "Add syntax properties to code blocks in POD."
+  (while (search-forward "=begin code" limit t)
+    (let ((code-beg (point))
+          (code-end (- (search-forward "=end code" limit t)
+                       (length "=end code"))))
+      (put-text-property code-beg (1+ code-beg)
+                         'syntax-table (string-to-syntax ">"))
+      (put-text-property (1- code-end) code-end
+                         'syntax-table (string-to-syntax "<"))
+      (remove-text-properties code-beg code-end '(syntax-multiline nil))
+      (raku-syntax-propertize code-beg code-end))))
+
+(defun raku-syntax-propertize-pod-inline-code (limit)
+  "Add syntax properties to inline code blocks in POD."
+  (while (and
+          (re-search-forward "^\s*\n\s+[^\s]" limit t))
+    (backward-char)
+    (unless (looking-at 
"=\(begin\|end\|head\|for\|para\|item\|defn\|comment\)")
+      (let ((code-beg (1- (point))))
+        (re-search-forward "^[^\s]" limit t)
+        (when (looking-back "^[^\s]" code-beg)
+          (forward-line -1)
+          (end-of-line))
+        (put-text-property (1- code-beg) code-beg
+                           'syntax-table (string-to-syntax ">"))
+        (put-text-property (point) (1+ (point))
+                           'syntax-table (string-to-syntax "<"))
+        (remove-text-properties code-beg (point) '(syntax-multiline nil))
+        (raku-syntax-propertize code-beg (point))))))
+
+(defun raku-syntax-propertize-pod (limit)
+  "Add syntax properties to POD."
+  (let ((pod-beg (- (point) (length "=begin pod")))
+        (pod-end (search-forward "=end pod" limit t)))
+    (save-excursion
+      (put-text-property (1- pod-beg) pod-beg
+                         'syntax-table (string-to-syntax "<"))
+      (put-text-property pod-end (1+ pod-end)
+                         'syntax-table (string-to-syntax ">"))
+      (put-text-property pod-beg pod-end
+                         'syntax-multiline t)
+      (goto-char pod-beg)
+      (raku-syntax-propertize-pod-code-blocks pod-end)
+      (goto-char pod-beg)
+      (raku-syntax-propertize-pod-inline-code pod-end))))
+
 (defun raku-syntax-propertize-angles (open-angles)
   "Add syntax properties to angle-bracketed quotes (e.g. <foo> and «bar»).
 
@@ -431,6 +478,9 @@ Takes arguments START and END which delimit the region to 
propertize."
                      (and identifier (group "::"))))
        (1 "_")
        (2 "_"))
+      ;; pod
+      ((rx "=begin pod")
+       (0 (ignore (raku-syntax-propertize-pod end))))
       ;; comments
       ((rx "#")
        (0 (ignore (raku-syntax-propertize-comment end))))



reply via email to

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