1
0
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-12-29 11:02:33 +00:00

Fontification: Better treatment of #+ lines and blocks

The content of blocks like #+begin_example will be marked with a
separate face.  That same face is also used for single lines
introducing text for specific backends.
This commit is contained in:
Carsten Dominik 2009-05-23 22:58:38 +02:00
parent 99b3b2d261
commit 476493d3b3
3 changed files with 76 additions and 2 deletions

View File

@ -1,3 +1,12 @@
2009-05-24 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-fontify-meta-lines): New function.
(org-set-font-lock-defaults): Call the new fontification
function.
* org-faces.el (org-meta-line): New face
(org-block): New face.
2009-05-27 Carsten Dominik <carsten.dominik@gmail.com>
* org.el (org-treat-insert-todo-heading-as-state-change)

View File

@ -402,7 +402,7 @@ changes."
:group 'org-faces)
(defface org-code
(org-compatible-face nil
(org-compatible-face 'shadow
'((((class color grayscale) (min-colors 88) (background light))
(:foreground "grey50"))
(((class color grayscale) (min-colors 88) (background dark))
@ -415,8 +415,28 @@ changes."
:group 'org-faces
:version "22.1")
(defface org-meta-line
(org-compatible-face 'font-lock-comment-face nil)
"Face for meta lines startin with \"#+\"."
:group 'org-faces
:version "22.1")
(defface org-block
(org-compatible-face 'shadow
'((((class color grayscale) (min-colors 88) (background light))
(:foreground "grey50"))
(((class color grayscale) (min-colors 88) (background dark))
(:foreground "grey70"))
(((class color) (min-colors 8) (background light))
(:foreground "green"))
(((class color) (min-colors 8) (background dark))
(:foreground "yellow"))))
"Face text in #+begin ... #+end blocks."
:group 'org-faces
:version "22.1")
(defface org-verbatim
(org-compatible-face nil
(org-compatible-face 'shadow
'((((class color grayscale) (min-colors 88) (background light))
(:foreground "grey50" :underline t))
(((class color grayscale) (min-colors 88) (background dark))

View File

@ -4204,6 +4204,49 @@ will be prompted for."
'(display t invisible t intangible t))
t)))
(defun org-fontify-meta-lines (limit)
(let ((case-fold-search t))
(if (re-search-forward
"^\\([ \t]*#\\+\\(\\([a-zA-Z]+:?\\)\\(_[a-zA-Z]+\\)?\\)\\(.*\\)\\)"
limit t)
(let ((beg (match-beginning 0))
(beg1 (line-beginning-position 2))
(dc1 (downcase (match-string 2)))
(dc3 (downcase (match-string 3)))
end end1)
(cond
((member dc1 '("html:" "ascii:" "latex:" "docbook:"))
;; a single line of backend-specific content
(remove-text-properties (match-beginning 0) (match-end 0)
'(display t invisible t intangible t))
(add-text-properties (match-beginning 1) (match-end 3)
'(font-lock-fontified t face org-meta-line))
(add-text-properties (match-beginning 5) (match-end 5)
'(font-lock-fontified t face org-block))
t)
((and (match-end 4) (equal dc3 "begin"))
;; Truely a block
(when (re-search-forward
(concat "^[ \t]*#\\+end" (match-string 4) "\\>.*")
nil t) ;; on purpose, we look further than LIMIT
(setq end (match-end 0) end1 (1- (match-beginning 0)))
(remove-text-properties beg end
'(display t invisible t intangible t))
(add-text-properties
beg end
'(font-lock-fontified t font-lock-multiline t))
(add-text-properties beg beg1 '(face org-meta-line))
(add-text-properties end1 end '(face org-meta-line))
(add-text-properties beg1 end1 '(face org-block))
t))
((not (member (char-after beg) '(?\ ?\t)))
;; just any other in-buffer setting, but not indented
(add-text-properties
beg (match-end 0)
'(font-lock-fontified t face org-meta-line))
t)
(t nil))))))
(defun org-activate-angle-links (limit)
"Run through the buffer and add overlays to links."
(if (re-search-forward org-angle-link-re limit t)
@ -4537,6 +4580,8 @@ between words."
"\\|" org-quote-string "\\)\\>")
'(1 'org-special-keyword t))
'("^#.*" (0 'font-lock-comment-face t))
;; Blocks and meta lines
'(org-fontify-meta-lines)
)))
(setq org-font-lock-extra-keywords (delq nil org-font-lock-extra-keywords))
;; Now set the full font-lock-keywords