Skip to content

Commit

Permalink
Merge pull request #35 from tmtvl/24-highlight-pod-the-same-as-comments
Browse files Browse the repository at this point in the history
Add comment-style highlighting to POD.
  • Loading branch information
tmtvl authored May 24, 2020
2 parents 43fd562 + 357a72b commit e0639c8
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions raku-font-lock.el
Original file line number Diff line number Diff line change
Expand Up @@ -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»).
Expand Down Expand Up @@ -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))))
Expand Down

0 comments on commit e0639c8

Please sign in to comment.