How can I color some things in Emacs?

I program Django / Python in emacs and I would like things like {% comment%} FOO {% endcomment%} to turn orange.

How do I customize some colors for important Django template tags?

+4
source share
3 answers

You can use special modes like django-mode or MuMaMo .

If you want something very simple and assuming you are editing in html-mode, you can try the following:

(defun django-highlight-comments ()
  (interactive "p")
  (highlight-regexp "{%.*?%}" 'hi-orange))
(add-hook 'html-mode-hook 'django-highlight-comments)

(Just add the above lines to your .emacsor init.el, and eval it or restart emacs).

+6

. , , .

(defvar django-tag-face (make-face 'django-tag-face))
(defvar django-variable-face (make-face 'django-variable-face))
(set-face-background 'django-tag-face "Aquamarine")
(set-face-foreground 'django-tag-face "Black")
(set-face-background 'django-variable-face "Plum")
(set-face-foreground 'django-variable-face "Black")


(font-lock-add-keywords
 'html-mode
 '(("\\({%[^%]*%}\\)" 1 django-tag-face prepend)
   ("\\({{[^}]*}}\\)" 1 django-variable-face prepend)))
+3

Here are some links . I found them on Google. It seems that there is no completely complete and “official” solution to this problem, but there are a number of completely affordable alternatives.

+1
source

All Articles