Skip to content

Emacs minor mode to highlight each source code identifier uniquely based on its name

Notifications You must be signed in to change notification settings

AdrieanKhisbeArchives/color-identifiers-mode

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 

Repository files navigation

Color Identifiers Mode

Color Identifiers is a minor mode for Emacs that highlights each source code identifier uniquely based on its name. It is inspired by a post by Evan Brooks.

Currently it supports Scala (scala-mode2), JavaScript (js-mode and js2-mode), Ruby, Python, Emacs Lisp, Clojure, C, C++, and Java. You can add support for your favorite mode by modifying color-identifiers:modes-alist and optionally calling color-identifiers:set-declaration-scan-fn.

Check out the demo.

Screenshot of Color Identifiers Mode on Scala

It picks colors adaptively to fit the theme:

Different Themes

Use M-x color-identifiers:regenerate-colors after a theme change.

Installation

Color Identifiers is in MELPA. First set up MELPA:

(package-initialize)
(add-to-list 'package-archives
             '("melpa" . "http://melpa.milkbox.net/packages/") t)
(package-refresh-contents)

Then install it:

(package-install 'color-identifiers-mode)

Finally, visit a supported file and type M-x color-identifiers-mode.

If you like it, enable it for all supported files by adding the following to your init file:

(add-hook 'after-init-hook 'global-color-identifiers-mode)

Extras

To make the variables stand out, you can turn off highlighting for all other keywords using code similar to the following:

(let ((faces '(font-lock-comment-face font-lock-comment-delimiter-face font-lock-constant-face font-lock-type-face font-lock-function-name-face font-lock-variable-name-face font-lock-keyword-face font-lock-string-face font-lock-builtin-face font-lock-preprocessor-face font-lock-warning-face font-lock-doc-face)))
  (dolist (face faces)
    (set-face-attribute face nil :foreground nil :weight 'normal :slant 'normal)))

(set-face-attribute 'font-lock-comment-delimiter-face nil :slant 'italic)
(set-face-attribute 'font-lock-comment-face nil :slant 'italic)
(set-face-attribute 'font-lock-doc-face nil :slant 'italic)
(set-face-attribute 'font-lock-keyword-face nil :weight 'bold)
(set-face-attribute 'font-lock-builtin-face nil :weight 'bold)
(set-face-attribute 'font-lock-preprocessor-face nil :weight 'bold)

Other Keywords Dimmed

About

Emacs minor mode to highlight each source code identifier uniquely based on its name

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 100.0%