help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: random color of variables in programming languages


From: Emanuel Berg
Subject: Re: random color of variables in programming languages
Date: Fri, 20 Dec 2013 02:36:00 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Luca Ferrari <fluca1978@infinito.it> writes:

> any suggestion on where to start (in elisp code) for
> variable font face?

Cool dump: http://user.it.uu.se/~embe8573/colvar.png

(save-excursion
  (require 'thingatpt) ; word-at-point
  (if (search-forward-regexp "defvar " (point-max) t)
      (let*((var-name (word-at-point))
            (color-code (car (string-to-list var-name)))
            (the-face (if (= color-code 114) ; if it starts with 'r'
                     'font-lock-warning-face ; use this face
                     'font-lock-variable-face)) )
        (font-lock-add-keywords
         'emacs-lisp-mode
         `((,var-name . ,the-face)))
        (emacs-lisp-mode) ))) ; <-- hit this

(defvar red 1)
(defvar another-variable 4)

(if (= red 1) t nil)

-- 
Emanuel Berg, programmer-for-rent. CV, projects, etc at uXu
underground experts united:  http://user.it.uu.se/~embe8573


reply via email to

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