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: Thu, 12 Dec 2013 22:05:22 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)

Luca Ferrari <fluca1978@infinito.it> writes:

> Using the variable name is a good idea, even if names
> could easily produce a clash.  However, any
> suggestion on where to start (in elisp code) for
> variable font face?

To setup the faces of a major mode, the way I did it
was to first define the faces, then setup regular
expressions (in groups), and then hook those groups to
faces. If there isn't any groups (or just one,
perhaps), you don't have to use the digits to hook the
groups, but can use the dotted pair notation (check out
fpscalc-comment below).

However, I am unsure if this can be twisted to do
"dynamic faces".

If not, we'll have to move closer to where actual
coloring is done. Does the Emacs idle-timer invoke
that?  Could you insert something in between?

Or what about a hook for each completed word? Or would
that be too slow?

;; ... the other faces

(defface fpscalc-semaphore-name
  '((t :inherit font-lock-variable-name-face :background "black" :foreground 
"yellow" :bold t))
  "The word after the word semaphore, after the left parenthesis."
  )

(defvar fpscalc-keywords
  '(("\\(!.*$\\)" . 'fpscalc-comment)
    ("\\(semaphore\\)\\((\\)\\([[:word:]]+\\)\\(\\, \\)\\([[:word:]]+\\)"
     (1 'fpscalc-semaphore-keyword)
     (3 'fpscalc-semaphore-name)
     (5 'fpscalc-task-name-and-index) )
    ("declarations\\|initialise\\|semaphores\\|formulas" . 
'fpscalc-program-parts)
    ("sigma\\|floor\\|ceiling\\|min\\|max" . 'fpscalc-math-functions)
    ("lp\\|ep\\|hp\\|all" . 'fpscalc-task-priority-sets)
    ("\\([[:word:]]\\)\\(\\[\\)\\(i\\)\\(\\]\\)"
     (1 'fpscalc-variable-name)
     (3 'fpscalc-i-task) )
    ("\\([[:word:]]\\)\\(\\[\\)\\(j\\)\\(\\]\\)"
     (1 'fpscalc-variable-name)
     (3 'fpscalc-j-task))
    ("\\([[:word:]]\\)\\(\\[\\)\\(.*\\)\\(\\]\\)"
     (1 'fpscalc-variable-name)
     (3 'fpscalc-task-name-and-index))
    ("\\(system \\)\\(.* \\)"
     (1 'fpscalc-system-keyword)
     (2 'fpscalc-system-name))
    ("\\(scalar\\|indexed\\|priority\\|blocking\\)\\( 
\\)+\\(\\(\\([[:word:]]\\( *\\, *\\)?\\)\\)*\\)"
     (1 'fpscalc-variable-type)
     (3 'fpscalc-variable-name))
    ("\\(tasks +\\)\\(\\(\\([[:word:]]\\( *\\, *\\)?\\)\\)*\\)"
     (1 'fpscalc-tasks-keyword)
     (2 'fpscalc-task-name-and-index))
    ))

-- 
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]